Skip to content

Commit 6d248da

Browse files
authored
22 datetime error (#24)
* [#22] Add PHP 7.4 for testing environment * [#22] Add better type hints
1 parent 528c054 commit 6d248da

25 files changed

+63
-112
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
vendor
33
composer.lock
4+
.phpunit.result.cache

Diff for: .travis.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ language: php
33

44
matrix:
55
include:
6-
- php: 7.1
7-
- php: 7.2
8-
- php: 7.3
6+
- php: 7.4
97
allow_failures:
108
- php: nightly
119
fast_finish: true
1210

13-
before_install:
14-
1511
install:
1612
- composer install
1713

Diff for: composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cubicl/php-structure-check",
3-
"description": "Structural check of arrays for PHP 7.1+",
3+
"description": "Structural check of arrays for PHP 7.3+",
44
"keywords": ["array", "structure", "types"],
55
"homepage": "https://github.com/cubicldev/php-structure-check",
66
"type": "library",
@@ -19,9 +19,9 @@
1919
"tests-spec": "phpspec run --no-interaction"
2020
},
2121
"require-dev": {
22-
"phpspec/phpspec": "^5.1.0",
23-
"phpunit/phpunit": "^7",
24-
"phpstan/phpstan": "^0.11.4"
22+
"phpspec/phpspec": "^6.2",
23+
"phpunit/phpunit": "^9.3",
24+
"phpstan/phpstan": "^0.12"
2525
},
2626
"autoload": {
2727
"psr-4": {

Diff for: spec/CheckerSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class CheckerSpec extends ObjectBehavior
1111
{
12-
function it_is_initializable()
12+
function it_is_initializable(): void
1313
{
1414
$this->shouldHaveType(Checker::class);
1515
}

Diff for: spec/Type/DatetimeTypeSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88

99
class DatetimeTypeSpec extends ObjectBehavior
1010
{
11-
function it_is_initializable()
11+
public function it_is_initializable(): void
1212
{
1313
$this->beConstructedWith('d-m-Y h:m:s', 'UTC');
1414
$this->shouldHaveType(DatetimeType::class);
1515
}
1616

17-
function it_should_return_valid_for_correct_values()
17+
public function it_should_return_valid_for_correct_values(): void
1818
{
1919
$this->beConstructedWith('d-m-Y h:m:s', 'Europe/Berlin');
2020

2121
$this->check('', '12-12-2012 12:12:10')->isValid()->shouldBe(true);
2222
}
2323

24-
function it_should_return_invalid_for_others()
24+
public function it_should_return_invalid_for_others(): void
2525
{
2626
$this->beConstructedWith('d-m-Y h:m:s', 'Europe/Berlin');
2727

Diff for: spec/Type/OptionalTypeSpec.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
class OptionalTypeSpec extends ObjectBehavior
1111
{
12-
function it_is_initializable(TypeInterface $childType)
12+
function it_is_initializable(TypeInterface $childType): void
1313
{
1414
$this->beConstructedWith($childType);
1515
$this->shouldHaveType(OptionalType::class);
1616
}
1717

18-
function it_should_return_the_value_from_the_child(TypeInterface $childType) {
18+
function it_should_return_the_value_from_the_child(TypeInterface $childType): void
19+
{
1920
$this->beConstructedWith($childType);
2021
$childType->check('', false)->willReturn(new Result(false, []));
2122
$this->check('', false)->isValid()->shouldBe(false);

Diff for: spec/Type/RegexTypeSpec.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
class RegexTypeSpec extends ObjectBehavior
99
{
1010

11-
function it_is_initializable()
11+
function it_is_initializable(): void
1212
{
1313
$this->beConstructedWith('/^def/');
1414

1515
$this->shouldHaveType(RegexType::class);
1616
}
1717

18-
function it_should_return_valid_for_matching_strings()
18+
function it_should_return_valid_for_matching_strings(): void
1919
{
2020
$this->beConstructedWith('/^def/');
2121

2222
$this->check('', 'definitive')->isValid()->shouldBe(true);
2323
}
2424

25-
function it_should_return_invalid_for_not_matching_strings()
25+
function it_should_return_invalid_for_not_matching_strings(): void
2626
{
2727
$this->beConstructedWith('/^def/');
2828

2929
$this->check('', 'developers')->isValid()->shouldBe(false);
3030
}
3131

32-
function it_should_return_invalid_for_others()
32+
function it_should_return_invalid_for_others(): void
3333
{
3434
$this->beConstructedWith('/^def/');
3535

Diff for: spec/Type/StringTypeSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
class StringTypeSpec extends ObjectBehavior
1010
{
11-
function it_is_initializable()
11+
function it_is_initializable(): void
1212
{
1313
$this->shouldHaveType(StringType::class);
1414
}
1515

16-
function it_should_return_valid_for_strings()
16+
function it_should_return_valid_for_strings(): void
1717
{
1818
$this->check('', '')->isValid()->shouldBe(true);
1919
$this->check('', 'fooo')->isValid()->shouldBe(true);
2020
$this->check('', 'adadsad asd a')->isValid()->shouldBe(true);
2121
}
2222

23-
function it_should_return_invalid_for_others()
23+
function it_should_return_invalid_for_others(): void
2424
{
2525
$this->check('', null)->isValid()->shouldBe(false);
2626
$this->check('', 12.3)->isValid()->shouldBe(false);

Diff for: src/Check/CountCheck.php

+7-19
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,13 @@
1010

1111
class CountCheck implements TypeInterface
1212
{
13-
/**
14-
* @var string
15-
*/
16-
private static $countErrorMessage = 'The given countable %s has not the expected count %d.';
17-
18-
/**
19-
* @var string
20-
*/
21-
private static $countableErrorMessage = 'The given value %s is not a countable';
22-
23-
/**
24-
* @var TypeInterface
25-
*/
26-
private $child;
27-
28-
/**
29-
* @var int
30-
*/
31-
private $count;
13+
private static string $countErrorMessage = 'The given countable %s has not the expected count %d.';
14+
15+
private static string $countableErrorMessage = 'The given value %s is not a countable';
16+
17+
private TypeInterface $child;
18+
19+
private int $count;
3220

3321
public function __construct(TypeInterface $child, int $count)
3422
{

Diff for: src/Error.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class Error implements ErrorInterface
66
{
7-
private $key;
7+
private string $key;
88

9-
private $message;
9+
private string $message;
1010

1111
public function __construct(string $key, string $message)
1212
{

Diff for: src/Type/AnyType.php

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
use Cubicl\StructureCheck\Result;
66
use Cubicl\StructureCheck\ResultInterface;
77

8-
/**
9-
* Class AnyType
10-
* @package Cubicl\Cubicl\StructureCheck\Type
11-
*/
128
class AnyType implements TypeInterface
139
{
1410
/**

Diff for: src/Type/BoolType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class BoolType implements TypeInterface
1010
{
11-
private static $errorMessage = 'The value %s is not a boolean.';
11+
private static string $errorMessage = 'The value %s is not a boolean.';
1212

1313
public function check(string $key, $value): ResultInterface
1414
{

Diff for: src/Type/DatetimeType.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,15 @@
77
use DateTimeZone;
88
use Cubicl\StructureCheck\Result;
99
use Cubicl\StructureCheck\ResultInterface;
10+
use JsonException;
1011

1112
class DatetimeType implements TypeInterface
1213
{
13-
/**
14-
* @var string
15-
*/
16-
private static $errorMessage = 'The value %s is not a valid datetime.';
17-
18-
/**
19-
* @var string
20-
*/
21-
private $datetimeFormat;
22-
23-
/**
24-
* @var string
25-
*/
26-
private $datetimeZone;
14+
private static string $errorMessage = 'The value %s is not a valid datetime.';
15+
16+
private string $datetimeFormat;
17+
18+
private string $datetimeZone;
2719

2820
public function __construct(string $format, string $datetimeZone)
2921
{

Diff for: src/Type/EnumType.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
use Cubicl\StructureCheck\Result;
77
use Cubicl\StructureCheck\ResultInterface;
88

9+
/**
10+
* @template T
11+
*/
912
class EnumType implements TypeInterface
1013
{
11-
/**
12-
* @var string
13-
*/
14-
private static $errorMessage = 'The value %s is not in the allowed values (%s).';
14+
private static string $errorMessage = 'The value %s is not in the allowed values (%s).';
1515

16-
/**
17-
* @var array
18-
*/
19-
private $values;
16+
/** @var array<T> */
17+
private array $values;
2018

2119
/**
22-
* EnumType constructor.
23-
*
24-
* @param array $values
20+
* @param array<T> $values
2521
*/
2622
public function __construct(array $values)
2723
{
2824
$this->values = $values;
2925
}
3026

27+
/**
28+
* @param string $key
29+
* @param T $value
30+
*
31+
* @return ResultInterface
32+
*/
3133
public function check(string $key, $value): ResultInterface
3234
{
3335
$checkResult = in_array($value, $this->values, true);

Diff for: src/Type/ExactValueType.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88

99
class ExactValueType implements TypeInterface
1010
{
11-
/**
12-
* @var string
13-
*/
14-
private static $errorMessage = 'The value %s is not the same value as %s.';
11+
private static string $errorMessage = 'The value %s is not the same value as %s.';
1512

1613
/** @var mixed */
1714
private $value;
1815

1916
/**
20-
* ExactValueType constructor.
21-
*
2217
* @param mixed $value
2318
*/
2419
public function __construct($value)

Diff for: src/Type/FloatType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class FloatType implements TypeInterface
1010
{
11-
private static $errorMessage = 'The value %s is not a float.';
11+
private static string $errorMessage = 'The value %s is not a float.';
1212

1313
public function check(string $key, $value): ResultInterface
1414
{

Diff for: src/Type/IntType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class IntType implements TypeInterface
1010
{
11-
private static $errorMessage = 'The value %s is not an integer.';
11+
private static string $errorMessage = 'The value %s is not an integer.';
1212

1313
public function check(string $key, $value): ResultInterface
1414
{

Diff for: src/Type/ListType.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
class ListType implements TypeInterface
1010
{
11-
private static $isNotAnArrayMessage = 'The given value %s is not an array.';
11+
private static string $isNotAnArrayMessage = 'The given value %s is not an array.';
1212

13-
/**
14-
* @var TypeInterface
15-
*/
16-
private $child;
13+
private TypeInterface $child;
1714

1815
public function __construct(TypeInterface $child)
1916
{

Diff for: src/Type/NullableType.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77

88
class NullableType implements TypeInterface
99
{
10-
/**
11-
* @var TypeInterface
12-
*/
13-
private $child;
10+
private TypeInterface $child;
1411

1512
public function __construct(TypeInterface $child)
1613
{

Diff for: src/Type/NumericType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class NumericType implements TypeInterface
1010
{
11-
private static $errorMessage = 'The value %s is not a numeric value.';
11+
private static string $errorMessage = 'The value %s is not a numeric value.';
1212

1313
public function check(string $key, $value): ResultInterface
1414
{

Diff for: src/Type/ObjectType.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88

99
class ObjectType implements TypeInterface
1010
{
11-
private static $missingKeyErrorMessage = 'The key "%s" does not exists';
11+
private static string $missingKeyErrorMessage = 'The key "%s" does not exists';
1212

13-
/**
14-
* @var TypeInterface[]
15-
*/
16-
private $children;
13+
/** @var TypeInterface[] */
14+
private array $children;
1715

1816
/**
19-
* ObjectType constructor.
20-
*
2117
* @param TypeInterface[] $children
2218
*/
2319
public function __construct(array $children)

Diff for: src/Type/OptionalType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class OptionalType implements TypeInterface
88
{
9-
private $child;
9+
private TypeInterface $child;
1010

1111
public function __construct(TypeInterface $child)
1212
{

0 commit comments

Comments
 (0)