diff --git a/README.md b/README.md index 4412858..4db7554 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ return [ ## Features -- [Auto-Register Custom Doctrine Types](#auto-register-custom-doctrine-types) -- [Auto-Register Carbon Doctrine Types](#auto-register-carbon-datetime-types) +- [Auto-Register Custom Doctrine Type Mappings](#auto-register-custom-doctrine-types) +- [Auto-Register Carbon Doctrine Type Mappings](#auto-register-carbon-datetime-types) ### Auto-Register Custom Doctrine Types @@ -44,12 +44,12 @@ headsnet_doctrine_tools: - 'src/Infra/Persistence/DBAL/Types' ``` -Then add the `#[CustomType]` attribute to the custom type class: +Then add the `#[DoctrineTypeMapping]` attribute to the custom type class: ```php use Doctrine\DBAL\Types\Type; -#[CustomType] +#[DoctrineTypeMapping] final class ReservationIdType extends Type { // defines "reservation_id" type @@ -59,11 +59,11 @@ final class ReservationIdType extends Type This will register a custom type based on the class name - in this case the custom column type will be called `reservation_id`. -To customise the type name, specify it in the `#[CustomType]` attribute. The following will register a type +To customise the type name, specify it in the `#[DoctrineTypeMapping]` attribute. The following will register a type called `my_reservation_id`. ```php -#[CustomType(name: 'my_reservation_id')] +#[DoctrineTypeMapping(name: 'my_reservation_id')] final class ReservationIdType extends Type { // customised name "my_reservation_id" type diff --git a/ecs.php b/ecs.php index ac76e58..b93b82b 100644 --- a/ecs.php +++ b/ecs.php @@ -4,6 +4,7 @@ use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer; +use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; @@ -16,6 +17,7 @@ $ecsConfig->skip([ BlankLineAfterOpeningTagFixer::class, NotOperatorWithSuccessorSpaceFixer::class, + MethodChainingIndentationFixer::class ]); $ecsConfig->rules([ diff --git a/src/CustomTypes/CustomType.php b/src/Attribute/DoctrineTypeMapping.php similarity index 79% rename from src/CustomTypes/CustomType.php rename to src/Attribute/DoctrineTypeMapping.php index 03faf81..6931f83 100644 --- a/src/CustomTypes/CustomType.php +++ b/src/Attribute/DoctrineTypeMapping.php @@ -1,12 +1,12 @@ rootNode() ->children() - ->arrayNode('custom_types') - ->children() - ->arrayNode('scan_dirs') - ->scalarPrototype()->end() - ->end() - ->end() - ->end() // End custom_types - ->arrayNode('carbon_types') - ->canBeDisabled() - ->children() - ->booleanNode('enabled') - ->defaultTrue()->end() - ->booleanNode('replace') - ->defaultTrue()->end() - ->end() - ->end() // End carbon_types + ->arrayNode('custom_types') + ->children() + ->arrayNode('scan_dirs') + ->scalarPrototype()->end() + ->end() + ->end() + ->end() // End custom_types + ->arrayNode('carbon_types') + ->canBeDisabled() + ->children() + ->booleanNode('replace')->defaultTrue()->end() + ->end() + ->end() // End carbon_types ; } @@ -54,11 +51,11 @@ public function build(ContainerBuilder $container): void parent::build($container); $container->addCompilerPass( - new RegisterDoctrineTypesCompilerPass() + new DoctrineTypeMappingsCompilerPass() ); $container->addCompilerPass( - new RegisterCarbonTypesCompilerPass() + new CarbonTypeMappingsCompilerPass() ); } } diff --git a/src/CarbonTypes/RegisterCarbonTypesCompilerPass.php b/src/Mapping/CarbonTypeMappingsCompilerPass.php similarity index 93% rename from src/CarbonTypes/RegisterCarbonTypesCompilerPass.php rename to src/Mapping/CarbonTypeMappingsCompilerPass.php index b84cc6d..bdc7cff 100644 --- a/src/CarbonTypes/RegisterCarbonTypesCompilerPass.php +++ b/src/Mapping/CarbonTypeMappingsCompilerPass.php @@ -1,7 +1,7 @@ "carbon_date" */ -final class CustomTypeNamer +final class DoctrineTypeMappingNamer { /** * @param ReflectionClass $reflection */ public static function getTypeName(ReflectionClass $reflection): string { - $attribute = $reflection->getAttributes(CustomType::class)[0]; + $attribute = $reflection->getAttributes(DoctrineTypeMapping::class)[0]; $attributeArgs = $attribute->getArguments(); diff --git a/src/CustomTypes/RegisterDoctrineTypesCompilerPass.php b/src/Mapping/DoctrineTypeMappingsCompilerPass.php similarity index 87% rename from src/CustomTypes/RegisterDoctrineTypesCompilerPass.php rename to src/Mapping/DoctrineTypeMappingsCompilerPass.php index e564b99..d549dc9 100644 --- a/src/CustomTypes/RegisterDoctrineTypesCompilerPass.php +++ b/src/Mapping/DoctrineTypeMappingsCompilerPass.php @@ -1,10 +1,11 @@ getAttributes(CustomType::class)) { + if ($reflection->getAttributes(DoctrineTypeMapping::class)) { yield [ - 'name' => CustomTypeNamer::getTypeName($reflection), + 'name' => DoctrineTypeMappingNamer::getTypeName($reflection), 'class' => $className, ]; } diff --git a/tests/CustomTypes/CustomTypeTest.php b/tests/Attribute/DoctrineTypeMappingTest.php similarity index 56% rename from tests/CustomTypes/CustomTypeTest.php rename to tests/Attribute/DoctrineTypeMappingTest.php index bf07ef8..0b396f2 100644 --- a/tests/CustomTypes/CustomTypeTest.php +++ b/tests/Attribute/DoctrineTypeMappingTest.php @@ -1,20 +1,20 @@ assertEquals('custom_name', $sut->name); } @@ -22,7 +22,7 @@ public function name_can_be_specified(): void #[Test] public function name_is_normalised(): void { - $sut = new CustomType('some-custom Name'); + $sut = new DoctrineTypeMapping('some-custom Name'); $this->assertEquals('some_custom_name', $sut->name); } diff --git a/tests/HeadsnetDoctrineToolsBundleTest.php b/tests/HeadsnetDoctrineToolsBundleTest.php index 8c4b8ff..6af4b96 100644 --- a/tests/HeadsnetDoctrineToolsBundleTest.php +++ b/tests/HeadsnetDoctrineToolsBundleTest.php @@ -3,9 +3,9 @@ namespace Headsnet\DoctrineToolsBundle\Tests; -use Headsnet\DoctrineToolsBundle\CarbonTypes\RegisterCarbonTypesCompilerPass; -use Headsnet\DoctrineToolsBundle\CustomTypes\RegisterDoctrineTypesCompilerPass; use Headsnet\DoctrineToolsBundle\HeadsnetDoctrineToolsBundle; +use Headsnet\DoctrineToolsBundle\Mapping\CarbonTypeMappingsCompilerPass; +use Headsnet\DoctrineToolsBundle\Mapping\DoctrineTypeMappingsCompilerPass; use Nyholm\BundleTest\TestKernel; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; @@ -13,8 +13,8 @@ use Symfony\Component\HttpKernel\KernelInterface; #[CoversClass(HeadsnetDoctrineToolsBundle::class)] -#[CoversClass(RegisterCarbonTypesCompilerPass::class)] -#[CoversClass(RegisterDoctrineTypesCompilerPass::class)] +#[CoversClass(CarbonTypeMappingsCompilerPass::class)] +#[CoversClass(DoctrineTypeMappingsCompilerPass::class)] class HeadsnetDoctrineToolsBundleTest extends KernelTestCase { protected static function getKernelClass(): string diff --git a/tests/CarbonTypes/RegisterCarbonTypesCompilerPassTest.php b/tests/Mapping/CarbonTypeMappingsCompilerPassTest.php similarity index 85% rename from tests/CarbonTypes/RegisterCarbonTypesCompilerPassTest.php rename to tests/Mapping/CarbonTypeMappingsCompilerPassTest.php index 04aee43..777d809 100644 --- a/tests/CarbonTypes/RegisterCarbonTypesCompilerPassTest.php +++ b/tests/Mapping/CarbonTypeMappingsCompilerPassTest.php @@ -1,18 +1,18 @@ setParameter('doctrine.dbal.connection_factory.types', []); $container->setParameter('headsnet_doctrine_tools.carbon_types.enabled', true); $container->setParameter('headsnet_doctrine_tools.carbon_types.replace', true); - $sut = new RegisterCarbonTypesCompilerPass(); + $sut = new CarbonTypeMappingsCompilerPass(); $sut->process($container); @@ -44,7 +44,7 @@ public function carbon_types_are_registered_separately(): void $container->setParameter('doctrine.dbal.connection_factory.types', []); $container->setParameter('headsnet_doctrine_tools.carbon_types.enabled', true); $container->setParameter('headsnet_doctrine_tools.carbon_types.replace', false); - $sut = new RegisterCarbonTypesCompilerPass(); + $sut = new CarbonTypeMappingsCompilerPass(); $sut->process($container); @@ -66,7 +66,7 @@ public function if_disabled_then_register_nothing(): void $container = new ContainerBuilder(); $container->setParameter('doctrine.dbal.connection_factory.types', []); $container->setParameter('headsnet_doctrine_tools.carbon_types.enabled', false); - $sut = new RegisterCarbonTypesCompilerPass(); + $sut = new CarbonTypeMappingsCompilerPass(); $sut->process($container); diff --git a/tests/CustomTypes/CustomTypeNamerTest.php b/tests/Mapping/DoctrineTypeMappingNamerTest.php similarity index 53% rename from tests/CustomTypes/CustomTypeNamerTest.php rename to tests/Mapping/DoctrineTypeMappingNamerTest.php index bb11d53..ab13e69 100644 --- a/tests/CustomTypes/CustomTypeNamerTest.php +++ b/tests/Mapping/DoctrineTypeMappingNamerTest.php @@ -1,25 +1,25 @@ assertEquals('dummy_custom', $sut); } @@ -29,7 +29,7 @@ public function name_can_be_specified(): void { $reflection = new ReflectionClass(new DummyCustomTypeWithName()); - $sut = CustomTypeNamer::getTypeName($reflection); + $sut = DoctrineTypeMappingNamer::getTypeName($reflection); $this->assertEquals('my_custom_name', $sut); } diff --git a/tests/CustomTypes/RegisterDoctrineTypesCompilerPassTest.php b/tests/Mapping/DoctrineTypeMappingsCompilerPassTest.php similarity index 74% rename from tests/CustomTypes/RegisterDoctrineTypesCompilerPassTest.php rename to tests/Mapping/DoctrineTypeMappingsCompilerPassTest.php index 9b34bce..4f15820 100644 --- a/tests/CustomTypes/RegisterDoctrineTypesCompilerPassTest.php +++ b/tests/Mapping/DoctrineTypeMappingsCompilerPassTest.php @@ -1,20 +1,20 @@ setParameter('headsnet_doctrine_tools.custom_types.scan_dirs', [ __DIR__ . '/Fixtures', ]); - $sut = new RegisterDoctrineTypesCompilerPass(); + $sut = new DoctrineTypeMappingsCompilerPass(); $sut->process($container); @@ -52,7 +52,7 @@ public function ignores_types_that_are_manually_registered(): void $container->setParameter('headsnet_doctrine_tools.custom_types.scan_dirs', [ __DIR__ . '/Fixtures', ]); - $sut = new RegisterDoctrineTypesCompilerPass(); + $sut = new DoctrineTypeMappingsCompilerPass(); $sut->process($container); diff --git a/tests/CustomTypes/Fixtures/AbstractCustomType.php b/tests/Mapping/Fixtures/AbstractCustomType.php similarity index 65% rename from tests/CustomTypes/Fixtures/AbstractCustomType.php rename to tests/Mapping/Fixtures/AbstractCustomType.php index cb18e56..d8b64aa 100644 --- a/tests/CustomTypes/Fixtures/AbstractCustomType.php +++ b/tests/Mapping/Fixtures/AbstractCustomType.php @@ -1,13 +1,13 @@