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

Phil davis issue 588 #628

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
605cee3
Bump dependencies in composer.json
phil-davis Sep 11, 2022
f0aeaba
Increase phpstan to level 6
phil-davis Sep 11, 2022
3fe0960
Adjust mostly test code for phpstan level 6
phil-davis Sep 11, 2022
14c482b
Declare more types in tests
phil-davis Sep 13, 2022
96d2b0d
Remove useless check of propertyCounters < 1
phil-davis Sep 14, 2022
4fda87f
Adjust some type declarations in lib/Component.php
phil-davis Sep 14, 2022
e4777ff
Remove phpstan-ignore-line from lines that no longer give a phpstan e…
phil-davis Sep 14, 2022
1baf535
Fixup phpstan errors in lib/Component/VEvent.php
phil-davis Sep 14, 2022
4aa9c7f
add ATTENDEE to possible magic properties of VEvent
phil-davis Sep 14, 2022
d0398cb
Adjust tests to remove phpstan errors
phil-davis Sep 14, 2022
a7745a6
Move public string 'name' into Node
phil-davis Sep 14, 2022
0b50fa3
Add dollar in front of @property variables
phil-davis Jan 23, 2023
8d14f74
Fixup phpstan things reported in MainTest
phil-davis Jan 23, 2023
2bd8ee5
Fix cs-style
phil-davis Jan 23, 2023
d09fcf3
Fix things reported by phpstan in tests
phil-davis Jan 23, 2023
e8d39e6
Adjust types in lib/Writer.php
phil-davis Jan 23, 2023
719bac9
Adjust types in lib/VCardConverter.php
phil-davis Jan 23, 2023
bf44efb
Call static assert functions with self::
phil-davis Feb 8, 2023
ef31eff
fix: left over phpstan errors after rebase
DeepDiver1975 Nov 8, 2023
bccb315
fix: declare iterator type on class Node + array types in ICalendar
DeepDiver1975 Nov 8, 2023
4c449ce
fix: cs-fixer
DeepDiver1975 Nov 8, 2023
8d45cf0
ci: add php 8.3
DeepDiver1975 Nov 8, 2023
6805cf2
fix: type declarations when using VCalendar->VEVENT
DeepDiver1975 Nov 8, 2023
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2']
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
coverage: ['pcov']
code-analysis: ['no']
include:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"require-dev" : {
"friendsofphp/php-cs-fixer": "^3.14",
"phpunit/phpunit" : "^9.6",
"phpunit/php-invoker" : "^2.0 || ^3.1",
"phpunit/php-invoker" : "^3.1",
"phpstan/phpstan": "^1.9"
},
"suggest" : {
Expand Down Expand Up @@ -91,7 +91,7 @@
},
"scripts": {
"phpstan": [
"phpstan analyse lib tests --memory-limit 1G"
"phpstan analyse lib tests --memory-limit 2G"
],
"cs-fixer": [
"php-cs-fixer fix"
Expand Down
49 changes: 32 additions & 17 deletions lib/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Sabre\VObject;

use Sabre\VObject;
use Sabre\VObject\Property\FlatText;
use Sabre\Xml;

/**
Expand All @@ -15,21 +15,16 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\FlatText UID
* @property FlatText $UID
*/
class Component extends Node
{
/**
* Component name.
*
* This will contain a string such as VEVENT, VTODO, VCALENDAR, VCARD.
*/
public string $name;

/**
* A list of properties and/or sub-components.
*
* @var array<string, Component|Property>
* ToDo: maybe be more specific array<string, Component<int, mixed>|Property<int, mixed>>
*
* @var array<string, array<int, mixed>>
*/
protected array $children = [];

Expand All @@ -44,7 +39,9 @@ class Component extends Node
* an iCalendar object, this may be something like CALSCALE:GREGORIAN. To
* ensure that this does not happen, set $defaults to false.
*
* @param string|null $name such as VCALENDAR, VEVENT
* @param Document<int, mixed> $root
* @param string|null $name such as VCALENDAR, VEVENT
* @param array<int|string, mixed> $children
*/
public function __construct(Document $root, ?string $name, array $children = [], bool $defaults = true)
{
Expand All @@ -54,7 +51,7 @@ public function __construct(Document $root, ?string $name, array $children = [],
if ($defaults) {
// This is a terribly convoluted way to do this, but this ensures
// that the order of properties as they are specified in both
// defaults and the childrens list, are inserted in the object in a
// defaults and the children's list, are inserted in the object in a
// natural way.
$list = $this->getDefaults();
$nodes = [];
Expand Down Expand Up @@ -97,6 +94,8 @@ public function __construct(Document $root, ?string $name, array $children = [],
* add($name, $value, array $parameters = []) // Adds a new property
* add($name, array $children = []) // Adds a new component
* by name.
*
* @return Node<int, mixed>
*/
public function add(): Node
{
Expand All @@ -114,7 +113,7 @@ public function add(): Node
throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Node or a string');
}

/** @var Component|Property|Parameter $newNode */
/** @var Component<int, mixed>|Property<int, mixed>|Parameter $newNode */
$name = $newNode->name;
if (isset($this->children[$name])) {
$this->children[$name][] = $newNode;
Expand All @@ -133,7 +132,7 @@ public function add(): Node
* pass an instance of a property or component, in which case only that
* exact item will be removed.
*
* @param string|Property|Component $item
* @param string|Property<int, mixed>|Component<int, mixed> $item
*/
public function remove($item): void
{
Expand Down Expand Up @@ -167,6 +166,8 @@ public function remove($item): void
/**
* Returns a flat list of all the properties and components in this
* component.
*
* @return array<int, Component<int, mixed>|Property<int, mixed>>
*/
public function children(): array
{
Expand All @@ -181,6 +182,8 @@ public function children(): array
/**
* This method only returns a list of sub-components. Properties are
* ignored.
*
* @return array<int, Component<int, mixed>>
*/
public function getComponents(): array
{
Expand All @@ -206,6 +209,10 @@ public function getComponents(): array
* search for a property in a specific group, you can select on the entire
* string ("HOME.EMAIL"). If you want to search on a specific property that
* has not been assigned a group, specify ".EMAIL".
*
* ToDo: something like (array<int, mixed> & Component)|(array<int, mixed> & Property)
*
* @return array<int, mixed>
*/
public function select(string $name): array
{
Expand Down Expand Up @@ -271,7 +278,7 @@ public function serialize(): string
*
* @return int
*/
$sortScore = function (int $key, array $array): ?int {
$sortScore = function (int $key, array $array): int {
if ($array[$key] instanceof Component) {
// We want to encode VTIMEZONE first, this is a personal
// preference.
Expand Down Expand Up @@ -322,6 +329,8 @@ function ($a, $b) use ($sortScore, $tmp): int {
/**
* This method returns an array, with the representation as it should be
* encoded in JSON. This is used to create jCard or jCal documents.
*
* @return array{0: string, 1: array<int, mixed>, 2: array<int, mixed>}
*/
#[\ReturnTypeWillChange]
public function jsonSerialize(): array
Expand Down Expand Up @@ -394,6 +403,8 @@ public function xmlSerialize(Xml\Writer $writer): void

/**
* This method should return a list of default property values.
*
* @return array<string, string>
*/
protected function getDefaults(): array
{
Expand All @@ -412,7 +423,7 @@ protected function getDefaults(): array
*
* $event = $calendar->VEVENT;
*
* @return Property|Component
* @return Property<int, mixed>|Component<int, mixed>
*/
public function __get(string $name): ?Node
{
Expand Down Expand Up @@ -507,6 +518,8 @@ public function __clone()
*
* See the VEVENT implementation for getValidationRules for a more complex
* example.
*
* @return array<string, string|int>
*/
public function getValidationRules(): array
{
Expand All @@ -532,6 +545,8 @@ public function getValidationRules(): array
* 1 - The issue was repaired (only happens if REPAIR was turned on).
* 2 - A warning.
* 3 - An error.
*
* @return array<int, array{level: int, message: string, node: object}>
*/
public function validate(int $options = 0): array
{
Expand Down Expand Up @@ -578,7 +593,7 @@ public function validate(int $options = 0): array
}
break;
case '+':
if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] < 1) {
if (!isset($propertyCounters[$propName])) {
$messages[] = [
'level' => 3,
'message' => $propName.' MUST appear at least once in a '.$this->name.' component',
Expand Down
6 changes: 3 additions & 3 deletions lib/Component/Available.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* @author Ivan Enderlin
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\ICalendar\DateTime DTSTART
* @property VObject\Property\ICalendar\DateTime DTEND
* @property VObject\Property\ICalendar\Duration DURATION
* @property VObject\Property\ICalendar\DateTime $DTSTART
* @property VObject\Property\ICalendar\DateTime $DTEND
* @property VObject\Property\ICalendar\Duration $DURATION
*/
class Available extends VObject\Component
{
Expand Down
10 changes: 5 additions & 5 deletions lib/Component/VAlarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\ICalendar\DateTime DTSTART
* @property VObject\Property\ICalendar\DateTime DTEND
* @property VObject\Property\ICalendar\Duration DURATION
* @property VObject\Property\ICalendar\Duration|VObject\Property\ICalendar\DateTime TRIGGER
* @property VObject\Property\IntegerValue REPEAT
* @property VObject\Property\ICalendar\DateTime $DTSTART
* @property VObject\Property\ICalendar\DateTime $DTEND
* @property VObject\Property\ICalendar\Duration $DURATION
* @property VObject\Property\ICalendar\Duration|VObject\Property\ICalendar\DateTime $TRIGGER
* @property VObject\Property\IntegerValue $REPEAT
*/
class VAlarm extends VObject\Component
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Component/VAvailability.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* @author Ivan Enderlin
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\ICalendar\DateTime DTSTART
* @property VObject\Property\ICalendar\DateTime DTEND
* @property VObject\Property\ICalendar\Duration DURATION
* @property VObject\Property\ICalendar\DateTime $DTSTART
* @property VObject\Property\ICalendar\DateTime $DTEND
* @property VObject\Property\ICalendar\Duration $DURATION
*/
class VAvailability extends VObject\Component
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Component/VCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VEvent VEVENT
* @property VJournal VJOURNAL
* @property VObject\Property\Text ORG
* @property VObject\Property\FlatText METHOD
* @property VEvent $VEVENT
* @property VJournal $VJOURNAL
* @property VObject\Property\Text $ORG
* @property VObject\Property\FlatText $METHOD
*/
class VCalendar extends VObject\Document
{
Expand Down
12 changes: 6 additions & 6 deletions lib/Component/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\FlatText FN
* @property VObject\Property\Text ORG
* @property VObject\Property\FlatText EMAIL
* @property VObject\Property\FlatText $FN
* @property VObject\Property\Text $ORG
* @property VObject\Property\FlatText $EMAIL
*/
class VCard extends VObject\Document
{
Expand Down Expand Up @@ -272,17 +272,17 @@ public function validate(int $options = 0): array
}
$repaired = true;

// Otherwise, the ORG property may work
// Otherwise, the ORG property may work
} elseif (isset($this->ORG)) {
$this->FN = (string) $this->ORG;
$repaired = true;

// Otherwise, the NICKNAME property may work
// Otherwise, the NICKNAME property may work
} elseif (isset($this->NICKNAME)) {
$this->FN = (string) $this->NICKNAME;
$repaired = true;

// Otherwise, the EMAIL property may work
// Otherwise, the EMAIL property may work
} elseif (isset($this->EMAIL)) {
$this->FN = (string) $this->EMAIL;
$repaired = true;
Expand Down
41 changes: 27 additions & 14 deletions lib/Component/VEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\ICalendar\DateTime DTSTART
* @property VObject\Property\ICalendar\DateTime DTEND
* @property VObject\Property\ICalendar\DateTime DTSTAMP
* @property VObject\Property\ICalendar\Duration DURATION
* @property VObject\Property\ICalendar\Recur RRULE
* @property VObject\Property\ICalendar\DateTime[] EXDATE
* @property VObject\Property\ICalendar\DateTime RDATE
* @property VObject\Property\ICalendar\Recur EXRULE
* @property VObject\Property\ICalendar\DateTime RECURRENCE-ID
* @property VObject\Property\FlatText TRANSP
* @property VObject\Property\FlatText STATUS
* @property VObject\Property\ICalendar\DateTime $DTSTART
* @property VObject\Property\ICalendar\DateTime $DTEND
* @property VObject\Property\ICalendar\DateTime $DTSTAMP
* @property VObject\Property\ICalendar\Duration $DURATION
* @property VObject\Property\ICalendar\Recur $RRULE
* @property VObject\Property\ICalendar\DateTime[] $EXDATE
* @property VObject\Property\ICalendar\DateTime $RDATE
* @property VObject\Property\ICalendar\Recur $EXRULE
* @property VObject\Property\ICalendar\DateTime $RECURRENCE-ID
* @property VObject\Property\ICalendar\CalAddress $ATTENDEE
* @property VObject\Property\FlatText $TRANSP
* @property VObject\Property\FlatText $STATUS
*/
class VEvent extends VObject\Component
{
Expand Down Expand Up @@ -61,18 +62,26 @@ public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end
return $it->getDTStart() < $end && $it->getDTEnd() > $start;
}

$effectiveStart = $this->DTSTART->getDateTime($start->getTimezone());
/**
* @var \Sabre\VObject\Property\ICalendar\DateTime<int, DateTimeInterface> $dateTimeStart
*/
$dateTimeStart = $this->DTSTART;
$effectiveStart = $dateTimeStart->getDateTime($start->getTimezone());
if (isset($this->DTEND)) {
/**
* @var \Sabre\VObject\Property\ICalendar\DateTime<int, DateTimeInterface> $dateTimeEnd
*/
$dateTimeEnd = $this->DTEND;
// The DTEND property is considered non-inclusive. So for a 3-day
// event in july, dtstart and dtend would have to be July 1st and
// July 4th respectively.
//
// See:
// http://tools.ietf.org/html/rfc5545#page-54
$effectiveEnd = $this->DTEND->getDateTime($end->getTimezone());
$effectiveEnd = $dateTimeEnd->getDateTime($end->getTimezone());
} elseif (isset($this->DURATION)) {
$effectiveEnd = $effectiveStart->add(VObject\DateTimeParser::parseDuration($this->DURATION));
} elseif (!$this->DTSTART->hasTime()) {
} elseif (!$dateTimeStart->hasTime()) {
$effectiveEnd = $effectiveStart->modify('+1 day');
} else {
$effectiveEnd = $effectiveStart;
Expand All @@ -85,6 +94,8 @@ public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end

/**
* This method should return a list of default property values.
*
* @return array<string, string>
*/
protected function getDefaults(): array
{
Expand All @@ -106,6 +117,8 @@ protected function getDefaults(): array
* * + - Must appear at least once.
* * * - Can appear any number of times.
* * ? - May appear, but not more than once.
*
* @return array<string, string|int>
*/
public function getValidationRules(): array
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Component/VFreeBusy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\ICalendar\Period FREEBUSY
* @property VObject\Property\ICalendar\Period $FREEBUSY
*/
class VFreeBusy extends VObject\Component
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Component/VJournal.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\ICalendar\DateTime DTSTART
* @property VObject\Property\ICalendar\DateTime $DTSTART
*/
class VJournal extends VObject\Component
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Component/VTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*
* @property VObject\Property\FlatText TZID
* @property VObject\Property\FlatText $TZID
*/
class VTimeZone extends VObject\Component
{
Expand Down
Loading
Loading