From 065fdc146ce1c7ad36e54200b4672ea180508f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Wed, 26 Jun 2019 21:18:12 +0200 Subject: [PATCH] [Asset] Add type-hints to public interfaces --- src/Symfony/Component/Asset/Package.php | 6 +++--- src/Symfony/Component/Asset/PackageInterface.php | 8 ++------ src/Symfony/Component/Asset/Packages.php | 13 +++++-------- src/Symfony/Component/Asset/PathPackage.php | 2 +- src/Symfony/Component/Asset/UrlPackage.php | 12 ++++-------- .../Asset/VersionStrategy/EmptyVersionStrategy.php | 4 ++-- .../VersionStrategy/JsonManifestVersionStrategy.php | 6 +++--- .../Asset/VersionStrategy/StaticVersionStrategy.php | 4 ++-- .../VersionStrategy/VersionStrategyInterface.php | 8 ++------ 9 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/Symfony/Component/Asset/Package.php b/src/Symfony/Component/Asset/Package.php index 77b1c934eb17..e770a1779471 100644 --- a/src/Symfony/Component/Asset/Package.php +++ b/src/Symfony/Component/Asset/Package.php @@ -35,7 +35,7 @@ public function __construct(VersionStrategyInterface $versionStrategy, ContextIn /** * {@inheritdoc} */ - public function getVersion($path) + public function getVersion(string $path) { return $this->versionStrategy->getVersion($path); } @@ -43,7 +43,7 @@ public function getVersion($path) /** * {@inheritdoc} */ - public function getUrl($path) + public function getUrl(string $path) { if ($this->isAbsoluteUrl($path)) { return $path; @@ -68,7 +68,7 @@ protected function getVersionStrategy() return $this->versionStrategy; } - protected function isAbsoluteUrl($url) + protected function isAbsoluteUrl(string $url) { return false !== strpos($url, '://') || '//' === substr($url, 0, 2); } diff --git a/src/Symfony/Component/Asset/PackageInterface.php b/src/Symfony/Component/Asset/PackageInterface.php index b9e9ff90b90c..644a30acaf95 100644 --- a/src/Symfony/Component/Asset/PackageInterface.php +++ b/src/Symfony/Component/Asset/PackageInterface.php @@ -21,18 +21,14 @@ interface PackageInterface /** * Returns the asset version for an asset. * - * @param string $path A path - * * @return string The version string */ - public function getVersion($path); + public function getVersion(string $path); /** * Returns an absolute or root-relative public path. * - * @param string $path A path - * * @return string The public path */ - public function getUrl($path); + public function getUrl(string $path); } diff --git a/src/Symfony/Component/Asset/Packages.php b/src/Symfony/Component/Asset/Packages.php index 3e82dcdcd407..6ac2ee370196 100644 --- a/src/Symfony/Component/Asset/Packages.php +++ b/src/Symfony/Component/Asset/Packages.php @@ -44,12 +44,9 @@ public function setDefaultPackage(PackageInterface $defaultPackage) } /** - * Adds a package. - * - * @param string $name The package name - * @param PackageInterface $package The package + * Adds a package. */ - public function addPackage($name, PackageInterface $package) + public function addPackage(string $name, PackageInterface $package) { $this->packages[$name] = $package; } @@ -64,7 +61,7 @@ public function addPackage($name, PackageInterface $package) * @throws InvalidArgumentException If there is no package by that name * @throws LogicException If no default package is defined */ - public function getPackage($name = null) + public function getPackage(string $name = null) { if (null === $name) { if (null === $this->defaultPackage) { @@ -89,7 +86,7 @@ public function getPackage($name = null) * * @return string The current version */ - public function getVersion($path, $packageName = null) + public function getVersion(string $path, string $packageName = null) { return $this->getPackage($packageName)->getVersion($path); } @@ -104,7 +101,7 @@ public function getVersion($path, $packageName = null) * * @return string A public path which takes into account the base path and URL path */ - public function getUrl($path, $packageName = null) + public function getUrl(string $path, string $packageName = null) { return $this->getPackage($packageName)->getUrl($path); } diff --git a/src/Symfony/Component/Asset/PathPackage.php b/src/Symfony/Component/Asset/PathPackage.php index e3cc56c0f711..7ee71ec987ce 100644 --- a/src/Symfony/Component/Asset/PathPackage.php +++ b/src/Symfony/Component/Asset/PathPackage.php @@ -51,7 +51,7 @@ public function __construct(string $basePath, VersionStrategyInterface $versionS /** * {@inheritdoc} */ - public function getUrl($path) + public function getUrl(string $path) { $versionedPath = parent::getUrl($path); diff --git a/src/Symfony/Component/Asset/UrlPackage.php b/src/Symfony/Component/Asset/UrlPackage.php index cb949d5969db..7bce30f6f505 100644 --- a/src/Symfony/Component/Asset/UrlPackage.php +++ b/src/Symfony/Component/Asset/UrlPackage.php @@ -69,7 +69,7 @@ public function __construct($baseUrls, VersionStrategyInterface $versionStrategy /** * {@inheritdoc} */ - public function getUrl($path) + public function getUrl(string $path) { if ($this->isAbsoluteUrl($path)) { return $path; @@ -95,11 +95,9 @@ public function getUrl($path) /** * Returns the base URL for a path. * - * @param string $path - * * @return string The base URL */ - public function getBaseUrl($path) + public function getBaseUrl(string $path) { if (1 === \count($this->baseUrls)) { return $this->baseUrls[0]; @@ -114,16 +112,14 @@ public function getBaseUrl($path) * Override this method to change the default distribution strategy. * This method should always return the same base URL index for a given path. * - * @param string $path - * * @return int The base URL index for the given path */ - protected function chooseBaseUrl($path) + protected function chooseBaseUrl(string $path) { return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls)); } - private function getSslUrls($urls) + private function getSslUrls(array $urls) { $sslUrls = []; foreach ($urls as $url) { diff --git a/src/Symfony/Component/Asset/VersionStrategy/EmptyVersionStrategy.php b/src/Symfony/Component/Asset/VersionStrategy/EmptyVersionStrategy.php index aa06eaa55ee7..8ee048c27983 100644 --- a/src/Symfony/Component/Asset/VersionStrategy/EmptyVersionStrategy.php +++ b/src/Symfony/Component/Asset/VersionStrategy/EmptyVersionStrategy.php @@ -21,7 +21,7 @@ class EmptyVersionStrategy implements VersionStrategyInterface /** * {@inheritdoc} */ - public function getVersion($path) + public function getVersion(string $path) { return ''; } @@ -29,7 +29,7 @@ public function getVersion($path) /** * {@inheritdoc} */ - public function applyVersion($path) + public function applyVersion(string $path) { return $path; } diff --git a/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php b/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php index 7bbfa90786ef..4752737c3e72 100644 --- a/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php +++ b/src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php @@ -40,17 +40,17 @@ public function __construct(string $manifestPath) * the version is. Instead, this returns the path to the * versioned file. */ - public function getVersion($path) + public function getVersion(string $path) { return $this->applyVersion($path); } - public function applyVersion($path) + public function applyVersion(string $path) { return $this->getManifestPath($path) ?: $path; } - private function getManifestPath($path) + private function getManifestPath(string $path) { if (null === $this->manifestData) { if (!file_exists($this->manifestPath)) { diff --git a/src/Symfony/Component/Asset/VersionStrategy/StaticVersionStrategy.php b/src/Symfony/Component/Asset/VersionStrategy/StaticVersionStrategy.php index e7ce0ec21897..3111e557d16b 100644 --- a/src/Symfony/Component/Asset/VersionStrategy/StaticVersionStrategy.php +++ b/src/Symfony/Component/Asset/VersionStrategy/StaticVersionStrategy.php @@ -34,7 +34,7 @@ public function __construct(string $version, string $format = null) /** * {@inheritdoc} */ - public function getVersion($path) + public function getVersion(string $path) { return $this->version; } @@ -42,7 +42,7 @@ public function getVersion($path) /** * {@inheritdoc} */ - public function applyVersion($path) + public function applyVersion(string $path) { $versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path)); diff --git a/src/Symfony/Component/Asset/VersionStrategy/VersionStrategyInterface.php b/src/Symfony/Component/Asset/VersionStrategy/VersionStrategyInterface.php index a0fb26003365..338192866f33 100644 --- a/src/Symfony/Component/Asset/VersionStrategy/VersionStrategyInterface.php +++ b/src/Symfony/Component/Asset/VersionStrategy/VersionStrategyInterface.php @@ -21,18 +21,14 @@ interface VersionStrategyInterface /** * Returns the asset version for an asset. * - * @param string $path A path - * * @return string The version string */ - public function getVersion($path); + public function getVersion(string $path); /** * Applies version to the supplied path. * - * @param string $path A path - * * @return string The versionized path */ - public function applyVersion($path); + public function applyVersion(string $path); }