diff --git a/composer.json b/composer.json index def47ec..7d407f6 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,12 @@ "gedmo/doctrine-extensions": "^3.0", "hubspot/hubspot-php": "^3.1", "knplabs/doctrine-behaviors": "^2.0.6", - "runroom-packages/form-handler-bundle": "^0.12", - "runroom-packages/render-event-bundle": "^0.12", - "runroom-packages/sortable-behavior-bundle": "^0.12", - "sonata-project/admin-bundle": "^3.103 || ^4.0@dev", + "runroom-packages/form-handler-bundle": "^0.13", + "runroom-packages/render-event-bundle": "^0.13", + "runroom-packages/sortable-behavior-bundle": "^0.13", + "sonata-project/admin-bundle": "^3.103 || ^4.0@rc", "sonata-project/doctrine-extensions": "^1.13", - "sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@dev", + "sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@rc", "sonata-project/media-bundle": "^3.32 || ^4.0@dev", "symfony/config": "^4.4 || ^5.3", "symfony/dependency-injection": "^4.4 || ^5.3", @@ -59,8 +59,8 @@ "phpstan/phpstan-symfony": "^0.12", "phpunit/phpunit": "^9.3", "psalm/plugin-phpunit": "^0.16", - "psalm/plugin-symfony": "^2.0", - "runroom-packages/testing": "^0.12", + "psalm/plugin-symfony": "^3.0", + "runroom-packages/testing": "^0.13", "symfony/phpunit-bridge": "^5.3", "vimeo/psalm": "^4.0", "weirdan/doctrine-psalm-plugin": "^1.0", diff --git a/src/BasicEntities/Admin/BookAdmin.php b/src/BasicEntities/Admin/BookAdmin.php index 68b6027..b7447c7 100644 --- a/src/BasicEntities/Admin/BookAdmin.php +++ b/src/BasicEntities/Admin/BookAdmin.php @@ -48,15 +48,11 @@ protected function configureListFields(ListMapper $list): void 'sort_parent_association_mappings' => [['fieldName' => 'translations']], ]) ->add('category') - ->add('publish', null, [ - 'editable' => true, - ]) + ->add('publish', null, ['editable' => true]) ->add('_action', 'actions', [ 'actions' => [ 'delete' => [], - 'move' => [ - 'template' => '@RunroomSortableBehavior/sort.html.twig', - ], + 'move' => ['template' => '@RunroomSortableBehavior/sort.html.twig'], ], ]); } @@ -68,17 +64,13 @@ protected function configureFormFields(FormMapper $form): void 'label' => false, 'fields' => [ 'title' => [], - 'slug' => [ - 'display' => false, - ], + 'slug' => ['display' => false], 'description' => [ 'field_type' => CKEditorType::class, 'required' => false, ], ], - 'constraints' => [ - new Assert\Valid(), - ], + 'constraints' => [new Assert\Valid()], ]) ->add('category') ->add('picture', MediaType::class, [ diff --git a/src/BasicEntities/Admin/CategoryAdmin.php b/src/BasicEntities/Admin/CategoryAdmin.php index 9c22664..6d6cc4c 100644 --- a/src/BasicEntities/Admin/CategoryAdmin.php +++ b/src/BasicEntities/Admin/CategoryAdmin.php @@ -41,9 +41,7 @@ protected function configureListFields(ListMapper $list): void ]) ->add('books') ->add('_action', 'actions', [ - 'actions' => [ - 'delete' => [], - ], + 'actions' => ['delete' => []], ]); } @@ -55,9 +53,7 @@ protected function configureFormFields(FormMapper $form): void 'fields' => [ 'name' => [], ], - 'constraints' => [ - new Assert\Valid(), - ], + 'constraints' => [new Assert\Valid()], ]) ->add('books'); } diff --git a/src/BasicEntities/Service/BookService.php b/src/BasicEntities/Service/BookService.php index 1d9a2d7..f029ecd 100644 --- a/src/BasicEntities/Service/BookService.php +++ b/src/BasicEntities/Service/BookService.php @@ -28,21 +28,11 @@ public function __construct(BookRepository $repository) public function getBooksViewModel(): BooksViewModel { - $books = $this->repository->findBy(['publish' => true], ['position' => 'ASC']); - - $model = new BooksViewModel(); - $model->setBooks($books); - - return $model; + return new BooksViewModel($this->repository->findBy(['publish' => true], ['position' => 'ASC'])); } public function getBookViewModel(string $slug): BookViewModel { - $book = $this->repository->findBySlug($slug); - - $model = new BookViewModel(); - $model->setBook($book); - - return $model; + return new BookViewModel($this->repository->findBySlug($slug)); } } diff --git a/src/BasicEntities/ViewModel/BookViewModel.php b/src/BasicEntities/ViewModel/BookViewModel.php index ae3f7c1..e869578 100644 --- a/src/BasicEntities/ViewModel/BookViewModel.php +++ b/src/BasicEntities/ViewModel/BookViewModel.php @@ -17,14 +17,14 @@ class BookViewModel { - private ?Book $book = null; + private Book $book; - public function setBook(Book $book): void + public function __construct(Book $book) { $this->book = $book; } - public function getBook(): ?Book + public function getBook(): Book { return $this->book; } diff --git a/src/BasicEntities/ViewModel/BooksViewModel.php b/src/BasicEntities/ViewModel/BooksViewModel.php index a888ba9..791ac23 100644 --- a/src/BasicEntities/ViewModel/BooksViewModel.php +++ b/src/BasicEntities/ViewModel/BooksViewModel.php @@ -17,17 +17,17 @@ class BooksViewModel { - /** @var Book[]|null */ - private ?array $books = null; + /** @var Book[] */ + private array $books; /** @param Book[] $books */ - public function setBooks(array $books): void + public function __construct(array $books) { $this->books = $books; } - /** @return Book[]|null */ - public function getBooks(): ?array + /** @return Book[] */ + public function getBooks(): array { return $this->books; } diff --git a/src/Forms/Admin/ContactAdmin.php b/src/Forms/Admin/ContactAdmin.php index 2db5166..193fe3e 100644 --- a/src/Forms/Admin/ContactAdmin.php +++ b/src/Forms/Admin/ContactAdmin.php @@ -41,9 +41,7 @@ protected function configureRoutes(RouteCollectionInterface $collection): void protected function configureShowFields(ShowMapper $show): void { $show - ->add('date', null, [ - 'format' => 'd/m/Y h:i', - ]) + ->add('date', null, ['format' => 'd/m/Y h:i']) ->add('name') ->add('email') ->add('phone') @@ -72,32 +70,24 @@ protected function configureShowFields(ShowMapper $show): void protected function configureDatagridFilters(DatagridMapper $filter): void { $filter - ->add('date', DateRangeFilter::class, [ - 'field_type' => DateTimeRangePickerType::class, - ]) + ->add('date', DateRangeFilter::class, ['field_type' => DateTimeRangePickerType::class]) ->add('name') ->add('email') ->add('subject', null, [ 'field_type' => ChoiceType::class, - 'field_options' => [ - 'choices' => Contact::$subjectChoices, - ], + 'field_options' => ['choices' => Contact::$subjectChoices], ]) ->add('newsletter') ->add('status', null, [ 'field_type' => ChoiceType::class, - 'field_options' => [ - 'choices' => Contact::$statusChoices, - ], + 'field_options' => ['choices' => Contact::$statusChoices], ]); } protected function configureListFields(ListMapper $list): void { $list - ->add('date', null, [ - 'format' => 'd/m/Y h:i', - ]) + ->add('date', null, ['format' => 'd/m/Y h:i']) ->addIdentifier('name') ->add('email', 'email') ->add('subject', 'choice', [ @@ -112,9 +102,7 @@ protected function configureListFields(ListMapper $list): void 'template' => '@Samples/Forms/sonata/contact-status.html.twig', ]) ->add('_action', 'actions', [ - 'actions' => [ - 'delete' => [], - ], + 'actions' => ['delete' => []], ]); } } diff --git a/src/Forms/Controller/ContactController.php b/src/Forms/Controller/ContactController.php index a04ee09..9490f10 100644 --- a/src/Forms/Controller/ContactController.php +++ b/src/Forms/Controller/ContactController.php @@ -45,16 +45,11 @@ public function contact(): Response if ($model->formIsValid()) { return new RedirectResponse( - $this->router->generate('runroom_samples.forms.contact', [ - '_fragment' => 'form', - ]) + $this->router->generate('runroom_samples.forms.contact', ['_fragment' => 'form']) ); } - return $this->renderer->renderResponse( - '@RunroomSamples/Forms/contact.html.twig', - $model - ); + return $this->renderer->renderResponse('@RunroomSamples/Forms/contact.html.twig', $model); } public function contactAjax(): Response @@ -82,15 +77,10 @@ public function contactHubspot(): Response if ($model->formIsValid()) { return new RedirectResponse( - $this->router->generate('runroom_samples.forms.hubspot', [ - '_fragment' => 'form', - ]) + $this->router->generate('runroom_samples.forms.hubspot', ['_fragment' => 'form']) ); } - return $this->renderer->renderResponse( - '@RunroomSamples/Forms/contact-hubspot.html.twig', - $model - ); + return $this->renderer->renderResponse('@RunroomSamples/Forms/contact-hubspot.html.twig', $model); } } diff --git a/src/Forms/Form/ContactEventHandler.php b/src/Forms/Form/ContactEventHandler.php index f1380b7..9f1a2b9 100644 --- a/src/Forms/Form/ContactEventHandler.php +++ b/src/Forms/Form/ContactEventHandler.php @@ -53,8 +53,6 @@ public function onContactSuccess(GenericEvent $event): void public static function getSubscribedEvents(): array { - return [ - 'form.contact_form.event.success' => 'onContactSuccess', - ]; + return ['form.contact_form.event.success' => 'onContactSuccess']; } } diff --git a/src/Forms/Form/ContactHubspotEventHandler.php b/src/Forms/Form/ContactHubspotEventHandler.php index 2b23862..fce4cbb 100644 --- a/src/Forms/Form/ContactHubspotEventHandler.php +++ b/src/Forms/Form/ContactHubspotEventHandler.php @@ -76,9 +76,7 @@ public function onContactSuccess(GenericEvent $event): void public static function getSubscribedEvents(): array { - return [ - 'form.contact_hubspot_form.event.success' => 'onContactSuccess', - ]; + return ['form.contact_hubspot_form.event.success' => 'onContactSuccess']; } /** @param array{ fields: array{name: string, value: mixed}[], legalConsentOptions: array{consent: array{consentToProcess: mixed, text: string} } } $data */ diff --git a/src/Forms/Form/Type/ContactFormType.php b/src/Forms/Form/Type/ContactFormType.php index 66f7989..7c8045f 100644 --- a/src/Forms/Form/Type/ContactFormType.php +++ b/src/Forms/Form/Type/ContactFormType.php @@ -89,17 +89,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]) ->add('comment', TextareaType::class, [ - 'constraints' => [ - new Assert\NotBlank(['message' => 'not_blank']), - ], - ]) - ->add('newsletter', CheckboxType::class, [ - 'required' => false, + 'constraints' => [new Assert\NotBlank(['message' => 'not_blank'])], ]) + ->add('newsletter', CheckboxType::class, ['required' => false]) ->add('privacyPolicy', CheckboxType::class, [ - 'constraints' => [ - new Assert\IsTrue(['message' => 'privacy_policy']), - ], + 'constraints' => [new Assert\IsTrue(['message' => 'privacy_policy'])], ]) ->add('send', SubmitType::class); } diff --git a/src/Forms/Form/Type/ContactHubspotFormType.php b/src/Forms/Form/Type/ContactHubspotFormType.php index d112108..4d96851 100644 --- a/src/Forms/Form/Type/ContactHubspotFormType.php +++ b/src/Forms/Form/Type/ContactHubspotFormType.php @@ -50,14 +50,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ], ]) ->add('comment', TextareaType::class, [ - 'constraints' => [ - new Assert\NotBlank(['message' => 'not_blank']), - ], + 'constraints' => [new Assert\NotBlank(['message' => 'not_blank'])], ]) ->add('privacyPolicy', CheckboxType::class, [ - 'constraints' => [ - new Assert\IsTrue(['message' => 'privacy_policy']), - ], + 'constraints' => [new Assert\IsTrue(['message' => 'privacy_policy'])], ]) ->add('send', SubmitType::class); } diff --git a/tests/BasicEntities/Unit/BookControllerTest.php b/tests/BasicEntities/Unit/BookControllerTest.php index ff1dc98..6558579 100644 --- a/tests/BasicEntities/Unit/BookControllerTest.php +++ b/tests/BasicEntities/Unit/BookControllerTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Runroom\SamplesBundle\BasicEntities\Controller\BookController; +use Runroom\SamplesBundle\BasicEntities\Entity\Book; use Runroom\SamplesBundle\BasicEntities\Service\BookService; use Runroom\SamplesBundle\BasicEntities\ViewModel\BooksViewModel; use Runroom\SamplesBundle\BasicEntities\ViewModel\BookViewModel; @@ -49,7 +50,7 @@ protected function setUp(): void /** @test */ public function itRenderBooks(): void { - $model = new BooksViewModel(); + $model = new BooksViewModel([]); $this->service->method('getBooksViewModel')->willReturn($model); @@ -61,7 +62,7 @@ public function itRenderBooks(): void /** @test */ public function itRenderBook(): void { - $model = new BookViewModel(); + $model = new BookViewModel(new Book()); $this->service->method('getBookViewModel')->with('book')->willReturn($model);