Skip to content

Commit

Permalink
Add all PHP internal functions and constants to its namespace by
Browse files Browse the repository at this point in the history
Function resolution without the backslash forces the PHP internals to verify for each function call if function or constant belongs to current namespace or the global namespace. With the backslash PHP does not check the current namespace and therefore execution is faster when using OP Cache.

Signed-off-by: Sacha Telgenhof <stelgenhof@gmail.com>
  • Loading branch information
stelgenhof committed Jan 27, 2018
1 parent 971b122 commit 651359e
Show file tree
Hide file tree
Showing 31 changed files with 145 additions and 142 deletions.
5 changes: 4 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@

$finder = PhpCsFixer\Finder::create()->in(__DIR__);

return PhpCsFixer\Config::create()->setRules(['@PSR2' => true])->setFinder($finder);
return PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules([
'@PSR2' => true,
'native_function_invocation' => true
])->setFinder($finder);
6 changes: 3 additions & 3 deletions src/Yasumi/Exception/InvalidDateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InvalidDateException extends InvalidArgumentException implements Exception
*/
public function __construct($argumentValue)
{
$type = gettype($argumentValue);
$type = \gettype($argumentValue);
switch ($type) {
case 'boolean':
$displayName = $argumentValue ? 'true' : 'false';
Expand All @@ -40,13 +40,13 @@ public function __construct($argumentValue)
$displayName = $argumentValue;
break;
case 'object':
$displayName = get_class($argumentValue);
$displayName = \get_class($argumentValue);
break;
default:
$displayName = $type;
break;
}

parent::__construct(sprintf(sprintf('\'%s\' is not a valid DateTime(Immutable) instance', $displayName)));
parent::__construct(\sprintf(\sprintf('\'%s\' is not a valid DateTime(Immutable) instance', $displayName)));
}
}
8 changes: 4 additions & 4 deletions src/Yasumi/Filters/BankHolidaysFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function accept(): bool
*/
public function count(): int
{
$days = array_keys(iterator_to_array($this));
$days = \array_keys(\iterator_to_array($this));

array_walk($days, function (&$day) {
$day = str_replace('substituteHoliday:', '', $day);
\array_walk($days, function (&$day) {
$day = \str_replace('substituteHoliday:', '', $day);
});

return count(array_unique($days));
return \count(\array_unique($days));
}
}
8 changes: 4 additions & 4 deletions src/Yasumi/Filters/BetweenFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public function accept(): bool
*/
public function count(): int
{
$days = array_keys(iterator_to_array($this));
$days = \array_keys(\iterator_to_array($this));

array_walk($days, function (&$day) {
$day = str_replace('substituteHoliday:', '', $day);
\array_walk($days, function (&$day) {
$day = \str_replace('substituteHoliday:', '', $day);
});

return count(array_unique($days));
return \count(\array_unique($days));
}
}
8 changes: 4 additions & 4 deletions src/Yasumi/Filters/ObservedHolidaysFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function accept(): bool
*/
public function count(): int
{
$days = array_keys(iterator_to_array($this));
$days = \array_keys(\iterator_to_array($this));

array_walk($days, function (&$day) {
$day = str_replace('substituteHoliday:', '', $day);
\array_walk($days, function (&$day) {
$day = \str_replace('substituteHoliday:', '', $day);
});

return count(array_unique($days));
return \count(\array_unique($days));
}
}
8 changes: 4 additions & 4 deletions src/Yasumi/Filters/OfficialHolidaysFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function accept(): bool
*/
public function count(): int
{
$days = array_keys(iterator_to_array($this));
$days = \array_keys(\iterator_to_array($this));

array_walk($days, function (&$day) {
$day = str_replace('substituteHoliday:', '', $day);
\array_walk($days, function (&$day) {
$day = \str_replace('substituteHoliday:', '', $day);
});

return count(array_unique($days));
return \count(\array_unique($days));
}
}
8 changes: 4 additions & 4 deletions src/Yasumi/Filters/OtherHolidaysFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function accept(): bool
*/
public function count(): int
{
$days = array_keys(iterator_to_array($this));
$days = \array_keys(\iterator_to_array($this));

array_walk($days, function (&$day) {
$day = str_replace('substituteHoliday:', '', $day);
\array_walk($days, function (&$day) {
$day = \str_replace('substituteHoliday:', '', $day);
});

return count(array_unique($days));
return \count(\array_unique($days));
}
}
8 changes: 4 additions & 4 deletions src/Yasumi/Filters/SeasonalHolidaysFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function accept(): bool
*/
public function count(): int
{
$days = array_keys(iterator_to_array($this));
$days = \array_keys(\iterator_to_array($this));

array_walk($days, function (&$day) {
$day = str_replace('substituteHoliday:', '', $day);
\array_walk($days, function (&$day) {
$day = \str_replace('substituteHoliday:', '', $day);
});

return count(array_unique($days));
return \count(\array_unique($days));
}
}
6 changes: 3 additions & 3 deletions src/Yasumi/Holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function __construct(
}

// Assert display locale input
if (! in_array($displayLocale, static::$locales, true)) {
throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $displayLocale));
if (! \in_array($displayLocale, static::$locales, true)) {
throw new UnknownLocaleException(\sprintf('Locale "%s" is not a valid locale.', $displayLocale));
}

// Set additional attributes
Expand Down Expand Up @@ -183,7 +183,7 @@ public function getName()
public function mergeGlobalTranslations(TranslationsInterface $globalTranslations)
{
$holidayGlobalTranslations = $globalTranslations->getTranslations($this->shortName);
$this->translations = array_merge($holidayGlobalTranslations, $this->translations);
$this->translations = \array_merge($holidayGlobalTranslations, $this->translations);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/Yasumi/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct($year, $locale = 'en_US', TranslationsInterface $glo
{
$this->clearHolidays();

$this->year = $year ?: date('Y');
$this->year = $year ?: \date('Y');
$this->locale = $locale;
$this->globalTranslations = $globalTranslations;

Expand Down Expand Up @@ -148,7 +148,7 @@ public function addHoliday(Holiday $holiday)
}

$this->holidays[$holiday->shortName] = $holiday;
uasort($this->holidays, [__CLASS__, 'compareDates']);
\uasort($this->holidays, [__CLASS__, 'compareDates']);
}

/**
Expand Down Expand Up @@ -183,7 +183,7 @@ public function isWorkingDay($date): bool
$weekend_data = self::WEEKEND_DATA;
$weekend_days = $weekend_data[$this::ID] ?? [0, 6];

if (in_array((int)$date->format('w'), $weekend_days, true)) {
if (\in_array((int)$date->format('w'), $weekend_days, true)) {
return false;
}
}
Expand All @@ -209,7 +209,7 @@ public function isHoliday($date): bool
}

// Check if given date is a holiday or not
if (in_array($date->format('Y-m-d'), array_values($this->getHolidayDates()), true)) {
if (\in_array($date->format('Y-m-d'), \array_values($this->getHolidayDates()), true)) {
return true;
}

Expand All @@ -223,7 +223,7 @@ public function isHoliday($date): bool
*/
public function getHolidayDates(): array
{
return array_map(function ($holiday) {
return \array_map(function ($holiday) {
return (string)$holiday;
}, $this->holidays);
}
Expand Down Expand Up @@ -291,11 +291,11 @@ public function count(): int
{
$list = $this->getHolidayNames();

array_walk($list, function (&$holiday) {
$holiday = str_replace('substituteHoliday:', '', $holiday);
\array_walk($list, function (&$holiday) {
$holiday = \str_replace('substituteHoliday:', '', $holiday);
});

return count(array_unique($list));
return \count(\array_unique($list));
}

/**
Expand All @@ -305,7 +305,7 @@ public function count(): int
*/
public function getHolidayNames(): array
{
return array_keys($this->holidays);
return \array_keys($this->holidays);
}

/**
Expand Down Expand Up @@ -355,7 +355,7 @@ private function anotherTime($year, $shortName)
$this->isHolidayNameNotEmpty($shortName); // Validate if short name is not empty

// Get calling class name
$hReflectionClass = new \ReflectionClass(get_class($this));
$hReflectionClass = new \ReflectionClass(\get_class($this));

return Yasumi::create($hReflectionClass->getShortName(), $year, $this->locale)->getHoliday($shortName);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Yasumi/Provider/ChristianHolidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public function calculateOrthodoxEaster($year, $timezone): \DateTime
$c = $year % 19;
$d = (19 * $c + 15) % 30;
$e = (2 * $a + 4 * $b - $d + 34) % 7;
$month = floor(($d + $e + 114) / 31);
$month = \floor(($d + $e + 114) / 31);
$day = (($d + $e + 114) % 31) + 1;

return (new DateTime("$year-$month-$day", new DateTimeZone($timezone)))->add(new DateInterval('P13D'));
Expand Down Expand Up @@ -761,7 +761,7 @@ public function reformationDay($year, $timezone, $locale, $type = Holiday::TYPE_
*/
protected function calculateEaster($year, $timezone): DateTime
{
if (extension_loaded('calendar')) {
if (\extension_loaded('calendar')) {
$easter_days = \easter_days($year);
} else {
$golden = ($year % 19) + 1; // The Golden Number
Expand Down
6 changes: 3 additions & 3 deletions src/Yasumi/Provider/Ireland.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function calculateChristmasDay()
$this->addHoliday($holiday);

// Whenever Christmas Day does not fall on a weekday, the Tuesday following on it shall be a public holiday.
if (in_array((int)$holiday->format('w'), [0, 6], true)) {
if (\in_array((int)$holiday->format('w'), [0, 6], true)) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next tuesday');

Expand Down Expand Up @@ -191,7 +191,7 @@ public function calculateStStephensDay()
$this->addHoliday($holiday);

// Whenever St. Stephens Day does not fall on a weekday, the Monday following on it shall be a public holiday.
if (in_array((int)$holiday->format('w'), [0, 6], true)) {
if (\in_array((int)$holiday->format('w'), [0, 6], true)) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next monday');

Expand Down Expand Up @@ -231,7 +231,7 @@ public function calculateStPatricksDay()
$this->addHoliday($holiday);

// Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday
if (in_array((int)$holiday->format('w'), [0, 6], true)) {
if (\in_array((int)$holiday->format('w'), [0, 6], true)) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next monday');

Expand Down
16 changes: 8 additions & 8 deletions src/Yasumi/Provider/Japan.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ private function calculateVernalEquinoxDay()
if ($this->year < 1948 || $this->year > 2150) {
$day = null;
} elseif ($this->year >= 1948 && $this->year <= 1979) {
$day = floor(self::VERNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * ($this->year - 1980) - floor(($this->year - 1983) / 4));
$day = \floor(self::VERNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1983) / 4));
} elseif ($this->year <= 2099) {
$day = floor(self::VERNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * ($this->year - 1980) - floor(($this->year - 1980) / 4));
$day = \floor(self::VERNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4));
} elseif ($this->year <= 2150) {
$day = floor(self::VERNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * ($this->year - 1980) - floor(($this->year - 1980) / 4));
$day = \floor(self::VERNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4));
}

if (null !== $day) {
Expand Down Expand Up @@ -396,11 +396,11 @@ private function calculateAutumnalEquinoxDay()
if ($this->year < 1948 || $this->year > 2150) {
$day = null;
} elseif ($this->year >= 1948 && $this->year <= 1979) {
$day = floor(self::AUTUMNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * ($this->year - 1980) - floor(($this->year - 1983) / 4));
$day = \floor(self::AUTUMNAL_EQUINOX_PARAM_1979 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1983) / 4));
} elseif ($this->year <= 2099) {
$day = floor(self::AUTUMNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * ($this->year - 1980) - floor(($this->year - 1980) / 4));
$day = \floor(self::AUTUMNAL_EQUINOX_PARAM_2099 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4));
} elseif ($this->year <= 2150) {
$day = floor(self::AUTUMNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * ($this->year - 1980) - floor(($this->year - 1980) / 4));
$day = \floor(self::AUTUMNAL_EQUINOX_PARAM_2150 + self::EQUINOX_GRADIENT * ($this->year - 1980) - \floor(($this->year - 1980) / 4));
}

if (null !== $day) {
Expand Down Expand Up @@ -437,13 +437,13 @@ private function calculateSubstituteHolidays()
if (0 === (int)$date->format('w')) {
if ($this->year >= 2007) {
// Find next week day (not being another holiday)
while (in_array($substituteDay, $dates)) {
while (\in_array($substituteDay, $dates)) {
$substituteDay->add(new DateInterval('P1D'));
continue;
}
} elseif ($date >= '1973-04-12') {
$substituteDay->add(new DateInterval('P1D'));
if (in_array($substituteDay, $dates)) {
if (\in_array($substituteDay, $dates)) {
continue; // @codeCoverageIgnore
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Yasumi/Provider/SouthAfrica.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private function calculateSubstituteHolidays()
while ($datesIterator->valid()) {

// Exclude Good Friday, Family Day, 2016 Municipal Elections Day as these don't fall in the weekend
if (in_array(
if (\in_array(
$datesIterator->current()->shortName,
['goodFriday', 'familyDay', '2016MunicipalElectionsDay'],
true
Expand Down
2 changes: 1 addition & 1 deletion src/Yasumi/Provider/USA.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private function calculateSubstituteHolidays()
while ($datesIterator->valid()) {

// Only process New Year's Day, Independence Day, or Christmas Day
if (in_array(
if (\in_array(
$datesIterator->current()->shortName,
['newYearsDay', 'independenceDay', 'christmasDay'],
true
Expand Down
6 changes: 3 additions & 3 deletions src/Yasumi/Provider/UnitedKingdom.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function calculateNewYearsDay()
$newYearsDay = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone));

// If New Years Day falls on a Saturday or Sunday, it is observed the next Monday (January 2nd or 3rd)
if (in_array((int)$newYearsDay->format('w'), [0, 6], true)) {
if (\in_array((int)$newYearsDay->format('w'), [0, 6], true)) {
$newYearsDay->modify('next monday');
}

Expand Down Expand Up @@ -220,7 +220,7 @@ public function calculateChristmasHolidays()
$substituteChristmasDay = clone $christmasDay;
$substituteBoxingDay = clone $boxingDay;

if (in_array((int)$christmasDay->format('w'), [0, 6], true)) {
if (\in_array((int)$christmasDay->format('w'), [0, 6], true)) {
$substituteChristmasDay->add(new DateInterval('P2D'));
$this->addHoliday(new Holiday(
'substituteHoliday:christmasDay',
Expand All @@ -231,7 +231,7 @@ public function calculateChristmasHolidays()
));
}

if (in_array((int)$boxingDay->format('w'), [0, 6], true)) {
if (\in_array((int)$boxingDay->format('w'), [0, 6], true)) {
$substituteBoxingDay->add(new DateInterval('P2D'));
$this->addHoliday(new Holiday(
'substituteHoliday:secondChristmasDay',
Expand Down
Loading

0 comments on commit 651359e

Please sign in to comment.