mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fix Entity/UserTest and phpstan error
This commit is contained in:
@@ -17,6 +17,7 @@ use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Common\Collections\Selectable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Iterator;
|
||||
use RuntimeException;
|
||||
@@ -117,11 +118,11 @@ class User implements UserInterface, \Stringable
|
||||
private ?Location $mainLocation = null;
|
||||
|
||||
/**
|
||||
* @var Collection<UserScopeHistory>
|
||||
* @var Collection&Selectable<int, UserScopeHistory>
|
||||
* @ORM\OneToMany(targetEntity=UserScopeHistory::class,
|
||||
* mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
private Collection $scopeHistories;
|
||||
private Collection&Selectable $scopeHistories;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
@@ -136,11 +137,11 @@ class User implements UserInterface, \Stringable
|
||||
private ?string $salt = null;
|
||||
|
||||
/**
|
||||
* @var Collection<UserJobHistory>
|
||||
* @var Collection&Selectable<int, UserJobHistory>
|
||||
* @ORM\OneToMany(targetEntity=UserJobHistory::class,
|
||||
* mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
private Collection $jobHistories;
|
||||
private Collection&Selectable $jobHistories;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
@@ -266,23 +267,12 @@ class User implements UserInterface, \Stringable
|
||||
{
|
||||
$at ??= new DateTimeImmutable('now');
|
||||
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->andX(
|
||||
$expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gt('endDate', $at)
|
||||
),
|
||||
$expr->lte('startDate', $at)
|
||||
)
|
||||
);
|
||||
|
||||
$scopes = $this->scopeHistories->matching($criteria)->getIterator();
|
||||
|
||||
if ($scopes->count() > 0) {
|
||||
return $scopes->first()->getScope();
|
||||
foreach ($this->scopeHistories as $scopeHistory) {
|
||||
if ($at >= $scopeHistory->getStartDate() && (
|
||||
null === $scopeHistory->getEndDate() || $at < $scopeHistory->getEndDate()
|
||||
)) {
|
||||
return $scopeHistory->getScope();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -315,23 +305,12 @@ class User implements UserInterface, \Stringable
|
||||
{
|
||||
$at ??= new DateTimeImmutable('now');
|
||||
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
|
||||
$criteria->where(
|
||||
$expr->andX(
|
||||
$expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gt('endDate', $at)
|
||||
),
|
||||
$expr->lte('startDate', $at)
|
||||
)
|
||||
);
|
||||
|
||||
$jobs = $this->jobHistories->matching($criteria)->getIterator();
|
||||
|
||||
if ($jobs->count() > 0) {
|
||||
return $jobs->first()->getJob();
|
||||
foreach ($this->jobHistories as $jobHistory) {
|
||||
if ($at >= $jobHistory->getStartDate() && (
|
||||
null === $jobHistory->getEndDate() || $at < $jobHistory->getEndDate()
|
||||
)) {
|
||||
return $jobHistory->getJob();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user