Skip to content

Commit 7ec3443

Browse files
committed
update classes for PHP 8.1 #8
1 parent 69ae216 commit 7ec3443

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

src/SapDateInterval.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class SapDateInterval extends DateInterval
3636
/**
3737
* Sets up a DateInterval from the relative parts of the string
3838
* @param string $datetime
39-
* @return DateInterval
39+
* @return DateInterval|false
4040
* @throws Exception
4141
* @link https://php.net/manual/en/dateinterval.createfromdatestring.php
4242
*/
43-
public static function createFromDateString($datetime): DateInterval
43+
public static function createFromDateString(string $datetime): DateInterval|false
4444
{
4545
$matches = [];
4646
if (preg_match('~^([\d]{2})([0-5][\d])([0-5][\d])$~', $datetime, $matches)) {

src/SapDateTime.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class SapDateTime extends DateTime
6262
* @param string $sapWeek String representing the SAP week.
6363
* @param DateTimeZone|null $timezone A DateTimeZone object representing the desired
6464
* time zone.
65-
* @return DateTime|bool
65+
* @return DateTime|false
6666
* @throws Exception
6767
*/
68-
public static function createFromSapWeek(string $sapWeek, DateTimeZone $timezone = null)
68+
public static function createFromSapWeek(string $sapWeek, DateTimeZone $timezone = null): DateTime|false
6969
{
7070
if (preg_match(static::$sapWeekRegex, $sapWeek, $matches) !== 1) {
7171
return false;
@@ -81,16 +81,16 @@ public static function createFromSapWeek(string $sapWeek, DateTimeZone $timezone
8181
* @param string $datetime String representing the time.
8282
* @param DateTimeZone|null $timezone A DateTimeZone object representing the desired
8383
* time zone.
84-
* @return DateTime|bool
84+
* @return DateTime|false
8585
* @throws Exception
8686
*
8787
* @link https://php.net/manual/en/datetime.createfromformat.php
8888
*/
8989
public static function createFromFormat(
90-
$format,
91-
$datetime,
92-
DateTimeZone $timezone = null
93-
) {
90+
string $format,
91+
string $datetime,
92+
DateTimeZone|null $timezone = null
93+
): DateTime|false {
9494
if ($format === static::SAP_WEEK) {
9595
return static::createFromSapWeek($datetime, $timezone);
9696
}

tests/SapDateIntervalTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace tests\phpsap\DateTime;
1616

17+
use DateInterval;
1718
use DateTime;
1819
use Exception;
1920
use phpsap\DateTime\SapDateInterval;
@@ -32,7 +33,7 @@ class SapDateIntervalTest extends TestCase
3233
{
3334
/**
3435
* Data provider for valid time return values from SAP.
35-
* @return array
36+
* @return array<int, array<int, string>>
3637
*/
3738
public static function provideValidTimes(): array
3839
{
@@ -51,10 +52,11 @@ public static function provideValidTimes(): array
5152
* @throws Exception
5253
* @dataProvider provideValidTimes
5354
*/
54-
public function testValidTimes(string $sapTime, string $startDate, string $expected)
55+
public function testValidTimes(string $sapTime, string $startDate, string $expected): void
5556
{
5657
$dateTime = new DateTime($startDate);
5758
$time = SapDateInterval::createFromDateString($sapTime);
59+
static::assertInstanceOf(DateInterval::class, $time);
5860
$dateTime->add($time);
5961
static::assertSame($expected, $dateTime->format('Y-m-d H:i:s'));
6062
}

tests/SapDateTimeTest.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SapDateTimeTest extends TestCase
3434
/**
3535
* Data provider for valid SAP week strings and the expected output.
3636
*
37-
* @return array
37+
* @return array<int, array<int, string>>
3838
*/
3939
public static function validSapWeeks(): array
4040
{
@@ -58,7 +58,7 @@ public static function validSapWeeks(): array
5858
* @dataProvider validSapWeeks
5959
* @throws Exception
6060
*/
61-
public function testParseSapWeeks(string $sapWeek, string $expected, string $timestamp)
61+
public function testParseSapWeeks(string $sapWeek, string $expected, string $timestamp): void
6262
{
6363
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_WEEK, $sapWeek);
6464
static::assertInstanceOf(DateTime::class, $dateTime);
@@ -69,7 +69,7 @@ public function testParseSapWeeks(string $sapWeek, string $expected, string $tim
6969
/**
7070
* Data provider for invalid SAP week strings.
7171
*
72-
* @return array
72+
* @return array<int, array<int, string>>
7373
*/
7474
public static function invalidSapWeeks(): array
7575
{
@@ -88,15 +88,15 @@ public static function invalidSapWeeks(): array
8888
* @dataProvider invalidSapWeeks
8989
* @throws Exception
9090
*/
91-
public function testParseInvalidSapWeeks(string $sapWeek)
91+
public function testParseInvalidSapWeeks(string $sapWeek): void
9292
{
9393
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_WEEK, $sapWeek);
9494
static::assertFalse($dateTime);
9595
}
9696

9797
/**
9898
* Data provider of timestamps and their according SAP week strings.
99-
* @return array
99+
* @return array<int, array<int, string>>
100100
*/
101101
public static function timestampsAndSapWeeks(): array
102102
{
@@ -118,7 +118,7 @@ public static function timestampsAndSapWeeks(): array
118118
* @throws Exception
119119
* @dataProvider timestampsAndSapWeeks
120120
*/
121-
public function testCreateSapWeeks(string $timestamp, string $expected)
121+
public function testCreateSapWeeks(string $timestamp, string $expected): void
122122
{
123123
$dateTime = new SapDateTime($timestamp);
124124
$sapWeekString = $dateTime->format(SapDateTime::SAP_WEEK);
@@ -127,7 +127,7 @@ public function testCreateSapWeeks(string $timestamp, string $expected)
127127

128128
/**
129129
* Data provider of SAP dates and their ISO date representations.
130-
* @return array
130+
* @return array<int, array<int, string>>
131131
*/
132132
public static function sapDatesAndIsoDates(): array
133133
{
@@ -149,15 +149,16 @@ public static function sapDatesAndIsoDates(): array
149149
* @throws Exception
150150
* @dataProvider sapDatesAndIsoDates
151151
*/
152-
public function testParseSapDates(string $sapDate, string $isoDate)
152+
public function testParseSapDates(string $sapDate, string $isoDate): void
153153
{
154154
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_DATE, $sapDate);
155+
static::assertInstanceOf(DateTime::class, $dateTime);
155156
static::assertSame($isoDate, $dateTime->format('Y-m-d H:i:s'));
156157
}
157158

158159
/**
159160
* Data provider of times and their according SAP time strings.
160-
* @return array
161+
* @return array<int, array<int, string>>
161162
*/
162163
public static function timesAndSapTimes(): array
163164
{
@@ -176,7 +177,7 @@ public static function timesAndSapTimes(): array
176177
* @throws Exception
177178
* @dataProvider timesAndSapTimes
178179
*/
179-
public function testCreateSapTimes(string $isoTime, string $sapTime)
180+
public function testCreateSapTimes(string $isoTime, string $sapTime): void
180181
{
181182
$dateTime = new SapDateTime($isoTime);
182183
static::assertSame($sapTime, $dateTime->format(SapDateTime::SAP_TIME));
@@ -189,15 +190,16 @@ public function testCreateSapTimes(string $isoTime, string $sapTime)
189190
* @throws Exception
190191
* @dataProvider timesAndSapTimes
191192
*/
192-
public function testParseSapTimes(string $isoTime, string $sapTime)
193+
public function testParseSapTimes(string $isoTime, string $sapTime): void
193194
{
194195
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_TIME, $sapTime);
196+
static::assertInstanceOf(DateTime::class, $dateTime);
195197
static::assertSame($isoTime, $dateTime->format('H:i:s'));
196198
}
197199

198200
/**
199201
* Data provider of timestamps and their according SAP dates.
200-
* @return array
202+
* @return array<int, array<int, string>>
201203
*/
202204
public static function timestampsAndSapDates(): array
203205
{
@@ -219,15 +221,15 @@ public static function timestampsAndSapDates(): array
219221
* @throws Exception
220222
* @dataProvider timestampsAndSapDates
221223
*/
222-
public function testCreateSapDates(string $timestamp, string $sapDate)
224+
public function testCreateSapDates(string $timestamp, string $sapDate): void
223225
{
224226
$dateTime = new SapDateTime($timestamp);
225227
static::assertSame($sapDate, $dateTime->format(SapDateTime::SAP_DATE));
226228
}
227229

228230
/**
229231
* Data provider of timestamps and their according SAP timestamps.
230-
* @return array
232+
* @return array<int, array<int, string>>
231233
*/
232234
public static function timestampsAndSapTimestamps(): array
233235
{
@@ -249,9 +251,10 @@ public static function timestampsAndSapTimestamps(): array
249251
* @throws Exception
250252
* @dataProvider timestampsAndSapTimestamps
251253
*/
252-
public function testParseSapTimestamps(string $isotime, string $saptime)
254+
public function testParseSapTimestamps(string $isotime, string $saptime): void
253255
{
254256
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_TIMESTAMP, $saptime);
257+
static::assertInstanceOf(DateTime::class, $dateTime);
255258
static::assertSame($isotime, $dateTime->format('Y-m-d H:i:s'));
256259
}
257260

@@ -262,15 +265,15 @@ public function testParseSapTimestamps(string $isotime, string $saptime)
262265
* @throws Exception
263266
* @dataProvider timestampsAndSapTimestamps
264267
*/
265-
public function testCreateSapTimestamps(string $isotime, string $saptime)
268+
public function testCreateSapTimestamps(string $isotime, string $saptime): void
266269
{
267270
$dateTime = new SapDateTime($isotime);
268271
static::assertSame($saptime, $dateTime->format(SapDateTime::SAP_TIMESTAMP));
269272
}
270273

271274
/**
272275
* Data provider for timezones.
273-
* @return array
276+
* @return array<int, array<int, mixed>>
274277
*/
275278
public static function provideTimezones(): array
276279
{
@@ -309,9 +312,10 @@ public static function provideTimezones(): array
309312
* @param string $utc
310313
* @throws Exception
311314
*/
312-
public function testTimezones(string $format, string $time, DateTimeZone $zone, string $expected, string $utc)
315+
public function testTimezones(string $format, string $time, DateTimeZone $zone, string $expected, string $utc): void
313316
{
314317
$dateTime = SapDateTime::createFromFormat($format, $time, $zone);
318+
static::assertInstanceOf(DateTime::class, $dateTime);
315319
static::assertSame($expected, $dateTime->format('c'));
316320
$dateTime->setTimezone(new DateTimeZone('UTC'));
317321
static::assertSame($utc, $dateTime->format('c'));

0 commit comments

Comments
 (0)