Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event method #572

Draft
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Build arguments
ARG IMAGE

FROM $IMAGE

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install git -y

RUN apt-get install -y zlib1g-dev zip

RUN pecl install xdebug && docker-php-ext-enable xdebug

RUN rm -rf /etc/localtime
RUN ln -s /usr/share/zoneinfo/Europe/Rome /etc/localtime && echo Europe/Rome > /etc/timezone

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
RUN composer self-update
14 changes: 14 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.9"

services:

ical:
build:
context: ./
dockerfile: Dockerfile
args:
IMAGE: php:8.2-apache
volumes:
- ../:/var/www/html
ports:
- '80:80'
8 changes: 3 additions & 5 deletions examples/example1.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Example;

use DateInterval;
use DateTimeImmutable;
use Eluceo\iCal\Domain\Entity\Calendar;
use Eluceo\iCal\Domain\Entity\Event;
use Eluceo\iCal\Domain\ValueObject\Alarm;
Expand Down Expand Up @@ -43,14 +41,14 @@
)
->setOccurrence(
new TimeSpan(
new DateTime(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2030-12-24 13:30:00'), true),
new DateTime(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2030-12-24 14:30:00'), true)
new DateTime(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2030-12-24 13:30:00'), true),
new DateTime(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2030-12-24 14:30:00'), true)
)
)
->addAlarm(
new Alarm(
new Alarm\DisplayAction('Reminder: the meeting starts in 15 minutes!'),
(new Alarm\RelativeTrigger(DateInterval::createFromDateString('-15 minutes')))->withRelationToEnd()
(new Alarm\RelativeTrigger(\DateInterval::createFromDateString('-15 minutes')))->withRelationToEnd()
)
)
->addAttachment(
Expand Down
3 changes: 1 addition & 2 deletions examples/example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue;
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
use Eluceo\iCal\Presentation\Factory\EventFactory;
use Generator;

require_once __DIR__ . '/../vendor/autoload.php';

Expand All @@ -37,7 +36,7 @@ public function getMyCustomProperty(): string
// that can add the additional property to the presentation component.
class CustomEventFactory extends EventFactory
{
protected function getProperties(Event $event): Generator
protected function getProperties(Event $event): \Generator
{
yield from parent::getProperties($event);
if ($event instanceof CustomEvent) {
Expand Down
6 changes: 2 additions & 4 deletions examples/example3.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Example;

use DateInterval;
use DateTimeImmutable;
use Eluceo\iCal\Domain\Entity\Calendar;
use Eluceo\iCal\Domain\Entity\Event;
use Eluceo\iCal\Domain\ValueObject\Date;
Expand All @@ -29,8 +27,8 @@

// 1. Create event generator
$generator = function (): Generator {
$day = new DateTimeImmutable();
$dayInterval = new DateInterval('P1D');
$day = new \DateTimeImmutable();
$dayInterval = new \DateInterval('P1D');
for ($i = 0; $i < 10; ++$i) {
yield (new Event())
->setSummary('Event ' . $i)
Expand Down
42 changes: 18 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./vendor/autoload.php">
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
</logging>
<testsuites>
<testsuite name="Unit Tests">
<directory suffix="Test.php">./tests/Unit/</directory>
</testsuite>
<testsuite name="Integration Tests">
<directory suffix="Test.php">./tests/Integration/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<text outputFile="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
</report>
</coverage>
<logging/>
<testsuites>
<testsuite name="Unit Tests">
<directory suffix="Test.php">./tests/Unit/</directory>
</testsuite>
<testsuite name="Integration Tests">
<directory suffix="Test.php">./tests/Integration/</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 14 additions & 1 deletion rulesets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess"/>
<exclude name="MissingImport" />
</rule>
<rule ref="rulesets/cleancode.xml/MissingImport">
<properties>
<property name="ignore-global" value="true"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml">
<exclude name="ExcessivePublicCount"/>
</rule>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount">
<properties>
<property name="minimum" description="The public item reporting threshold" value="50"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
Expand Down
8 changes: 3 additions & 5 deletions src/Domain/Collection/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
namespace Eluceo\iCal\Domain\Collection;

use Eluceo\iCal\Domain\Entity\Event;
use Iterator;
use IteratorAggregate;
use ReturnTypeWillChange;

/**
* @implements IteratorAggregate<Event>
*/
abstract class Events implements IteratorAggregate
abstract class Events implements \IteratorAggregate
{
/**
* @return Iterator<Event>
* @return \Iterator<Event>
*/
#[ReturnTypeWillChange]
#[\ReturnTypeWillChange]
abstract public function getIterator();

abstract public function addEvent(Event $event): void;
Expand Down
6 changes: 2 additions & 4 deletions src/Domain/Collection/EventsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

namespace Eluceo\iCal\Domain\Collection;

use ArrayIterator;
use Eluceo\iCal\Domain\Entity\Event;
use ReturnTypeWillChange;

final class EventsArray extends Events
{
Expand All @@ -30,10 +28,10 @@ public function __construct(array $events)
array_walk($events, [$this, 'addEvent']);
}

#[ReturnTypeWillChange]
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->events);
return new \ArrayIterator($this->events);
}

public function addEvent(Event $event): void
Expand Down
15 changes: 6 additions & 9 deletions src/Domain/Collection/EventsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,31 @@

namespace Eluceo\iCal\Domain\Collection;

use BadMethodCallException;
use Eluceo\iCal\Domain\Entity\Event;
use Iterator;
use ReturnTypeWillChange;

final class EventsGenerator extends Events
{
/**
* @var Iterator<Event>
* @var \Iterator<Event>
*/
private Iterator $generator;
private \Iterator $generator;

/**
* @param Iterator<Event> $generator
* @param \Iterator<Event> $generator
*/
public function __construct(Iterator $generator)
public function __construct(\Iterator $generator)
{
$this->generator = $generator;
}

#[ReturnTypeWillChange]
#[\ReturnTypeWillChange]
public function getIterator()
{
return $this->generator;
}

public function addEvent(Event $event): void
{
throw new BadMethodCallException('Events cannot be added to an EventsGenerator.');
throw new \BadMethodCallException('Events cannot be added to an EventsGenerator.');
}
}
17 changes: 7 additions & 10 deletions src/Domain/Entity/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@

namespace Eluceo\iCal\Domain\Entity;

use DateInterval;
use Eluceo\iCal\Domain\Collection\Events;
use Eluceo\iCal\Domain\Collection\EventsArray;
use Eluceo\iCal\Domain\Collection\EventsGenerator;
use InvalidArgumentException;
use Iterator;

class Calendar
{
private string $productIdentifier = '-//eluceo/ical//2.0/EN';

private ?DateInterval $publishedTTL = null;
private ?\DateInterval $publishedTTL = null;

private Events $events;

Expand All @@ -32,15 +29,15 @@ class Calendar
private array $timeZones = [];

/**
* @param array<array-key, Event>|Iterator<Event>|Events $events
* @param array<array-key, Event>|\Iterator<Event>|Events $events
*/
public function __construct($events = [])
{
$this->events = $this->ensureEventsObject($events);
}

/**
* @param array<array-key, Event>|Iterator<Event>|Events $events
* @param array<array-key, Event>|\Iterator<Event>|Events $events
*/
private function ensureEventsObject($events = []): Events
{
Expand All @@ -52,19 +49,19 @@ private function ensureEventsObject($events = []): Events
return new EventsArray($events);
}

if ($events instanceof Iterator) {
if ($events instanceof \Iterator) {
return new EventsGenerator($events);
}

throw new InvalidArgumentException('$events must be an array, an object implementing Iterator or an instance of Events.');
throw new \InvalidArgumentException('$events must be an array, an object implementing Iterator or an instance of Events.');
}

public function getPublishedTTL(): ?DateInterval
public function getPublishedTTL(): ?\DateInterval
{
return $this->publishedTTL;
}

public function setPublishedTTL(?DateInterval $ttl): self
public function setPublishedTTL(?\DateInterval $ttl): self
{
$this->publishedTTL = $ttl;

Expand Down
23 changes: 21 additions & 2 deletions src/Domain/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Eluceo\iCal\Domain\Entity;

use Eluceo\iCal\Domain\Enum\EventStatus;
use Eluceo\iCal\Domain\Enum\MethodType;
use Eluceo\iCal\Domain\ValueObject\Alarm;
use Eluceo\iCal\Domain\ValueObject\Attachment;
use Eluceo\iCal\Domain\ValueObject\Category;
Expand All @@ -34,6 +35,7 @@ class Event
private ?Organizer $organizer = null;
private ?Timestamp $lastModified = null;
private ?EventStatus $status = null;
private ?MethodType $method = null;

/**
* @var array<Attendee>
Expand All @@ -55,7 +57,7 @@ class Event
*/
private array $categories = [];

public function __construct(?UniqueIdentifier $uniqueIdentifier = null)
public function __construct(UniqueIdentifier $uniqueIdentifier = null)
{
$this->uniqueIdentifier = $uniqueIdentifier ?? UniqueIdentifier::createRandom();
$this->touchedAt = new Timestamp();
Expand All @@ -71,13 +73,30 @@ public function getTouchedAt(): Timestamp
return $this->touchedAt;
}

public function touch(?Timestamp $dateTime = null): self
public function touch(Timestamp $dateTime = null): self
{
$this->touchedAt = $dateTime ?? new Timestamp();

return $this;
}

public function getMethod(): ?MethodType
{
return $this->method;
}

public function hasMethod(): bool
{
return $this->method !== null;
}

public function setMethod(?MethodType $method): Event
{
$this->method = $method;

return $this;
}

public function getSummary(): string
{
assert($this->summary !== null);
Expand Down
Loading
Loading