Skip to content

Commit

Permalink
Improve Deprecated attribute usage in the package
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 23, 2024
1 parent 92c6ac9 commit d985041
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 87 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3', '8.4']
stability: [prefer-lowest, prefer-stable]
include:
- php: '8.4'
flags: "--ignore-platform-req=php"
phpunit-flags: '--no-coverage'
stability: prefer-stable
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -50,11 +45,6 @@ jobs:

- name: Run Unit tests with coverage
run: composer phpunit -- ${{ matrix.phpunit-flags }}
if: ${{ matrix.php == '8.3' || matrix.php == '8.2' || matrix.php == '8.1'}}

- name: Run Unit tests without coverage
run: composer phpunit:min
if: ${{ matrix.php == '8.4'}}

- name: Run static analysis
run: composer phpstan
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64.0",
"phpstan/phpstan": "^1.12.3",
"phpstan/phpstan": "^1.12.11",
"phpstan/phpstan-deprecation-rules": "^1.2.1",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.0",
"phpunit/phpunit": "^10.5.15 || ^11.3.4",
"symfony/var-dumper": "^6.4.11"
"phpstan/phpstan-phpunit": "^1.4.1",
"phpstan/phpstan-strict-rules": "^1.6.1",
"phpunit/phpunit": "^10.5.15 || ^11.4.3",
"symfony/var-dumper": "^6.4.15"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 20 additions & 0 deletions src/MissingFeature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* League.Period (https://period.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace League\Period;

use LogicException;

final class MissingFeature extends LogicException implements IntervalError
{
}
140 changes: 69 additions & 71 deletions src/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Deprecated;
use Exception;
use Generator;
use JsonSerializable;
Expand Down Expand Up @@ -247,35 +248,12 @@ public static function before(
return new self($endDate->sub(self::filterDuration($duration)), $endDate, $bounds);
}

/**
* @deprecated since version 5.2.1
* @see ::fromRange
*
* @throws InvalidInterval If no instance can be generated from a DatePeriod object
*/
public static function fromDateRange(DatePeriod $dateRange, Bounds $bounds = Bounds::IncludeStartExcludeEnd): self
{
$endDate = $dateRange->getEndDate();
if (null === $endDate) {
throw InvalidInterval::dueToInvalidDatePeriod();
}

return new self(
self::filterDatePoint($dateRange->getStartDate()),
self::filterDatePoint($endDate),
$bounds
);
}

/**
* @throws InvalidInterval If the PHP version is lower than PHP 8.2
*/
public static function fromRange(DatePeriod $range): self
{
$endDate = $range->getEndDate();
if (null === $endDate) {
throw InvalidInterval::dueToInvalidDatePeriod();
}
$endDate = $range->getEndDate() ?? throw InvalidInterval::dueToInvalidDatePeriod();

if (property_exists(DatePeriod::class, 'include_end_date')) {
return new self(
Expand Down Expand Up @@ -763,53 +741,6 @@ public function dateIntervalDiff(self $period): DateInterval
return $this->endDate->diff($this->startDate->add($period->dateInterval()));
}

/**
* @deprecated since version 5.2.0
* @see ::rangeForward
*
*
* Allows iteration over a set of dates and times,
* recurring at regular intervals, over the instance.
*
* The returned DatePeriod object contains only DateTimeImmutable objects.
*
* @see http://php.net/manual/en/dateperiod.construct.php
*
* @return DatePeriod<DateTimeImmutable>
*/
public function dateRangeForward(Period|Duration|DateInterval|string $timeDelta, InitialDatePresence $startDatePresence = InitialDatePresence::Included): DatePeriod
{
return new DatePeriod(
$this->startDate,
self::filterDuration($timeDelta),
$this->endDate,
InitialDatePresence::Excluded === $startDatePresence ? DatePeriod::EXCLUDE_START_DATE : 0
);
}

/**
* @deprecated since version 5.2.0
* @see Period::rangeBackwards()
*
* Allows iteration over a set of dates and times,
* recurring at regular intervals, over the instance backwards starting from the instance ending.
*
* @return Generator<int,DateTimeImmutable>
*/
public function dateRangeBackwards(Period|Duration|DateInterval|string $timeDelta, InitialDatePresence $endDatePresence = InitialDatePresence::Included): Generator
{
$timeDelta = self::filterDuration($timeDelta);
$date = $this->endDate;
if (InitialDatePresence::Excluded === $endDatePresence) {
$date = $this->endDate->sub($timeDelta);
}

while ($date > $this->startDate) {
yield $date;
$date = $date->sub($timeDelta);
}
}

/**
* Allows iteration over a set of dates and times,
* recurring at regular intervals, over the instance.
Expand Down Expand Up @@ -1446,4 +1377,71 @@ public function snapToIsoYear(): self

return $this->newInstance(new self($startDate, $endDate, $this->bounds));
}



/**
* @deprecated since version 5.2.0
* @see ::rangeForward
*
*
* Allows iteration over a set of dates and times,
* recurring at regular intervals, over the instance.
*
* The returned DatePeriod object contains only DateTimeImmutable objects.
*
* @see http://php.net/manual/en/dateperiod.construct.php
*
* @return DatePeriod<DateTimeImmutable>
*/
#[Deprecated(since:'league/period:5.2.0', message: "use League\Perio\Period::rangeForward()")]

Check failure on line 1397 in src/Period.php

View workflow job for this annotation

GitHub Actions / PHP on 8.3 - prefer-stable -

Attribute class Deprecated does not exist.
public function dateRangeForward(Period|Duration|DateInterval|string $timeDelta, InitialDatePresence $startDatePresence = InitialDatePresence::Included): DatePeriod
{
return new DatePeriod(
$this->startDate,
self::filterDuration($timeDelta),
$this->endDate,
InitialDatePresence::Excluded === $startDatePresence ? DatePeriod::EXCLUDE_START_DATE : 0
);
}

/**
* @deprecated since version 5.2.0
* @see Period::rangeBackwards()
*
* Allows iteration over a set of dates and times,
* recurring at regular intervals, over the instance backwards starting from the instance ending.
*
* @return Generator<int,DateTimeImmutable>
*/
#[Deprecated(since:'league/period:5.2.0', message: "use League\Perio\Period::rangeBackwards()")]

Check failure on line 1417 in src/Period.php

View workflow job for this annotation

GitHub Actions / PHP on 8.3 - prefer-stable -

Attribute class Deprecated does not exist.
public function dateRangeBackwards(Period|Duration|DateInterval|string $timeDelta, InitialDatePresence $endDatePresence = InitialDatePresence::Included): Generator
{
$timeDelta = self::filterDuration($timeDelta);
$date = $this->endDate;
if (InitialDatePresence::Excluded === $endDatePresence) {
$date = $this->endDate->sub($timeDelta);
}

while ($date > $this->startDate) {
yield $date;
$date = $date->sub($timeDelta);
}
}

/**
* @deprecated since version 5.2.1
* @see ::fromRange
*
* @throws InvalidInterval If no instance can be generated from a DatePeriod object
*/
#[Deprecated(since:'league/period:5.2.1', message: "use League\Perio\Period::fromRange()")]

Check failure on line 1438 in src/Period.php

View workflow job for this annotation

GitHub Actions / PHP on 8.3 - prefer-stable -

Attribute class Deprecated does not exist.
public static function fromDateRange(DatePeriod $dateRange, Bounds $bounds = Bounds::IncludeStartExcludeEnd): self
{
return new self(
self::filterDatePoint($dateRange->getStartDate()),
self::filterDatePoint($dateRange->getEndDate() ?? throw InvalidInterval::dueToInvalidDatePeriod()),
$bounds
);
}
}

0 comments on commit d985041

Please sign in to comment.