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

@@ -11,16 +11,10 @@ declare(strict_types=1);
namespace Chill\MainBundle\Timeline;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\ResultSetMapping;
use LogicException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Twig\Environment;
use function array_key_exists;
use function is_string;
/**
* Build timeline.
@@ -51,7 +45,7 @@ class TimelineBuilder
* @internal This function is called by the TimelineCompilerClass
*
* @param string $context the context of the service
* @param string $id the
* @param string $id the
*/
public function addProvider($context, $id, TimelineProviderInterface $provider)
{
@@ -91,10 +85,9 @@ class TimelineBuilder
*/
public function getProvidersByContext($context)
{
//throw an exception if no provider have been defined for this context
if (!array_key_exists($context, $this->providersByContext)) {
throw new LogicException(sprintf('No builders have been defined for "%s"'
. ' context', $context));
// throw an exception if no provider have been defined for this context
if (!\array_key_exists($context, $this->providersByContext)) {
throw new \LogicException(sprintf('No builders have been defined for "%s" context', $context));
}
$providers = [];
@@ -114,9 +107,9 @@ class TimelineBuilder
* @example https://redmine.champs-libres.coop/projects/chillperson/repository/revisions/bd2e1b1808f73e39532e9538413025df5487cad0/entry/Controller/TimelinePersonController.php#L47 the implementation in person bundle
*
* @param string $context
* @param array $args arguments defined by the bundle which create the context
* @param int $firstItem first item number
* @param int $number number of items by page
* @param array $args arguments defined by the bundle which create the context
* @param int $firstItem first item number
* @param int $number number of items by page
*
* @return string an HTML representation, must be included using `|raw` filter
*/
@@ -124,8 +117,8 @@ class TimelineBuilder
{
[$union, $parameters] = $this->buildUnionQuery($context, $args);
//add ORDER BY clause and LIMIT
$query = $union . sprintf(
// add ORDER BY clause and LIMIT
$query = $union.sprintf(
' ORDER BY date DESC LIMIT %d OFFSET %d',
$number,
$firstItem
@@ -156,8 +149,6 @@ class TimelineBuilder
*
* return $s;
* }
*
* @param mixed $data
*/
/**
@@ -173,15 +164,15 @@ class TimelineBuilder
$sql = sprintf(
'SELECT %s AS id, '
. '%s AS "date", '
. "'%s' AS type "
. 'FROM %s '
. 'WHERE %s',
.'%s AS "date", '
."'%s' AS type "
.'FROM %s '
.'WHERE %s',
$data['id'],
$data['date'],
$data['type'],
$data['FROM'],
is_string($data['WHERE']) ? $data['WHERE'] : $data['WHERE'][0]
\is_string($data['WHERE']) ? $data['WHERE'] : $data['WHERE'][0]
);
return [$sql, $data['WHERE'][1]];
@@ -192,20 +183,20 @@ class TimelineBuilder
*
* @uses self::buildSelectQuery to build individual SELECT queries
*
* @throws LogicException if no builder have been defined for this context
*
* @return array, where first element is the query, the second one an array with the parameters
*
* @throws \LogicException if no builder have been defined for this context
*/
private function buildUnionQuery(string $context, array $args): array
{
//append SELECT queries with UNION keyword between them
// append SELECT queries with UNION keyword between them
$union = '';
$parameters = [];
foreach ($this->getProvidersByContext($context) as $provider) {
$data = $provider->fetchQuery($context, $args);
[$select, $selectParameters] = $this->buildSelectQuery($data);
$append = empty($union) ? $select : ' UNION ' . $select;
$append = empty($union) ? $select : ' UNION '.$select;
$union .= $append;
$parameters = array_merge($parameters, $selectParameters);
}
@@ -220,23 +211,23 @@ class TimelineBuilder
*/
private function getEntities(array $queriedIds, $context)
{
//gather entities by type to pass all id with same type to the TimelineProvider.
// gather entities by type to pass all id with same type to the TimelineProvider.
$idsByType = [];
foreach ($queriedIds as $result) {
$idsByType[$result['type']][] = $result['id'];
}
//fetch entities from providers
// fetch entities from providers
$entitiesByType = [];
foreach ($idsByType as $type => $ids) {
//iterate providers for current context
// iterate providers for current context
foreach ($this->getProvidersByContext($context) as $provider) {
if ($provider->supportsType($type)) {
$entitiesByType[$type] = $provider->getEntities($ids);
break; //we assume that providers have unique keys => we break the loop
break; // we assume that providers have unique keys => we break the loop
}
}
}
@@ -247,9 +238,10 @@ class TimelineBuilder
/**
* get the template data from the provider for the given entity, by type.
*
* @param string $type
* @param string $context
* @param string $type
* @param string $context
* @param mixed[] $args
*
* @return array the template data fetched from the provider
*/
private function getTemplateData($type, mixed $entity, $context, array $args)
@@ -264,26 +256,26 @@ class TimelineBuilder
/**
* render the timeline as HTML.
*
* @param string $context
* @param string $context
* @param mixed[] $args
*
* @return string the HTML representation of the timeline
*/
private function render(array $fetched, array $entitiesByType, $context, array $args)
{
//add results to a pretty array
// add results to a pretty array
$timelineEntries = [];
foreach ($fetched as $result) {
$data = $this->getTemplateData(
$result['type'],
$entitiesByType[$result['type']][$result['id']], //the entity
$entitiesByType[$result['type']][$result['id']], // the entity
$context,
$args
);
$timelineEntries[] = [
'date' => new DateTime($result['date']),
'date' => new \DateTime($result['date']),
'template' => $data['template'],
'template_data' => $data['template_data'],
];

View File

@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Timeline;
use LogicException;
/**
* Interface for service providing info to timeline.
*
@@ -55,10 +53,11 @@ interface TimelineProviderInterface
* `$context` and `$args` are defined by the bundle which will call the timeline
* rendering.
*
* @param string $context
* @param mixed[] $args the argument to the context.
* @param string $context
* @param mixed[] $args the argument to the context
*
* @return string[]
*
* @throw \LogicException if the context is not supported
*/
public function fetchQuery($context, array $args);
@@ -106,9 +105,9 @@ interface TimelineProviderInterface
* @param type $entity
* @param type $context
*
* @throws LogicException if the context is not supported
*
* @return mixed[]
*
* @throws \LogicException if the context is not supported
*/
public function getEntityTemplate($entity, $context, array $args);

View File

@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Timeline;
use function strtr;
class TimelineSingleQuery
{
private bool $distinct = false;
@@ -23,12 +21,12 @@ class TimelineSingleQuery
{
$parameters = [];
return strtr(
return \strtr(
'SELECT {distinct} {id} AS id, '
. '{date} AS "date", '
. "'{key}' AS type "
. 'FROM {from} '
. 'WHERE {where}',
.'{date} AS "date", '
."'{key}' AS type "
.'FROM {from} '
.'WHERE {where}',
[
'{distinct}' => $this->distinct ? 'DISTINCT' : '',
'{id}' => $this->getId(),