Skip to content

Commit 7bb391c

Browse files
committed
chore: code changes to make code analysis pass
1 parent dee2dfb commit 7bb391c

44 files changed

Lines changed: 221 additions & 205 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/BirthdayCalendarGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getResult(): VCalendar
9595
// We've seen clients (ez-vcard) putting "BDAY:" properties
9696
// without a value into vCards. If we come across those, we'll
9797
// skip them.
98-
if (empty($object->BDAY->getValue())) {
98+
if ('' === $object->BDAY->getValue()) {
9999
continue;
100100
}
101101

lib/Cli.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function main(array $argv): int
147147
throw new \InvalidArgumentException('Too many arguments');
148148
}
149149

150-
if (!in_array($positional[0], ['validate', 'repair', 'convert', 'color'])) {
150+
if (!in_array($positional[0], ['validate', 'repair', 'convert', 'color'], true)) {
151151
throw new \InvalidArgumentException('Unknown command: '.$positional[0]);
152152
}
153153
} catch (\InvalidArgumentException $e) {
@@ -185,6 +185,7 @@ public function main(array $argv): int
185185

186186
try {
187187
while ($input = $this->readInput()) {
188+
// @phpstan-ignore method.dynamicName
188189
$returnCode = $this->$command($input);
189190
if (0 !== $returnCode) {
190191
$realCode = $returnCode;

lib/Component.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public function xmlSerialize(Xml\Writer $writer): void
366366

367367
$writer->startElement(strtolower($this->name));
368368

369-
if (!empty($properties)) {
369+
if ([] !== $properties) {
370370
$writer->startElement('properties');
371371

372372
foreach ($properties as $property) {
@@ -376,7 +376,7 @@ public function xmlSerialize(Xml\Writer $writer): void
376376
$writer->endElement();
377377
}
378378

379-
if (!empty($components)) {
379+
if ([] !== $components) {
380380
$writer->startElement('components');
381381

382382
foreach ($components as $component) {

lib/Component/VAlarm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getEffectiveTriggerTime(): \DateTimeImmutable
3434
$trigger = $this->TRIGGER;
3535
if (!isset($trigger['VALUE']) || ($trigger['VALUE'] && 'DURATION' === strtoupper((string) $trigger['VALUE']))) {
3636
$triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
37-
$related = (isset($trigger['RELATED']) && 'END' == strtoupper($trigger['RELATED'])) ? 'END' : 'START';
37+
$related = (isset($trigger['RELATED']) && 'END' === strtoupper($trigger['RELATED'])) ? 'END' : 'START';
3838

3939
/** @var VEvent|VTodo $parentComponent */
4040
$parentComponent = $this->parent;

lib/Component/VCalendar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public function validate(int $options = 0): array
424424
if ($child instanceof Component) {
425425
++$componentsFound;
426426

427-
if (!in_array($child->name, ['VEVENT', 'VTODO', 'VJOURNAL'])) {
427+
if (!in_array($child->name, ['VEVENT', 'VTODO', 'VJOURNAL'], true)) {
428428
continue;
429429
}
430430
$componentTypes[] = $child->name;

lib/Component/VCard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public function xmlSerialize(Xml\Writer $writer): void
491491
$writer->startElement(strtolower($this->name));
492492

493493
foreach ($propertiesByGroup as $group => $properties) {
494-
if (!empty($group)) {
494+
if ('' !== $group) {
495495
$writer->startElement('group');
496496
$writer->writeAttribute('name', strtolower((string) $group));
497497
}
@@ -513,7 +513,7 @@ public function xmlSerialize(Xml\Writer $writer): void
513513
}
514514
}
515515

516-
if (!empty($group)) {
516+
if ('' !== $group) {
517517
$writer->endElement();
518518
}
519519
}
@@ -529,7 +529,7 @@ public function getClassNameForPropertyName(string $propertyName): string
529529
$className = parent::getClassNameForPropertyName($propertyName);
530530

531531
// In vCard 4, BINARY no longer exists, and we need URI instead.
532-
if (VObject\Property\Binary::class == $className && self::VCARD40 === $this->getDocumentType()) {
532+
if (VObject\Property\Binary::class === $className && self::VCARD40 === $this->getDocumentType()) {
533533
return VObject\Property\Uri::class;
534534
}
535535

lib/DateTimeParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public static function parseVCardDateTime(string $date): array
329329

330330
$result = [];
331331
foreach ($parts as $part) {
332-
if (empty($matches[$part])) {
332+
if (!array_key_exists($part, $matches)) {
333333
$result[$part] = null;
334334
} elseif ('-' === $matches[$part] || '--' === $matches[$part]) {
335335
$result[$part] = null;
@@ -424,7 +424,7 @@ public static function parseVCardTime(string $date): array
424424

425425
$result = [];
426426
foreach ($parts as $part) {
427-
if (empty($matches[$part])) {
427+
if (!array_key_exists($part, $matches)) {
428428
$result[$part] = null;
429429
} elseif ('-' === $matches[$part]) {
430430
$result[$part] = null;
@@ -541,7 +541,7 @@ public static function parseVCardDateAndOrTime(string $date): array
541541
$parts['year0'] = &$parts['year'];
542542

543543
foreach ($parts as $part => &$value) {
544-
if (!empty($matches[$part])) {
544+
if (array_key_exists($part, $matches)) {
545545
$value = $matches[$part];
546546
}
547547
}

lib/ITip/Broker.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null): array
228228

229229
$eventInfo = $oldEventInfo;
230230

231-
if (in_array($eventInfo['organizer'], $userHref)) {
231+
if (in_array($eventInfo['organizer'], $userHref, true)) {
232232
// This is an organizer deleting the event.
233233
$eventInfo['attendees'] = [];
234234
// Increasing the sequence, but only if the organizer deleted
@@ -237,7 +237,7 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null): array
237237
} else {
238238
// This is an attendee deleting the event.
239239
foreach ($eventInfo['attendees'] as $key => $attendee) {
240-
if (in_array($attendee['href'], $userHref)) {
240+
if (in_array($attendee['href'], $userHref, true)) {
241241
$eventInfo['attendees'][$key]['instances'] = ['master' => ['id' => 'master', 'partstat' => 'DECLINED'],
242242
];
243243
}
@@ -247,13 +247,13 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null): array
247247
}
248248

249249
// Check if the user is the organizer
250-
if (in_array($eventInfo['organizer'], $userHref)) {
250+
if (in_array($eventInfo['organizer'], $userHref, true)) {
251251
return $this->parseEventForOrganizer($baseCalendar, $eventInfo, $oldEventInfo);
252252
}
253253

254254
// Check if the user is an attendee
255255
foreach ($eventInfo['attendees'] as $attendee) {
256-
if (in_array($attendee['href'], $userHref)) {
256+
if (in_array($attendee['href'], $userHref, true)) {
257257
// If this is a event update, we always generate a reply
258258
if ($oldCalendar) {
259259
return $this->parseEventForAttendee($baseCalendar, $eventInfo, $oldEventInfo, $attendee['href']);
@@ -566,7 +566,7 @@ protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo,
566566

567567
$message->significantChange =
568568
'REQUEST' === $attendee['forceSend']
569-
|| count($oldAttendeeInstances) != count($newAttendeeInstances)
569+
|| count($oldAttendeeInstances) !== count($newAttendeeInstances)
570570
|| count(array_diff($oldAttendeeInstances, $newAttendeeInstances)) > 0
571571
|| $oldEventInfo['significantChangeHash'] !== $eventInfo['significantChangeHash'];
572572

@@ -576,9 +576,9 @@ protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo,
576576
// We need to find a list of events that the attendee
577577
// is not a part of to add to the list of exceptions.
578578
$exceptions = [];
579-
foreach ($eventInfo['instances'] as $instanceId => $vevent) {
580-
if (!isset($attendee['newInstances'][$instanceId])) {
581-
$exceptions[] = $instanceId;
579+
foreach ($eventInfo['instances'] as $eventInstanceId => $vevent) {
580+
if (!isset($attendee['newInstances'][$eventInstanceId])) {
581+
$exceptions[] = $eventInstanceId;
582582
}
583583
}
584584

@@ -648,7 +648,7 @@ protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo,
648648
return [];
649649
}
650650

651-
$oldInstances = !empty($oldEventInfo['attendees'][$attendee]['instances']) ?
651+
$oldInstances = array_key_exists('instances', $oldEventInfo['attendees'][$attendee]) ?
652652
$oldEventInfo['attendees'][$attendee]['instances'] :
653653
[];
654654

@@ -679,7 +679,7 @@ protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo,
679679
// We only need to do that though, if the master event is not declined.
680680
if (isset($instances['master']) && 'DECLINED' !== $instances['master']['newstatus']) {
681681
foreach ($eventInfo['exdate'] as $exDate) {
682-
if (!in_array($exDate, $oldEventInfo['exdate'] ?? [])) {
682+
if (!in_array($exDate, $oldEventInfo['exdate'] ?? [], true)) {
683683
if (isset($instances[$exDate])) {
684684
$instances[$exDate]['newstatus'] = 'DECLINED';
685685
} else {
@@ -722,7 +722,7 @@ protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo,
722722
$hasReply = false;
723723

724724
foreach ($instances as $instance) {
725-
if ($instance['oldstatus'] == $instance['newstatus'] && 'REPLY' !== $eventInfo['organizerForceSend']) {
725+
if ($instance['oldstatus'] === $instance['newstatus'] && 'REPLY' !== $eventInfo['organizerForceSend']) {
726726
// Skip
727727
continue;
728728
}
@@ -884,7 +884,7 @@ protected function parseEventInfo(VCalendar $calendar): array
884884
foreach ($vevent->select('RRULE') as $rr) {
885885
foreach ($rr->getParts() as $key => $val) {
886886
// ignore default values (https://github.com/sabre-io/vobject/issues/126)
887-
if ('INTERVAL' === $key && 1 == $val) {
887+
if ('INTERVAL' === $key && 1 === $val) {
888888
continue;
889889
}
890890
if (is_array($val)) {
@@ -951,6 +951,7 @@ protected function parseEventInfo(VCalendar $calendar): array
951951
}
952952

953953
foreach ($this->significantChangeProperties as $prop) {
954+
// @phpstan-ignore property.dynamicName
954955
if (isset($vevent->$prop)) {
955956
$propertyValues = $vevent->select($prop);
956957

lib/PHPUnitAssertions.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function assertVObjectEqualsVObject($expected, $actual, string $message =
4141
$input = Reader::read($input);
4242
}
4343
if (!$input instanceof Component) {
44-
$this->fail('Input must be a string, stream or VObject component');
44+
$this::fail('Input must be a string, stream or VObject component');
4545
}
4646
unset($input->PRODID);
4747
if ($input instanceof Component\VCalendar && 'GREGORIAN' === (string) $input->CALSCALE) {
@@ -51,23 +51,26 @@ public function assertVObjectEqualsVObject($expected, $actual, string $message =
5151
return $input;
5252
};
5353

54-
$expected = $getObj($expected)->serialize();
55-
$actual = $getObj($actual)->serialize();
54+
/**
55+
* @var string $expectedSerialized
56+
*/
57+
$expectedSerialized = $getObj($expected)->serialize();
58+
$actualSerialized = $getObj($actual)->serialize();
5659

5760
// Finding wildcards in expected.
58-
preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\r$|m', (string) $expected, $matches, PREG_SET_ORDER);
61+
preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\r$|m', $expectedSerialized, $matches, PREG_SET_ORDER);
5962

6063
foreach ($matches as $match) {
61-
$actual = preg_replace(
64+
$actualSerialized = preg_replace(
6265
'|^'.preg_quote($match[1], '|').':(.*)\r$|m',
6366
$match[1].':**ANY**'."\r",
64-
(string) $actual
67+
(string) $actualSerialized
6568
);
6669
}
6770

68-
$this->assertEquals(
69-
$expected,
70-
$actual,
71+
$this::assertEquals(
72+
$expectedSerialized,
73+
$actualSerialized,
7174
$message
7275
);
7376
}

lib/Parameter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ public function has(string $value): bool
163163
{
164164
return in_array(
165165
strtolower($value),
166-
array_map(strtolower(...), (array) $this->value)
166+
array_map(strtolower(...), (array) $this->value),
167+
true
167168
);
168169
}
169170

0 commit comments

Comments
 (0)