diff --git a/src/Clock/FixedClock.php b/src/Clock/FixedClock.php index 29754cba..3a22e5d2 100644 --- a/src/Clock/FixedClock.php +++ b/src/Clock/FixedClock.php @@ -13,14 +13,11 @@ */ final class FixedClock implements Clock { - private Instant $instant; - /** * @param Instant $instant The time to set the clock at. */ - public function __construct(Instant $instant) + public function __construct(private Instant $instant) { - $this->instant = $instant; } public function getTime(): Instant diff --git a/src/Clock/OffsetClock.php b/src/Clock/OffsetClock.php index 14c1df12..d27cf282 100644 --- a/src/Clock/OffsetClock.php +++ b/src/Clock/OffsetClock.php @@ -13,24 +13,14 @@ */ final class OffsetClock implements Clock { - /** - * The reference clock. - */ - private readonly Clock $referenceClock; - - /** - * The offset to apply to the clock. - */ - private readonly Duration $offset; - /** * @param Clock $referenceClock The reference clock. * @param Duration $offset The offset to apply to the clock. */ - public function __construct(Clock $referenceClock, Duration $offset) - { - $this->referenceClock = $referenceClock; - $this->offset = $offset; + public function __construct( + private readonly Clock $referenceClock, + private readonly Duration $offset + ) { } public function getTime(): Instant diff --git a/src/Clock/ScaleClock.php b/src/Clock/ScaleClock.php index e9da3817..3c478c25 100644 --- a/src/Clock/ScaleClock.php +++ b/src/Clock/ScaleClock.php @@ -13,21 +13,11 @@ */ final class ScaleClock implements Clock { - /** - * The reference clock. - */ - private readonly Clock $referenceClock; - /** * The start time. */ private readonly Instant $startTime; - /** - * The time scale. - */ - private readonly int $timeScale; - /** * - a scale > 1 makes the time move at an accelerated pace; * - a scale == 1 makes the time move at the normal pace; @@ -37,11 +27,11 @@ final class ScaleClock implements Clock * @param Clock $referenceClock The reference clock. * @param int $timeScale The time scale. */ - public function __construct(Clock $referenceClock, int $timeScale) - { - $this->referenceClock = $referenceClock; - $this->startTime = $referenceClock->getTime(); - $this->timeScale = $timeScale; + public function __construct( + private readonly Clock $referenceClock, + private readonly int $timeScale + ) { + $this->startTime = $this->referenceClock->getTime(); } public function getTime(): Instant diff --git a/src/Duration.php b/src/Duration.php index 77d35834..472780b6 100644 --- a/src/Duration.php +++ b/src/Duration.php @@ -26,28 +26,17 @@ */ final class Duration implements JsonSerializable, Stringable { - /** - * The duration in seconds. - */ - private readonly int $seconds; - - /** - * The nanoseconds adjustment to the duration, in the range 0 to 999,999,999. - * - * A duration of -1 nanoseconds is stored as -1 seconds plus 999,999,999 nanoseconds. - */ - private readonly int $nanos; - /** * Private constructor. Use one of the factory methods to obtain a Duration. * * @param int $seconds The duration in seconds. - * @param int $nanos The nanoseconds adjustment, validated in the range 0 to 999,999,999. + * @param int $nanos The nanoseconds adjustment to the duration, validated in the range 0 to 999,999,999. + * A duration of -1 nanoseconds is stored as -1 seconds plus 999,999,999 nanoseconds. */ - private function __construct(int $seconds, int $nanos = 0) - { - $this->seconds = $seconds; - $this->nanos = $nanos; + private function __construct( + private readonly int $seconds, + private readonly int $nanos = 0 + ) { } /** diff --git a/src/Instant.php b/src/Instant.php index 14c17b3d..fca1a7d2 100644 --- a/src/Instant.php +++ b/src/Instant.php @@ -25,26 +25,16 @@ */ final class Instant implements JsonSerializable, Stringable { - /** - * The number of seconds since the epoch of 1970-01-01T00:00:00Z. - */ - private readonly int $epochSecond; - - /** - * The nanoseconds adjustment to the epoch second, in the range 0 to 999,999,999. - */ - private readonly int $nano; - /** * Private constructor. Use of() to obtain an Instant. * - * @param int $epochSecond The epoch second. - * @param int $nano The nanosecond adjustment, validated in the range 0 to 999,999,999. + * @param int $epochSecond The number of seconds since the epoch of 1970-01-01T00:00:00Z. + * @param int $nano The nanosecond adjustment to the epoch second, validated in the range 0 to 999,999,999. */ - private function __construct(int $epochSecond, int $nano) - { - $this->epochSecond = $epochSecond; - $this->nano = $nano; + private function __construct( + private readonly int $epochSecond, + private readonly int $nano + ) { } /** diff --git a/src/Interval.php b/src/Interval.php index d8476964..0d477b18 100644 --- a/src/Interval.php +++ b/src/Interval.php @@ -16,23 +16,13 @@ final class Interval implements JsonSerializable, Stringable { /** - * The start instant, inclusive. + * @param Instant $start The start instant, inclusive. + * @param Instant $end The end instant, exclusive, validated as not before the start instant. */ - private readonly Instant $start; - - /** - * The end instant, exclusive. - */ - private readonly Instant $end; - - /** - * @param Instant $startInclusive The start instant, inclusive. - * @param Instant $endExclusive The end instant, exclusive, validated as not before the start instant. - */ - private function __construct(Instant $startInclusive, Instant $endExclusive) - { - $this->start = $startInclusive; - $this->end = $endExclusive; + private function __construct( + private readonly Instant $start, + private readonly Instant $end + ) { } /** diff --git a/src/LocalDate.php b/src/LocalDate.php index 59e4859d..1aecf047 100644 --- a/src/LocalDate.php +++ b/src/LocalDate.php @@ -48,21 +48,6 @@ final class LocalDate implements JsonSerializable, Stringable */ public const DAYS_PER_CYCLE = 146097; - /** - * The year. - */ - private readonly int $year; - - /** - * The month-of-year. - */ - private readonly int $month; - - /** - * The day-of-month. - */ - private readonly int $day; - /** * Private constructor. Use of() to obtain an instance. * @@ -70,11 +55,11 @@ final class LocalDate implements JsonSerializable, Stringable * @param int $month The month-of-year, validated from 1 to 12. * @param int $day The day-of-month, validated from 1 to 31, valid for the year-month. */ - private function __construct(int $year, int $month, int $day) - { - $this->year = $year; - $this->month = $month; - $this->day = $day; + private function __construct( + private readonly int $year, + private readonly int $month, + private readonly int $day + ) { } /** diff --git a/src/LocalDateRange.php b/src/LocalDateRange.php index 5c919b82..cb0673a2 100644 --- a/src/LocalDateRange.php +++ b/src/LocalDateRange.php @@ -26,24 +26,14 @@ */ final class LocalDateRange implements IteratorAggregate, Countable, JsonSerializable, Stringable { - /** - * The start date, inclusive. - */ - private readonly LocalDate $start; - - /** - * The end date, inclusive. - */ - private readonly LocalDate $end; - /** * @param LocalDate $start The start date, inclusive. * @param LocalDate $end The end date, inclusive, validated as not before the start date. */ - private function __construct(LocalDate $start, LocalDate $end) - { - $this->start = $start; - $this->end = $end; + private function __construct( + private readonly LocalDate $start, + private readonly LocalDate $end + ) { } /** diff --git a/src/LocalDateTime.php b/src/LocalDateTime.php index 6da9d614..76327045 100644 --- a/src/LocalDateTime.php +++ b/src/LocalDateTime.php @@ -24,14 +24,10 @@ */ final class LocalDateTime implements JsonSerializable, Stringable { - private readonly LocalDate $date; - - private readonly LocalTime $time; - - public function __construct(LocalDate $date, LocalTime $time) - { - $this->date = $date; - $this->time = $time; + public function __construct( + private readonly LocalDate $date, + private readonly LocalTime $time + ) { } /** diff --git a/src/LocalTime.php b/src/LocalTime.php index 9ca1e99b..e6aef2d4 100644 --- a/src/LocalTime.php +++ b/src/LocalTime.php @@ -43,26 +43,6 @@ final class LocalTime implements JsonSerializable, Stringable public const NANOS_PER_MILLI = 1_000_000; public const MILLIS_PER_SECOND = 1000; - /** - * The hour, in the range 0 to 23. - */ - private readonly int $hour; - - /** - * The minute, in the range 0 to 59. - */ - private readonly int $minute; - - /** - * The second, in the range 0 to 59. - */ - private readonly int $second; - - /** - * The nanosecond, in the range 0 to 999,999,999. - */ - private readonly int $nano; - /** * Private constructor. Use of() to obtain an instance. * @@ -71,12 +51,12 @@ final class LocalTime implements JsonSerializable, Stringable * @param int $second The second-of-minute, validated in the range 0 to 59. * @param int $nano The nano-of-second, validated in the range 0 to 999,999,999. */ - private function __construct(int $hour, int $minute, int $second, int $nano) - { - $this->hour = $hour; - $this->minute = $minute; - $this->second = $second; - $this->nano = $nano; + private function __construct( + private readonly int $hour, + private readonly int $minute, + private readonly int $second, + private readonly int $nano + ) { } /** diff --git a/src/MonthDay.php b/src/MonthDay.php index 15912f92..fed9cdc8 100644 --- a/src/MonthDay.php +++ b/src/MonthDay.php @@ -16,26 +16,16 @@ */ final class MonthDay implements JsonSerializable, Stringable { - /** - * The month-of-year, from 1 to 12. - */ - private readonly int $month; - - /** - * The day-of-month, from 1 to 31. - */ - private readonly int $day; - /** * Private constructor. Use of() to obtain an instance. * - * @param int $month The month-of-year, validated. - * @param int $day The day-of-month, validated. + * @param int $month The month-of-year, validated in the range of 1 to 12. + * @param int $day The day-of-month, validated in the range of 1 to 31, valid for this month. */ - private function __construct(int $month, int $day) - { - $this->month = $month; - $this->day = $day; + private function __construct( + private readonly int $month, + private readonly int $day + ) { } /** diff --git a/src/Parser/PatternParser.php b/src/Parser/PatternParser.php index 682819f3..e8f2c2a6 100644 --- a/src/Parser/PatternParser.php +++ b/src/Parser/PatternParser.php @@ -12,21 +12,14 @@ */ final class PatternParser implements DateTimeParser { - private readonly string $pattern; - - /** - * @var string[] - */ - private readonly array $fields; - /** * @param string $pattern The regular expression pattern. * @param string[] $fields The fields constants to match. */ - public function __construct(string $pattern, array $fields) - { - $this->pattern = $pattern; - $this->fields = $fields; + public function __construct( + private readonly string $pattern, + private readonly array $fields + ) { } public function getPattern(): string diff --git a/src/Period.php b/src/Period.php index 0f1844c9..6008c40e 100644 --- a/src/Period.php +++ b/src/Period.php @@ -19,12 +19,6 @@ */ final class Period implements JsonSerializable, Stringable { - private readonly int $years; - - private readonly int $months; - - private readonly int $days; - /** * Private constructor. Use of() to obtain an instance. * @@ -32,11 +26,11 @@ final class Period implements JsonSerializable, Stringable * @param int $months The number of months. * @param int $days The number of days. */ - private function __construct(int $years, int $months, int $days) - { - $this->years = $years; - $this->months = $months; - $this->days = $days; + private function __construct( + private readonly int $years, + private readonly int $months, + private readonly int $days + ) { } /** diff --git a/src/TimeZoneOffset.php b/src/TimeZoneOffset.php index ba1e2c53..26a5ff9a 100644 --- a/src/TimeZoneOffset.php +++ b/src/TimeZoneOffset.php @@ -15,8 +15,6 @@ */ final class TimeZoneOffset extends TimeZone { - private readonly int $totalSeconds; - /** * The string representation of this time-zone offset. * @@ -31,9 +29,8 @@ final class TimeZoneOffset extends TimeZone * * @param int $totalSeconds The total offset in seconds, validated from -64800 to +64800. */ - private function __construct(int $totalSeconds) + private function __construct(private readonly int $totalSeconds) { - $this->totalSeconds = $totalSeconds; } /** diff --git a/src/TimeZoneRegion.php b/src/TimeZoneRegion.php index eb40b715..2324ab38 100644 --- a/src/TimeZoneRegion.php +++ b/src/TimeZoneRegion.php @@ -17,14 +17,11 @@ */ final class TimeZoneRegion extends TimeZone { - private readonly DateTimeZone $zone; - /** * Private constructor. Use a factory method to obtain an instance. */ - private function __construct(DateTimeZone $zone) + private function __construct(private readonly DateTimeZone $zone) { - $this->zone = $zone; } /** diff --git a/src/Year.php b/src/Year.php index 105278de..7125ce86 100644 --- a/src/Year.php +++ b/src/Year.php @@ -27,16 +27,10 @@ final class Year implements JsonSerializable, Stringable public const MAX_VALUE = LocalDate::MAX_YEAR; /** - * The year being represented. + * @param int $year The year, validated. */ - private readonly int $year; - - /** - * @param int $year The year to represent, validated. - */ - private function __construct(int $year) + private function __construct(private readonly int $year) { - $this->year = $year; } /** diff --git a/src/YearMonth.php b/src/YearMonth.php index b30ff4a4..66a54f11 100644 --- a/src/YearMonth.php +++ b/src/YearMonth.php @@ -21,24 +21,14 @@ */ final class YearMonth implements JsonSerializable, Stringable { - /** - * The year, from MIN_YEAR to MAX_YEAR. - */ - private readonly int $year; - - /** - * The month, from 1 to 12. - */ - private readonly int $month; - /** * @param int $year The year, validated from MIN_YEAR to MAX_YEAR. * @param int $month The month, validated in the range 1 to 12. */ - private function __construct(int $year, int $month) - { - $this->year = $year; - $this->month = $month; + private function __construct( + private readonly int $year, + private readonly int $month + ) { } /** diff --git a/src/YearMonthRange.php b/src/YearMonthRange.php index 7606c982..24d077c8 100644 --- a/src/YearMonthRange.php +++ b/src/YearMonthRange.php @@ -24,24 +24,14 @@ */ class YearMonthRange implements IteratorAggregate, Countable, JsonSerializable, Stringable { - /** - * The start year-month, inclusive. - */ - private readonly YearMonth $start; - - /** - * The end year-month, inclusive. - */ - private readonly YearMonth $end; - /** * @param YearMonth $start The start year-month, inclusive. * @param YearMonth $end The end year-month, inclusive, validated as not before the start year-month. */ - private function __construct(YearMonth $start, YearMonth $end) - { - $this->start = $start; - $this->end = $end; + private function __construct( + private readonly YearMonth $start, + private readonly YearMonth $end + ) { } /** diff --git a/src/YearWeek.php b/src/YearWeek.php index f430775b..e7f68a5d 100644 --- a/src/YearWeek.php +++ b/src/YearWeek.php @@ -23,24 +23,14 @@ */ final class YearWeek implements JsonSerializable, Stringable { - /** - * The year, from MIN_YEAR to MAX_YEAR. - */ - private readonly int $year; - - /** - * The week number, from 1 to 53. Must be valid for the year. - */ - private readonly int $week; - /** * @param int $year The year, validated from MIN_YEAR to MAX_YEAR. * @param int $week The week number, validated in the range 1 to 53, and valid for the year. */ - private function __construct(int $year, int $week) - { - $this->year = $year; - $this->week = $week; + private function __construct( + private readonly int $year, + private readonly int $week + ) { } /** diff --git a/src/ZonedDateTime.php b/src/ZonedDateTime.php index 86b9d646..41c4fb3a 100644 --- a/src/ZonedDateTime.php +++ b/src/ZonedDateTime.php @@ -24,38 +24,22 @@ */ class ZonedDateTime implements JsonSerializable, Stringable { - /** - * The local date-time. - */ - private readonly LocalDateTime $localDateTime; - - /** - * The time-zone offset from UTC/Greenwich. - */ - private readonly TimeZoneOffset $timeZoneOffset; - - /** - * The time-zone. - * - * It is either a TimeZoneRegion if this ZonedDateTime is region-based, - * or the same instance as the offset if this ZonedDateTime is offset-based. - */ - private readonly TimeZone $timeZone; - - /** - * The instant represented by this ZonedDateTime. - */ - private readonly Instant $instant; - /** * Private constructor. Use a factory method to obtain an instance. - */ - private function __construct(LocalDateTime $localDateTime, TimeZoneOffset $offset, TimeZone $zone, Instant $instant) - { - $this->localDateTime = $localDateTime; - $this->timeZone = $zone; - $this->timeZoneOffset = $offset; - $this->instant = $instant; + * + * @param LocalDateTime $localDateTime The local date-time. + * @param TimeZoneOffset $timeZoneOffset The time-zone offset from UTC/Greenwich. + * @param TimeZone $timeZone The time-zone. It is either a TimeZoneRegion if this ZonedDateTime is + * region-based, or the same instance as the offset if this ZonedDateTime + * is offset-based. + * @param Instant $instant The instant represented by this ZonedDateTime. + */ + private function __construct( + private readonly LocalDateTime $localDateTime, + private readonly TimeZoneOffset $timeZoneOffset, + private readonly TimeZone $timeZone, + private readonly Instant $instant + ) { } /** diff --git a/tools/ecs/ecs.php b/tools/ecs/ecs.php index a994f446..b3843ff5 100644 --- a/tools/ecs/ecs.php +++ b/tools/ecs/ecs.php @@ -80,6 +80,7 @@ use SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff; use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff; use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff; +use Symplify\CodingStandard\Fixer\Spacing\StandaloneLinePromotedPropertyFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; @@ -193,6 +194,7 @@ WhitespaceAfterCommaInArrayFixer::class, NoTrailingCommaInSinglelineArrayFixer::class, TrailingCommaInMultilineFixer::class, + StandaloneLinePromotedPropertyFixer::class, ] );