mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 11:14:05 +00:00
General code cleanup (#28)
* Add .idea folder to .gitignore * Remove useless concatenation * Add phpunit cache directory to .gitignore * Use iterable type instead of unnecessary checks * Remove unnecessary null coalescing If the return value is `null`, it will return `null` anyway. If the method doesn't exist, it will throw an `Error` because of the undefined method. * Add typehint * Merge meta properties in one go instead of in a loop * Simplify control flow * Use non-deprecated phpstan configuration value * Add missing types * Fix style with php-cs-fixer * Add tests that satisfy the ArrayIterator branch * Use is() for comparison in in() * from(int|string), tryFrom(int|string) --------- Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
6a0399823f
commit
df3681965c
20 changed files with 52 additions and 38 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Enums\Tests\PHPStan\InvokableCases;
|
||||
|
||||
use PHPStan\Analyser\OutOfClassScope;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use ArchTech\Enums\Tests\PHPStan\InvokableCases\InvokableCasesTestCase;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\StringType;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use ArchTech\Enums\{Comparable, InvokableCases, Options, Names, Values, From, Metadata};
|
||||
use ArchTech\Enums\Meta\Meta;
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
test('the is method checks for equality', function () {
|
||||
expect(Status::PENDING->is(Status::PENDING))->toBeTrue();
|
||||
expect(Status::PENDING->is(Status::DONE))->toBeFalse();
|
||||
|
|
@ -23,6 +25,11 @@ it('the in method checks for presence in an array', function () {
|
|||
expect(Status::PENDING->in([Status::PENDING, Status::DONE]))->toBeTrue();
|
||||
expect(Role::ADMIN->in([Role::ADMIN]))->toBeTrue();
|
||||
|
||||
$iterator = new ArrayIterator([Status::PENDING, Status::DONE]);
|
||||
expect(Status::PENDING->in($iterator))->toBeTrue();
|
||||
expect(Status::DONE->in($iterator))->toBeTrue();
|
||||
expect(Status::PENDING->in(new ArrayIterator([Role::ADMIN, Role::GUEST])))->toBeFalse();
|
||||
|
||||
expect(Status::PENDING->in([Status::DONE]))->toBeFalse();
|
||||
expect(Status::PENDING->in([Role::ADMIN, Role::GUEST]))->toBeFalse();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
it('does not override the default BackedEnum from method')
|
||||
->expect(Status::from(0))
|
||||
->toBe(Status::PENDING);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use ArchTech\Enums\Exceptions\UndefinedCaseError;
|
||||
|
||||
it('can be used as a static method with backed enums', function () {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
test('pure enums can have metadata on cases', function () {
|
||||
expect(Role::ADMIN->color())->toBe('indigo');
|
||||
expect(Role::GUEST->color())->toBe('gray');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
it('can return an array of case names from backed enums')
|
||||
->expect(Status::names())
|
||||
->toBe(['PENDING', 'DONE']);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
it('can return an associative array of options from a backed enum')
|
||||
->expect(Status::options())->toBe([
|
||||
'PENDING' => 0,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use ArchTech\Enums\Meta\Meta;
|
||||
use ArchTech\Enums\Meta\MetaProperty;
|
||||
use ArchTech\Enums\Metadata;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
it('can return an array of case values from a backed enum')
|
||||
->expect(Status::values())
|
||||
->toBe([0, 1]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ArchTech\Enums\Tests;
|
||||
|
||||
use Orchestra\Testbench\TestCase as TestbenchTestCase;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue