Apply new CS rules on the webdav feature

This commit is contained in:
2024-01-15 20:38:03 +01:00
parent fca929f56f
commit 4cff706306
14 changed files with 104 additions and 108 deletions

View File

@@ -16,7 +16,6 @@ use Chill\DocStoreBundle\Dav\Response\DavResponse;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use DateTimeInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -42,7 +41,7 @@ final readonly class WebdavController
public function __construct(
private \Twig\Environment $engine,
private StoredObjectManagerInterface $storedObjectManager,
private Security $security,
private Security $security,
) {
$this->requestAnalyzer = new PropfindRequestAnalyzer();
}
@@ -73,11 +72,11 @@ final readonly class WebdavController
throw new AccessDeniedHttpException();
}
$response = (new DavResponse(""))
$response = (new DavResponse(''))
->setEtag($this->storedObjectManager->etag($storedObject))
;
//$response->headers->add(['Allow' => 'OPTIONS,GET,HEAD,DELETE,PROPFIND,PUT,PROPPATCH,COPY,MOVE,REPORT,PATCH,POST,TRACE']);
// $response->headers->add(['Allow' => 'OPTIONS,GET,HEAD,DELETE,PROPFIND,PUT,PROPPATCH,COPY,MOVE,REPORT,PATCH,POST,TRACE']);
$response->headers->add(['Allow' => 'OPTIONS,GET,HEAD,DELETE,PROPFIND,PUT']);
return $response;
@@ -94,8 +93,8 @@ final readonly class WebdavController
$depth = $request->headers->get('depth');
if ("0" !== $depth && "1" !== $depth) {
throw new BadRequestHttpException("only 1 and 0 are accepted for Depth header");
if ('0' !== $depth && '1' !== $depth) {
throw new BadRequestHttpException('only 1 and 0 are accepted for Depth header');
}
[$properties, $lastModified, $etag, $length] = $this->parseDavRequest($request->getContent(), $storedObject);
@@ -104,7 +103,7 @@ final readonly class WebdavController
$this->engine->render('@ChillDocStore/Webdav/directory_propfind.xml.twig', [
'stored_object' => $storedObject,
'properties' => $properties,
'last_modified' => $lastModified ,
'last_modified' => $lastModified,
'etag' => $etag,
'content_length' => $length,
'depth' => (int) $depth,
@@ -114,7 +113,7 @@ final readonly class WebdavController
);
$response->headers->add([
'Content-Type' => 'text/xml'
'Content-Type' => 'text/xml',
]);
return $response;
@@ -142,13 +141,13 @@ final readonly class WebdavController
throw new AccessDeniedHttpException();
}
$response = new DavResponse("");
$response = new DavResponse('');
$response->headers->add(
[
'Content-Length' => $this->storedObjectManager->getContentLength($storedObject),
'Content-Type' => $storedObject->getType(),
'Etag' => $this->storedObjectManager->etag($storedObject)
'Etag' => $this->storedObjectManager->etag($storedObject),
]
);
@@ -164,7 +163,7 @@ final readonly class WebdavController
throw new AccessDeniedHttpException();
}
$response = (new DavResponse(""))
$response = (new DavResponse(''))
->setEtag($this->storedObjectManager->etag($storedObject))
;
@@ -201,7 +200,7 @@ final readonly class WebdavController
$response
->headers->add([
'Content-Type' => 'text/xml'
'Content-Type' => 'text/xml',
]);
return $response;
@@ -218,11 +217,11 @@ final readonly class WebdavController
$this->storedObjectManager->write($storedObject, $request->getContent());
return (new DavResponse("", Response::HTTP_NO_CONTENT));
return new DavResponse('', Response::HTTP_NO_CONTENT);
}
/**
* @return array{0: array, 1: DateTimeInterface, 2: string, 3: int} properties, lastModified, etag, length
* @return array{0: array, 1: \DateTimeInterface, 2: string, 3: int} properties, lastModified, etag, length
*/
private function parseDavRequest(string $content, StoredObject $storedObject): array
{
@@ -247,7 +246,7 @@ final readonly class WebdavController
$properties,
$lastModified ?? null,
$etag ?? null,
$length ?? null
$length ?? null,
];
}
}