Skip to content

Commit e026aef

Browse files
committed
replace fully qualified names with imports #6
1 parent e93021f commit e026aef

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

src/SapDateInterval.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace phpsap\DateTime;
1414

1515
use DateInterval;
16+
use Exception;
1617

1718
/**
1819
* Class SapDateInterval
@@ -33,8 +34,8 @@ class SapDateInterval extends DateInterval
3334
/**
3435
* Sets up a DateInterval from the relative parts of the string
3536
* @param string $time
36-
* @return \DateInterval
37-
* @throws \Exception
37+
* @return DateInterval
38+
* @throws Exception
3839
* @link https://php.net/manual/en/dateinterval.createfromdatestring.php
3940
*/
4041
public static function createFromDateString($time)

src/SapDateTime.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
namespace phpsap\DateTime;
1414

15+
use DateTime;
16+
use DateTimeZone;
17+
use Exception;
18+
1519
/**
1620
* Class phpsap\DateTime\SapDateTime
1721
*
@@ -22,7 +26,7 @@
2226
* @author Gregor J.
2327
* @license MIT
2428
*/
25-
class SapDateTime extends \DateTime
29+
class SapDateTime extends DateTime
2630
{
2731
/**
2832
* @const string SAP week format.
@@ -54,10 +58,10 @@ class SapDateTime extends \DateTime
5458
* Parse an SAP week string into a new DateTime object.
5559
*
5660
* @param string $sapWeek String representing the SAP week.
57-
* @param \DateTimeZone $timezone A DateTimeZone object representing the desired
61+
* @param DateTimeZone $timezone A DateTimeZone object representing the desired
5862
* time zone.
59-
* @return \DateTime|bool
60-
* @throws \Exception
63+
* @return DateTime|bool
64+
* @throws Exception
6165
*/
6266
public static function createFromSapWeek($sapWeek, $timezone = null)
6367
{
@@ -73,10 +77,10 @@ public static function createFromSapWeek($sapWeek, $timezone = null)
7377
*
7478
* @param string $format Format accepted by date().
7579
* @param string $time String representing the time.
76-
* @param \DateTimeZone $timezone A DateTimeZone object representing the desired
80+
* @param DateTimeZone $timezone A DateTimeZone object representing the desired
7781
* time zone.
78-
* @return \DateTime|bool
79-
* @throws \Exception
82+
* @return DateTime|bool
83+
* @throws Exception
8084
*
8185
* @link https://php.net/manual/en/datetime.createfromformat.php
8286
*/

tests/SapDateIntervalTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace tests\phpsap\DateTime;
1414

15+
use DateTime;
16+
use Exception;
1517
use phpsap\DateTime\SapDateInterval;
1618
use PHPUnit\Framework\TestCase;
1719

@@ -44,12 +46,12 @@ public static function provideValidTimes()
4446
* @param string $sapTime
4547
* @param string $startDate
4648
* @param string $expected
47-
* @throws \Exception
49+
* @throws Exception
4850
* @dataProvider provideValidTimes
4951
*/
5052
public function testValidTimes($sapTime, $startDate, $expected)
5153
{
52-
$dateTime = new \DateTime($startDate);
54+
$dateTime = new DateTime($startDate);
5355
$time = SapDateInterval::createFromDateString($sapTime);
5456
$dateTime->add($time);
5557
static::assertSame($expected, $dateTime->format('Y-m-d H:i:s'));

tests/SapDateTimeTest.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace tests\phpsap\DateTime;
1414

15+
use DateTime;
16+
use DateTimeZone;
17+
use Exception;
1518
use phpsap\DateTime\SapDateTime;
1619
use PHPUnit\Framework\TestCase;
1720

@@ -51,12 +54,12 @@ public static function validSapWeeks()
5154
* @param string $expected The expected week in format <year>W<week>.
5255
* @param string $timestamp The expected timestamp in format Y-m-d H:i:s
5356
* @dataProvider validSapWeeks
54-
* @throws \Exception
57+
* @throws Exception
5558
*/
5659
public function testParseSapWeeks($sapWeek, $expected, $timestamp)
5760
{
5861
$dateTime = SapDateTime::createFromFormat(SapDateTime::SAP_WEEK, $sapWeek);
59-
static::assertInstanceOf(\DateTime::class, $dateTime);
62+
static::assertInstanceOf(DateTime::class, $dateTime);
6063
static::assertSame($expected, $dateTime->format('o \w\e\ek W'));
6164
static::assertSame($timestamp, $dateTime->format('Y-m-d H:i:s'));
6265
}
@@ -81,7 +84,7 @@ public static function invalidSapWeeks()
8184
*
8285
* @param string $sapWeek The SAP week string.
8386
* @dataProvider invalidSapWeeks
84-
* @throws \Exception
87+
* @throws Exception
8588
*/
8689
public function testParseInvalidSapWeeks($sapWeek)
8790
{
@@ -110,7 +113,7 @@ public static function timestampsAndSapWeeks()
110113
* Test formatting timestamps to SAP week strings.
111114
* @param string $timestamp Timestamp string
112115
* @param string $expected SAP week string
113-
* @throws \Exception
116+
* @throws Exception
114117
* @dataProvider timestampsAndSapWeeks
115118
*/
116119
public function testCreateSapWeeks($timestamp, $expected)
@@ -141,7 +144,7 @@ public static function sapDatesAndIsoDates()
141144
* Test parsing SAP dates.
142145
* @param string $sapDate
143146
* @param string $isoDate
144-
* @throws \Exception
147+
* @throws Exception
145148
* @dataProvider sapDatesAndIsoDates
146149
*/
147150
public function testParseSapDates($sapDate, $isoDate)
@@ -168,7 +171,7 @@ public static function timesAndSapTimes()
168171
* Test formatting an ISO time as SAP time.
169172
* @param string $isoTime
170173
* @param string $sapTime
171-
* @throws \Exception
174+
* @throws Exception
172175
* @dataProvider timesAndSapTimes
173176
*/
174177
public function testCreateSapTimes($isoTime, $sapTime)
@@ -181,7 +184,7 @@ public function testCreateSapTimes($isoTime, $sapTime)
181184
* Test reading time from SAP and formatting it as ISO.
182185
* @param string $isoTime
183186
* @param string $sapTime
184-
* @throws \Exception
187+
* @throws Exception
185188
* @dataProvider timesAndSapTimes
186189
*/
187190
public function testParseSapTimes($isoTime, $sapTime)
@@ -211,7 +214,7 @@ public static function timestampsAndSapDates()
211214
* Test formatting DateTime objects as SAP dates.
212215
* @param string $timestamp
213216
* @param string $sapDate
214-
* @throws \Exception
217+
* @throws Exception
215218
* @dataProvider timestampsAndSapDates
216219
*/
217220
public function testCreateSapDates($timestamp, $sapDate)
@@ -241,7 +244,7 @@ public static function timestampsAndSapTimestamps()
241244
* Test parsing SAP timestamps.
242245
* @param string $isotime
243246
* @param string $saptime
244-
* @throws \Exception
247+
* @throws Exception
245248
* @dataProvider timestampsAndSapTimestamps
246249
*/
247250
public function testParseSapTimestamps($isotime, $saptime)
@@ -254,7 +257,7 @@ public function testParseSapTimestamps($isotime, $saptime)
254257
* Test formatting DateTime objects as SAP timestamps.
255258
* @param string $isotime
256259
* @param string $saptime
257-
* @throws \Exception
260+
* @throws Exception
258261
* @dataProvider timestampsAndSapTimestamps
259262
*/
260263
public function testCreateSapTimestamps($isotime, $saptime)
@@ -273,21 +276,21 @@ public static function provideTimezones()
273276
[
274277
SapDateTime::SAP_TIMESTAMP,
275278
'20200301000102',
276-
new \DateTimeZone('CET'),
279+
new DateTimeZone('CET'),
277280
'2020-03-01T00:01:02+01:00',
278281
'2020-02-29T23:01:02+00:00'
279282
],
280283
[
281284
'Y-m-d H:i:s',
282285
'2020-03-01 00:01:02',
283-
new \DateTimeZone('CET'),
286+
new DateTimeZone('CET'),
284287
'2020-03-01T00:01:02+01:00',
285288
'2020-02-29T23:01:02+00:00'
286289
],
287290
[
288291
SapDateTime::SAP_DATE,
289292
'20200301',
290-
new \DateTimeZone('CET'),
293+
new DateTimeZone('CET'),
291294
'2020-03-01T00:00:00+01:00',
292295
'2020-02-29T23:00:00+00:00'
293296
]
@@ -299,16 +302,16 @@ public static function provideTimezones()
299302
* @dataProvider provideTimezones
300303
* @param string $format
301304
* @param string $time
302-
* @param \DateTimeZone $zone
305+
* @param DateTimeZone $zone
303306
* @param string $expected
304307
* @param string $utc
305-
* @throws \Exception
308+
* @throws Exception
306309
*/
307310
public function testTimezones($format, $time, $zone, $expected, $utc)
308311
{
309312
$dateTime = SapDateTime::createFromFormat($format, $time, $zone);
310313
static::assertSame($expected, $dateTime->format('c'));
311-
$dateTime->setTimezone(new \DateTimeZone('UTC'));
314+
$dateTime->setTimezone(new DateTimeZone('UTC'));
312315
static::assertSame($utc, $dateTime->format('c'));
313316
}
314317
}

0 commit comments

Comments
 (0)