Skip to content

Commit

Permalink
Fix PHP 8.4 deprecations (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikow13 authored Dec 2, 2024
1 parent 4506f4e commit 206a94d
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/ComponentPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(string $type)
$this->type = $type;
}

public function property(Property $property, array $parameters = null): ComponentPayload
public function property(Property $property, ?array $parameters = null): ComponentPayload
{
$property->addParameters($parameters ?? []);

Expand Down
14 changes: 7 additions & 7 deletions src/Components/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,43 @@ class Alert extends Component

private bool $withoutTimezone = false;

public static function date(DateTimeInterface $date, string $description = null): Alert
public static function date(DateTimeInterface $date, ?string $description = null): Alert
{
return static::create($description)->triggerDate($date);
}

public static function minutesBeforeStart(int $minutes, string $description = null): Alert
public static function minutesBeforeStart(int $minutes, ?string $description = null): Alert
{
$interval = new DateInterval("PT{$minutes}M");
$interval->invert = 1;

return static::create($description)->triggerAtStart($interval);
}

public static function minutesAfterStart(int $minutes, string $description = null): Alert
public static function minutesAfterStart(int $minutes, ?string $description = null): Alert
{
return static::create($description)->triggerAtStart(new DateInterval("PT{$minutes}M"));
}

public static function minutesBeforeEnd(int $minutes, string $description = null): Alert
public static function minutesBeforeEnd(int $minutes, ?string $description = null): Alert
{
$interval = new DateInterval("PT{$minutes}M");
$interval->invert = 1;

return static::create($description)->triggerAtEnd($interval);
}

public static function minutesAfterEnd(int $minutes, string $description = null): Alert
public static function minutesAfterEnd(int $minutes, ?string $description = null): Alert
{
return static::create($description)->triggerAtEnd(new DateInterval("PT{$minutes}M"));
}

private static function create(string $description = null): Alert
private static function create(?string $description = null): Alert
{
return new self($description);
}

public function __construct(string $description = null)
public function __construct(?string $description = null)
{
$this->message = $description;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class Calendar extends Component implements HasTimezones

private ?string $source = null;

public static function create(string $name = null): Calendar
public static function create(?string $name = null): Calendar
{
return new self($name);
}

public function __construct(string $name = null)
public function __construct(?string $name = null)
{
$this->name = $name;
}
Expand Down
28 changes: 16 additions & 12 deletions src/Components/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ class Event extends Component implements HasTimezones
/** @var array[] */
private array $images = [];

public static function create(string $name = null): Event
public static function create(?string $name = null): Event
{
return new self($name);
}

public function __construct(string $name = null)
public function __construct(?string $name = null)
{
$this->name = $name;
$this->uuid = uniqid();
Expand Down Expand Up @@ -128,8 +128,12 @@ public function startsAt(DateTimeInterface $starts, bool $withTime = true): Even
public function endsAt(DateTimeInterface $ends, bool $withTime = true): Event
{
if ($this->isFullDay) {
// The DTEND is the non-inclusive end of the event.
$ends = $ends->modify('+1 day');
if (method_exists($ends, 'modify')) {
$ends = $ends->modify('+1 day');
} else {
throw new \LogicException('The provided DateTimeInterface instance does not support the modify method.');
}

$this->ends = DateTimeValue::create($ends, false);
} else {
$this->ends = DateTimeValue::create($ends, $withTime);
Expand Down Expand Up @@ -164,7 +168,7 @@ public function description(string $description): Event
return $this;
}

public function address(string $address, string $name = null): Event
public function address(string $address, ?string $name = null): Event
{
$this->address = $address;

Expand Down Expand Up @@ -240,21 +244,21 @@ public function alert(Alert $alert): Event
return $this;
}

public function alertAt(DateTimeInterface $alert, string $message = null)
public function alertAt(DateTimeInterface $alert, ?string $message = null)
{
$this->alerts[] = Alert::date($alert, $message);

return $this;
}

public function alertMinutesBefore(int $minutes, string $message = null): Event
public function alertMinutesBefore(int $minutes, ?string $message = null): Event
{
$this->alerts[] = Alert::minutesBeforeStart($minutes, $message);

return $this;
}

public function alertMinutesAfter(int $minutes, string $message = null): Event
public function alertMinutesAfter(int $minutes, ?string $message = null): Event
{
$this->alerts[] = Alert::minutesAfterEnd($minutes, $message);

Expand All @@ -277,16 +281,16 @@ public function transparent(): Event

public function attendee(
string $email,
string $name = null,
ParticipationStatus $participationStatus = null,
?string $name = null,
?ParticipationStatus $participationStatus = null,
bool $requiresResponse = false
): Event {
$this->attendees[] = new CalendarAddress($email, $name, $participationStatus, $requiresResponse);

return $this;
}

public function organizer(string $email, string $name = null): Event
public function organizer(string $email, ?string $name = null): Event
{
$this->organizer = new CalendarAddress($email, $name);

Expand All @@ -307,7 +311,7 @@ public function rrule(RRule $rrule): Event
return $this;
}

public function rruleAsString(string $rrule, ?DateTimeInterface $starting = null, DateTimeInterface $until = null): Event
public function rruleAsString(string $rrule, ?DateTimeInterface $starting = null, ?DateTimeInterface $until = null): Event
{
$this->rrule = $rrule;
$this->rruleStarting = $starting;
Expand Down
4 changes: 2 additions & 2 deletions src/ValueObjects/CalendarAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class CalendarAddress

public function __construct(
string $email,
string $name = null,
ParticipationStatus $participationStatus = null,
?string $name = null,
?ParticipationStatus $participationStatus = null,
bool $requiresResponse = false
) {
$this->email = $email;
Expand Down
42 changes: 21 additions & 21 deletions tests/Builders/ComponentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

assertEquals(
<<<EOT
BEGIN:VTEST\r
location:Antwerp\r
END:VTEST
EOT,
BEGIN:VTEST\r
location:Antwerp\r
END:VTEST
EOT,
$builder->build()
);
});
Expand All @@ -35,11 +35,11 @@

assertEquals(
<<<EOT
BEGIN:VTEST\r
location:Antwerp\r
geo:Antwerp\r
END:VTEST
EOT,
BEGIN:VTEST\r
location:Antwerp\r
geo:Antwerp\r
END:VTEST
EOT,
$builder->build()
);
});
Expand All @@ -53,12 +53,12 @@

assertEquals(
<<<EOT
BEGIN:VTEST\r
BEGIN:VDUMMY\r
name:SUBCOMPONENT\r
END:VDUMMY\r
END:VTEST
EOT,
BEGIN:VTEST\r
BEGIN:VDUMMY\r
name:SUBCOMPONENT\r
END:VDUMMY\r
END:VTEST
EOT,
$builder->build()
);
});
Expand All @@ -72,12 +72,12 @@

assertEquals(
<<<EOT
BEGIN:VTEST\r
location:This is a really long text. Possibly you will never write a text l\r
ike this in a property. But hey we support the RFC so let us chip it! You \r
can maybe write some HTML in here that will make it longer than usual.\r
END:VTEST
EOT,
BEGIN:VTEST\r
location:This is a really long text. Possibly you will never write a text l\r
ike this in a property. But hey we support the RFC so let us chip it! You \r
can maybe write some HTML in here that will make it longer than usual.\r
END:VTEST
EOT,
$builder->build()
);
});
114 changes: 57 additions & 57 deletions tests/Components/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,75 +234,75 @@ function (Event $event) {

assertInstanceOf(Timezone::class, $utcComponent);
assertEquals(<<<EOT
BEGIN:VTIMEZONE\r
TZID:UTC\r
BEGIN:STANDARD\r
DTSTART:20180406T000000\r
TZOFFSETFROM:+0000\r
TZOFFSETTO:+0000\r
END:STANDARD\r
END:VTIMEZONE
EOT, $utcComponent->toString());
BEGIN:VTIMEZONE\r
TZID:UTC\r
BEGIN:STANDARD\r
DTSTART:20180406T000000\r
TZOFFSETFROM:+0000\r
TZOFFSETTO:+0000\r
END:STANDARD\r
END:VTIMEZONE
EOT, $utcComponent->toString());

/** @var \Spatie\IcalendarGenerator\Components\Timezone $alternativeTimezoneComponent */
$alternativeTimezoneComponent = $subComponents[1];

assertInstanceOf(Timezone::class, $alternativeTimezoneComponent);
assertEquals(<<<EOT
BEGIN:VTIMEZONE\r
TZID:Europe/Brussels\r
BEGIN:STANDARD\r
DTSTART:20191027T030000\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20200329T020000\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
DTSTART:20201025T030000\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20210328T020000\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
END:DAYLIGHT\r
END:VTIMEZONE
EOT, $alternativeTimezoneComponent->toString());
BEGIN:VTIMEZONE\r
TZID:Europe/Brussels\r
BEGIN:STANDARD\r
DTSTART:20191027T030000\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20200329T020000\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
DTSTART:20201025T030000\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20210328T020000\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
END:DAYLIGHT\r
END:VTIMEZONE
EOT, $alternativeTimezoneComponent->toString());

/** @var \Spatie\IcalendarGenerator\Components\Timezone $negativeOffsetTimezoneComponent */
$negativeOffsetTimezoneComponent = $subComponents[2];

assertInstanceOf(Timezone::class, $negativeOffsetTimezoneComponent);
assertEquals(<<<EOT
BEGIN:VTIMEZONE\r
TZID:America/New_York\r
BEGIN:STANDARD\r
DTSTART:20191103T020000\r
TZOFFSETFROM:-0400\r
TZOFFSETTO:-0500\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20200308T020000\r
TZOFFSETFROM:-0500\r
TZOFFSETTO:-0400\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
DTSTART:20201101T020000\r
TZOFFSETFROM:-0400\r
TZOFFSETTO:-0500\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20210314T020000\r
TZOFFSETFROM:-0500\r
TZOFFSETTO:-0400\r
END:DAYLIGHT\r
END:VTIMEZONE
EOT, $negativeOffsetTimezoneComponent->toString());
BEGIN:VTIMEZONE\r
TZID:America/New_York\r
BEGIN:STANDARD\r
DTSTART:20191103T020000\r
TZOFFSETFROM:-0400\r
TZOFFSETTO:-0500\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20200308T020000\r
TZOFFSETFROM:-0500\r
TZOFFSETTO:-0400\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
DTSTART:20201101T020000\r
TZOFFSETFROM:-0400\r
TZOFFSETTO:-0500\r
END:STANDARD\r
BEGIN:DAYLIGHT\r
DTSTART:20210314T020000\r
TZOFFSETFROM:-0500\r
TZOFFSETTO:-0400\r
END:DAYLIGHT\r
END:VTIMEZONE
EOT, $negativeOffsetTimezoneComponent->toString());
});

test('it can add timezone components manually', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/PropertyExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PropertyExpectation
*
* @return static
*/
public static function create($instance, string $name = null): self
public static function create($instance, ?string $name = null): self
{
if ($instance instanceof Property) {
return new self($instance);
Expand Down

0 comments on commit 206a94d

Please sign in to comment.