Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Aug 15, 2024
1 parent 206d876 commit f9cdd45
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Classes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function call($class, string $method, array $args = [], bool $static = false)
return $classMethod->invoke($class, ...array_values($args));
}

return $classMethod->invoke($static ? null : new $class(), ...array_values($args));
return $classMethod->invoke($static ? null : new $class, ...array_values($args));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Numbers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function short_number(int|float $value): string
}

$suffix = match (true) {
$count >= 3 && $count < 6 => "K",
$count >= 6 => "M",
default => ""
$count >= 3 && $count < 6 => 'K',
$count >= 6 => 'M',
default => ''
};

return $iteratorValue . $suffix;
return $iteratorValue.$suffix;
}
4 changes: 2 additions & 2 deletions src/Strings/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function is_json(mixed $value): bool

if (
! is_string($value)
|| (null === \json_decode($value, false, 512, JSON_UNESCAPED_UNICODE)
&& JSON_ERROR_NONE !== \json_last_error())
|| (\json_decode($value, false, 512, JSON_UNESCAPED_UNICODE) === null
&& \json_last_error() !== JSON_ERROR_NONE)
) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* This method does require the package "symfony/http-foundation".
*/
function parse_http_query(string $query = null): array
function parse_http_query(?string $query = null): array
{
$query ??= $_SERVER['QUERY_STRING'] ?? '';

Expand Down
31 changes: 16 additions & 15 deletions tests/ClassesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

use Exception;
use Illuminate\Database\Eloquent\Concerns\HasAttributes;
use function OpenSoutheners\ExtendedPhp\Classes\call;
use function OpenSoutheners\ExtendedPhp\Classes\call_static;
use function OpenSoutheners\ExtendedPhp\Classes\class_implement;
use function OpenSoutheners\ExtendedPhp\Classes\class_namespace;
use function OpenSoutheners\ExtendedPhp\Classes\class_use;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyClass;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyTrait;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyInterface;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyOtherClass;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyTrait;
use PHPUnit\Framework\TestCase;
use ReflectionException;

use function OpenSoutheners\ExtendedPhp\Classes\call;
use function OpenSoutheners\ExtendedPhp\Classes\call_static;
use function OpenSoutheners\ExtendedPhp\Classes\class_implement;
use function OpenSoutheners\ExtendedPhp\Classes\class_namespace;
use function OpenSoutheners\ExtendedPhp\Classes\class_use;

class ClassesTest extends TestCase
{
public function test_class_namespace(): void
Expand All @@ -27,22 +28,22 @@ public function test_class_namespace(): void

public function test_class_implement(): void
{
$this->assertTrue(class_implement(new MyClass(), MyInterface::class));
$this->assertTrue(class_implement(new MyClass, MyInterface::class));
$this->assertTrue(class_implement(MyClass::class, MyInterface::class));
$this->assertFalse(class_implement(new MyClass(), Exception::class));
$this->assertFalse(class_implement(new MyClass, Exception::class));
$this->assertFalse(class_implement(MyClass::class, MyTrait::class));
$this->assertFalse(class_implement(MyClass::class, 'This/Does/Not/Exists'));
}

public function test_class_use(): void
{
$this->assertTrue(class_use(new MyClass(), MyTrait::class, true));
$this->assertTrue(class_use(new MyClass, MyTrait::class, true));
$this->assertTrue(class_use(MyOtherClass::class, MyTrait::class, true));
$this->assertFalse(class_use(MyOtherClass::class, MyTrait::class));
$this->assertFalse(class_use(MyClass::class, Exception::class));
$this->assertFalse(class_use(new MyClass(), Exception::class, true));
$this->assertFalse(class_use(new MyClass, Exception::class, true));
$this->assertFalse(class_use(MyClass::class, HasAttributes::class));
$this->assertFalse(class_use(new MyClass(), HasAttributes::class));
$this->assertFalse(class_use(new MyClass, HasAttributes::class));
$this->assertFalse(class_use(MyClass::class, 'This/Does/Not/Exists'));
}

Expand All @@ -54,13 +55,13 @@ public function test_call()
];

$this->assertTrue(call(MyClass::class, 'method'));
$this->assertTrue(call(new MyClass(), 'method'));
$this->assertTrue(call(new MyClass, 'method'));
$this->assertEquals(call(MyClass::class, 'methodWithArgs', $args), $args);
$this->assertEquals(call(new MyClass(), 'methodWithArgs', $args), $args);
$this->assertEquals(call(new MyClass, 'methodWithArgs', $args), $args);
$this->assertTrue(call_static(MyClass::class, 'staticMethod'));
$this->assertTrue(call_static(new MyClass(), 'staticMethod'));
$this->assertTrue(call_static(new MyClass, 'staticMethod'));
$this->assertEquals(call_static(MyClass::class, 'staticMethodWithArgs', $args), $args);
$this->assertEquals(call_static(new MyClass(), 'staticMethodWithArgs', $args), $args);
$this->assertEquals(call_static(new MyClass, 'staticMethodWithArgs', $args), $args);
}

public function test_call_static_method_as_non_static_throws_exception()
Expand Down
13 changes: 7 additions & 6 deletions tests/EnumsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
namespace OpenSoutheners\ExtendedPhp\Tests;

use Exception;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyBackedEnum;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyEnum;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyTrait;
use PHPUnit\Framework\TestCase;
use stdClass;

use function OpenSoutheners\ExtendedPhp\Enums\enum_is_backed;
use function OpenSoutheners\ExtendedPhp\Enums\enum_to_array;
use function OpenSoutheners\ExtendedPhp\Enums\enum_values;
use function OpenSoutheners\ExtendedPhp\Enums\get_enum_class;
use function OpenSoutheners\ExtendedPhp\Enums\has_case;
use function OpenSoutheners\ExtendedPhp\Enums\is_enum;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyBackedEnum;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyTrait;
use OpenSoutheners\ExtendedPhp\Tests\Fixtures\MyEnum;
use PHPUnit\Framework\TestCase;
use stdClass;

/**
* @group needsPhp81
Expand All @@ -24,7 +25,7 @@ public function test_is_enum(): void
{
$this->assertTrue(is_enum(MyEnum::class));
$this->assertFalse(is_enum(MyTrait::class));
$this->assertFalse(is_enum(new stdClass()));
$this->assertFalse(is_enum(new stdClass));
$this->assertFalse(is_enum(''));
}

Expand Down
9 changes: 5 additions & 4 deletions tests/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling;
use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;
use PHPUnit\Framework\TestCase;
use Throwable;

use function OpenSoutheners\ExtendedPhp\Strings\get_email_domain;
use function OpenSoutheners\ExtendedPhp\Strings\is_json;
use function OpenSoutheners\ExtendedPhp\Strings\is_json_structure;
use PHPUnit\Framework\TestCase;
use Throwable;

class StringsTest extends TestCase
{
Expand All @@ -26,7 +27,7 @@ public function test_is_json(): void
$this->assertTrue(is_json('"hello"'));
$this->assertFalse(is_json("{\u0022foo\u0022: \u0022bar\u0022}"));
$this->assertFalse(is_json([]));
$this->assertFalse(is_json(new \stdClass()));
$this->assertFalse(is_json(new \stdClass));
$this->assertFalse(is_json(1));
};

Expand Down Expand Up @@ -57,7 +58,7 @@ public function test_is_json_structure()
$this->assertFalse(is_json_structure('"hello"'));
$this->assertFalse(is_json_structure("{\u0022foo\u0022: \u0022bar\u0022}"));
$this->assertFalse(is_json_structure([]));
$this->assertFalse(is_json_structure(new \stdClass()));
$this->assertFalse(is_json_structure(new \stdClass));
$this->assertFalse(is_json_structure(1));
}

Expand Down
3 changes: 2 additions & 1 deletion tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace OpenSoutheners\ExtendedPhp\Tests;

use PHPUnit\Framework\TestCase;

use function OpenSoutheners\ExtendedPhp\Utils\build_http_query;
use function OpenSoutheners\ExtendedPhp\Utils\parse_http_query;
use PHPUnit\Framework\TestCase;

class UtilsTest extends TestCase
{
Expand Down

0 comments on commit f9cdd45

Please sign in to comment.