DX: fix cs

This commit is contained in:
Julien Fastré 2023-02-28 22:39:33 +01:00
parent b1d4334c0f
commit c35ca3dbeb
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
16 changed files with 134 additions and 20 deletions

View File

@ -151,6 +151,7 @@ final class CalendarContext implements CalendarContextInterface
/** /**
* param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData * param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData
* @param mixed $entity
*/ */
public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array public function getData(DocGeneratorTemplate $template, $entity, array $contextGenerationData = []): array
{ {

View File

@ -257,7 +257,8 @@ final class DocGeneratorTemplateController extends AbstractController
return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [ return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [
'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT) 'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT)
]); ]);
} elseif ($isTest) { }
if ($isTest) {
$generated = $this->generator->generateDocFromTemplate( $generated = $this->generator->generateDocFromTemplate(
$template, $template,
$entityId, $entityId,
@ -283,7 +284,7 @@ final class DocGeneratorTemplateController extends AbstractController
// we prepare the object to store the document // we prepare the object to store the document
$storedObject = (new StoredObject()) $storedObject = (new StoredObject())
->setStatus(StoredObject::STATUS_PENDING) ->setStatus(StoredObject::STATUS_PENDING)
; ;
$this->entityManager->persist($storedObject); $this->entityManager->persist($storedObject);

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Generator; namespace Chill\DocGeneratorBundle\Service\Generator;
use Chill\DocGeneratorBundle\Context\ContextManagerInterface; use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
@ -72,7 +81,7 @@ class Generator implements GeneratorInterface
$entity = $this $entity = $this
->entityManager ->entityManager
->find($context->getEntityClass(), $entityId) ->find($context->getEntityClass(), $entityId)
; ;
if (null === $entity) { if (null === $entity) {
throw new RelatedEntityNotFoundException($template->getEntity(), $entityId); throw new RelatedEntityNotFoundException($template->getEntity(), $entityId);
@ -80,9 +89,9 @@ class Generator implements GeneratorInterface
$contextGenerationDataNormalized = array_merge( $contextGenerationDataNormalized = array_merge(
$contextGenerationDataNormalized, $contextGenerationDataNormalized,
$context instanceof DocGeneratorContextWithPublicFormInterface ? $context instanceof DocGeneratorContextWithPublicFormInterface ?
$context->contextGenerationDataDenormalize($template, $entity, $contextGenerationDataNormalized) $context->contextGenerationDataDenormalize($template, $entity, $contextGenerationDataNormalized)
: [] : []
); );
$data = $context->getData($template, $entity, $contextGenerationDataNormalized); $data = $context->getData($template, $entity, $contextGenerationDataNormalized);
@ -127,7 +136,7 @@ class Generator implements GeneratorInterface
->setType($template->getFile()->getType()) ->setType($template->getFile()->getType())
->setFilename(sprintf('%s_odt', uniqid('doc_', true))) ->setFilename(sprintf('%s_odt', uniqid('doc_', true)))
->setStatus(StoredObject::STATUS_READY) ->setStatus(StoredObject::STATUS_READY)
; ;
$this->storedObjectManager->write($destinationStoredObject, $generatedResource); $this->storedObjectManager->write($destinationStoredObject, $generatedResource);

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Generator; namespace Chill\DocGeneratorBundle\Service\Generator;
class GeneratorException extends \RuntimeException class GeneratorException extends \RuntimeException
@ -12,8 +21,11 @@ class GeneratorException extends \RuntimeException
public function __construct(array $errors = [], \Throwable $previous = null) public function __construct(array $errors = [], \Throwable $previous = null)
{ {
$this->errors = $errors; $this->errors = $errors;
parent::__construct("Could not generate the document", 15252, parent::__construct(
$previous); "Could not generate the document",
15252,
$previous
);
} }
/** /**

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Generator; namespace Chill\DocGeneratorBundle\Service\Generator;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Generator; namespace Chill\DocGeneratorBundle\Service\Generator;
class ObjectReadyException extends \RuntimeException class ObjectReadyException extends \RuntimeException

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Generator; namespace Chill\DocGeneratorBundle\Service\Generator;
class RelatedEntityNotFoundException extends \RuntimeException class RelatedEntityNotFoundException extends \RuntimeException
@ -9,6 +18,7 @@ class RelatedEntityNotFoundException extends \RuntimeException
parent::__construct( parent::__construct(
sprintf("Related entity not found: %s, %s", $relatedEntityClass, $relatedEntityId), sprintf("Related entity not found: %s, %s", $relatedEntityClass, $relatedEntityId),
99876652, 99876652,
$previous); $previous
);
} }
} }

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Messenger; namespace Chill\DocGeneratorBundle\Service\Messenger;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
@ -31,7 +40,7 @@ final class OnGenerationFails implements EventSubscriberInterface
private UserRepositoryInterface $userRepository; private UserRepositoryInterface $userRepository;
const LOG_PREFIX = '[docgen failed] '; public const LOG_PREFIX = '[docgen failed] ';
/** /**
* @param DocGeneratorTemplateRepository $docGeneratorTemplateRepository * @param DocGeneratorTemplateRepository $docGeneratorTemplateRepository

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Messenger; namespace Chill\DocGeneratorBundle\Service\Messenger;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\Service\Messenger; namespace Chill\DocGeneratorBundle\Service\Messenger;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
@ -8,15 +17,15 @@ use Chill\MainBundle\Entity\User;
class RequestGenerationMessage class RequestGenerationMessage
{ {
private int $creatorId; private int $creatorId;
private int $templateId; private int $templateId;
private int $entityId; private int $entityId;
private int $destinationStoredObjectId; private int $destinationStoredObjectId;
private array $contextGenerationData; private array $contextGenerationData;
public function __construct( public function __construct(
User $creator, User $creator,

View File

@ -2,6 +2,13 @@
declare(strict_types=1); declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\DocGenerator; namespace Chill\Migrations\DocGenerator;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocGeneratorBundle\tests\Service\Context\Generator; namespace Chill\DocGeneratorBundle\tests\Service\Context\Generator;
use Chill\DocGeneratorBundle\Context\ContextManagerInterface; use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
@ -17,6 +26,10 @@ use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
/**
* @internal
* @coversNothing
*/
class GeneratorTest extends TestCase class GeneratorTest extends TestCase
{ {
use ProphecyTrait; use ProphecyTrait;
@ -29,7 +42,7 @@ class GeneratorTest extends TestCase
$reflection = new \ReflectionClass($destinationStoredObject); $reflection = new \ReflectionClass($destinationStoredObject);
$reflection->getProperty('id')->setAccessible(true); $reflection->getProperty('id')->setAccessible(true);
$reflection->getProperty('id')->setValue($destinationStoredObject, 1); $reflection->getProperty('id')->setValue($destinationStoredObject, 1);
$entity = new class {}; $entity = new class () {};
$data = []; $data = [];
$context = $this->prophesize(DocGeneratorContextInterface::class); $context = $this->prophesize(DocGeneratorContextInterface::class);

View File

@ -1,5 +1,14 @@
<?php <?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\DocStoreBundle\Controller; namespace Chill\DocStoreBundle\Controller;
use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Entity\StoredObject;

View File

@ -35,12 +35,11 @@ use Symfony\Component\Serializer\Annotation as Serializer;
*/ */
class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface
{ {
use TrackCreationTrait;
public const STATUS_READY = "ready"; public const STATUS_READY = "ready";
public const STATUS_PENDING = "pending"; public const STATUS_PENDING = "pending";
public const STATUS_FAILURE = "failure"; public const STATUS_FAILURE = "failure";
use TrackCreationTrait;
/** /**
* @ORM\Column(type="json", name="datas") * @ORM\Column(type="json", name="datas")
* @Serializer\Groups({"read", "write"}) * @Serializer\Groups({"read", "write"})

View File

@ -2,6 +2,13 @@
declare(strict_types=1); declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\DocStore; namespace Chill\Migrations\DocStore;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;

View File

@ -104,7 +104,8 @@ final class Editor
$this->engine $this->engine
->render('@ChillWopi/Editor/stored_object_failure.html.twig') ->render('@ChillWopi/Editor/stored_object_failure.html.twig')
); );
} elseif (StoredObject::STATUS_PENDING === $storedObject->getStatus()) { }
if (StoredObject::STATUS_PENDING === $storedObject->getStatus()) {
return new Response( return new Response(
$this->engine $this->engine
->render('@ChillWopi/Editor/stored_object_pending.html.twig', [ ->render('@ChillWopi/Editor/stored_object_pending.html.twig', [