From b63eb44b3976a04be464c767465309741b656604 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 28 Dec 2021 14:43:23 +0100 Subject: [PATCH] Schedule: Simplify & cleanup data classes --- src/Controllers/Admin/ScheduleController.php | 6 ++-- src/Helpers/Schedule/Conference.php | 3 -- src/Helpers/Schedule/Day.php | 36 ++++--------------- src/Helpers/Schedule/Event.php | 18 +++++----- src/Helpers/Schedule/Room.php | 24 ++++--------- src/Helpers/Schedule/Schedule.php | 20 +++++------ src/Helpers/Schedule/XmlParser.php | 6 ++-- tests/Unit/Helpers/Schedule/DayTest.php | 6 ++-- tests/Unit/Helpers/Schedule/RoomTest.php | 13 +++---- tests/Unit/Helpers/Schedule/ScheduleTest.php | 4 +-- tests/Unit/Helpers/Schedule/XmlParserTest.php | 6 ++-- 11 files changed, 53 insertions(+), 89 deletions(-) diff --git a/src/Controllers/Admin/ScheduleController.php b/src/Controllers/Admin/ScheduleController.php index 0d53631e..2a78f4e9 100644 --- a/src/Controllers/Admin/ScheduleController.php +++ b/src/Controllers/Admin/ScheduleController.php @@ -498,13 +498,13 @@ class ScheduleController extends BaseController $locations = $this->getAllLocations(); $eventTimeZone = Carbon::now()->timezone; - foreach ($schedule->getDay() as $day) { - foreach ($day->getRoom() as $room) { + foreach ($schedule->getDays() as $day) { + foreach ($day->getRooms() as $room) { if (!$scheduleModel->activeLocations->where('name', $room->getName())->count()) { continue; } - foreach ($room->getEvent() as $event) { + foreach ($room->getEvents() as $event) { $scheduleEvents[$event->getGuid()] = $event; $event->getDate()->timezone($eventTimeZone)->subMinutes($minutesBefore); diff --git a/src/Helpers/Schedule/Conference.php b/src/Helpers/Schedule/Conference.php index efb9ef61..0c94a8dc 100644 --- a/src/Helpers/Schedule/Conference.php +++ b/src/Helpers/Schedule/Conference.php @@ -8,9 +8,6 @@ class Conference { use CalculatesTime; - /** - * Event constructor. - */ public function __construct( protected string $title, protected string $acronym, diff --git a/src/Helpers/Schedule/Day.php b/src/Helpers/Schedule/Day.php index c63e61cf..dedb45c6 100644 --- a/src/Helpers/Schedule/Day.php +++ b/src/Helpers/Schedule/Day.php @@ -8,38 +8,16 @@ use Carbon\Carbon; class Day { - /** @var string required */ - protected string $date; - - /** @var Carbon required */ - protected Carbon $start; - - /** @var Carbon required */ - protected Carbon $end; - - /** @var int required */ - protected int $index; - - /** @var Room[] */ - protected array $room; - /** - * Day constructor. - * * @param Room[] $rooms */ public function __construct( - string $date, - Carbon $start, - Carbon $end, - int $index, - array $rooms = [] + protected string $date, + protected Carbon $start, + protected Carbon $end, + protected int $index, + protected array $rooms = [] ) { - $this->date = $date; - $this->start = $start; - $this->end = $end; - $this->index = $index; - $this->room = $rooms; } public function getDate(): string @@ -65,8 +43,8 @@ class Day /** * @return Room[] */ - public function getRoom(): array + public function getRooms(): array { - return $this->room; + return $this->rooms; } } diff --git a/src/Helpers/Schedule/Event.php b/src/Helpers/Schedule/Event.php index 2fd566fc..87edb0d5 100644 --- a/src/Helpers/Schedule/Event.php +++ b/src/Helpers/Schedule/Event.php @@ -14,16 +14,16 @@ class Event protected Carbon $endDate; /** - * @param string $guid globally unique - * @param int $id globally unique - * @param string $start time (hh:mm:ss || hh:mm) - * @param string $duration (h?h:mm:ss || h?h:mm) - * @param string $slug globally unique - * @param string[] $persons id => name - * @param string|null $language two letter code + * @param string $guid globally unique + * @param int $id globally unique + * @param string $start time (hh:mm:ss || hh:mm) + * @param string $duration (h?h:mm:ss || h?h:mm) + * @param string $slug globally unique + * @param string[] $persons id => name + * @param string|null $language two-letter code * @param string|null $recording license (and opt out in XML, null if not recorded, empty if no license defined)/ - * @param array $links href => title - * @param array $attachments href => title + * @param array $links href => title + * @param array $attachments href => title */ public function __construct( protected string $guid, diff --git a/src/Helpers/Schedule/Room.php b/src/Helpers/Schedule/Room.php index e856d253..b99521bf 100644 --- a/src/Helpers/Schedule/Room.php +++ b/src/Helpers/Schedule/Room.php @@ -6,23 +6,13 @@ namespace Engelsystem\Helpers\Schedule; class Room { - /** @var string required */ - protected string $name; - - /** @var Event[] */ - protected array $event; - /** - * Room constructor. - * * @param Event[] $events */ public function __construct( - string $name, - array $events = [] + protected string $name, + protected array $events = [] ) { - $this->name = $name; - $this->event = $events; } public function getName(): string @@ -33,16 +23,16 @@ class Room /** * @return Event[] */ - public function getEvent(): array + public function getEvents(): array { - return $this->event; + return $this->events; } /** - * @param Event[] $event + * @param Event[] $events */ - public function setEvent(array $event): void + public function setEvents(array $events): void { - $this->event = $event; + $this->events = $events; } } diff --git a/src/Helpers/Schedule/Schedule.php b/src/Helpers/Schedule/Schedule.php index a477d580..3569330f 100644 --- a/src/Helpers/Schedule/Schedule.php +++ b/src/Helpers/Schedule/Schedule.php @@ -8,18 +8,14 @@ use Carbon\Carbon; class Schedule { - /** @var Day[] */ - protected array $day; - /** - * @param Day[] $days + * @param Day[] $days */ public function __construct( protected string $version, protected Conference $conference, - array $days + protected array $days ) { - $this->day = $days; } public function getVersion(): string @@ -35,9 +31,9 @@ class Schedule /** * @return Day[] */ - public function getDay(): array + public function getDays(): array { - return $this->day; + return $this->days; } /** @@ -46,8 +42,8 @@ class Schedule public function getRooms(): array { $rooms = []; - foreach ($this->day as $day) { - foreach ($day->getRoom() as $room) { + foreach ($this->days as $day) { + foreach ($day->getRooms() as $room) { $name = $room->getName(); $rooms[$name] = $room; } @@ -60,7 +56,7 @@ class Schedule public function getStartDateTime(): ?Carbon { $start = null; - foreach ($this->day as $day) { + foreach ($this->days as $day) { $time = $day->getStart(); if ($time > $start && $start) { continue; @@ -75,7 +71,7 @@ class Schedule public function getEndDateTime(): ?Carbon { $end = null; - foreach ($this->day as $day) { + foreach ($this->days as $day) { $time = $day->getEnd(); if ($time < $end && $end) { continue; diff --git a/src/Helpers/Schedule/XmlParser.php b/src/Helpers/Schedule/XmlParser.php index 27419820..d64d9de4 100644 --- a/src/Helpers/Schedule/XmlParser.php +++ b/src/Helpers/Schedule/XmlParser.php @@ -28,7 +28,9 @@ class XmlParser /** * Parse the predefined XML content * - * According to https://github.com/voc/voctosched/blob/master/schema/basic.xsd + * See also https://c3voc.de/wiki/schedule + * + * According to https://github.com/voc/schedule/blob/master/validator/xsd/schedule.xml.xsd */ protected function parseXml(): void { @@ -53,7 +55,7 @@ class XmlParser ); $events = $this->parseEvents($roomElement->xpath('event'), $room); - $room->setEvent($events); + $room->setEvents($events); $rooms[] = $room; } diff --git a/tests/Unit/Helpers/Schedule/DayTest.php b/tests/Unit/Helpers/Schedule/DayTest.php index 5dbc753e..7bbc04ee 100644 --- a/tests/Unit/Helpers/Schedule/DayTest.php +++ b/tests/Unit/Helpers/Schedule/DayTest.php @@ -17,7 +17,7 @@ class DayTest extends TestCase * @covers \Engelsystem\Helpers\Schedule\Day::getStart * @covers \Engelsystem\Helpers\Schedule\Day::getEnd * @covers \Engelsystem\Helpers\Schedule\Day::getIndex - * @covers \Engelsystem\Helpers\Schedule\Day::getRoom + * @covers \Engelsystem\Helpers\Schedule\Day::getRooms */ public function testCreate(): void { @@ -31,7 +31,7 @@ class DayTest extends TestCase $this->assertEquals('2000-01-01T03:00:00+01:00', $day->getStart()->format(Carbon::RFC3339)); $this->assertEquals('2000-01-02T05:59:00+00:00', $day->getEnd()->format(Carbon::RFC3339)); $this->assertEquals(1, $day->getIndex()); - $this->assertEquals([], $day->getRoom()); + $this->assertEquals([], $day->getRooms()); $rooms = [ new Room('Foo'), @@ -44,6 +44,6 @@ class DayTest extends TestCase 1, $rooms ); - $this->assertEquals($rooms, $day->getRoom()); + $this->assertEquals($rooms, $day->getRooms()); } } diff --git a/tests/Unit/Helpers/Schedule/RoomTest.php b/tests/Unit/Helpers/Schedule/RoomTest.php index 9d0cdad4..b5944f5e 100644 --- a/tests/Unit/Helpers/Schedule/RoomTest.php +++ b/tests/Unit/Helpers/Schedule/RoomTest.php @@ -6,6 +6,7 @@ namespace Engelsystem\Test\Unit\Helpers\Schedule; use Engelsystem\Helpers\Schedule\Event; use Engelsystem\Helpers\Schedule\Room; +use Engelsystem\Helpers\Uuid; use Engelsystem\Test\Unit\TestCase; class RoomTest extends TestCase @@ -13,21 +14,21 @@ class RoomTest extends TestCase /** * @covers \Engelsystem\Helpers\Schedule\Room::__construct * @covers \Engelsystem\Helpers\Schedule\Room::getName - * @covers \Engelsystem\Helpers\Schedule\Room::getEvent - * @covers \Engelsystem\Helpers\Schedule\Room::setEvent + * @covers \Engelsystem\Helpers\Schedule\Room::getEvents + * @covers \Engelsystem\Helpers\Schedule\Room::setEvents */ public function testCreate(): void { $room = new Room('Test'); $this->assertEquals('Test', $room->getName()); - $this->assertEquals([], $room->getEvent()); + $this->assertEquals([], $room->getEvents()); $events = [$this->createMock(Event::class), $this->createMock(Event::class)]; $events2 = [$this->createMock(Event::class)]; $room = new Room('Test2', $events); - $this->assertEquals($events, $room->getEvent()); + $this->assertEquals($events, $room->getEvents()); - $room->setEvent($events2); - $this->assertEquals($events2, $room->getEvent()); + $room->setEvents($events2); + $this->assertEquals($events2, $room->getEvents()); } } diff --git a/tests/Unit/Helpers/Schedule/ScheduleTest.php b/tests/Unit/Helpers/Schedule/ScheduleTest.php index d9df5a46..0ed5ac40 100644 --- a/tests/Unit/Helpers/Schedule/ScheduleTest.php +++ b/tests/Unit/Helpers/Schedule/ScheduleTest.php @@ -20,7 +20,7 @@ class ScheduleTest extends TestCase * @covers \Engelsystem\Helpers\Schedule\Schedule::__construct * @covers \Engelsystem\Helpers\Schedule\Schedule::getVersion * @covers \Engelsystem\Helpers\Schedule\Schedule::getConference - * @covers \Engelsystem\Helpers\Schedule\Schedule::getDay + * @covers \Engelsystem\Helpers\Schedule\Schedule::getDays */ public function testCreate(): void { @@ -30,7 +30,7 @@ class ScheduleTest extends TestCase $this->assertEquals('Foo\'ing stuff 1.0', $schedule->getVersion()); $this->assertEquals($conference, $schedule->getConference()); - $this->assertEquals($days, $schedule->getDay()); + $this->assertEquals($days, $schedule->getDays()); } /** diff --git a/tests/Unit/Helpers/Schedule/XmlParserTest.php b/tests/Unit/Helpers/Schedule/XmlParserTest.php index 6af982bd..7e99866b 100644 --- a/tests/Unit/Helpers/Schedule/XmlParserTest.php +++ b/tests/Unit/Helpers/Schedule/XmlParserTest.php @@ -46,14 +46,14 @@ class XmlParserTest extends TestCase $this->assertEquals('Rooming', $room->getName()); /** @var Day $day */ - $day = Arr::first($schedule->getDay()); + $day = Arr::first($schedule->getDays()); $this->assertEquals('2042-01-01', $day->getDate()); $this->assertEquals(1, $day->getIndex()); /** @var Room $room */ - $room = Arr::first($day->getRoom()); + $room = Arr::first($day->getRooms()); /** @var Event $event */ - $event = Arr::first($room->getEvent()); + $event = Arr::first($room->getEvents()); $this->assertEquals('Foo Bar Test', $event->getTitle()); $this->assertEquals('WTFPL', $event->getRecording());