mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 20:16:45 +00:00
added type hints
This commit is contained in:
@@ -31,7 +31,7 @@ class EmbedNode extends IncludeNode
|
||||
$this->setAttribute('index', $index);
|
||||
}
|
||||
|
||||
protected function addGetTemplate(Compiler $compiler)
|
||||
protected function addGetTemplate(Compiler $compiler): void
|
||||
{
|
||||
$compiler
|
||||
->write('$this->loadTemplate(')
|
||||
|
||||
@@ -29,10 +29,9 @@ class ArrayExpression extends AbstractExpression
|
||||
}
|
||||
}
|
||||
|
||||
public function getKeyValuePairs()
|
||||
public function getKeyValuePairs(): array
|
||||
{
|
||||
$pairs = [];
|
||||
|
||||
foreach (array_chunk($this->nodes, 2) as $pair) {
|
||||
$pairs[] = [
|
||||
'key' => $pair[0],
|
||||
@@ -43,7 +42,7 @@ class ArrayExpression extends AbstractExpression
|
||||
return $pairs;
|
||||
}
|
||||
|
||||
public function hasElement(AbstractExpression $key)
|
||||
public function hasElement(AbstractExpression $key): bool
|
||||
{
|
||||
foreach ($this->getKeyValuePairs() as $pair) {
|
||||
// we compare the string representation of the keys
|
||||
@@ -56,7 +55,7 @@ class ArrayExpression extends AbstractExpression
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addElement(AbstractExpression $value, AbstractExpression $key = null)
|
||||
public function addElement(AbstractExpression $value, AbstractExpression $key = null): void
|
||||
{
|
||||
if (null === $key) {
|
||||
$key = new ConstantExpression(++$this->index, $value->getTemplateLine());
|
||||
|
||||
@@ -38,5 +38,5 @@ abstract class AbstractBinary extends AbstractExpression
|
||||
;
|
||||
}
|
||||
|
||||
abstract public function operator(Compiler $compiler);
|
||||
abstract public function operator(Compiler $compiler): Compiler;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class AddBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('+');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class AndBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('&&');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class BitwiseAndBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('&');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class BitwiseOrBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('|');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class BitwiseXorBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('^');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class ConcatBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('.');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class DivBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('/');
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class EndsWithBinary extends AbstractBinary
|
||||
;
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class EqualBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('==');
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class FloorDivBinary extends AbstractBinary
|
||||
$compiler->raw(')');
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('/');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class GreaterBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('>');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class GreaterEqualBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('>=');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class InBinary extends AbstractBinary
|
||||
;
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('in');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class LessBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('<');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class LessEqualBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('<=');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class MatchesBinary extends AbstractBinary
|
||||
;
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class ModBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('%');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class MulBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('*');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class NotEqualBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('!=');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class NotInBinary extends AbstractBinary
|
||||
;
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('not in');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class OrBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('||');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use Twig\Compiler;
|
||||
|
||||
class PowerBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('**');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class RangeBinary extends AbstractBinary
|
||||
;
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('..');
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class StartsWithBinary extends AbstractBinary
|
||||
;
|
||||
}
|
||||
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('');
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use Twig\Compiler;
|
||||
|
||||
class SubBinary extends AbstractBinary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
return $compiler->raw('-');
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
}
|
||||
}
|
||||
|
||||
protected function compileArguments(Compiler $compiler, $isArray = false)
|
||||
protected function compileArguments(Compiler $compiler, $isArray = false): void
|
||||
{
|
||||
$compiler->raw($isArray ? '[' : '(');
|
||||
|
||||
@@ -228,7 +228,7 @@ abstract class CallExpression extends AbstractExpression
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
protected function normalizeName($name)
|
||||
protected function normalizeName(string $name): string
|
||||
{
|
||||
return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name));
|
||||
}
|
||||
|
||||
@@ -30,5 +30,5 @@ abstract class AbstractUnary extends AbstractExpression
|
||||
$compiler->subcompile($this->getNode('node'));
|
||||
}
|
||||
|
||||
abstract public function operator(Compiler $compiler);
|
||||
abstract public function operator(Compiler $compiler): Compiler;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ use Twig\Compiler;
|
||||
|
||||
class NegUnary extends AbstractUnary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
$compiler->raw('-');
|
||||
return $compiler->raw('-');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ use Twig\Compiler;
|
||||
|
||||
class NotUnary extends AbstractUnary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
$compiler->raw('!');
|
||||
return $compiler->raw('!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ use Twig\Compiler;
|
||||
|
||||
class PosUnary extends AbstractUnary
|
||||
{
|
||||
public function operator(Compiler $compiler)
|
||||
public function operator(Compiler $compiler): Compiler
|
||||
{
|
||||
$compiler->raw('+');
|
||||
return $compiler->raw('+');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use Twig\Node\BodyNode;
|
||||
use Twig\Node\MacroNode;
|
||||
use Twig\Node\ModuleNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\NodeVisitor\AbstractNodeVisitor;
|
||||
use Twig\NodeVisitor\NodeVisitorInterface;
|
||||
use Twig\Profiler\Node\EnterProfileNode;
|
||||
use Twig\Profiler\Node\LeaveProfileNode;
|
||||
use Twig\Profiler\Profile;
|
||||
@@ -34,12 +34,12 @@ final class ProfilerNodeVisitor implements NodeVisitorInterface
|
||||
$this->extensionName = $extensionName;
|
||||
}
|
||||
|
||||
protected function doEnterNode(Node $node, Environment $env)
|
||||
public function enterNode(Node $node, Environment $env): Node
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
protected function doLeaveNode(Node $node, Environment $env)
|
||||
public function leaveNode(Node $node, Environment $env): ?Node
|
||||
{
|
||||
if ($node instanceof ModuleNode) {
|
||||
$varName = $this->getVarName();
|
||||
@@ -69,7 +69,7 @@ final class ProfilerNodeVisitor implements NodeVisitorInterface
|
||||
return sprintf('__internal_%s', hash('sha256', $this->extensionName));
|
||||
}
|
||||
|
||||
public function getPriority()
|
||||
public function getPriority(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ class ContainerRuntimeLoader implements RuntimeLoaderInterface
|
||||
|
||||
public function load(string $class)
|
||||
{
|
||||
if ($this->container->has($class)) {
|
||||
return $this->container->get($class);
|
||||
}
|
||||
return $this->container->has($class) ? $this->container->get($class) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,12 @@ class FactoryRuntimeLoader implements RuntimeLoaderInterface
|
||||
|
||||
public function load(string $class)
|
||||
{
|
||||
if (isset($this->map[$class])) {
|
||||
$runtimeFactory = $this->map[$class];
|
||||
|
||||
return $runtimeFactory();
|
||||
if (!isset($this->map[$class])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$runtimeFactory = $this->map[$class];
|
||||
|
||||
return $runtimeFactory();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user