Skip to content

Commit

Permalink
Increase phpstan to level 1
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Feb 11, 2021
1 parent 38efc9e commit 0939a25
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 23 deletions.
1 change: 1 addition & 0 deletions lib/CalDAV/Schedule/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public function scheduleLocalDelivery(ITip\Message $iTipMessage)

$currentObject = null;
$objectNode = null;
$oldICalendarData = null;
$isNewNode = false;

$result = $home->getCalendarObjectByUID($uid);
Expand Down
5 changes: 4 additions & 1 deletion lib/DAV/FSExt/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/DAV/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ protected function copyNode(INode $source, ICollection $destinationParent, $dest
$destinationName = $source->getName();
}

$destination = null;

if ($source instanceof IFile) {
$data = $source->get();

Expand Down
3 changes: 0 additions & 3 deletions lib/DAV/Xml/Property/Href.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
parameters:
level: 0
level: 1
bootstrapFiles:
- tests/bootstrap.php
14 changes: 7 additions & 7 deletions tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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',
Expand All @@ -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',
]);

Expand All @@ -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',
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 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,7 +84,6 @@ 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
7 changes: 7 additions & 0 deletions tests/Sabre/DAV/DbTestHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
29 changes: 28 additions & 1 deletion tests/Sabre/DAV/FSExt/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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+');
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
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: 2 additions & 0 deletions tests/Sabre/DAVACL/PrincipalBackend/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0939a25

Please sign in to comment.