DX: fix phstan & cs

This commit is contained in:
2023-03-05 17:43:44 +01:00
parent 4dbb195b45
commit 8695099819
25 changed files with 119 additions and 349 deletions

View File

@@ -13,13 +13,18 @@ namespace Chill\ActivityBundle\Templating\Entity;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
/**
* Render activity reason.
*
* @implements ChillEntityRenderInterface<ActivityReason>
*/
class ActivityReasonRender extends AbstractChillEntityRender
class ActivityReasonRender implements ChillEntityRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
/**
* @var TranslatableStringHelper
*/
@@ -51,9 +56,6 @@ class ActivityReasonRender extends AbstractChillEntityRender
$this->getDefaultClosingBox();
}
/**
* @param ActivityReason $entity
*/
public function renderString($entity, array $options): string
{
$category = '';

View File

@@ -16,6 +16,9 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface;
/**
* @implements ChillEntityRenderInterface<AsideActivityCategory>
*/
final class CategoryRender implements ChillEntityRenderInterface
{
public const DEFAULT_ARGS = [
@@ -45,9 +48,6 @@ final class CategoryRender implements ChillEntityRenderInterface
return $parents;
}
/**
* @param AsideActivityCategory $asideActivityCategory
*/
public function renderBox($asideActivityCategory, array $options): string
{
$options = array_merge(self::DEFAULT_ARGS, $options);
@@ -63,9 +63,6 @@ final class CategoryRender implements ChillEntityRenderInterface
);
}
/**
* @param AsideActivityCategory $asideActivityCategory
*/
public function renderString($asideActivityCategory, array $options): string
{
$options = array_merge(self::DEFAULT_ARGS, $options);
@@ -84,9 +81,6 @@ final class CategoryRender implements ChillEntityRenderInterface
return implode($options[self::SEPERATOR_KEY], $titles);
}
/**
* @param AsideActivityCategory $asideActivityCategory
*/
public function supports($asideActivityCategory, array $options): bool
{
return $asideActivityCategory instanceof AsideActivityCategory;

View File

@@ -17,6 +17,9 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Symfony\Component\Templating\EngineInterface;
/**
* @implements ChillEntityRenderInterface<ResourceKind|ChargeKind>
*/
final class BudgetElementTypeRender implements ChillEntityRenderInterface
{
private EngineInterface $engine;

View File

@@ -43,36 +43,20 @@ class Country
private ?int $id = null;
/**
* @var string
* @var array<string, string>
*
* @ORM\Column(type="json")
* @groups({"read", "docgen:read"})
* @Context({"is-translatable": true}, groups={"docgen:read"})
*/
private $name;
private array $name = [];
/**
* @return string
*/
public function __toString()
{
return $this->getName();
}
/**
* @return the string
*/
public function getCountryCode()
public function getCountryCode(): string
{
return $this->countryCode;
}
/**
* Get id.
*
* @return int
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@@ -81,29 +65,22 @@ class Country
* Get name.
*
*/
public function getName()
public function getName(): array
{
return $this->name;
}
/**
* @param string $countryCode
*/
public function setCountryCode($countryCode)
public function setCountryCode(?string $countryCode): self
{
$this->countryCode = $countryCode;
$this->countryCode = (string) $countryCode;
return $this;
}
/**
* Set name.
*
* @param string $name
*
* @return Country
* @param array<string, string> $name
*/
public function setName($name)
public function setName(array $name): self
{
$this->name = $name;

View File

@@ -51,10 +51,7 @@ class CommentEmbeddable
return $this->date;
}
/**
* @return interger $userId
*/
public function getUserId()
public function getUserId(): ?int
{
return $this->userId;
}

View File

@@ -11,15 +11,10 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Entity;
/**
* @deprecated load @link{BoxUtilsChillEntityRenderTrait} in the render
*/
abstract class AbstractChillEntityRender implements ChillEntityRenderInterface
{
protected function getDefaultClosingBox(): string
{
return '</section>';
}
protected function getDefaultOpeningBox($classSuffix): string
{
return '<section class="chill-entity entity-' . $classSuffix . '">';
}
use BoxUtilsChillEntityRenderTrait;
}

View File

@@ -18,6 +18,9 @@ use Symfony\Component\Templating\EngineInterface;
use function array_merge;
use function strtr;
/**
* @implements ChillEntityRenderInterface<Address>
*/
class AddressRender implements ChillEntityRenderInterface
{
public const DEFAULT_OPTIONS = [
@@ -41,10 +44,6 @@ class AddressRender implements ChillEntityRenderInterface
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param Address addr
* @param mixed $addr
*/
public function renderBox($addr, array $options): string
{
$options = array_merge(self::DEFAULT_OPTIONS, $options);
@@ -59,18 +58,12 @@ class AddressRender implements ChillEntityRenderInterface
]);
}
/**
* @param Address addr
* @param mixed $addr
*
* @return string[]
*/
public function renderLines(Address $addr, bool $includeCityLine = true, bool $includeCountry = true): array
{
$lines = [];
if (null !== $addr->getPostCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
if (null !== $addr->getPostcode()) {
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
$lines[] = $this->renderIntraBuildingLine($addr);
$lines[] = $this->renderBuildingLine($addr);
$lines[] = $this->renderStreetLine($addr);
@@ -117,10 +110,8 @@ class AddressRender implements ChillEntityRenderInterface
$res = trim($street . ', ' . $streetNumber, ', ');
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$res = trim($streetNumber . ', ' . $street, ', ');
}
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
$res = trim($streetNumber . ', ' . $street, ', ');
}
if ((',' === $res) || ('' === $res)) {
@@ -130,10 +121,6 @@ class AddressRender implements ChillEntityRenderInterface
return $res;
}
/**
* @param Address addr
* @param mixed $addr
*/
public function renderString($addr, array $options): string
{
return implode(' — ', $this->renderLines($addr));
@@ -163,10 +150,8 @@ class AddressRender implements ChillEntityRenderInterface
$res = null;
}
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$res = $addr->getBuildingName();
}
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
$res = $addr->getBuildingName();
}
return $res;

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
/*
* 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;
trait BoxUtilsChillEntityRenderTrait
{
protected function getDefaultClosingBox(): string
{
return '</section>';
}
protected function getDefaultOpeningBox($classSuffix): string
{
return '<section class="chill-entity entity-' . $classSuffix . '">';
}
}

View File

@@ -14,8 +14,10 @@ namespace Chill\MainBundle\Templating\Entity;
/**
* Render an entity using `__toString()`.
*/
class ChillEntityRender extends AbstractChillEntityRender
class ChillEntityRender implements ChillEntityRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
public function renderBox($entity, array $options): string
{
return $this->getDefaultOpeningBox('default') . $entity

View File

@@ -14,6 +14,8 @@ namespace Chill\MainBundle\Templating\Entity;
/**
* Interface to implement which will render an entity in template on a custom
* manner.
*
* @template T
*/
interface ChillEntityRenderInterface
{
@@ -29,7 +31,7 @@ interface ChillEntityRenderInterface
* </span>
* ```
*
* @param type $entity
* @param T $entity
*/
public function renderBox($entity, array $options): string;
@@ -38,14 +40,12 @@ interface ChillEntityRenderInterface
*
* Example: returning the name of a person.
*
* @param object $entity
* @param T $entity
*/
public function renderString($entity, array $options): string;
/**
* Return true if the class support this object for the given options.
*
* @param object $entity
*/
public function supports($entity, array $options): bool;
public function supports(object $entity, array $options): bool;
}

View File

@@ -13,33 +13,32 @@ namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Repository\UserRepositoryInterface;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
class CommentRender extends AbstractChillEntityRender
/**
* @implements ChillEntityRenderInterface<CommentEmbeddable>
*/
class CommentRender implements ChillEntityRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
/**
* @var EngineInterface
*/
private $engine;
/**
* @var \Chill\MainBundle\Repository\UserRepository
*/
private $userRepository;
private UserRepositoryInterface $userRepository;
public function __construct(
UserRepository $userRepository,
UserRepositoryInterface $userRepository,
EngineInterface $engine
) {
$this->userRepository = $userRepository;
$this->engine = $engine;
}
/**
* @param CommentEmbeddable $entity
*/
public function renderBox($entity, array $options): string
{
// default options
@@ -50,7 +49,7 @@ class CommentRender extends AbstractChillEntityRender
'metadata' => true,
], $options);
if ($entity->getUserId()) {
if (null !== $entity->getUserId()) {
$user = $this->userRepository->find($entity->getUserId());
}
@@ -67,9 +66,6 @@ class CommentRender extends AbstractChillEntityRender
);
}
/**
* @param CommentEmbeddable $entity
*/
public function renderString($entity, array $options): string
{
return $entity->getComment();

View File

@@ -19,6 +19,9 @@ use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_merge;
/**
* @implements ChillEntityRenderInterface<User>
*/
class UserRender implements ChillEntityRenderInterface
{
public const DEFAULT_OPTIONS = [
@@ -50,9 +53,6 @@ class UserRender implements ChillEntityRenderInterface
]);
}
/**
* @param User $entity
*/
public function renderString($entity, array $options): string
{
$opts = array_merge(self::DEFAULT_OPTIONS, $options);

View File

@@ -2,6 +2,13 @@
declare(strict_types=1);
/*
* 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\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;

View File

@@ -12,14 +12,19 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
/**
* Render closing motive.
*
* @implements ChillEntityRenderInterface<ClosingMotive>
*/
class ClosingMotiveRender extends AbstractChillEntityRender
class ClosingMotiveRender implements ChillEntityRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
private const SEPARATOR = ' > ';
/**
@@ -40,9 +45,6 @@ class ClosingMotiveRender extends AbstractChillEntityRender
$this->getDefaultClosingBox();
}
/**
* @param ClosingMotive $entity
*/
public function renderString($entity, array $options): string
{
return $this->renderStringRecursive(
@@ -57,12 +59,12 @@ class ClosingMotiveRender extends AbstractChillEntityRender
return $entity instanceof ClosingMotive;
}
protected function renderStringRecursive(ClosingMotive $motive, $existing, array $options)
private function renderStringRecursive(ClosingMotive $motive, string $existing, array $options)
{
$newExisting = $this->translatableStringHelper->localize($motive->getName());
if ($motive->hasParent()) {
if (!empty($existing)) {
if ('' !== $existing) {
$newExisting = $newExisting . self::SEPARATOR . $existing;
}
@@ -73,7 +75,7 @@ class ClosingMotiveRender extends AbstractChillEntityRender
);
}
if (!empty($existing)) {
if ('' !== $existing) {
return $newExisting . self::SEPARATOR . $existing;
}

View File

@@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Templating\EngineInterface;
@@ -22,8 +24,9 @@ use function array_key_exists;
/**
* Render a Person.
*/
class PersonRender extends AbstractChillEntityRender implements PersonRenderInterface
class PersonRender implements PersonRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
private ConfigPersonAltNamesHelper $configAltNamesHelper;
private EngineInterface $engine;
@@ -40,9 +43,6 @@ class PersonRender extends AbstractChillEntityRender implements PersonRenderInte
$this->translator = $translator;
}
/**
* @param Person $person
*/
public function renderBox($person, array $options): string
{
$params = [
@@ -72,9 +72,6 @@ class PersonRender extends AbstractChillEntityRender implements PersonRenderInte
$this->getDefaultClosingBox();
}
/**
* @param Person $person
*/
public function renderString($person, array $options): string
{
$options = array_merge(['addAge' => true], $options);

View File

@@ -12,9 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\PersonBundle\Entity\Person;
/**
* Render a Person.
*
* @extends ChillEntityRenderInterface<Person>
*/
interface PersonRenderInterface extends ChillEntityRenderInterface
{

View File

@@ -15,6 +15,9 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Person\PersonResourceKind;
/**
* @implements ChillEntityRenderInterface<PersonResourceKind>
*/
final class ResourceKindRender implements ChillEntityRenderInterface
{
private TranslatableStringHelper $translatableStringHelper;

View File

@@ -20,6 +20,9 @@ use function array_merge;
use function array_reverse;
use function implode;
/**
* @implements ChillEntityRenderInterface<SocialAction>
*/
class SocialActionRender implements ChillEntityRenderInterface
{
public const AND_CHILDREN_MENTION = 'show_and_children_mention';

View File

@@ -19,6 +19,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
use function array_reverse;
use function implode;
/**
* @implements ChillEntityRenderInterface<SocialIssue>
*/
final class SocialIssueRender implements ChillEntityRenderInterface
{
public const AND_CHILDREN_MENTION = 'show_and_children_mention';
@@ -53,9 +56,6 @@ final class SocialIssueRender implements ChillEntityRenderInterface
$this->translator = $translator;
}
/**
* @param SocialIssue $socialIssue
*/
public function renderBox($socialIssue, array $options): string
{
$options = array_merge(self::DEFAULT_ARGS, $options);
@@ -74,9 +74,6 @@ final class SocialIssueRender implements ChillEntityRenderInterface
);
}
/**
* @param SocialIssue $socialIssue
*/
public function renderString($socialIssue, array $options): string
{
/** @var SocialIssue $socialIssue */

View File

@@ -12,12 +12,18 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Templating\EngineInterface;
class ThirdPartyRender extends AbstractChillEntityRender
/**
* @implements ChillEntityRenderInterface<ThirdParty>
*/
class ThirdPartyRender implements ChillEntityRenderInterface
{
use BoxUtilsChillEntityRenderTrait;
protected EngineInterface $engine;
protected TranslatableStringHelper $translatableStringHelper;
@@ -30,9 +36,6 @@ class ThirdPartyRender extends AbstractChillEntityRender
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param ThirdParty $entity
*/
public function renderBox($entity, array $options): string
{
$params = [
@@ -59,9 +62,6 @@ class ThirdPartyRender extends AbstractChillEntityRender
$this->getDefaultClosingBox();
}
/**
* @param ThirdParty $entity
*/
public function renderString($entity, array $options): string
{
if ($entity->getCivility() !== null) {