Skip to content

Commit

Permalink
Fix iterable typehint
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierozi committed Jul 9, 2018
1 parent fe3b470 commit 8169e0a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yml

This file was deleted.

12 changes: 10 additions & 2 deletions src/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions tests/units/Fixtures/Parameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Plab\Validator\tests\unit;

use atoum\test;

class Parameters extends test
{
public function test__construct()
{
$data = json_decode('{"city": "Lux"}');

$this
->given(
$this->newTestedInstance(\Plab\Validator\Fixtures\Parameter::class, $data),
$result = $this->testedInstance->isValid()
)
->variable($result)
->isEqualTo(true)
;
}
}

0 comments on commit 8169e0a

Please sign in to comment.