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

PHPStan level 1 #1255

Closed
wants to merge 6 commits into from
Closed
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
16 changes: 4 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"phpstan/phpstan": "^0.12",
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.0",
"evert/phpdoc-md" : "~0.1.0",
"monolog/monolog": "^1.18"
"monolog/monolog": "^1.18",
"phpstan/phpstan-phpunit": "^0.12.6"
},
"suggest" : {
"ext-curl" : "*",
Expand All @@ -46,21 +47,12 @@
},
"autoload": {
"psr-4" : {
"Sabre\\DAV\\" : "lib/DAV/",
"Sabre\\DAVACL\\" : "lib/DAVACL/",
"Sabre\\CalDAV\\" : "lib/CalDAV/",
"Sabre\\CardDAV\\" : "lib/CardDAV/"
"Sabre\\" : "lib/"
}
},
"autoload-dev" : {
"psr-4" : {
"Sabre\\" : "tests/Sabre/",
"Sabre\\CalDAV\\" : "tests/Sabre/CalDAV",
"Sabre\\CardDAV\\" : "tests/Sabre/CardDAV",
"Sabre\\DAV\\" : "tests/Sabre/DAV",
"Sabre\\DAV\\Property\\" : "tests/Sabre/DAV/Xml/Property",
"Sabre\\DAVACL\\" : "tests/Sabre/DAVACL",
"Sabre\\HTTP\\" : "tests/Sabre/HTTP"
"Sabre\\" : "tests/Sabre/"
}
},
"support" : {
Expand Down
5 changes: 2 additions & 3 deletions lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,7 @@ public function scheduleLocalDelivery(ITip\Message $iTipMessage)
// There was an existing object, we need to update probably.
$objectPath = $homePath.'/'.$result;
$objectNode = $this->server->tree->getNodeForPath($objectPath);
$oldICalendarData = $objectNode->get();
$currentObject = Reader::read($oldICalendarData);
$currentObject = Reader::read($objectNode->get());
} else {
$isNewNode = true;
}
Expand Down Expand Up @@ -528,7 +527,7 @@ public function scheduleLocalDelivery(ITip\Message $iTipMessage)
// another itipMessage.
if ('REPLY' === $iTipMessage->method) {
$this->processICalendarChange(
$oldICalendarData,
$objectNode->get(),
$newObject,
[$iTipMessage->recipient],
[$iTipMessage->sender]
Expand Down
2 changes: 2 additions & 0 deletions lib/DAV/FSExt/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public function patch($data, $rangeType, $offset = null)
$f = fopen($this->path, 'c');
fseek($f, $offset, SEEK_END);
break;
default:
throw new \UnexpectedValueException('Unkown rangeType used: '.$rangeType);
}
if (is_string($data)) {
fwrite($f, $data);
Expand Down
2 changes: 2 additions & 0 deletions lib/DAV/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ protected function copyNode(INode $source, ICollection $destinationParent, $dest
foreach ($source->getChildren() as $child) {
$this->copyNode($child, $destination);
}
} else {
throw new \UnexpectedValueException('Source must be either IFile or ICollection.');
}
if ($source instanceof IProperties && $destination instanceof IProperties) {
$props = $source->getProperties([]);
Expand Down
9 changes: 8 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
parameters:
level: 0
level: 1
ignoreErrors:
-
message: '#Constant (SABRE_TEMPDIR|SABRE_MYSQLDSN|SABRE_MYSQLPASS|SABRE_MYSQLUSER|SABRE_PGSQLDSN|SABRE_HASSQLITE) not found\.#'
path: tests/*
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
14 changes: 7 additions & 7 deletions tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ public function testGetChangesBadId()
public function testCreateSubscriptions()
{
$props = [
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics'),
'{DAV:}displayname' => 'cal',
'{http://apple.com/ns/ical/}refreshrate' => 'P1W',
'{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF',
Expand Down Expand Up @@ -916,7 +916,7 @@ public function testCreateSubscriptionFail()
public function testUpdateSubscriptions()
{
$props = [
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics'),
'{DAV:}displayname' => 'cal',
'{http://apple.com/ns/ical/}refreshrate' => 'P1W',
'{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF',
Expand All @@ -930,7 +930,7 @@ public function testUpdateSubscriptions()

$newProps = [
'{DAV:}displayname' => 'new displayname',
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics'),
];

$propPatch = new DAV\PropPatch($newProps);
Expand Down Expand Up @@ -958,7 +958,7 @@ public function testUpdateSubscriptions()
public function testUpdateSubscriptionsFail()
{
$props = [
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics'),
'{DAV:}displayname' => 'cal',
'{http://apple.com/ns/ical/}refreshrate' => 'P1W',
'{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF',
Expand All @@ -972,7 +972,7 @@ public function testUpdateSubscriptionsFail()

$propPatch = new DAV\PropPatch([
'{DAV:}displayname' => 'new displayname',
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics'),
'{DAV:}unknown' => 'foo',
]);

Expand All @@ -989,7 +989,7 @@ public function testUpdateSubscriptionsFail()
public function testDeleteSubscriptions()
{
$props = [
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics'),
'{DAV:}displayname' => 'cal',
'{http://apple.com/ns/ical/}refreshrate' => 'P1W',
'{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF',
Expand All @@ -1003,7 +1003,7 @@ public function testDeleteSubscriptions()

$newProps = [
'{DAV:}displayname' => 'new displayname',
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics', false),
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics'),
];

$backend->deleteSubscription(1);
Expand Down
4 changes: 1 addition & 3 deletions tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function testInvalidArg1()
$this->expectException('InvalidArgumentException');
$obj = new SchedulingObject(
new Backend\MockScheduling([], []),
[],
[]
);
}
Expand All @@ -85,8 +84,7 @@ public function testInvalidArg2()
$this->expectException('InvalidArgumentException');
$obj = new SchedulingObject(
new Backend\MockScheduling([], []),
[],
['calendarid' => '1']
[]
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getSub($override = [])
$caldavBackend = new \Sabre\CalDAV\Backend\MockSubscriptionSupport([], []);

$info = [
'{http://calendarserver.org/ns/}source' => new Href('http://example.org/src', false),
'{http://calendarserver.org/ns/}source' => new Href('http://example.org/src'),
'lastmodified' => date('2013-04-06 11:40:00'), // tomorrow is my birthday!
'{DAV:}displayname' => 'displayname',
];
Expand All @@ -43,7 +43,7 @@ public function testValues()
$this->assertEquals(
[
'{DAV:}displayname' => 'displayname',
'{http://calendarserver.org/ns/}source' => new Href('http://example.org/src', false),
'{http://calendarserver.org/ns/}source' => new Href('http://example.org/src'),
],
$sub->getProperties(['{DAV:}displayname', '{http://calendarserver.org/ns/}source'])
);
Expand Down
2 changes: 2 additions & 0 deletions tests/Sabre/DAV/DbTestHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function getDb()
$this->markTestSkipped('We require at least Postgres 9.5. This server is running '.$version);
}
break;
default:
throw new \UnexpectedValueException('Unknown driver: '.$this->driver);
}
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/SyncTokenPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function data()
],
[
'{DAV:}sync-token',
new Xml\Property\Href(Sync\Plugin::SYNCTOKEN_PREFIX.'hello', false),
new Xml\Property\Href(Sync\Plugin::SYNCTOKEN_PREFIX.'hello'),
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/Xml/Element/PropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testDeserializeCustom()
XML;

$expected = [
'{DAV:}foo' => new Href('/hello', false),
'{DAV:}foo' => new Href('/hello'),
];

$elementMap = [
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/Xml/Element/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testSerializeComplexProperty()
{
$innerProps = [
200 => [
'{DAV:}link' => new DAV\Xml\Property\Href('http://sabredav.org/', false),
'{DAV:}link' => new DAV\Xml\Property\Href('http://sabredav.org/'),
],
];

Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/Xml/Property/HrefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testUnserializeEmpty()
*/
public function testSerializeEntity()
{
$href = new Href('http://example.org/?a&b', false);
$href = new Href('http://example.org/?a&b');
$this->assertEquals('http://example.org/?a&b', $href->getHref());

$xml = $this->write(['{DAV:}anything' => $href]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/Xml/Property/SupportedReportSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Sabre\DAV\Property;
namespace Sabre\DAV\Xml\Property;

use Sabre\DAV;
use Sabre\HTTP;
Expand Down
4 changes: 2 additions & 2 deletions tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testSetGroupMembers()
$server->addPlugin($plugin);

$result = $server->updateProperties('foo', [
'{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar', '/baz'], true),
'{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar', '/baz']),
]);

$expected = [
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testSetBadNode()
$server->addPlugin($plugin);

$result = $server->updateProperties('foo', [
'{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar', '/baz'], false),
'{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar', '/baz']),
]);

$expected = [
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/DAVACL/PrincipalBackend/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch)
break;
}
}
if (!$principal) {
if (!isset($principal) || !isset($principalIndex)) {
return;
}

Expand Down