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

@@ -17,22 +17,16 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\TaskBundle\Entity\SingleTask;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use DateInterval;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Security\Core\Security;
use function count;
use function substr;
final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepositoryInterface
{
public function __construct(private CenterResolverManagerInterface $centerResolverDispatcher, private EntityManagerInterface $em, private Security $security, private AuthorizationHelperInterface $authorizationHelper) {}
public function buildBaseQuery(
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = []
@@ -43,18 +37,18 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
if (null !== $pattern && '' !== $pattern) {
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(t.title))', 'LOWER(UNACCENT(:pattern))'))
->setParameter('pattern', '%' . $pattern . '%');
->setParameter('pattern', '%'.$pattern.'%');
}
if (null !== $users && count($users) > 0) {
if (null !== $users && \count($users) > 0) {
$orXUser = $qb->expr()->orX();
foreach ($users as $key => $user) {
$orXUser->add(
$qb->expr()->eq('t.assignee', ':user_' . $key)
$qb->expr()->eq('t.assignee', ':user_'.$key)
);
$qb->setParameter('user_' . $key, $user);
$qb->setParameter('user_'.$key, $user);
}
if ($orXUser->count() > 0) {
@@ -62,16 +56,16 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
}
}
if (null !== $types && count($types) > 0) {
if (null !== $types && \count($types) > 0) {
$qb->andWhere($qb->expr()->in('t.type', ':types'));
$qb->setParameter('types', $types);
}
if (null !== $flags && count($flags) > 0) {
if (null !== $flags && \count($flags) > 0) {
$orXDate = $qb->expr()->orX();
$orXState = $qb->expr()->orX();
$now = new DateTime();
$now = new \DateTime();
foreach ($flags as $key => $flag) {
switch ($flag) {
@@ -84,7 +78,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
)
);
$qb
->setParameter('intervalBlank', new DateInterval('P0D'))
->setParameter('intervalBlank', new \DateInterval('P0D'))
->setParameter('now', $now);
break;
@@ -126,7 +120,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
break;
case str_starts_with((string) $flag, 'state_'):
$state = substr((string) $flag, 6);
$state = \substr((string) $flag, 6);
$orXState
->add(
"JSONB_EXISTS_IN_ARRAY(t.currentStates, :state_{$key}) = 'TRUE'"
@@ -136,7 +130,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
break;
default:
throw new LogicException("this flag is not supported: {$flag}");
throw new \LogicException("this flag is not supported: {$flag}");
}
}
@@ -154,7 +148,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function buildQueryByCourse(
AccompanyingPeriod $course,
?string $pattern = null,
string $pattern = null,
?array $flags = []
): QueryBuilder {
$qb = $this->buildBaseQuery($pattern, $flags);
@@ -166,7 +160,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function buildQueryByPerson(
Person $person,
?string $pattern = null,
string $pattern = null,
?array $flags = []
): QueryBuilder {
$qb = $this->buildBaseQuery($pattern, $flags);
@@ -177,7 +171,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
}
public function buildQueryMyTasks(
?string $pattern = null,
string $pattern = null,
?array $flags = []
): QueryBuilder {
$qb = $this->buildBaseQuery($pattern, $flags);
@@ -188,7 +182,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
}
public function countByAllViewable(
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = []
@@ -203,7 +197,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function countByCourse(
AccompanyingPeriod $course,
?string $pattern = null,
string $pattern = null,
?array $flags = []
): int {
$qb = $this->buildQueryByCourse($course, $pattern, $flags);
@@ -215,7 +209,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
}
public function countByCurrentUsersTasks(
?string $pattern = null,
string $pattern = null,
?array $flags = []
): int {
return $this->buildQueryMyTasks($pattern, $flags)
@@ -225,7 +219,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function countByPerson(
Person $person,
?string $pattern = null,
string $pattern = null,
?array $flags = []
): int {
$qb = $this->buildQueryByPerson($person, $pattern, $flags);
@@ -237,7 +231,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
}
public function findByAllViewable(
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = [],
@@ -253,7 +247,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function findByCourse(
AccompanyingPeriod $course,
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?int $start = 0,
?int $limit = 50,
@@ -266,7 +260,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
}
public function findByCurrentUsersTasks(
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?int $start = 0,
?int $limit = 50,
@@ -279,7 +273,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
public function findByPerson(
Person $person,
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?int $start = 0,
?int $limit = 50,
@@ -304,7 +298,7 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
->setMaxResults($limit);
foreach ($orderBy as $field => $direction) {
$qb->addOrderBy('t.' . $field, $direction);
$qb->addOrderBy('t.'.$field, $direction);
}
return $qb->getQuery()->getResult();
@@ -360,14 +354,14 @@ final readonly class SingleTaskAclAwareRepository implements SingleTaskAclAwareR
$and = $qb->expr()->andX(
$qb->expr()->orX(
$qb->expr()->eq('center_current_person.center', ':center_' . $k),
$qb->expr()->eq('center_current_participation.center', ':center_' . $k)
$qb->expr()->eq('center_current_person.center', ':center_'.$k),
$qb->expr()->eq('center_current_participation.center', ':center_'.$k)
),
$qb->expr()->in('t.circle', ':scopes_' . $k)
$qb->expr()->in('t.circle', ':scopes_'.$k)
);
$qb
->setParameter('center_' . $k, $center)
->setParameter('scopes_' . $k, $allowedScopes);
->setParameter('center_'.$k, $center)
->setParameter('scopes_'.$k, $allowedScopes);
$orX->add($and);
++$k;

View File

@@ -17,7 +17,7 @@ use Chill\PersonBundle\Entity\Person;
interface SingleTaskAclAwareRepositoryInterface
{
public function countByAllViewable(
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = []
@@ -25,20 +25,20 @@ interface SingleTaskAclAwareRepositoryInterface
public function countByCourse(
AccompanyingPeriod $course,
?string $pattern = null,
string $pattern = null,
?array $flags = []
): int;
public function countByCurrentUsersTasks(?string $pattern = null, ?array $flags = []): int;
public function countByCurrentUsersTasks(string $pattern = null, ?array $flags = []): int;
public function countByPerson(
Person $person,
?string $pattern = null,
string $pattern = null,
?array $flags = []
): int;
public function findByAllViewable(
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?array $types = [],
?array $users = [],
@@ -49,18 +49,18 @@ interface SingleTaskAclAwareRepositoryInterface
public function findByCourse(
AccompanyingPeriod $course,
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?int $start = 0,
?int $limit = 50,
?array $orderBy = []
): array;
public function findByCurrentUsersTasks(?string $pattern = null, ?array $flags = [], ?int $start = 0, ?int $limit = 50, ?array $orderBy = []): array;
public function findByCurrentUsersTasks(string $pattern = null, ?array $flags = [], ?int $start = 0, ?int $limit = 50, ?array $orderBy = []): array;
public function findByPerson(
Person $person,
?string $pattern = null,
string $pattern = null,
?array $flags = [],
?int $start = 0,
?int $limit = 50,

View File

@@ -15,15 +15,9 @@ use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Security\Core\Role\Role;
use UnexpectedValueException;
use function array_key_exists;
use function count;
/**
@@ -59,11 +53,10 @@ class SingleTaskRepository extends EntityRepository
* @see SingleTaskRepository::filterByParameters
*
* @param array $params
* @param User $currentUser
*
* @return int
*/
public function countByParameters($params, ?User $currentUser = null)
public function countByParameters($params, User $currentUser = null)
{
$qb = $this->createQueryBuilder('st')
->select('COUNT(st)');
@@ -146,17 +139,14 @@ class SingleTaskRepository extends EntityRepository
->add($this->buildNowIsAfterWarningDate($qb, true))
->add($this->buildNowIsAfterStartDate($qb, true));
}
$qb->setParameter('now', new DateTime('today'), Types::DATE_MUTABLE);
$qb->setParameter('now', new \DateTime('today'), Types::DATE_MUTABLE);
$qb->andWhere($andWhere);
}
protected function buildACLQuery(QueryBuilder $qb, User $currentUser)
{
if (null === $this->authorizationHelper) {
throw new LogicException('Injecting the authorization helper is '
. 'required to run this query. Please use dependency injection '
. 'to initialize this repository or use the method '
. '`setAuthorizationHelper`');
throw new \LogicException('Injecting the authorization helper is required to run this query. Please use dependency injection to initialize this repository or use the method `setAuthorizationHelper`');
}
$role = TaskVoter::SHOW;
@@ -174,10 +164,10 @@ class SingleTaskRepository extends EntityRepository
$centerWhere = $qb->expr()->andX();
$centerWhere->add($qb->expr()->eq('p.center', ':center_' . $i));
$qb->setParameter('center_' . $i, $center);
$centerWhere->add($qb->expr()->in('st.circle', ':circles_' . $i));
$qb->setParameter('circles_' . $i, $circles);
$centerWhere->add($qb->expr()->eq('p.center', ':center_'.$i));
$qb->setParameter('center_'.$i, $center);
$centerWhere->add($qb->expr()->in('st.circle', ':circles_'.$i));
$qb->setParameter('circles_'.$i, $circles);
$where->add($centerWhere);
++$i;
}
@@ -185,56 +175,55 @@ class SingleTaskRepository extends EntityRepository
$qb->where($where);
}
protected function buildQuery(QueryBuilder $qb, $params, ?User $currentUser = null)
protected function buildQuery(QueryBuilder $qb, $params, User $currentUser = null)
{
if (null !== $currentUser) {
$this->buildACLQuery($qb, $currentUser);
}
if (array_key_exists('person', $params) && !empty($params['person'])) {
if (\array_key_exists('person', $params) && !empty($params['person'])) {
$qb->andWhere($qb->expr()->eq('st.person', ':person'));
$qb->setParameter('person', $params['person']);
} elseif (array_key_exists('center', $params)) {
} elseif (\array_key_exists('center', $params)) {
if ($params['center'] instanceof Center) {
$qb->join('st.person', 'person');
$qb->andWhere($qb->expr()->eq('person.center', ':center'));
$qb->setParameter('center', $params['center']);
} else {
throw new UnexpectedValueException("params 'center' should be an instance of " . Center::class);
throw new \UnexpectedValueException("params 'center' should be an instance of ".Center::class);
}
}
if (array_key_exists('unassigned', $params) && true === $params['unassigned']) {
if (array_key_exists('user', $params) && !empty($params['user'])) {
throw new UnexpectedValueException('You should not require for '
. 'unassigned tasks and tasks assigned to some user.');
if (\array_key_exists('unassigned', $params) && true === $params['unassigned']) {
if (\array_key_exists('user', $params) && !empty($params['user'])) {
throw new \UnexpectedValueException('You should not require for unassigned tasks and tasks assigned to some user.');
}
$qb->andWhere($qb->expr()->isNull('st.assignee'));
}
if (array_key_exists('user', $params) && !empty($params['user'])) {
if (\array_key_exists('user', $params) && !empty($params['user'])) {
$qb->andWhere($qb->expr()->eq('st.assignee', ':user'));
$qb->setParameter('user', $params['user']);
}
if (array_key_exists('scope', $params) && !empty($params['scope'])) {
if (\array_key_exists('scope', $params) && !empty($params['scope'])) {
$qb->andWhere($qb->expr()->eq('st.circle', ':scope'));
$qb->setParameter('scope', $params['scope']);
}
if (array_key_exists('types', $params) && null !== $params['types']) {
if (count($params['types']) > 0) {
if (\array_key_exists('types', $params) && null !== $params['types']) {
if (\count($params['types']) > 0) {
$qb->andWhere($qb->expr()->in('st.type', ':types'));
$qb->setParameter('types', $params['types']);
}
}
if (array_key_exists('date_status', $params) && !empty($params['date_status'])) {
if (\array_key_exists('date_status', $params) && !empty($params['date_status'])) {
$this->addTypeFilter($qb, $params);
}
if (array_key_exists('is_closed', $params)) {
if (\array_key_exists('is_closed', $params)) {
$qb->andWhere($this->buildIsClosed($qb, !$params['is_closed']));
}
}

View File

@@ -25,9 +25,10 @@ class SingleTaskStateRepository
) {}
/**
* Return a list of all states associated to at least one single task in the database
* Return a list of all states associated to at least one single task in the database.
*
* @return list<string>
*
* @throws Exception
*/
public function findAllExistingStates(): array