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,38 +1,23 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\MainBundle\Templating\Entity;
/**
*
* 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\MainBundle\Templating\Entity;
abstract class AbstractChillEntityRender implements ChillEntityRenderInterface
{
protected function getDefaultOpeningBox($classSuffix): string
{
return '<section class="chill-entity entity-'.$classSuffix.'">';
}
protected function getDefaultClosingBox(): string
{
return '</section>';
}
protected function getDefaultOpeningBox($classSuffix): string
{
return '<section class="chill-entity entity-' . $classSuffix . '">';
}
}

View File

@@ -1,14 +1,21 @@
<?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\MainBundle\Templating\Entity;
use Symfony\Component\Templating\EngineInterface;
use Chill\MainBundle\Entity\Address;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
use function strtr;
class AddressRender implements ChillEntityRenderInterface
{
private EngineInterface $templating;
public const DEFAULT_OPTIONS = [
'with_valid_from' => false,
'with_valid_to' => false,
@@ -16,57 +23,59 @@ class AddressRender implements ChillEntityRenderInterface
'with_delimiter' => false,
'has_no_address' => false,
'multiline' => true,
'extended_infos' => false
'extended_infos' => false,
];
private EngineInterface $templating;
public function __construct(EngineInterface $templating)
{
$this->templating = $templating;
}
/**
* {@inheritDoc}
*/
public function supports($entity, array $options): bool
{
return $entity instanceof Address;
}
/**
* @param Address addr
*/
public function renderString($addr, array $options): string
{
$lines = [];
if (!empty($addr->getStreet())) {
$lines[0] = $addr->getStreet();
}
if (!empty($addr->getStreetNumber())) {
$lines[0] .= ", ".$addr->getStreetNumber();
}
if (!empty($addr->getPostcode())) {
$lines[1] = \strtr("{postcode} {label}", [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName()
]);
}
return implode(" - ", $lines);
}
/**
* {@inheritDoc}
* @param Address addr
*/
public function renderBox($addr, array $options): string
{
$options = \array_merge(self::DEFAULT_OPTIONS, $options);
$options = array_merge(self::DEFAULT_OPTIONS, $options);
return $this->templating
->render('@ChillMain/Entity/address.html.twig', [
'address' => $addr,
'render' => $options['render'] ?? 'bloc',
'options' => $options
'options' => $options,
]);
}
/**
* @param Address addr
* @param mixed $addr
*/
public function renderString($addr, array $options): string
{
$lines = [];
if (!empty($addr->getStreet())) {
$lines[0] = $addr->getStreet();
}
if (!empty($addr->getStreetNumber())) {
$lines[0] .= ', ' . $addr->getStreetNumber();
}
if (!empty($addr->getPostcode())) {
$lines[1] = strtr('{postcode} {label}', [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName(),
]);
}
return implode(' - ', $lines);
}
public function supports($entity, array $options): bool
{
return $entity instanceof Address;
}
}

View File

@@ -1,34 +1,23 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Templating\Entity;
/**
* Render an entity using `__toString()`
* Render an entity using `__toString()`.
*/
class ChillEntityRender extends AbstractChillEntityRender
{
public function renderBox($entity, array $options): string
{
return $this->getDefaultOpeningBox('default').$entity
.$this->getDefaultClosingBox();
return $this->getDefaultOpeningBox('default') . $entity
. $this->getDefaultClosingBox();
}
public function renderString($entity, array $options): string

View File

@@ -1,45 +1,32 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Templating\Entity;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
/**
* Class ChillEntityRenderExtension
*
* @package Chill\MainBundle\Templating\Entity
* Class ChillEntityRenderExtension.
*/
class ChillEntityRenderExtension extends AbstractExtension
{
/**
* @var ChillEntityRenderInterface
*/
protected $renders = [];
/**
* @var ChillEntityRender
*/
protected $defaultRender;
/**
* @var ChillEntityRenderInterface
*/
protected $renders = [];
/**
* ChillEntityRenderExtension constructor.
*/
@@ -47,7 +34,12 @@ class ChillEntityRenderExtension extends AbstractExtension
{
$this->defaultRender = new ChillEntityRender();
}
public function addRender(ChillEntityRenderInterface $render)
{
$this->renders[] = $render;
}
/**
* @return array|TwigFilter[]
*/
@@ -55,54 +47,43 @@ class ChillEntityRenderExtension extends AbstractExtension
{
return [
new TwigFilter('chill_entity_render_string', [$this, 'renderString'], [
'is_safe' => [ 'html' ]
'is_safe' => ['html'],
]),
new TwigFilter('chill_entity_render_box', [$this, 'renderBox'], [
'is_safe' => [ 'html' ]
])
'is_safe' => ['html'],
]),
];
}
/**
* @param $entity
* @param array $options
* @return string
*/
public function renderString($entity, array $options = []): string
{
if (NULL === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderString($entity, $options);
}
/**
* @param $entity
* @param array $options
* @return string
*/
public function renderBox($entity, array $options = []): string
{
if (NULL === $entity) {
if (null === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderBox($entity, $options);
}
/**
* @param ChillEntityRenderInterface $render
* @param $entity
*/
public function addRender(ChillEntityRenderInterface $render)
public function renderString($entity, array $options = []): string
{
$this->renders[] = $render;
if (null === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderString($entity, $options);
}
/**
* @param $entity
* @param $options
* @return ChillEntityRenderInterface|null
*/
protected function getRender($entity, $options): ?ChillEntityRenderInterface
{
@@ -111,6 +92,7 @@ class ChillEntityRenderExtension extends AbstractExtension
return $render;
}
}
return $this->defaultRender;
}
}

View File

@@ -1,23 +1,12 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Templating\Entity;
/**
@@ -27,40 +16,34 @@ namespace Chill\MainBundle\Templating\Entity;
interface ChillEntityRenderInterface
{
/**
* Return true if the class support this object for the given options
*
* @param type $entity
* @param array $options
* @return bool
*/
public function supports($entity, array $options): bool;
/**
* Return the entity as a string.
*
* Example: returning the name of a person.
*
* @param object $entity
* @param array $options
* @return string
*/
public function renderString($entity, array $options): string;
/**
* Return the entity in a box
*
* Return the entity in a box.
*
* Example: return a person inside a box:
*
*
* ```html
* <span class="chill-entity">
* <span class="chill-entity__first-name">Roger</span>
* <span class="chill-entity__last-name">Dupont</span>
* </span>
* ```
*
*
* @param type $entity
* @param array $options
* @return string
*/
public function renderBox($entity, array $options): string;
/**
* Return the entity as a string.
*
* Example: returning the name of a person.
*
* @param object $entity
*/
public function renderString($entity, array $options): string;
/**
* Return true if the class support this object for the given options.
*
* @param type $entity
*/
public function supports($entity, array $options): bool;
}

View File

@@ -1,43 +1,31 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
class CommentRender extends AbstractChillEntityRender
{
/**
* @var \Chill\MainBundle\Repository\UserRepository
*/
private $userRepository;
/**
*
* @var EngineInterface
*/
private $engine;
/**
* @var \Chill\MainBundle\Repository\UserRepository
*/
private $userRepository;
public function __construct(
UserRepository $userRepository,
EngineInterface $engine
@@ -48,42 +36,36 @@ class CommentRender extends AbstractChillEntityRender
/**
* @param CommentEmbeddable $entity
* @param array $options
*
* @return string
*/
public function renderBox($entity, array $options): string
{
// default options
$options = \array_merge([
'user' => [],
'disable_markdown' => false,
'limit_lines' => null,
'metadata' => true
], $options);
$options = array_merge([
'user' => [],
'disable_markdown' => false,
'limit_lines' => null,
'metadata' => true,
], $options);
if ($entity->getUserId()) {
$user = $this->userRepository->find($entity->getUserId());
}
return $this->engine
->render(
'@ChillMain/Entity/CommentEmbeddable.html.twig',
[
'opening_box' => $this->getDefaultOpeningBox('comment-embeddable'),
'closing_box' => $this->getDefaultClosingBox(),
'user' => $user ?? NULL,
'user' => $user ?? null,
'comment' => $entity,
'options' => $options
'options' => $options,
]
);
}
/**
* @param CommentEmbeddable $entity
* @param array $options
*
* @return string
*/
public function renderString($entity, array $options): string
{

View File

@@ -1,39 +1,27 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Templating\Entity;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Add service tagged with `chill.render_entity` to appropriate service
*
* Add service tagged with `chill.render_entity` to appropriate service.
*/
class CompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$extension = $container->getDefinition(ChillEntityRenderExtension::class);
foreach ($container->findTaggedServiceIds('chill.render_entity') as $id => $tags) {
$extension->addMethodCall('addRender', [new Reference($id)]);
}

View File

@@ -1,20 +1,29 @@
<?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\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
class UserRender implements ChillEntityRenderInterface
{
private TranslatableStringHelper $translatableStringHelper;
public const DEFAULT_OPTIONS = [
'main_scope' => true,
'user_job' => true,
];
private EngineInterface $engine;
const DEFAULT_OPTIONS = [
'main_scope' => true,
'user_job' => true
];
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
{
@@ -22,45 +31,40 @@ class UserRender implements ChillEntityRenderInterface
$this->engine = $engine;
}
/**
* @inheritDoc
*/
public function supports($entity, array $options): bool
public function renderBox($entity, array $options): string
{
return $entity instanceof User;
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
return $this->engine->render('@ChillMain/Entity/user.html.twig', [
'user' => $entity,
'opts' => $opts,
]);
}
/**
* @inheritDoc
* @param User $entity
*/
public function renderString($entity, array $options): string
{
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
$str = $entity->getLabel();
if (NULL !== $entity->getUserJob() && $opts['user_job']) {
$str .= ' ('.$this->translatableStringHelper
->localize($entity->getUserJob()->getLabel()).')';
if (null !== $entity->getUserJob() && $opts['user_job']) {
$str .= ' (' . $this->translatableStringHelper
->localize($entity->getUserJob()->getLabel()) . ')';
}
if (NULL !== $entity->getMainScope() && $opts['main_scope']) {
$str .= ' ('.$this->translatableStringHelper
->localize($entity->getMainScope()->getName()).')';
if (null !== $entity->getMainScope() && $opts['main_scope']) {
$str .= ' (' . $this->translatableStringHelper
->localize($entity->getMainScope()->getName()) . ')';
}
return $str;
}
/**
* @inheritDoc
*/
public function renderBox($entity, array $options): string
public function supports($entity, array $options): bool
{
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
return $this->engine->render('@ChillMain/Entity/user.html.twig', [
'user' => $entity,
'opts' => $opts
]);
return $entity instanceof User;
}
}