Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f545ba1

Browse files
committed
minor #32774 [TwigBridge] add parameter type declarations where possible (xabbuh)
This PR was merged into the 5.0-dev branch. Discussion ---------- [TwigBridge] add parameter type declarations where possible | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | part of #32179 | License | MIT | Doc PR | Commits ------- b9fa515 add parameter type declarations where possible
2 parents c4a0086 + b9fa515 commit f545ba1

24 files changed

+88
-168
lines changed

src/Symfony/Bridge/Twig/AppVariable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function setRequestStack(RequestStack $requestStack)
3939
$this->requestStack = $requestStack;
4040
}
4141

42-
public function setEnvironment($environment)
42+
public function setEnvironment(string $environment)
4343
{
4444
$this->environment = $environment;
4545
}
4646

47-
public function setDebug($debug)
47+
public function setDebug(bool $debug)
4848
{
49-
$this->debug = (bool) $debug;
49+
$this->debug = $debug;
5050
}
5151

5252
/**

src/Symfony/Bridge/Twig/Extension/AssetExtension.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,19 @@ public function getFunctions()
4646
* If the package used to generate the path is an instance of
4747
* UrlPackage, you will always get a URL and not a path.
4848
*
49-
* @param string $path A public path
50-
* @param string $packageName The name of the asset package to use
51-
*
5249
* @return string The public path of the asset
5350
*/
54-
public function getAssetUrl($path, $packageName = null)
51+
public function getAssetUrl(string $path, string $packageName = null)
5552
{
5653
return $this->packages->getUrl($path, $packageName);
5754
}
5855

5956
/**
6057
* Returns the version of an asset.
6158
*
62-
* @param string $path A public path
63-
* @param string $packageName The name of the asset package to use
64-
*
6559
* @return string The asset version
6660
*/
67-
public function getAssetVersion($path, $packageName = null)
61+
public function getAssetVersion(string $path, string $packageName = null)
6862
{
6963
return $this->packages->getVersion($path, $packageName);
7064
}

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public function getFilters()
5757
];
5858
}
5959

60-
public function abbrClass($class)
60+
public function abbrClass(string $class)
6161
{
6262
$parts = explode('\\', $class);
6363
$short = array_pop($parts);
6464

6565
return sprintf('<abbr title="%s">%s</abbr>', $class, $short);
6666
}
6767

68-
public function abbrMethod($method)
68+
public function abbrMethod(string $method)
6969
{
7070
if (false !== strpos($method, '::')) {
7171
list($class, $method) = explode('::', $method, 2);
@@ -82,11 +82,9 @@ public function abbrMethod($method)
8282
/**
8383
* Formats an array as a string.
8484
*
85-
* @param array $args The argument array
86-
*
8785
* @return string
8886
*/
89-
public function formatArgs($args)
87+
public function formatArgs(array $args)
9088
{
9189
$result = [];
9290
foreach ($args as $key => $item) {
@@ -115,25 +113,19 @@ public function formatArgs($args)
115113
/**
116114
* Formats an array as a string.
117115
*
118-
* @param array $args The argument array
119-
*
120116
* @return string
121117
*/
122-
public function formatArgsAsText($args)
118+
public function formatArgsAsText(array $args)
123119
{
124120
return strip_tags($this->formatArgs($args));
125121
}
126122

127123
/**
128124
* Returns an excerpt of a code file around the given line number.
129125
*
130-
* @param string $file A file path
131-
* @param int $line The selected line number
132-
* @param int $srcContext The number of displayed lines around or -1 for the whole file
133-
*
134126
* @return string An HTML string
135127
*/
136-
public function fileExcerpt($file, $line, $srcContext = 3)
128+
public function fileExcerpt(string $file, int $line, int $srcContext = 3)
137129
{
138130
if (is_file($file) && is_readable($file)) {
139131
// highlight_file could throw warnings
@@ -165,13 +157,9 @@ public function fileExcerpt($file, $line, $srcContext = 3)
165157
/**
166158
* Formats a file path.
167159
*
168-
* @param string $file An absolute file path
169-
* @param int $line The line number
170-
* @param string $text Use this text for the link rather than the file path
171-
*
172160
* @return string
173161
*/
174-
public function formatFile($file, $line, $text = null)
162+
public function formatFile(string $file, int $line, string $text = null)
175163
{
176164
$file = trim($file);
177165

@@ -197,12 +185,9 @@ public function formatFile($file, $line, $text = null)
197185
/**
198186
* Returns the link for a given file/line pair.
199187
*
200-
* @param string $file An absolute file path
201-
* @param int $line The line number
202-
*
203188
* @return string|false A link or false
204189
*/
205-
public function getFileLink($file, $line)
190+
public function getFileLink(string $file, int $line)
206191
{
207192
if ($fmt = $this->fileLinkFormat) {
208193
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
@@ -222,7 +207,7 @@ public function getFileRelative(string $file): ?string
222207
return null;
223208
}
224209

225-
public function formatFileFromText($text)
210+
public function formatFileFromText(string $text)
226211
{
227212
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
228213
return 'in '.$this->formatFile($match[2], $match[3]);
@@ -232,7 +217,7 @@ public function formatFileFromText($text)
232217
/**
233218
* @internal
234219
*/
235-
public function formatLogMessage($message, array $context)
220+
public function formatLogMessage(string $message, array $context)
236221
{
237222
if ($context && false !== strpos($message, '{')) {
238223
$replacements = [];
@@ -258,7 +243,7 @@ public function getName()
258243
return 'code';
259244
}
260245

261-
protected static function fixCodeMarkup($line)
246+
protected static function fixCodeMarkup(string $line)
262247
{
263248
// </span> ending tag from previous line
264249
$opening = strpos($line, '<span');

src/Symfony/Bridge/Twig/Extension/DumpExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getName()
5252
return 'dump';
5353
}
5454

55-
public function dump(Environment $env, $context)
55+
public function dump(Environment $env, array $context)
5656
{
5757
if (!$env->isDebug()) {
5858
return;

src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getFunctions()
3232
];
3333
}
3434

35-
public function createExpression($expression)
35+
public function createExpression(string $expression)
3636
{
3737
return new Expression($expression);
3838
}

src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ public function getFunctions()
4646
*
4747
* This method returns the path unchanged if no request is available.
4848
*
49-
* @param string $path The path
50-
*
5149
* @return string The absolute URL
5250
*
5351
* @see Request::getUriForPath()
5452
*/
55-
public function generateAbsoluteUrl($path)
53+
public function generateAbsoluteUrl(string $path)
5654
{
5755
return $this->urlHelper->getAbsoluteUrl($path);
5856
}
@@ -62,13 +60,11 @@ public function generateAbsoluteUrl($path)
6260
*
6361
* This method returns the path unchanged if no request is available.
6462
*
65-
* @param string $path The path
66-
*
6763
* @return string The relative path
6864
*
6965
* @see Request::getRelativeUriForPath()
7066
*/
71-
public function generateRelativePath($path)
67+
public function generateRelativePath(string $path)
7268
{
7369
return $this->urlHelper->getRelativePath($path);
7470
}

src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getFunctions()
3131
];
3232
}
3333

34-
public static function controller($controller, $attributes = [], $query = [])
34+
public static function controller(string $controller, array $attributes = [], array $query = [])
3535
{
3636
return new ControllerReference($controller, $attributes, $query);
3737
}

src/Symfony/Bridge/Twig/Extension/HttpKernelRuntime.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ public function __construct(FragmentHandler $handler)
3131
/**
3232
* Renders a fragment.
3333
*
34-
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
35-
* @param array $options An array of options
34+
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
3635
*
3736
* @return string The fragment content
3837
*
3938
* @see FragmentHandler::render()
4039
*/
41-
public function renderFragment($uri, $options = [])
40+
public function renderFragment($uri, array $options = [])
4241
{
4342
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
4443
unset($options['strategy']);
@@ -49,15 +48,13 @@ public function renderFragment($uri, $options = [])
4948
/**
5049
* Renders a fragment.
5150
*
52-
* @param string $strategy A strategy name
53-
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
54-
* @param array $options An array of options
51+
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
5552
*
5653
* @return string The fragment content
5754
*
5855
* @see FragmentHandler::render()
5956
*/
60-
public function renderFragmentStrategy($strategy, $uri, $options = [])
57+
public function renderFragmentStrategy(string $strategy, $uri, array $options = [])
6158
{
6259
return $this->handler->render($uri, $strategy, $options);
6360
}

src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getFunctions()
4747
*
4848
* @return string The relative logout URL
4949
*/
50-
public function getLogoutPath($key = null)
50+
public function getLogoutPath(string $key = null)
5151
{
5252
return $this->generator->getLogoutPath($key);
5353
}
@@ -59,7 +59,7 @@ public function getLogoutPath($key = null)
5959
*
6060
* @return string The absolute logout URL
6161
*/
62-
public function getLogoutUrl($key = null)
62+
public function getLogoutUrl(string $key = null)
6363
{
6464
return $this->generator->getLogoutUrl($key);
6565
}

src/Symfony/Bridge/Twig/Extension/RoutingExtension.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,17 @@ public function getFunctions()
4646
}
4747

4848
/**
49-
* @param string $name
50-
* @param array $parameters
51-
* @param bool $relative
52-
*
5349
* @return string
5450
*/
55-
public function getPath($name, $parameters = [], $relative = false)
51+
public function getPath(string $name, array $parameters = [], bool $relative = false)
5652
{
5753
return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH);
5854
}
5955

6056
/**
61-
* @param string $name
62-
* @param array $parameters
63-
* @param bool $schemeRelative
64-
*
6557
* @return string
6658
*/
67-
public function getUrl($name, $parameters = [], $schemeRelative = false)
59+
public function getUrl(string $name, array $parameters = [], bool $schemeRelative = false)
6860
{
6961
return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
7062
}

0 commit comments

Comments
 (0)