Skip to content

Commit

Permalink
PHP 8.1 Language features
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Aug 28, 2023
1 parent 68fa671 commit e139b76
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2022 (c) Jeroen van den Enden
Copyright 2023 (c) Jeroen van den Enden

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Endroid\Calendar\Model;

class Calendar
final class Calendar
{
public function __construct(
private string $title,
private readonly string $title,
/** @var array<CalendarItem> */
private array $calendarItems = []
private readonly array $calendarItems = []
) {
}

Expand Down
34 changes: 15 additions & 19 deletions src/Model/CalendarItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@

namespace Endroid\Calendar\Model;

class CalendarItem
final class CalendarItem
{
/** @var array<string> */
private array $repeatDays = [];

/** @var array<\DateTimeImmutable> */
private array $repeatExceptions = [];

private int $repeatCount = 0;
private \DateInterval|null $repeatInterval = null;
private \DateTimeImmutable|null $repeatEndDate = null;
private \DateTimeImmutable|null $originalDate = null;

private string $rawSourceData = '';

public function __construct(
private string $id,
private string $title,
private string $description,
private \DateTimeImmutable $dateStart,
private \DateTimeImmutable $dateEnd
private readonly string $id,
private readonly string $title,
private readonly string $description,
private readonly \DateTimeImmutable $dateStart,
private readonly \DateTimeImmutable $dateEnd,
/** @var array<string> */
private array $repeatDays = [],
/** @var array<\DateTimeImmutable> */
private array $repeatExceptions = [],
private int $repeatCount = 0,
private \DateInterval|null $repeatInterval = null,
private \DateTimeImmutable|null $repeatEndDate = null,
private \DateTimeImmutable|null $originalDate = null,
private string $rawSourceData = ''
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Endroid\Calendar\Model;

class Event
final class Event
{
public function __construct(
private string $title,
private string $description,
private \DateTimeImmutable $dateStart,
private \DateTimeImmutable $dateEnd
private readonly string $title,
private readonly string $description,
private readonly \DateTimeImmutable $dateStart,
private readonly \DateTimeImmutable $dateEnd
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Reader/IcalReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Endroid\Calendar\Model\Calendar;
use Endroid\Calendar\Model\CalendarItem;

class IcalReader
final class IcalReader
{
/** @var array<string, int> */
private array $weekDays = [
private const WEEK_DAYS = [
'MO' => 1,
'TU' => 2,
'WE' => 3,
Expand Down Expand Up @@ -192,7 +192,7 @@ private function getRepeatDays(array $data): array

$days = explode(',', $data['extra']['BYDAY']);
foreach ($days as &$day) {
$day = $this->weekDays[$day];
$day = self::WEEK_DAYS[$day];
}

return $days;
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/IcalWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Endroid\Calendar\Model\Calendar;

class IcalWriter
final class IcalWriter
{
public function writeToString(Calendar $calendar, \DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd): string
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Reader/IcalReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Endroid\Calendar\Reader\IcalReader;
use PHPUnit\Framework\TestCase;

class IcalReaderTest extends TestCase
final class IcalReaderTest extends TestCase
{
/**
* @testdox Recurring events count is correct
Expand Down

0 comments on commit e139b76

Please sign in to comment.