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

@@ -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;