Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[TwigBridge] add parameter type declarations where possible #32774

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
Jul 28, 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 6 src/Symfony/Bridge/Twig/AppVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function setRequestStack(RequestStack $requestStack)
$this->requestStack = $requestStack;
}

public function setEnvironment($environment)
public function setEnvironment(string $environment)
{
$this->environment = $environment;
}

public function setDebug($debug)
public function setDebug(bool $debug)
{
$this->debug = (bool) $debug;
$this->debug = $debug;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function getFilesInfo(array $filenames)
return $filesInfo;
}

protected function findFiles($filename)
protected function findFiles(string $filename)
{
if (is_file($filename)) {
return [$filename];
Expand Down
10 changes: 2 additions & 8 deletions 10 src/Symfony/Bridge/Twig/Extension/AssetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,19 @@ public function getFunctions()
* If the package used to generate the path is an instance of
* UrlPackage, you will always get a URL and not a path.
*
* @param string $path A public path
* @param string $packageName The name of the asset package to use
*
* @return string The public path of the asset
*/
public function getAssetUrl($path, $packageName = null)
public function getAssetUrl(string $path, string $packageName = null)
{
return $this->packages->getUrl($path, $packageName);
}

/**
* Returns the version of an asset.
*
* @param string $path A public path
* @param string $packageName The name of the asset package to use
*
* @return string The asset version
*/
public function getAssetVersion($path, $packageName = null)
public function getAssetVersion(string $path, string $packageName = null)
{
return $this->packages->getVersion($path, $packageName);
}
Expand Down
35 changes: 10 additions & 25 deletions 35 src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public function getFilters()
];
}

public function abbrClass($class)
public function abbrClass(string $class)
{
$parts = explode('\\', $class);
$short = array_pop($parts);

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

public function abbrMethod($method)
public function abbrMethod(string $method)
{
if (false !== strpos($method, '::')) {
list($class, $method) = explode('::', $method, 2);
Expand All @@ -82,11 +82,9 @@ public function abbrMethod($method)
/**
* Formats an array as a string.
*
* @param array $args The argument array
*
* @return string
*/
public function formatArgs($args)
public function formatArgs(array $args)
{
$result = [];
foreach ($args as $key => $item) {
Expand Down Expand Up @@ -115,25 +113,19 @@ public function formatArgs($args)
/**
* Formats an array as a string.
*
* @param array $args The argument array
*
* @return string
*/
public function formatArgsAsText($args)
public function formatArgsAsText(array $args)
{
return strip_tags($this->formatArgs($args));
}

/**
* Returns an excerpt of a code file around the given line number.
*
* @param string $file A file path
* @param int $line The selected line number
* @param int $srcContext The number of displayed lines around or -1 for the whole file
*
* @return string An HTML string
*/
public function fileExcerpt($file, $line, $srcContext = 3)
public function fileExcerpt(string $file, int $line, int $srcContext = 3)
{
if (is_file($file) && is_readable($file)) {
// highlight_file could throw warnings
Expand Down Expand Up @@ -165,13 +157,9 @@ public function fileExcerpt($file, $line, $srcContext = 3)
/**
* Formats a file path.
*
* @param string $file An absolute file path
* @param int $line The line number
* @param string $text Use this text for the link rather than the file path
*
* @return string
*/
public function formatFile($file, $line, $text = null)
public function formatFile(string $file, int $line, string $text = null)
{
$file = trim($file);

Expand All @@ -197,12 +185,9 @@ public function formatFile($file, $line, $text = null)
/**
* Returns the link for a given file/line pair.
*
* @param string $file An absolute file path
* @param int $line The line number
*
* @return string|false A link or false
*/
public function getFileLink($file, $line)
public function getFileLink(string $file, int $line)
{
if ($fmt = $this->fileLinkFormat) {
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
Expand All @@ -222,7 +207,7 @@ public function getFileRelative(string $file): ?string
return null;
}

public function formatFileFromText($text)
public function formatFileFromText(string $text)
{
return preg_replace_callback('/in ("|&quot;)?(.+?)\1(?: +(?:on|at))? +line (\d+)/s', function ($match) {
return 'in '.$this->formatFile($match[2], $match[3]);
Expand All @@ -232,7 +217,7 @@ public function formatFileFromText($text)
/**
* @internal
*/
public function formatLogMessage($message, array $context)
public function formatLogMessage(string $message, array $context)
{
if ($context && false !== strpos($message, '{')) {
$replacements = [];
Expand All @@ -258,7 +243,7 @@ public function getName()
return 'code';
}

protected static function fixCodeMarkup($line)
protected static function fixCodeMarkup(string $line)
{
// </span> ending tag from previous line
$opening = strpos($line, '<span');
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Twig/Extension/DumpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getName()
return 'dump';
}

public function dump(Environment $env, $context)
public function dump(Environment $env, array $context)
{
if (!$env->isDebug()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getFunctions()
];
}

public function createExpression($expression)
public function createExpression(string $expression)
{
return new Expression($expression);
}
Expand Down
8 changes: 2 additions & 6 deletions 8 src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ public function getFunctions()
*
* This method returns the path unchanged if no request is available.
*
* @param string $path The path
*
* @return string The absolute URL
*
* @see Request::getUriForPath()
*/
public function generateAbsoluteUrl($path)
public function generateAbsoluteUrl(string $path)
{
return $this->urlHelper->getAbsoluteUrl($path);
}
Expand All @@ -62,13 +60,11 @@ public function generateAbsoluteUrl($path)
*
* This method returns the path unchanged if no request is available.
*
* @param string $path The path
*
* @return string The relative path
*
* @see Request::getRelativeUriForPath()
*/
public function generateRelativePath($path)
public function generateRelativePath(string $path)
{
return $this->urlHelper->getRelativePath($path);
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Twig/Extension/HttpKernelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getFunctions()
];
}

public static function controller($controller, $attributes = [], $query = [])
public static function controller(string $controller, array $attributes = [], array $query = [])
{
return new ControllerReference($controller, $attributes, $query);
}
Expand Down
11 changes: 4 additions & 7 deletions 11 src/Symfony/Bridge/Twig/Extension/HttpKernelRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public function __construct(FragmentHandler $handler)
/**
* Renders a fragment.
*
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param array $options An array of options
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
*
* @return string The fragment content
*
* @see FragmentHandler::render()
*/
public function renderFragment($uri, $options = [])
public function renderFragment($uri, array $options = [])
{
$strategy = isset($options['strategy']) ? $options['strategy'] : 'inline';
unset($options['strategy']);
Expand All @@ -49,15 +48,13 @@ public function renderFragment($uri, $options = [])
/**
* Renders a fragment.
*
* @param string $strategy A strategy name
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param array $options An array of options
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
*
* @return string The fragment content
*
* @see FragmentHandler::render()
*/
public function renderFragmentStrategy($strategy, $uri, $options = [])
public function renderFragmentStrategy(string $strategy, $uri, array $options = [])
{
return $this->handler->render($uri, $strategy, $options);
}
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Bridge/Twig/Extension/LogoutUrlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getFunctions()
*
* @return string The relative logout URL
*/
public function getLogoutPath($key = null)
public function getLogoutPath(string $key = null)
{
return $this->generator->getLogoutPath($key);
}
Expand All @@ -59,7 +59,7 @@ public function getLogoutPath($key = null)
*
* @return string The absolute logout URL
*/
public function getLogoutUrl($key = null)
public function getLogoutUrl(string $key = null)
{
return $this->generator->getLogoutUrl($key);
}
Expand Down
12 changes: 2 additions & 10 deletions 12 src/Symfony/Bridge/Twig/Extension/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,17 @@ public function getFunctions()
}

/**
* @param string $name
* @param array $parameters
* @param bool $relative
*
* @return string
*/
public function getPath($name, $parameters = [], $relative = false)
public function getPath(string $name, array $parameters = [], bool $relative = false)
{
return $this->generator->generate($name, $parameters, $relative ? UrlGeneratorInterface::RELATIVE_PATH : UrlGeneratorInterface::ABSOLUTE_PATH);
}

/**
* @param string $name
* @param array $parameters
* @param bool $schemeRelative
*
* @return string
*/
public function getUrl($name, $parameters = [], $schemeRelative = false)
public function getUrl(string $name, array $parameters = [], bool $schemeRelative = false)
{
return $this->generator->generate($name, $parameters, $schemeRelative ? UrlGeneratorInterface::NETWORK_PATH : UrlGeneratorInterface::ABSOLUTE_URL);
}
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Twig/Extension/SecurityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(AuthorizationCheckerInterface $securityChecker = nul
$this->securityChecker = $securityChecker;
}

public function isGranted($role, $object = null, $field = null)
public function isGranted($role, object $object = null, string $field = null)
{
if (null === $this->securityChecker) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getTranslationNodeVisitor(): TranslationNodeVisitor
return $this->translationNodeVisitor ?: $this->translationNodeVisitor = new TranslationNodeVisitor();
}

public function trans($message, array $arguments = [], $domain = null, $locale = null, $count = null): string
public function trans(string $message, array $arguments = [], string $domain = null, string $locale = null, int $count = null): string
{
if (null !== $count) {
$arguments['%count%'] = $count;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.