Skip to content

Commit fcc3fb6

Browse files
committed
Force type to be lowercase internally
1 parent 7931225 commit fcc3fb6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/framework/src/Framework/Features/Publications/Models/PublicationField.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use InvalidArgumentException;
1010
use JsonSerializable;
1111

12+
use function strtolower;
13+
1214
/**
1315
* @see \Hyde\Framework\Testing\Feature\PublicationFieldTest
1416
*/
@@ -18,9 +20,13 @@ class PublicationField implements JsonSerializable, Arrayable
1820

1921
public final const TYPES = ['string', 'boolean', 'integer', 'float', 'datetime', 'url', 'array', 'text', 'image'];
2022

21-
public function __construct(public readonly string $type, public readonly string $name, public readonly ?int $min, public readonly ?int $max)
23+
public readonly string $type;
24+
25+
public function __construct(string $type, public readonly string $name, public readonly ?int $min, public readonly ?int $max)
2226
{
23-
if (! in_array($type, self::TYPES)) {
27+
$this->type = strtolower($type);
28+
29+
if (! in_array(strtolower($type), self::TYPES)) {
2430
throw new InvalidArgumentException(sprintf("The type '$type' is not a valid type. Valid types are: %s.", implode(', ', self::TYPES)));
2531
}
2632

packages/framework/tests/Feature/PublicationFieldTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public function test_type_must_be_valid()
7777
new PublicationField('invalid', 'test', 1, 10);
7878
}
7979

80+
public function test_type_input_is_case_insensitive()
81+
{
82+
$field = new PublicationField('STRING', 'test', 1, 10);
83+
$this->assertSame('string', $field->type);
84+
}
85+
8086
public function test_validate_input_against_rules()
8187
{
8288
$this->markTestIncomplete('TODO: Implement this method.');

0 commit comments

Comments
 (0)