1: <?php
2: declare(strict_types=1);
3:
4: namespace om\ICal\Parser;
5:
6: use om\ICal\Calendar;
7: use om\ICal\Exception\SyntaxException;
8:
9: final readonly class ParseResult {
10: /**
11: * @param list<Calendar> $calendars
12: * @param list<ParseWarning> $warnings
13: */
14: public function __construct(
15: public array $calendars,
16: public array $warnings = [],
17: ) {
18: }
19:
20: /**
21: * The first calendar.
22: *
23: * @throws SyntaxException when the input contains no VCALENDAR
24: */
25: public function calendar(): Calendar {
26: return $this->calendars[0] ?? throw SyntaxException::create('syntax.no-calendar', 'The input contains no VCALENDAR component.');
27: }
28:
29: /**
30: * @return list<Calendar>
31: */
32: public function calendars(): array {
33: return $this->calendars;
34: }
35:
36: /**
37: * @return list<ParseWarning>
38: */
39: public function warnings(): array {
40: return $this->warnings;
41: }
42:
43: public function hasWarnings(): bool {
44: return $this->warnings !== [];
45: }
46: }
47: