Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parenthesis for ease up the understanding of conditions priorities #2598

Merged
merged 4 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
uses: actions/checkout@v3

- name: Check for code style violation with PHP-CS-Fixer
uses: OskarStark/php-cs-fixer-ga@3.2.1
uses: OskarStark/php-cs-fixer-ga@3.7.0
with:
args: --diff --dry-run
8 changes: 4 additions & 4 deletions src/Carbon/CarbonPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ public function __construct(...$arguments)
$this->setTimezone($argument);
} elseif ($this->dateInterval === null &&
(
\is_string($argument) && preg_match(
(\is_string($argument) && preg_match(
'/^(-?\d(\d(?![\/-])|[^\d\/-]([\/-])?)*|P[T0-9].*|(?:\h*\d+(?:\.\d+)?\h*[a-z]+)+)$/i',
$argument
) ||
)) ||
$argument instanceof DateInterval ||
$argument instanceof Closure
) &&
Expand Down Expand Up @@ -1235,7 +1235,7 @@ public function resetFilters()
*/
public function setRecurrences($recurrences)
{
if (!is_numeric($recurrences) && $recurrences !== null || $recurrences < 0) {
if ((!is_numeric($recurrences) && $recurrences !== null) || $recurrences < 0) {
throw new InvalidPeriodParameterException('Invalid number of recurrences.');
}

Expand Down Expand Up @@ -1461,7 +1461,7 @@ public function toString()

$parts = [];

$format = !$this->startDate->isStartOfDay() || $this->endDate && !$this->endDate->isStartOfDay()
$format = !$this->startDate->isStartOfDay() || ($this->endDate && !$this->endDate->isStartOfDay())
? 'Y-m-d H:i:s'
: 'Y-m-d';

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public function toPeriod($end = null, $interval = null, $unit = null)
$period->setDateInterval($interval);
}

if (\is_int($end) || \is_string($end) && ctype_digit($end)) {
if (\is_int($end) || (\is_string($end) && ctype_digit($end))) {
$period->setRecurrences($end);
} elseif ($end) {
$period->setEndDate($end);
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private static function createNowInstance($tz)
*/
public static function create($year = 0, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0, $tz = null)
{
if (\is_string($year) && !is_numeric($year) || $year instanceof DateTimeInterface) {
if ((\is_string($year) && !is_numeric($year)) || $year instanceof DateTimeInterface) {
return static::parse($year, $tz ?: (\is_string($month) || $month instanceof DateTimeZone ? $month : null));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ protected function getTranslatedFormByRegExp($baseKey, $keySuffix, $context, $su

if (
$this->getTranslationMessage("$standaloneKey.$subKey") &&
(!$context || ($regExp = $this->getTranslationMessage("${baseKey}_regexp")) && !preg_match($regExp, $context))
(!$context || (($regExp = $this->getTranslationMessage("${baseKey}_regexp")) && !preg_match($regExp, $context)))
) {
$key = $standaloneKey;
}
Expand Down
14 changes: 5 additions & 9 deletions src/Carbon/Traits/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,13 @@ public static function executeWithLocale($locale, $func)
public static function localeHasShortUnits($locale)
{
return static::executeWithLocale($locale, function ($newLocale, TranslatorInterface $translator) {
return $newLocale &&
(
($y = static::translateWith($translator, 'y')) !== 'y' &&
$y !== static::translateWith($translator, 'year')
) || (
($y = static::translateWith($translator, 'd')) !== 'd' &&
return ($newLocale && (($y = static::translateWith($translator, 'y')) !== 'y' && $y !== static::translateWith($translator, 'year'))) || (
($y = static::translateWith($translator, 'd')) !== 'd' &&
$y !== static::translateWith($translator, 'day')
) || (
($y = static::translateWith($translator, 'h')) !== 'h' &&
) || (
($y = static::translateWith($translator, 'h')) !== 'h' &&
$y !== static::translateWith($translator, 'hour')
);
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function createFromTimestampUTC($timestamp)
public static function createFromTimestampMsUTC($timestamp)
{
[$milliseconds, $microseconds] = self::getIntegerAndDecimalParts($timestamp, 3);
$sign = $milliseconds < 0 || $milliseconds === 0.0 && $microseconds < 0 ? -1 : 1;
$sign = $milliseconds < 0 || ($milliseconds === 0.0 && $microseconds < 0) ? -1 : 1;
$milliseconds = abs($milliseconds);
$microseconds = $sign * abs($microseconds) + static::MICROSECONDS_PER_MILLISECOND * ($milliseconds % static::MILLISECONDS_PER_SECOND);
$seconds = $sign * floor($milliseconds / static::MILLISECONDS_PER_SECOND);
Expand Down
4 changes: 2 additions & 2 deletions src/Carbon/Traits/Units.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ public function addUnit($unit, $value = 1, $overflow = null)
}

$timeString = $date->toTimeString();
} elseif ($canOverflow = \in_array($unit, [
} elseif ($canOverflow = (\in_array($unit, [
'month',
'year',
]) && ($overflow === false || (
$overflow === null &&
($ucUnit = ucfirst($unit).'s') &&
!($this->{'local'.$ucUnit.'Overflow'} ?? static::{'shouldOverflow'.$ucUnit}())
))) {
)))) {
$day = $date->day;
}

Expand Down