Skip to content

Commit

Permalink
chore: Fix code style
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Sep 5, 2024
1 parent 069c16d commit 3e722c3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/DAV/CorePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public function httpMove(RequestInterface $request, ResponseInterface $response)
$moveInfo = $this->server->getCopyAndMoveInfo($request);

// MOVE does only allow "infinity" every other header value is considered invalid
if ($moveInfo['depth'] !== 'infinity') {
if ('infinity' !== $moveInfo['depth']) {
throw new BadRequest('The HTTP Depth header must only contain "infinity" for MOVE');
}

Expand Down
12 changes: 6 additions & 6 deletions lib/DAV/ICopyTarget.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ interface ICopyTarget extends ICollection
* is that the copy was successful.
* If you return false, sabre/dav will handle the copy itself.
*
* @param string $targetName new local file/collection name
* @param string $sourcePath Full path to source node
* @param INode $sourceNode Source node itself
* @param string|int $depth How many level of children to copy.
* The value can be 'infinity' or a positiv number including zero.
* Zero means to only copy a shallow collection with props but without children.
* @param string $targetName new local file/collection name
* @param string $sourcePath Full path to source node
* @param INode $sourceNode Source node itself
* @param string|int $depth How many level of children to copy.
* The value can be 'infinity' or a positiv number including zero.
* Zero means to only copy a shallow collection with props but without children.
*
* @return bool
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/DAV/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ public function getCopyAndMoveInfo(RequestInterface $request)

// Depth of inifinty is valid for MOVE and COPY. If it is not set the RFC requires to act like it was 'infinity'.
$depth = strtolower($request->getHeader('Depth') ?? 'infinity');
if ($depth !== 'infinity' && is_numeric($depth)) {
$depth = (int)$depth;
if ('infinity' !== $depth && is_numeric($depth)) {
$depth = (int) $depth;
if ($depth < 0) {
throw new Exception\BadRequest('The HTTP Depth header may only be "infinity", 0 or a positiv number');

Check warning on line 734 in lib/DAV/Server.php

View check run for this annotation

Codecov / codecov/patch

lib/DAV/Server.php#L734

Added line #L734 was not covered by tests
}
Expand Down
18 changes: 9 additions & 9 deletions lib/DAV/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ public function nodeExists($path)
/**
* Copies a file from path to another.
*
* @param string $sourcePath The source location
* @param string $destinationPath The full destination path
* @param int|string $depth How much levle of children to copy.
* The value can be 'infinity' or a positiv integer, including zero.
* Zero means only copy the collection without children but with its properties.
* @param string $sourcePath The source location
* @param string $destinationPath The full destination path
* @param int|string $depth How much levle of children to copy.
* The value can be 'infinity' or a positiv integer, including zero.
* Zero means only copy the collection without children but with its properties.
*/
public function copy($sourcePath, $destinationPath, $depth = 'infinity')
{
Expand Down Expand Up @@ -310,8 +310,8 @@ public function getMultipleNodes($paths)
/**
* copyNode.
*
* @param string $destinationName
* @param int|string $depth How many children of the node to copy
* @param string $destinationName
* @param int|string $depth How many children of the node to copy
*/
protected function copyNode(INode $source, ICollection $destinationParent, ?string $destinationName = null, $depth = 'infinity')
{
Expand All @@ -338,9 +338,9 @@ protected function copyNode(INode $source, ICollection $destinationParent, ?stri
$destination = $destinationParent->getChild($destinationName);

// Copy children if depth is not zero
if ($depth !== 0) {
if (0 !== $depth) {
// Adjust next depth for children (keep 'infinity' or decrease)
$depth = $depth === 'infinity' ? 'infinity' : $depth - 1;
$depth = 'infinity' === $depth ? 'infinity' : $depth - 1;
$destination = $destinationParent->getChild($destinationName);
foreach ($source->getChildren() as $child) {
$this->copyNode($child, $destination, null, $depth);
Expand Down
14 changes: 9 additions & 5 deletions tests/Sabre/DAV/CorePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ public function testGetInfo()
self::assertEquals('core', $corePlugin->getPluginInfo()['name']);
}

public function moveInvalidDepthHeaderProvider() {
public function moveInvalidDepthHeaderProvider()
{
return [
[0],
[1],
];
}

/**
* MOVE does only allow "infinity" every other header value is considered invalid
* MOVE does only allow "infinity" every other header value is considered invalid.
*
* @dataProvider moveInvalidDepthHeaderProvider
*/
public function testMoveWithInvalidDepth($depthHeader) {
public function testMoveWithInvalidDepth($depthHeader)
{
$request = new HTTP\Request('MOVE', '/path/');
$response = new HTTP\Response();

Expand All @@ -45,9 +48,10 @@ public function testMoveWithInvalidDepth($depthHeader) {
}

/**
* MOVE does only allow "infinity" every other header value is considered invalid
* MOVE does only allow "infinity" every other header value is considered invalid.
*/
public function testMoveSupportsDepth() {
public function testMoveSupportsDepth()
{
$request = new HTTP\Request('MOVE', '/path/');
$response = new HTTP\Response();

Expand Down
5 changes: 3 additions & 2 deletions tests/Sabre/DAV/Mock/PropertiesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function propPatch(PropPatch $proppatch)
foreach ($updateProperties as $k => $v) {
$this->properties[$k] = $v;
}

return true;
case 'updatepropsarray':
$r = [];
Expand Down Expand Up @@ -81,7 +82,7 @@ public function propPatch(PropPatch $proppatch)
*/
public function getProperties($requestedProperties)
{
if (count($requestedProperties) === 0) {
if (0 === count($requestedProperties)) {
return $this->properties;
}

Expand All @@ -97,7 +98,7 @@ public function getProperties($requestedProperties)
}

/**
* Creates a new subdirectory. (Override to ensure props are preserved)
* Creates a new subdirectory. (Override to ensure props are preserved).
*
* @param string $name
*/
Expand Down
20 changes: 13 additions & 7 deletions tests/Sabre/DAV/ServerCopyMoveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
use Sabre\DAV\Exception\BadRequest;
use Sabre\HTTP;

class ServerCopyMoveTest extends AbstractServer
class ServerCopyMoveTest extends AbstractServerTestCase
{
/**
* Only 'infinity' and positiv (incl. 0) numbers are allowed
* Only 'infinity' and positive (incl. 0) numbers are allowed.
*
* @dataProvider dataInvalidDepthHeader
*/
public function testInvalidDepthHeader(?string $headerValue)
{
$request = new HTTP\Request('COPY', '/', $headerValue !== null ? ['Depth' => $headerValue] : []);
$request = new HTTP\Request('COPY', '/', null !== $headerValue ? ['Depth' => $headerValue] : []);

$this->expectException(BadRequest::class);
$this->server->getCopyAndMoveInfo($request);
}

public function dataInvalidDepthHeader() {
public function dataInvalidDepthHeader()
{
return [
['-1'],
['0.5'],
Expand All @@ -31,17 +33,21 @@ public function dataInvalidDepthHeader() {
}

/**
* Only 'infinity' and positiv (incl. 0) numbers are allowed
* Only 'infinity' and positive (incl. 0) numbers are allowed.
*
* @dataProvider dataDepthHeader
*
* @param string|int $expectedDepth
*/
public function testValidDepthHeader(array $depthHeader, string|int $expectedDepth)
public function testValidDepthHeader(array $depthHeader, $expectedDepth)
{
$request = new HTTP\Request('COPY', '/', array_merge(['Destination' => '/dst'], $depthHeader));

$this->assertEquals($expectedDepth, $this->server->getCopyAndMoveInfo($request)['depth']);
}

public function dataDepthHeader() {
public function dataDepthHeader()
{
return [
[
[],
Expand Down

0 comments on commit 3e722c3

Please sign in to comment.