Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/briannesbitt/Carbon into …
Browse files Browse the repository at this point in the history
…master
  • Loading branch information
kylekatarnls committed Oct 16, 2020
2 parents 7a751d2 + c762e89 commit db2173f
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 157 deletions.
3 changes: 3 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ $rules = array(
'spacing' => 'none',
),
'ereg_to_preg' => true,
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
],
'no_blank_lines_after_phpdoc' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
Expand Down
66 changes: 33 additions & 33 deletions src/Carbon/CarbonInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public function __construct($years = 1, $months = null, $weeks = null, $days = n

$spec = $years;

if (!is_string($spec) || floatval($years) || preg_match('/^[0-9.]/', $years)) {
if (!\is_string($spec) || \floatval($years) || preg_match('/^[0-9.]/', $years)) {
$spec = static::PERIOD_PREFIX;

$spec .= $years > 0 ? $years.static::PERIOD_YEARS : '';
Expand All @@ -361,7 +361,7 @@ public function __construct($years = 1, $months = null, $weeks = null, $days = n

parent::__construct($spec);

if (!is_null($microseconds)) {
if (!\is_null($microseconds)) {
$this->f = $microseconds / Carbon::MICROSECONDS_PER_SECOND;
}
}
Expand Down Expand Up @@ -499,7 +499,7 @@ public static function createFromFormat(string $format, ?string $interval)

if (preg_match('/s([,.])([uv])$/', $format, $match)) {
$interval = explode($match[1], $interval);
$index = count($interval) - 1;
$index = \count($interval) - 1;
$interval[$index] = str_pad($interval[$index], $match[2] === 'v' ? 3 : 6, '0');
$interval = implode($match[1], $interval);
}
Expand All @@ -515,7 +515,7 @@ public static function createFromFormat(string $format, ?string $interval)
}

$interval = mb_substr($interval, mb_strlen($match[0]));
$instance->$unit += intval($match[0]);
$instance->$unit += \intval($match[0]);

continue;
}
Expand Down Expand Up @@ -642,8 +642,8 @@ public static function fromString($intervalDefinition)
preg_match_all($pattern, $intervalDefinition, $parts, PREG_SET_ORDER);

while ([$part, $value, $unit] = array_shift($parts)) {
$intValue = intval($value);
$fraction = floatval($value) - $intValue;
$intValue = \intval($value);
$fraction = \floatval($value) - $intValue;

// Fix calculation precision
switch (round($fraction, 6)) {
Expand Down Expand Up @@ -881,7 +881,7 @@ public static function make($interval, $unit = null)
return new static($interval);
}

if (!is_string($interval)) {
if (!\is_string($interval)) {
return null;
}

Expand Down Expand Up @@ -1028,7 +1028,7 @@ public function __get($name)
*/
public function set($name, $value = null)
{
$properties = is_array($name) ? $name : [$name => $value];
$properties = \is_array($name) ? $name : [$name => $value];

foreach ($properties as $key => $value) {
switch (Carbon::singularUnit(rtrim($key, 'z'))) {
Expand Down Expand Up @@ -1228,10 +1228,10 @@ protected function callMacro($name, $parameters)
if ($macro instanceof Closure) {
$boundMacro = @$macro->bindTo($this, static::class) ?: @$macro->bindTo(null, static::class);

return call_user_func_array($boundMacro ?: $macro, $parameters);
return \call_user_func_array($boundMacro ?: $macro, $parameters);
}

return call_user_func_array($macro, $parameters);
return \call_user_func_array($macro, $parameters);
}

/**
Expand Down Expand Up @@ -1262,7 +1262,7 @@ public function __call($method, $parameters)
}

try {
$this->set($method, count($parameters) === 0 ? 1 : $parameters[0]);
$this->set($method, \count($parameters) === 0 ? 1 : $parameters[0]);
} catch (UnknownSetterException $exception) {
if ($this->localStrictModeEnabled ?? Carbon::isStrictModeEnabled()) {
throw new BadFluentSetterException($method, 0, $exception);
Expand All @@ -1274,18 +1274,18 @@ public function __call($method, $parameters)

protected function getForHumansInitialVariables($syntax, $short)
{
if (is_array($syntax)) {
if (\is_array($syntax)) {
return $syntax;
}

if (is_int($short)) {
if (\is_int($short)) {
return [
'parts' => $short,
'short' => false,
];
}

if (is_bool($syntax)) {
if (\is_bool($syntax)) {
return [
'short' => $syntax,
'syntax' => CarbonInterface::DIFF_ABSOLUTE,
Expand Down Expand Up @@ -1313,15 +1313,15 @@ protected function getForHumansParameters($syntax = null, $short = false, $parts
$minimumUnit = 's';
extract($this->getForHumansInitialVariables($syntax, $short));

if (is_null($syntax)) {
if (\is_null($syntax)) {
$syntax = CarbonInterface::DIFF_ABSOLUTE;
}

if ($parts === -1) {
$parts = INF;
}

if (is_null($options)) {
if (\is_null($options)) {
$options = static::getHumanDiffOptions();
}

Expand All @@ -1337,19 +1337,19 @@ protected function getForHumansParameters($syntax = null, $short = false, $parts
if ($altNumbers) {
if ($altNumbers !== true) {
$language = new Language($this->locale);
$altNumbers = in_array($language->getCode(), (array) $altNumbers);
$altNumbers = \in_array($language->getCode(), (array) $altNumbers);
}
}

if (is_array($join)) {
if (\is_array($join)) {
[$default, $last] = $join;

if ($default !== ' ') {
$optionalSpace = '';
}

$join = function ($list) use ($default, $last) {
if (count($list) < 2) {
if (\count($list) < 2) {
return implode('', $list);
}

Expand All @@ -1359,7 +1359,7 @@ protected function getForHumansParameters($syntax = null, $short = false, $parts
};
}

if (is_string($join)) {
if (\is_string($join)) {
if ($join !== ' ') {
$optionalSpace = '';
}
Expand Down Expand Up @@ -1439,7 +1439,7 @@ public function getValuesSequence()

$keys = array_keys($nonZeroValues);
$firstKey = $keys[0];
$lastKey = $keys[count($keys) - 1];
$lastKey = $keys[\count($keys) - 1];
$values = [];
$record = false;

Expand Down Expand Up @@ -1544,8 +1544,8 @@ public function forHumans($syntax = null, $short = false, $parts = -1, $options

if ($method) {
while (
count($intervalValues->getNonZeroValues()) > $parts &&
($count = count($keys = array_keys($intervalValues->getValuesSequence()))) > 1
\count($intervalValues->getNonZeroValues()) > $parts &&
($count = \count($keys = array_keys($intervalValues->getValuesSequence()))) > 1
) {
$intervalValues = $this->copy()->roundUnit($keys[$count - 2], 1, $method);
}
Expand Down Expand Up @@ -1593,24 +1593,24 @@ public function forHumans($syntax = null, $short = false, $parts = -1, $options
$unit = $short ? $diffIntervalData['unitShort'] : $diffIntervalData['unit'];
$count = $diffIntervalData['value'];
$interval[] = $transChoice($short, $diffIntervalData);
} elseif ($options & CarbonInterface::SEQUENTIAL_PARTS_ONLY && count($interval) > 0) {
} elseif ($options & CarbonInterface::SEQUENTIAL_PARTS_ONLY && \count($interval) > 0) {
break;
}

// break the loop after we get the required number of parts in array
if (count($interval) >= $parts) {
if (\count($interval) >= $parts) {
break;
}

// break the loop after we have reached the minimum unit
if (in_array($minimumUnit, [$diffIntervalData['unit'], $diffIntervalData['unitShort']])) {
if (\in_array($minimumUnit, [$diffIntervalData['unit'], $diffIntervalData['unitShort']])) {
$fallbackUnit = [$diffIntervalData['unit'], $diffIntervalData['unitShort']];

break;
}
}

if (count($interval) === 0) {
if (\count($interval) === 0) {
if ($relativeToNow && $options & CarbonInterface::JUST_NOW) {
$key = 'diff_now';
$translation = $this->translate($key, $interpolations, null, $translator);
Expand Down Expand Up @@ -1728,7 +1728,7 @@ public function toPeriod(...$params)
*/
public function invert($inverted = null)
{
$this->invert = (func_num_args() === 0 ? !$this->invert : $inverted) ? 1 : 0;
$this->invert = (\func_num_args() === 0 ? !$this->invert : $inverted) ? 1 : 0;

return $this;
}
Expand Down Expand Up @@ -1763,7 +1763,7 @@ public function add($unit, $value = 1)
[$value, $unit] = [$unit, $value];
}

if (is_string($unit) && !preg_match('/^\s*\d/', $unit)) {
if (\is_string($unit) && !preg_match('/^\s*\d/', $unit)) {
$unit = "$value $unit";
$value = 1;
}
Expand Down Expand Up @@ -1806,7 +1806,7 @@ public function sub($unit, $value = 1)
[$value, $unit] = [$unit, $value];
}

return $this->add($unit, -floatval($value));
return $this->add($unit, -\floatval($value));
}

/**
Expand Down Expand Up @@ -1959,7 +1959,7 @@ public static function getDateIntervalSpec(DateInterval $interval)
$specString .= $value.$key;
}

if (count($time) > 0) {
if (\count($time) > 0) {
$specString .= static::PERIOD_TIME_PREFIX;
foreach ($time as $key => $value) {
$specString .= $value.$key;
Expand Down Expand Up @@ -2112,9 +2112,9 @@ public function total($unit)
{
$realUnit = $unit = strtolower($unit);

if (in_array($unit, ['days', 'weeks'])) {
if (\in_array($unit, ['days', 'weeks'])) {
$realUnit = 'dayz';
} elseif (!in_array($unit, ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'dayz', 'months', 'years'])) {
} elseif (!\in_array($unit, ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'dayz', 'months', 'years'])) {
throw new UnknownUnitException($unit);
}

Expand Down
Loading

0 comments on commit db2173f

Please sign in to comment.