diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php index d6ec9c19c..c92aff527 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/AdminDocGeneratorTemplateController.php @@ -32,6 +32,7 @@ class AdminDocGeneratorTemplateController extends CRUDController switch ($action) { case 'new': $context = $this->contextManager->getContextByKey($request->get('context')); + // no break case 'edit': $context = $this->contextManager->getContextByDocGeneratorTemplate($entity); @@ -39,6 +40,7 @@ class AdminDocGeneratorTemplateController extends CRUDController $defaultTemplateParameters, ['context' => $context] ); + case 'index': return array_merge( $defaultTemplateParameters, @@ -48,7 +50,6 @@ class AdminDocGeneratorTemplateController extends CRUDController default: return parent::generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters); // TODO: Change the autogenerated stub } - } public function new(Request $request): Response diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index 3267b2225..21a830bfd 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -90,7 +90,6 @@ final class DocGeneratorTemplateController extends AbstractController int $entityId, Request $request ): Response { - try { $context = $this->contextManager->getContextByDocGeneratorTemplate($template); } catch (ContextNotFoundException $e) { diff --git a/src/Bundle/ChillDocGeneratorBundle/Menu/AdminMenuBuilder.php b/src/Bundle/ChillDocGeneratorBundle/Menu/AdminMenuBuilder.php index bfe8ba66c..39b21ed0e 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Menu/AdminMenuBuilder.php +++ b/src/Bundle/ChillDocGeneratorBundle/Menu/AdminMenuBuilder.php @@ -1,18 +1,28 @@ translator = $translator; @@ -22,12 +32,12 @@ class AdminMenuBuilder implements LocalMenuBuilderInterface public function buildMenu($menuId, MenuItem $menu, array $parameters) { if ($this->security->isGranted('ROLE_ADMIN')) { - if (in_array($menuId, ['admin_index', 'admin_section'])) { + if (in_array($menuId, ['admin_index', 'admin_section'], true)) { $menu->addChild($this->translator->trans('docgen.Document generation'), [ - 'route' => 'chill_crud_docgen_template_index' + 'route' => 'chill_crud_docgen_template_index', ])->setExtras([ 'order' => 350, - 'explain' => 'docgen.Manage templates and document generation' + 'explain' => 'docgen.Manage templates and document generation', ]); } } @@ -37,6 +47,4 @@ class AdminMenuBuilder implements LocalMenuBuilderInterface { return ['admin_index', 'admin_section', 'docgen_admin']; } - - } diff --git a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php index 4f0a9f1ab..c32be9913 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php +++ b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php @@ -212,6 +212,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte if (is_iterable($value)) { $arr = []; + foreach ($value as $k => $v) { $arr[$k] = $this->normalizer->normalize($v, $format, array_merge( diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php index ee3ac7dc9..055da93e9 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php @@ -11,7 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity; -use DateTimeImmutable; +use DateTime; use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; @@ -38,7 +38,7 @@ class AccompanyingPeriodParticipation * @ORM\Column(type="date", nullable=true) * @Groups({"read", "docgen:read"}) */ - private ?\DateTime $endDate = null; + private ?DateTime $endDate = null; /** * @ORM\Id @@ -59,11 +59,11 @@ class AccompanyingPeriodParticipation * @ORM\Column(type="date", nullable=false) * @Groups({"read", "docgen:read"}) */ - private ?\DateTime $startDate = null; + private ?DateTime $startDate = null; public function __construct(AccompanyingPeriod $accompanyingPeriod, Person $person) { - $this->startDate = new \DateTime('now'); + $this->startDate = new DateTime('now'); $this->accompanyingPeriod = $accompanyingPeriod; $this->person = $person; } diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index c5adbbd6a..95aa83872 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -157,8 +157,6 @@ class Household } /** - * @param DateTimeImmutable|null $now - * @return Collection * @Serializer\Groups({"docgen:read"}) */ public function getCurrentMembers(?DateTimeImmutable $now = null): Collection diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php index 96af56e95..5fa12f741 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Serializer\Normalizer; use Chill\PersonBundle\Entity\SocialWork\SocialAction; -use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; @@ -41,8 +40,8 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte 'desactivationDate' => $this->normalizer->normalize($socialAction->getDesactivationDate()), 'title' => $socialAction->getTitle(), ]; - case 'docgen': + case 'docgen': if (null === $socialAction) { return ['id' => 0, 'title' => '', 'text' => '']; } @@ -52,12 +51,13 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte 'text' => $this->render->renderString($socialAction, []), 'title' => $socialAction->getTitle(), ]; + default: - throw new \Symfony\Component\Serializer\Exception\RuntimeException("format not supported"); + throw new \Symfony\Component\Serializer\Exception\RuntimeException('format not supported'); } } - public function supportsNormalization($data, string $format = null, array $context = []) + public function supportsNormalization($data, ?string $format = null, array $context = []) { if ($data instanceof SocialAction && 'json' === $format) { return true; @@ -68,7 +68,7 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte return true; } - if (null === $data && ($context['docgen:expects'] ?? null) === SocialAction::class) { + if (null === $data && SocialAction::class === ($context['docgen:expects'] ?? null)) { return true; } } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php index cfe7c0895..5be7df4bc 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialIssueNormalizer.php @@ -16,9 +16,8 @@ use Chill\PersonBundle\Templating\Entity\SocialIssueRender; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -class SocialIssueNormalizer implements NormalizerAwareInterface, ContextAwareNormalizerInterface +class SocialIssueNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface { use NormalizerAwareTrait; @@ -42,8 +41,8 @@ class SocialIssueNormalizer implements NormalizerAwareInterface, ContextAwareNor 'title' => $socialIssue->getTitle(), 'text' => $this->render->renderString($socialIssue, []), ]; - case 'docgen': + case 'docgen': if (null === $socialIssue) { return ['id' => 0, 'title' => '', 'text' => '']; } @@ -56,20 +55,20 @@ class SocialIssueNormalizer implements NormalizerAwareInterface, ContextAwareNor } } - public function supportsNormalization($data, string $format = null, array $context = []) + public function supportsNormalization($data, ?string $format = null, array $context = []) { if ($data instanceof SocialIssue && 'json' === $format) { return true; } if ('docgen' === $format) { - if ($data instanceof SocialIssue) { - return true; - } + if ($data instanceof SocialIssue) { + return true; + } - if (null === $data && ($context['docgen:expects'] ?? null) === SocialIssue::class) { - return true; - } + if (null === $data && SocialIssue::class === ($context['docgen:expects'] ?? null)) { + return true; + } } return false; diff --git a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php index bd104bbe8..af2dca1f3 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizerTest.php @@ -80,22 +80,6 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase } } - public function testNormalizeParticipations() - { - $period = new AccompanyingPeriod(); - $period->addPerson($person = new Person()); - $person->setFirstName('test'); - - $data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]); - - $this->assertIsArray($data); - $this->assertArrayHasKey('participations', $data); - $this->assertCount(1, $data['participations']); - - $this->assertArrayHasKey('currentParticipations', $data); - $this->assertCount(1, $data['currentParticipations']); - } - public function testNormalizeNull() { $data = $this->normalizer->normalize(null, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]); @@ -134,4 +118,20 @@ final class AccompanyingPeriodDocGenNormalizerTest extends KernelTestCase $this->assertEquals($item, $data[$key]); } } + + public function testNormalizeParticipations() + { + $period = new AccompanyingPeriod(); + $period->addPerson($person = new Person()); + $person->setFirstName('test'); + + $data = $this->normalizer->normalize($period, 'docgen', ['docgen:expects' => AccompanyingPeriod::class]); + + $this->assertIsArray($data); + $this->assertArrayHasKey('participations', $data); + $this->assertCount(1, $data['participations']); + + $this->assertArrayHasKey('currentParticipations', $data); + $this->assertCount(1, $data['currentParticipations']); + } }