From 4cd4c73e8efd57b538289d5232c6011ec20571fc Mon Sep 17 00:00:00 2001 From: Rafael Pezzetti Pelliccioli Date: Thu, 12 Sep 2019 10:23:12 -0300 Subject: [PATCH] Refactor PHP 7 and strategy pattern --- .travis.yml | 3 +- composer.json | 4 +- composer.lock | 1861 +++++++++++++++++++++++ readme.md | 2 +- src/Util/Mask.php | 98 +- src/Util/Mask/Acre.php | 3 +- src/Util/Mask/Alagoas.php | 3 +- src/Util/Mask/Amapa.php | 3 +- src/Util/Mask/Amazonas.php | 3 +- src/Util/Mask/Bahia.php | 3 +- src/Util/Mask/Ceara.php | 3 +- src/Util/Mask/DistritoFederal.php | 3 +- src/Util/Mask/EspiritoSanto.php | 3 +- src/Util/Mask/Goias.php | 3 +- src/Util/Mask/Maranhao.php | 3 +- src/Util/Mask/MatoGrosso.php | 3 +- src/Util/Mask/MatoGrossoDoSul.php | 3 +- src/Util/Mask/MinasGerais.php | 3 +- src/Util/Mask/Para.php | 3 +- src/Util/Mask/Paraiba.php | 3 +- src/Util/Mask/Parana.php | 3 +- src/Util/Mask/Pernambuco.php | 3 +- src/Util/Mask/Piaui.php | 3 +- src/Util/Mask/RioDeJaneiro.php | 3 +- src/Util/Mask/RioGrandeDoNorte.php | 3 +- src/Util/Mask/RioGrandeDoSul.php | 3 +- src/Util/Mask/Rondonia.php | 3 +- src/Util/Mask/Roraima.php | 3 +- src/Util/Mask/SantaCatarina.php | 3 +- src/Util/Mask/SaoPaulo.php | 3 +- src/Util/Mask/Sergipe.php | 3 +- src/Util/Mask/Tocantins.php | 5 +- src/Util/MaskFactory.php | 76 + src/Util/MaskInterface.php | 2 +- src/Util/Validator.php | 134 +- src/Util/Validator/Acre.php | 62 +- src/Util/Validator/Alagoas.php | 44 +- src/Util/Validator/Amapa.php | 48 +- src/Util/Validator/Amazonas.php | 48 +- src/Util/Validator/Bahia.php | 73 +- src/Util/Validator/Ceara.php | 43 +- src/Util/Validator/DistritoFederal.php | 65 +- src/Util/Validator/EspiritoSanto.php | 15 +- src/Util/Validator/Goias.php | 50 +- src/Util/Validator/Maranhao.php | 19 +- src/Util/Validator/MatoGrosso.php | 49 +- src/Util/Validator/MatoGrossoDoSul.php | 19 +- src/Util/Validator/MinasGerais.php | 89 +- src/Util/Validator/Para.php | 17 +- src/Util/Validator/Paraiba.php | 6 +- src/Util/Validator/Parana.php | 63 +- src/Util/Validator/Pernambuco.php | 52 +- src/Util/Validator/Piaui.php | 4 - src/Util/Validator/RioDeJaneiro.php | 51 +- src/Util/Validator/RioGrandeDoNorte.php | 50 +- src/Util/Validator/RioGrandeDoSul.php | 51 +- src/Util/Validator/Rondonia.php | 50 +- src/Util/Validator/Roraima.php | 46 +- src/Util/Validator/SantaCatarina.php | 5 - src/Util/Validator/SaoPaulo.php | 72 +- src/Util/Validator/Sergipe.php | 6 +- src/Util/Validator/StateValidator.php | 21 + src/Util/Validator/Tocantins.php | 91 +- src/Util/ValidatorFactory.php | 76 + src/Util/ValidatorInterface.php | 8 - tests/TestCase/MaskTest.php | 5 +- tests/TestCase/ValidatorTest.php | 4 + 67 files changed, 2578 insertions(+), 987 deletions(-) create mode 100644 composer.lock create mode 100644 src/Util/MaskFactory.php create mode 100644 src/Util/Validator/StateValidator.php create mode 100644 src/Util/ValidatorFactory.php delete mode 100644 src/Util/ValidatorInterface.php diff --git a/.travis.yml b/.travis.yml index 7808d79..ec87b27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php -php: - - 5.6 +php: - 7 before_script: diff --git a/composer.json b/composer.json index 7945525..a88acf3 100644 --- a/composer.json +++ b/composer.json @@ -3,10 +3,10 @@ "homepage": "https://github.com/pezzetti/ie-validator", "license": "MIT", "type": "library", - "version": "1.0", + "version": "2.0", "description": "PHP library for validating and printing Inscrição Estadual IE for brazilian states", "require": { - "php": ">=5.6" + "php": ">=7.0" }, "authors": [ { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..2c8c349 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1861 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "b770626a0585b2beecbefff0d3fb9d71", + "packages": [], + "packages-dev": [ + { + "name": "codacy/coverage", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/codacy/php-codacy-coverage.git", + "reference": "629d1fd597f91fb072bd822830059fd5145ce49a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/codacy/php-codacy-coverage/zipball/629d1fd597f91fb072bd822830059fd5145ce49a", + "reference": "629d1fd597f91fb072bd822830059fd5145ce49a", + "shasum": "" + }, + "require": { + "gitonomy/gitlib": ">=1.0", + "php": ">=5.3.3", + "symfony/console": "~2.5|~3.0|~4.0" + }, + "require-dev": { + "phpunit/phpunit": "~6.5" + }, + "bin": [ + "bin/codacycoverage" + ], + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jakob Pupke", + "email": "jakob.pupke@gmail.com" + } + ], + "description": "Sends PHP test coverage information to Codacy.", + "homepage": "https://github.com/codacy/php-codacy-coverage", + "time": "2018-04-30T16:23:12+00:00" + }, + { + "name": "doctrine/instantiator", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "a2c590166b2133a4633738648b6b064edae0814a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-03-17T17:37:11+00:00" + }, + { + "name": "gitonomy/gitlib", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/gitonomy/gitlib.git", + "reference": "49e599915eae04b734f31e6e88f773d32d921e2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/gitonomy/gitlib/zipball/49e599915eae04b734f31e6e88f773d32d921e2e", + "reference": "49e599915eae04b734f31e6e88f773d32d921e2e", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0", + "symfony/process": "^3.4|^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7|^6.5", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required to use loggers for reporting of execution" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Gitonomy\\Git\\": "src/Gitonomy/Git/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexandre Salomé", + "email": "alexandre.salome@gmail.com", + "homepage": "http://alexandre-salome.fr" + }, + { + "name": "Julien DIDIER", + "email": "genzo.wm@gmail.com", + "homepage": "http://www.jdidier.net" + } + ], + "description": "Library for accessing git", + "homepage": "http://gitonomy.com", + "time": "2019-06-23T09:49:01+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.9.3", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2019-08-09T12:45:53+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2019-04-30T17:48:53+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-07-14T14:27:02+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\": "src/Prophecy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2019-06-13T12:50:23+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "^1.0 || ^2.0" + }, + "require-dev": { + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" + }, + "suggest": { + "ext-xdebug": "^2.5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2017-04-02T07:44:40+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2017-11-27T13:52:08+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "791198a2c6254db10131eecfe8c06670700904db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-11-27T05:48:46+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "5.7.27", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.4.3", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "~2.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "^1.0.6|^2.0.1", + "symfony/yaml": "~2.1|~3.0|~4.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2018-02-01T05:50:59+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "3.4.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "abandoned": true, + "time": "2017-06-30T09:13:00+00:00" + }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14T16:28:37+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2017-01-29T09:50:25+00:00" + }, + { + "name": "sebastian/diff", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2017-05-22T07:24:03+00:00" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26T07:53:53+00:00" + }, + { + "name": "sebastian/exporter", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-11-19T08:54:04+00:00" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12T03:26:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-02-18T15:18:39+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2016-11-19T07:33:16+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/console", + "version": "v4.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "de63799239b3881b8a08f8481b22348f77ed7b36" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/de63799239b3881b8a08f8481b22348f77ed7b36", + "reference": "de63799239b3881b8a08f8481b22348f77ed7b36", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "^1.8", + "symfony/service-contracts": "^1.1" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/event-dispatcher": "<4.3", + "symfony/process": "<3.3" + }, + "provide": { + "psr/log-implementation": "1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.4|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "^4.3", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.4|~4.0", + "symfony/var-dumper": "^4.3" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2019-08-26T08:26:39+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "2ceb49eaccb9352bff54d22570276bb75ba4a188" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/2ceb49eaccb9352bff54d22570276bb75ba4a188", + "reference": "2ceb49eaccb9352bff54d22570276bb75ba4a188", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-08-06T08:03:45+00:00" + }, + { + "name": "symfony/process", + "version": "v4.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "e89969c00d762349f078db1128506f7f3dcc0d4a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/e89969c00d762349f078db1128506f7f3dcc0d4a", + "reference": "e89969c00d762349f078db1128506f7f3dcc0d4a", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2019-08-26T08:26:39+00:00" + }, + { + "name": "symfony/service-contracts", + "version": "v1.1.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "ea7263d6b6d5f798b56a45a5b8d686725f2719a3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/ea7263d6b6d5f798b56a45a5b8d686725f2719a3", + "reference": "ea7263d6b6d5f798b56a45a5b8d686725f2719a3", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "psr/container": "^1.0" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2019-08-20T14:44:19+00:00" + }, + { + "name": "symfony/yaml", + "version": "v4.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "symfony/console": "<3.4" + }, + "require-dev": { + "symfony/console": "~3.4|~4.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2019-08-20T14:27:59+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^7.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2019-08-24T08:43:50+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "codacy/coverage": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.6" + }, + "platform-dev": [] +} diff --git a/readme.md b/readme.md index ab9ac25..98f4a0e 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ PHP library for validating and printing Inscrição Estadual (IE) for brazilian ## Requirements -* PHP >=5.6 +* PHP >=7.0 ## Instalation diff --git a/src/Util/Mask.php b/src/Util/Mask.php index 597fd24..f8fd77d 100644 --- a/src/Util/Mask.php +++ b/src/Util/Mask.php @@ -33,95 +33,15 @@ class Mask { - public static function getIEForUF($estado, $inscricaoEstadual) + public static function getIEForUF($uf, $inscricaoEstadual) { - $estado = strtoupper($estado); - - switch ($estado) { - case States::AC: - $valid = Acre::getIE($inscricaoEstadual); - break; - case States::AL: - $valid = Alagoas::getIE($inscricaoEstadual); - break; - case States::AP: - $valid = Amapa::getIE($inscricaoEstadual); - break; - case States::AM: - $valid = Amazonas::getIE($inscricaoEstadual); - break; - case States::BA: - $valid = Bahia::getIE($inscricaoEstadual); - break; - case States::CE: - $valid = Ceara::getIE($inscricaoEstadual); - break; - case States::DF: - $valid = DistritoFederal::getIE($inscricaoEstadual); - break; - case States::ES: - $valid = EspiritoSanto::getIE($inscricaoEstadual); - break; - case States::GO: - $valid = Goias::getIE($inscricaoEstadual); - break; - case States::MA: - $valid = Maranhao::getIE($inscricaoEstadual); - break; - case States::MT: - $valid = MatoGrosso::getIE($inscricaoEstadual); - break; - case States::MS: - $valid = MatoGrossoDoSul::getIE($inscricaoEstadual); - break; - case States::MG: - $valid = MinasGerais::getIE($inscricaoEstadual); - break; - case States::PA: - $valid = Para::getIE($inscricaoEstadual); - break; - case States::PB: - $valid = Paraiba::getIE($inscricaoEstadual); - break; - case States::PR: - $valid = Parana::getIE($inscricaoEstadual); - break; - case States::PE: - $valid = Pernambuco::getIE($inscricaoEstadual); - break; - case States::PI: - $valid = Piaui::getIE($inscricaoEstadual); - break; - case States::RJ: - $valid = RioDeJaneiro::getIE($inscricaoEstadual); - break; - case States::RN: - $valid = RioGrandeDoNorte::getIE($inscricaoEstadual); - break; - case States::RS: - $valid = RioGrandeDoSul::getIE($inscricaoEstadual); - break; - case States::RO: - $valid = Rondonia::getIE($inscricaoEstadual); - break; - case States::RR: - $valid = Roraima::getIE($inscricaoEstadual); - break; - case States::SC: - $valid = SantaCatarina::getIE($inscricaoEstadual); - break; - case States::SP: - $valid = SaoPaulo::getIE($inscricaoEstadual); - break; - case States::SE: - $valid = Sergipe::getIE($inscricaoEstadual); - break; - case States::TO: - $valid = Tocantins::getIE($inscricaoEstadual); - break; - default: - $valid = false; - } - return $valid; + try { + $uf = strtoupper($uf); + $maskFactory = new MaskFactory(); + $mask = $maskFactory->makeMaskFor($uf); + return $mask->getMaskForIE($inscricaoEstadual); + } catch (Exception $err) { + throw $err; + } } } diff --git a/src/Util/Mask/Acre.php b/src/Util/Mask/Acre.php index 024122e..b9eb954 100644 --- a/src/Util/Mask/Acre.php +++ b/src/Util/Mask/Acre.php @@ -7,8 +7,7 @@ class Acre implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' .$inscricaoArr[2] . '.' .$inscricaoArr[3] . '/' .$inscricaoArr[4] . '-' . $inscricaoArr[5]; } diff --git a/src/Util/Mask/Alagoas.php b/src/Util/Mask/Alagoas.php index a7d0a64..1992740 100644 --- a/src/Util/Mask/Alagoas.php +++ b/src/Util/Mask/Alagoas.php @@ -6,8 +6,7 @@ class Alagoas implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { return $inscricaoEstadual; } } \ No newline at end of file diff --git a/src/Util/Mask/Amapa.php b/src/Util/Mask/Amapa.php index 8f14d5b..4941776 100644 --- a/src/Util/Mask/Amapa.php +++ b/src/Util/Mask/Amapa.php @@ -6,8 +6,7 @@ class Amapa implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { return $inscricaoEstadual; } } \ No newline at end of file diff --git a/src/Util/Mask/Amazonas.php b/src/Util/Mask/Amazonas.php index f930712..3e2db83 100644 --- a/src/Util/Mask/Amazonas.php +++ b/src/Util/Mask/Amazonas.php @@ -7,8 +7,7 @@ class Amazonas implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{2})(\d{3})(\d{3})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' .$inscricaoArr[2] . '.' .$inscricaoArr[3] . '-' .$inscricaoArr[4]; } diff --git a/src/Util/Mask/Bahia.php b/src/Util/Mask/Bahia.php index db563ed..444f90f 100644 --- a/src/Util/Mask/Bahia.php +++ b/src/Util/Mask/Bahia.php @@ -7,8 +7,7 @@ class Bahia implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{6})(\d{2})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' .$inscricaoArr[2] ; } diff --git a/src/Util/Mask/Ceara.php b/src/Util/Mask/Ceara.php index b519266..10f2f96 100644 --- a/src/Util/Mask/Ceara.php +++ b/src/Util/Mask/Ceara.php @@ -7,8 +7,7 @@ class Ceara implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' .$inscricaoArr[2] ; } diff --git a/src/Util/Mask/DistritoFederal.php b/src/Util/Mask/DistritoFederal.php index fdf9215..431a994 100644 --- a/src/Util/Mask/DistritoFederal.php +++ b/src/Util/Mask/DistritoFederal.php @@ -7,8 +7,7 @@ class DistritoFederal implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{11})(\d{2})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' .$inscricaoArr[2] ; } diff --git a/src/Util/Mask/EspiritoSanto.php b/src/Util/Mask/EspiritoSanto.php index edfc4aa..ca6093b 100644 --- a/src/Util/Mask/EspiritoSanto.php +++ b/src/Util/Mask/EspiritoSanto.php @@ -7,8 +7,7 @@ class EspiritoSanto implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' .$inscricaoArr[2] ; } diff --git a/src/Util/Mask/Goias.php b/src/Util/Mask/Goias.php index cd7afd0..b044020 100644 --- a/src/Util/Mask/Goias.php +++ b/src/Util/Mask/Goias.php @@ -7,8 +7,7 @@ class Goias implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{2})(\d{3})(\d{3})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2] . '.' . $inscricaoArr[3] . '-' . $inscricaoArr[4]; } diff --git a/src/Util/Mask/Maranhao.php b/src/Util/Mask/Maranhao.php index bf058de..a6a43e4 100644 --- a/src/Util/Mask/Maranhao.php +++ b/src/Util/Mask/Maranhao.php @@ -7,8 +7,7 @@ class Maranhao implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/MatoGrosso.php b/src/Util/Mask/MatoGrosso.php index 49471e7..6972650 100644 --- a/src/Util/Mask/MatoGrosso.php +++ b/src/Util/Mask/MatoGrosso.php @@ -7,8 +7,7 @@ class MatoGrosso implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{10})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/MatoGrossoDoSul.php b/src/Util/Mask/MatoGrossoDoSul.php index 215481f..357e458 100644 --- a/src/Util/Mask/MatoGrossoDoSul.php +++ b/src/Util/Mask/MatoGrossoDoSul.php @@ -6,8 +6,7 @@ class MatoGrossoDoSul implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/MinasGerais.php b/src/Util/Mask/MinasGerais.php index aa4ac52..fd05932 100644 --- a/src/Util/Mask/MinasGerais.php +++ b/src/Util/Mask/MinasGerais.php @@ -7,8 +7,7 @@ class MinasGerais implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{3})(\d{3})(\d{3})(\d{4})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2] . '.' . $inscricaoArr[3] . '/' . $inscricaoArr[4]; } diff --git a/src/Util/Mask/Para.php b/src/Util/Mask/Para.php index be5ba6f..ef083f6 100644 --- a/src/Util/Mask/Para.php +++ b/src/Util/Mask/Para.php @@ -7,8 +7,7 @@ class Para implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{2})(\d{6})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2] . '-' . $inscricaoArr[3] ; } diff --git a/src/Util/Mask/Paraiba.php b/src/Util/Mask/Paraiba.php index 375b795..fc668e5 100644 --- a/src/Util/Mask/Paraiba.php +++ b/src/Util/Mask/Paraiba.php @@ -7,8 +7,7 @@ class Paraiba implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2] ; } diff --git a/src/Util/Mask/Parana.php b/src/Util/Mask/Parana.php index 42c57a6..9779527 100644 --- a/src/Util/Mask/Parana.php +++ b/src/Util/Mask/Parana.php @@ -7,8 +7,7 @@ class Parana implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{3})(\d{5})(\d{2})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2] . '-' . $inscricaoArr[3] ; } diff --git a/src/Util/Mask/Pernambuco.php b/src/Util/Mask/Pernambuco.php index 959d4d3..bcb33b3 100644 --- a/src/Util/Mask/Pernambuco.php +++ b/src/Util/Mask/Pernambuco.php @@ -7,8 +7,7 @@ class Pernambuco implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{7})(\d{2})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2] ; } diff --git a/src/Util/Mask/Piaui.php b/src/Util/Mask/Piaui.php index 1dc42d1..967deb2 100644 --- a/src/Util/Mask/Piaui.php +++ b/src/Util/Mask/Piaui.php @@ -7,8 +7,7 @@ class Piaui implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2] ; } diff --git a/src/Util/Mask/RioDeJaneiro.php b/src/Util/Mask/RioDeJaneiro.php index 9ce04af..38fc51c 100644 --- a/src/Util/Mask/RioDeJaneiro.php +++ b/src/Util/Mask/RioDeJaneiro.php @@ -7,8 +7,7 @@ class RioDeJaneiro implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{2})(\d{3})(\d{2})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2]. '.' . $inscricaoArr[3]. '-' . $inscricaoArr[4] ; } diff --git a/src/Util/Mask/RioGrandeDoNorte.php b/src/Util/Mask/RioGrandeDoNorte.php index 3531d51..a7bd9ec 100644 --- a/src/Util/Mask/RioGrandeDoNorte.php +++ b/src/Util/Mask/RioGrandeDoNorte.php @@ -7,8 +7,7 @@ class RioGrandeDoNorte implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{2})(\d{3})(\d{3})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2]. '.' . $inscricaoArr[3]. '-' . $inscricaoArr[4] ; } diff --git a/src/Util/Mask/RioGrandeDoSul.php b/src/Util/Mask/RioGrandeDoSul.php index 82f510e..adfb3d1 100644 --- a/src/Util/Mask/RioGrandeDoSul.php +++ b/src/Util/Mask/RioGrandeDoSul.php @@ -7,8 +7,7 @@ class RioGrandeDoSul implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{3})(\d{7})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '/' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/Rondonia.php b/src/Util/Mask/Rondonia.php index a695d22..a6904c2 100644 --- a/src/Util/Mask/Rondonia.php +++ b/src/Util/Mask/Rondonia.php @@ -7,8 +7,7 @@ class Rondonia implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{13})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/Roraima.php b/src/Util/Mask/Roraima.php index 8264cb6..0f94045 100644 --- a/src/Util/Mask/Roraima.php +++ b/src/Util/Mask/Roraima.php @@ -7,8 +7,7 @@ class Roraima implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/SantaCatarina.php b/src/Util/Mask/SantaCatarina.php index 9355bfb..c7aad89 100644 --- a/src/Util/Mask/SantaCatarina.php +++ b/src/Util/Mask/SantaCatarina.php @@ -7,8 +7,7 @@ class SantaCatarina implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{3})(\d{3})(\d{3})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2]. '.' . $inscricaoArr[3]; } diff --git a/src/Util/Mask/SaoPaulo.php b/src/Util/Mask/SaoPaulo.php index 9ead359..145c622 100644 --- a/src/Util/Mask/SaoPaulo.php +++ b/src/Util/Mask/SaoPaulo.php @@ -7,8 +7,7 @@ class SaoPaulo implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{3})(\d{3})(\d{3})(\d{3})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '.' . $inscricaoArr[2]. '.' . $inscricaoArr[3]. '.' . $inscricaoArr[4]; } diff --git a/src/Util/Mask/Sergipe.php b/src/Util/Mask/Sergipe.php index e7a352a..f1014dd 100644 --- a/src/Util/Mask/Sergipe.php +++ b/src/Util/Mask/Sergipe.php @@ -7,8 +7,7 @@ class Sergipe implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{8})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } diff --git a/src/Util/Mask/Tocantins.php b/src/Util/Mask/Tocantins.php index aadcb71..aa96db1 100644 --- a/src/Util/Mask/Tocantins.php +++ b/src/Util/Mask/Tocantins.php @@ -7,12 +7,11 @@ class Tocantins implements MaskInterface { - public static function getIE($inscricaoEstadual) - { + public function getMaskForIE(string $inscricaoEstadual) : string { if(preg_match( '/^(\d{10})(\d{1})$/', $inscricaoEstadual, $inscricaoArr )) { return $inscricaoArr[1] . '-' . $inscricaoArr[2]; } return $inscricaoEstadual; - } + } } \ No newline at end of file diff --git a/src/Util/MaskFactory.php b/src/Util/MaskFactory.php new file mode 100644 index 0000000..3639626 --- /dev/null +++ b/src/Util/MaskFactory.php @@ -0,0 +1,76 @@ +states = [ + 'AC' => Acre::class, + 'AL' => Alagoas::class, + 'AP' => Amapa::class, + 'AM' => Amazonas::class, + 'BA' => Bahia::class, + 'CE' => Ceara::class, + 'DF' => DistritoFederal::class, + 'ES' => EspiritoSanto::class, + 'GO' => Goias::class, + 'ES' => EspiritoSanto::class, + 'MA' => Maranhao::class, + 'MT' => MatoGrosso::class, + 'MS' => MatoGrossoDoSul::class, + 'MG' => MinasGerais::class, + 'PA' => Para::class, + 'PB' => Paraiba::class, + 'PE' => Pernambuco::class, + 'PI' => Piaui::class, + 'PR' => Parana::class, + 'RJ' => RioDeJaneiro::class, + 'RN' => RioGrandeDoNorte::class, + 'RS' => RioGrandeDoSul::class, + 'RO' => Rondonia::class, + 'RR' => Roraima::class, + 'SC' => SantaCatarina::class, + 'SP' => SaoPaulo::class, + 'SE' => Sergipe::class, + 'TO' => Tocantins::class, + ]; + } + + public function makeMaskFor($state) { + if(!array_key_exists($state, $this->states)) { + throw new Exception('State not found'); + } + return new $this->states[$state]; + } +} \ No newline at end of file diff --git a/src/Util/MaskInterface.php b/src/Util/MaskInterface.php index d708cf2..f5facc8 100644 --- a/src/Util/MaskInterface.php +++ b/src/Util/MaskInterface.php @@ -4,5 +4,5 @@ interface MaskInterface { - public static function getIE($inscricaoEstatual); + public function getMaskForIE(string $ie) : string; } \ No newline at end of file diff --git a/src/Util/Validator.php b/src/Util/Validator.php index c117643..5c7ed6c 100644 --- a/src/Util/Validator.php +++ b/src/Util/Validator.php @@ -1,128 +1,18 @@ makeValidatorFor($uf); + $inscricaoEstadual = preg_replace( '/[^0-9]/', '', $inscricaoEstadual); + return $validator->isValidIE($inscricaoEstadual); + } catch (Exception $err) { + throw $err; + } + } } diff --git a/src/Util/Validator/Acre.php b/src/Util/Validator/Acre.php index 85bd8b7..d968633 100644 --- a/src/Util/Validator/Acre.php +++ b/src/Util/Validator/Acre.php @@ -1,60 +1,50 @@ calcDigit($body); + $secondDigit = $this->calcDigit($body . $firstDigit); - $pos2dig = strlen($inscricaoEstadual) - 1; - $pos1dig = strlen($inscricaoEstadual) - 2; + $pos2dig = strlen($ie) - 1; + $pos1dig = strlen($ie) - 2; - return $inscricaoEstadual[$pos1dig] == $_1dig && $inscricaoEstadual[$pos2dig] == $_2dig; + return $ie[$pos1dig] == $firstDigit && $ie[$pos2dig] == $secondDigit; } - private static function calculaDigito($corpo) + private function calcDigit($body) { - $peso = strlen($corpo) - 7; + $weight = strlen($body) - 7; $soma = 0; - foreach (str_split($corpo) as $digito) { - $soma += $digito * $peso; - $peso--; - if ($peso == 1) { - $peso = 9; + foreach (str_split($body) as $digito) { + $soma += $digito * $weight; + $weight--; + if ($weight == 1) { + $weight = 9; } } - $modulo = 11; - - $resto = $soma % $modulo; - - $dig = $modulo - $resto; + $mod = 11; + $rest = $soma % $mod; + $dig = $mod - $rest; if ($dig >= 10) { $dig = 0; } diff --git a/src/Util/Validator/Alagoas.php b/src/Util/Validator/Alagoas.php index d6a82bc..1587e53 100644 --- a/src/Util/Validator/Alagoas.php +++ b/src/Util/Validator/Alagoas.php @@ -1,45 +1,29 @@ = 10) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/Amapa.php b/src/Util/Validator/Amapa.php index b10830f..ecd09a3 100644 --- a/src/Util/Validator/Amapa.php +++ b/src/Util/Validator/Amapa.php @@ -1,51 +1,37 @@ = 10) { $dig = 0; } } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/Bahia.php b/src/Util/Validator/Bahia.php index 8b2a003..6709d1d 100644 --- a/src/Util/Validator/Bahia.php +++ b/src/Util/Validator/Bahia.php @@ -4,67 +4,58 @@ use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; -class Bahia implements ValidatorInterface +class Bahia extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - $length = strlen($inscricaoEstadual); - - if ($length !== 9 && $length !== 8) { - $valid = false; - } - if ($valid && !self::calculaDigitos($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + $length = strlen($ie); + return $length == 9 || $length == 8; + } + + protected function itStartsWith(string $ie) : bool { + return true; } - private static function calculaDigitos($inscricaoEstadual) + protected function calcIE(string $ie) : bool { - - $length = strlen($inscricaoEstadual); - $corpo = substr($inscricaoEstadual, 0, $length - 2); - $modulo = self::getModulo($inscricaoEstadual); - $_2dig = self::calculaDigito($corpo, $modulo); - $_1dig = self::calculaDigito($corpo . $_2dig, $modulo); - - $pos2dig = strlen($inscricaoEstadual) - 1; - - $pos1dig = strlen($inscricaoEstadual) - 2; - - return $inscricaoEstadual[$pos1dig] == $_1dig && $inscricaoEstadual[$pos2dig] == $_2dig; + $lenght = strlen($ie); + $body = substr($ie, 0, $lenght - 2); + $mod = $this->getMod($ie); + $secondDigit = $this->calcDigit($body, $mod); + $firstDigit = $this->calcDigit($body . $secondDigit, $mod); + $pos2dig = strlen($ie) - 1; + $pos1dig = strlen($ie) - 2; + + return $ie[$pos1dig] == $firstDigit && $ie[$pos2dig] == $secondDigit; } - private static function getModulo($inscricaoEstadual) + private function getMod($ie) { - $comprimento = strlen($inscricaoEstadual); - $posicao = 0; - if ($comprimento == 9) { - $posicao = 1; + $length = strlen($ie); + $position = 0; + if ($length == 9) { + $position = 1; } - $char = substr($inscricaoEstadual, $posicao, 1); + $char = substr($ie, $position, 1); if (in_array($char, [0, 1, 2, 3, 4, 5, 8], false)) { return 10; } return 11; } - private static function calculaDigito($corpo, $modulo) + private function calcDigit($body, $mod) { - $peso = strlen($corpo) + 1; + $weight = strlen($body) + 1; - $soma = 0; - foreach (str_split($corpo) as $digito) { - $soma += $digito * $peso; - $peso--; + $sum = 0; + foreach (str_split($body) as $digit) { + $sum += $digit * $weight; + $weight--; } - $resto = $soma % $modulo; + $rest = $sum % $mod; - $dig = $modulo - $resto; + $dig = $mod - $rest; if ($dig >= 10) { $dig = 0; } diff --git a/src/Util/Validator/Ceara.php b/src/Util/Validator/Ceara.php index ff20d31..84cb473 100644 --- a/src/Util/Validator/Ceara.php +++ b/src/Util/Validator/Ceara.php @@ -2,42 +2,33 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class Ceara implements ValidatorInterface +class Ceara extends StateValidator { - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigito($inscricaoEstadual) + protected function calcIE(string $ie) : bool { - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $peso = $length; - $corpo = substr($inscricaoEstadual, 0, $posicao); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $weight = $length; + $body = substr($ie, 0, $position); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; } - $resto = $soma % 11; + $rest = $sum % 11; - $dig = 11 - $resto; + $dig = 11 - $rest; if ($dig >= 10) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/DistritoFederal.php b/src/Util/Validator/DistritoFederal.php index ce820cc..64f8e52 100644 --- a/src/Util/Validator/DistritoFederal.php +++ b/src/Util/Validator/DistritoFederal.php @@ -2,60 +2,51 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class DistritoFederal implements ValidatorInterface +class DistritoFederal extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 13) { - $valid = false; - } - if ($valid && '07' != substr($inscricaoEstadual, 0, 2)) { - $valid = false; - } - - if ($valid && !self::calculaDigitos($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + return strlen($ie) == 13; + } + + protected function itStartsWith(string $ie) : bool { + return substr($ie, 0, 2) == '07'; } - private static function calculaDigitos($inscricaoEstadual) + protected function calcIE(string $ie) : bool { - $length = strlen($inscricaoEstadual); - $corpo = substr($inscricaoEstadual, 0, $length - 2); + $length = strlen($ie); + $body = substr($ie, 0, $length - 2); - $_1dig = self::calculaDigito($corpo); - $_2dig = self::calculaDigito($corpo . $_1dig); + $_1dig = $this->calcDigit($body); + $_2dig = $this->calcDigit($body . $_1dig); - $pos2dig = strlen($inscricaoEstadual) - 1; - $pos1dig = strlen($inscricaoEstadual) - 2; + $pos2dig = strlen($ie) - 1; + $pos1dig = strlen($ie) - 2; - return $inscricaoEstadual[$pos1dig] == $_1dig && $inscricaoEstadual[$pos2dig] == $_2dig; + return $ie[$pos1dig] == $_1dig && $ie[$pos2dig] == $_2dig; } - private static function calculaDigito($corpo) + private function calcDigit($body) { - $peso = strlen($corpo) - 7; - - $soma = 0; - foreach (str_split($corpo) as $digito) { - $soma += $digito * $peso; - $peso--; - if ($peso == 1) { - $peso = 9; + $weight = strlen($body) - 7; + + $sum = 0; + foreach (str_split($body) as $digit) { + $sum += $digit * $weight; + $weight--; + if ($weight == 1) { + $weight = 9; } } - $modulo = 11; + $mod = 11; - $resto = $soma % $modulo; - $dig = $modulo - $resto; + $rest = $sum % $mod; + $dig = $mod - $rest; if ($dig >= 10) { $dig = 0; } diff --git a/src/Util/Validator/EspiritoSanto.php b/src/Util/Validator/EspiritoSanto.php index 2244131..443bbdf 100644 --- a/src/Util/Validator/EspiritoSanto.php +++ b/src/Util/Validator/EspiritoSanto.php @@ -4,18 +4,5 @@ class EspiritoSanto extends Ceara { - - public static function check($inscricaoEstadual) - { - $valid = true; - // se não tiver 9 digitos não é valido - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - - } + } \ No newline at end of file diff --git a/src/Util/Validator/Goias.php b/src/Util/Validator/Goias.php index ea54cb8..6e3acd6 100644 --- a/src/Util/Validator/Goias.php +++ b/src/Util/Validator/Goias.php @@ -2,52 +2,40 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class Goias implements ValidatorInterface +class Goias extends StateValidator { - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - $inicio = substr($inscricaoEstadual, 0, 2); - if ($valid && !in_array($inicio, ['10', '11', '15'])) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + + protected function itStartsWith(string $ie) : bool { + $begin = substr($ie, 0, 2); + return in_array($begin, ['10', '11', '15']); } - protected static function calculaDigito($inscricaoEstadual) + protected function calcIE(string $ie) : bool { - $peso = 9; - $posicao = 8; - $soma = 0; - $length = strlen($inscricaoEstadual); - $corpo = substr($inscricaoEstadual, 0, $length - 1); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; + $weight = 9; + $position = 8; + $sum = 0; + $length = strlen($ie); + $body = substr($ie, 0, $length - 1); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; } - $resto = $soma % 11; + $rest = $sum % 11; - $dig = 11 - $resto; + $dig = 11 - $rest; if ($dig >= 10) { - if ($dig == 11 && '10103105' <= $corpo && $corpo <= '10119997') { + if ($dig == 11 && '10103105' <= $body && $body <= '10119997') { $dig = 1; } else { $dig = 0; } } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/Maranhao.php b/src/Util/Validator/Maranhao.php index 5ff5a7d..6e9c8e1 100644 --- a/src/Util/Validator/Maranhao.php +++ b/src/Util/Validator/Maranhao.php @@ -4,21 +4,8 @@ class Maranhao extends Ceara -{ - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - if ($valid && substr($inscricaoEstadual, 0, 2) != '12') { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - +{ + protected function itStartsWith(string $ie) : bool { + return substr($ie, 0, 2) == '12'; } } \ No newline at end of file diff --git a/src/Util/Validator/MatoGrosso.php b/src/Util/Validator/MatoGrosso.php index e527802..d88f885 100644 --- a/src/Util/Validator/MatoGrosso.php +++ b/src/Util/Validator/MatoGrosso.php @@ -2,44 +2,39 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class MatoGrosso implements ValidatorInterface +class MatoGrosso extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 11) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + return strlen($ie) == 11; + } + + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigito($inscricaoEstadual) + protected function calcIE(string $ie) : bool { - $peso = 3; - $posicao = 10; - $soma = 0; - $length = strlen($inscricaoEstadual); - $corpo = substr($inscricaoEstadual, 0, $length - 1); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; - if ($peso == 1) { - $peso = 9; + $weight = 3; + $position = 10; + $sum = 0; + $length = strlen($ie); + $body = substr($ie, 0, $length - 1); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; + if ($weight == 1) { + $weight = 9; } } - $resto = $soma % 11; + $rest = $sum % 11; - $dig = 11 - $resto; + $dig = 11 - $rest; if ($dig >= 10) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/MatoGrossoDoSul.php b/src/Util/Validator/MatoGrossoDoSul.php index 488976c..c88325f 100644 --- a/src/Util/Validator/MatoGrossoDoSul.php +++ b/src/Util/Validator/MatoGrossoDoSul.php @@ -3,21 +3,8 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; class MatoGrossoDoSul extends Ceara -{ - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - if ($valid && substr($inscricaoEstadual, 0, 2) != '28') { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - +{ + protected function itStartsWith(string $ie) : bool { + return substr($ie, 0, 2) == '28'; } } \ No newline at end of file diff --git a/src/Util/Validator/MinasGerais.php b/src/Util/Validator/MinasGerais.php index 4637e23..25c1c8c 100644 --- a/src/Util/Validator/MinasGerais.php +++ b/src/Util/Validator/MinasGerais.php @@ -2,71 +2,66 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class MinasGerais implements ValidatorInterface +class MinasGerais extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 13) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; + protected function checkLength(string $ie) : bool { + return strlen($ie) == 13; } - protected static function calculaDigito($inscricaoEstadual) - { - $length = strlen($inscricaoEstadual); - $pos_1dig = $length - 2; - $pos_2dig = $length - 1; + protected function itStartsWith(string $ie) : bool { + return true; + } + + protected function calcIE(string $ie) : bool { + $length = strlen($ie); + $posFirstDigit = $length - 2; + $posSecondDigit = $length - 1; - $corpo = substr($inscricaoEstadual, 0, 11); + $body = substr($ie, 0, 11); - $_1dig = self::calculaPrimeiroDigito($corpo); - $_2dig = self::calculaSegundoDigito($corpo . $_1dig); + $firstDigit = $this->calcFirstDigit($body); + $secondDigit = $this->calcSecondDigit($body . $firstDigit); - return $_1dig == $inscricaoEstadual[$pos_1dig] && $_2dig == $inscricaoEstadual[$pos_2dig]; + return $firstDigit == $ie[$posFirstDigit] && $secondDigit == $ie[$posSecondDigit]; } - private static function calculaPrimeiroDigito($corpo) - { - $corpo = substr_replace($corpo, '0', 3, 0); - $concatenacao = ""; - foreach (str_split($corpo) as $i => $item) { - $peso = ((($i + 3) % 2) == 0) ? 2 : 1; - $concatenacao .= ($item * $peso); - } - $soma = 0; + private function calcFirstDigit($body) { + $body = substr_replace($body, '0', 3, 0); + $concatenate = ""; + $count = 0; + foreach (str_split($body) as $i => $item) { + $count++; + $weight = ((($i + 3) % 2) == 0) ? 2 : 1; + $concatenate .= ($item * $weight); + } + $sum = 0; - foreach (str_split($concatenacao) as $algarismo) { - $soma += $algarismo; + foreach (str_split($concatenate) as $algarismo) { + $sum += $algarismo; } - $strSoma = $soma . ''; - $length = strlen($strSoma); - $last_char = substr($strSoma, $length - 1, 1); + $strSum = $sum . ''; + $length = strlen($strSum); + $lastChar = substr($strSum, $length - 1, 1); - return ($last_char == 0) ? 0 : (10 - $last_char); + return ($lastChar == 0) ? 0 : (10 - $lastChar); } - private static function calculaSegundoDigito($corpo) - { - $peso = 3; - $soma = 0; - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; - if ($peso == 1) { - $peso = 11; + private function calcSecondDigit($body) { + $weight = 3; + $sum = 0; + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; + if ($weight == 1) { + $weight = 11; } } - $resto = $soma % 11; - $dig = 11 - $resto; + $rest = $sum % 11; + $dig = 11 - $rest; if ($dig >= 10) { $dig = 0; diff --git a/src/Util/Validator/Para.php b/src/Util/Validator/Para.php index 50be182..155d351 100644 --- a/src/Util/Validator/Para.php +++ b/src/Util/Validator/Para.php @@ -5,20 +5,7 @@ class Para extends Ceara { - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - if ($valid && substr($inscricaoEstadual, 0, 2) != '15') { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function itStartsWith(string $ie) : bool { + return substr($ie, 0, 2) == '15'; } } \ No newline at end of file diff --git a/src/Util/Validator/Paraiba.php b/src/Util/Validator/Paraiba.php index f8ebbc7..8033b68 100644 --- a/src/Util/Validator/Paraiba.php +++ b/src/Util/Validator/Paraiba.php @@ -5,9 +5,5 @@ class Paraiba extends Ceara { - public static final function check($inscricaoEstadual) - { - return parent::check((string)$inscricaoEstadual); - } - + } \ No newline at end of file diff --git a/src/Util/Validator/Parana.php b/src/Util/Validator/Parana.php index ecc2011..5dfc8f3 100644 --- a/src/Util/Validator/Parana.php +++ b/src/Util/Validator/Parana.php @@ -2,57 +2,50 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class Parana implements ValidatorInterface +class Parana extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) !== 10) { - $valid = false; - } - if ($valid && !self::calculaDigitos($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + return strlen($ie) == 10; + } + + protected function itStartsWith(string $ie) : bool { + return true; } + protected function calcIE(string $ie) : bool { - private static function calculaDigitos($inscricaoEstadual) - { - - $length = strlen($inscricaoEstadual); - $corpo = substr($inscricaoEstadual, 0, $length - 2); + $length = strlen($ie); + $body = substr($ie, 0, $length - 2); - $_1dig = self::calculaDigito($corpo); - $_2dig = self::calculaDigito($corpo . $_1dig); + $firstDigit = $this->calcDigit($body); + $secondDigit = $this->calcDigit($body . $firstDigit); - $pos2dig = strlen($inscricaoEstadual) - 1; - $pos1dig = strlen($inscricaoEstadual) - 2; + $pos2dig = strlen($ie) - 1; + $pos1dig = strlen($ie) - 2; - return $inscricaoEstadual[$pos1dig] == $_1dig && $inscricaoEstadual[$pos2dig] == $_2dig; + return $ie[$pos1dig] == $firstDigit && $ie[$pos2dig] == $secondDigit; } - private static function calculaDigito($corpo) + private static function calcDigit($body) { - $peso = strlen($corpo) - 5; - - $soma = 0; - foreach (str_split($corpo) as $digito) { - $soma += $digito * $peso; - $peso--; - if ($peso == 1) { - $peso = 7; + $weight = strlen($body) - 5; + + $sum = 0; + foreach (str_split($body) as $digit) { + $sum += $digit * $weight; + $weight--; + if ($weight == 1) { + $weight = 7; } } - $modulo = 11; - $resto = $soma % $modulo; + $mod = 11; + $rest = $sum % $mod; - $dig = $modulo - $resto; + $dig = $mod - $rest; if ($dig >= 10) { $dig = 0; } diff --git a/src/Util/Validator/Pernambuco.php b/src/Util/Validator/Pernambuco.php index bb41a24..402af42 100644 --- a/src/Util/Validator/Pernambuco.php +++ b/src/Util/Validator/Pernambuco.php @@ -2,54 +2,44 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class Pernambuco implements ValidatorInterface +class Pernambuco extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) !== 9) { - $valid = false; - } - if ($valid && !self::calculaDigitos($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigitos($inscricaoEstadual) - { + protected function calcIE(string $ie) : bool { - $length = strlen($inscricaoEstadual); - $corpo = substr($inscricaoEstadual, 0, $length - 2); + $length = strlen($ie); + $body = substr($ie, 0, $length - 2); - $_1dig = self::calculaDigito($corpo); - $_2dig = self::calculaDigito($corpo . $_1dig); + $firstDigit = $this->calculaDigito($body); + $secondDigit = $this->calculaDigito($body . $firstDigit); - $pos2dig = strlen($inscricaoEstadual) - 1; - $pos1dig = strlen($inscricaoEstadual) - 2; + $pos2dig = strlen($ie) - 1; + $pos1dig = strlen($ie) - 2; - return $inscricaoEstadual[$pos1dig] == $_1dig && $inscricaoEstadual[$pos2dig] == $_2dig; + return $ie[$pos1dig] == $firstDigit && $ie[$pos2dig] == $secondDigit; } - private static function calculaDigito($corpo) + private function calculaDigito($body) { - $peso = strlen($corpo) + 1; + $weight = strlen($body) + 1; - $soma = 0; - foreach (str_split($corpo) as $digito) { - $soma += $digito * $peso; - $peso--; + $sum = 0; + foreach (str_split($body) as $digito) { + $sum += $digito * $weight; + $weight--; } - $modulo = 11; - $resto = $soma % $modulo; + $mod = 11; + $rest = $sum % $mod; - $dig = $modulo - $resto; + $dig = $mod - $rest; if ($dig >= 10) { $dig = 0; } diff --git a/src/Util/Validator/Piaui.php b/src/Util/Validator/Piaui.php index 29fb56f..b346cbd 100644 --- a/src/Util/Validator/Piaui.php +++ b/src/Util/Validator/Piaui.php @@ -4,9 +4,5 @@ class Piaui extends Ceara { - public static final function check($inscricaoEstadual) - { - return parent::check((string)$inscricaoEstadual); - } } \ No newline at end of file diff --git a/src/Util/Validator/RioDeJaneiro.php b/src/Util/Validator/RioDeJaneiro.php index 33e3c03..ae282eb 100644 --- a/src/Util/Validator/RioDeJaneiro.php +++ b/src/Util/Validator/RioDeJaneiro.php @@ -2,44 +2,37 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class RioDeJaneiro implements ValidatorInterface +class RioDeJaneiro extends StateValidator { - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 8) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + return strlen($ie) == 8; + } + + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigito($inscricaoEstadual) - { - $peso = 2; - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $corpo = substr($inscricaoEstadual, 0, $length - 1); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; - if ($peso == 1) { - $peso = 7; + protected function calcIE(string $ie) : bool { + $weight = 2; + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $body = substr($ie, 0, $length - 1); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; + if ($weight == 1) { + $weight = 7; } } - $resto = $soma % 11; - $dig = 11 - $resto; + $rest = $sum % 11; + $dig = 11 - $rest; if ($dig >= 10) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/RioGrandeDoNorte.php b/src/Util/Validator/RioGrandeDoNorte.php index 06c7bcf..2ae491c 100644 --- a/src/Util/Validator/RioGrandeDoNorte.php +++ b/src/Util/Validator/RioGrandeDoNorte.php @@ -2,44 +2,34 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class RioGrandeDoNorte implements ValidatorInterface +class RioGrandeDoNorte extends StateValidator { - - public static function check($inscricaoEstadual) - { - $valid = true; - $length = strlen($inscricaoEstadual); - if ($length != 9 && $length != 10) { - $valid = false; - } - if ($valid && substr($inscricaoEstadual, 0, 2) != '20') { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + $length = strlen($ie); + return $length == 9 || $length == 10; + } + + protected function itStartsWith(string $ie) : bool { + return substr($ie, 0, 2) == '20'; } - protected static function calculaDigito($inscricaoEstadual) - { - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $peso = $length; - $corpo = substr($inscricaoEstadual, 0, $posicao); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; + protected function calcIE(string $ie) : bool { + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $weight = $length; + $body = substr($ie, 0, $position); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; } - $dig = $soma * 10 % 11; + $dig = $sum * 10 % 11; if ($dig == 10) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/RioGrandeDoSul.php b/src/Util/Validator/RioGrandeDoSul.php index 1f08aa8..08fc683 100644 --- a/src/Util/Validator/RioGrandeDoSul.php +++ b/src/Util/Validator/RioGrandeDoSul.php @@ -2,46 +2,39 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class RioGrandeDoSul implements ValidatorInterface +class RioGrandeDoSul extends StateValidator { - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 10) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + return strlen($ie) == 10; + } + + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigito($inscricaoEstadual) - { - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $peso = 2; - $corpo = substr($inscricaoEstadual, 0, $posicao); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; - if ($peso == 1) { - $peso = 9; + protected function calcIE(string $ie) : bool { + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $weight = 2; + $body = substr($ie, 0, $position); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; + if ($weight == 1) { + $weight = 9; } } - $resto = $soma % 11; + $rest = $sum % 11; - $dig = 11 - $resto; + $dig = 11 - $rest; if ($dig >= 10) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/Rondonia.php b/src/Util/Validator/Rondonia.php index ba33944..255d1b6 100644 --- a/src/Util/Validator/Rondonia.php +++ b/src/Util/Validator/Rondonia.php @@ -2,45 +2,39 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class Rondonia implements ValidatorInterface +class Rondonia extends StateValidator { - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 14) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; - + protected function checkLength(string $ie) : bool { + return strlen($ie) == 14; + } + + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigito($inscricaoEstadual) - { - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $peso = 6; - $corpo = substr($inscricaoEstadual, 0, $posicao); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; - if ($peso == 1) { - $peso = 9; + protected function calcIE(string $ie) : bool { + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $weight = 6; + $body = substr($ie, 0, $position); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; + if ($weight == 1) { + $weight = 9; } } - $resto = $soma % 11; - $dig = 11 - $resto; + $rest = $sum % 11; + $dig = 11 - $rest; if ($dig >= 10) { $dig -= 10; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/Roraima.php b/src/Util/Validator/Roraima.php index 9c28723..d7f3561 100644 --- a/src/Util/Validator/Roraima.php +++ b/src/Util/Validator/Roraima.php @@ -2,41 +2,27 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; - -class Roraima implements ValidatorInterface -{ - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 9) { - $valid = false; - } - if ($valid && substr($inscricaoEstadual, 0, 2) != '24') { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; +class Roraima extends StateValidator +{ + protected function itStartsWith(string $ie) : bool { + return substr($ie, 0, 2) == '24'; } - protected static function calculaDigito($inscricaoEstadual) - { - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $peso = 1; - $corpo = substr($inscricaoEstadual, 0, $posicao); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso++; + protected function calcIE(string $ie) : bool { + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $weight = 1; + $body = substr($ie, 0, $position); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight++; } - $dig = $soma % 9; + $dig = $sum % 9; - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/Validator/SantaCatarina.php b/src/Util/Validator/SantaCatarina.php index b7e03f5..ff32cc1 100644 --- a/src/Util/Validator/SantaCatarina.php +++ b/src/Util/Validator/SantaCatarina.php @@ -6,9 +6,4 @@ class SantaCatarina extends Ceara { - public static final function check($inscricaoEstadual) - { - return parent::check((string)$inscricaoEstadual); - } - } \ No newline at end of file diff --git a/src/Util/Validator/SaoPaulo.php b/src/Util/Validator/SaoPaulo.php index 2c26438..4dfbf73 100644 --- a/src/Util/Validator/SaoPaulo.php +++ b/src/Util/Validator/SaoPaulo.php @@ -2,46 +2,39 @@ namespace Pezzetti\InscricaoEstadual\Util\Validator; -use Pezzetti\InscricaoEstadual\Util\ValidatorInterface; +use Pezzetti\InscricaoEstadual\Util\Validator\StateValidator; -class SaoPaulo implements ValidatorInterface +class SaoPaulo extends StateValidator { - - public static function check($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 12) { - $valid = false; - } - if ($valid && !self::calculaDigito($inscricaoEstadual)) { - $valid = false; - } - return $valid; + protected function checkLength(string $ie) : bool { + return strlen($ie) == 12; + } + + protected function itStartsWith(string $ie) : bool { + return true; } - protected static function calculaDigito($inscricaoEstadual) - { - $length = strlen($inscricaoEstadual); - $pos_1dig = $length - 4; - $pos_2dig = $length - 1; + protected function calcIE(string $ie) : bool { + $length = strlen($ie); + $positionFirstDigit = $length - 4; + $positionSecondDigit = $length - 1; - $_1dig = self::calculaPrimeiroDigito($inscricaoEstadual); + $firstDigit = $this->calcFirstDigit($ie); - $_2dig = self::calculaSegundoDigito($inscricaoEstadual); + $secondDigit = $this->calcSecondDigit($ie); - return $_1dig == $inscricaoEstadual[$pos_1dig] && $_2dig == $inscricaoEstadual[$pos_2dig]; + return $firstDigit == $ie[$positionFirstDigit] && $secondDigit == $ie[$positionSecondDigit]; } - private static function calculaPrimeiroDigito($inscricaoEstadual) - { - $corpo = substr($inscricaoEstadual, 0, 8); - $pesos = [1, 3, 4, 5, 6, 7, 8, 10]; - $soma = 0; - foreach (str_split($corpo) as $i => $item) { - $soma += ($item * $pesos[$i]); + private function calcFirstDigit($ie) { + $body = substr($ie, 0, 8); + $weights = [1, 3, 4, 5, 6, 7, 8, 10]; + $sum = 0; + foreach (str_split($body) as $i => $item) { + $sum += ($item * $weights[$i]); } - $dig = $soma % 11; + $dig = $sum % 11; $strDig = $dig . ''; $length = strlen($strDig); @@ -49,20 +42,19 @@ private static function calculaPrimeiroDigito($inscricaoEstadual) return substr($dig, $length - 1, 1); } - private static function calculaSegundoDigito($inscricaoEstadual) - { - $corpo = substr($inscricaoEstadual, 0, 11); - $peso = 3; - $soma = 0; - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; - if ($peso == 1) { - $peso = 10; + private function calcSecondDigit($ie) { + $body = substr($ie, 0, 11); + $weight = 3; + $sum = 0; + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; + if ($weight == 1) { + $weight = 10; } } - $dig = $soma % 11; + $dig = $sum % 11; $strDig = $dig . ''; $length = strlen($strDig); diff --git a/src/Util/Validator/Sergipe.php b/src/Util/Validator/Sergipe.php index 80f24b4..af87c08 100644 --- a/src/Util/Validator/Sergipe.php +++ b/src/Util/Validator/Sergipe.php @@ -4,9 +4,5 @@ class Sergipe extends Ceara { - public static final function check($inscricaoEstadual) - { - return parent::check((string)$inscricaoEstadual); - } - + } \ No newline at end of file diff --git a/src/Util/Validator/StateValidator.php b/src/Util/Validator/StateValidator.php new file mode 100644 index 0000000..b7f5eeb --- /dev/null +++ b/src/Util/Validator/StateValidator.php @@ -0,0 +1,21 @@ +checkLength($ie) && + $this->itStartsWith($ie) && + $this->calcIE($ie); + + } + + protected function checkLength(string $ie) : bool { + return strlen($ie) == 9; + } + + abstract protected function itStartsWith(string $ie) : bool; + + abstract protected function calcIE(string $ie) : bool; + +} \ No newline at end of file diff --git a/src/Util/Validator/Tocantins.php b/src/Util/Validator/Tocantins.php index 03f4825..c91a65d 100644 --- a/src/Util/Validator/Tocantins.php +++ b/src/Util/Validator/Tocantins.php @@ -1,62 +1,75 @@ checkOld($ie) || $this->checkNew($ie); } - protected static function checkOld($inscricaoEstadual) - { - $valid = true; - if (strlen($inscricaoEstadual) != 11) { - $valid = false; - } - if ($valid) { - $categoria = substr($inscricaoEstadual, 2, 2); - if (!in_array($categoria, ['01', '02', '03', '99'])) { - $valid = false; - } - $corpo = substr_replace($inscricaoEstadual, '', 2, 2); - } + protected function checkLength(string $ie) : bool { + return strlen($ie) == 11 || strlen($ie) == 9; + } + + protected function itStartsWith(string $ie) : bool { + return true; + } + + private function checkOld($ie) { + $body = substr_replace($ie, '', 2, 2); + return $this->oldStartsWith($ie) && $this->calcOld($body); + } + + private function oldStartsWith($ie) { + $categ = substr($ie, 2, 2); + return in_array($categ, ['01', '02', '03', '99']); + } - if ($valid && !self::calculaDigito($corpo)) { - $valid = false; + private function calcOld($ie) { + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $weight = $length; + $body = substr($ie, 0, $position); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; } - return $valid; - } + $rest = $sum % 11; - protected static function checkNew($inscricaoEstadual) - { - return strlen($inscricaoEstadual) == 9 && static::calculaDigitoNova($inscricaoEstadual); + $dig = 11 - $rest; + if ($dig >= 10) { + $dig = 0; + } + return $dig == $ie[$position]; } + private function checkNew($ie) { + return $this->calcDigitNew($ie); + } - protected static function calculaDigitoNova($inscricaoEstadual) - { - $peso = 9; - $soma = 0; - $length = strlen($inscricaoEstadual); - $posicao = $length - 1; - $corpo = substr($inscricaoEstadual, 0, $length - 1); - foreach (str_split($corpo) as $item) { - $soma += $item * $peso; - $peso--; + private function calcDigitNew($ie) { + $weight = 9; + $sum = 0; + $length = strlen($ie); + $position = $length - 1; + $body = substr($ie, 0, $length - 1); + foreach (str_split($body) as $item) { + $sum += $item * $weight; + $weight--; } - $resto = $soma % 11; + $rest = $sum % 11; - $dig = 11 - $resto; - if ($resto < 2) { + $dig = 11 - $rest; + if ($rest < 2) { $dig = 0; } - return $dig == $inscricaoEstadual[$posicao]; + return $dig == $ie[$position]; } } \ No newline at end of file diff --git a/src/Util/ValidatorFactory.php b/src/Util/ValidatorFactory.php new file mode 100644 index 0000000..fc1425d --- /dev/null +++ b/src/Util/ValidatorFactory.php @@ -0,0 +1,76 @@ +states = [ + 'AC' => Acre::class, + 'AL' => Alagoas::class, + 'AP' => Amapa::class, + 'AM' => Amazonas::class, + 'BA' => Bahia::class, + 'CE' => Ceara::class, + 'DF' => DistritoFederal::class, + 'ES' => EspiritoSanto::class, + 'GO' => Goias::class, + 'ES' => EspiritoSanto::class, + 'MA' => Maranhao::class, + 'MT' => MatoGrosso::class, + 'MS' => MatoGrossoDoSul::class, + 'MG' => MinasGerais::class, + 'PA' => Para::class, + 'PB' => Paraiba::class, + 'PE' => Pernambuco::class, + 'PI' => Piaui::class, + 'PR' => Parana::class, + 'RJ' => RioDeJaneiro::class, + 'RN' => RioGrandeDoNorte::class, + 'RS' => RioGrandeDoSul::class, + 'RO' => Rondonia::class, + 'RR' => Roraima::class, + 'SC' => SantaCatarina::class, + 'SP' => SaoPaulo::class, + 'SE' => Sergipe::class, + 'TO' => Tocantins::class, + ]; + } + + public function makeValidatorFor($state) { + if(!array_key_exists($state, $this->states)) { + throw new Exception('State not found'); + } + return new $this->states[$state]; + } +} \ No newline at end of file diff --git a/src/Util/ValidatorInterface.php b/src/Util/ValidatorInterface.php deleted file mode 100644 index f039ba9..0000000 --- a/src/Util/ValidatorInterface.php +++ /dev/null @@ -1,8 +0,0 @@ -