Skip to content

[Asset] Add type-hints to public interfaces and classes #32202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Symfony/Component/Asset/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public function __construct(VersionStrategyInterface $versionStrategy, ContextIn
/**
* {@inheritdoc}
*/
public function getVersion($path)
public function getVersion(string $path)
{
return $this->versionStrategy->getVersion($path);
}

/**
* {@inheritdoc}
*/
public function getUrl($path)
public function getUrl(string $path)
{
if ($this->isAbsoluteUrl($path)) {
return $path;
Expand All @@ -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);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Asset/PackageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 5 additions & 8 deletions src/Symfony/Component/Asset/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Asset/PathPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Asset/UrlPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class EmptyVersionStrategy implements VersionStrategyInterface
/**
* {@inheritdoc}
*/
public function getVersion($path)
public function getVersion(string $path)
{
return '';
}

/**
* {@inheritdoc}
*/
public function applyVersion($path)
public function applyVersion(string $path)
{
return $path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public function __construct(string $version, string $format = null)
/**
* {@inheritdoc}
*/
public function getVersion($path)
public function getVersion(string $path)
{
return $this->version;
}

/**
* {@inheritdoc}
*/
public function applyVersion($path)
public function applyVersion(string $path)
{
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}