php cs fixes

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

View File

@ -50,7 +50,7 @@ class LocationFilter implements FilterInterface
{ {
$builder->add('accepted_location', PickUserLocationType::class, [ $builder->add('accepted_location', PickUserLocationType::class, [
'multiple' => true, 'multiple' => true,
'label' => 'pick location' 'label' => 'pick location',
]); ]);
} }

View File

@ -1,10 +1,18 @@
<?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\AsideActivityBundle\Export\Export; namespace Chill\AsideActivityBundle\Export\Export;
use Chill\AsideActivityBundle\Entity\AsideActivity; use Chill\AsideActivityBundle\Entity\AsideActivity;
use Chill\AsideActivityBundle\Export\Declarations; use Chill\AsideActivityBundle\Export\Declarations;
use Chill\AsideActivityBundle\Form\AsideActivityCategoryType;
use Chill\AsideActivityBundle\Repository\AsideActivityCategoryRepository; use Chill\AsideActivityBundle\Repository\AsideActivityCategoryRepository;
use Chill\AsideActivityBundle\Security\AsideActivityVoter; use Chill\AsideActivityBundle\Security\AsideActivityVoter;
use Chill\AsideActivityBundle\Templating\Entity\CategoryRender; use Chill\AsideActivityBundle\Templating\Entity\CategoryRender;
@ -16,32 +24,32 @@ use Chill\MainBundle\Export\Helper\UserHelper;
use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Export\ListInterface;
use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Closure; use DateTimeInterface;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
final class ListAsideActivity implements ListInterface, GroupedExportInterface final class ListAsideActivity implements ListInterface, GroupedExportInterface
{ {
private EntityManagerInterface $em;
private UserHelper $userHelper;
private DateTimeHelper $dateTimeHelper;
private ScopeRepositoryInterface $scopeRepository;
private CenterRepositoryInterface $centerRepository;
private AsideActivityCategoryRepository $asideActivityCategoryRepository; private AsideActivityCategoryRepository $asideActivityCategoryRepository;
private CategoryRender $categoryRender; private CategoryRender $categoryRender;
private CenterRepositoryInterface $centerRepository;
private DateTimeHelper $dateTimeHelper;
private EntityManagerInterface $em;
private ScopeRepositoryInterface $scopeRepository;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
private UserHelper $userHelper;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
DateTimeHelper $dateTimeHelper, DateTimeHelper $dateTimeHelper,
@ -76,11 +84,6 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
return 'export.aside_activity.List of aside activities'; return 'export.aside_activity.List of aside activities';
} }
public function getTitle()
{
return 'export.aside_activity.List of aside activities';
}
public function getGroup(): string public function getGroup(): string
{ {
return 'export.Exports of aside activities'; return 'export.Exports of aside activities';
@ -91,15 +94,16 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
switch ($key) { switch ($key) {
case 'id': case 'id':
case 'note': case 'note':
return function ($value) use ($key) { return static function ($value) use ($key) {
if ('_header' === $value) { if ('_header' === $value) {
return 'export.aside_activity.' . $key; return 'export.aside_activity.' . $key;
} }
return $value ?? ''; return $value ?? '';
}; };
case 'duration': case 'duration':
return function ($value) use ($key) { return static function ($value) use ($key) {
if ('_header' === $value) { if ('_header' === $value) {
return 'export.aside_activity.' . $key; return 'export.aside_activity.' . $key;
} }
@ -108,7 +112,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
return ''; return '';
} }
if ($value instanceof \DateTimeInterface) { if ($value instanceof DateTimeInterface) {
return $value->format('H:i:s'); return $value->format('H:i:s');
} }
@ -118,7 +122,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
case 'createdAt': case 'createdAt':
case 'updatedAt': case 'updatedAt':
case 'date': case 'date':
return $this->dateTimeHelper->getLabel('export.aside_activity.'.$key); return $this->dateTimeHelper->getLabel('export.aside_activity.' . $key);
case 'agent_id': case 'agent_id':
case 'creator_id': case 'creator_id':
@ -165,7 +169,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
}; };
default: default:
throw new \LogicException('this key is not supported : ' . $key); throw new LogicException('this key is not supported : ' . $key);
} }
} }
@ -182,7 +186,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
'aside_activity_type', 'aside_activity_type',
'date', 'date',
'duration', 'duration',
'note' 'note',
]; ];
} }
@ -195,6 +199,11 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
return $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY); return $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);
} }
public function getTitle()
{
return 'export.aside_activity.List of aside activities';
}
public function getType(): string public function getType(): string
{ {
return Declarations::ASIDE_ACTIVITY_TYPE; return Declarations::ASIDE_ACTIVITY_TYPE;
@ -204,8 +213,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
{ {
$qb = $this->em->createQueryBuilder() $qb = $this->em->createQueryBuilder()
->from(AsideActivity::class, 'aside') ->from(AsideActivity::class, 'aside')
->leftJoin('aside.agent', 'agent') ->leftJoin('aside.agent', 'agent');
;
$qb $qb
->addSelect('aside.id AS id') ->addSelect('aside.id AS id')
@ -218,8 +226,7 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
->addSelect('IDENTITY(aside.type) AS aside_activity_type') ->addSelect('IDENTITY(aside.type) AS aside_activity_type')
->addSelect('aside.date') ->addSelect('aside.date')
->addSelect('aside.duration') ->addSelect('aside.duration')
->addSelect('aside.note') ->addSelect('aside.note');
;
return $qb; return $qb;
} }

View File

@ -17,7 +17,6 @@ use Chill\MainBundle\Form\Type\Export\FilterType;
use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;

View File

@ -15,7 +15,6 @@ use Chill\AsideActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\Entity\UserRender;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;

View File

@ -30,7 +30,7 @@ class ChargeKindType extends AbstractType
]) ])
->add('kind', TextType::class, [ ->add('kind', TextType::class, [
'label' => 'budget.admin.form.Charge_kind_key', 'label' => 'budget.admin.form.Charge_kind_key',
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document' 'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document',
]) ])
->add('ordering', NumberType::class) ->add('ordering', NumberType::class)
->add('isActive', CheckboxType::class, [ ->add('isActive', CheckboxType::class, [

View File

@ -30,7 +30,7 @@ class ResourceKindType extends AbstractType
]) ])
->add('kind', TextType::class, [ ->add('kind', TextType::class, [
'label' => 'budget.admin.form.Resource_kind_key', 'label' => 'budget.admin.form.Resource_kind_key',
'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document' 'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document',
]) ])
->add('ordering', NumberType::class) ->add('ordering', NumberType::class)
->add('isActive', CheckboxType::class, [ ->add('isActive', CheckboxType::class, [

View File

@ -49,8 +49,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
->where($qb->expr()->eq('c.isActive', 'true')) ->where($qb->expr()->eq('c.isActive', 'true'))
->orderBy('c.ordering', 'ASC') ->orderBy('c.ordering', 'ASC')
->getQuery() ->getQuery()
->getResult() ->getResult();
;
} }
/** /**

View File

@ -28,8 +28,6 @@ interface ChargeKindRepositoryInterface extends ObjectRepository
*/ */
public function findAllActive(): array; public function findAllActive(): array;
public function findOneByKind(string $kind): ?ChargeKind;
/** /**
* @return ChargeType[] * @return ChargeType[]
*/ */
@ -45,5 +43,7 @@ interface ChargeKindRepositoryInterface extends ObjectRepository
public function findOneBy(array $criteria): ?ChargeKind; public function findOneBy(array $criteria): ?ChargeKind;
public function findOneByKind(string $kind): ?ChargeKind;
public function getClassName(): string; public function getClassName(): string;
} }

View File

@ -49,8 +49,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
->where($qb->expr()->eq('r.isActive', 'true')) ->where($qb->expr()->eq('r.isActive', 'true'))
->orderBy('r.ordering', 'ASC') ->orderBy('r.ordering', 'ASC')
->getQuery() ->getQuery()
->getResult() ->getResult();
;
} }
/** /**

View File

@ -34,7 +34,7 @@ class ResourceRepository extends EntityRepository
//->andWhere('c.startDate < :date') //->andWhere('c.startDate < :date')
// TODO: there is a misconception here, the end date must be lower or null. startDate are never null // TODO: there is a misconception here, the end date must be lower or null. startDate are never null
//->andWhere('c.startDate < :date OR c.startDate IS NULL'); //->andWhere('c.startDate < :date OR c.startDate IS NULL');
; ;
if (null !== $sort) { if (null !== $sort) {
$qb->orderBy($sort); $qb->orderBy($sort);

View File

@ -13,9 +13,7 @@ namespace Chill\BudgetBundle\Service\Summary;
use Chill\BudgetBundle\Entity\ChargeKind; use Chill\BudgetBundle\Entity\ChargeKind;
use Chill\BudgetBundle\Entity\ResourceKind; use Chill\BudgetBundle\Entity\ResourceKind;
use Chill\BudgetBundle\Repository\ChargeKindRepository;
use Chill\BudgetBundle\Repository\ChargeKindRepositoryInterface; use Chill\BudgetBundle\Repository\ChargeKindRepositoryInterface;
use Chill\BudgetBundle\Repository\ResourceKindRepository;
use Chill\BudgetBundle\Repository\ResourceKindRepositoryInterface; use Chill\BudgetBundle\Repository\ResourceKindRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;

View File

@ -20,12 +20,15 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionClass;
use RuntimeException;
/** /**
* @internal * @internal
@ -47,10 +50,9 @@ final class SummaryBudgetTest extends TestCase
], ],
]); ]);
$queryCharges->setParameters(Argument::type('array')) $queryCharges->setParameters(Argument::type('array'))
->will(function ($args, $query) { ->will(static function ($args, $query) {
return $query; return $query;
}) });
;
$queryResources = $this->prophesize(AbstractQuery::class); $queryResources = $this->prophesize(AbstractQuery::class);
$queryResources->getResult()->willReturn([ $queryResources->getResult()->willReturn([
@ -61,23 +63,23 @@ final class SummaryBudgetTest extends TestCase
], ],
]); ]);
$queryResources->setParameters(Argument::type('array')) $queryResources->setParameters(Argument::type('array'))
->will(function ($args, $query) { ->will(static function ($args, $query) {
return $query; return $query;
}) });
;
$em = $this->prophesize(EntityManagerInterface::class); $em = $this->prophesize(EntityManagerInterface::class);
$em->createNativeQuery(Argument::type('string'), Argument::type(Query\ResultSetMapping::class)) $em->createNativeQuery(Argument::type('string'), Argument::type(Query\ResultSetMapping::class))
->will(function ($args) use ($queryResources, $queryCharges) { ->will(static function ($args) use ($queryResources, $queryCharges) {
if (false !== strpos($args[0], 'chill_budget.resource')) { if (false !== strpos($args[0], 'chill_budget.resource')) {
return $queryResources->reveal(); return $queryResources->reveal();
} }
if (false !== strpos($args[0], 'chill_budget.charge')) { if (false !== strpos($args[0], 'chill_budget.charge')) {
return $queryCharges->reveal(); return $queryCharges->reveal();
} }
throw new \RuntimeException('this query does not have a stub counterpart: '.$args[0]);
}) throw new RuntimeException('this query does not have a stub counterpart: ' . $args[0]);
; });
$chargeRepository = $this->prophesize(ChargeKindRepositoryInterface::class); $chargeRepository = $this->prophesize(ChargeKindRepositoryInterface::class);
$chargeRepository->findAll()->willReturn([ $chargeRepository->findAll()->willReturn([
@ -98,24 +100,23 @@ final class SummaryBudgetTest extends TestCase
$resourceRepository->findOneByKind('misc')->willReturn($misc); $resourceRepository->findOneByKind('misc')->willReturn($misc);
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class); $translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
$translatableStringHelper->localize(Argument::type('array'))->will(function ($arg) { $translatableStringHelper->localize(Argument::type('array'))->will(static function ($arg) {
return $arg[0]['fr']; return $arg[0]['fr'];
}); });
$person = new Person(); $person = new Person();
$personReflection = new \ReflectionClass($person); $personReflection = new ReflectionClass($person);
$personIdReflection = $personReflection->getProperty('id'); $personIdReflection = $personReflection->getProperty('id');
$personIdReflection->setAccessible(true); $personIdReflection->setAccessible(true);
$personIdReflection->setValue($person, 1); $personIdReflection->setValue($person, 1);
$household = new Household(); $household = new Household();
$householdReflection = new \ReflectionClass($household); $householdReflection = new ReflectionClass($household);
$householdId = $householdReflection->getProperty('id'); $householdId = $householdReflection->getProperty('id');
$householdId->setAccessible(true); $householdId->setAccessible(true);
$householdId->setValue($household, 1); $householdId->setValue($household, 1);
$householdMember = (new HouseholdMember())->setPerson($person) $householdMember = (new HouseholdMember())->setPerson($person)
->setStartDate(new \DateTimeImmutable('1 month ago')) ->setStartDate(new DateTimeImmutable('1 month ago'));
;
$household->addMember($householdMember); $household->addMember($householdMember);
$summaryBudget = new SummaryBudget( $summaryBudget = new SummaryBudget(

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\Budget; namespace Chill\Migrations\Budget;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
@ -9,6 +16,12 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20230209161546 extends AbstractMigration final class Version20230209161546 extends AbstractMigration
{ {
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX resource_kind_unique_type_idx');
$this->addSql('DROP INDEX charge_kind_unique_type_idx');
}
public function getDescription(): string public function getDescription(): string
{ {
return 'Budget: add unique constraint on kind for charge_kind and resource_kind'; return 'Budget: add unique constraint on kind for charge_kind and resource_kind';
@ -21,10 +34,4 @@ final class Version20230209161546 extends AbstractMigration
$this->addSql('CREATE UNIQUE INDEX resource_kind_unique_type_idx ON chill_budget.resource_type (kind);'); $this->addSql('CREATE UNIQUE INDEX resource_kind_unique_type_idx ON chill_budget.resource_type (kind);');
$this->addSql('CREATE UNIQUE INDEX charge_kind_unique_type_idx ON chill_budget.charge_type (kind);'); $this->addSql('CREATE UNIQUE INDEX charge_kind_unique_type_idx ON chill_budget.charge_type (kind);');
} }
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX resource_kind_unique_type_idx');
$this->addSql('DROP INDEX charge_kind_unique_type_idx');
}
} }

View File

@ -41,6 +41,7 @@ use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
use Throwable; use Throwable;
use function strlen; use function strlen;
use const JSON_PRETTY_PRINT;
final class DocGeneratorTemplateController extends AbstractController final class DocGeneratorTemplateController extends AbstractController
{ {
@ -273,7 +274,7 @@ final class DocGeneratorTemplateController extends AbstractController
if ($isTest && isset($form) && $form['show_data']->getData()) { if ($isTest && isset($form) && $form['show_data']->getData()) {
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),
]); ]);
} }

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

View File

@ -1,18 +1,33 @@
<?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 use RuntimeException;
use Throwable;
class GeneratorException extends RuntimeException
{ {
/** /**
* @var list<string> * @var list<string>
*/ */
private array $errors; private array $errors;
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,11 +1,22 @@
<?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 use RuntimeException;
class ObjectReadyException extends RuntimeException
{ {
public function __construct() public function __construct()
{ {
parent::__construct("object is already ready", 6698856); parent::__construct('object is already ready', 6698856);
} }
} }

View File

@ -1,14 +1,26 @@
<?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 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( 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\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
@ -7,13 +16,13 @@ use Chill\MainBundle\Entity\User;
class RequestGenerationMessage class RequestGenerationMessage
{ {
private int $creatorId; private int $creatorId;
private int $templateId; private string $entityClassName;
private int $entityId; private int $entityId;
private string $entityClassName; private int $templateId;
public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName) public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName)
{ {
@ -28,9 +37,9 @@ class RequestGenerationMessage
return $this->creatorId; return $this->creatorId;
} }
public function getTemplateId(): int public function getEntityClassName(): string
{ {
return $this->templateId; return $this->entityClassName;
} }
public function getEntityId(): int public function getEntityId(): int
@ -38,8 +47,8 @@ class RequestGenerationMessage
return $this->entityId; return $this->entityId;
} }
public function getEntityClassName(): string public function getTemplateId(): int
{ {
return $this->entityClassName; return $this->templateId;
} }
} }

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,60 +26,14 @@ use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
class GeneratorTest extends TestCase /**
* @internal
* @coversNothing
*/
final class GeneratorTest extends TestCase
{ {
use ProphecyTrait; use ProphecyTrait;
public function testSuccessfulGeneration(): void
{
$template = (new DocGeneratorTemplate())->setFile($templateStoredObject = (new StoredObject())
->setType('application/test'));
$destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_PENDING);
$entity = new class {};
$data = [];
$context = $this->prophesize(DocGeneratorContextInterface::class);
$context->getData($template, $entity, Argument::type('array'))->willReturn($data);
$context->storeGenerated($template, $destinationStoredObject, $entity, Argument::type('array'))
->shouldBeCalled();
$context->getName()->willReturn('dummy_context');
$context->getEntityClass()->willReturn('DummyClass');
$context = $context->reveal();
$contextManagerInterface = $this->prophesize(ContextManagerInterface::class);
$contextManagerInterface->getContextByDocGeneratorTemplate($template)
->willReturn($context);
$driver = $this->prophesize(DriverInterface::class);
$driver->generateFromString('template', 'application/test', $data, Argument::any())
->willReturn('generated');
$entityManager = $this->prophesize(EntityManagerInterface::class);
$entityManager->find(Argument::type('string'), Argument::type('int'))
->willReturn($entity);
$entityManager->flush()->shouldBeCalled();
$storedObjectManager = $this->prophesize(StoredObjectManagerInterface::class);
$storedObjectManager->read($templateStoredObject)->willReturn('template');
$storedObjectManager->write($destinationStoredObject, 'generated')->shouldBeCalled();
$generator = new Generator(
$contextManagerInterface->reveal(),
$driver->reveal(),
$entityManager->reveal(),
new NullLogger(),
$storedObjectManager->reveal()
);
$generator->generateDocFromTemplate(
$template,
'DummyEntity',
1,
$destinationStoredObject
);
}
public function testPreventRegenerateDocument(): void public function testPreventRegenerateDocument(): void
{ {
$this->expectException(ObjectReadyException::class); $this->expectException(ObjectReadyException::class);
@ -131,4 +94,54 @@ class GeneratorTest extends TestCase
$destinationStoredObject $destinationStoredObject
); );
} }
public function testSuccessfulGeneration(): void
{
$template = (new DocGeneratorTemplate())->setFile($templateStoredObject = (new StoredObject())
->setType('application/test'));
$destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_PENDING);
$entity = new class() {
};
$data = [];
$context = $this->prophesize(DocGeneratorContextInterface::class);
$context->getData($template, $entity, Argument::type('array'))->willReturn($data);
$context->storeGenerated($template, $destinationStoredObject, $entity, Argument::type('array'))
->shouldBeCalled();
$context->getName()->willReturn('dummy_context');
$context->getEntityClass()->willReturn('DummyClass');
$context = $context->reveal();
$contextManagerInterface = $this->prophesize(ContextManagerInterface::class);
$contextManagerInterface->getContextByDocGeneratorTemplate($template)
->willReturn($context);
$driver = $this->prophesize(DriverInterface::class);
$driver->generateFromString('template', 'application/test', $data, Argument::any())
->willReturn('generated');
$entityManager = $this->prophesize(EntityManagerInterface::class);
$entityManager->find(Argument::type('string'), Argument::type('int'))
->willReturn($entity);
$entityManager->flush()->shouldBeCalled();
$storedObjectManager = $this->prophesize(StoredObjectManagerInterface::class);
$storedObjectManager->read($templateStoredObject)->willReturn('template');
$storedObjectManager->write($destinationStoredObject, 'generated')->shouldBeCalled();
$generator = new Generator(
$contextManagerInterface->reveal(),
$driver->reveal(),
$entityManager->reveal(),
new NullLogger(),
$storedObjectManager->reveal()
);
$generator->generateDocFromTemplate(
$template,
'DummyEntity',
1,
$destinationStoredObject
);
}
} }

View File

@ -18,6 +18,7 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use DateTime; use DateTime;
use DateTimeImmutable;
use DateTimeInterface; use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
@ -35,12 +36,14 @@ use Symfony\Component\Serializer\Annotation as Serializer;
*/ */
class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface
{ {
public const STATUS_READY = "ready";
public const STATUS_PENDING = "pending";
public const STATUS_FAILURE = "failure";
use TrackCreationTrait; use TrackCreationTrait;
public const STATUS_FAILURE = 'failure';
public const STATUS_PENDING = 'pending';
public const STATUS_READY = 'ready';
/** /**
* @ORM\Column(type="datetime", name="creation_date") * @ORM\Column(type="datetime", name="creation_date")
* @Serializer\Groups({"read", "write"}) * @Serializer\Groups({"read", "write"})
@ -80,6 +83,16 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
*/ */
private array $keyInfos = []; private array $keyInfos = [];
/**
* @ORM\Column(type="text", options={"default": "ready"})
*/
private string $status;
/**
* @ORM\ManyToOne(targetEntity=DocGeneratorTemplate::class)
*/
private ?DocGeneratorTemplate $template;
/** /**
* @ORM\Column(type="text", name="title") * @ORM\Column(type="text", name="title")
* @Serializer\Groups({"read", "write"}) * @Serializer\Groups({"read", "write"})
@ -98,20 +111,10 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
*/ */
private UuidInterface $uuid; private UuidInterface $uuid;
/**
* @ORM\ManyToOne(targetEntity=DocGeneratorTemplate::class)
*/
private ?DocGeneratorTemplate $template;
/**
* @ORM\Column(type="text", options={"default": "ready"})
*/
private string $status;
/** /**
* @param StoredObject::STATUS_* $status * @param StoredObject::STATUS_* $status
*/ */
public function __construct(string $status = "ready") public function __construct(string $status = 'ready')
{ {
$this->uuid = Uuid::uuid4(); $this->uuid = Uuid::uuid4();
$this->status = $status; $this->status = $status;
@ -188,7 +191,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa
*/ */
public function setCreationDate(DateTime $creationDate): self public function setCreationDate(DateTime $creationDate): self
{ {
$this->createdAt = \DateTimeImmutable::createFromMutable($creationDate); $this->createdAt = DateTimeImmutable::createFromMutable($creationDate);
return $this; return $this;
} }

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export; namespace Chill\MainBundle\Export;
use Closure;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
/** /**

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export\Helper; namespace Chill\MainBundle\Export\Helper;
use DateTime; use DateTime;
use DateTimeInterface;
use Exception; use Exception;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
@ -35,7 +36,7 @@ class DateTimeHelper
return ''; return '';
} }
if ($value instanceof \DateTimeInterface) { if ($value instanceof DateTimeInterface) {
return $value; return $value;
} }

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;

View File

@ -24,10 +24,36 @@ use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
class ParticipationOverlapValidatorTest extends ConstraintValidatorTestCase /**
* @internal
* @coversNothing
*/
final class ParticipationOverlapValidatorTest extends ConstraintValidatorTestCase
{ {
use ProphecyTrait; use ProphecyTrait;
/**
* @return mixed
*/
public function getConstraint()
{
return new ParticipationOverlap();
}
public function testOneParticipation()
{
$period = new AccompanyingPeriod();
$person = new Person();
$collection = new ArrayCollection([
new AccompanyingPeriodParticipation($period, $person),
]);
$this->validator->validate($collection, $this->getConstraint());
$this->assertNoViolation();
}
protected function createValidator() protected function createValidator()
{ {
$personRender = $this->prophesize(PersonRenderInterface::class); $personRender = $this->prophesize(PersonRenderInterface::class);
@ -37,26 +63,4 @@ class ParticipationOverlapValidatorTest extends ConstraintValidatorTestCase
return new ParticipationOverlapValidator($personRender->reveal(), $thirdPartyRender->reveal()); return new ParticipationOverlapValidator($personRender->reveal(), $thirdPartyRender->reveal());
} }
public function testOneParticipation()
{
$period = new AccompanyingPeriod();
$person = new Person();
$collection = new ArrayCollection([
new AccompanyingPeriodParticipation($period, $person)
]);
$this->validator->validate($collection, $this->getConstraint());
$this->assertNoViolation();
}
/**
* @return mixed
*/
public function getConstraint()
{
return new ParticipationOverlap();
}
} }