diff --git a/README.md b/README.md index 1b40d5e..e491b67 100644 --- a/README.md +++ b/README.md @@ -1 +1,37 @@ +## Filipac CNP - Validare CNP [![Build Status](https://travis-ci.org/filipac/cnp.svg)](https://travis-ci.org/laravel/framework)[![Latest Stable Version](https://poser.pugx.org/filipac/cnp/v/stable.svg)](https://packagist.org/packages/filipac/cnp) [![Total Downloads](https://poser.pugx.org/filipac/cnp/downloads.svg)](https://packagist.org/packages/filipac/cnp) [![Latest Unstable Version](https://poser.pugx.org/filipac/cnp/v/unstable.svg)](https://packagist.org/packages/filipac/cnp) [![License](https://poser.pugx.org/filipac/cnp/license.svg)](https://packagist.org/packages/filipac/cnp) + +### Cum instalez pachetul? +``` +composer require filipac/cnp ~1.0 +``` +Sau introduceti in sectiunea require din ```composer.json```: +```json +"filipac/cnp": "~1.0" +``` + +### Cum folosesc acest pachet? +Clasa ```Cnp``` are 2 metode publice statice: ```valid``` care returneaza un boolean (true, false). Este disponibila si functia +```invalid``` care este practic functia valid, dar negata. +```php + +``` + +### Cum sa contribui? +Daca ai idei de imbunatatire a acestui script, da fork acestui repository, fa modificarile necesare si apoi da un pull-request. +Nu uita sa scrii un test (vezi ```tests/CnpTest.php```) pentru ce ai implementat, altfel nu voi accepta request-ul. +Testarea se face cu **PhpUnit**. + +### Licienta + +Acest script este distribuit sub [licienta MIT](http://opensource.org/licenses/MIT). \ No newline at end of file diff --git a/src/Cnp.php b/src/Cnp.php index 30d33ca..1e1998d 100644 --- a/src/Cnp.php +++ b/src/Cnp.php @@ -4,6 +4,12 @@ class Cnp { + public static function invalid($cnp) + { + return ! static::valid($cnp); + } + + public static function valid($p_cnp) { // CNP must have 13 characters diff --git a/tests/CnpTest.php b/tests/CnpTest.php index 7c61e3c..ae036ed 100644 --- a/tests/CnpTest.php +++ b/tests/CnpTest.php @@ -9,14 +9,20 @@ public function testCnpValid() { $valid = Cnp::valid('1930101021162'); $this->assertTrue($valid); + + $valid = Cnp::invalid('1930101021162'); + $this->assertFalse($valid); } /** @test */ public function testCnpInvalid() { - $valid = Cnp::valid('1930101021161'); - $this->assertFalse($valid); + $invalid = Cnp::valid('1930101021161'); + $this->assertFalse($invalid); + + $invalid = Cnp::invalid('1930101021161'); + $this->assertTrue($invalid); } }