mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-05 21:09:43 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -11,8 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Service\RollingDate;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
class RollingDate
|
||||
{
|
||||
final public const ALL_T = [
|
||||
@@ -64,21 +62,21 @@ class RollingDate
|
||||
final public const T_YEAR_PREVIOUS_START = 'year_previous_start';
|
||||
|
||||
/**
|
||||
* @param string|self::T_* $roll
|
||||
* @param DateTimeImmutable|null $fixedDate Only to insert if $roll equals @see{self::T_FIXED_DATE}
|
||||
* @param string|self::T_* $roll
|
||||
* @param \DateTimeImmutable|null $fixedDate Only to insert if $roll equals @see{self::T_FIXED_DATE}
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly string $roll,
|
||||
private readonly ?\DateTimeImmutable $fixedDate = null,
|
||||
private readonly DateTimeImmutable $pivotDate = new DateTimeImmutable('now')
|
||||
private readonly \DateTimeImmutable $pivotDate = new \DateTimeImmutable('now')
|
||||
) {}
|
||||
|
||||
public function getFixedDate(): ?DateTimeImmutable
|
||||
public function getFixedDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->fixedDate;
|
||||
}
|
||||
|
||||
public function getPivotDate(): DateTimeImmutable
|
||||
public function getPivotDate(): \DateTimeImmutable
|
||||
{
|
||||
return $this->pivotDate;
|
||||
}
|
||||
|
@@ -11,14 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Service\RollingDate;
|
||||
|
||||
use DateInterval;
|
||||
use DateTimeImmutable;
|
||||
use LogicException;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class RollingDateConverter implements RollingDateConverterInterface
|
||||
{
|
||||
public function convert(?RollingDate $rollingDate): ?DateTimeImmutable
|
||||
public function convert(?RollingDate $rollingDate): ?\DateTimeImmutable
|
||||
{
|
||||
if (null === $rollingDate) {
|
||||
return null;
|
||||
@@ -29,62 +24,62 @@ class RollingDateConverter implements RollingDateConverterInterface
|
||||
return $this->toBeginOfMonth($rollingDate->getPivotDate());
|
||||
|
||||
case RollingDate::T_MONTH_NEXT_START:
|
||||
return $this->toBeginOfMonth($rollingDate->getPivotDate()->add(new DateInterval('P1M')));
|
||||
return $this->toBeginOfMonth($rollingDate->getPivotDate()->add(new \DateInterval('P1M')));
|
||||
|
||||
case RollingDate::T_MONTH_PREVIOUS_START:
|
||||
return $this->toBeginOfMonth($rollingDate->getPivotDate()->sub(new DateInterval('P1M')));
|
||||
return $this->toBeginOfMonth($rollingDate->getPivotDate()->sub(new \DateInterval('P1M')));
|
||||
|
||||
case RollingDate::T_QUARTER_CURRENT_START:
|
||||
return $this->toBeginOfQuarter($rollingDate->getPivotDate());
|
||||
|
||||
case RollingDate::T_QUARTER_NEXT_START:
|
||||
return $this->toBeginOfQuarter($rollingDate->getPivotDate()->add(new DateInterval('P3M')));
|
||||
return $this->toBeginOfQuarter($rollingDate->getPivotDate()->add(new \DateInterval('P3M')));
|
||||
|
||||
case RollingDate::T_QUARTER_PREVIOUS_START:
|
||||
return $this->toBeginOfQuarter($rollingDate->getPivotDate()->sub(new DateInterval('P3M')));
|
||||
return $this->toBeginOfQuarter($rollingDate->getPivotDate()->sub(new \DateInterval('P3M')));
|
||||
|
||||
case RollingDate::T_WEEK_CURRENT_START:
|
||||
return $this->toBeginOfWeek($rollingDate->getPivotDate());
|
||||
|
||||
case RollingDate::T_WEEK_NEXT_START:
|
||||
return $this->toBeginOfWeek($rollingDate->getPivotDate()->add(new DateInterval('P1W')));
|
||||
return $this->toBeginOfWeek($rollingDate->getPivotDate()->add(new \DateInterval('P1W')));
|
||||
|
||||
case RollingDate::T_WEEK_PREVIOUS_START:
|
||||
return $this->toBeginOfWeek($rollingDate->getPivotDate()->sub(new DateInterval('P1W')));
|
||||
return $this->toBeginOfWeek($rollingDate->getPivotDate()->sub(new \DateInterval('P1W')));
|
||||
|
||||
case RollingDate::T_YEAR_CURRENT_START:
|
||||
return $this->toBeginOfYear($rollingDate->getPivotDate());
|
||||
|
||||
case RollingDate::T_YEAR_PREVIOUS_START:
|
||||
return $this->toBeginOfYear($rollingDate->getPivotDate()->sub(new DateInterval('P1Y')));
|
||||
return $this->toBeginOfYear($rollingDate->getPivotDate()->sub(new \DateInterval('P1Y')));
|
||||
|
||||
case RollingDate::T_YEAR_NEXT_START:
|
||||
return $this->toBeginOfYear($rollingDate->getPivotDate()->add(new DateInterval('P1Y')));
|
||||
return $this->toBeginOfYear($rollingDate->getPivotDate()->add(new \DateInterval('P1Y')));
|
||||
|
||||
case RollingDate::T_TODAY:
|
||||
return $rollingDate->getPivotDate();
|
||||
|
||||
case RollingDate::T_FIXED_DATE:
|
||||
if (null === $rollingDate->getFixedDate()) {
|
||||
throw new LogicException('You must provide a fixed date when selecting a fixed date');
|
||||
throw new \LogicException('You must provide a fixed date when selecting a fixed date');
|
||||
}
|
||||
|
||||
return $rollingDate->getFixedDate();
|
||||
|
||||
default:
|
||||
throw new UnexpectedValueException(sprintf('%s rolling operation not supported', $rollingDate->getRoll()));
|
||||
throw new \UnexpectedValueException(sprintf('%s rolling operation not supported', $rollingDate->getRoll()));
|
||||
}
|
||||
}
|
||||
|
||||
private function toBeginOfMonth(DateTimeImmutable $date): DateTimeImmutable
|
||||
private function toBeginOfMonth(\DateTimeImmutable $date): \DateTimeImmutable
|
||||
{
|
||||
return DateTimeImmutable::createFromFormat(
|
||||
return \DateTimeImmutable::createFromFormat(
|
||||
'Y-m-d His',
|
||||
sprintf('%s-%s-01 000000', $date->format('Y'), $date->format('m'))
|
||||
);
|
||||
}
|
||||
|
||||
private function toBeginOfQuarter(DateTimeImmutable $date): DateTimeImmutable
|
||||
private function toBeginOfQuarter(\DateTimeImmutable $date): \DateTimeImmutable
|
||||
{
|
||||
$month = match ((int) $date->format('n')) {
|
||||
1, 2, 3 => '01',
|
||||
@@ -93,26 +88,26 @@ class RollingDateConverter implements RollingDateConverterInterface
|
||||
10, 11, 12 => '10',
|
||||
};
|
||||
|
||||
return DateTimeImmutable::createFromFormat(
|
||||
return \DateTimeImmutable::createFromFormat(
|
||||
'Y-m-d His',
|
||||
sprintf('%s-%s-01 000000', $date->format('Y'), $month)
|
||||
);
|
||||
}
|
||||
|
||||
private function toBeginOfWeek(DateTimeImmutable $date): DateTimeImmutable
|
||||
private function toBeginOfWeek(\DateTimeImmutable $date): \DateTimeImmutable
|
||||
{
|
||||
if (1 === $dayOfWeek = (int) $date->format('N')) {
|
||||
return $date->setTime(0, 0, 0);
|
||||
}
|
||||
|
||||
return $date
|
||||
->sub(new DateInterval('P' . ($dayOfWeek - 1) . 'D'))
|
||||
->sub(new \DateInterval('P'.($dayOfWeek - 1).'D'))
|
||||
->setTime(0, 0, 0);
|
||||
}
|
||||
|
||||
private function toBeginOfYear(DateTimeImmutable $date): DateTimeImmutable
|
||||
private function toBeginOfYear(\DateTimeImmutable $date): \DateTimeImmutable
|
||||
{
|
||||
return DateTimeImmutable::createFromFormat(
|
||||
return \DateTimeImmutable::createFromFormat(
|
||||
'Y-m-d His',
|
||||
sprintf('%s-01-01 000000', $date->format('Y'))
|
||||
);
|
||||
|
@@ -11,13 +11,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Service\RollingDate;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
interface RollingDateConverterInterface
|
||||
{
|
||||
/**
|
||||
* @param RollingDate|null $rollingDate
|
||||
* @return ($rollingDate is null ? null : DateTimeImmutable)
|
||||
* @return ($rollingDate is null ? null : \DateTimeImmutable)
|
||||
*/
|
||||
public function convert(?RollingDate $rollingDate): ?DateTimeImmutable;
|
||||
public function convert(?RollingDate $rollingDate): ?\DateTimeImmutable;
|
||||
}
|
||||
|
Reference in New Issue
Block a user