Skip to content

Commit

Permalink
Merge pull request #14 from brazanation/cleanup
Browse files Browse the repository at this point in the history
remove unsed code
  • Loading branch information
tonicospinelli committed Aug 25, 2016
2 parents 6a2c868 + 68addaa commit eb5e707
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/Cnpj.php
Expand Up @@ -12,8 +12,6 @@ final class Cnpj implements DocumentInterface

const REGEX = '/^([\d]{2,3})([\d]{3})([\d]{3})([\d]{4})([\d]{2})$/';

const FORMAT_REGEX = '/^[\d]{2,3}\.[\d]{3}\.[\d]{3}\/[\d]{4}-[\d]{2}$/';

/**
* @var string
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Cpf.php
Expand Up @@ -12,8 +12,6 @@ final class Cpf implements DocumentInterface

const REGEX = '/^([\d]{3})([\d]{3})([\d]{3})([\d]{2})$/';

const FORMAT_REGEX = '/^[\d]{3}\.[\d]{3}\.[\d]{3}-[\d]{2}$/';

/**
* @var string
*/
Expand Down
21 changes: 13 additions & 8 deletions src/NFeAccessKey.php
Expand Up @@ -52,14 +52,14 @@ public static function generate($state, \DateTime $generatedAt, Cnpj $cnpj, $ser

$baseNumber = "{$state}{$yearMonth}{$cnpj}{$model}{$serie}{$invoiceNumber}{$controlNumber}";

$digit = self::calculateDigits($baseNumber);
$digit = self::calculateDigit($baseNumber);

return new self("{$baseNumber}{$digit}");
}

public function format()
{
return trim(preg_replace(static::REGEX, static::MASK, $this->nfeKey));
return trim(preg_replace(self::REGEX, self::MASK, $this->nfeKey));
}

public function __toString()
Expand All @@ -70,29 +70,34 @@ public function __toString()
private function validate($number)
{
if (empty($number)) {
throw InvalidDocumentException::notEmpty(static::LABEL);
throw InvalidDocumentException::notEmpty(self::LABEL);
}
if (!$this->isValid($number)) {
throw InvalidDocumentException::isNotValid(static::LABEL, $number);
throw InvalidDocumentException::isNotValid(self::LABEL, $number);
}
}

private function isValid($number)
{
if (strlen($number) != static::LENGTH) {
if (strlen($number) != self::LENGTH) {
return false;
}

if (preg_match("/^{$number[0]}{" . static::LENGTH . '}$/', $number)) {
if (preg_match("/^{$number[0]}{" . self::LENGTH . '}$/', $number)) {
return false;
}

$digits = static::calculateDigits(substr($number, 0, -1));
$digits = self::calculateDigit(substr($number, 0, -1));

return $digits === substr($number, -1);
}

private static function calculateDigits($baseNumber)
/**
* @param string $baseNumber
*
* @return string
*/
private static function calculateDigit($baseNumber)
{
$calculator = new DigitCalculator($baseNumber);
$calculator->useComplementaryInsteadOfModule();
Expand Down
8 changes: 2 additions & 6 deletions src/PisPasep.php
Expand Up @@ -12,15 +12,11 @@ final class PisPasep implements DocumentInterface

const REGEX = '/^([\d]{3})([\d]{5})([\d]{2})([\d]{1})$/';

const FORMAT_REGEX = '/^[\d]{3}\.[\d]{5}\.[\d]{2}-[\d]{1}$/';

/**
* @var string
*/
private $pispasep;

protected $mask = '000.00000.00-0';

/**
* PisPasep constructor.
*
Expand Down Expand Up @@ -53,7 +49,7 @@ private function isValidCV($number)
return false;
}

$digits = $this->calculateDigits(substr($number, 0, -1));
$digits = $this->calculateDigit(substr($number, 0, -1));

return $digits === substr($number, -1);
}
Expand All @@ -80,7 +76,7 @@ public function __toString()
*
* @return string
*/
private function calculateDigits($number)
private function calculateDigit($number)
{
$calculator = new DigitCalculator($number);
$calculator->withMultipliersInterval(2, 9);
Expand Down

0 comments on commit eb5e707

Please sign in to comment.