From f58a2a5b85d17c084549923d4ca95bcd89742a9c Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Tue, 18 Aug 2020 19:27:25 +0200 Subject: [PATCH] refacto(model): from crudablemodel to melodiiamodel #15 Fix #15 MelodiiaModel makes a lot more sense than CrudableModelInterface. This is DX. --- CHANGELOG.md | 3 ++- .../Listener/ReorderDataToMatchCollectionListener.php | 6 +++--- src/Crud/Controller/CrudControllerTrait.php | 4 ++-- .../{CrudableModelInterface.php => MelodiiaModel.php} | 2 +- .../Listener/ReorderDataToMatchCollectionListenerTest.php | 8 ++++---- tests/Melodiia/TestFixtures/FakeMelodiiaModel.php | 4 ++-- tests/TestApplication/src/Entity/Todo.php | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) rename src/Crud/{CrudableModelInterface.php => MelodiiaModel.php} (82%) diff --git a/CHANGELOG.md b/CHANGELOG.md index be4e51d..2c97c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Huge BC Break on namespaces. You need to rename all classes used to SwagIndustries instead of Biig -- BC Break on CRUD classes. It's big changes time. So we made the security optional for crud controllers, this has a +- BC Break: on CRUD classes. It's big changes time. So we made the security optional for crud controllers, this has a consequence on their constructor +- BC Break: `CrudableModelInterface` is now `MelodiiaModel` ## [0.6.0] 2020-06-01 ### Added diff --git a/src/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListener.php b/src/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListener.php index 6d64bcb..5c75b9b 100644 --- a/src/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListener.php +++ b/src/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListener.php @@ -2,7 +2,7 @@ namespace SwagIndustries\Melodiia\Bridge\Symfony\Form\Listener; -use SwagIndustries\Melodiia\Crud\CrudableModelInterface; +use SwagIndustries\Melodiia\Crud\MelodiiaModel; use SwagIndustries\Melodiia\Exception\MelodiiaLogicException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormEvent; @@ -34,8 +34,8 @@ public function preSubmit(FormEvent $event) foreach ($form as $name => $child) { $lastCollectionIndex = $name; $item = $child->getData(); - if (!$item instanceof CrudableModelInterface) { - throw new MelodiiaLogicException(sprintf('Impossible manage the model of type "%s" inside Melodiia because it does not implement CrudableModelInterface.', get_class($item))); + if (!$item instanceof MelodiiaModel) { + throw new MelodiiaLogicException(sprintf('Impossible manage the model of type "%s" inside Melodiia because it does not implement MelodiiaModel.', get_class($item))); } $itemId = (string) $item->getId(); foreach ($data as $inputItem) { diff --git a/src/Crud/Controller/CrudControllerTrait.php b/src/Crud/Controller/CrudControllerTrait.php index f79d704..0ce8c05 100644 --- a/src/Crud/Controller/CrudControllerTrait.php +++ b/src/Crud/Controller/CrudControllerTrait.php @@ -4,8 +4,8 @@ namespace SwagIndustries\Melodiia\Crud\Controller; -use SwagIndustries\Melodiia\Crud\CrudableModelInterface; use SwagIndustries\Melodiia\Crud\CrudControllerInterface; +use SwagIndustries\Melodiia\Crud\MelodiiaModel; use SwagIndustries\Melodiia\Exception\MelodiiaLogicException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Exception\AccessDeniedException; @@ -19,7 +19,7 @@ trait CrudControllerTrait */ public function assertModelClassInvalid(string $modelClass): void { - if (empty($modelClass) || !class_exists($modelClass) || !is_subclass_of($modelClass, CrudableModelInterface::class)) { + if (empty($modelClass) || !class_exists($modelClass) || !is_subclass_of($modelClass, MelodiiaModel::class)) { throw new MelodiiaLogicException('If you use melodiia CRUD classes, you need to specify a model.'); } } diff --git a/src/Crud/CrudableModelInterface.php b/src/Crud/MelodiiaModel.php similarity index 82% rename from src/Crud/CrudableModelInterface.php rename to src/Crud/MelodiiaModel.php index c2ef81b..820b2fb 100644 --- a/src/Crud/CrudableModelInterface.php +++ b/src/Crud/MelodiiaModel.php @@ -2,7 +2,7 @@ namespace SwagIndustries\Melodiia\Crud; -interface CrudableModelInterface +interface MelodiiaModel { /** * @return string|object that have a __toString() method diff --git a/tests/Melodiia/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListenerTest.php b/tests/Melodiia/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListenerTest.php index 0663415..5e74a20 100644 --- a/tests/Melodiia/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListenerTest.php +++ b/tests/Melodiia/Bridge/Symfony/Form/Listener/ReorderDataToMatchCollectionListenerTest.php @@ -3,7 +3,7 @@ namespace SwagIndustries\Melodiia\Test\Bridge\Symfony\Form\Listener; use SwagIndustries\Melodiia\Bridge\Symfony\Form\Listener\ReorderDataToMatchCollectionListener; -use SwagIndustries\Melodiia\Crud\CrudableModelInterface; +use SwagIndustries\Melodiia\Crud\MelodiiaModel; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Event\PreSubmitEvent; @@ -61,7 +61,7 @@ protected function getForm($name = 'name', $data = null) public function testItReorderDataInputWithFormData() { $formData = [ - new class() extends \ArrayObject implements CrudableModelInterface { + new class() extends \ArrayObject implements MelodiiaModel { public function __construct() { parent::__construct(['hello' => 'yo', 'world' => 'ye']); @@ -75,7 +75,7 @@ public function getId() return 'foo'; } }, - new class() extends \ArrayObject implements CrudableModelInterface { + new class() extends \ArrayObject implements MelodiiaModel { public function __construct() { parent::__construct(['hello' => 'yoh', 'world' => 'yeh']); @@ -109,7 +109,7 @@ public function getId() public function testItRemovesDataThatDoesNotExistsAnymore() { $formData = [ - new class() extends \ArrayObject implements CrudableModelInterface { + new class() extends \ArrayObject implements MelodiiaModel { public function __construct() { parent::__construct(['hello' => 'yo', 'world' => 'ye']); diff --git a/tests/Melodiia/TestFixtures/FakeMelodiiaModel.php b/tests/Melodiia/TestFixtures/FakeMelodiiaModel.php index 85a0cd2..ec8204d 100644 --- a/tests/Melodiia/TestFixtures/FakeMelodiiaModel.php +++ b/tests/Melodiia/TestFixtures/FakeMelodiiaModel.php @@ -2,9 +2,9 @@ namespace SwagIndustries\Melodiia\Test\TestFixtures; -use SwagIndustries\Melodiia\Crud\CrudableModelInterface; +use SwagIndustries\Melodiia\Crud\MelodiiaModel; -class FakeMelodiiaModel implements CrudableModelInterface +class FakeMelodiiaModel implements MelodiiaModel { public function getId() { diff --git a/tests/TestApplication/src/Entity/Todo.php b/tests/TestApplication/src/Entity/Todo.php index 61e7e47..1b1ff69 100644 --- a/tests/TestApplication/src/Entity/Todo.php +++ b/tests/TestApplication/src/Entity/Todo.php @@ -3,12 +3,12 @@ namespace TestApplication\Entity; use Doctrine\ORM\Mapping as ORM; -use SwagIndustries\Melodiia\Crud\CrudableModelInterface; +use SwagIndustries\Melodiia\Crud\MelodiiaModel; /** * @ORM\Entity() */ -class Todo implements CrudableModelInterface +class Todo implements MelodiiaModel { /** * @ORM\Id