diff --git a/src/Renavam.php b/src/Renavam.php index 8621a04..949f666 100644 --- a/src/Renavam.php +++ b/src/Renavam.php @@ -20,10 +20,26 @@ final class Renavam extends AbstractDocument public function __construct($renavam) { $renavam = preg_replace('/\D/', '', $renavam); - $renavam = str_pad($renavam, self::LENGTH, 0, STR_PAD_LEFT); + $renavam = $this->padNumber($renavam); parent::__construct($renavam, self::LENGTH, self::NUMBER_OF_DIGITS, self::LABEL); } + /** + * Pad left a number to length(11) with 0(ZERO) + * + * @param string $number + * + * @return string + */ + private function padNumber($number) + { + if (empty($number)) { + return ''; + } + + return str_pad($number, self::LENGTH, 0, STR_PAD_LEFT); + } + /** * {@inheritdoc} */ diff --git a/tests/RenavamTest.php b/tests/RenavamTest.php index a5a7826..6635452 100644 --- a/tests/RenavamTest.php +++ b/tests/RenavamTest.php @@ -29,7 +29,10 @@ public function provideValidNumbersAndExpectedFormat() public function provideEmptyData() { - return []; + return [ + [Renavam::LABEL, ''], + [Renavam::LABEL, null], + ]; } public function provideInvalidNumber()