mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,25 +1,35 @@
|
||||
<?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\DataFixtures\Helper;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use function array_pop;
|
||||
use function random_int;
|
||||
|
||||
trait PersonRandomHelper
|
||||
{
|
||||
private array $randPersons = [];
|
||||
private ?int $countPersons = null;
|
||||
|
||||
private array $randPersons = [];
|
||||
|
||||
protected function getRandomPerson(EntityManagerInterface $em): Person
|
||||
{
|
||||
$fetchBy = 5;
|
||||
|
||||
if (null === $this->countPersons) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$this->countPersons = $qb->select('count(p)')
|
||||
->from(Person::class, 'p')
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
if ([] === $this->randPersons) {
|
||||
@@ -28,13 +38,11 @@ trait PersonRandomHelper
|
||||
->select('p')
|
||||
->from(Person::class, 'p')
|
||||
->getQuery()
|
||||
->setFirstResult(\random_int(0, $this->countPersons - $fetchBy))
|
||||
->setFirstResult(random_int(0, $this->countPersons - $fetchBy))
|
||||
->setMaxResults($fetchBy)
|
||||
->getResult()
|
||||
;
|
||||
->getResult();
|
||||
}
|
||||
|
||||
return \array_pop($this->randPersons);
|
||||
return array_pop($this->randPersons);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user