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

@@ -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]);