Skip to content

Commit

Permalink
Fixed TypeError and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rayblair06 committed Nov 15, 2024
1 parent 0d1fc8d commit e893352
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

declare(strict_types=1);

use TypeError;
use Rayblair\ArrayType\Type;

if (!function_exists('type')) {
if (! function_exists('type')) {
/**
* Validates that the provided variable matches the expected type.
*
Expand All @@ -20,7 +19,7 @@ function type(mixed $variable, string $type): mixed
{
// Check if the variable is an object and ensure it's an instance of the expected class
if (is_object($variable)) {
if (!$variable instanceof $type) {
if (! $variable instanceof $type) {
$actualType = get_class($variable);

throw new TypeError("Expected instance of {$type}, instance of {$actualType} given.");
Expand All @@ -41,7 +40,7 @@ function type(mixed $variable, string $type): mixed
};

// If the type check fails, throw a TypeError
if (!$check) {
if (! $check) {
$actualType = gettype($variable);

throw new TypeError("Expected type {$type}, {$actualType} given.");
Expand Down
8 changes: 3 additions & 5 deletions tests/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Rayblair\ArrayType\Tests;

use stdClass;
use TypeError;
use ArgumentCountError;
use Rayblair\ArrayType\Type;
use PHPUnit\Framework\TestCase;
use Rayblair\ArrayType\Tests\Classes\FooType;
use Rayblair\ArrayType\Tests\Classes\FooArrayType;
use Rayblair\ArrayType\Type;
use stdClass;
use TypeError;

class TypeTest extends TestCase
{
Expand Down

0 comments on commit e893352

Please sign in to comment.