Fix phpstan issues

This commit is contained in:
2023-02-28 21:43:28 +01:00
parent 7dc07129f8
commit 318599334e
21 changed files with 81 additions and 208 deletions

View File

@@ -18,6 +18,9 @@ use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @implements LocalMenuBuilderInterface<array{accompanyingCourse: AccompanyingPeriod}>
*/
class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
{
protected Security $security;

View File

@@ -15,6 +15,9 @@ use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Security;
/**
* @implements LocalMenuBuilderInterface<array>
*/
final class AdminMenuBuilder implements LocalMenuBuilderInterface
{
private Security $security;

View File

@@ -13,11 +13,15 @@ namespace Chill\ActivityBundle\Menu;
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\PersonBundle\Entity\Person;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class PersonMenuBuilder implements LocalMenuBuilderInterface
/**
* @implements LocalMenuBuilderInterface<array{person: Person}>
*/
final class PersonMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface

View File

@@ -29,6 +29,8 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use function count;
/**
*/
final class CalendarContext implements CalendarContextInterface
{
private BaseContextData $baseContextData;
@@ -138,8 +140,7 @@ final class CalendarContext implements CalendarContextInterface
}
/**
* @param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData
* @param mixed $entity
* param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData
*/
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
@@ -237,7 +238,7 @@ final class CalendarContext implements CalendarContextInterface
}
/**
* @param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData
* param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{
@@ -250,7 +251,7 @@ final class CalendarContext implements CalendarContextInterface
}
/**
* @return array{askMainPerson: bool, mainPersonLabel: ?string, askThirdParty: bool, thirdPartyLabel: ?string, trackDateTime: bool} $options
* return array{askMainPerson: bool, mainPersonLabel: ?string, askThirdParty: bool, thirdPartyLabel: ?string, trackDateTime: bool} $options
*/
private function getOptions(DocGeneratorTemplate $template): array
{

View File

@@ -18,6 +18,9 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @template-extends DocGeneratorContextWithPublicFormInterface<Calendar>
*/
interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInterface, DocGeneratorContextWithAdminFormInterface
{
public function adminFormReverseTransform(array $data): array;
@@ -26,23 +29,14 @@ interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInte
public function buildAdminForm(FormBuilderInterface $builder): void;
/**
* @param Calendar $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
/**
* @param Calendar $entity
*/
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array;
public function getDescription(): string;
public function getEntityClass(): string;
/**
* @param Calendar $entity
*/
public function getFormData(DocGeneratorTemplate $template, $entity): array;
public static function getKey(): string;
@@ -51,17 +45,11 @@ interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInte
public function hasAdminForm(): bool;
/**
* @param Calendar $entity
*/
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
public function contextGenerationDataNormalize(DocGeneratorTemplate $template, $entity, array $data): array;
public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array;
/**
* @param Calendar $entity
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void;
}

View File

@@ -16,15 +16,17 @@ use Chill\DocStoreBundle\Entity\StoredObject;
/**
* Interface for context for document generation.
*
* @template T of object
*/
interface DocGeneratorContextInterface
{
/**
* Get the data that will be injected to the generated document.
*
* @param mixed $entity
* @param T $entity
*/
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array;
public function getData(DocGeneratorTemplate $template, object $entity, array $contextGenerationData = []): array;
public function getDescription(): string;
@@ -34,5 +36,8 @@ interface DocGeneratorContextInterface
public function getName(): string;
/**
* @param T $entity
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void;
}

View File

@@ -14,34 +14,43 @@ namespace Chill\DocGeneratorBundle\Context;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @template T
*/
interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContextInterface
{
/**
* Generate the form that display.
*
* @param mixed $entity
* @param T $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, mixed $entity): void;
/**
* Fill the form with initial data
*
* @param T $entity
*/
public function getFormData(DocGeneratorTemplate $template, $entity): array;
public function getFormData(DocGeneratorTemplate $template, mixed $entity): array;
/**
* has form.
*
* @param mixed $entity
* @param T $entity
*/
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
public function hasPublicForm(DocGeneratorTemplate $template, mixed $entity): bool;
/**
* Transform the data from the form into serializable data, storable into messenger's message
*
* @param T $entity
*/
public function contextGenerationDataNormalize(DocGeneratorTemplate $template, $entity, array $data): array;
public function contextGenerationDataNormalize(DocGeneratorTemplate $template, mixed $entity, array $data): array;
/**
* Reverse the data from the messenger's message into data usable for doc's generation
*
* @param T $entity
*/
public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array;
public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, mixed $entity, array $data): array;
}

View File

@@ -61,7 +61,7 @@ class LoadDocGeneratorTemplate extends AbstractFixture
->setFilename($template['file']['filename'])
->setKeyInfos(json_decode($template['file']['key'], true))
->setIv(json_decode($template['file']['iv'], true))
->setCreationDate(new DateTime('today'))
->setCreatedAt(new DateTime('today'))
->setType($template['file']['type']);
$manager->persist($newStoredObj);

View File

@@ -113,7 +113,7 @@ class Generator implements GeneratorInterface
throw new GeneratorException($e->getErrors(), $e);
}
if ($isTest) {
if (true === $isTest) {
$this->logger->info(self::LOG_PREFIX.'Finished generation of a document', [
'is_test' => true,
'entity_id' => $entityId,
@@ -122,7 +122,7 @@ class Generator implements GeneratorInterface
return $generatedResource;
}
/** @var StoredObject $storedObject */
/** @var StoredObject $destinationStoredObject */
$destinationStoredObject
->setType($template->getFile()->getType())
->setFilename(sprintf('%s_odt', uniqid('doc_', true)))

View File

@@ -4,7 +4,7 @@ namespace Chill\DocGeneratorBundle\Service\Generator;
class RelatedEntityNotFoundException extends \RuntimeException
{
public function __construct(string $relatedEntityClass, int $relatedEntityId, Throwable $previous = null)
public function __construct(string $relatedEntityClass, int $relatedEntityId, \Throwable $previous = null)
{
parent::__construct(
sprintf("Related entity not found: %s, %s", $relatedEntityClass, $relatedEntityId),

View File

@@ -108,10 +108,7 @@ final class OnGenerationFails implements EventSubscriberInterface
private function warnCreator(RequestGenerationMessage $message, WorkerMessageFailedEvent $event): void
{
if (null === $creatorId = $message->getCreatorId()) {
$this->logger->info(self::LOG_PREFIX.'creator id is null');
return;
}
$creatorId = $message->getCreatorId();
if (null === $creator = $this->userRepository->find($creatorId)) {
$this->logger->error(self::LOG_PREFIX.'Creator not found with given id', ['creator_id', $creatorId]);

View File

@@ -31,6 +31,9 @@ class NativeDateIntervalType extends DateIntervalType
{
public const FORMAT = '%rP%YY%MM%DDT%HH%IM%SS';
/**
* @param DateInterval|null $value
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (null === $value) {

View File

@@ -13,8 +13,18 @@ namespace Chill\MainBundle\Routing;
use Knp\Menu\MenuItem;
/**
* Implements a builder for menu
*
* @template TParams of array
*/
interface LocalMenuBuilderInterface
{
/**
* @param $menuId
* @param MenuItem $menu
* @param TParams $parameters
*/
public function buildMenu($menuId, MenuItem $menu, array $parameters);
/**

View File

@@ -28,6 +28,8 @@ use function count;
*
* - person details ;
* - accompanying period (if `visible`)
*
* @implements LocalMenuBuilderInterface<array{person: Person}>
*/
class PersonMenuBuilder implements LocalMenuBuilderInterface
{

View File

@@ -38,6 +38,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
/**
* @template-implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriod>
*/
class AccompanyingPeriodContext implements
DocGeneratorContextWithAdminFormInterface,
DocGeneratorContextWithPublicFormInterface
@@ -153,7 +156,7 @@ class AccompanyingPeriodContext implements
/**
* @param AccompanyingPeriod $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, mixed $entity): void
{
$options = $template->getOptions();
$persons = $entity->getCurrentParticipations()->map(static function (AccompanyingPeriodParticipation $p) {
@@ -286,9 +289,6 @@ class AccompanyingPeriodContext implements
return $denormalized;
}
/**
* @param AccompanyingPeriod $entity
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{
$doc = new AccompanyingCourseDocument();

View File

@@ -24,6 +24,8 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
*
* Although there isn't any document associated to AccompanyingPeriodWork, this context
* is use by @link{AccompanyingPeriodWorkEvaluationContext}.
*
* @implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriodWork>
*/
class AccompanyingPeriodWorkContext implements DocGeneratorContextWithPublicFormInterface
{
@@ -56,17 +58,11 @@ class AccompanyingPeriodWorkContext implements DocGeneratorContextWithPublicForm
$builder->remove('category');
}
/**
* @param AccompanyingPeriodWork $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
$this->periodContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriod());
}
/**
* @param AccompanyingPeriodWork $entity
*/
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
$data = $this->periodContext->getData($template, $entity->getAccompanyingPeriod(), $contextGenerationData);
@@ -88,9 +84,6 @@ class AccompanyingPeriodWorkContext implements DocGeneratorContextWithPublicForm
return AccompanyingPeriodWork::class;
}
/**
* @param AccompanyingPeriodWork $entity
*/
public function getFormData(DocGeneratorTemplate $template, $entity): array
{
return $this->periodContext->getFormData($template, $entity->getAccompanyingPeriod());
@@ -113,17 +106,17 @@ class AccompanyingPeriodWorkContext implements DocGeneratorContextWithPublicForm
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool
{
return $this->periodContext->hasPublicForm($template, $entity);
return $this->periodContext->hasPublicForm($template, $entity->getAccompanyingPeriod());
}
public function contextGenerationDataNormalize(DocGeneratorTemplate $template, $entity, array $data): array
{
return $this->periodContext->contextGenerationDataNormalize($template, $entity, $data);
return $this->periodContext->contextGenerationDataNormalize($template, $entity->getAccompanyingPeriod(), $data);
}
public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array
{
return $this->periodContext->contextGenerationDataDenormalize($template, $entity, $data);
return $this->periodContext->contextGenerationDataDenormalize($template, $entity->getAccompanyingPeriod(), $data);
}
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void

View File

@@ -26,6 +26,9 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @implements DocGeneratorContextWithPublicFormInterface<AccompanyingPeriodWorkEvaluation>
*/
class AccompanyingPeriodWorkEvaluationContext implements
DocGeneratorContextWithAdminFormInterface,
DocGeneratorContextWithPublicFormInterface
@@ -102,17 +105,11 @@ class AccompanyingPeriodWorkEvaluationContext implements
]);
}
/**
* @param AccompanyingPeriodWorkEvaluation $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
{
$this->accompanyingPeriodWorkContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriodWork());
}
/**
* @param AccompanyingPeriodWorkEvaluation $entity
*/
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{
$data = $this->accompanyingPeriodWorkContext
@@ -139,9 +136,6 @@ class AccompanyingPeriodWorkEvaluationContext implements
return AccompanyingPeriodWorkEvaluation::class;
}
/**
* @param AccompanyingPeriodWorkEvaluation $entity
*/
public function getFormData(DocGeneratorTemplate $template, $entity): array
{
return $this->accompanyingPeriodWorkContext->getFormData(
@@ -177,13 +171,13 @@ class AccompanyingPeriodWorkEvaluationContext implements
public function contextGenerationDataNormalize(DocGeneratorTemplate $template, $entity, array $data): array
{
return $this->accompanyingPeriodWorkContext
->contextGenerationDataNormalize($template, $entity, $data);
->contextGenerationDataNormalize($template, $entity->getAccompanyingPeriodWork(), $data);
}
public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array
{
return $this->accompanyingPeriodWorkContext
->contextGenerationDataDenormalize($template, $entity, $data);
->contextGenerationDataDenormalize($template, $entity->getAccompanyingPeriodWork(), $data);
}
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void

View File

@@ -249,9 +249,6 @@ final class PersonContext implements PersonContextInterface
];
}
/**
* @param Person $entity
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void
{
$doc = new PersonDocument();

View File

@@ -18,6 +18,9 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @template-extends DocGeneratorContextWithPublicFormInterface<Person>
*/
interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterface, DocGeneratorContextWithPublicFormInterface
{
public function adminFormReverseTransform(array $data): array;
@@ -26,10 +29,7 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa
public function buildAdminForm(FormBuilderInterface $builder): void;
/**
* @param Person $entity
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, mixed $entity): void;
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array;
@@ -37,7 +37,7 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa
public function getEntityClass(): string;
public function getFormData(DocGeneratorTemplate $template, $entity): array;
public function getFormData(DocGeneratorTemplate $template, mixed $entity): array;
public function getName(): string;
@@ -52,8 +52,5 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa
public function contextGenerationDataDenormalize(DocGeneratorTemplate $template, $entity, array $data): array;
/**
* @param Person $entity
*/
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void;
}