Skip to content

Commit 6e8961f

Browse files
srmnqSaraGfroerer
andauthored
Php7.4 (#25)
* Declare strict types * Typehinting * Remove redundant docbloc Co-authored-by: Sara Gfrörer <[email protected]>
1 parent 6d248da commit 6e8961f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+136
-82
lines changed

composer.json

+43-34
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
11
{
2-
"name": "cubicl/php-structure-check",
3-
"description": "Structural check of arrays for PHP 7.3+",
4-
"keywords": ["array", "structure", "types"],
5-
"homepage": "https://github.com/cubicldev/php-structure-check",
6-
"type": "library",
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Christian Blank",
11-
"email": "[email protected]",
12-
"homepage": "https://cubicl.de"
13-
}
2+
"name": "cubicl/php-structure-check",
3+
"description": "Structural check of arrays for PHP 7.3+",
4+
"keywords": [
5+
"array",
6+
"structure",
7+
"types"
8+
],
9+
"homepage": "https://github.com/cubicldev/php-structure-check",
10+
"type": "library",
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Christian Blank",
15+
"email": "[email protected]",
16+
"homepage": "https://cubicl.de"
17+
}
18+
],
19+
"scripts": {
20+
"check": [
21+
"@analyze",
22+
"@tests",
23+
"@tests-spec"
1424
],
15-
"scripts": {
16-
"check": ["@analyze", "@tests", "@tests-spec"],
17-
"tests": "phpunit tests",
18-
"analyze": "phpstan analyse --level max src",
19-
"tests-spec": "phpspec run --no-interaction"
20-
},
21-
"require-dev": {
22-
"phpspec/phpspec": "^6.2",
23-
"phpunit/phpunit": "^9.3",
24-
"phpstan/phpstan": "^0.12"
25-
},
26-
"autoload": {
27-
"psr-4": {
28-
"Cubicl\\StructureCheck\\": [
29-
"src"
30-
],
31-
"Cubicl\\StructureCheck\\Test\\": [
32-
"tests"
33-
]
34-
}
35-
},
25+
"tests": "phpunit tests",
26+
"analyze": "phpstan analyse --level max src",
27+
"tests-spec": "phpspec run --no-interaction"
28+
},
29+
"require-dev": {
30+
"phpspec/phpspec": "^6.2",
31+
"phpunit/phpunit": "^9.3",
32+
"phpstan/phpstan": "^0.12"
33+
},
34+
"autoload": {
35+
"psr-4": {
36+
"Cubicl\\StructureCheck\\": [
37+
"src"
38+
],
39+
"Cubicl\\StructureCheck\\Test\\": [
40+
"tests"
41+
]
42+
}
43+
},
3644
"require": {
37-
"ext-json": "*"
45+
"ext-json": "*",
46+
"php": "^7.4"
3847
}
3948
}

spec/Check/CountCheckSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Check;
46

57
use Cubicl\StructureCheck\Check\CountCheck;

spec/Check/NumericRangeCheckSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Check;
46

57
use Prophecy\Argument;

spec/CheckerSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck;
46

57
use PhpSpec\ObjectBehavior;

spec/ResultSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck;
46

57
use PhpSpec\ObjectBehavior;

spec/Type/AnyTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\AnyType;

spec/Type/BoolTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use PhpSpec\ObjectBehavior;

spec/Type/DatetimeTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\DatetimeType;

spec/Type/EnumTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\EnumType;

spec/Type/ExactValueTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\ExactValueType;

spec/Type/FloatTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\FloatType;

spec/Type/IntTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\IntType;

spec/Type/ListTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\ListType;

spec/Type/NullableTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Result;

spec/Type/NumericTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\NumericType;

spec/Type/ObjectTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\ObjectType;

spec/Type/OptionalTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Result;

spec/Type/RegexTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use PhpSpec\ObjectBehavior;

spec/Type/StringTypeSpec.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace spec\Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Type\StringType;

src/Check/CountCheck.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck\Check;
46

57
use Countable;

src/Check/NumericRangeCheck.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck\Check;
46

57
use Cubicl\StructureCheck\Error;

src/Checker.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck;
46

57
use Cubicl\StructureCheck\Type\TypeInterface;
68

79
class Checker implements CheckerInterface
810
{
9-
/**
10-
* @inheritdoc
11-
*/
1211
public function fulfills($element, TypeInterface $requirement): ResultInterface
1312
{
1413
return $requirement->check('', $element);

src/CheckerInterface.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck;
46

57
use Cubicl\StructureCheck\Type\TypeInterface;
@@ -8,9 +10,6 @@ interface CheckerInterface
810
{
911
/**
1012
* @param mixed $element the element which should be tested
11-
* @param TypeInterface $requirement
12-
*
13-
* @return ResultInterface
1413
*/
1514
public function fulfills($element, TypeInterface $requirement): ResultInterface;
1615
}

src/Error.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck;
46

57
class Error implements ErrorInterface

src/ErrorInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck;
46

57
interface ErrorInterface

src/Result.php

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck;
46

57
class Result implements ResultInterface
68
{
9+
private bool $valid;
710

811
/**
9-
* @var bool
10-
*/
11-
private $valid;
12-
13-
/**
14-
* @var ErrorInterface[]
12+
* @var array<ErrorInterface>
1513
*/
16-
private $errors;
14+
private array $errors;
1715

1816
/**
19-
* Result constructor.
20-
*
21-
* @param bool $valid
22-
* @param ErrorInterface[] $errors
17+
* @param array<ErrorInterface> $errors
2318
*/
24-
public function __construct($valid, array $errors)
19+
public function __construct(bool $valid, array $errors)
2520
{
2621
$this->valid = $valid;
2722
$this->errors = $errors;
@@ -33,26 +28,18 @@ public static function valid(): ResultInterface
3328
}
3429

3530
/**
36-
* @param ErrorInterface[] $errors
37-
*
38-
* @return ResultInterface
31+
* @param array<ErrorInterface> $errors
3932
*/
4033
public static function invalid(array $errors): ResultInterface
4134
{
4235
return new self(false, $errors);
4336
}
4437

45-
/**
46-
* @inheritdoc
47-
*/
4838
public function isValid(): bool
4939
{
5040
return $this->valid;
5141
}
5242

53-
/**
54-
* @inheritdoc
55-
*/
5643
public function getErrors(): array
5744
{
5845
return $this->errors;

src/ResultInterface.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck;
46

57
/**
6-
*
78
* @package Cubicl\StructureCheck
89
*/
910
interface ResultInterface
@@ -16,7 +17,7 @@ public function isValid(): bool;
1617
/**
1718
* Returns a list of errors. If no error occurred, it will return an empty array.
1819
*
19-
* @return ErrorInterface[]
20+
* @return array<ErrorInterface>
2021
*/
2122
public function getErrors(): array;
2223
}

src/Type/AnyType.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cubicl\StructureCheck\Type;
46

57
use Cubicl\StructureCheck\Result;
68
use Cubicl\StructureCheck\ResultInterface;
79

810
class AnyType implements TypeInterface
911
{
10-
/**
11-
* @inheritdoc
12-
*/
1312
public function check(string $key, $value): ResultInterface
1413
{
1514
return Result::valid();

0 commit comments

Comments
 (0)