From dec91be1714401dd6e609a76eda5970e9148c600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 25 Aug 2022 16:59:21 +0200 Subject: [PATCH 1/2] [CS] Remove @inheritdoc PHPDoc --- Context/NullContext.php | 6 ------ Context/RequestStackContext.php | 6 ------ Package.php | 6 ------ PathPackage.php | 3 --- UrlPackage.php | 3 --- VersionStrategy/EmptyVersionStrategy.php | 6 ------ VersionStrategy/StaticVersionStrategy.php | 6 ------ 7 files changed, 36 deletions(-) diff --git a/Context/NullContext.php b/Context/NullContext.php index d662fef..982ca3c 100644 --- a/Context/NullContext.php +++ b/Context/NullContext.php @@ -18,17 +18,11 @@ */ class NullContext implements ContextInterface { - /** - * {@inheritdoc} - */ public function getBasePath(): string { return ''; } - /** - * {@inheritdoc} - */ public function isSecure(): bool { return false; diff --git a/Context/RequestStackContext.php b/Context/RequestStackContext.php index 19cd526..431c7f1 100644 --- a/Context/RequestStackContext.php +++ b/Context/RequestStackContext.php @@ -31,9 +31,6 @@ public function __construct(RequestStack $requestStack, string $basePath = '', b $this->secure = $secure; } - /** - * {@inheritdoc} - */ public function getBasePath(): string { if (!$request = $this->requestStack->getMainRequest()) { @@ -43,9 +40,6 @@ public function getBasePath(): string return $request->getBasePath(); } - /** - * {@inheritdoc} - */ public function isSecure(): bool { if (!$request = $this->requestStack->getMainRequest()) { diff --git a/Package.php b/Package.php index 76cd949..35f3fb6 100644 --- a/Package.php +++ b/Package.php @@ -32,17 +32,11 @@ public function __construct(VersionStrategyInterface $versionStrategy, ContextIn $this->context = $context ?? new NullContext(); } - /** - * {@inheritdoc} - */ public function getVersion(string $path): string { return $this->versionStrategy->getVersion($path); } - /** - * {@inheritdoc} - */ public function getUrl(string $path): string { if ($this->isAbsoluteUrl($path)) { diff --git a/PathPackage.php b/PathPackage.php index 4c79140..d8e08a3 100644 --- a/PathPackage.php +++ b/PathPackage.php @@ -46,9 +46,6 @@ public function __construct(string $basePath, VersionStrategyInterface $versionS } } - /** - * {@inheritdoc} - */ public function getUrl(string $path): string { $versionedPath = parent::getUrl($path); diff --git a/UrlPackage.php b/UrlPackage.php index abd8567..5f3c1cc 100644 --- a/UrlPackage.php +++ b/UrlPackage.php @@ -64,9 +64,6 @@ public function __construct(string|array $baseUrls, VersionStrategyInterface $ve } } - /** - * {@inheritdoc} - */ public function getUrl(string $path): string { if ($this->isAbsoluteUrl($path)) { diff --git a/VersionStrategy/EmptyVersionStrategy.php b/VersionStrategy/EmptyVersionStrategy.php index 93dbbb9..6903d7b 100644 --- a/VersionStrategy/EmptyVersionStrategy.php +++ b/VersionStrategy/EmptyVersionStrategy.php @@ -18,17 +18,11 @@ */ class EmptyVersionStrategy implements VersionStrategyInterface { - /** - * {@inheritdoc} - */ public function getVersion(string $path): string { return ''; } - /** - * {@inheritdoc} - */ public function applyVersion(string $path): string { return $path; diff --git a/VersionStrategy/StaticVersionStrategy.php b/VersionStrategy/StaticVersionStrategy.php index 6c6a343..4cbc8f7 100644 --- a/VersionStrategy/StaticVersionStrategy.php +++ b/VersionStrategy/StaticVersionStrategy.php @@ -31,17 +31,11 @@ public function __construct(string $version, string $format = null) $this->format = $format ?: '%s?%s'; } - /** - * {@inheritdoc} - */ public function getVersion(string $path): string { return $this->version; } - /** - * {@inheritdoc} - */ public function applyVersion(string $path): string { $versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path)); From a0ebf67f56f028217256d5f99438175430b3836c Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Tue, 18 Oct 2022 17:30:57 -0400 Subject: [PATCH 2/2] [Asset] improve performance of `UrlPackage::chooseBaseUrl()` Co-authored-by: Frank de Jonge --- Tests/UrlPackageTest.php | 15 ++++++++------- UrlPackage.php | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Tests/UrlPackageTest.php b/Tests/UrlPackageTest.php index 0b681a4..6384b45 100644 --- a/Tests/UrlPackageTest.php +++ b/Tests/UrlPackageTest.php @@ -48,10 +48,10 @@ public function getConfigs() ['file:///example/com/foo/', '', 'foo', 'file:///example/com/foo/foo?v1'], [['http://example.com'], '', '/foo', 'http://example.com/foo?v1'], - [['http://example.com', 'http://example.net'], '', '/foo', 'http://example.com/foo?v1'], - [['http://example.com', 'http://example.net'], '', '/fooa', 'http://example.net/fooa?v1'], - [['file:///example/com', 'file:///example/net'], '', '/foo', 'file:///example/com/foo?v1'], - [['ftp://example.com', 'ftp://example.net'], '', '/fooa', 'ftp://example.net/fooa?v1'], + [['http://example.com', 'http://example.net'], '', '/foo', 'http://example.net/foo?v1'], + [['http://example.com', 'http://example.net'], '', '/fooa', 'http://example.com/fooa?v1'], + [['file:///example/com', 'file:///example/net'], '', '/foo', 'file:///example/net/foo?v1'], + [['ftp://example.com', 'ftp://example.net'], '', '/fooa', 'ftp://example.com/fooa?v1'], ['http://example.com', 'version-%2$s/%1$s', '/foo', 'http://example.com/version-v1/foo'], ['http://example.com', 'version-%2$s/%1$s', 'foo', 'http://example.com/version-v1/foo'], @@ -77,15 +77,16 @@ public function getContextConfigs() return [ [false, 'http://example.com', '', 'foo', 'http://example.com/foo?v1'], [false, ['http://example.com'], '', 'foo', 'http://example.com/foo?v1'], - [false, ['http://example.com', 'https://example.com'], '', 'foo', 'http://example.com/foo?v1'], - [false, ['http://example.com', 'https://example.com'], '', 'fooa', 'https://example.com/fooa?v1'], + [false, ['http://example.com', 'https://example.com'], '', 'foo', 'https://example.com/foo?v1'], + [false, ['http://example.com', 'https://example.com'], '', 'fooa', 'http://example.com/fooa?v1'], [false, ['http://example.com/bar'], '', 'foo', 'http://example.com/bar/foo?v1'], [false, ['http://example.com/bar/'], '', 'foo', 'http://example.com/bar/foo?v1'], [false, ['//example.com/bar/'], '', 'foo', '//example.com/bar/foo?v1'], [true, ['http://example.com'], '', 'foo', 'http://example.com/foo?v1'], [true, ['http://example.com', 'https://example.com'], '', 'foo', 'https://example.com/foo?v1'], - [true, ['', 'https://example.com'], '', 'foo', '/foo?v1'], + [true, ['', 'https://example.com'], '', 'foo', 'https://example.com/foo?v1'], + [true, ['', 'https://example.com'], '', 'bar', '/bar?v1'], ]; } diff --git a/UrlPackage.php b/UrlPackage.php index 5f3c1cc..575523d 100644 --- a/UrlPackage.php +++ b/UrlPackage.php @@ -107,7 +107,7 @@ public function getBaseUrl(string $path): string */ protected function chooseBaseUrl(string $path): int { - return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls)); + return abs(crc32($path)) % \count($this->baseUrls); } private function getSslUrls(array $urls)