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

PHP 8.1 deprecated support for null values in its APIs #561

Merged
merged 10 commits into from
Aug 17, 2022
2 changes: 1 addition & 1 deletion lib/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ protected function convert($vObj)
*/
protected function color($vObj)
{
fwrite($this->stdout, $this->serializeComponent($vObj));
$this->serializeComponent($vObj);
phil-davis marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Component extends Node
/**
* A list of properties and/or sub-components.
*
* @var array
* @var array<string, Component|Property>
*/
protected $children = [];

Expand All @@ -43,12 +43,12 @@ 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 $name such as VCALENDAR, VEVENT
* @param bool $defaults
* @param string|null $name such as VCALENDAR, VEVENT
* @param bool $defaults
*/
public function __construct(Document $root, $name, array $children = [], $defaults = true)
{
$this->name = strtoupper($name);
$this->name = isset($name) ? strtoupper($name) : '';
$this->root = $root;

if ($defaults) {
Expand Down Expand Up @@ -238,7 +238,7 @@ public function select($name)
return array_filter(
$result,
function ($child) use ($group) {
return $child instanceof Property && strtoupper($child->group) === $group;
return $child instanceof Property && (null !== $child->group ? strtoupper($child->group) : '') === $group;
}
);
}
Expand All @@ -249,7 +249,7 @@ function ($child) use ($group) {
$result = [];
foreach ($this->children as $childGroup) {
foreach ($childGroup as $child) {
if ($child instanceof Property && $child->group && strtoupper($child->group) === $group) {
if ($child instanceof Property && (null !== $child->group ? strtoupper($child->group) : '') === $group) {
$result[] = $child;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ class Parameter extends Node
*/
public function __construct(Document $root, $name, $value = null)
{
$this->name = strtoupper($name);
$this->root = $root;
if (is_null($name)) {
$this->noName = true;
$this->name = static::guessParameterNameByValue($value);
} else {
$this->name = strtoupper($name);
}

// If guessParameterNameByValue() returns an empty string
Expand Down
2 changes: 1 addition & 1 deletion lib/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class Property extends Node
*
* This is only used in vcards
*
* @var string
* @var string|null
*/
public $group;

Expand Down
22 changes: 12 additions & 10 deletions lib/Property/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ public function getRawMimeDirValue()
}

foreach ($item as &$subItem) {
$subItem = strtr(
$subItem,
[
'\\' => '\\\\',
';' => '\;',
',' => '\,',
"\n" => '\n',
"\r" => '',
]
);
if (!is_null($subItem)) {
$subItem = strtr(
$subItem,
[
'\\' => '\\\\',
';' => '\;',
',' => '\,',
"\n" => '\n',
"\r" => '',
]
);
}
}
$item = implode(',', $item);
}
Expand Down
17 changes: 16 additions & 1 deletion tests/VObject/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,31 @@ public function testMagicGetGroups()
$sub = $comp->createProperty('EMAIL', '3@3.com');
$comp->add($sub);

$sub = $comp->createProperty('0.EMAIL', '0@0.com');
$comp->add($sub);

$emails = $comp->email;
$this->assertEquals(3, count($emails));
$this->assertEquals(4, count($emails));

$email1 = $comp->{'group1.email'};
$this->assertEquals('EMAIL', $email1[0]->name);
$this->assertEquals('GROUP1', $email1[0]->group);

$email0 = $comp->{'0.email'};
$this->assertEquals('EMAIL', $email0[0]->name);
$this->assertEquals('0', $email0[0]->group);

// this is supposed to return all EMAIL properties that do not have a group
$email3 = $comp->{'.email'};
$this->assertEquals('EMAIL', $email3[0]->name);
$this->assertEquals(null, $email3[0]->group);

// this is supposed to return all properties that do not have a group
$nogroupProps = $comp->{'.'};
$this->assertGreaterThan(0, count($email3));
foreach ($nogroupProps as $prop) {
$this->assertEquals(null, $prop->group);
}
}

public function testAddGroupProperties()
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
failOnWarning="true"
enforceTimeLimit="true"
>
<php>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuites>
<testsuite name="Sabre\VObject">
<directory>.</directory>
Expand Down