apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -13,15 +13,13 @@ namespace Chill\DocGeneratorBundle\Service\Context;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class BaseContextData
{
public function __construct(private readonly NormalizerInterface $normalizer) {}
public function getData(?User $user = null): array
public function getData(User $user = null): array
{
$data = [];
@@ -30,11 +28,11 @@ class BaseContextData
'docgen',
['docgen:expects' => User::class, 'groups' => ['docgen:read']]
);
$data['createdAt'] = $this->normalizer->normalize(new DateTimeImmutable(), 'docgen', [
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
$data['createdAt'] = $this->normalizer->normalize(new \DateTimeImmutable(), 'docgen', [
'docgen:expects' => \DateTimeImmutable::class, 'groups' => ['docgen:read'],
]);
$data['createdAtDate'] = $this->normalizer->normalize(new DateTimeImmutable('today'), 'docgen', [
'docgen:expects' => DateTimeImmutable::class, 'groups' => ['docgen:read'],
$data['createdAtDate'] = $this->normalizer->normalize(new \DateTimeImmutable('today'), 'docgen', [
'docgen:expects' => \DateTimeImmutable::class, 'groups' => ['docgen:read'],
]);
$data['location'] = $this->normalizer->normalize(
$user instanceof User ? $user->getCurrentLocation() : null,

View File

@@ -32,19 +32,22 @@ class Generator implements GeneratorInterface
/**
* @template T of File|null
* @template B of bool
* @param B $isTest
*
* @param B $isTest
* @param (B is true ? T : null) $testFile
*
* @psalm-return (B is true ? string : null)
*
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable
*/
public function generateDocFromTemplate(
DocGeneratorTemplate $template,
int $entityId,
array $contextGenerationDataNormalized,
?StoredObject $destinationStoredObject = null,
bool $isTest = false,
?File $testFile = null,
?User $creator = null
int $entityId,
array $contextGenerationDataNormalized,
StoredObject $destinationStoredObject = null,
bool $isTest = false,
File $testFile = null,
User $creator = null
): ?string {
if ($destinationStoredObject instanceof StoredObject && StoredObject::STATUS_PENDING !== $destinationStoredObject->getStatus()) {
$this->logger->info(self::LOG_PREFIX.'Aborting generation of an already generated document');
@@ -53,7 +56,7 @@ class Generator implements GeneratorInterface
$this->logger->info(self::LOG_PREFIX.'Starting generation of a document', [
'entity_id' => $entityId,
'destination_stored_object' => $destinationStoredObject === null ? null : $destinationStoredObject->getId()
'destination_stored_object' => null === $destinationStoredObject ? null : $destinationStoredObject->getId(),
]);
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
@@ -107,12 +110,13 @@ class Generator implements GeneratorInterface
$this->logger->info(self::LOG_PREFIX.'Finished generation of a document', [
'is_test' => true,
'entity_id' => $entityId,
'destination_stored_object' => $destinationStoredObject === null ? null : $destinationStoredObject->getId()
'destination_stored_object' => null === $destinationStoredObject ? null : $destinationStoredObject->getId(),
]);
return $generatedResource;
}
/** @var StoredObject $destinationStoredObject */
/* @var StoredObject $destinationStoredObject */
$destinationStoredObject
->setType($template->getFile()->getType())
->setFilename(sprintf('%s_odt', uniqid('doc_', true)))

View File

@@ -11,15 +11,12 @@ declare(strict_types=1);
namespace Chill\DocGeneratorBundle\Service\Generator;
use RuntimeException;
use Throwable;
class GeneratorException extends RuntimeException
class GeneratorException extends \RuntimeException
{
/**
* @param string[] $errors
*/
public function __construct(private readonly array $errors = [], ?Throwable $previous = null)
public function __construct(private readonly array $errors = [], \Throwable $previous = null)
{
parent::__construct(
'Could not generate the document',

View File

@@ -21,18 +21,21 @@ interface GeneratorInterface
/**
* @template T of File|null
* @template B of bool
* @param B $isTest
*
* @param B $isTest
* @param (B is true ? T : null) $testFile
*
* @psalm-return (B is true ? string : null)
*
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable
*/
public function generateDocFromTemplate(
DocGeneratorTemplate $template,
int $entityId,
array $contextGenerationDataNormalized,
?StoredObject $destinationStoredObject = null,
bool $isTest = false,
?File $testFile = null,
?User $creator = null
int $entityId,
array $contextGenerationDataNormalized,
StoredObject $destinationStoredObject = null,
bool $isTest = false,
File $testFile = null,
User $creator = null
): ?string;
}

View File

@@ -11,9 +11,7 @@ declare(strict_types=1);
namespace Chill\DocGeneratorBundle\Service\Generator;
use RuntimeException;
class ObjectReadyException extends RuntimeException
class ObjectReadyException extends \RuntimeException
{
public function __construct()
{

View File

@@ -11,11 +11,9 @@ declare(strict_types=1);
namespace Chill\DocGeneratorBundle\Service\Generator;
use RuntimeException;
class RelatedEntityNotFoundException extends RuntimeException
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

@@ -30,11 +30,10 @@ final readonly class OnGenerationFails implements EventSubscriberInterface
public function __construct(private DocGeneratorTemplateRepository $docGeneratorTemplateRepository, private EntityManagerInterface $entityManager, private LoggerInterface $logger, private MailerInterface $mailer, private StoredObjectRepository $storedObjectRepository, private TranslatorInterface $translator, private UserRepositoryInterface $userRepository) {}
public static function getSubscribedEvents()
{
return [
WorkerMessageFailedEvent::class => 'onMessageFailed'
WorkerMessageFailedEvent::class => 'onMessageFailed',
];
}
@@ -82,11 +81,13 @@ final readonly class OnGenerationFails implements EventSubscriberInterface
if (null === $creator = $this->userRepository->find($creatorId)) {
$this->logger->error(self::LOG_PREFIX.'Creator not found with given id', ['creator_id', $creatorId]);
return;
}
if (null === $creator->getEmail() || '' === $creator->getEmail()) {
$this->logger->info(self::LOG_PREFIX.'Creator does not have any email', ['user' => $creator->getUsernameCanonical()]);
return;
}
@@ -104,6 +105,7 @@ final readonly class OnGenerationFails implements EventSubscriberInterface
if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) {
$this->logger->info(self::LOG_PREFIX.'Template not found', ['template_id' => $message->getTemplateId()]);
return;
}

View File

@@ -22,7 +22,7 @@ use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
/**
* Handle the request of document generation
* Handle the request of document generation.
*/
class RequestGenerationHandler implements MessageHandlerInterface
{
@@ -35,11 +35,11 @@ class RequestGenerationHandler implements MessageHandlerInterface
public function __invoke(RequestGenerationMessage $message)
{
if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) {
throw new \RuntimeException('template not found: ' . $message->getTemplateId());
throw new \RuntimeException('template not found: '.$message->getTemplateId());
}
if (null === $destinationStoredObject = $this->storedObjectRepository->find($message->getDestinationStoredObjectId())) {
throw new \RuntimeException('destination stored object not found : ' . $message->getDestinationStoredObjectId());
throw new \RuntimeException('destination stored object not found : '.$message->getDestinationStoredObjectId());
}
if ($destinationStoredObject->getGenerationTrialsCounter() >= self::AUTHORIZED_TRIALS) {