diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7abeb9d --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "fdisotto/PartitaIVA", + "description": "Partita IVA checker", + "homepage": "https://github.com/fdisotto/partitaIva", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Fabio Di Sotto", + "email": "fabio.disotto@gmail.com" + } + ], + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "4.5.*" + }, + "minimum-stability": "dev", + "autoload": { + "psr-0": { + "fdisotto": "src/" + } + } +} \ No newline at end of file diff --git a/example/index.php b/example/index.php new file mode 100644 index 0000000..1e5c0d9 --- /dev/null +++ b/example/index.php @@ -0,0 +1,8 @@ +check('012345678')); + +var_dump($pIva->check('01234567891')); \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..219d911 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + + + + + tests + + + + \ No newline at end of file diff --git a/src/fdisotto/PartitaIVA.php b/src/fdisotto/PartitaIVA.php new file mode 100644 index 0000000..32db334 --- /dev/null +++ b/src/fdisotto/PartitaIVA.php @@ -0,0 +1,55 @@ + + * @copyright 2015 Fabio Di Sotto + * @link https://github.com/fdisotto/cac-api + * @version 1.0.0 + * + * MIT LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +namespace fdisotto; + +/** + * PartitaIVA + * + * Partita IVA checker + * + * @author Fabio Di Sotto + */ +class PartitaIVA +{ + /** + * Return the check result + * + * @param string $partitaIVA Partita IVA to check + * @return bool Check result + */ + public function check($partitaIVA) + { + $pattern = "/^[0-9]{11}$/i"; + + return preg_match($pattern, trim($partitaIVA)) ? true : false; + } +} \ No newline at end of file diff --git a/tests/PartitaIVATest.php b/tests/PartitaIVATest.php new file mode 100644 index 0000000..a24be42 --- /dev/null +++ b/tests/PartitaIVATest.php @@ -0,0 +1,20 @@ +pIva = new \fdisotto\PartitaIVA(); + } + + public function testCheckTrue() + { + $this->assertTrue($this->pIva->check('01234567891')); + } + + public function testCheckFalse() + { + $this->assertFalse($this->pIva->check('123456')); + } +} \ No newline at end of file