Skip to content

Commit

Permalink
Rector: PHP 8.0: apply ClassPropertyAssignToConstructorPromotionRector
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Mar 24, 2024
1 parent 0893888 commit 1c22628
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 276 deletions.
5 changes: 1 addition & 4 deletions src/Clock/FixedClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions src/Clock/OffsetClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 5 additions & 15 deletions src/Clock/ScaleClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
23 changes: 6 additions & 17 deletions src/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
22 changes: 6 additions & 16 deletions src/Instant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
22 changes: 6 additions & 16 deletions src/Interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
25 changes: 5 additions & 20 deletions src/LocalDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,18 @@ 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.
*
* @param int $year The year, validated from MIN_YEAR to MAX_YEAR.
* @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
) {
}

/**
Expand Down
18 changes: 4 additions & 14 deletions src/LocalDateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/LocalDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
32 changes: 6 additions & 26 deletions src/LocalTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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
) {
}

/**
Expand Down
22 changes: 6 additions & 16 deletions src/MonthDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
15 changes: 4 additions & 11 deletions src/Parser/PatternParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1c22628

Please sign in to comment.