mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-25 11:56:26 +00:00
changed false to null to allow for type hinting
This commit is contained in:
+3
-27
@@ -781,18 +781,9 @@ class Environment
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a filter by name.
|
||||
*
|
||||
* Subclasses may override this method and load filters differently;
|
||||
* so no list of filters is available.
|
||||
*
|
||||
* @param string $name The filter name
|
||||
*
|
||||
* @return TwigFilter|false
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getFilter($name)
|
||||
public function getFilter(string $name): ?TwigFilter
|
||||
{
|
||||
return $this->extensionSet->getFilter($name);
|
||||
}
|
||||
@@ -836,15 +827,9 @@ class Environment
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a test by name.
|
||||
*
|
||||
* @param string $name The test name
|
||||
*
|
||||
* @return TwigTest|false
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getTest($name)
|
||||
public function getTest(string $name): ?TwigTest
|
||||
{
|
||||
return $this->extensionSet->getTest($name);
|
||||
}
|
||||
@@ -855,18 +840,9 @@ class Environment
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a function by name.
|
||||
*
|
||||
* Subclasses may override this method and load functions differently;
|
||||
* so no list of functions is available.
|
||||
*
|
||||
* @param string $name function name
|
||||
*
|
||||
* @return TwigFunction|false
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getFunction($name)
|
||||
public function getFunction(string $name): ?TwigFunction
|
||||
{
|
||||
return $this->extensionSet->getFunction($name);
|
||||
}
|
||||
|
||||
@@ -668,7 +668,7 @@ class ExpressionParser
|
||||
|
||||
private function getFunctionNodeClass(string $name, int $line): string
|
||||
{
|
||||
if (false === $function = $this->env->getFunction($name)) {
|
||||
if (!$function = $this->env->getFunction($name)) {
|
||||
$e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext());
|
||||
$e->addSuggestions($name, array_keys($this->env->getFunctions()));
|
||||
|
||||
@@ -694,7 +694,7 @@ class ExpressionParser
|
||||
|
||||
private function getFilterNodeClass(string $name, int $line): string
|
||||
{
|
||||
if (false === $filter = $this->env->getFilter($name)) {
|
||||
if (!$filter = $this->env->getFilter($name)) {
|
||||
$e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext());
|
||||
$e->addSuggestions($name, array_keys($this->env->getFilters()));
|
||||
|
||||
|
||||
+6
-15
@@ -175,10 +175,7 @@ final class ExtensionSet
|
||||
return $this->functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TwigFunction|false
|
||||
*/
|
||||
public function getFunction(string $name)
|
||||
public function getFunction(string $name): ?TwigFunction
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initExtensions();
|
||||
@@ -205,7 +202,7 @@ final class ExtensionSet
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function registerUndefinedFunctionCallback(callable $callable)
|
||||
@@ -234,10 +231,7 @@ final class ExtensionSet
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TwigFilter|false
|
||||
*/
|
||||
public function getFilter(string $name)
|
||||
public function getFilter(string $name): ?TwigFilter
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initExtensions();
|
||||
@@ -264,7 +258,7 @@ final class ExtensionSet
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function registerUndefinedFilterCallback(callable $callable)
|
||||
@@ -362,10 +356,7 @@ final class ExtensionSet
|
||||
return $this->tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TwigTest|false
|
||||
*/
|
||||
public function getTest(string $name)
|
||||
public function getTest(string $name): ?TwigTest
|
||||
{
|
||||
if (!$this->initialized) {
|
||||
$this->initExtensions();
|
||||
@@ -388,7 +379,7 @@ final class ExtensionSet
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getUnaryOperators(): array
|
||||
|
||||
@@ -95,7 +95,7 @@ final class SafeAnalysisNodeVisitor extends AbstractNodeVisitor
|
||||
// filter expression is safe when the filter is safe
|
||||
$name = $node->getNode('filter')->getAttribute('value');
|
||||
$args = $node->getNode('arguments');
|
||||
if (false !== $filter = $env->getFilter($name)) {
|
||||
if ($filter = $env->getFilter($name)) {
|
||||
$safe = $filter->getSafe($args);
|
||||
if (null === $safe) {
|
||||
$safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
|
||||
@@ -108,8 +108,7 @@ final class SafeAnalysisNodeVisitor extends AbstractNodeVisitor
|
||||
// function expression is safe when the function is safe
|
||||
$name = $node->getAttribute('name');
|
||||
$args = $node->getNode('arguments');
|
||||
$function = $env->getFunction($name);
|
||||
if (false !== $function) {
|
||||
if ($function = $env->getFunction($name)) {
|
||||
$this->setSafe($node, $function->getSafe($args));
|
||||
} else {
|
||||
$this->setSafe($node, []);
|
||||
|
||||
Reference in New Issue
Block a user