Use CPP in full code base

This commit is contained in:
andreybolonin1989@gmail.com
2024-08-24 11:31:27 +03:00
committed by Fabien Potencier
parent 75d888f2e0
commit 28923f4269
23 changed files with 74 additions and 119 deletions
+3 -5
View File
@@ -21,14 +21,12 @@ namespace Twig\Cache;
*/
final class ChainCache implements CacheInterface
{
private $caches;
/**
* @param iterable<CacheInterface> $caches The ordered list of caches used to store and fetch cached items
*/
public function __construct(iterable $caches)
{
$this->caches = $caches;
public function __construct(
private iterable $caches,
) {
}
public function generateKey(string $name, string $className): string
+3 -4
View File
@@ -22,7 +22,6 @@ class Compiler
private $lastLine;
private $source;
private $indentation;
private $env;
private $debugInfo = [];
private $sourceOffset;
private $sourceLine;
@@ -30,9 +29,9 @@ class Compiler
private $didUseEcho = false;
private $didUseEchoStack = [];
public function __construct(Environment $env)
{
$this->env = $env;
public function __construct(
private Environment $env,
) {
}
public function getEnvironment(): Environment
+1 -1
View File
@@ -107,7 +107,7 @@ class Environment
* false (default): allows templates to use a mix of "yield" and "echo" calls to allow for a progressive migration
* Switch to "true" when possible as this will be the only supported mode in Twig 4.0
*/
public function __construct(LoaderInterface $loader, $options = [])
public function __construct(LoaderInterface $loader, array $options = [])
{
$this->setLoader($loader);
+4 -6
View File
@@ -47,18 +47,16 @@ class ExpressionParser
public const OPERATOR_LEFT = 1;
public const OPERATOR_RIGHT = 2;
private $parser;
private $env;
/** @var array<string, array{precedence: int, class: class-string<AbstractUnary>}> */
private $unaryOperators;
/** @var array<string, array{precedence: int, class: class-string<AbstractBinary>, associativity: self::OPERATOR_*}> */
private $binaryOperators;
private $readyNodes = [];
public function __construct(Parser $parser, Environment $env)
{
$this->parser = $parser;
$this->env = $env;
public function __construct(
private Parser $parser,
private Environment $env,
) {
$this->unaryOperators = $env->getUnaryOperators();
$this->binaryOperators = $env->getBinaryOperators();
}
+3 -5
View File
@@ -15,11 +15,9 @@ use Twig\NodeVisitor\OptimizerNodeVisitor;
final class OptimizerExtension extends AbstractExtension
{
private $optimizers;
public function __construct(int $optimizers = -1)
{
$this->optimizers = $optimizers;
public function __construct(
private int $optimizers = -1,
) {
}
public function getNodeVisitors(): array
+3 -5
View File
@@ -18,11 +18,9 @@ use Twig\NodeVisitor\YieldNotReadyNodeVisitor;
*/
final class YieldNotReadyExtension extends AbstractExtension
{
private $useYield;
public function __construct(bool $useYield)
{
$this->useYield = $useYield;
public function __construct(
private bool $useYield,
) {
}
public function getNodeVisitors(): array
+3 -5
View File
@@ -28,14 +28,12 @@ use Twig\Source;
*/
final class ArrayLoader implements LoaderInterface
{
private $templates = [];
/**
* @param array $templates An array of templates (keys are the names, and values are the source code)
*/
public function __construct(array $templates = [])
{
$this->templates = $templates;
public function __construct(
private array $templates = [],
) {
}
public function setTemplate(string $name, string $template): void
+3 -8
View File
@@ -21,11 +21,6 @@ use Twig\Source;
*/
final class ChainLoader implements LoaderInterface
{
/**
* @var \Traversable<LoaderInterface>|LoaderInterface[]
*/
private $loaders;
/**
* @var array<string, bool>
*/
@@ -34,9 +29,9 @@ final class ChainLoader implements LoaderInterface
/**
* @param iterable<LoaderInterface> $loaders
*/
public function __construct(iterable $loaders = [])
{
$this->loaders = $loaders;
public function __construct(
private iterable $loaders = [],
) {
}
public function addLoader(LoaderInterface $loader): void
+1 -1
View File
@@ -19,7 +19,7 @@ namespace Twig;
class Markup implements \Countable, \JsonSerializable
{
private $content;
private $charset;
private ?string $charset;
public function __construct($content, $charset)
{
+3 -5
View File
@@ -47,13 +47,13 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
private $loops = [];
private $loopsTargets = [];
private $optimizers;
/**
* @param int $optimizers The optimizer mode
*/
public function __construct(int $optimizers = -1)
{
public function __construct(
private int $optimizers = -1,
) {
if ($optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_TEXT_NODES)) {
throw new \InvalidArgumentException(\sprintf('Optimizer mode "%s" is not valid.', $optimizers));
}
@@ -65,8 +65,6 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
if (-1 !== $optimizers && self::OPTIMIZE_TEXT_NODES === (self::OPTIMIZE_TEXT_NODES & $optimizers)) {
trigger_deprecation('twig/twig', '3.12', 'The "Twig\NodeVisitor\OptimizerNodeVisitor::OPTIMIZE_TEXT_NODES" option is deprecated and does nothing.');
}
$this->optimizers = $optimizers;
}
public function enterNode(Node $node, Environment $env): Node
+3 -4
View File
@@ -21,12 +21,11 @@ use Twig\Node\Node;
*/
final class YieldNotReadyNodeVisitor implements NodeVisitorInterface
{
private $useYield;
private $yieldReadyNodes = [];
public function __construct(bool $useYield)
{
$this->useYield = $useYield;
public function __construct(
private bool $useYield,
) {
}
public function enterNode(Node $node, Environment $env): Node
+3 -4
View File
@@ -40,15 +40,14 @@ class Parser
private $blocks;
private $blockStack;
private $macros;
private $env;
private $importedSymbols;
private $traits;
private $embeddedTemplates = [];
private $varNameSalt = 0;
public function __construct(Environment $env)
{
$this->env = $env;
public function __construct(
private Environment $env,
) {
}
public function getVarName(): string
@@ -27,12 +27,11 @@ use Twig\Profiler\Profile;
*/
final class ProfilerNodeVisitor implements NodeVisitorInterface
{
private $extensionName;
private $varName;
public function __construct(string $extensionName)
{
$this->extensionName = $extensionName;
public function __construct(
private string $extensionName,
) {
$this->varName = \sprintf('__internal_%s', hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $extensionName));
}
+5 -8
View File
@@ -20,18 +20,15 @@ final class Profile implements \IteratorAggregate, \Serializable
public const BLOCK = 'block';
public const TEMPLATE = 'template';
public const MACRO = 'macro';
private $template;
private $name;
private $type;
private $starts = [];
private $ends = [];
private $profiles = [];
public function __construct(string $template = 'main', string $type = self::ROOT, string $name = 'main')
{
$this->template = $template;
$this->type = $type;
public function __construct(
private string $template = 'main',
private string $type = self::ROOT,
private string $name = 'main',
) {
$this->name = str_starts_with($name, '__internal_') ? 'INTERNAL' : $name;
$this->enter();
}
+3 -5
View File
@@ -26,11 +26,9 @@ final class EscaperRuntime implements RuntimeExtensionInterface
/** @internal */
public $safeLookup = [];
private $charset;
public function __construct($charset = 'UTF-8')
{
$this->charset = $charset;
public function __construct(
private $charset = 'UTF-8',
) {
}
/**
+3 -5
View File
@@ -23,11 +23,9 @@ use Psr\Container\ContainerInterface;
*/
class ContainerRuntimeLoader implements RuntimeLoaderInterface
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
public function __construct(
private ContainerInterface $container,
) {
}
public function load(string $class)
+3 -5
View File
@@ -18,14 +18,12 @@ namespace Twig\RuntimeLoader;
*/
class FactoryRuntimeLoader implements RuntimeLoaderInterface
{
private $map;
/**
* @param array $map An array where keys are class names and values factory callables
*/
public function __construct(array $map = [])
{
$this->map = $map;
public function __construct(
private array $map = [],
) {
}
public function load(string $class)
+5 -9
View File
@@ -18,20 +18,16 @@ namespace Twig;
*/
final class Source
{
private $code;
private $name;
private $path;
/**
* @param string $code The template source code
* @param string $name The template logical name
* @param string $path The filesystem path of the template if any
*/
public function __construct(string $code, string $name, string $path = '')
{
$this->code = $code;
$this->name = $name;
$this->path = $path;
public function __construct(
private string $code,
private string $name,
private string $path = '',
) {
}
public function getCode(): string
+3 -4
View File
@@ -35,7 +35,6 @@ abstract class Template
protected $parent;
protected $parents = [];
protected $env;
protected $blocks = [];
protected $traits = [];
protected $extensions = [];
@@ -43,9 +42,9 @@ abstract class Template
private $useYield;
public function __construct(Environment $env)
{
$this->env = $env;
public function __construct(
protected Environment $env,
) {
$this->useYield = $env->useYield();
$this->extensions = $env->getExtensions();
}
+4 -7
View File
@@ -18,19 +18,16 @@ namespace Twig;
*/
final class TemplateWrapper
{
private $env;
private $template;
/**
* This method is for internal use only and should never be called
* directly (use Twig\Environment::load() instead).
*
* @internal
*/
public function __construct(Environment $env, Template $template)
{
$this->env = $env;
$this->template = $template;
public function __construct(
private Environment $env,
private Template $template,
) {
}
public function render(array $context = []): string
+5 -9
View File
@@ -17,10 +17,6 @@ namespace Twig;
*/
final class Token
{
private $value;
private $type;
private $lineno;
public const EOF_TYPE = -1;
public const TEXT_TYPE = 0;
public const BLOCK_START_TYPE = 1;
@@ -37,11 +33,11 @@ final class Token
public const ARROW_TYPE = 12;
public const SPREAD_TYPE = 13;
public function __construct(int $type, $value, int $lineno)
{
$this->type = $type;
$this->value = $value;
$this->lineno = $lineno;
public function __construct(
private int $type,
private $value,
private int $lineno,
) {
}
public function __toString()
+4 -5
View File
@@ -21,13 +21,12 @@ use Twig\Error\SyntaxError;
*/
final class TokenStream
{
private $tokens;
private $current = 0;
private $source;
public function __construct(array $tokens, ?Source $source = null)
{
$this->tokens = $tokens;
public function __construct(
private array $tokens,
private ?Source $source = null,
) {
$this->source = $source ?: new Source('', '');
}
+3 -5
View File
@@ -20,11 +20,9 @@ use Twig\Source;
*/
final class DeprecationCollector
{
private $twig;
public function __construct(Environment $twig)
{
$this->twig = $twig;
public function __construct(
private Environment $twig,
) {
}
/**