Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f7ed1a0

Browse files
committedJan 8, 2025
Added constant and methods.
1 parent 2233503 commit f7ed1a0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
 

‎Src/Enum/Argument.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,27 @@ enum Argument: string {
2929
self::Position->value => self::Position,
3030
);
3131

32+
public const TYPES = array(
33+
self::Reference->value => 'bool',
34+
self::Nullable->value => 'bool',
35+
self::Variadic->value => 'bool',
36+
self::Promoted->value => 'bool',
37+
self::Position->value => 'int',
38+
self::Default->value => 'mixed',
39+
self::Type->value => '?string',
40+
self::Name->value => 'string',
41+
);
42+
3243
public function isIntractable(): bool {
3344
return ! isset( self::NON_INTRACTABLE[ $this->value ] );
3445
}
46+
47+
public function type(): string {
48+
return self::TYPES[ $this->value ];
49+
}
50+
51+
/** @return string[] */
52+
public static function casesToString(): array {
53+
return array_column( self::cases(), column_key: 'value' );
54+
}
3555
}

‎Tests/ArgumentTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use PHPUnit\Framework\TestCase;
77
use PHPUnit\Framework\Attributes\Test;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89
use TheWebSolver\Codegarage\Generator\Enum\Argument;
910

1011
class ArgumentTest extends TestCase {
@@ -18,4 +19,24 @@ public function itReturnsTrueIfArgumentCaseIsIntractable(): void {
1819
}
1920
}
2021
}
22+
23+
#[Test]
24+
#[DataProvider( 'provideArgumentCaseWithItsType' )]
25+
public function isReturnsArgumentCaseExpectedDataType( Argument $arg, string $expectedType ): void {
26+
$this->assertSame( $expectedType, $arg->type() );
27+
$this->assertContains( $arg->value, Argument::casesToString() );
28+
}
29+
30+
public static function provideArgumentCaseWithItsType(): array {
31+
return array(
32+
array( Argument::Reference, 'bool' ),
33+
array( Argument::Nullable, 'bool' ),
34+
array( Argument::Variadic, 'bool' ),
35+
array( Argument::Promoted, 'bool' ),
36+
array( Argument::Position, 'int' ),
37+
array( Argument::Default, 'mixed' ),
38+
array( Argument::Type, '?string' ),
39+
array( Argument::Name, 'string' ),
40+
);
41+
}
2142
}

0 commit comments

Comments
 (0)
Please sign in to comment.