mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
Fix CS
This commit is contained in:
@@ -65,7 +65,7 @@ class FunctionalTest extends TestCase
|
||||
$twig->render('index');
|
||||
}
|
||||
|
||||
private function createEnvironment(array $templates, ArrayAdapter $cache = null): Environment
|
||||
private function createEnvironment(array $templates, ?ArrayAdapter $cache = null): Environment
|
||||
{
|
||||
$twig = new Environment(new ArrayLoader($templates));
|
||||
$cache = $cache ?? new ArrayAdapter();
|
||||
|
||||
@@ -21,7 +21,7 @@ final class HtmlExtension extends AbstractExtension
|
||||
{
|
||||
private $mimeTypes;
|
||||
|
||||
public function __construct(MimeTypes $mimeTypes = null)
|
||||
public function __construct(?MimeTypes $mimeTypes = null)
|
||||
{
|
||||
$this->mimeTypes = $mimeTypes;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ final class HtmlExtension extends AbstractExtension
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function dataUri(string $data, string $mime = null, array $parameters = []): string
|
||||
public function dataUri(string $data, ?string $mime = null, array $parameters = []): string
|
||||
{
|
||||
$repr = 'data:';
|
||||
|
||||
|
||||
@@ -21,6 +21,6 @@ class LegacyFunctionsTest extends TestCase
|
||||
{
|
||||
public function testHtmlToMarkdown()
|
||||
{
|
||||
$this->assertSame(HtmlExtension::htmlClasses(['charset' => 'utf-8']), \twig_html_classes(['charset' => 'utf-8']));
|
||||
$this->assertSame(HtmlExtension::htmlClasses(['charset' => 'utf-8']), twig_html_classes(['charset' => 'utf-8']));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ final class IntlExtension extends AbstractExtension
|
||||
private $dateFormatterPrototype;
|
||||
private $numberFormatterPrototype;
|
||||
|
||||
public function __construct(\IntlDateFormatter $dateFormatterPrototype = null, \NumberFormatter $numberFormatterPrototype = null)
|
||||
public function __construct(?\IntlDateFormatter $dateFormatterPrototype = null, ?\NumberFormatter $numberFormatterPrototype = null)
|
||||
{
|
||||
$this->dateFormatterPrototype = $dateFormatterPrototype;
|
||||
$this->numberFormatterPrototype = $numberFormatterPrototype;
|
||||
@@ -191,7 +191,7 @@ final class IntlExtension extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
public function getCountryName(?string $country, string $locale = null): string
|
||||
public function getCountryName(?string $country, ?string $locale = null): string
|
||||
{
|
||||
if (null === $country) {
|
||||
return '';
|
||||
@@ -204,7 +204,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getCurrencyName(?string $currency, string $locale = null): string
|
||||
public function getCurrencyName(?string $currency, ?string $locale = null): string
|
||||
{
|
||||
if (null === $currency) {
|
||||
return '';
|
||||
@@ -217,7 +217,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getCurrencySymbol(?string $currency, string $locale = null): string
|
||||
public function getCurrencySymbol(?string $currency, ?string $locale = null): string
|
||||
{
|
||||
if (null === $currency) {
|
||||
return '';
|
||||
@@ -230,7 +230,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getLanguageName(?string $language, string $locale = null): string
|
||||
public function getLanguageName(?string $language, ?string $locale = null): string
|
||||
{
|
||||
if (null === $language) {
|
||||
return '';
|
||||
@@ -243,7 +243,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getLocaleName(?string $data, string $locale = null): string
|
||||
public function getLocaleName(?string $data, ?string $locale = null): string
|
||||
{
|
||||
if (null === $data) {
|
||||
return '';
|
||||
@@ -256,7 +256,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getTimezoneName(?string $timezone, string $locale = null): string
|
||||
public function getTimezoneName(?string $timezone, ?string $locale = null): string
|
||||
{
|
||||
if (null === $timezone) {
|
||||
return '';
|
||||
@@ -278,7 +278,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getLanguageNames(string $locale = null): array
|
||||
public function getLanguageNames(?string $locale = null): array
|
||||
{
|
||||
try {
|
||||
return Languages::getNames($locale);
|
||||
@@ -287,7 +287,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getScriptNames(string $locale = null): array
|
||||
public function getScriptNames(?string $locale = null): array
|
||||
{
|
||||
try {
|
||||
return Scripts::getNames($locale);
|
||||
@@ -296,7 +296,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getCountryNames(string $locale = null): array
|
||||
public function getCountryNames(?string $locale = null): array
|
||||
{
|
||||
try {
|
||||
return Countries::getNames($locale);
|
||||
@@ -305,7 +305,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getLocaleNames(string $locale = null): array
|
||||
public function getLocaleNames(?string $locale = null): array
|
||||
{
|
||||
try {
|
||||
return Locales::getNames($locale);
|
||||
@@ -314,7 +314,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getCurrencyNames(string $locale = null): array
|
||||
public function getCurrencyNames(?string $locale = null): array
|
||||
{
|
||||
try {
|
||||
return Currencies::getNames($locale);
|
||||
@@ -323,7 +323,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function getTimezoneNames(string $locale = null): array
|
||||
public function getTimezoneNames(?string $locale = null): array
|
||||
{
|
||||
try {
|
||||
return Timezones::getNames($locale);
|
||||
@@ -332,7 +332,7 @@ final class IntlExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function formatCurrency($amount, string $currency, array $attrs = [], string $locale = null): string
|
||||
public function formatCurrency($amount, string $currency, array $attrs = [], ?string $locale = null): string
|
||||
{
|
||||
$formatter = $this->createNumberFormatter($locale, 'currency', $attrs);
|
||||
|
||||
@@ -343,7 +343,7 @@ final class IntlExtension extends AbstractExtension
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function formatNumber($number, array $attrs = [], string $style = 'decimal', string $type = 'default', string $locale = null): string
|
||||
public function formatNumber($number, array $attrs = [], string $style = 'decimal', string $type = 'default', ?string $locale = null): string
|
||||
{
|
||||
if (!isset(self::NUMBER_TYPES[$type])) {
|
||||
throw new RuntimeError(sprintf('The type "%s" does not exist, known types are: "%s".', $type, implode('", "', array_keys(self::NUMBER_TYPES))));
|
||||
@@ -358,7 +358,7 @@ final class IntlExtension extends AbstractExtension
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function formatNumberStyle(string $style, $number, array $attrs = [], string $type = 'default', string $locale = null): string
|
||||
public function formatNumberStyle(string $style, $number, array $attrs = [], string $type = 'default', ?string $locale = null): string
|
||||
{
|
||||
return $this->formatNumber($number, $attrs, $style, $type, $locale);
|
||||
}
|
||||
@@ -367,7 +367,7 @@ final class IntlExtension extends AbstractExtension
|
||||
* @param \DateTimeInterface|string|null $date A date or null to use the current time
|
||||
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
|
||||
*/
|
||||
public function formatDateTime(Environment $env, $date, ?string $dateFormat = 'medium', ?string $timeFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null): string
|
||||
public function formatDateTime(Environment $env, $date, ?string $dateFormat = 'medium', ?string $timeFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', ?string $locale = null): string
|
||||
{
|
||||
$date = CoreExtension::dateConverter($env, $date, $timezone);
|
||||
|
||||
@@ -390,7 +390,7 @@ final class IntlExtension extends AbstractExtension
|
||||
* @param \DateTimeInterface|string|null $date A date or null to use the current time
|
||||
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
|
||||
*/
|
||||
public function formatDate(Environment $env, $date, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null): string
|
||||
public function formatDate(Environment $env, $date, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', ?string $locale = null): string
|
||||
{
|
||||
return $this->formatDateTime($env, $date, $dateFormat, 'none', $pattern, $timezone, $calendar, $locale);
|
||||
}
|
||||
@@ -399,7 +399,7 @@ final class IntlExtension extends AbstractExtension
|
||||
* @param \DateTimeInterface|string|null $date A date or null to use the current time
|
||||
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
|
||||
*/
|
||||
public function formatTime(Environment $env, $date, ?string $timeFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null): string
|
||||
public function formatTime(Environment $env, $date, ?string $timeFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', ?string $locale = null): string
|
||||
{
|
||||
return $this->formatDateTime($env, $date, 'none', $timeFormat, $pattern, $timezone, $calendar, $locale);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class ErusevMarkdown implements MarkdownInterface
|
||||
{
|
||||
private $converter;
|
||||
|
||||
public function __construct(Parsedown $converter = null)
|
||||
public function __construct(?Parsedown $converter = null)
|
||||
{
|
||||
$this->converter = $converter ?: new Parsedown();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class LeagueMarkdown implements MarkdownInterface
|
||||
private $converter;
|
||||
private $legacySupport;
|
||||
|
||||
public function __construct(CommonMarkConverter $converter = null)
|
||||
public function __construct(?CommonMarkConverter $converter = null)
|
||||
{
|
||||
$this->converter = $converter ?: new CommonMarkConverter();
|
||||
$this->legacySupport = !method_exists($this->converter, 'convert');
|
||||
|
||||
@@ -17,7 +17,7 @@ class MichelfMarkdown implements MarkdownInterface
|
||||
{
|
||||
private $converter;
|
||||
|
||||
public function __construct(MarkdownExtra $converter = null)
|
||||
public function __construct(?MarkdownExtra $converter = null)
|
||||
{
|
||||
if (null === $converter) {
|
||||
$converter = new MarkdownExtra();
|
||||
|
||||
@@ -22,7 +22,7 @@ final class StringExtension extends AbstractExtension
|
||||
{
|
||||
private $slugger;
|
||||
|
||||
public function __construct(SluggerInterface $slugger = null)
|
||||
public function __construct(?SluggerInterface $slugger = null)
|
||||
{
|
||||
$this->slugger = $slugger ?: new AsciiSlugger();
|
||||
}
|
||||
|
||||
+3
-3
@@ -278,7 +278,7 @@ class Environment
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getTemplateClass(string $name, int $index = null): string
|
||||
public function getTemplateClass(string $name, ?int $index = null): string
|
||||
{
|
||||
$key = $this->getLoader()->getCacheKey($name).$this->optionsHash;
|
||||
|
||||
@@ -346,7 +346,7 @@ class Environment
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function loadTemplate(string $cls, string $name, int $index = null): Template
|
||||
public function loadTemplate(string $cls, string $name, ?int $index = null): Template
|
||||
{
|
||||
$mainCls = $cls;
|
||||
if (null !== $index) {
|
||||
@@ -401,7 +401,7 @@ class Environment
|
||||
* @throws LoaderError When the template cannot be found
|
||||
* @throws SyntaxError When an error occurred during compilation
|
||||
*/
|
||||
public function createTemplate(string $template, string $name = null): TemplateWrapper
|
||||
public function createTemplate(string $template, ?string $name = null): TemplateWrapper
|
||||
{
|
||||
$hash = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $template, false);
|
||||
if (null !== $name) {
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ class Error extends \Exception
|
||||
* @param int $lineno The template line where the error occurred
|
||||
* @param Source|null $source The source context where the error occurred
|
||||
*/
|
||||
public function __construct(string $message, int $lineno = -1, Source $source = null, \Throwable $previous = null)
|
||||
public function __construct(string $message, int $lineno = -1, ?Source $source = null, ?\Throwable $previous = null)
|
||||
{
|
||||
parent::__construct('', 0, $previous);
|
||||
|
||||
@@ -93,7 +93,7 @@ class Error extends \Exception
|
||||
return $this->name ? new Source($this->sourceCode, $this->name, $this->sourcePath) : null;
|
||||
}
|
||||
|
||||
public function setSourceContext(Source $source = null): void
|
||||
public function setSourceContext(?Source $source = null): void
|
||||
{
|
||||
if (null === $source) {
|
||||
$this->sourceCode = $this->name = $this->sourcePath = null;
|
||||
|
||||
@@ -15,7 +15,6 @@ use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\ExpressionParser;
|
||||
use Twig\Extension\SandboxExtension;
|
||||
use Twig\Markup;
|
||||
use Twig\Node\Expression\Binary\AddBinary;
|
||||
use Twig\Node\Expression\Binary\AndBinary;
|
||||
|
||||
@@ -26,7 +26,7 @@ final class SandboxExtension extends AbstractExtension
|
||||
private $policy;
|
||||
private $sourcePolicy;
|
||||
|
||||
public function __construct(SecurityPolicyInterface $policy, $sandboxed = false, SourcePolicyInterface $sourcePolicy = null)
|
||||
public function __construct(SecurityPolicyInterface $policy, $sandboxed = false, ?SourcePolicyInterface $sourcePolicy = null)
|
||||
{
|
||||
$this->policy = $policy;
|
||||
$this->sandboxedGlobally = $sandboxed;
|
||||
@@ -53,7 +53,7 @@ final class SandboxExtension extends AbstractExtension
|
||||
$this->sandboxed = false;
|
||||
}
|
||||
|
||||
public function isSandboxed(Source $source = null): bool
|
||||
public function isSandboxed(?Source $source = null): bool
|
||||
{
|
||||
return $this->sandboxedGlobally || $this->sandboxed || $this->isSourceSandboxed($source);
|
||||
}
|
||||
@@ -82,14 +82,14 @@ final class SandboxExtension extends AbstractExtension
|
||||
return $this->policy;
|
||||
}
|
||||
|
||||
public function checkSecurity($tags, $filters, $functions, Source $source = null): void
|
||||
public function checkSecurity($tags, $filters, $functions, ?Source $source = null): void
|
||||
{
|
||||
if ($this->isSandboxed($source)) {
|
||||
$this->policy->checkSecurity($tags, $filters, $functions);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkMethodAllowed($obj, $method, int $lineno = -1, Source $source = null): void
|
||||
public function checkMethodAllowed($obj, $method, int $lineno = -1, ?Source $source = null): void
|
||||
{
|
||||
if ($this->isSandboxed($source)) {
|
||||
try {
|
||||
@@ -103,7 +103,7 @@ final class SandboxExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function checkPropertyAllowed($obj, $property, int $lineno = -1, Source $source = null): void
|
||||
public function checkPropertyAllowed($obj, $property, int $lineno = -1, ?Source $source = null): void
|
||||
{
|
||||
if ($this->isSandboxed($source)) {
|
||||
try {
|
||||
@@ -117,7 +117,7 @@ final class SandboxExtension extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
public function ensureToStringAllowed($obj, int $lineno = -1, Source $source = null)
|
||||
public function ensureToStringAllowed($obj, int $lineno = -1, ?Source $source = null)
|
||||
{
|
||||
if ($this->isSandboxed($source) && \is_object($obj) && method_exists($obj, '__toString')) {
|
||||
try {
|
||||
|
||||
@@ -34,7 +34,7 @@ final class StringLoaderExtension extends AbstractExtension
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function templateFromString(Environment $env, $template, string $name = null): TemplateWrapper
|
||||
public static function templateFromString(Environment $env, $template, ?string $name = null): TemplateWrapper
|
||||
{
|
||||
return $env->createTemplate((string) $template, $name);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class FilesystemLoader implements LoaderInterface
|
||||
* @param string|array $paths A path or an array of paths where to look for templates
|
||||
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
|
||||
*/
|
||||
public function __construct($paths = [], string $rootPath = null)
|
||||
public function __construct($paths = [], ?string $rootPath = null)
|
||||
{
|
||||
$this->rootPath = ($rootPath ?? getcwd()).\DIRECTORY_SEPARATOR;
|
||||
if (null !== $rootPath && false !== ($realPath = realpath($rootPath))) {
|
||||
|
||||
@@ -21,7 +21,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class BlockNode extends Node
|
||||
{
|
||||
public function __construct(string $name, Node $body, int $lineno, string $tag = null)
|
||||
public function __construct(string $name, Node $body, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class BlockReferenceNode extends Node implements NodeOutputInterface
|
||||
{
|
||||
public function __construct(string $name, int $lineno, string $tag = null)
|
||||
public function __construct(string $name, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct([], ['name' => $name], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class CaptureNode extends Node
|
||||
{
|
||||
public function __construct(Node $body, int $lineno, string $tag = null)
|
||||
public function __construct(Node $body, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['body' => $body], ['raw' => false, 'with_blocks' => false], $lineno, $tag);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ class CaptureNode extends Node
|
||||
if (!$this->getAttribute('raw')) {
|
||||
$compiler->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())");
|
||||
}
|
||||
$compiler->raw(";");
|
||||
$compiler->raw(';');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Node\Expression\ConstantExpression;
|
||||
*/
|
||||
class DeprecatedNode extends Node
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
|
||||
public function __construct(AbstractExpression $expr, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ use Twig\Node\Expression\AbstractExpression;
|
||||
*/
|
||||
class DoNode extends Node
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
|
||||
public function __construct(AbstractExpression $expr, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use Twig\Node\Expression\ConstantExpression;
|
||||
class EmbedNode extends IncludeNode
|
||||
{
|
||||
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
|
||||
public function __construct(string $name, int $index, ?AbstractExpression $variables, bool $only, bool $ignoreMissing, int $lineno, string $tag = null)
|
||||
public function __construct(string $name, int $index, ?AbstractExpression $variables, bool $only, bool $ignoreMissing, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class ArrayExpression extends AbstractExpression
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addElement(AbstractExpression $value, AbstractExpression $key = null): void
|
||||
public function addElement(AbstractExpression $value, ?AbstractExpression $key = null): void
|
||||
{
|
||||
if (null === $key) {
|
||||
$key = new ConstantExpression(++$this->index, $value->getTemplateLine());
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Node\Node;
|
||||
*/
|
||||
class BlockReferenceExpression extends AbstractExpression
|
||||
{
|
||||
public function __construct(Node $name, ?Node $template, int $lineno, string $tag = null)
|
||||
public function __construct(Node $name, ?Node $template, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$nodes = ['name' => $name];
|
||||
if (null !== $template) {
|
||||
|
||||
@@ -29,7 +29,7 @@ use Twig\Node\Node;
|
||||
*/
|
||||
class DefaultFilter extends FilterExpression
|
||||
{
|
||||
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null)
|
||||
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use Twig\Node\Node;
|
||||
|
||||
class FilterExpression extends CallExpression
|
||||
{
|
||||
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null)
|
||||
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class ParentExpression extends AbstractExpression
|
||||
{
|
||||
public function __construct(string $name, int $lineno, string $tag = null)
|
||||
public function __construct(string $name, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class ForLoopNode extends Node
|
||||
{
|
||||
public function __construct(int $lineno, string $tag = null)
|
||||
public function __construct(int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class ForNode extends Node
|
||||
{
|
||||
private $loop;
|
||||
|
||||
public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, ?Node $ifexpr, Node $body, ?Node $else, int $lineno, string $tag = null)
|
||||
public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, ?Node $ifexpr, Node $body, ?Node $else, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]);
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class IfNode extends Node
|
||||
{
|
||||
public function __construct(Node $tests, ?Node $else, int $lineno, string $tag = null)
|
||||
public function __construct(Node $tests, ?Node $else, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$nodes = ['tests' => $tests];
|
||||
if (null !== $else) {
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Node\Expression\NameExpression;
|
||||
*/
|
||||
class ImportNode extends Node
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, string $tag = null, bool $global = true)
|
||||
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, ?string $tag = null, bool $global = true)
|
||||
{
|
||||
parent::__construct(['expr' => $expr, 'var' => $var], ['global' => $global], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Node\Expression\AbstractExpression;
|
||||
*/
|
||||
class IncludeNode extends Node implements NodeOutputInterface
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, ?AbstractExpression $variables, bool $only, bool $ignoreMissing, int $lineno, string $tag = null)
|
||||
public function __construct(AbstractExpression $expr, ?AbstractExpression $variables, bool $only, bool $ignoreMissing, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$nodes = ['expr' => $expr];
|
||||
if (null !== $variables) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class MacroNode extends Node
|
||||
{
|
||||
public const VARARGS_NAME = 'varargs';
|
||||
|
||||
public function __construct(string $name, Node $body, Node $arguments, int $lineno, string $tag = null)
|
||||
public function __construct(string $name, Node $body, Node $arguments, int $lineno, ?string $tag = null)
|
||||
{
|
||||
foreach ($arguments as $argumentName => $argument) {
|
||||
if (self::VARARGS_NAME === $argumentName) {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class Node implements \Countable, \IteratorAggregate
|
||||
* @param int $lineno The line number
|
||||
* @param string $tag The tag name associated with the Node
|
||||
*/
|
||||
public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0, string $tag = null)
|
||||
public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0, ?string $tag = null)
|
||||
{
|
||||
foreach ($nodes as $name => $node) {
|
||||
if (!$node instanceof self) {
|
||||
|
||||
@@ -22,7 +22,7 @@ use Twig\Node\Expression\AbstractExpression;
|
||||
*/
|
||||
class PrintNode extends Node implements NodeOutputInterface
|
||||
{
|
||||
public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
|
||||
public function __construct(AbstractExpression $expr, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class SandboxNode extends Node
|
||||
{
|
||||
public function __construct(Node $body, int $lineno, string $tag = null)
|
||||
public function __construct(Node $body, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['body' => $body], [], $lineno, $tag);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use Twig\Node\Expression\ConstantExpression;
|
||||
*/
|
||||
class SetNode extends Node implements NodeCaptureInterface
|
||||
{
|
||||
public function __construct(bool $capture, Node $names, Node $values, int $lineno, string $tag = null)
|
||||
public function __construct(bool $capture, Node $names, Node $values, int $lineno, ?string $tag = null)
|
||||
{
|
||||
/*
|
||||
* Optimizes the node when capture is used for a large block of text.
|
||||
|
||||
@@ -20,7 +20,7 @@ use Twig\Compiler;
|
||||
*/
|
||||
class WithNode extends Node
|
||||
{
|
||||
public function __construct(Node $body, ?Node $variables, bool $only, int $lineno, string $tag = null)
|
||||
public function __construct(Node $body, ?Node $variables, bool $only, int $lineno, ?string $tag = null)
|
||||
{
|
||||
$nodes = ['body' => $body];
|
||||
if (null !== $variables) {
|
||||
|
||||
@@ -137,7 +137,7 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
|
||||
|
||||
$exprNode = $node->getNode('expr');
|
||||
|
||||
if ($exprNode instanceof ConstantExpression && is_string($exprNode->getAttribute('value'))) {
|
||||
if ($exprNode instanceof ConstantExpression && \is_string($exprNode->getAttribute('value'))) {
|
||||
return new TextNode($exprNode->getAttribute('value'), $exprNode->getTemplateLine());
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function intersectSafe(array $a = null, array $b = null): array
|
||||
private function intersectSafe(?array $a = null, ?array $b = null): array
|
||||
{
|
||||
if (null === $a || null === $b) {
|
||||
return [];
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ class Parser
|
||||
$this->embeddedTemplates[] = $template;
|
||||
}
|
||||
|
||||
public function addImportedSymbol(string $type, string $alias, string $name = null, AbstractExpression $node = null): void
|
||||
public function addImportedSymbol(string $type, string $alias, ?string $name = null, ?AbstractExpression $node = null): void
|
||||
{
|
||||
$this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node];
|
||||
}
|
||||
|
||||
@@ -15,9 +15,10 @@ use Twig\TemplateWrapper;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @deprecated since Twig 3.9.0
|
||||
*/
|
||||
function twig_template_from_string(Environment $env, $template, string $name = null): TemplateWrapper
|
||||
function twig_template_from_string(Environment $env, $template, ?string $name = null): TemplateWrapper
|
||||
{
|
||||
trigger_deprecation('twig/twig', '3.9.0', 'Using the internal "%s" function is deprecated.', __FUNCTION__);
|
||||
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ abstract class Template
|
||||
* @param array $blocks The current set of blocks
|
||||
* @param bool $useBlocks Whether to use the current set of blocks
|
||||
*/
|
||||
public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, self $templateContext = null)
|
||||
public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, ?self $templateContext = null)
|
||||
{
|
||||
if ($useBlocks && isset($blocks[$name])) {
|
||||
$template = $blocks[$name][0];
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class NodeTestCase extends TestCase
|
||||
$this->assertNodeCompilation($source, $node, $environment, $isPattern);
|
||||
}
|
||||
|
||||
public function assertNodeCompilation($source, Node $node, Environment $environment = null, $isPattern = false)
|
||||
public function assertNodeCompilation($source, Node $node, ?Environment $environment = null, $isPattern = false)
|
||||
{
|
||||
$compiler = $this->getCompiler($environment);
|
||||
$compiler->compile($node);
|
||||
@@ -46,7 +46,7 @@ abstract class NodeTestCase extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCompiler(Environment $environment = null)
|
||||
protected function getCompiler(?Environment $environment = null)
|
||||
{
|
||||
return new Compiler($environment ?? $this->getEnvironment());
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ final class TokenStream
|
||||
private $current = 0;
|
||||
private $source;
|
||||
|
||||
public function __construct(array $tokens, Source $source = null)
|
||||
public function __construct(array $tokens, ?Source $source = null)
|
||||
{
|
||||
$this->tokens = $tokens;
|
||||
$this->source = $source ?: new Source('', '');
|
||||
@@ -66,7 +66,7 @@ final class TokenStream
|
||||
/**
|
||||
* Tests a token and returns it or throws a syntax error.
|
||||
*/
|
||||
public function expect($type, $value = null, string $message = null): Token
|
||||
public function expect($type, $value = null, ?string $message = null): Token
|
||||
{
|
||||
$token = $this->tokens[$this->current];
|
||||
if (!$token->test($type, $value)) {
|
||||
|
||||
@@ -71,7 +71,7 @@ abstract class YieldingTemplate extends Template
|
||||
/**
|
||||
* @return iterable<string>
|
||||
*/
|
||||
public function yieldBlock($name, array $context, array $blocks = [], $useBlocks = true, Template $templateContext = null)
|
||||
public function yieldBlock($name, array $context, array $blocks = [], $useBlocks = true, ?Template $templateContext = null)
|
||||
{
|
||||
if ($useBlocks && isset($blocks[$name])) {
|
||||
$template = $blocks[$name][0];
|
||||
@@ -165,7 +165,7 @@ abstract class YieldingTemplate extends Template
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, Template $templateContext = null)
|
||||
public function displayBlock($name, array $context, array $blocks = [], $useBlocks = true, ?Template $templateContext = null)
|
||||
{
|
||||
throw new RuntimeError(sprintf('Calling "%s" for block "%s" is not supported as "use_yield" is set to "true".', __METHOD__, $name), -1, $this->getSourceContext());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public function block_foo(\$context, array \$blocks = [])
|
||||
echo "foo";
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader())
|
||||
, new Environment(new ArrayLoader()),
|
||||
];
|
||||
} else {
|
||||
$tests[] = [new BlockNode('foo', new TextNode('foo', 1), 1), <<<EOF
|
||||
@@ -53,7 +53,7 @@ public function block_foo(\$context, array \$blocks = [])
|
||||
yield "foo";
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader())
|
||||
, new Environment(new ArrayLoader()),
|
||||
];
|
||||
|
||||
$tests[] = [new BlockNode('foo', new Node(), 1), <<<EOF
|
||||
@@ -64,7 +64,7 @@ public function block_foo(\$context, array \$blocks = [])
|
||||
yield '';
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader())
|
||||
, new Environment(new ArrayLoader()),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ class SetTest extends NodeTestCase
|
||||
EOF
|
||||
];
|
||||
|
||||
|
||||
$names = new Node([new AssignNameExpression('foo', 1)], [], 1);
|
||||
$values = new Node([new PrintNode(new ConstantExpression('foo', 1), 1)], [], 1);
|
||||
$node = new SetNode(true, $names, $values, 1);
|
||||
|
||||
Reference in New Issue
Block a user