Skip to content

Commit f860d84

Browse files
committed
Handling PHP8.3 changes in Exception handling for date
1 parent 767c8bd commit f860d84

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
"ext-json": "*"
4848
},
4949
"require-dev": {
50-
"friendsofphp/php-cs-fixer": "^v3.13.1",
51-
"phpstan/phpstan": "^1.10.2",
52-
"phpstan/phpstan-deprecation-rules": "^1.1.2",
53-
"phpstan/phpstan-phpunit": "^1.3.7",
54-
"phpstan/phpstan-strict-rules": "^1.5.0",
55-
"phpunit/phpunit": "^10.0.12"
50+
"friendsofphp/php-cs-fixer": "^v3.22.0",
51+
"phpstan/phpstan": "^1.10.28",
52+
"phpstan/phpstan-deprecation-rules": "^1.1.4",
53+
"phpstan/phpstan-phpunit": "^1.3.13",
54+
"phpstan/phpstan-strict-rules": "^1.5.1",
55+
"phpunit/phpunit": "^10.3.1"
5656
},
5757
"autoload": {
5858
"psr-4": {
@@ -65,7 +65,7 @@
6565
"scripts": {
6666
"phpcs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff -vvv --allow-risky=yes --ansi",
6767
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
68-
"phpstan": "phpstan analyse -c phpstan.neon --xdebug --ansi --memory-limit 192M",
68+
"phpstan": "phpstan analyse -c phpstan.neon --ansi --memory-limit 192M",
6969
"phpunit": "XDEBUG_MODE=coverage phpunit --coverage-text",
7070
"test": [
7171
"@phpunit",

phpunit.xml

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
33
<coverage>
4-
<include>
5-
<directory suffix=".php">src</directory>
6-
</include>
7-
<exclude>
8-
<directory suffix="Test.php">src</directory>
9-
</exclude>
104
<report>
115
<clover outputFile="build/clover.xml"/>
126
<html outputDirectory="build/coverage"/>
@@ -21,4 +15,12 @@
2115
<logging>
2216
<junit outputFile="build/junit.xml"/>
2317
</logging>
18+
<source>
19+
<include>
20+
<directory suffix=".php">src</directory>
21+
</include>
22+
<exclude>
23+
<directory suffix="Test.php">src</directory>
24+
</exclude>
25+
</source>
2426
</phpunit>

src/Duration.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use DateTimeInterface;
1919
use Exception;
2020
use InvalidArgumentException;
21+
use Throwable;
2122
use function preg_match;
2223
use function str_pad;
2324
use function strlen;
@@ -166,7 +167,12 @@ public static function fromTimeString(string $duration): self
166167
*/
167168
public static function fromDateString(string $duration): self
168169
{
169-
$dateInterval = DateInterval::createFromDateString($duration);
170+
try {
171+
$dateInterval = DateInterval::createFromDateString($duration);
172+
} catch (Throwable $exception) {
173+
throw new InvalidArgumentException('Unknown or bad format `'.$duration.'`.', 0, $exception);
174+
}
175+
170176
if (false === $dateInterval) {
171177
throw new InvalidArgumentException('Unknown or bad format `'.$duration.'`.');
172178
}

src/Period.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public function dateRangeForward(Period|Duration|DateInterval|string $timeDelta,
794794

795795
/**
796796
* @deprecated since version 5.2.0
797-
* @see ::rangeBackwards
797+
* @see Period::rangeBackwards()
798798
*
799799
* Allows iteration over a set of dates and times,
800800
* recurring at regular intervals, over the instance backwards starting from the instance ending.

src/PeriodFactoryTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,23 @@ public function testFromRange(int $option, Bounds $expectedBounds): void
234234
*/
235235
public static function provideDatePeriodOptions(): iterable
236236
{
237-
yield 'include start date' => [
237+
yield 'include start date legacy' => [
238238
'options' => DatePeriod::EXCLUDE_START_DATE,
239239
'expectedBounds' => Bounds::ExcludeAll,
240240
];
241241

242-
yield 'exclude start date' => [
242+
yield 'exclude start date legacy' => [
243243
'options' => 0,
244244
'expectedBounds' => Bounds::IncludeStartExcludeEnd,
245245
];
246246

247247
if (defined('DatePeriod::INCLUDE_END_DATE')) {
248-
yield 'include all' => [
248+
yield 'include all new' => [
249249
'options' => DatePeriod::INCLUDE_END_DATE,
250250
'expectedBounds' => Bounds::IncludeAll,
251251
];
252252

253-
yield 'exclude start date' => [
253+
yield 'exclude start date new' => [
254254
'options' => DatePeriod::INCLUDE_END_DATE | DatePeriod::EXCLUDE_START_DATE,
255255
'expectedBounds' => Bounds::ExcludeStartIncludeEnd,
256256
];

src/Sequence.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ public function map(Closure $closure): self
570570
* @template TReduceReturnType
571571
*
572572
* @param Closure(TReduceInitial|TReduceReturnType, Period, array-key=): TReduceReturnType $closure
573-
* @param TReduceInitial $carry
573+
* @param TReduceInitial $carry
574574
*
575575
* @return TReduceInitial|TReduceReturnType
576576
*/

0 commit comments

Comments
 (0)