[Asset] Add type-hints to public interfaces

This commit is contained in:
Jan Schädlich 2019-06-26 21:18:12 +02:00
parent aac5765779
commit 065fdc146c
9 changed files with 24 additions and 39 deletions

View File

@ -35,7 +35,7 @@ class Package implements PackageInterface
/**
* {@inheritdoc}
*/
public function getVersion($path)
public function getVersion(string $path)
{
return $this->versionStrategy->getVersion($path);
}
@ -43,7 +43,7 @@ class Package implements PackageInterface
/**
* {@inheritdoc}
*/
public function getUrl($path)
public function getUrl(string $path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
@ -68,7 +68,7 @@ class Package implements PackageInterface
return $this->versionStrategy;
}
protected function isAbsoluteUrl($url)
protected function isAbsoluteUrl(string $url)
{
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
}

View File

@ -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);
}

View File

@ -44,12 +44,9 @@ class Packages
}
/**
* 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 @@ class Packages
* @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 @@ class Packages
*
* @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 @@ class Packages
*
* @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);
}

View File

@ -51,7 +51,7 @@ class PathPackage extends Package
/**
* {@inheritdoc}
*/
public function getUrl($path)
public function getUrl(string $path)
{
$versionedPath = parent::getUrl($path);

View File

@ -69,7 +69,7 @@ class UrlPackage extends Package
/**
* {@inheritdoc}
*/
public function getUrl($path)
public function getUrl(string $path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
@ -95,11 +95,9 @@ class UrlPackage extends Package
/**
* 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 @@ class UrlPackage extends Package
* 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) {

View File

@ -21,7 +21,7 @@ class EmptyVersionStrategy implements VersionStrategyInterface
/**
* {@inheritdoc}
*/
public function getVersion($path)
public function getVersion(string $path)
{
return '';
}
@ -29,7 +29,7 @@ class EmptyVersionStrategy implements VersionStrategyInterface
/**
* {@inheritdoc}
*/
public function applyVersion($path)
public function applyVersion(string $path)
{
return $path;
}

View File

@ -40,17 +40,17 @@ class JsonManifestVersionStrategy implements VersionStrategyInterface
* 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)) {

View File

@ -34,7 +34,7 @@ class StaticVersionStrategy implements VersionStrategyInterface
/**
* {@inheritdoc}
*/
public function getVersion($path)
public function getVersion(string $path)
{
return $this->version;
}
@ -42,7 +42,7 @@ class StaticVersionStrategy implements VersionStrategyInterface
/**
* {@inheritdoc}
*/
public function applyVersion($path)
public function applyVersion(string $path)
{
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));

View File

@ -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);
}