Skip to content

Commit 341a7bc

Browse files
committed
Round 2 of psalm-mutation annotations
1 parent 2477866 commit 341a7bc

19 files changed

Lines changed: 155 additions & 18 deletions

src/Clock.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface Clock
88
{
99
/**
1010
* Returns the current time.
11+
*
12+
* @psalm-mutation-free
1113
*/
1214
public function getTime() : Instant;
1315
}

src/Clock/OffsetClock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function __construct(Clock $referenceClock, Duration $offset)
3737
$this->offset = $offset;
3838
}
3939

40+
/**
41+
* @psalm-mutation-free
42+
*/
4043
public function getTime() : Instant
4144
{
4245
return $this->referenceClock->getTime()->plus($this->offset);

src/Clock/ScaleClock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public function __construct(Clock $referenceClock, int $timeScale)
5050
$this->timeScale = $timeScale;
5151
}
5252

53+
/**
54+
* @psalm-mutation-free
55+
*/
5356
public function getTime() : Instant
5457
{
5558
$duration = Duration::between($this->startTime, $this->referenceClock->getTime());

src/Clock/SystemClock.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414
*/
1515
final class SystemClock implements Clock
1616
{
17+
/**
18+
* @psalm-mutation-free
19+
*/
1720
public function getTime() : Instant
1821
{
22+
/**
23+
* @psalm-suppress ImpureFunctionCall This is how time works
24+
*/
1925
[$fraction, $epochSecond] = \explode(' ', microtime());
2026

2127
$epochSecond = (int) $epochSecond;

src/DayOfWeek.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ private function __construct(int $value)
4747
*/
4848
private static function get(int $value) : DayOfWeek
4949
{
50-
/** @var array<int, DayOfWeek> $values */
50+
/**
51+
* @var array<int, DayOfWeek> $values
52+
* @psalm-suppress ImpureStaticVariable only used to cache results
53+
*/
5154
static $values = [];
5255

5356
if (! isset($values[$value])) {

src/DefaultClock.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ private function __construct()
3131
/**
3232
* Gets the default clock.
3333
*
34-
* @psalm-external-mutation-free
34+
* @psalm-mutation-free
35+
* @psalm-suppress ImpureStaticProperty
3536
*/
3637
public static function get() : Clock
3738
{

src/Field/TimeZoneOffsetHour.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final class TimeZoneOffsetHour
2525
* @param int $offsetHour The offset-hour to check.
2626
*
2727
* @throws DateTimeException If the offset-hour is not valid.
28+
*
29+
* @psalm-pure
2830
*/
2931
public static function check(int $offsetHour) : void
3032
{

src/Field/TimeZoneOffsetMinute.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final class TimeZoneOffsetMinute
2525
* @param int $offsetMinute The offset-minute to check.
2626
*
2727
* @throws DateTimeException If the offset-minute is not valid.
28+
*
29+
* @psalm-pure
2830
*/
2931
public static function check(int $offsetMinute) : void
3032
{

src/Field/TimeZoneOffsetSecond.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final class TimeZoneOffsetSecond
2525
* @param int $offsetSecond The offset-second to check.
2626
*
2727
* @throws DateTimeException If the offset-second is not valid.
28+
*
29+
* @psalm-pure
2830
*/
2931
public static function check(int $offsetSecond) : void
3032
{

0 commit comments

Comments
 (0)