mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 23:04:58 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -11,10 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Util;
|
||||
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* Get information about countries.
|
||||
*
|
||||
@@ -69,12 +65,11 @@ class CountriesInfo
|
||||
{
|
||||
self::prepareCacheCountriesByContinent();
|
||||
|
||||
if (array_key_exists($continent, self::$cacheCountriesCodeByContinent)) {
|
||||
if (\array_key_exists($continent, self::$cacheCountriesCodeByContinent)) {
|
||||
return self::$cacheCountriesCodeByContinent[$continent];
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException(sprintf('The continent with prefix '
|
||||
. '%s is unknown.', $continent));
|
||||
throw new \UnexpectedValueException(sprintf('The continent with prefix %s is unknown.', $continent));
|
||||
}
|
||||
|
||||
public static function getCountriesData()
|
||||
|
@@ -11,23 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Util;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use DateTimeZone;
|
||||
use LogicException;
|
||||
|
||||
use function array_diff;
|
||||
use function array_flip;
|
||||
use function array_intersect_key;
|
||||
use function array_key_exists;
|
||||
use function array_merge;
|
||||
use function array_unique;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function ksort;
|
||||
|
||||
use const PHP_INT_MAX;
|
||||
|
||||
/**
|
||||
* Utilities to compare date periods.
|
||||
*
|
||||
@@ -74,19 +57,19 @@ class DateRangeCovering
|
||||
/**
|
||||
* @param int $minCover the minimum of covering required
|
||||
*/
|
||||
public function __construct(int $minCover, private readonly DateTimeZone $tz)
|
||||
public function __construct(int $minCover, private readonly \DateTimeZone $tz)
|
||||
{
|
||||
if (0 > $minCover) {
|
||||
throw new LogicException('argument minCover cannot be lower than 0');
|
||||
throw new \LogicException('argument minCover cannot be lower than 0');
|
||||
}
|
||||
|
||||
$this->minCover = $minCover;
|
||||
}
|
||||
|
||||
public function add(DateTimeInterface $start, ?DateTimeInterface $end = null, $metadata = null): self
|
||||
public function add(\DateTimeInterface $start, \DateTimeInterface $end = null, $metadata = null): self
|
||||
{
|
||||
if ($this->computed) {
|
||||
throw new LogicException('You cannot add intervals to a computed instance');
|
||||
throw new \LogicException('You cannot add intervals to a computed instance');
|
||||
}
|
||||
|
||||
$k = $this->uniqueKeyCounter++;
|
||||
@@ -95,7 +78,7 @@ class DateRangeCovering
|
||||
|
||||
$this->addToSequence($start->getTimestamp(), $k, null);
|
||||
$this->addToSequence(
|
||||
null === $end ? PHP_INT_MAX : $end->getTimestamp(),
|
||||
null === $end ? \PHP_INT_MAX : $end->getTimestamp(),
|
||||
null,
|
||||
$k
|
||||
);
|
||||
@@ -105,7 +88,7 @@ class DateRangeCovering
|
||||
|
||||
public function compute(): self
|
||||
{
|
||||
ksort($this->sequence);
|
||||
\ksort($this->sequence);
|
||||
|
||||
$currentPeriod = [];
|
||||
$currents = [];
|
||||
@@ -113,34 +96,34 @@ class DateRangeCovering
|
||||
$overs = [];
|
||||
|
||||
foreach ($this->sequence as $ts => $moves) {
|
||||
$currents = array_merge($currents, $moves['s']);
|
||||
$currents = array_diff($currents, $moves['e']);
|
||||
$currents = \array_merge($currents, $moves['s']);
|
||||
$currents = \array_diff($currents, $moves['e']);
|
||||
|
||||
if (count($currents) > $this->minCover && !$isOpen) {
|
||||
if (\count($currents) > $this->minCover && !$isOpen) {
|
||||
$currentPeriod[0] = $ts;
|
||||
$currentPeriod[2] = $currents;
|
||||
$isOpen = true;
|
||||
} elseif ($isOpen && count($currents) <= $this->minCover) {
|
||||
} elseif ($isOpen && \count($currents) <= $this->minCover) {
|
||||
$currentPeriod[1] = $ts;
|
||||
$overs[] = $currentPeriod;
|
||||
$currentPeriod = [];
|
||||
$isOpen = false;
|
||||
} elseif ($isOpen) {
|
||||
$currentPeriod[2] = array_merge($currentPeriod[2], $currents);
|
||||
$currentPeriod[2] = \array_merge($currentPeriod[2], $currents);
|
||||
}
|
||||
}
|
||||
|
||||
// process metadata
|
||||
foreach ($overs as [$start, $end, $metadata]) {
|
||||
$this->intersections[] = [
|
||||
(new DateTimeImmutable('@' . $start))
|
||||
(new \DateTimeImmutable('@'.$start))
|
||||
->setTimezone($this->tz),
|
||||
PHP_INT_MAX === $end ? null : (new DateTimeImmutable('@' . $end))
|
||||
\PHP_INT_MAX === $end ? null : (new \DateTimeImmutable('@'.$end))
|
||||
->setTimezone($this->tz),
|
||||
array_values(
|
||||
array_intersect_key(
|
||||
\array_values(
|
||||
\array_intersect_key(
|
||||
$this->metadatas,
|
||||
array_flip(array_unique($metadata))
|
||||
\array_flip(\array_unique($metadata))
|
||||
)
|
||||
),
|
||||
];
|
||||
@@ -154,8 +137,7 @@ class DateRangeCovering
|
||||
public function getIntersections(): array
|
||||
{
|
||||
if (!$this->computed) {
|
||||
throw new LogicException(sprintf('You cannot call the method %s before ' .
|
||||
"'process'", __METHOD__));
|
||||
throw new \LogicException(sprintf('You cannot call the method %s before '."'process'", __METHOD__));
|
||||
}
|
||||
|
||||
return $this->intersections;
|
||||
@@ -164,16 +146,15 @@ class DateRangeCovering
|
||||
public function hasIntersections(): bool
|
||||
{
|
||||
if (!$this->computed) {
|
||||
throw new LogicException(sprintf('You cannot call the method %s before ' .
|
||||
"'process'", __METHOD__));
|
||||
throw new \LogicException(sprintf('You cannot call the method %s before '."'process'", __METHOD__));
|
||||
}
|
||||
|
||||
return count($this->intersections) > 0;
|
||||
return \count($this->intersections) > 0;
|
||||
}
|
||||
|
||||
private function addToSequence($timestamp, ?int $start = null, ?int $end = null)
|
||||
private function addToSequence($timestamp, int $start = null, int $end = null)
|
||||
{
|
||||
if (!array_key_exists($timestamp, $this->sequence)) {
|
||||
if (!\array_key_exists($timestamp, $this->sequence)) {
|
||||
$this->sequence[$timestamp] = ['s' => [], 'e' => []];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user