Skip to content

Commit c780a8f

Browse files
authored
Merge pull request #97 from gnutix/add-more-psalm-annotations
Add @psalm-* annotations for better static analysis (compatible with PHPStan too)
2 parents 68f799e + fe52b56 commit c780a8f

17 files changed

+115
-0
lines changed

src/DayOfWeek.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ public function minus(int $days): DayOfWeek
226226

227227
/**
228228
* Serializes as a string using {@see DayOfWeek::toString()}.
229+
*
230+
* @psalm-return non-empty-string
229231
*/
230232
public function jsonSerialize(): string
231233
{
@@ -234,6 +236,8 @@ public function jsonSerialize(): string
234236

235237
/**
236238
* Returns the capitalized English name of this day-of-week.
239+
*
240+
* @psalm-return non-empty-string
237241
*/
238242
public function toString(): string
239243
{

src/Duration.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ public function abs(): Duration
466466
* @param Duration $that The other duration to compare to.
467467
*
468468
* @return int [-1,0,1] If this duration is less than, equal to, or greater than the given duration.
469+
*
470+
* @psalm-return -1|0|1
469471
*/
470472
public function compareTo(Duration $that): int
471473
{
@@ -756,6 +758,8 @@ public function toNanosPart(): int
756758

757759
/**
758760
* Serializes as a string using {@see Duration::toISOString()}.
761+
*
762+
* @psalm-return non-empty-string
759763
*/
760764
public function jsonSerialize(): string
761765
{
@@ -772,6 +776,8 @@ public function jsonSerialize(): string
772776
* The hours, minutes and seconds will all have the same sign.
773777
*
774778
* Note that multiples of 24 hours are not output as days to avoid confusion with Period.
779+
*
780+
* @psalm-return non-empty-string
775781
*/
776782
public function toISOString(): string
777783
{
@@ -817,6 +823,8 @@ public function toISOString(): string
817823

818824
/**
819825
* {@see Duration::toISOString()}.
826+
*
827+
* @psalm-return non-empty-string
820828
*/
821829
public function __toString(): string
822830
{

src/Instant.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ public function getNano(): int
238238
* Compares this instant with another.
239239
*
240240
* @return int [-1,0,1] If this instant is before, on, or after the given instant.
241+
*
242+
* @psalm-return -1|0|1
241243
*/
242244
public function compareTo(Instant $that): int
243245
{
@@ -368,6 +370,8 @@ public function toDecimal(): string
368370

369371
/**
370372
* Serializes as a string using {@see Instant::toISOString()}.
373+
*
374+
* @psalm-return non-empty-string
371375
*/
372376
public function jsonSerialize(): string
373377
{
@@ -376,6 +380,8 @@ public function jsonSerialize(): string
376380

377381
/**
378382
* Returns the ISO 8601 representation of this instant.
383+
*
384+
* @psalm-return non-empty-string
379385
*/
380386
public function toISOString(): string
381387
{
@@ -384,6 +390,8 @@ public function toISOString(): string
384390

385391
/**
386392
* {@see Instant::toISOString()}.
393+
*
394+
* @psalm-return non-empty-string
387395
*/
388396
public function __toString(): string
389397
{

src/Interval.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public function isEqualTo(Interval $that): bool
140140

141141
/**
142142
* Serializes as a string using {@see Interval::toISOString()}.
143+
*
144+
* @psalm-return non-empty-string
143145
*/
144146
public function jsonSerialize(): string
145147
{
@@ -148,6 +150,8 @@ public function jsonSerialize(): string
148150

149151
/**
150152
* Returns the ISO 8601 representation of this interval.
153+
*
154+
* @psalm-return non-empty-string
151155
*/
152156
public function toISOString(): string
153157
{
@@ -156,6 +160,8 @@ public function toISOString(): string
156160

157161
/**
158162
* {@see Interval::toISOString()}.
163+
*
164+
* @psalm-return non-empty-string
159165
*/
160166
public function __toString(): string
161167
{

src/LocalDate.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ public function minusDays(int $days): LocalDate
591591
* Returns -1 if this date is before the given date, 1 if after, 0 if the dates are equal.
592592
*
593593
* @return int [-1,0,1] If this date is before, on, or after the given date.
594+
*
595+
* @psalm-return -1|0|1
594596
*/
595597
public function compareTo(LocalDate $that): int
596598
{
@@ -771,6 +773,8 @@ public function toNativeDateTimeImmutable(): DateTimeImmutable
771773

772774
/**
773775
* Serializes as a string using {@see LocalDate::toISOString()}.
776+
*
777+
* @psalm-return non-empty-string
774778
*/
775779
public function jsonSerialize(): string
776780
{
@@ -779,6 +783,8 @@ public function jsonSerialize(): string
779783

780784
/**
781785
* Returns the ISO 8601 representation of this date.
786+
*
787+
* @psalm-return non-empty-string
782788
*/
783789
public function toISOString(): string
784790
{
@@ -799,6 +805,8 @@ public function toISOString(): string
799805

800806
/**
801807
* {@see LocalDate::toISOString()}.
808+
*
809+
* @psalm-return non-empty-string
802810
*/
803811
public function __toString(): string
804812
{

src/LocalDateRange.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ public function count(): int
239239

240240
/**
241241
* Serializes as a string using {@see LocalDateRange::toISOString()}.
242+
*
243+
* @psalm-return non-empty-string
242244
*/
243245
public function jsonSerialize(): string
244246
{
@@ -262,6 +264,8 @@ public function toNativeDatePeriod(): DatePeriod
262264

263265
/**
264266
* Returns the ISO 8601 representation of this date range.
267+
*
268+
* @psalm-return non-empty-string
265269
*/
266270
public function toISOString(): string
267271
{
@@ -270,6 +274,8 @@ public function toISOString(): string
270274

271275
/**
272276
* {@see LocalDateRange::toISOString()}.
277+
*
278+
* @psalm-return non-empty-string
273279
*/
274280
public function __toString(): string
275281
{

src/LocalDateTime.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ public function minusNanos(int $nanos): LocalDateTime
659659
* @param LocalDateTime $that The date-time to compare to.
660660
*
661661
* @return int [-1,0,1] If this date-time is before, on, or after the given date-time.
662+
*
663+
* @psalm-return -1|0|1
662664
*/
663665
public function compareTo(LocalDateTime $that): int
664666
{
@@ -738,6 +740,8 @@ public function toNativeDateTimeImmutable(): DateTimeImmutable
738740

739741
/**
740742
* Serializes as a string using {@see LocalDateTime::toISOString()}.
743+
*
744+
* @psalm-return non-empty-string
741745
*/
742746
public function jsonSerialize(): string
743747
{
@@ -746,6 +750,8 @@ public function jsonSerialize(): string
746750

747751
/**
748752
* Returns the ISO 8601 representation of this date time.
753+
*
754+
* @psalm-return non-empty-string
749755
*/
750756
public function toISOString(): string
751757
{
@@ -754,6 +760,8 @@ public function toISOString(): string
754760

755761
/**
756762
* {@see LocalDateTime::toISOString()}.
763+
*
764+
* @psalm-return non-empty-string
757765
*/
758766
public function __toString(): string
759767
{

src/LocalTime.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ public function minusNanos(int $nanos): LocalTime
527527
* @param LocalTime $that The time to compare to.
528528
*
529529
* @return int [-1,0,1] If this time is before, on, or after the given time.
530+
*
531+
* @psalm-return -1|0|1
530532
*/
531533
public function compareTo(LocalTime $that): int
532534
{
@@ -643,6 +645,8 @@ public function toNativeDateTimeImmutable(): DateTimeImmutable
643645

644646
/**
645647
* Serializes as a string using {@see LocalTime::toISOString()}.
648+
*
649+
* @psalm-return non-empty-string
646650
*/
647651
public function jsonSerialize(): string
648652
{
@@ -661,6 +665,8 @@ public function jsonSerialize(): string
661665
* The format used will be the shortest that outputs the full value of
662666
* the time where the omitted parts are implied to be zero.
663667
* The nanoseconds value, if present, can be 0 to 9 digits.
668+
*
669+
* @psalm-return non-empty-string
664670
*/
665671
public function toISOString(): string
666672
{
@@ -674,6 +680,8 @@ public function toISOString(): string
674680

675681
/**
676682
* {@see LocalTime::toISOString()}.
683+
*
684+
* @psalm-return non-empty-string
677685
*/
678686
public function __toString(): string
679687
{

src/Month.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ public function minus(int $months): Month
201201

202202
/**
203203
* Serializes as a string using {@see Month::toString()}.
204+
*
205+
* @psalm-return non-empty-string
204206
*/
205207
public function jsonSerialize(): string
206208
{
@@ -209,6 +211,8 @@ public function jsonSerialize(): string
209211

210212
/**
211213
* Returns the capitalized English name of this Month.
214+
*
215+
* @psalm-return non-empty-string
212216
*/
213217
public function toString(): string
214218
{

src/MonthDay.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public function getDayOfMonth(): int
133133
* Returns -1 if this date is before the given date, 1 if after, 0 if the dates are equal.
134134
*
135135
* @return int [-1,0,1] If this date is before, on, or after the given date.
136+
*
137+
* @psalm-return -1|0|1
136138
*/
137139
public function compareTo(MonthDay $that): int
138140
{
@@ -243,6 +245,8 @@ public function atYear(int $year): LocalDate
243245

244246
/**
245247
* Serializes as a string using {@see MonthDay::toISOString()}.
248+
*
249+
* @psalm-return non-empty-string
246250
*/
247251
public function jsonSerialize(): string
248252
{
@@ -251,6 +255,8 @@ public function jsonSerialize(): string
251255

252256
/**
253257
* Returns the ISO 8601 representation of this month-day.
258+
*
259+
* @psalm-return non-empty-string
254260
*/
255261
public function toISOString(): string
256262
{
@@ -263,6 +269,8 @@ public function toISOString(): string
263269

264270
/**
265271
* {@see MonthDay::toISOString()}.
272+
*
273+
* @psalm-return non-empty-string
266274
*/
267275
public function __toString(): string
268276
{

0 commit comments

Comments
 (0)