Skip to content

Commit

Permalink
22 datetime error (#24)
Browse files Browse the repository at this point in the history
* [#22] Add PHP 7.4 for testing environment

* [#22] Add better type hints
  • Loading branch information
1blankz7 authored Sep 25, 2020
1 parent 528c054 commit 6d248da
Show file tree
Hide file tree
Showing 25 changed files with 63 additions and 112 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
vendor
composer.lock
.phpunit.result.cache
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ language: php

matrix:
include:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
allow_failures:
- php: nightly
fast_finish: true

before_install:

install:
- composer install

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cubicl/php-structure-check",
"description": "Structural check of arrays for PHP 7.1+",
"description": "Structural check of arrays for PHP 7.3+",
"keywords": ["array", "structure", "types"],
"homepage": "https://github.com/cubicldev/php-structure-check",
"type": "library",
Expand All @@ -19,9 +19,9 @@
"tests-spec": "phpspec run --no-interaction"
},
"require-dev": {
"phpspec/phpspec": "^5.1.0",
"phpunit/phpunit": "^7",
"phpstan/phpstan": "^0.11.4"
"phpspec/phpspec": "^6.2",
"phpunit/phpunit": "^9.3",
"phpstan/phpstan": "^0.12"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion spec/CheckerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CheckerSpec extends ObjectBehavior
{
function it_is_initializable()
function it_is_initializable(): void
{
$this->shouldHaveType(Checker::class);
}
Expand Down
6 changes: 3 additions & 3 deletions spec/Type/DatetimeTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

class DatetimeTypeSpec extends ObjectBehavior
{
function it_is_initializable()
public function it_is_initializable(): void
{
$this->beConstructedWith('d-m-Y h:m:s', 'UTC');
$this->shouldHaveType(DatetimeType::class);
}

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

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

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

Expand Down
5 changes: 3 additions & 2 deletions spec/Type/OptionalTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

class OptionalTypeSpec extends ObjectBehavior
{
function it_is_initializable(TypeInterface $childType)
function it_is_initializable(TypeInterface $childType): void
{
$this->beConstructedWith($childType);
$this->shouldHaveType(OptionalType::class);
}

function it_should_return_the_value_from_the_child(TypeInterface $childType) {
function it_should_return_the_value_from_the_child(TypeInterface $childType): void
{
$this->beConstructedWith($childType);
$childType->check('', false)->willReturn(new Result(false, []));
$this->check('', false)->isValid()->shouldBe(false);
Expand Down
8 changes: 4 additions & 4 deletions spec/Type/RegexTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
class RegexTypeSpec extends ObjectBehavior
{

function it_is_initializable()
function it_is_initializable(): void
{
$this->beConstructedWith('/^def/');

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

function it_should_return_valid_for_matching_strings()
function it_should_return_valid_for_matching_strings(): void
{
$this->beConstructedWith('/^def/');

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

function it_should_return_invalid_for_not_matching_strings()
function it_should_return_invalid_for_not_matching_strings(): void
{
$this->beConstructedWith('/^def/');

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

function it_should_return_invalid_for_others()
function it_should_return_invalid_for_others(): void
{
$this->beConstructedWith('/^def/');

Expand Down
6 changes: 3 additions & 3 deletions spec/Type/StringTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

class StringTypeSpec extends ObjectBehavior
{
function it_is_initializable()
function it_is_initializable(): void
{
$this->shouldHaveType(StringType::class);
}

function it_should_return_valid_for_strings()
function it_should_return_valid_for_strings(): void
{
$this->check('', '')->isValid()->shouldBe(true);
$this->check('', 'fooo')->isValid()->shouldBe(true);
$this->check('', 'adadsad asd a')->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
function it_should_return_invalid_for_others(): void
{
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', 12.3)->isValid()->shouldBe(false);
Expand Down
26 changes: 7 additions & 19 deletions src/Check/CountCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@

class CountCheck implements TypeInterface
{
/**
* @var string
*/
private static $countErrorMessage = 'The given countable %s has not the expected count %d.';

/**
* @var string
*/
private static $countableErrorMessage = 'The given value %s is not a countable';

/**
* @var TypeInterface
*/
private $child;

/**
* @var int
*/
private $count;
private static string $countErrorMessage = 'The given countable %s has not the expected count %d.';

private static string $countableErrorMessage = 'The given value %s is not a countable';

private TypeInterface $child;

private int $count;

public function __construct(TypeInterface $child, int $count)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class Error implements ErrorInterface
{
private $key;
private string $key;

private $message;
private string $message;

public function __construct(string $key, string $message)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Type/AnyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
use Cubicl\StructureCheck\Result;
use Cubicl\StructureCheck\ResultInterface;

/**
* Class AnyType
* @package Cubicl\Cubicl\StructureCheck\Type
*/
class AnyType implements TypeInterface
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Type/BoolType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BoolType implements TypeInterface
{
private static $errorMessage = 'The value %s is not a boolean.';
private static string $errorMessage = 'The value %s is not a boolean.';

public function check(string $key, $value): ResultInterface
{
Expand Down
20 changes: 6 additions & 14 deletions src/Type/DatetimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,15 @@
use DateTimeZone;
use Cubicl\StructureCheck\Result;
use Cubicl\StructureCheck\ResultInterface;
use JsonException;

class DatetimeType implements TypeInterface
{
/**
* @var string
*/
private static $errorMessage = 'The value %s is not a valid datetime.';

/**
* @var string
*/
private $datetimeFormat;

/**
* @var string
*/
private $datetimeZone;
private static string $errorMessage = 'The value %s is not a valid datetime.';

private string $datetimeFormat;

private string $datetimeZone;

public function __construct(string $format, string $datetimeZone)
{
Expand Down
24 changes: 13 additions & 11 deletions src/Type/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
use Cubicl\StructureCheck\Result;
use Cubicl\StructureCheck\ResultInterface;

/**
* @template T
*/
class EnumType implements TypeInterface
{
/**
* @var string
*/
private static $errorMessage = 'The value %s is not in the allowed values (%s).';
private static string $errorMessage = 'The value %s is not in the allowed values (%s).';

/**
* @var array
*/
private $values;
/** @var array<T> */
private array $values;

/**
* EnumType constructor.
*
* @param array $values
* @param array<T> $values
*/
public function __construct(array $values)
{
$this->values = $values;
}

/**
* @param string $key
* @param T $value
*
* @return ResultInterface
*/
public function check(string $key, $value): ResultInterface
{
$checkResult = in_array($value, $this->values, true);
Expand Down
7 changes: 1 addition & 6 deletions src/Type/ExactValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@

class ExactValueType implements TypeInterface
{
/**
* @var string
*/
private static $errorMessage = 'The value %s is not the same value as %s.';
private static string $errorMessage = 'The value %s is not the same value as %s.';

/** @var mixed */
private $value;

/**
* ExactValueType constructor.
*
* @param mixed $value
*/
public function __construct($value)
Expand Down
2 changes: 1 addition & 1 deletion src/Type/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class FloatType implements TypeInterface
{
private static $errorMessage = 'The value %s is not a float.';
private static string $errorMessage = 'The value %s is not a float.';

public function check(string $key, $value): ResultInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Type/IntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class IntType implements TypeInterface
{
private static $errorMessage = 'The value %s is not an integer.';
private static string $errorMessage = 'The value %s is not an integer.';

public function check(string $key, $value): ResultInterface
{
Expand Down
7 changes: 2 additions & 5 deletions src/Type/ListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

class ListType implements TypeInterface
{
private static $isNotAnArrayMessage = 'The given value %s is not an array.';
private static string $isNotAnArrayMessage = 'The given value %s is not an array.';

/**
* @var TypeInterface
*/
private $child;
private TypeInterface $child;

public function __construct(TypeInterface $child)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Type/NullableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

class NullableType implements TypeInterface
{
/**
* @var TypeInterface
*/
private $child;
private TypeInterface $child;

public function __construct(TypeInterface $child)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Type/NumericType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class NumericType implements TypeInterface
{
private static $errorMessage = 'The value %s is not a numeric value.';
private static string $errorMessage = 'The value %s is not a numeric value.';

public function check(string $key, $value): ResultInterface
{
Expand Down
10 changes: 3 additions & 7 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@

class ObjectType implements TypeInterface
{
private static $missingKeyErrorMessage = 'The key "%s" does not exists';
private static string $missingKeyErrorMessage = 'The key "%s" does not exists';

/**
* @var TypeInterface[]
*/
private $children;
/** @var TypeInterface[] */
private array $children;

/**
* ObjectType constructor.
*
* @param TypeInterface[] $children
*/
public function __construct(array $children)
Expand Down
2 changes: 1 addition & 1 deletion src/Type/OptionalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class OptionalType implements TypeInterface
{
private $child;
private TypeInterface $child;

public function __construct(TypeInterface $child)
{
Expand Down
Loading

0 comments on commit 6d248da

Please sign in to comment.