php cs fixes

This commit is contained in:
2023-02-22 11:54:03 +01:00
parent 1f4438690e
commit f07ea3259e
25 changed files with 273 additions and 186 deletions

View File

@@ -1,5 +1,14 @@
<?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;
use Chill\DocGeneratorBundle\Context\ContextManagerInterface;
@@ -9,8 +18,10 @@ use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\File\File;
use Throwable;
class Generator
{
@@ -41,18 +52,20 @@ class Generator
/**
* @template T of File|null
* @template B of bool
*
* @param B $isTest
* @param (B is true ? T : null) $testFile
* @psalm-return (B is true ? string : null)
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable
*
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|Throwable
*/
public function generateDocFromTemplate(
DocGeneratorTemplate $template,
string $entityClassName,
int $entityId,
?StoredObject $destinationStoredObject = null,
bool $isTest = false,
?File $testFile = null
string $entityClassName,
int $entityId,
?StoredObject $destinationStoredObject = null,
bool $isTest = false,
?File $testFile = null
): ?string {
if ($destinationStoredObject instanceof StoredObject && StoredObject::STATUS_PENDING !== $destinationStoredObject->getStatus()) {
throw new ObjectReadyException();
@@ -63,8 +76,7 @@ class Generator
$entity = $this
->entityManager
->find($context->getEntityClass(), $entityId)
;
->find($context->getEntityClass(), $entityId);
if (null === $entity) {
throw new RelatedEntityNotFoundException($entityClassName, $entityId);
@@ -97,8 +109,7 @@ class Generator
$destinationStoredObject
->setType($template->getFile()->getType())
->setFilename(sprintf('%s_odt', uniqid('doc_', true)))
->setStatus(StoredObject::STATUS_READY)
;
->setStatus(StoredObject::STATUS_READY);
$this->storedObjectManager->write($destinationStoredObject, $generatedResource);
@@ -110,7 +121,7 @@ class Generator
$entity,
$contextGenerationData
);
} catch (\Exception $e) {
} catch (Exception $e) {
$this
->logger
->error(

View File

@@ -1,18 +1,33 @@
<?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;
class GeneratorException extends \RuntimeException
use RuntimeException;
use Throwable;
class GeneratorException extends RuntimeException
{
/**
* @var list<string>
*/
private array $errors;
public function __construct(array $errors = [], \Throwable $previous = null)
public function __construct(array $errors = [], ?Throwable $previous = null)
{
$this->errors = $errors;
parent::__construct("Could not generate the document", 15252,
$previous);
parent::__construct(
'Could not generate the document',
15252,
$previous
);
}
}

View File

@@ -1,11 +1,22 @@
<?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;
class ObjectReadyException extends \RuntimeException
use RuntimeException;
class ObjectReadyException extends RuntimeException
{
public function __construct()
{
parent::__construct("object is already ready", 6698856);
parent::__construct('object is already ready', 6698856);
}
}

View File

@@ -1,14 +1,26 @@
<?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;
class RelatedEntityNotFoundException extends \RuntimeException
use 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),
sprintf('Related entity not found: %s, %s', $relatedEntityClass, $relatedEntityId),
99876652,
$previous);
$previous
);
}
}