mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -17,7 +17,7 @@ use Chill\BudgetBundle\Entity\Resource;
|
||||
interface CalculatorInterface
|
||||
{
|
||||
/**
|
||||
* @param array<Charge|Resource> $elements
|
||||
* @param array<Charge|resource> $elements
|
||||
*/
|
||||
public function calculate(array $elements): ?CalculatorResult;
|
||||
|
||||
|
@@ -11,14 +11,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\BudgetBundle\Calculator;
|
||||
|
||||
use Chill\BudgetBundle\Entity\AbstractElement;
|
||||
use Chill\BudgetBundle\Entity\Charge;
|
||||
use Chill\BudgetBundle\Entity\Resource;
|
||||
use OutOfBoundsException;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function implode;
|
||||
|
||||
class CalculatorManager
|
||||
{
|
||||
@@ -42,7 +36,7 @@ class CalculatorManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Resource|Charge> $elements
|
||||
* @param array<resource|Charge> $elements
|
||||
*
|
||||
* @return CalculatorResult[]
|
||||
*/
|
||||
@@ -63,9 +57,8 @@ class CalculatorManager
|
||||
|
||||
public function getCalculator(string $alias): CalculatorInterface
|
||||
{
|
||||
if (false === array_key_exists($alias, $this->calculators)) {
|
||||
throw new OutOfBoundsException("The calculator with alias '{$alias}' does "
|
||||
. 'not exists. Possible values are ' . implode(', ', array_keys($this->calculators)));
|
||||
if (false === \array_key_exists($alias, $this->calculators)) {
|
||||
throw new \OutOfBoundsException("The calculator with alias '{$alias}' does ".'not exists. Possible values are '.\implode(', ', \array_keys($this->calculators)));
|
||||
}
|
||||
|
||||
return $this->calculators[$alias];
|
||||
|
@@ -23,8 +23,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function get_class;
|
||||
|
||||
abstract class AbstractElementController extends AbstractController
|
||||
{
|
||||
public function __construct(protected EntityManagerInterface $em, protected TranslatorInterface $translator, protected LoggerInterface $chillMainLogger) {}
|
||||
@@ -38,7 +36,7 @@ abstract class AbstractElementController extends AbstractController
|
||||
protected function _delete(AbstractElement $element, Request $request, mixed $template, mixed $flashMessage): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(BudgetElementVoter::DELETE, $element, 'You are not '
|
||||
. 'allowed to delete this item');
|
||||
.'allowed to delete this item');
|
||||
|
||||
$form = $this->createDeleteForm();
|
||||
|
||||
@@ -50,7 +48,7 @@ abstract class AbstractElementController extends AbstractController
|
||||
$indexPage = 'chill_budget_elements_household_index';
|
||||
}
|
||||
|
||||
if ($request->getMethod() === Request::METHOD_DELETE) {
|
||||
if (Request::METHOD_DELETE === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
@@ -20,7 +20,7 @@ class ChargeKindController extends CRUDController
|
||||
{
|
||||
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
|
||||
{
|
||||
/** @var QueryBuilder $query */
|
||||
/* @var QueryBuilder $query */
|
||||
$query->addOrderBy('e.ordering', 'ASC');
|
||||
|
||||
return $query;
|
||||
|
@@ -20,7 +20,7 @@ class ResourceKindController extends CRUDController
|
||||
{
|
||||
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator)
|
||||
{
|
||||
/** @var QueryBuilder $query */
|
||||
/* @var QueryBuilder $query */
|
||||
$query->addOrderBy('e.ordering', 'ASC');
|
||||
|
||||
return $query;
|
||||
|
@@ -15,14 +15,13 @@ use Chill\BudgetBundle\Entity\Charge;
|
||||
use Chill\BudgetBundle\Form\ChargeType;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ChargeController extends AbstractElementController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route("{_locale}/budget/charge/{id}/delete", name="chill_budget_charge_delete")
|
||||
*/
|
||||
public function deleteAction(Request $request, Charge $charge)
|
||||
@@ -36,8 +35,8 @@ class ChargeController extends AbstractElementController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route("{_locale}/budget/charge/{id}/edit", name="chill_budget_charge_edit")
|
||||
*/
|
||||
public function editAction(Request $request, Charge $charge)
|
||||
@@ -51,8 +50,8 @@ class ChargeController extends AbstractElementController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route("{_locale}/budget/charge/by-person/{id}/new", name="chill_budget_charge_new")
|
||||
*/
|
||||
public function newAction(Request $request, Person $person)
|
||||
@@ -66,8 +65,8 @@ class ChargeController extends AbstractElementController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route("{_locale}/budget/charge/by-household/{id}/new", name="chill_budget_charge_household_new")
|
||||
*/
|
||||
public function newHouseholdAction(Request $request, Household $household)
|
||||
@@ -81,8 +80,8 @@ class ChargeController extends AbstractElementController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route("{_locale}/budget/charge/{id}/view", name="chill_budget_charge_view")
|
||||
*/
|
||||
public function viewAction(Charge $charge)
|
||||
|
@@ -12,22 +12,12 @@ declare(strict_types=1);
|
||||
namespace Chill\BudgetBundle\Controller;
|
||||
|
||||
use Chill\BudgetBundle\Calculator\CalculatorManager;
|
||||
use Chill\BudgetBundle\Entity\Charge;
|
||||
use Chill\BudgetBundle\Entity\Resource;
|
||||
use Chill\BudgetBundle\Repository\ChargeRepository;
|
||||
use Chill\BudgetBundle\Repository\ResourceRepository;
|
||||
use Chill\BudgetBundle\Security\Authorization\BudgetElementVoter;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function array_merge;
|
||||
use function count;
|
||||
|
||||
class ElementController extends AbstractController
|
||||
{
|
||||
@@ -43,9 +33,9 @@ class ElementController extends AbstractController
|
||||
$charges = $this->chargeRepository->findAllByEntity($person);
|
||||
$resources = $this->resourceRepository->findAllByEntity($person);
|
||||
|
||||
$elements = array_merge($charges, $resources);
|
||||
$elements = \array_merge($charges, $resources);
|
||||
|
||||
if (count($elements) > 0) {
|
||||
if (\count($elements) > 0) {
|
||||
$results = $this->calculator->calculateDefault($elements);
|
||||
}
|
||||
|
||||
@@ -67,9 +57,9 @@ class ElementController extends AbstractController
|
||||
$charges = $this->chargeRepository->findAllByEntity($household);
|
||||
$resources = $this->resourceRepository->findAllByEntity($household);
|
||||
|
||||
$elements = array_merge($charges, $resources);
|
||||
$elements = \array_merge($charges, $resources);
|
||||
|
||||
if (count($elements) > 0) {
|
||||
if (\count($elements) > 0) {
|
||||
$results = $this->calculator->calculateDefault($elements);
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,6 @@ use Chill\BudgetBundle\Entity\Resource;
|
||||
use Chill\BudgetBundle\Form\ResourceType;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
|
@@ -34,7 +34,7 @@ class ChillBudgetExtension extends Extension implements PrependExtensionInterfac
|
||||
$configuration = $this->getConfiguration($configs, $container);
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||
$loader->load('services/form.yaml');
|
||||
$loader->load('services/repository.yaml');
|
||||
$loader->load('services/security.yaml');
|
||||
@@ -60,7 +60,7 @@ class ChillBudgetExtension extends Extension implements PrependExtensionInterfac
|
||||
*/
|
||||
public function prependRoutes(ContainerBuilder $container)
|
||||
{
|
||||
//add routes for custom bundle
|
||||
// add routes for custom bundle
|
||||
$container->prependExtensionConfig('chill_main', [
|
||||
'routing' => [
|
||||
'resources' => [
|
||||
|
@@ -14,8 +14,6 @@ namespace Chill\BudgetBundle\Entity;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\Type\Decimal;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
@@ -29,9 +27,11 @@ abstract class AbstractElement
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="amount", type="decimal", precision=10, scale=2)
|
||||
*
|
||||
* @Assert\GreaterThan(
|
||||
* value=0
|
||||
* )
|
||||
*
|
||||
* @Assert\NotNull(
|
||||
* message="The amount cannot be empty"
|
||||
* )
|
||||
@@ -45,12 +45,13 @@ abstract class AbstractElement
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="endDate", type="datetime_immutable", nullable=true)
|
||||
*
|
||||
* @Assert\GreaterThan(
|
||||
* propertyPath="startDate",
|
||||
* message="The budget element's end date must be after the start date"
|
||||
* )
|
||||
*/
|
||||
private ?DateTimeImmutable $endDate = null;
|
||||
private ?\DateTimeImmutable $endDate = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(
|
||||
@@ -68,16 +69,17 @@ abstract class AbstractElement
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="startDate", type="datetime_immutable")
|
||||
*
|
||||
* @Assert\Date
|
||||
*/
|
||||
private DateTimeImmutable $startDate;
|
||||
private \DateTimeImmutable $startDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="type", type="string", length=255)
|
||||
*/
|
||||
private string $type = '';
|
||||
|
||||
/*Getters and Setters */
|
||||
/* Getters and Setters */
|
||||
|
||||
public function getAmount(): float
|
||||
{
|
||||
@@ -89,7 +91,7 @@ abstract class AbstractElement
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
public function getEndDate(): ?DateTimeImmutable
|
||||
public function getEndDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
@@ -104,7 +106,7 @@ abstract class AbstractElement
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
public function getStartDate(): DateTimeImmutable
|
||||
public function getStartDate(): \DateTimeImmutable
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
@@ -130,17 +132,17 @@ abstract class AbstractElement
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setComment(?string $comment = null): self
|
||||
public function setComment(string $comment = null): self
|
||||
{
|
||||
$this->comment = $comment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEndDate(?DateTimeInterface $endDate = null): self
|
||||
public function setEndDate(\DateTimeInterface $endDate = null): self
|
||||
{
|
||||
if ($endDate instanceof DateTime) {
|
||||
$this->endDate = DateTimeImmutable::createFromMutable($endDate);
|
||||
if ($endDate instanceof \DateTime) {
|
||||
$this->endDate = \DateTimeImmutable::createFromMutable($endDate);
|
||||
} elseif (null === $endDate) {
|
||||
$this->endDate = null;
|
||||
} else {
|
||||
@@ -164,10 +166,10 @@ abstract class AbstractElement
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setStartDate(DateTimeInterface $startDate): self
|
||||
public function setStartDate(\DateTimeInterface $startDate): self
|
||||
{
|
||||
if ($startDate instanceof DateTime) {
|
||||
$this->startDate = DateTimeImmutable::createFromMutable($startDate);
|
||||
if ($startDate instanceof \DateTime) {
|
||||
$this->startDate = \DateTimeImmutable::createFromMutable($startDate);
|
||||
} elseif (null === $startDate) {
|
||||
$this->startDate = null;
|
||||
} else {
|
||||
|
@@ -13,13 +13,13 @@ namespace Chill\BudgetBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\HasCentersInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Charge.
|
||||
*
|
||||
* @ORM\Table(name="chill_budget.charge")
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="Chill\BudgetBundle\Repository\ChargeRepository")
|
||||
*/
|
||||
class Charge extends AbstractElement implements HasCentersInterface
|
||||
@@ -41,6 +41,7 @@ class Charge extends AbstractElement implements HasCentersInterface
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=ChargeKind::class, inversedBy="AbstractElement")
|
||||
*
|
||||
* @ORM\JoinColumn
|
||||
*/
|
||||
private ?ChargeKind $charge = null;
|
||||
@@ -52,14 +53,16 @@ class Charge extends AbstractElement implements HasCentersInterface
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
*
|
||||
* @ORM\Id
|
||||
*
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setStartDate(new DateTimeImmutable('today'));
|
||||
$this->setStartDate(new \DateTimeImmutable('today'));
|
||||
}
|
||||
|
||||
public function getCenters(): array
|
||||
|
@@ -21,14 +21,18 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
* @ORM\Table(name="chill_budget.charge_type",
|
||||
* uniqueConstraints={@ORM\UniqueConstraint(name="charge_kind_unique_type_idx", fields={"kind"})}
|
||||
* )
|
||||
*
|
||||
* @ORM\Entity
|
||||
*
|
||||
* @UniqueEntity(fields={"kind"})
|
||||
*/
|
||||
class ChargeKind
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
*
|
||||
* @ORM\GeneratedValue
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private ?int $id = null;
|
||||
@@ -40,7 +44,9 @@ class ChargeKind
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, options={"default": ""}, nullable=false)
|
||||
*
|
||||
* @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric")
|
||||
*
|
||||
* @Assert\Length(min=3)
|
||||
*/
|
||||
private string $kind = '';
|
||||
|
@@ -13,33 +13,36 @@ namespace Chill\BudgetBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\HasCentersInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Resource.
|
||||
*
|
||||
* @ORM\Table(name="chill_budget.resource")
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="Chill\BudgetBundle\Repository\ResourceRepository")
|
||||
*/
|
||||
class Resource extends AbstractElement implements HasCentersInterface
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
*
|
||||
* @ORM\Id
|
||||
*
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=ResourceKind::class, inversedBy="AbstractElement")
|
||||
*
|
||||
* @ORM\JoinColumn
|
||||
*/
|
||||
private ?ResourceKind $resource = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setStartDate(new DateTimeImmutable('today'));
|
||||
$this->setStartDate(new \DateTimeImmutable('today'));
|
||||
}
|
||||
|
||||
public function getCenters(): array
|
||||
|
@@ -19,16 +19,21 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
* Type of resource.
|
||||
*
|
||||
* @ORM\Table(name="chill_budget.resource_type", uniqueConstraints={
|
||||
*
|
||||
* @ORM\UniqueConstraint(name="resource_kind_unique_type_idx", fields={"kind"})
|
||||
* })
|
||||
*
|
||||
* @ORM\Entity
|
||||
*
|
||||
* @UniqueEntity(fields={"kind"})
|
||||
*/
|
||||
class ResourceKind
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
*
|
||||
* @ORM\GeneratedValue
|
||||
*
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private ?int $id = null;
|
||||
@@ -40,7 +45,9 @@ class ResourceKind
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=false, options={"default": ""})
|
||||
*
|
||||
* @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric")
|
||||
*
|
||||
* @Assert\Length(min=3)
|
||||
*/
|
||||
private string $kind = '';
|
||||
|
@@ -66,7 +66,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
|
||||
*
|
||||
* @return array<ChargeKind>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
|
||||
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
@@ -34,12 +34,9 @@ interface ChargeKindRepositoryInterface extends ObjectRepository
|
||||
public function findAllByType(string $type): array;
|
||||
|
||||
/**
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
*
|
||||
* @return array<ChargeKind>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
|
||||
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array;
|
||||
|
||||
public function findOneBy(array $criteria): ?ChargeKind;
|
||||
|
||||
|
@@ -14,7 +14,6 @@ namespace Chill\BudgetBundle\Repository;
|
||||
use Chill\BudgetBundle\Entity\Charge;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -46,7 +45,7 @@ class ChargeRepository extends ServiceEntityRepository
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findByEntityAndDate($entity, DateTime $date, $sort = null)
|
||||
public function findByEntityAndDate($entity, \DateTime $date, $sort = null)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('c');
|
||||
|
||||
|
@@ -54,7 +54,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
|
||||
|
||||
public function findOneByKind(string $kind): ?ResourceKind
|
||||
{
|
||||
return $this->repository->findOneBy(['kind' => $kind]) ;
|
||||
return $this->repository->findOneBy(['kind' => $kind]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
|
||||
*
|
||||
* @return list<ResourceKind>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
|
||||
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
@@ -34,12 +34,9 @@ interface ResourceKindRepositoryInterface extends ObjectRepository
|
||||
public function findAllByType(string $type): array;
|
||||
|
||||
/**
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
*
|
||||
* @return list<ResourceKind>
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
|
||||
public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array;
|
||||
|
||||
public function findOneBy(array $criteria): ?ResourceKind;
|
||||
|
||||
|
@@ -14,9 +14,7 @@ namespace Chill\BudgetBundle\Repository;
|
||||
use Chill\BudgetBundle\Entity\Resource;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTime;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -33,7 +31,7 @@ class ResourceRepository extends ServiceEntityRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resource[]
|
||||
* @return resource[]
|
||||
*/
|
||||
public function findAllByEntity(Household|Person $entity): array
|
||||
{
|
||||
@@ -47,7 +45,7 @@ class ResourceRepository extends ServiceEntityRepository
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findByEntityAndDate(Household|Person $entity, DateTime $date, $sort = null)
|
||||
public function findByEntityAndDate(Household|Person $entity, \DateTime $date, $sort = null)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('c');
|
||||
|
||||
|
@@ -20,8 +20,6 @@ use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
use UnexpectedValueException;
|
||||
|
||||
class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
final public const CREATE = 'CHILL_BUDGET_ELEMENT_CREATE';
|
||||
@@ -91,6 +89,6 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('This subject is not supported, or is an element not associated with person or household');
|
||||
throw new \UnexpectedValueException('This subject is not supported, or is an element not associated with person or household');
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,6 @@ use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
use LogicException;
|
||||
use RuntimeException;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Helps to find a summary of the budget: the sum of resources and charges.
|
||||
@@ -49,7 +46,7 @@ final readonly class SummaryBudget implements SummaryBudgetInterface
|
||||
}
|
||||
|
||||
$personIds = $household->getCurrentPersons()->map(static fn (Person $p) => $p->getId());
|
||||
$ids = implode(', ', array_fill(0, count($personIds), '?'));
|
||||
$ids = implode(', ', array_fill(0, \count($personIds), '?'));
|
||||
|
||||
$parameters = [...$personIds, $household->getId()];
|
||||
|
||||
@@ -127,7 +124,7 @@ final readonly class SummaryBudget implements SummaryBudgetInterface
|
||||
$chargeKind = $this->chargeKindRepository->find($row['kind_id']);
|
||||
|
||||
if (null === $chargeKind) {
|
||||
throw new RuntimeException('charge kind not found: ' . $row['kind_id']);
|
||||
throw new \RuntimeException('charge kind not found: '.$row['kind_id']);
|
||||
}
|
||||
$result[$chargeKind->getKind()] = [
|
||||
'sum' => (float) $row['sum'],
|
||||
@@ -143,7 +140,7 @@ final readonly class SummaryBudget implements SummaryBudgetInterface
|
||||
$resourceKind = $this->resourceKindRepository->find($row['kind_id']);
|
||||
|
||||
if (null === $resourceKind) {
|
||||
throw new RuntimeException('charge kind not found: ' . $row['kind_id']);
|
||||
throw new \RuntimeException('charge kind not found: '.$row['kind_id']);
|
||||
}
|
||||
|
||||
$result[$resourceKind->getKind()] = [
|
||||
@@ -156,7 +153,7 @@ final readonly class SummaryBudget implements SummaryBudgetInterface
|
||||
return $result;
|
||||
|
||||
default:
|
||||
throw new LogicException();
|
||||
throw new \LogicException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ use Chill\BudgetBundle\Entity\ChargeKind;
|
||||
use Chill\BudgetBundle\Entity\ResourceKind;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
/**
|
||||
* @implements ChillEntityRenderInterface<ResourceKind|ChargeKind>
|
||||
|
@@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ElementControllerTest extends WebTestCase
|
||||
|
@@ -20,15 +20,12 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\AbstractQuery;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use ReflectionClass;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -74,7 +71,7 @@ final class SummaryBudgetTest extends TestCase
|
||||
return $queryCharges->reveal();
|
||||
}
|
||||
|
||||
throw new RuntimeException('this query does not have a stub counterpart: ' . $args[0]);
|
||||
throw new \RuntimeException('this query does not have a stub counterpart: '.$args[0]);
|
||||
});
|
||||
|
||||
$chargeRepository = $this->prophesize(ChargeKindRepositoryInterface::class);
|
||||
@@ -99,18 +96,18 @@ final class SummaryBudgetTest extends TestCase
|
||||
$translatableStringHelper->localize(Argument::type('array'))->will(static fn ($arg) => $arg[0]['fr']);
|
||||
|
||||
$person = new Person();
|
||||
$personReflection = new ReflectionClass($person);
|
||||
$personReflection = new \ReflectionClass($person);
|
||||
$personIdReflection = $personReflection->getProperty('id');
|
||||
$personIdReflection->setAccessible(true);
|
||||
$personIdReflection->setValue($person, 1);
|
||||
|
||||
$household = new Household();
|
||||
$householdReflection = new ReflectionClass($household);
|
||||
$householdReflection = new \ReflectionClass($household);
|
||||
$householdId = $householdReflection->getProperty('id');
|
||||
$householdId->setAccessible(true);
|
||||
$householdId->setValue($household, 1);
|
||||
$householdMember = (new HouseholdMember())->setPerson($person)
|
||||
->setStartDate(new DateTimeImmutable('1 month ago'));
|
||||
->setStartDate(new \DateTimeImmutable('1 month ago'));
|
||||
$household->addMember($householdMember);
|
||||
|
||||
$summaryBudget = new SummaryBudget(
|
||||
|
@@ -32,7 +32,7 @@ final class Version20221207105407 extends AbstractMigration implements Container
|
||||
return 'Use new budget admin entities';
|
||||
}
|
||||
|
||||
public function setContainer(?ContainerInterface $container = null)
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
Reference in New Issue
Block a user