From e293296f1e7841dac8c10a02233b412d6f61b97d Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Wed, 13 Nov 2024 16:09:47 +0100 Subject: [PATCH] Improved code quality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Paweł Niedzielski --- .../Core/Fragment/DecoratedFragmentRenderer.php | 1 - src/bundle/Core/Routing/DefaultRouter.php | 4 ++-- src/bundle/IO/BinaryStreamResponse.php | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bundle/Core/Fragment/DecoratedFragmentRenderer.php b/src/bundle/Core/Fragment/DecoratedFragmentRenderer.php index 6b7a97382c..846f4e7630 100644 --- a/src/bundle/Core/Fragment/DecoratedFragmentRenderer.php +++ b/src/bundle/Core/Fragment/DecoratedFragmentRenderer.php @@ -17,7 +17,6 @@ class DecoratedFragmentRenderer implements FragmentRendererInterface, SiteAccessAware { - /** @var \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface */ private FragmentRendererInterface $innerRenderer; private ?SiteAccess $siteAccess; diff --git a/src/bundle/Core/Routing/DefaultRouter.php b/src/bundle/Core/Routing/DefaultRouter.php index ed3a24aa79..b8999d2460 100644 --- a/src/bundle/Core/Routing/DefaultRouter.php +++ b/src/bundle/Core/Routing/DefaultRouter.php @@ -24,7 +24,7 @@ */ class DefaultRouter extends Router implements SiteAccessAware { - protected ?SiteAccess $siteAccess; + protected ?SiteAccess $siteAccess = null; /** @var string[] */ protected array $nonSiteAccessAwareRoutes = []; @@ -80,7 +80,7 @@ public function matchRequest(Request $request): array */ public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string { - $siteAccess = $this->siteAccess ?? null; + $siteAccess = $this->siteAccess; $originalContext = $context = $this->getContext(); $isSiteAccessAware = $this->isSiteAccessAwareRoute($name); diff --git a/src/bundle/IO/BinaryStreamResponse.php b/src/bundle/IO/BinaryStreamResponse.php index 4675f56e51..2b0725435c 100644 --- a/src/bundle/IO/BinaryStreamResponse.php +++ b/src/bundle/IO/BinaryStreamResponse.php @@ -56,6 +56,8 @@ public function __construct( /** * @phpstan-param \Symfony\Component\HttpFoundation\ResponseHeaderBag::DISPOSITION_*|null $contentDisposition + * + * @return $this */ public function setFile(BinaryFile $file, ?string $contentDisposition = null, bool $autoLastModified = true): static { @@ -79,6 +81,8 @@ public function getFile(): BinaryFile /** * Automatically sets the Last-Modified header according the file modification date. + * + * @return $this */ public function setAutoLastModified(): static { @@ -94,6 +98,8 @@ public function setAutoLastModified(): static * * @param string $filename Optionally use this filename instead of the real name of the file * @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename + * + * @return $this */ public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = ''): BinaryStreamResponse { @@ -111,6 +117,9 @@ public function setContentDisposition(string $disposition, string $filename = '' return $this; } + /** + * @return $this + */ public function prepare(Request $request): static { $this->headers->set('Content-Length', (string)$this->file->size); @@ -144,6 +153,8 @@ public function prepare(Request $request): static * Sends the file. * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * + * @return $this */ public function sendContent(): static { @@ -170,6 +181,8 @@ public function sendContent(): static /** * @throws \LogicException when the content is not null + * + * @return $this */ public function setContent(?string $content): static { @@ -216,12 +229,12 @@ private function processRangeRequest(Request $request): void if ($start < 0 || $end > $fileSize - 1) { $this->setStatusCode( Response::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE - ); // HTTP_REQUESTED_RANGE_NOT_SATISFIABLE + ); } elseif ($start !== 0 || $end !== $fileSize - 1) { $this->maxlen = $end < $fileSize ? $end - $start + 1 : -1; $this->offset = $start; - $this->setStatusCode(Response::HTTP_PARTIAL_CONTENT); // HTTP_PARTIAL_CONTENT + $this->setStatusCode(Response::HTTP_PARTIAL_CONTENT); $this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize)); $this->headers->set('Content-Length', $end - $start + 1); }