Skip to content

Commit c171410

Browse files
committed
[Asset] Add type-hints to public interfaces
1 parent c10ad18 commit c171410

File tree

9 files changed

+24
-39
lines changed

9 files changed

+24
-39
lines changed

src/Symfony/Component/Asset/Package.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public function __construct(VersionStrategyInterface $versionStrategy, ContextIn
3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function getVersion($path)
38+
public function getVersion(string $path)
3939
{
4040
return $this->versionStrategy->getVersion($path);
4141
}
4242

4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function getUrl($path)
46+
public function getUrl(string $path)
4747
{
4848
if ($this->isAbsoluteUrl($path)) {
4949
return $path;
@@ -68,7 +68,7 @@ protected function getVersionStrategy()
6868
return $this->versionStrategy;
6969
}
7070

71-
protected function isAbsoluteUrl($url)
71+
protected function isAbsoluteUrl(string $url)
7272
{
7373
return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
7474
}

src/Symfony/Component/Asset/PackageInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ interface PackageInterface
2121
/**
2222
* Returns the asset version for an asset.
2323
*
24-
* @param string $path A path
25-
*
2624
* @return string The version string
2725
*/
28-
public function getVersion($path);
26+
public function getVersion(string $path);
2927

3028
/**
3129
* Returns an absolute or root-relative public path.
3230
*
33-
* @param string $path A path
34-
*
3531
* @return string The public path
3632
*/
37-
public function getUrl($path);
33+
public function getUrl(string $path);
3834
}

src/Symfony/Component/Asset/Packages.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ public function setDefaultPackage(PackageInterface $defaultPackage)
4444
}
4545

4646
/**
47-
* Adds a package.
48-
*
49-
* @param string $name The package name
50-
* @param PackageInterface $package The package
47+
* Adds a package.
5148
*/
52-
public function addPackage($name, PackageInterface $package)
49+
public function addPackage(string $name, PackageInterface $package)
5350
{
5451
$this->packages[$name] = $package;
5552
}
@@ -64,7 +61,7 @@ public function addPackage($name, PackageInterface $package)
6461
* @throws InvalidArgumentException If there is no package by that name
6562
* @throws LogicException If no default package is defined
6663
*/
67-
public function getPackage($name = null)
64+
public function getPackage(string $name = null)
6865
{
6966
if (null === $name) {
7067
if (null === $this->defaultPackage) {
@@ -89,7 +86,7 @@ public function getPackage($name = null)
8986
*
9087
* @return string The current version
9188
*/
92-
public function getVersion($path, $packageName = null)
89+
public function getVersion(string $path, string $packageName = null)
9390
{
9491
return $this->getPackage($packageName)->getVersion($path);
9592
}
@@ -104,7 +101,7 @@ public function getVersion($path, $packageName = null)
104101
*
105102
* @return string A public path which takes into account the base path and URL path
106103
*/
107-
public function getUrl($path, $packageName = null)
104+
public function getUrl(string $path, string $packageName = null)
108105
{
109106
return $this->getPackage($packageName)->getUrl($path);
110107
}

src/Symfony/Component/Asset/PathPackage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(string $basePath, VersionStrategyInterface $versionS
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function getUrl($path)
54+
public function getUrl(string $path)
5555
{
5656
$versionedPath = parent::getUrl($path);
5757

src/Symfony/Component/Asset/UrlPackage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct($baseUrls, VersionStrategyInterface $versionStrategy
6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function getUrl($path)
72+
public function getUrl(string $path)
7373
{
7474
if ($this->isAbsoluteUrl($path)) {
7575
return $path;
@@ -95,11 +95,9 @@ public function getUrl($path)
9595
/**
9696
* Returns the base URL for a path.
9797
*
98-
* @param string $path
99-
*
10098
* @return string The base URL
10199
*/
102-
public function getBaseUrl($path)
100+
public function getBaseUrl(string $path)
103101
{
104102
if (1 === \count($this->baseUrls)) {
105103
return $this->baseUrls[0];
@@ -114,16 +112,14 @@ public function getBaseUrl($path)
114112
* Override this method to change the default distribution strategy.
115113
* This method should always return the same base URL index for a given path.
116114
*
117-
* @param string $path
118-
*
119115
* @return int The base URL index for the given path
120116
*/
121-
protected function chooseBaseUrl($path)
117+
protected function chooseBaseUrl(string $path)
122118
{
123119
return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), \count($this->baseUrls));
124120
}
125121

126-
private function getSslUrls($urls)
122+
private function getSslUrls(array $urls)
127123
{
128124
$sslUrls = [];
129125
foreach ($urls as $url) {

src/Symfony/Component/Asset/VersionStrategy/EmptyVersionStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class EmptyVersionStrategy implements VersionStrategyInterface
2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function getVersion($path)
24+
public function getVersion(string $path)
2525
{
2626
return '';
2727
}
2828

2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function applyVersion($path)
32+
public function applyVersion(string $path)
3333
{
3434
return $path;
3535
}

src/Symfony/Component/Asset/VersionStrategy/JsonManifestVersionStrategy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ public function __construct(string $manifestPath)
4040
* the version is. Instead, this returns the path to the
4141
* versioned file.
4242
*/
43-
public function getVersion($path)
43+
public function getVersion(string $path)
4444
{
4545
return $this->applyVersion($path);
4646
}
4747

48-
public function applyVersion($path)
48+
public function applyVersion(string $path)
4949
{
5050
return $this->getManifestPath($path) ?: $path;
5151
}
5252

53-
private function getManifestPath($path)
53+
private function getManifestPath(string $path)
5454
{
5555
if (null === $this->manifestData) {
5656
if (!file_exists($this->manifestPath)) {

src/Symfony/Component/Asset/VersionStrategy/StaticVersionStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public function __construct(string $version, string $format = null)
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function getVersion($path)
37+
public function getVersion(string $path)
3838
{
3939
return $this->version;
4040
}
4141

4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function applyVersion($path)
45+
public function applyVersion(string $path)
4646
{
4747
$versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
4848

src/Symfony/Component/Asset/VersionStrategy/VersionStrategyInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ interface VersionStrategyInterface
2121
/**
2222
* Returns the asset version for an asset.
2323
*
24-
* @param string $path A path
25-
*
2624
* @return string The version string
2725
*/
28-
public function getVersion($path);
26+
public function getVersion(string $path);
2927

3028
/**
3129
* Applies version to the supplied path.
3230
*
33-
* @param string $path A path
34-
*
3531
* @return string The versionized path
3632
*/
37-
public function applyVersion($path);
33+
public function applyVersion(string $path);
3834
}

0 commit comments

Comments
 (0)