mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 00:53:48 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -77,7 +77,7 @@ class FetchQuery implements FetchQueryInterface
|
||||
public function removeWhereClause(int $index): void
|
||||
{
|
||||
if (!array_key_exists($index, $this->wheres)) {
|
||||
throw new \UnexpectedValueException("this index does not exists");
|
||||
throw new \UnexpectedValueException('this index does not exists');
|
||||
}
|
||||
|
||||
unset($this->wheres[$index], $this->whereParams[$index], $this->whereTypes[$index]);
|
||||
@@ -86,7 +86,7 @@ class FetchQuery implements FetchQueryInterface
|
||||
public function removeJoinClause(int $index): void
|
||||
{
|
||||
if (!array_key_exists($index, $this->joins)) {
|
||||
throw new \UnexpectedValueException("this index does not exists");
|
||||
throw new \UnexpectedValueException('this index does not exists');
|
||||
}
|
||||
|
||||
unset($this->joins[$index], $this->joinParams[$index], $this->joinTypes[$index]);
|
||||
@@ -102,9 +102,6 @@ class FetchQuery implements FetchQueryInterface
|
||||
return $this->selectIdentifierJsonB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSelectIdentifierParams(): array
|
||||
{
|
||||
return $this->selectIdentifierParams;
|
||||
@@ -125,9 +122,6 @@ class FetchQuery implements FetchQueryInterface
|
||||
return $this->selectDateTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSelectDateParams(): array
|
||||
{
|
||||
return $this->selectDateParams;
|
||||
@@ -135,12 +129,9 @@ class FetchQuery implements FetchQueryInterface
|
||||
|
||||
public function getFromQuery(): string
|
||||
{
|
||||
return $this->from . " " . implode(' ', $this->joins);
|
||||
return $this->from.' '.implode(' ', $this->joins);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFromQueryParams(): array
|
||||
{
|
||||
$result = [];
|
||||
@@ -168,9 +159,6 @@ class FetchQuery implements FetchQueryInterface
|
||||
return implode(' AND ', $this->wheres);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWhereQueryParams(): array
|
||||
{
|
||||
$result = [];
|
||||
|
@@ -34,14 +34,14 @@ final readonly class FetchQueryToSqlBuilder
|
||||
'{{ identifiers }}' => $query->getSelectIdentifierJsonB(),
|
||||
'{{ date }}' => $query->getSelectDate(),
|
||||
'{{ from }}' => $query->getFromQuery(),
|
||||
'{{ where }}' => '' === ($w = $query->getWhereQuery()) ? '' : 'WHERE ' . $w,
|
||||
'{{ where }}' => '' === ($w = $query->getWhereQuery()) ? '' : 'WHERE '.$w,
|
||||
]);
|
||||
|
||||
$params = [
|
||||
...$query->getSelectIdentifierParams(),
|
||||
...$query->getSelectDateParams(),
|
||||
...$query->getFromQueryParams(),
|
||||
...$query->getWhereQueryParams()
|
||||
...$query->getWhereQueryParams(),
|
||||
];
|
||||
|
||||
$types = [
|
||||
|
@@ -17,10 +17,10 @@ interface GenericDocForAccompanyingPeriodProviderInterface
|
||||
{
|
||||
public function buildFetchQueryForAccompanyingPeriod(
|
||||
AccompanyingPeriod $accompanyingPeriod,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
?string $origin = null
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
string $origin = null
|
||||
): FetchQueryInterface;
|
||||
|
||||
/**
|
||||
|
@@ -12,16 +12,15 @@ declare(strict_types=1);
|
||||
namespace Chill\DocStoreBundle\GenericDoc;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
|
||||
interface GenericDocForPersonProviderInterface
|
||||
{
|
||||
public function buildFetchQueryForPerson(
|
||||
Person $person,
|
||||
?DateTimeImmutable $startDate = null,
|
||||
?DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
?string $origin = null
|
||||
Person $person,
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
string $origin = null
|
||||
): FetchQueryInterface;
|
||||
|
||||
/**
|
||||
|
@@ -38,13 +38,14 @@ final readonly class Manager
|
||||
|
||||
/**
|
||||
* @param list<string> $places
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function countDocForAccompanyingPeriod(
|
||||
AccompanyingPeriod $accompanyingPeriod,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
array $places = []
|
||||
): int {
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = $this->buildUnionQuery($accompanyingPeriod, $startDate, $endDate, $content, $places);
|
||||
@@ -54,7 +55,7 @@ final readonly class Manager
|
||||
|
||||
private function countDoc(string $sql, array $params, array $types): int
|
||||
{
|
||||
if ($sql === '') {
|
||||
if ('' === $sql) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ final readonly class Manager
|
||||
$number = $result->fetchOne();
|
||||
|
||||
if (false === $number) {
|
||||
throw new \UnexpectedValueException("number of documents failed to load");
|
||||
throw new \UnexpectedValueException('number of documents failed to load');
|
||||
}
|
||||
|
||||
return $number;
|
||||
@@ -72,9 +73,9 @@ final readonly class Manager
|
||||
|
||||
public function countDocForPerson(
|
||||
Person $person,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
array $places = []
|
||||
): int {
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = $this->buildUnionQuery($person, $startDate, $endDate, $content, $places);
|
||||
@@ -84,16 +85,18 @@ final readonly class Manager
|
||||
|
||||
/**
|
||||
* @param list<string> $places places to search. When empty, search in all places
|
||||
*
|
||||
* @return iterable<GenericDocDTO>
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function findDocForAccompanyingPeriod(
|
||||
AccompanyingPeriod $accompanyingPeriod,
|
||||
int $offset = 0,
|
||||
int $limit = 20,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
array $places = []
|
||||
): iterable {
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = $this->buildUnionQuery($accompanyingPeriod, $startDate, $endDate, $content, $places);
|
||||
@@ -107,7 +110,7 @@ final readonly class Manager
|
||||
*/
|
||||
private function findDocs(AccompanyingPeriod|Person $linked, string $sql, array $params, array $types, int $offset, int $limit): iterable
|
||||
{
|
||||
if ($sql === '') {
|
||||
if ('' === $sql) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -127,15 +130,16 @@ final readonly class Manager
|
||||
|
||||
/**
|
||||
* @param list<string> $places places to search. When empty, search in all places
|
||||
*
|
||||
* @return iterable<GenericDocDTO>
|
||||
*/
|
||||
public function findDocForPerson(
|
||||
Person $person,
|
||||
int $offset = 0,
|
||||
int $limit = 20,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
array $places = []
|
||||
): iterable {
|
||||
['sql' => $sql, 'params' => $params, 'types' => $types] = $this->buildUnionQuery($person, $startDate, $endDate, $content, $places);
|
||||
@@ -159,7 +163,7 @@ final readonly class Manager
|
||||
|
||||
private function places(string $sql, array $params, array $types): array
|
||||
{
|
||||
if ($sql === '') {
|
||||
if ('' === $sql) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -179,9 +183,9 @@ final readonly class Manager
|
||||
*/
|
||||
private function buildUnionQuery(
|
||||
AccompanyingPeriod|Person $linked,
|
||||
?\DateTimeImmutable $startDate = null,
|
||||
?\DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
array $places = [],
|
||||
): array {
|
||||
$queries = [];
|
||||
@@ -210,7 +214,7 @@ final readonly class Manager
|
||||
continue;
|
||||
}
|
||||
|
||||
['sql' => $q, 'params' => $p, 'types' => $t ] = $this->builder->toSql($query);
|
||||
['sql' => $q, 'params' => $p, 'types' => $t] = $this->builder->toSql($query);
|
||||
|
||||
$sql[] = $q;
|
||||
$params = [...$params, ...$p];
|
||||
|
@@ -20,7 +20,6 @@ use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
@@ -34,7 +33,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
private EntityManagerInterface $entityManager,
|
||||
) {}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, \DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null, string $origin = null): FetchQueryInterface
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingCourseDocument::class);
|
||||
|
||||
@@ -42,7 +41,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
self::KEY,
|
||||
sprintf('jsonb_build_object(\'id\', %s)', $classMetadata->getIdentifierColumnNames()[0]),
|
||||
$classMetadata->getColumnName('date'),
|
||||
$classMetadata->getSchemaName() . '.' . $classMetadata->getTableName()
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName()
|
||||
);
|
||||
|
||||
$query->addWhereClause(
|
||||
@@ -59,7 +58,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
return $this->security->isGranted(AccompanyingCourseDocumentVoter::SEE, $accompanyingPeriod);
|
||||
}
|
||||
|
||||
public function buildFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
public function buildFetchQueryForPerson(Person $person, \DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null, string $origin = null): FetchQueryInterface
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingCourseDocument::class);
|
||||
|
||||
@@ -67,7 +66,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
self::KEY,
|
||||
sprintf('jsonb_build_object(\'id\', %s)', $classMetadata->getIdentifierColumnNames()[0]),
|
||||
$classMetadata->getColumnName('date'),
|
||||
$classMetadata->getSchemaName() . '.' . $classMetadata->getTableName() . ' AS acc_course_document'
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS acc_course_document'
|
||||
);
|
||||
|
||||
$atLeastOne = false;
|
||||
@@ -98,7 +97,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
return $query;
|
||||
}
|
||||
|
||||
$query->addWhereClause('(' . implode(' OR ', $or) . ')', $orParams, $orTypes);
|
||||
$query->addWhereClause('('.implode(' OR ', $or).')', $orParams, $orTypes);
|
||||
|
||||
return $this->addWhereClause($query, $startDate, $endDate, $content);
|
||||
}
|
||||
@@ -108,7 +107,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
return $this->security->isGranted(AccompanyingPeriodVoter::SEE, $person);
|
||||
}
|
||||
|
||||
private function addWhereClause(FetchQuery $query, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery
|
||||
private function addWhereClause(FetchQuery $query, \DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null): FetchQuery
|
||||
{
|
||||
$classMetadata = $this->entityManager->getClassMetadata(AccompanyingCourseDocument::class);
|
||||
|
||||
@@ -135,7 +134,7 @@ final readonly class AccompanyingCourseDocumentGenericDocProvider implements Gen
|
||||
$classMetadata->getColumnName('title'),
|
||||
$classMetadata->getColumnName('description')
|
||||
),
|
||||
['%' . $content . '%', '%' . $content . '%'],
|
||||
['%'.$content.'%', '%'.$content.'%'],
|
||||
[Types::STRING, Types::STRING]
|
||||
);
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ use Chill\DocStoreBundle\Repository\PersonDocumentACLAwareRepositoryInterface;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final readonly class PersonDocumentGenericDocProvider implements GenericDocForPersonProviderInterface, GenericDocForAccompanyingPeriodProviderInterface
|
||||
@@ -32,10 +31,10 @@ final readonly class PersonDocumentGenericDocProvider implements GenericDocForPe
|
||||
|
||||
public function buildFetchQueryForPerson(
|
||||
Person $person,
|
||||
?DateTimeImmutable $startDate = null,
|
||||
?DateTimeImmutable $endDate = null,
|
||||
?string $content = null,
|
||||
?string $origin = null
|
||||
\DateTimeImmutable $startDate = null,
|
||||
\DateTimeImmutable $endDate = null,
|
||||
string $content = null,
|
||||
string $origin = null
|
||||
): FetchQueryInterface {
|
||||
return $this->personDocumentACLAwareRepository->buildFetchQueryForPerson(
|
||||
$person,
|
||||
@@ -50,7 +49,7 @@ final readonly class PersonDocumentGenericDocProvider implements GenericDocForPe
|
||||
return $this->security->isGranted(PersonDocumentVoter::SEE, $person);
|
||||
}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, \DateTimeImmutable $startDate = null, \DateTimeImmutable $endDate = null, string $content = null, string $origin = null): FetchQueryInterface
|
||||
{
|
||||
return $this->personDocumentACLAwareRepository->buildFetchQueryForAccompanyingPeriod($accompanyingPeriod, $startDate, $endDate, $content);
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface;
|
||||
use Chill\DocStoreBundle\GenericDoc\Providers\AccompanyingCourseDocumentGenericDocProvider;
|
||||
use Chill\DocStoreBundle\Repository\AccompanyingCourseDocumentRepository;
|
||||
use Chill\DocStoreBundle\Repository\PersonDocumentRepository;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
|
||||
final readonly class AccompanyingCourseDocumentGenericDocRenderer implements GenericDocRendererInterface
|
||||
{
|
||||
@@ -28,8 +27,8 @@ final readonly class AccompanyingCourseDocumentGenericDocRenderer implements Gen
|
||||
|
||||
public function supports(GenericDocDTO $genericDocDTO, $options = []): bool
|
||||
{
|
||||
return $genericDocDTO->key === AccompanyingCourseDocumentGenericDocProvider::KEY
|
||||
|| $genericDocDTO->key === PersonDocumentGenericDocProvider::KEY;
|
||||
return AccompanyingCourseDocumentGenericDocProvider::KEY === $genericDocDTO->key
|
||||
|| PersonDocumentGenericDocProvider::KEY === $genericDocDTO->key;
|
||||
}
|
||||
|
||||
public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string
|
||||
@@ -47,6 +46,7 @@ final readonly class AccompanyingCourseDocumentGenericDocRenderer implements Gen
|
||||
'context' => $genericDocDTO->getContext(),
|
||||
];
|
||||
}
|
||||
|
||||
// this is a person
|
||||
return [
|
||||
'document' => $doc = $this->personDocumentRepository->find($genericDocDTO->identifiers['id']),
|
||||
|
@@ -22,7 +22,7 @@ final class GenericDocExtension extends AbstractExtension
|
||||
new TwigFilter('chill_generic_doc_render', [GenericDocExtensionRuntime::class, 'renderGenericDoc'], [
|
||||
'needs_environment' => true,
|
||||
'is_safe' => ['html'],
|
||||
])
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -43,6 +43,6 @@ final readonly class GenericDocExtensionRuntime implements RuntimeExtensionInter
|
||||
}
|
||||
}
|
||||
|
||||
throw new \LogicException("no renderer found");
|
||||
throw new \LogicException('no renderer found');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user