mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -13,26 +13,24 @@ namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||
use Chill\MainBundle\Entity\User\UserScopeHistory;
|
||||
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;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* User.
|
||||
*
|
||||
* @ORM\Entity
|
||||
*
|
||||
* @ORM\Table(name="users")
|
||||
*
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region")
|
||||
*
|
||||
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
|
||||
* "user": User::class
|
||||
* })
|
||||
@@ -41,7 +39,9 @@ class User implements UserInterface, \Stringable
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
*
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected ?int $id = null;
|
||||
@@ -49,7 +49,7 @@ class User implements UserInterface, \Stringable
|
||||
/**
|
||||
* @ORM\Column(type="datetime_immutable", nullable=true)
|
||||
*/
|
||||
private ?DateTimeImmutable $absenceStart = null;
|
||||
private ?\DateTimeImmutable $absenceStart = null;
|
||||
|
||||
/**
|
||||
* Array where SAML attributes's data are stored.
|
||||
@@ -89,9 +89,11 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
/**
|
||||
* @var Collection<GroupCenter>
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\MainBundle\Entity\GroupCenter",
|
||||
* inversedBy="users")
|
||||
*
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
|
||||
*/
|
||||
private Collection $groupCenters;
|
||||
@@ -119,6 +121,7 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
/**
|
||||
* @var Collection&Selectable<int, UserScopeHistory>
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity=UserScopeHistory::class,
|
||||
* mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
@@ -138,6 +141,7 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
/**
|
||||
* @var Collection&Selectable<int, UserJobHistory>
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity=UserJobHistory::class,
|
||||
* mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
*/
|
||||
@@ -167,9 +171,6 @@ class User implements UserInterface, \Stringable
|
||||
$this->jobHistories = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getLabel();
|
||||
@@ -187,7 +188,7 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
public function eraseCredentials() {}
|
||||
|
||||
public function getAbsenceStart(): ?DateTimeImmutable
|
||||
public function getAbsenceStart(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->absenceStart;
|
||||
}
|
||||
@@ -216,9 +217,6 @@ class User implements UserInterface, \Stringable
|
||||
return $this->currentLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
@@ -263,9 +261,9 @@ class User implements UserInterface, \Stringable
|
||||
return $this->mainLocation;
|
||||
}
|
||||
|
||||
public function getMainScope(?DateTimeImmutable $at = null): ?Scope
|
||||
public function getMainScope(\DateTimeImmutable $at = null): ?Scope
|
||||
{
|
||||
$at ??= new DateTimeImmutable('now');
|
||||
$at ??= new \DateTimeImmutable('now');
|
||||
|
||||
foreach ($this->scopeHistories as $scopeHistory) {
|
||||
if ($at >= $scopeHistory->getStartDate() && (
|
||||
@@ -315,9 +313,9 @@ class User implements UserInterface, \Stringable
|
||||
return $this->salt;
|
||||
}
|
||||
|
||||
public function getUserJob(?DateTimeImmutable $at = null): ?UserJob
|
||||
public function getUserJob(\DateTimeImmutable $at = null): ?UserJob
|
||||
{
|
||||
$at ??= new DateTimeImmutable('now');
|
||||
$at ??= new \DateTimeImmutable('now');
|
||||
|
||||
foreach ($this->jobHistories as $jobHistory) {
|
||||
if ($at >= $jobHistory->getStartDate() && (
|
||||
@@ -367,7 +365,7 @@ class User implements UserInterface, \Stringable
|
||||
|
||||
public function isAbsent(): bool
|
||||
{
|
||||
return null !== $this->getAbsenceStart() && $this->getAbsenceStart() <= new DateTimeImmutable('now');
|
||||
return null !== $this->getAbsenceStart() && $this->getAbsenceStart() <= new \DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -412,7 +410,7 @@ class User implements UserInterface, \Stringable
|
||||
$groupCentersIds = [];
|
||||
|
||||
foreach ($this->getGroupCenters() as $groupCenter) {
|
||||
if (in_array($groupCenter->getId(), $groupCentersIds, true)) {
|
||||
if (\in_array($groupCenter->getId(), $groupCentersIds, true)) {
|
||||
$context->buildViolation('The user has already those permissions')
|
||||
->addViolation();
|
||||
} else {
|
||||
@@ -422,17 +420,16 @@ class User implements UserInterface, \Stringable
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException if the groupCenter is not in the collection
|
||||
* @throws \RuntimeException if the groupCenter is not in the collection
|
||||
*/
|
||||
public function removeGroupCenter(GroupCenter $groupCenter)
|
||||
{
|
||||
if ($this->groupCenters->removeElement($groupCenter) === false) {
|
||||
throw new RuntimeException('The groupCenter could not be removed, '
|
||||
. 'it seems not to be associated with the user. Aborting.');
|
||||
if (false === $this->groupCenters->removeElement($groupCenter)) {
|
||||
throw new \RuntimeException('The groupCenter could not be removed, it seems not to be associated with the user. Aborting.');
|
||||
}
|
||||
}
|
||||
|
||||
public function setAbsenceStart(?DateTimeImmutable $absenceStart): void
|
||||
public function setAbsenceStart(?\DateTimeImmutable $absenceStart): void
|
||||
{
|
||||
$this->absenceStart = $absenceStart;
|
||||
}
|
||||
@@ -471,8 +468,6 @@ class User implements UserInterface, \Stringable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmail($email)
|
||||
@@ -483,8 +478,6 @@ class User implements UserInterface, \Stringable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $emailCanonical
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEmailCanonical($emailCanonical)
|
||||
@@ -531,7 +524,7 @@ class User implements UserInterface, \Stringable
|
||||
$newScope = new UserScopeHistory();
|
||||
|
||||
$newScope
|
||||
->setStartDate(new DateTimeImmutable('now'))
|
||||
->setStartDate(new \DateTimeImmutable('now'))
|
||||
->setScope($mainScope)
|
||||
->setUser($this);
|
||||
|
||||
@@ -540,7 +533,7 @@ class User implements UserInterface, \Stringable
|
||||
$criteria = new Criteria();
|
||||
$criteria->orderBy(['startDate' => Criteria::ASC, 'id' => Criteria::ASC]);
|
||||
|
||||
/** @var Iterator $scopes */
|
||||
/** @var \Iterator $scopes */
|
||||
$scopes = $this->scopeHistories->matching($criteria)->getIterator();
|
||||
$scopes->rewind();
|
||||
|
||||
@@ -559,8 +552,6 @@ class User implements UserInterface, \Stringable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $password
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPassword($password)
|
||||
@@ -571,8 +562,6 @@ class User implements UserInterface, \Stringable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $salt
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSalt($salt)
|
||||
@@ -591,7 +580,7 @@ class User implements UserInterface, \Stringable
|
||||
$newJob = new UserJobHistory();
|
||||
|
||||
$newJob
|
||||
->setStartDate(new DateTimeImmutable('now'))
|
||||
->setStartDate(new \DateTimeImmutable('now'))
|
||||
->setJob($userJob)
|
||||
->setUser($this);
|
||||
|
||||
@@ -600,7 +589,7 @@ class User implements UserInterface, \Stringable
|
||||
$criteria = new Criteria();
|
||||
$criteria->orderBy(['startDate' => Criteria::ASC, 'id' => Criteria::ASC]);
|
||||
|
||||
/** @var Iterator $jobs */
|
||||
/** @var \Iterator $jobs */
|
||||
$jobs = $this->jobHistories->matching($criteria)->getIterator();
|
||||
$jobs->rewind();
|
||||
|
||||
@@ -621,15 +610,13 @@ class User implements UserInterface, \Stringable
|
||||
/**
|
||||
* Set username.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setUsername(?string $name)
|
||||
{
|
||||
$this->username = (string) $name;
|
||||
|
||||
if ("" === trim($this->getLabel())) {
|
||||
if ('' === trim($this->getLabel())) {
|
||||
$this->setLabel($name);
|
||||
}
|
||||
|
||||
@@ -637,8 +624,6 @@ class User implements UserInterface, \Stringable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $usernameCanonical
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsernameCanonical($usernameCanonical)
|
||||
|
Reference in New Issue
Block a user