Skip to content

Commit

Permalink
Downgrade nikic/php-parser in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Mar 27, 2024
1 parent d735797 commit d504c08
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 28 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ jobs:

- name: Select PHPUnit version
if: matrix.phpunit
run: composer require --no-update phpunit/phpunit:^${{ matrix.phpunit }} --no-interaction --dev
run: composer require --no-update --no-interaction --dev "phpunit/phpunit:^${{ matrix.phpunit }}"

- name: Remove conflicting optional dependencies
if: matrix.phpunit >= 11
run: composer remove --no-update ondrejmirtes/better-reflection --no-interaction --dev
run: composer remove --no-update --no-interaction --dev ondrejmirtes/better-reflection

- name: Downgrade nikic/php-parser
if: matrix.phpunit < 11
run: composer require --no-update --no-interaction --dev "nikic/php-parser:^4"

- name: Install dependencies
uses: nick-fields/retry@v3
Expand All @@ -76,7 +80,7 @@ jobs:
timeout_minutes: 10
max_attempts: 3
command: |
composer remove --no-update phpmd/phpmd friendsofphp/php-cs-fixer kylekatarnls/multi-tester --no-interaction --dev;
composer remove --no-update --no-interaction --dev phpmd/phpmd friendsofphp/php-cs-fixer kylekatarnls/multi-tester;
composer update --prefer-dist --no-progress --prefer-${{ matrix.setup || 'stable' }} ${{ matrix.classmap-authoritative && '--classmap-authoritative' || '' }}${{ matrix.php >= 8.2 && ' --ignore-platform-reqs' || '' }};
- name: Run test suite
Expand Down
12 changes: 6 additions & 6 deletions phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
['call', 'isSameUnit'],
['call', 'setUnit'],
['call', 'addUnit'],
['call', 'addRealUnit'],
['call', 'addUTCUnit'],
['call', 'roundUnit'],
['call', 'diffForHumans'],
];
Expand Down Expand Up @@ -418,33 +418,33 @@ function dumpParameter(string $method, ReflectionParameter $parameter): string

break;

case 'addRealUnit':
case 'addUTCUnit':
$unit = $vars->name;
$unitName = unitName($unit);
$plUnit = pluralize($unit);
$plUnitName = pluralize($unitName);
$autoDocLines[] = [
'@method',
'self',
'addReal'.ucFirst($plUnit).'(int|float $value = 1)',
'addUTC'.ucFirst($plUnit).'(int|float $value = 1)',
"Add $plUnitName (the \$value count passed in) to the instance (using timestamp).",
];
$autoDocLines[] = [
'@method',
'self',
'addReal'.ucFirst($unit).'()',
'addUTC'.ucFirst($unit).'()',
"Add one $unitName to the instance (using timestamp).",
];
$autoDocLines[] = [
'@method',
'self',
'subReal'.ucFirst($plUnit).'(int|float $value = 1)',
'subUTC'.ucFirst($plUnit).'(int|float $value = 1)',
"Sub $plUnitName (the \$value count passed in) to the instance (using timestamp).",
];
$autoDocLines[] = [
'@method',
'self',
'subReal'.ucFirst($unit).'()',
'subUTC'.ucFirst($unit).'()',
"Sub one $unitName to the instance (using timestamp).",
];
$autoDocLines[] = [
Expand Down
68 changes: 50 additions & 18 deletions src/Carbon/Traits/Units.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
trait Units
{
/**
* @deprecated Prefer to use add addUTCUnit() which more accurately defines what it's doing.
*
* Add seconds to the instance using timestamp. Positive $value travels
* forward while negative $value travels into the past.
*
Expand All @@ -43,14 +45,28 @@ trait Units
* @return static
*/
public function addRealUnit(string $unit, $value = 1): static
{
return $this->addUTCUnit($unit, $value);
}

/**
* Add seconds to the instance using timestamp. Positive $value travels
* forward while negative $value travels into the past.
*
* @param string $unit
* @param int|float|null $value
*
* @return static
*/
public function addUTCUnit(string $unit, $value = 1): static
{
$value ??= 0;

switch ($unit) {
// @call addRealUnit
// @call addUTCUnit
case 'micro':

// @call addRealUnit
// @call addUTCUnit
case 'microsecond':
/* @var CarbonInterface $this */
$diff = $this->microsecond + $value;
Expand All @@ -63,71 +79,71 @@ public function addRealUnit(string $unit, $value = 1): static

return $this->tz('UTC')->modify("@$time.$microtime")->setTimezone($timezone);

// @call addRealUnit
// @call addUTCUnit
case 'milli':
// @call addRealUnit
// @call addUTCUnit
case 'millisecond':
return $this->addRealUnit('microsecond', $value * static::MICROSECONDS_PER_MILLISECOND);
return $this->addUTCUnit('microsecond', $value * static::MICROSECONDS_PER_MILLISECOND);

// @call addRealUnit
// @call addUTCUnit
case 'second':
break;

// @call addRealUnit
// @call addUTCUnit
case 'minute':
$value *= static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'hour':
$value *= static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'day':
$value *= static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'week':
$value *= static::DAYS_PER_WEEK * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'month':
$value *= 30 * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'quarter':
$value *= static::MONTHS_PER_QUARTER * 30 * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'year':
$value *= 365 * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'decade':
$value *= static::YEARS_PER_DECADE * 365 * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'century':
$value *= static::YEARS_PER_CENTURY * 365 * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

break;

// @call addRealUnit
// @call addUTCUnit
case 'millennium':
$value *= static::YEARS_PER_MILLENNIUM * 365 * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE;

Expand All @@ -147,10 +163,12 @@ public function addRealUnit(string $unit, $value = 1): static
);
$date = $this->setTimestamp($this->getTimestamp() + $seconds);

return $microseconds ? $date->addRealUnit('microsecond', $microseconds) : $date;
return $microseconds ? $date->addUTCUnit('microsecond', $microseconds) : $date;
}

/**
* @deprecated Prefer to use add subUTCUnit() which more accurately defines what it's doing.
*
* Subtract seconds to the instance using timestamp. Positive $value travels
* into the past while negative $value travels forward.
*
Expand All @@ -161,7 +179,21 @@ public function addRealUnit(string $unit, $value = 1): static
*/
public function subRealUnit($unit, $value = 1): static
{
return $this->addRealUnit($unit, -$value);
return $this->addUTCUnit($unit, -$value);
}

/**
* Subtract seconds to the instance using timestamp. Positive $value travels
* into the past while negative $value travels forward.
*
* @param string $unit
* @param int $value
*
* @return static
*/
public function subUTCUnit($unit, $value = 1): static
{
return $this->addUTCUnit($unit, -$value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/MacroExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use Tests\AbstractTestCase;

#[RequiresPhpunit('<11')]
class MacroExtensionTest extends AbstractTestCase
{
private function mockReflectionProvider()
Expand Down Expand Up @@ -71,7 +72,6 @@ public function testHasMacro()
$this->assertFalse($scanner->hasMethod(CarbonInterface::class, 'foo'));
}

#[RequiresPhpunit('<11')]
public function testGetMacro()
{
$scanner = new MacroScanner($this->mockReflectionProvider());
Expand Down

0 comments on commit d504c08

Please sign in to comment.