Do not use DateTimeImmutable.

This commit is contained in:
Pol Dellaiera
2021-04-02 10:44:21 +02:00
parent 777fb25860
commit 48e2d2ceab
3 changed files with 64 additions and 50 deletions

View File

@@ -22,6 +22,7 @@ namespace Chill\PersonBundle\Entity;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use ArrayIterator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Entity\Country;
use Chill\PersonBundle\Entity\MaritalStatus;
@@ -29,9 +30,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\Address;
use DateTime;
use DateTimeImmutable;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\VarDumper\VarDumper;
/**
* Person
@@ -128,14 +127,14 @@ class Person implements HasCenterInterface {
*/
private $fullnameCanonical;
public function __construct(\DateTimeImmutable $opening = null) {
public function __construct(\DateTime $opening = null) {
$this->accompanyingPeriods = new ArrayCollection();
$this->spokenLanguages = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->altNames = new ArrayCollection();
if ($opening === null) {
$opening = new \DateTimeImmutable();
$opening = new \DateTime();
}
$this->open(new AccompanyingPeriod($opening));
@@ -747,18 +746,17 @@ class Person implements HasCenterInterface {
/**
* By default, the addresses are ordered by date, descending (the most
* recent first)
*
* @return ArrayCollection
*/
public function getAddresses(): ArrayCollection
{
return $this->addresses;
}
public function getLastAddress(?DateTimeImmutable $from = null): ?Address
public function getLastAddress(DateTime $from = null)
{
$from ??= new DateTimeImmutable('now');
$from ??= new DateTime('now');
/** @var ArrayIterator $addressesIterator */
$addressesIterator = $this->getAddresses()
->filter(static fn (Address $address): bool => $address->getValidFrom() <= $from)
->getIterator();