diff --git a/extra/html-extra/HtmlExtension.php b/extra/html-extra/HtmlExtension.php
index 8eeee5a58..fd67582f5 100644
--- a/extra/html-extra/HtmlExtension.php
+++ b/extra/html-extra/HtmlExtension.php
@@ -77,7 +77,7 @@ final class HtmlExtension extends AbstractExtension
$repr .= ';'.$key.'='.rawurlencode($value);
}
- if (0 === strpos($mime, 'text/')) {
+ if (str_starts_with($mime, 'text/')) {
$repr .= ','.rawurlencode($data);
} else {
$repr .= ';base64,'.base64_encode($data);
diff --git a/extra/twig-extra-bundle/DependencyInjection/Configuration.php b/extra/twig-extra-bundle/DependencyInjection/Configuration.php
index 1718593b9..fc94eaca3 100644
--- a/extra/twig-extra-bundle/DependencyInjection/Configuration.php
+++ b/extra/twig-extra-bundle/DependencyInjection/Configuration.php
@@ -58,7 +58,7 @@ class Configuration implements ConfigurationInterface
->end()
->enumNode('html_input')
->info('How to handle HTML input.')
- ->values(['strip','allow','escape'])
+ ->values(['strip', 'allow', 'escape'])
->end()
->booleanNode('allow_unsafe_links')
->info('Remove risky link and image URLs by setting this to false.')
@@ -66,7 +66,7 @@ class Configuration implements ConfigurationInterface
->end()
->integerNode('max_nesting_level')
->info('The maximum nesting level for blocks.')
- ->defaultValue(PHP_INT_MAX)
+ ->defaultValue(\PHP_INT_MAX)
->end()
->arrayNode('slug_normalizer')
->info('Array of options for configuring how URL-safe slugs are created.')
diff --git a/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php b/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php
index b17c040a7..ce263ac2c 100644
--- a/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php
+++ b/extra/twig-extra-bundle/Tests/DependencyInjection/TwigExtraExtensionTest.php
@@ -27,12 +27,12 @@ class TwigExtraExtensionTest extends TestCase
]));
$container->registerExtension(new TwigExtraExtension());
$container->loadFromExtension('twig_extra', [
- 'commonmark' => [
+ 'commonmark' => [
'extra_key' => true,
'renderer' => [
'block_separator' => "\n",
'inner_separator' => "\n",
- 'soft_break' => "\n",
+ 'soft_break' => "\n",
],
'commonmark' => [
'enable_em' => true,
@@ -43,7 +43,7 @@ class TwigExtraExtensionTest extends TestCase
],
'html_input' => 'escape',
'allow_unsafe_links' => false,
- 'max_nesting_level' => PHP_INT_MAX,
+ 'max_nesting_level' => \PHP_INT_MAX,
'slug_normalizer' => [
'max_length' => 255,
],
diff --git a/src/Compiler.php b/src/Compiler.php
index ce8b17c98..6f62c0919 100644
--- a/src/Compiler.php
+++ b/src/Compiler.php
@@ -74,7 +74,7 @@ class Compiler
$node->compile($this);
if ($this->didUseEcho) {
- trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, \get_class($node));
+ trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, $node::class);
}
return $this;
@@ -99,7 +99,7 @@ class Compiler
$node->compile($this);
if ($this->didUseEcho) {
- trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, \get_class($node));
+ trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, $node::class);
}
return $this;
diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php
index 60ebcb667..727cf7eba 100644
--- a/src/ExpressionParser.php
+++ b/src/ExpressionParser.php
@@ -258,7 +258,7 @@ class ExpressionParser
$name = null;
if ($namedArguments && (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || (!$definition && $token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':')))) {
if (!$value instanceof ContextVariable) {
- throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
+ throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', $value::class), $token->getLine(), $stream->getSourceContext());
}
$name = $value->getAttribute('name');
diff --git a/src/ExpressionParser/Prefix/LiteralExpressionParser.php b/src/ExpressionParser/Prefix/LiteralExpressionParser.php
index 188b92445..d98c9adf1 100644
--- a/src/ExpressionParser/Prefix/LiteralExpressionParser.php
+++ b/src/ExpressionParser/Prefix/LiteralExpressionParser.php
@@ -20,7 +20,6 @@ use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\Binary\ConcatBinary;
use Twig\Node\Expression\ConstantExpression;
-use Twig\Node\Expression\Unary\SpreadUnary;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Parser;
use Twig\Token;
diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php
index 039a36f43..f44b6ad6d 100644
--- a/src/Extension/CoreExtension.php
+++ b/src/Extension/CoreExtension.php
@@ -542,7 +542,6 @@ final class CoreExtension extends AbstractExtension
* Returns a formatted string.
*
* @param string|null $format
- * @param ...$values
*
* @internal
*/
@@ -1001,8 +1000,6 @@ final class CoreExtension extends AbstractExtension
*
* @param array|\Traversable|string|null $item
*
- * @return mixed
- *
* @internal
*/
public static function shuffle(string $charset, $item)
@@ -1437,8 +1434,6 @@ final class CoreExtension extends AbstractExtension
* {# ... #}
* {% endif %}
*
- * @param mixed $value
- *
* @internal
*/
public static function testSequence($value): bool
@@ -1462,8 +1457,6 @@ final class CoreExtension extends AbstractExtension
* {# ... #}
* {% endif %}
*
- * @param mixed $value
- *
* @internal
*/
public static function testMapping($value): bool
@@ -1613,10 +1606,10 @@ final class CoreExtension extends AbstractExtension
{
if (null !== $object) {
if ('class' === $constant) {
- return $checkDefined ? true : \get_class($object);
+ return $checkDefined ? true : $object::class;
}
- $constant = \get_class($object).'::'.$constant;
+ $constant = $object::class.'::'.$constant;
}
if (!\defined($constant)) {
@@ -1720,9 +1713,9 @@ final class CoreExtension extends AbstractExtension
}
if ($object instanceof \ArrayAccess) {
- $message = \sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object));
+ $message = \sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, $object::class);
} elseif (\is_object($object)) {
- $message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object));
+ $message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, $object::class);
} elseif (\is_array($object)) {
if (!$object) {
$message = \sprintf('Key "%s" does not exist as the sequence/mapping is empty.', $arrayItem);
@@ -1818,7 +1811,7 @@ final class CoreExtension extends AbstractExtension
static $cache = [];
- $class = \get_class($object);
+ $class = $object::class;
// object method
// precedence: getXxx() > isXxx() > hasXxx()
diff --git a/src/Extension/SandboxExtension.php b/src/Extension/SandboxExtension.php
index a9681c8d6..5d0f64443 100644
--- a/src/Extension/SandboxExtension.php
+++ b/src/Extension/SandboxExtension.php
@@ -118,10 +118,6 @@ final class SandboxExtension extends AbstractExtension
}
/**
- * @param mixed $obj
- *
- * @return mixed
- *
* @throws SecurityNotAllowedMethodError
*/
public function ensureToStringAllowed($obj, int $lineno = -1, ?Source $source = null)
diff --git a/src/ExtensionSet.php b/src/ExtensionSet.php
index 5afa729f9..14b1d3e29 100644
--- a/src/ExtensionSet.php
+++ b/src/ExtensionSet.php
@@ -142,7 +142,7 @@ final class ExtensionSet
public function addExtension(ExtensionInterface $extension): void
{
- $class = \get_class($extension);
+ $class = $extension::class;
if ($this->initialized) {
throw new \LogicException(\sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class));
@@ -484,11 +484,11 @@ final class ExtensionSet
$operators = $extension->getOperators();
if (!\is_array($operators)) {
- throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), get_debug_type($operators).(\is_resource($operators) ? '' : '#'.$operators)));
+ throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array with operators, got "%s".', $extension::class, get_debug_type($operators).(\is_resource($operators) ? '' : '#'.$operators)));
}
if (2 !== \count($operators)) {
- throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators)));
+ throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', $extension::class, \count($operators)));
}
$expressionParsers = [];
diff --git a/src/Loader/ChainLoader.php b/src/Loader/ChainLoader.php
index 6e4f9511c..0859dcd2f 100644
--- a/src/Loader/ChainLoader.php
+++ b/src/Loader/ChainLoader.php
@@ -104,7 +104,7 @@ final class ChainLoader implements LoaderInterface
try {
return $loader->getCacheKey($name);
} catch (LoaderError $e) {
- $exceptions[] = \get_class($loader).': '.$e->getMessage();
+ $exceptions[] = $loader::class.': '.$e->getMessage();
}
}
@@ -123,7 +123,7 @@ final class ChainLoader implements LoaderInterface
try {
return $loader->isFresh($name, $time);
} catch (LoaderError $e) {
- $exceptions[] = \get_class($loader).': '.$e->getMessage();
+ $exceptions[] = $loader::class.': '.$e->getMessage();
}
}
diff --git a/src/Markup.php b/src/Markup.php
index a933b69d3..c8efddb6f 100644
--- a/src/Markup.php
+++ b/src/Markup.php
@@ -46,9 +46,6 @@ class Markup implements \Countable, \JsonSerializable, \Stringable
return mb_strlen($this->content, $this->charset);
}
- /**
- * @return mixed
- */
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
diff --git a/src/Node/Expression/Binary/AbstractBinary.php b/src/Node/Expression/Binary/AbstractBinary.php
index bd6cc6c02..b4bf6662e 100644
--- a/src/Node/Expression/Binary/AbstractBinary.php
+++ b/src/Node/Expression/Binary/AbstractBinary.php
@@ -25,10 +25,10 @@ abstract class AbstractBinary extends AbstractExpression implements BinaryInterf
public function __construct(Node $left, Node $right, int $lineno)
{
if (!$left instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($left));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $left::class);
}
if (!$right instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($right));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $right::class);
}
parent::__construct(['left' => $left, 'right' => $right], [], $lineno);
diff --git a/src/Node/Expression/BlockReferenceExpression.php b/src/Node/Expression/BlockReferenceExpression.php
index a5a3cee3f..508ca2d83 100644
--- a/src/Node/Expression/BlockReferenceExpression.php
+++ b/src/Node/Expression/BlockReferenceExpression.php
@@ -28,7 +28,7 @@ class BlockReferenceExpression extends AbstractExpression
public function __construct(Node $name, ?Node $template, int $lineno)
{
if (!$name instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($name));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $name::class);
}
$nodes = ['name' => $name];
diff --git a/src/Node/Expression/Filter/DefaultFilter.php b/src/Node/Expression/Filter/DefaultFilter.php
index bccd7f0a4..04ef06cc4 100644
--- a/src/Node/Expression/Filter/DefaultFilter.php
+++ b/src/Node/Expression/Filter/DefaultFilter.php
@@ -42,7 +42,7 @@ class DefaultFilter extends FilterExpression
public function __construct(Node $node, TwigFilter|ConstantExpression $filter, Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}
if ($filter instanceof TwigFilter) {
diff --git a/src/Node/Expression/Filter/RawFilter.php b/src/Node/Expression/Filter/RawFilter.php
index 0a49e7c4f..707e8ec24 100644
--- a/src/Node/Expression/Filter/RawFilter.php
+++ b/src/Node/Expression/Filter/RawFilter.php
@@ -32,7 +32,7 @@ class RawFilter extends FilterExpression
public function __construct(Node $node, TwigFilter|ConstantExpression|null $filter = null, ?Node $arguments = null, int $lineno = 0)
{
if (!$node instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}
parent::__construct($node, $filter ?: new TwigFilter('raw', null, ['is_safe' => ['all']]), $arguments ?: new EmptyNode(), $lineno ?: $node->getTemplateLine());
diff --git a/src/Node/Expression/FilterExpression.php b/src/Node/Expression/FilterExpression.php
index 6e0c486ab..a66b0266d 100644
--- a/src/Node/Expression/FilterExpression.php
+++ b/src/Node/Expression/FilterExpression.php
@@ -27,7 +27,7 @@ class FilterExpression extends CallExpression
public function __construct(Node $node, TwigFilter|ConstantExpression $filter, Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}
if ($filter instanceof TwigFilter) {
diff --git a/src/Node/Expression/NullCoalesceExpression.php b/src/Node/Expression/NullCoalesceExpression.php
index 74ddaf791..f397f71f0 100644
--- a/src/Node/Expression/NullCoalesceExpression.php
+++ b/src/Node/Expression/NullCoalesceExpression.php
@@ -33,10 +33,10 @@ class NullCoalesceExpression extends ConditionalExpression
trigger_deprecation('twig/twig', '3.17', \sprintf('"%s" is deprecated; use "%s" instead.', __CLASS__, NullCoalesceBinary::class));
if (!$left instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($left));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $left::class);
}
if (!$right instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($right));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $right::class);
}
$test = new DefinedTest(clone $left, new TwigTest('defined'), new EmptyNode(), $left->getTemplateLine());
diff --git a/src/Node/Expression/Test/DefinedTest.php b/src/Node/Expression/Test/DefinedTest.php
index 5e32c38bb..9612892be 100644
--- a/src/Node/Expression/Test/DefinedTest.php
+++ b/src/Node/Expression/Test/DefinedTest.php
@@ -46,7 +46,7 @@ class DefinedTest extends TestExpression
public function __construct(Node $node, TwigTest|string $name, ?Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}
if ($node instanceof ContextVariable) {
diff --git a/src/Node/Expression/TestExpression.php b/src/Node/Expression/TestExpression.php
index 7b9a54138..27e1526a1 100644
--- a/src/Node/Expression/TestExpression.php
+++ b/src/Node/Expression/TestExpression.php
@@ -26,7 +26,7 @@ class TestExpression extends CallExpression
public function __construct(Node $node, string|TwigTest $test, ?Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}
$nodes = ['node' => $node];
diff --git a/src/Node/Expression/Unary/AbstractUnary.php b/src/Node/Expression/Unary/AbstractUnary.php
index b00027d1a..09f3d0984 100644
--- a/src/Node/Expression/Unary/AbstractUnary.php
+++ b/src/Node/Expression/Unary/AbstractUnary.php
@@ -24,7 +24,7 @@ abstract class AbstractUnary extends AbstractExpression implements UnaryInterfac
public function __construct(Node $node, int $lineno)
{
if (!$node instanceof AbstractExpression) {
- trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance argument to "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
+ trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance argument to "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}
parent::__construct(['node' => $node], ['with_parentheses' => false], $lineno);
diff --git a/src/Node/Node.php b/src/Node/Node.php
index 389119b55..dcf912c21 100644
--- a/src/Node/Node.php
+++ b/src/Node/Node.php
@@ -149,9 +149,6 @@ class Node implements \Countable, \IteratorAggregate
return \array_key_exists($name, $this->attributes);
}
- /**
- * @return mixed
- */
public function getAttribute(string $name)
{
if (!\array_key_exists($name, $this->attributes)) {
diff --git a/src/Node/SetNode.php b/src/Node/SetNode.php
index 4d97adb22..7b063b00b 100644
--- a/src/Node/SetNode.php
+++ b/src/Node/SetNode.php
@@ -34,7 +34,7 @@ class SetNode extends Node implements NodeCaptureInterface
if ($capture) {
$safe = true;
// Node::class === get_class($values) should be removed in Twig 4.0
- if (($values instanceof Nodes || Node::class === \get_class($values)) && !\count($values)) {
+ if (($values instanceof Nodes || Node::class === $values::class) && !\count($values)) {
$values = new ConstantExpression('', $values->getTemplateLine());
$capture = false;
} elseif ($values instanceof TextNode) {
diff --git a/src/NodeVisitor/YieldNotReadyNodeVisitor.php b/src/NodeVisitor/YieldNotReadyNodeVisitor.php
index 3c9786275..4d6cf60a0 100644
--- a/src/NodeVisitor/YieldNotReadyNodeVisitor.php
+++ b/src/NodeVisitor/YieldNotReadyNodeVisitor.php
@@ -30,7 +30,7 @@ final class YieldNotReadyNodeVisitor implements NodeVisitorInterface
public function enterNode(Node $node, Environment $env): Node
{
- $class = \get_class($node);
+ $class = $node::class;
if ($node instanceof AbstractExpression || isset($this->yieldReadyNodes[$class])) {
return $node;
diff --git a/src/Parser.php b/src/Parser.php
index 63ecccbe4..b40a92317 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -549,7 +549,7 @@ class Parser
// here, $nested means "being at the root level of a child template"
// we need to discard the wrapping "Node" for the "body" node
// Node::class !== \get_class($node) should be removed in Twig 4.0
- $nested = $nested || (Node::class !== \get_class($node) && !$node instanceof Nodes);
+ $nested = $nested || (Node::class !== $node::class && !$node instanceof Nodes);
foreach ($node as $k => $n) {
if (null !== $n && null === $this->filterBodyNodes($n, $nested)) {
$node->removeNode($k);
diff --git a/src/Runtime/EscaperRuntime.php b/src/Runtime/EscaperRuntime.php
index 719a5696a..ff7913f38 100644
--- a/src/Runtime/EscaperRuntime.php
+++ b/src/Runtime/EscaperRuntime.php
@@ -106,7 +106,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface
if (!\is_string($string)) {
if ($string instanceof \Stringable) {
if ($autoescape) {
- $c = \get_class($string);
+ $c = $string::class;
if (!isset($this->safeClasses[$c])) {
$this->safeClasses[$c] = [];
foreach (class_parents($string) + class_implements($string) as $class) {
diff --git a/src/Sandbox/SecurityPolicy.php b/src/Sandbox/SecurityPolicy.php
index b0d054260..8dd68ae99 100644
--- a/src/Sandbox/SecurityPolicy.php
+++ b/src/Sandbox/SecurityPolicy.php
@@ -107,7 +107,7 @@ final class SecurityPolicy implements SecurityPolicyInterface
}
if (!$allowed) {
- $class = \get_class($obj);
+ $class = $obj::class;
throw new SecurityNotAllowedMethodError(\sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
}
}
@@ -123,7 +123,7 @@ final class SecurityPolicy implements SecurityPolicyInterface
}
if (!$allowed) {
- $class = \get_class($obj);
+ $class = $obj::class;
throw new SecurityNotAllowedPropertyError(\sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
}
}
diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php
index f4a5dc7e5..f3f7adcee 100644
--- a/src/Test/IntegrationTestCase.php
+++ b/src/Test/IntegrationTestCase.php
@@ -275,14 +275,14 @@ abstract class IntegrationTestCase extends TestCase
} catch (\Exception $e) {
if (false !== $exception) {
$message = $e->getMessage();
- $this->assertSame(trim($exception), trim(\sprintf('%s: %s', \get_class($e), $message)));
+ $this->assertSame(trim($exception), trim(\sprintf('%s: %s', $e::class, $message)));
$last = substr($message, \strlen($message) - 1);
$this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.');
return;
}
- throw new Error(\sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
+ throw new Error(\sprintf('%s: %s', $e::class, $e->getMessage()), -1, null, $e);
} finally {
restore_error_handler();
}
@@ -293,14 +293,14 @@ abstract class IntegrationTestCase extends TestCase
$output = trim($template->render(eval($match[1].';')), "\n ");
} catch (\Exception $e) {
if (false !== $exception) {
- $this->assertStringMatchesFormat(trim($exception), trim(\sprintf('%s: %s', \get_class($e), $e->getMessage())));
+ $this->assertStringMatchesFormat(trim($exception), trim(\sprintf('%s: %s', $e::class, $e->getMessage())));
return;
}
- $e = new Error(\sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e);
+ $e = new Error(\sprintf('%s: %s', $e::class, $e->getMessage()), -1, null, $e);
- $output = trim(\sprintf('%s: %s', \get_class($e), $e->getMessage()));
+ $output = trim(\sprintf('%s: %s', $e::class, $e->getMessage()));
}
if (false !== $exception) {
diff --git a/src/Token.php b/src/Token.php
index 73fd02e1d..7059619f8 100644
--- a/src/Token.php
+++ b/src/Token.php
@@ -134,9 +134,6 @@ final class Token
return $this->type;
}
- /**
- * @return mixed
- */
public function getValue()
{
return $this->value;
diff --git a/src/Util/TemplateDirIterator.php b/src/Util/TemplateDirIterator.php
index 3bef14bee..8125341bd 100644
--- a/src/Util/TemplateDirIterator.php
+++ b/src/Util/TemplateDirIterator.php
@@ -16,18 +16,12 @@ namespace Twig\Util;
*/
class TemplateDirIterator extends \IteratorIterator
{
- /**
- * @return mixed
- */
#[\ReturnTypeWillChange]
public function current()
{
return file_get_contents(parent::current());
}
- /**
- * @return mixed
- */
#[\ReturnTypeWillChange]
public function key()
{
diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php
index 19f2fce46..fb9090c73 100644
--- a/tests/EnvironmentTest.php
+++ b/tests/EnvironmentTest.php
@@ -332,7 +332,7 @@ class EnvironmentTest extends TestCase
$twig = new Environment($loader);
$twig->addExtension($extension);
- $this->assertInstanceOf(ExtensionInterface::class, $twig->getExtension(\get_class($extension)));
+ $this->assertInstanceOf(ExtensionInterface::class, $twig->getExtension($extension::class));
$this->assertTrue($twig->isTemplateFresh('page', time()));
}
diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php
index 273324d10..91671880e 100644
--- a/tests/IntegrationTest.php
+++ b/tests/IntegrationTest.php
@@ -307,7 +307,7 @@ class TwigTestExtension extends AbstractExtension
public function is_multi_word($value)
{
- return false !== strpos($value, ' ');
+ return str_contains($value, ' ');
}
public function __call($method, $arguments)
diff --git a/tests/NodeVisitor/OptimizerTest.php b/tests/NodeVisitor/OptimizerTest.php
index 5964b7b48..859f4175c 100644
--- a/tests/NodeVisitor/OptimizerTest.php
+++ b/tests/NodeVisitor/OptimizerTest.php
@@ -70,7 +70,7 @@ class OptimizerTest extends TestCase
public function checkForVarConfiguration(Node $node, $target)
{
foreach ($node as $n) {
- if (NameExpression::class === \get_class($n) && $target === $n->getAttribute('name')) {
+ if (NameExpression::class === $n::class && $target === $n->getAttribute('name')) {
$this->assertTrue($n->getAttribute('always_defined'));
} else {
$this->checkForVarConfiguration($n, $target);