Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:spatie/typed
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Jul 23, 2018
2 parents 6fb0753 + d5351a3 commit 40e4ac8
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($type)
$this->set($type);
}

public function set(array $data): Collection
public function set(array $data): self
{
foreach ($data as $item) {
$this[] = $item;
Expand Down
2 changes: 1 addition & 1 deletion src/Excpetions/InferredTypeError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class InferredTypeError extends TypeError
{
public static function cannotInferType(string $name): InferredTypeError
public static function cannotInferType(string $name): self
{
return new self("Cannot infer type {$name}.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Excpetions/UninitialisedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class UninitialisedError extends TypeError
{
public static function forField(string $name): UninitialisedError
public static function forField(string $name): self
{
return new self("Field {$name} was uninitialised.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Spatie\Typed;

use ArrayAccess;
use Spatie\Typed\Excpetions\UninitialisedError;
use Spatie\Typed\Excpetions\WrongType;
use Spatie\Typed\Excpetions\UninitialisedError;

class Struct implements ArrayAccess
{
Expand All @@ -21,7 +21,7 @@ class Struct implements ArrayAccess
public function __construct(array $types)
{
foreach ($types as $field => $type) {
if (!$type instanceof Type) {
if (! $type instanceof Type) {
$this->values[$field] = $type;

$type = T::infer($type);
Expand Down
4 changes: 2 additions & 2 deletions src/T.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Spatie\Typed;

use Spatie\Typed\Excpetions\InferredTypeError;
use Spatie\Typed\Types\NullType;
use Spatie\Typed\Types\ArrayType;
use Spatie\Typed\Types\FloatType;
Expand All @@ -15,6 +14,7 @@
use Spatie\Typed\Types\IntegerType;
use Spatie\Typed\Types\CallableType;
use Spatie\Typed\Types\CollectionType;
use Spatie\Typed\Excpetions\InferredTypeError;

class T
{
Expand Down Expand Up @@ -99,6 +99,6 @@ public static function infer($value): Type
throw InferredTypeError::cannotInferType($type);
}

return forward_static_call(self::class . '::' . $type);
return forward_static_call(self::class.'::'.$type);
}
}
5 changes: 2 additions & 3 deletions src/Tuple.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

use Iterator;
use ArrayAccess;
use Spatie\Typed\Excpetions\UninitialisedError;
use Spatie\Typed\Excpetions\UninitialisedValue;
use Spatie\Typed\Excpetions\WrongType;
use Spatie\Typed\Excpetions\UninitialisedError;

class Tuple implements ArrayAccess
{
Expand All @@ -23,7 +22,7 @@ class Tuple implements ArrayAccess
public function __construct(...$types)
{
foreach ($types as $field => $type) {
if (!$type instanceof Type) {
if (! $type instanceof Type) {
$this->values[$field] = $type;

$type = T::infer($type);
Expand Down
2 changes: 1 addition & 1 deletion src/Types/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use TypeError;
use Spatie\Typed\Type;
use Spatie\Typed\Excpetions\WrongType;
use Spatie\Typed\ValidatesType;
use Spatie\Typed\Excpetions\WrongType;

class UnionType implements Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/ValidatesType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Spatie\Typed;

use Spatie\Typed\Excpetions\WrongType;
use TypeError;
use Spatie\Typed\Excpetions\WrongType;

trait ValidatesType
{
Expand Down
6 changes: 3 additions & 3 deletions tests/StructTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Spatie\Typed\Tests;

use Spatie\Typed\Excpetions\UninitialisedError;
use Spatie\Typed\Tests\Extra\Post;
use Spatie\Typed\Excpetions\WrongType;
use TypeError;
use Spatie\Typed\T;
use Spatie\Typed\Struct;
use Spatie\Typed\Tests\Extra\Post;
use Spatie\Typed\Tests\Extra\Wrong;
use Spatie\Typed\Excpetions\WrongType;
use Spatie\Typed\Excpetions\UninitialisedError;

class StructTest extends TestCase
{
Expand Down
3 changes: 1 addition & 2 deletions tests/TupleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Spatie\Typed\Tests;

use Spatie\Typed\Excpetions\InferredTypeError;
use Spatie\Typed\Excpetions\UninitialisedError;
use Spatie\Typed\T;
use Spatie\Typed\Tuple;
use Spatie\Typed\Tests\Extra\Post;
Expand All @@ -14,6 +12,7 @@
use Spatie\Typed\Types\BooleanType;
use Spatie\Typed\Types\IntegerType;
use Spatie\Typed\Excpetions\WrongType;
use Spatie\Typed\Excpetions\UninitialisedError;

class TupleTest extends TestCase
{
Expand Down
8 changes: 4 additions & 4 deletions tests/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Spatie\Typed\Tests;

use Spatie\Typed\Excpetions\InferredTypeError;
use Spatie\Typed\Type;
use TypeError;
use Spatie\Typed\T;
use Spatie\Typed\Type;
use Spatie\Typed\Collection;
use Spatie\Typed\Types\ArrayType;
use Spatie\Typed\Types\FloatType;
Expand All @@ -19,6 +18,7 @@
use Spatie\Typed\Types\IntegerType;
use Spatie\Typed\Types\CallableType;
use Spatie\Typed\Types\CollectionType;
use Spatie\Typed\Excpetions\InferredTypeError;

class TypeTest extends TestCase
{
Expand Down Expand Up @@ -48,7 +48,6 @@ public function wrong_types_throw_type_errors($type, $value)
$collection[] = $value;
}


/** @test */
public function unknown_types_cannot_be_inferred()
{
Expand Down Expand Up @@ -107,7 +106,8 @@ public function inferredProvider()
[new Post(), T::generic(Post::class)],
[[], T::array()],
[true, T::boolean()],
[function () {}, T::callable()],
[function () {
}, T::callable()],
];
}
}

0 comments on commit 40e4ac8

Please sign in to comment.