From 0939a252aa0a0079dc6259f7d22fbd8327fbd4ca Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 11 Feb 2021 10:23:13 +0545 Subject: [PATCH] Increase phpstan to level 1 --- lib/CalDAV/Schedule/Plugin.php | 1 + lib/DAV/FSExt/File.php | 5 +++- lib/DAV/Tree.php | 2 ++ lib/DAV/Xml/Property/Href.php | 3 -- phpstan.neon | 4 ++- .../Sabre/CalDAV/Backend/AbstractPDOTest.php | 14 ++++----- .../CalDAV/Schedule/SchedulingObjectTest.php | 2 -- .../CalDAV/Subscriptions/SubscriptionTest.php | 4 +-- tests/Sabre/DAV/DbTestHelperTrait.php | 7 +++++ tests/Sabre/DAV/FSExt/FileTest.php | 29 ++++++++++++++++++- tests/Sabre/DAV/SyncTokenPropertyTest.php | 2 +- tests/Sabre/DAV/Xml/Element/PropTest.php | 2 +- tests/Sabre/DAV/Xml/Element/ResponseTest.php | 2 +- tests/Sabre/DAV/Xml/Property/HrefTest.php | 2 +- .../DAVACL/PluginUpdatePropertiesTest.php | 4 +-- tests/Sabre/DAVACL/PrincipalBackend/Mock.php | 2 ++ 16 files changed, 62 insertions(+), 23 deletions(-) diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php index a1f8202ece..38a7ca96fd 100644 --- a/lib/CalDAV/Schedule/Plugin.php +++ b/lib/CalDAV/Schedule/Plugin.php @@ -486,6 +486,7 @@ public function scheduleLocalDelivery(ITip\Message $iTipMessage) $currentObject = null; $objectNode = null; + $oldICalendarData = null; $isNewNode = false; $result = $home->getCalendarObjectByUID($uid); diff --git a/lib/DAV/FSExt/File.php b/lib/DAV/FSExt/File.php index 060ef5a485..74849b564e 100644 --- a/lib/DAV/FSExt/File.php +++ b/lib/DAV/FSExt/File.php @@ -41,7 +41,7 @@ public function put($data) * * The second argument is the type of update we're doing. * This is either: - * * 1. append + * * 1. append (default) * * 2. update based on a start byte * * 3. update based on an end byte *; @@ -75,6 +75,9 @@ public function patch($data, $rangeType, $offset = null) $f = fopen($this->path, 'c'); fseek($f, $offset, SEEK_END); break; + default: + $f = fopen($this->path, 'a'); + break; } if (is_string($data)) { fwrite($f, $data); diff --git a/lib/DAV/Tree.php b/lib/DAV/Tree.php index aedc0155d7..2417979a61 100644 --- a/lib/DAV/Tree.php +++ b/lib/DAV/Tree.php @@ -292,6 +292,8 @@ protected function copyNode(INode $source, ICollection $destinationParent, $dest $destinationName = $source->getName(); } + $destination = null; + if ($source instanceof IFile) { $data = $source->get(); diff --git a/lib/DAV/Xml/Property/Href.php b/lib/DAV/Xml/Property/Href.php index 0ed14dcf3c..f88ce814ad 100644 --- a/lib/DAV/Xml/Property/Href.php +++ b/lib/DAV/Xml/Property/Href.php @@ -39,9 +39,6 @@ class Href implements Element, HtmlOutput * * You must either pass a string for a single href, or an array of hrefs. * - * If auto-prefix is set to false, the hrefs will be treated as absolute - * and not relative to the servers base uri. - * * @param string|string[] $hrefs */ public function __construct($hrefs) diff --git a/phpstan.neon b/phpstan.neon index 5335bc6516..bf76201a5f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,2 +1,4 @@ parameters: - level: 0 + level: 1 + bootstrapFiles: + - tests/bootstrap.php diff --git a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php index 77817c4fd0..920895450f 100644 --- a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php +++ b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php @@ -963,7 +963,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', @@ -1004,7 +1004,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', @@ -1018,7 +1018,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); @@ -1046,7 +1046,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', @@ -1060,7 +1060,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', ]); @@ -1077,7 +1077,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', @@ -1091,7 +1091,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); diff --git a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php index 80b4c3731b..37195dadde 100644 --- a/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php +++ b/tests/Sabre/CalDAV/Schedule/SchedulingObjectTest.php @@ -75,7 +75,6 @@ public function testInvalidArg1() $this->expectException('InvalidArgumentException'); $obj = new SchedulingObject( new Backend\MockScheduling([], []), - [], [] ); } @@ -85,7 +84,6 @@ public function testInvalidArg2() $this->expectException('InvalidArgumentException'); $obj = new SchedulingObject( new Backend\MockScheduling([], []), - [], ['calendarid' => '1'] ); } diff --git a/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php b/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php index a656322efa..1012ba183e 100644 --- a/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php +++ b/tests/Sabre/CalDAV/Subscriptions/SubscriptionTest.php @@ -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', ]; @@ -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']) ); diff --git a/tests/Sabre/DAV/DbTestHelperTrait.php b/tests/Sabre/DAV/DbTestHelperTrait.php index 31323aca5e..007a40f924 100644 --- a/tests/Sabre/DAV/DbTestHelperTrait.php +++ b/tests/Sabre/DAV/DbTestHelperTrait.php @@ -30,6 +30,8 @@ public function getDb() throw new \Exception('You must set the $driver public property'); } + $pdo = null; + if (array_key_exists($this->driver, DbCache::$cache)) { $pdo = DbCache::$cache[$this->driver]; if (null === $pdo) { @@ -58,6 +60,11 @@ public function getDb() } break; } + + if (null === $pdo) { + $this->markTestSkipped($this->driver.' was not recognised'); + } + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $this->markTestSkipped($this->driver.' was not enabled or not correctly configured. Error message: '.$e->getMessage()); diff --git a/tests/Sabre/DAV/FSExt/FileTest.php b/tests/Sabre/DAV/FSExt/FileTest.php index 2b759e5d0d..a4c2e4e3ea 100644 --- a/tests/Sabre/DAV/FSExt/FileTest.php +++ b/tests/Sabre/DAV/FSExt/FileTest.php @@ -34,7 +34,16 @@ public function testPut() ); } - public function testRange() + public function testRangeAppend() + { + $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file->put('0000000'); + $file->patch('111', 1); + + $this->assertEquals('0000000111', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + } + + public function testRangeOffset() { $file = new File(SABRE_TEMPDIR.'/file.txt'); $file->put('0000000'); @@ -43,6 +52,24 @@ public function testRange() $this->assertEquals('0001110', file_get_contents(SABRE_TEMPDIR.'/file.txt')); } + public function testRangeOffsetEnd() + { + $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file->put('0000000'); + $file->patch('11', 3, -4); + + $this->assertEquals('0001100', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + } + + public function testRangeOffsetDefault() + { + $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file->put('0000000'); + $file->patch('11', 0); + + $this->assertEquals('000000011', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + } + public function testRangeStream() { $stream = fopen('php://memory', 'r+'); diff --git a/tests/Sabre/DAV/SyncTokenPropertyTest.php b/tests/Sabre/DAV/SyncTokenPropertyTest.php index 46f9a1c819..1167679444 100644 --- a/tests/Sabre/DAV/SyncTokenPropertyTest.php +++ b/tests/Sabre/DAV/SyncTokenPropertyTest.php @@ -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'), ], ]; } diff --git a/tests/Sabre/DAV/Xml/Element/PropTest.php b/tests/Sabre/DAV/Xml/Element/PropTest.php index 16bc0d306b..c5f1d94168 100644 --- a/tests/Sabre/DAV/Xml/Element/PropTest.php +++ b/tests/Sabre/DAV/Xml/Element/PropTest.php @@ -65,7 +65,7 @@ public function testDeserializeCustom() XML; $expected = [ - '{DAV:}foo' => new Href('/hello', false), + '{DAV:}foo' => new Href('/hello'), ]; $elementMap = [ diff --git a/tests/Sabre/DAV/Xml/Element/ResponseTest.php b/tests/Sabre/DAV/Xml/Element/ResponseTest.php index 09f0621916..9e198088d0 100644 --- a/tests/Sabre/DAV/Xml/Element/ResponseTest.php +++ b/tests/Sabre/DAV/Xml/Element/ResponseTest.php @@ -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/'), ], ]; diff --git a/tests/Sabre/DAV/Xml/Property/HrefTest.php b/tests/Sabre/DAV/Xml/Property/HrefTest.php index 9dc748a757..7b8db962bd 100644 --- a/tests/Sabre/DAV/Xml/Property/HrefTest.php +++ b/tests/Sabre/DAV/Xml/Property/HrefTest.php @@ -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]); diff --git a/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php b/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php index e6796e014e..aeef743cb7 100644 --- a/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php +++ b/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php @@ -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 = [ @@ -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 = [ diff --git a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php index 5f0434579f..c12710c910 100644 --- a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php +++ b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php @@ -131,6 +131,8 @@ public function setGroupMemberSet($path, array $members) public function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) { $value = null; + $principal = false; + $principalIndex = null; foreach ($this->principals as $principalIndex => $value) { if ($value['uri'] === $path) { $principal = $value;