diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca99f03 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +[![continuousphp](https://img.shields.io/continuousphp/git-hub/Pierozi/Validator/master.svg)](https://app.continuousphp.com/git-hub/Pierozi/Validator) ![Packagist](https://img.shields.io/packagist/v/plab/validator.svg) + +# Validator +Validator and transform parameter with rules + +## Related Project +The rule use in this library are based on the famous [Hoa\Ruler](github.com/hoaproject/ruler) library diff --git a/composer.json b/composer.json index 36d709f..40dfbe9 100644 --- a/composer.json +++ b/composer.json @@ -7,12 +7,12 @@ "require": { "php": ">=7.2.0", "hoa/ruler": "~2.0", - "hoa/ustring": "~4.0", - "atoum/atoum": "^3.3", - "atoum/stubs": "^2.6" + "hoa/ustring": "~4.0" }, "require-dev": { - "phpstan/phpstan": "^0.10.1" + "phpstan/phpstan": "^0.10.1", + "atoum/atoum": "^3.3", + "atoum/stubs": "^2.6" }, "autoload": { "psr-4": { diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 162be97..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,5 +0,0 @@ -php: - image: plab/docker-php:7.0-fpm - volumes: - - .:/app - command: 'php-fpm' diff --git a/src/Parameters.php b/src/Parameters.php index 002e774..a7b5fe9 100644 --- a/src/Parameters.php +++ b/src/Parameters.php @@ -20,11 +20,19 @@ class Parameters implements \Iterator, \Countable /** * Parameters constructor. * @param string $parameterClassName - * @param \Traversable $parameters, must be Traversable + * @param mixed $parameters must be Traversable * @throws \Exception */ - public function __construct(string $parameterClassName, \Traversable $parameters) + public function __construct(string $parameterClassName, $parameters) { + if (false === is_array($parameters) + && false === ($parameters instanceof \stdClass) + && false === ($parameters instanceof \Iterator) + && false === ($parameters instanceof \Traversable) + ) { + throw new \Exception('Parameters must be an array or traversable object'); + } + $this->iterator = new \ArrayIterator(); foreach ($parameters as $key => $value) { diff --git a/tests/units/Fixtures/Parameters.php b/tests/units/Fixtures/Parameters.php new file mode 100644 index 0000000..6244130 --- /dev/null +++ b/tests/units/Fixtures/Parameters.php @@ -0,0 +1,22 @@ +given( + $this->newTestedInstance(\Plab\Validator\Fixtures\Parameter::class, $data), + $result = $this->testedInstance->isValid() + ) + ->variable($result) + ->isEqualTo(true) + ; + } +} \ No newline at end of file