cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,27 +1,39 @@
<?php
/**
* 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\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
use function array_reverse;
use function implode;
class SocialActionRender implements ChillEntityRenderInterface
{
private TranslatableStringHelper $translatableStringHelper;
private EngineInterface $engine;
public const SEPARATOR_KEY = 'default.separator';
/**
* if true, the action will not be encapsulated into a "badge"
*/
public const NO_BADGE = 'no-badge';
public const DEFAULT_ARGS = [
self::SEPARATOR_KEY => ' > ',
self::NO_BADGE => false,
];
];
/**
* if true, the action will not be encapsulated into a "badge".
*/
public const NO_BADGE = 'no-badge';
public const SEPARATOR_KEY = 'default.separator';
private EngineInterface $engine;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
{
@@ -29,15 +41,23 @@ class SocialActionRender implements ChillEntityRenderInterface
$this->engine = $engine;
}
public function supports($entity, array $options): bool
public function renderBox($socialAction, array $options): string
{
return $entity instanceof SocialAction;
$options = array_merge(self::DEFAULT_ARGS, $options);
// give some help to twig: an array of parents
$parents = $this->buildParents($socialAction);
return $this->engine->render('@ChillPerson/Entity/social_action.html.twig', [
'socialAction' => $socialAction,
'parents' => $parents,
'options' => $options,
]);
}
public function renderString($socialAction, array $options): string
{
/** @var $socialAction SocialAction */
$options = \array_merge(self::DEFAULT_ARGS, $options);
/** @var SocialAction $socialAction */
$options = array_merge(self::DEFAULT_ARGS, $options);
$titles = [$this->translatableStringHelper->localize($socialAction->getTitle())];
while ($socialAction->hasParent()) {
@@ -47,31 +67,24 @@ class SocialActionRender implements ChillEntityRenderInterface
);
}
$titles = \array_reverse($titles);
$titles = array_reverse($titles);
return \implode($options[self::SEPARATOR_KEY], $titles);
return implode($options[self::SEPARATOR_KEY], $titles);
}
public function supports($entity, array $options): bool
{
return $entity instanceof SocialAction;
}
protected function buildParents($socialAction): array
{
$parents = [];
while ($socialAction->hasParent()) {
$socialAction = $parents[] = $socialAction->getParent();
}
return $parents;
}
public function renderBox($socialAction, array $options): string
{
$options = \array_merge(self::DEFAULT_ARGS, $options);
// give some help to twig: an array of parents
$parents = $this->buildParents($socialAction);
return $this->engine->render('@ChillPerson/Entity/social_action.html.twig', [
'socialAction' => $socialAction,
'parents' => $parents,
'options' => $options
]);
}
}