Skip to content

Commit 9ceeb86

Browse files
committed
Add const DIRECTORY_SEPARATOR and fix whitespace issues
Introduce the DIRECTORY_SEPARATOR constant in SurrogateKeys, UriTag, and DevEtagSetter to replace direct string usage. Additionally, correct whitespace inconsistencies in method calls involving sprintf and str_replace.
1 parent e236fb1 commit 9ceeb86

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/DevEtagSetter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use function sprintf;
1515
use function str_replace;
1616

17+
use const DIRECTORY_SEPARATOR;
18+
1719
final class DevEtagSetter implements EtagSetterInterface
1820
{
1921
public function __construct(
@@ -26,7 +28,7 @@ public function __construct(
2628
*/
2729
public function __invoke(ResourceObject $ro, int|null $time = null, HttpCache|null $httpCache = null)
2830
{
29-
$ro->headers[Header::ETAG] = sprintf('%s_%s', str_replace([':', DIRECTORY_SEPARATOR ], ['_', '_'], $ro->uri->path), http_build_query($ro->uri->query));
31+
$ro->headers[Header::ETAG] = sprintf('%s_%s', str_replace([':', DIRECTORY_SEPARATOR], ['_', '_'], $ro->uri->path), http_build_query($ro->uri->query));
3032
$ro->headers[Header::LAST_MODIFIED] = gmdate(DateTimeInterface::RFC7231, 0);
3133
$this->setCacheDependency($ro);
3234
}

src/SurrogateKeys.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use function sprintf;
1717
use function str_replace;
1818

19+
use const DIRECTORY_SEPARATOR;
20+
1921
final class SurrogateKeys
2022
{
2123
/** @var list<string> */
@@ -24,7 +26,7 @@ final class SurrogateKeys
2426

2527
public function __construct(AbstractUri $uri)
2628
{
27-
$uriKey = sprintf('%s_%s', str_replace(DIRECTORY_SEPARATOR , '_', $uri->path), http_build_query($uri->query));
29+
$uriKey = sprintf('%s_%s', str_replace(DIRECTORY_SEPARATOR, '_', $uri->path), http_build_query($uri->query));
2830
$this->surrogateKeys = [$uriKey];
2931
$this->uriTag = new UriTag();
3032
}

src/UriTag.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use function str_replace;
1515
use function uri_template;
1616

17+
use const DIRECTORY_SEPARATOR;
18+
1719
final class UriTag implements UriTagInterface
1820
{
1921
/**
@@ -24,7 +26,7 @@ public function __invoke(AbstractUri $uri): string
2426
$query = $uri->query;
2527
ksort($query);
2628

27-
return str_replace(DIRECTORY_SEPARATOR , '_', sprintf('%s_%s', $uri->path, http_build_query($query)));
29+
return str_replace(DIRECTORY_SEPARATOR, '_', sprintf('%s_%s', $uri->path, http_build_query($query)));
2830
}
2931

3032
/**

0 commit comments

Comments
 (0)