From fcde4ea045ca24083a315057f7491dcbc2074b75 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 22 Nov 2022 13:39:43 +0100 Subject: [PATCH] Rename class PublicationField to PublicationFieldType --- .../Actions/CreatesNewPublicationFile.php | 6 ++--- ...tionField.php => PublicationFieldType.php} | 2 +- .../Publications/Models/PublicationType.php | 4 ++-- .../tests/Feature/PublicationFieldTest.php | 22 +++++++++---------- .../tests/Feature/PublicationTypeTest.php | 6 ++--- 5 files changed, 20 insertions(+), 20 deletions(-) rename packages/framework/src/Framework/Features/Publications/Models/{PublicationField.php => PublicationFieldType.php} (96%) diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php index 8544bf9e052..bf483bb6940 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationFile.php @@ -6,7 +6,7 @@ use Hyde\Framework\Actions\Interfaces\CreateActionInterface; use Hyde\Framework\Concerns\InteractsWithDirectories; -use Hyde\Framework\Features\Publications\Models\PublicationField; +use Hyde\Framework\Features\Publications\Models\PublicationFieldType; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Framework\Features\Publications\PublicationHelper; use Hyde\Hyde; @@ -41,7 +41,7 @@ public function create(): void { $dir = ($this->pubType->getDirectory()); $canonicalFieldName = $this->pubType->canonicalField; - $canonicalFieldDefinition = $this->pubType->getFields()->filter(fn (PublicationField $field): bool => $field->name === $canonicalFieldName)->first() ?? throw new RuntimeException("Could not find field definition for '$canonicalFieldName'"); + $canonicalFieldDefinition = $this->pubType->getFields()->filter(fn (PublicationFieldType $field): bool => $field->name === $canonicalFieldName)->first() ?? throw new RuntimeException("Could not find field definition for '$canonicalFieldName'"); $canonicalValue = $canonicalFieldDefinition->type !== 'array' ? $this->fieldData->{$canonicalFieldName} : $this->fieldData->{$canonicalFieldName}[0]; $canonicalStr = Str::of($canonicalValue)->substr(0, 64); $slug = $canonicalStr->slug()->toString(); @@ -55,7 +55,7 @@ public function create(): void $output = "---\n"; $output .= "__createdAt: $now\n"; foreach ($this->fieldData as $name => $value) { - /** @var PublicationField $fieldDefinition */ + /** @var PublicationFieldType $fieldDefinition */ $fieldDefinition = $this->pubType->getFields()->where('name', $name)->firstOrFail(); if ($fieldDefinition->type == 'text') { diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationField.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationFieldType.php similarity index 96% rename from packages/framework/src/Framework/Features/Publications/Models/PublicationField.php rename to packages/framework/src/Framework/Features/Publications/Models/PublicationFieldType.php index ef0436ebe31..e59a7438d82 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationField.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationFieldType.php @@ -13,7 +13,7 @@ /** * @see \Hyde\Framework\Testing\Feature\PublicationFieldTest */ -class PublicationField implements JsonSerializable, Arrayable +class PublicationFieldType implements JsonSerializable, Arrayable { use JsonSerializesArrayable; diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 85ea8e372ff..7e2e04d0826 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -107,11 +107,11 @@ public function getDirectory(): string return $this->directory; } - /** @return \Illuminate\Support\Collection */ + /** @return \Illuminate\Support\Collection */ public function getFields(): Collection { return collect($this->fields)->mapWithKeys(function (array $data) { - return [$data['name'] => new PublicationField(...$data)]; + return [$data['name'] => new PublicationFieldType(...$data)]; }); } diff --git a/packages/framework/tests/Feature/PublicationFieldTest.php b/packages/framework/tests/Feature/PublicationFieldTest.php index f40214758ab..34ce5aac8fb 100644 --- a/packages/framework/tests/Feature/PublicationFieldTest.php +++ b/packages/framework/tests/Feature/PublicationFieldTest.php @@ -4,19 +4,19 @@ namespace Hyde\Framework\Testing\Feature; -use Hyde\Framework\Features\Publications\Models\PublicationField; +use Hyde\Framework\Features\Publications\Models\PublicationFieldType; use Hyde\Testing\TestCase; use InvalidArgumentException; /** - * @covers \Hyde\Framework\Features\Publications\Models\PublicationField + * @covers \Hyde\Framework\Features\Publications\Models\PublicationFieldType */ class PublicationFieldTest extends TestCase { public function test_can_instantiate_class() { $field = $this->makeField(); - $this->assertInstanceOf(PublicationField::class, $field); + $this->assertInstanceOf(PublicationFieldType::class, $field); $this->assertSame('string', $field->type); $this->assertSame('test', $field->name); @@ -41,7 +41,7 @@ public function test_can_encode_field_as_json() public function test_range_values_can_be_null() { - $field = new PublicationField('string', 'test', null, null); + $field = new PublicationFieldType('string', 'test', null, null); $this->assertNull($field->min); $this->assertNull($field->max); } @@ -51,12 +51,12 @@ public function test_max_value_cannot_be_less_than_min_value() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("The 'max' value cannot be less than the 'min' value."); - new PublicationField('string', 'test', 10, 1); + new PublicationFieldType('string', 'test', 10, 1); } public function test_integers_can_be_added_as_strings() { - $field = new PublicationField('string', 'test', 1, '10'); + $field = new PublicationFieldType('string', 'test', 1, '10'); $this->assertSame(1, $field->min); $this->assertSame(10, $field->max); } @@ -73,7 +73,7 @@ public function test_types_constant() 'array', 'text', 'image', - ], PublicationField::TYPES); + ], PublicationFieldType::TYPES); } public function test_type_must_be_valid() @@ -81,12 +81,12 @@ public function test_type_must_be_valid() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("The type 'invalid' is not a valid type. Valid types are: string, boolean, integer, float, datetime, url, array, text, image."); - new PublicationField('invalid', 'test', 1, 10); + new PublicationFieldType('invalid', 'test', 1, 10); } public function test_type_input_is_case_insensitive() { - $field = new PublicationField('STRING', 'test', 1, 10); + $field = new PublicationFieldType('STRING', 'test', 1, 10); $this->assertSame('string', $field->type); } @@ -95,8 +95,8 @@ public function test_validate_input_against_rules() $this->markTestIncomplete('TODO: Implement this method.'); } - protected function makeField(): PublicationField + protected function makeField(): PublicationFieldType { - return new PublicationField('string', 'test', 1, 10); + return new PublicationFieldType('string', 'test', 1, 10); } } diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index b031df2a2f5..c280fffddb7 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -5,7 +5,7 @@ namespace Hyde\Framework\Testing\Feature; use function array_merge; -use Hyde\Framework\Features\Publications\Models\PublicationField; +use Hyde\Framework\Features\Publications\Models\PublicationFieldType; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Testing\TestCase; @@ -99,9 +99,9 @@ public function test_get_fields_method_returns_collection_of_field_objects() $collection = $publicationType->getFields(); $this->assertCount(1, $collection); $this->assertInstanceOf(Collection::class, $collection); - $this->assertInstanceOf(PublicationField::class, $collection->first()); + $this->assertInstanceOf(PublicationFieldType::class, $collection->first()); $this->assertEquals(new Collection([ - 'test' => new PublicationField('string', 'test', 0, 128), + 'test' => new PublicationFieldType('string', 'test', 0, 128), ]), $collection); }