|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the eluceo/iCal package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2019 Markus Poerschke <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Eluceo\iCal\Presentation\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use DateInterval; |
|
15
|
|
|
use Eluceo\iCal\Domain\Entity\Event; |
|
16
|
|
|
use Eluceo\iCal\Domain\ValueObject\MultiDay; |
|
17
|
|
|
use Eluceo\iCal\Domain\ValueObject\Occurrence; |
|
18
|
|
|
use Eluceo\iCal\Domain\ValueObject\SingleDay; |
|
19
|
|
|
use Eluceo\iCal\Domain\ValueObject\TimeSpan; |
|
20
|
|
|
use Eluceo\iCal\Presentation\Component; |
|
21
|
|
|
use Eluceo\iCal\Presentation\Component\Property; |
|
22
|
|
|
use Eluceo\iCal\Presentation\Component\Property\Value\DateTimeValue; |
|
23
|
|
|
use Eluceo\iCal\Presentation\Component\Property\Value\DateValue; |
|
24
|
|
|
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue; |
|
25
|
|
|
use Generator; |
|
26
|
|
|
|
|
27
|
|
|
class EventFactory |
|
28
|
|
|
{ |
|
29
|
|
|
public function createComponent(Event $event): Component |
|
30
|
|
|
{ |
|
31
|
|
|
return Component::create('VEVENT', iterator_to_array($this->getProperties($event))); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
private function getProperties(Event $event): Generator |
|
35
|
|
|
{ |
|
36
|
|
|
yield Property::create('UID', TextValue::fromString((string) $event->getUniqueIdentifier())); |
|
37
|
|
|
yield Property::create('DTSTAMP', DateTimeValue::fromTimestamp($event->getTouchedAt())); |
|
38
|
|
|
|
|
39
|
|
|
if ($event->hasSummary()) { |
|
40
|
|
|
yield Property::create('SUMMARY', TextValue::fromString($event->getSummary())); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if ($event->hasDescription()) { |
|
44
|
|
|
yield Property::create('DESCRIPTION', TextValue::fromString($event->getDescription())); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ($event->hasOccurrence()) { |
|
48
|
|
|
yield from $this->getOccurrenceProperties($event->getOccurrence()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function getOccurrenceProperties(Occurrence $occurrence): Generator |
|
53
|
|
|
{ |
|
54
|
|
|
if ($occurrence instanceof SingleDay) { |
|
|
|
|
|
|
55
|
|
|
yield Property::create('DTSTART', DateValue::fromDate($occurrence->getDate())); |
|
56
|
|
|
} elseif ($occurrence instanceof MultiDay) { |
|
|
|
|
|
|
57
|
|
|
yield Property::create('DTSTART', DateValue::fromDate($occurrence->getFirstDay())); |
|
58
|
|
|
yield Property::create('DTEND', DateValue::fromDate($occurrence->getLastDay()->add(new DateInterval('P1D')))); |
|
59
|
|
|
} elseif ($occurrence instanceof TimeSpan) { |
|
|
|
|
|
|
60
|
|
|
yield Property::create('DTSTART', DateTimeValue::fromDateTime($occurrence->getBegin())); |
|
61
|
|
|
yield Property::create('DTEND', DateTimeValue::fromDateTime($occurrence->getEnd())); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.