Skip to content

Commit 5bdfb1d

Browse files
author
Christian Blank
authored
Change constructor of result object
* Update informations * Make errors parameter in result constructor optional
1 parent a0e0b2b commit 5bdfb1d

8 files changed

+33
-11
lines changed

.scrutinizer.yml

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ tools:
66
config:
77
standard: PSR2
88

9+
checks:
10+
php:
11+
code_rating: true
12+
duplication: true
13+
914
filter:
1015
excluded_paths:
1116
- docs/*

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP Structure Check
22
===================
33

44
[![Build Status](https://travis-ci.org/1blankz7/php-structure-check.svg?branch=master)](https://travis-ci.org/1blankz7/php-structure-check)
5+
[![Latest Stable Version](https://poser.pugx.org/1blankz7/php-structure-check/v/stable)](https://packagist.org/packages/1blankz7/php-structure-check)
6+
[![Total Downloads](https://poser.pugx.org/1blankz7/php-structure-check/downloads)](https://packagist.org/packages/1blankz7/php-structure-check)
7+
[![License](https://poser.pugx.org/1blankz7/php-structure-check/license)](https://packagist.org/packages/1blankz7/php-structure-check)
58

69
This library can check a complex array structure against a given requirement.
710
The purpose of this library is to create a better experience when testing a result set from an api or something similar.

composer.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "1blankz7/php-structure-check",
33
"description": "Structural check of arrays for PHP 5.6+",
44
"keywords": ["array", "structure", "types"],
5-
"homepage": "http://phpspec.net/",
5+
"homepage": "https://github.com/1blankz7/php-structure-check",
66
"type": "library",
77
"license": "MIT",
88
"authors": [
@@ -12,8 +12,6 @@
1212
"homepage": "http://cblank.de"
1313
}
1414
],
15-
"require": {
16-
},
1715
"require-dev": {
1816
"phpspec/phpspec": "^3.2"
1917
},

spec/CheckerSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ function it_accepts_a_type_and_an_array_as_parameter_for_fulfills(TypeInterface
2222
function it_returns_the_result_of_the_type_in_fulfills(TypeInterface $type, ResultInterface $result)
2323
{
2424
$type->check([])->willReturn($result);
25-
$this->fulfills([], $type)->shouldBeAnInstanceOf(ResultInterface::class);
25+
$this->fulfills([], $type)->shouldBe($result);
2626
}
2727
}

spec/ResultSpec.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@
22

33
namespace spec\StructureCheck;
44

5-
use StructureCheck\Result;
65
use PhpSpec\ObjectBehavior;
6+
use StructureCheck\Result;
77

88
class ResultSpec extends ObjectBehavior
99
{
10-
function let() {
11-
$this->beConstructedWith(true, []);
12-
}
1310

1411
function it_is_initializable()
1512
{
13+
$this->beConstructedWith(true, []);
1614
$this->shouldHaveType(Result::class);
1715
}
16+
17+
function it_will_return_is_valid_if_it_was_set_in_constructor()
18+
{
19+
$this->beConstructedWith(true, []);
20+
$this->isValid()->shouldBe(true);
21+
}
22+
23+
function it_will_return_is_invalid_if_it_was_set_in_constructor()
24+
{
25+
$this->beConstructedWith(false, []);
26+
$this->isValid()->shouldBe(false);
27+
}
28+
29+
function it_will_return_an_empty_array_if_no_error_list_is_given()
30+
{
31+
$this->beConstructedWith(true);
32+
$this->getErrors()->shouldHaveCount(0);
33+
}
1834
}

src/Result.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Result implements ResultInterface
2525
* @param bool $valid
2626
* @param array $errors
2727
*/
28-
public function __construct($valid, array $errors)
28+
public function __construct($valid, array $errors = [])
2929
{
3030
$this->valid = $valid;
3131
$this->errors = $errors;

src/Type/AnyType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ class AnyType implements TypeInterface
1515
*/
1616
public function check($value)
1717
{
18-
return new Result(true, []);
18+
return new Result(true);
1919
}
2020
}

src/Type/NullableType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(TypeInterface $child)
3232
public function check($value)
3333
{
3434
if(is_null($value)) {
35-
return new Result(true, []);
35+
return new Result(true);
3636
}
3737

3838
return $this->child->check($value);

0 commit comments

Comments
 (0)