mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 19:36:43 +00:00
Merge branch '1.x' into 2.x
* 1.x: Fix CS Migrate to the new PHP CS Fixer config file
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
return (new PhpCsFixer\Config())
|
||||
->setRules([
|
||||
'@Symfony' => true,
|
||||
'@Symfony:risky' => true,
|
||||
@@ -16,5 +16,5 @@ return PhpCsFixer\Config::create()
|
||||
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'],
|
||||
])
|
||||
->setRiskyAllowed(true)
|
||||
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__))
|
||||
->setFinder((new PhpCsFixer\Finder())->in(__DIR__))
|
||||
;
|
||||
@@ -18,7 +18,7 @@ namespace Twig\Cache;
|
||||
*/
|
||||
class FilesystemCache implements CacheInterface
|
||||
{
|
||||
const FORCE_BYTECODE_INVALIDATION = 1;
|
||||
public const FORCE_BYTECODE_INVALIDATION = 1;
|
||||
|
||||
private $directory;
|
||||
private $options;
|
||||
@@ -67,7 +67,7 @@ class FilesystemCache implements CacheInterface
|
||||
|
||||
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
|
||||
// Compile cached file into bytecode cache
|
||||
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) {
|
||||
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) {
|
||||
@opcache_invalidate($key, true);
|
||||
} elseif (\function_exists('apc_compile_file')) {
|
||||
apc_compile_file($key);
|
||||
|
||||
@@ -41,7 +41,7 @@ class FileExtensionEscapingStrategy
|
||||
$name = substr($name, 0, -5);
|
||||
}
|
||||
|
||||
$extension = pathinfo($name, PATHINFO_EXTENSION);
|
||||
$extension = pathinfo($name, \PATHINFO_EXTENSION);
|
||||
|
||||
switch ($extension) {
|
||||
case 'js':
|
||||
|
||||
@@ -21,7 +21,7 @@ use Twig\Error\SyntaxError;
|
||||
*/
|
||||
class MacroNode extends Node
|
||||
{
|
||||
const VARARGS_NAME = 'varargs';
|
||||
public const VARARGS_NAME = 'varargs';
|
||||
|
||||
public function __construct(string $name, Node $body, Node $arguments, int $lineno, string $tag = null)
|
||||
{
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace Twig\Profiler;
|
||||
*/
|
||||
class Profile implements \IteratorAggregate, \Serializable
|
||||
{
|
||||
const ROOT = 'ROOT';
|
||||
const BLOCK = 'block';
|
||||
const TEMPLATE = 'template';
|
||||
const MACRO = 'macro';
|
||||
public const ROOT = 'ROOT';
|
||||
public const BLOCK = 'block';
|
||||
public const TEMPLATE = 'template';
|
||||
public const MACRO = 'macro';
|
||||
|
||||
private $template;
|
||||
private $name;
|
||||
|
||||
@@ -120,7 +120,7 @@ abstract class IntegrationTestCase extends TestCase
|
||||
$deprecation = $match[3];
|
||||
$templates = self::parseTemplates($match[4]);
|
||||
$exception = false;
|
||||
preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER);
|
||||
preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, \PREG_SET_ORDER);
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file)));
|
||||
}
|
||||
@@ -255,7 +255,7 @@ abstract class IntegrationTestCase extends TestCase
|
||||
protected static function parseTemplates($test)
|
||||
{
|
||||
$templates = [];
|
||||
preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER);
|
||||
preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$templates[($match[1] ?: 'index.twig')] = $match[2];
|
||||
}
|
||||
|
||||
+14
-14
@@ -23,20 +23,20 @@ final class Token
|
||||
private $type;
|
||||
private $lineno;
|
||||
|
||||
const EOF_TYPE = -1;
|
||||
const TEXT_TYPE = 0;
|
||||
const BLOCK_START_TYPE = 1;
|
||||
const VAR_START_TYPE = 2;
|
||||
const BLOCK_END_TYPE = 3;
|
||||
const VAR_END_TYPE = 4;
|
||||
const NAME_TYPE = 5;
|
||||
const NUMBER_TYPE = 6;
|
||||
const STRING_TYPE = 7;
|
||||
const OPERATOR_TYPE = 8;
|
||||
const PUNCTUATION_TYPE = 9;
|
||||
const INTERPOLATION_START_TYPE = 10;
|
||||
const INTERPOLATION_END_TYPE = 11;
|
||||
const ARROW_TYPE = 12;
|
||||
public const EOF_TYPE = -1;
|
||||
public const TEXT_TYPE = 0;
|
||||
public const BLOCK_START_TYPE = 1;
|
||||
public const VAR_START_TYPE = 2;
|
||||
public const BLOCK_END_TYPE = 3;
|
||||
public const VAR_END_TYPE = 4;
|
||||
public const NAME_TYPE = 5;
|
||||
public const NUMBER_TYPE = 6;
|
||||
public const STRING_TYPE = 7;
|
||||
public const OPERATOR_TYPE = 8;
|
||||
public const PUNCTUATION_TYPE = 9;
|
||||
public const INTERPOLATION_START_TYPE = 10;
|
||||
public const INTERPOLATION_END_TYPE = 11;
|
||||
public const ARROW_TYPE = 12;
|
||||
|
||||
/**
|
||||
* @param int $type The type of the token
|
||||
|
||||
@@ -22,19 +22,19 @@ class CompilerTest extends TestCase
|
||||
{
|
||||
$compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class)));
|
||||
|
||||
$locale = setlocale(LC_NUMERIC, 0);
|
||||
$locale = setlocale(\LC_NUMERIC, 0);
|
||||
if (false === $locale) {
|
||||
$this->markTestSkipped('Your platform does not support locales.');
|
||||
}
|
||||
|
||||
$required_locales = ['fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252'];
|
||||
if (false === setlocale(LC_NUMERIC, $required_locales)) {
|
||||
if (false === setlocale(\LC_NUMERIC, $required_locales)) {
|
||||
$this->markTestSkipped('Could not set any of required locales: '.implode(', ', $required_locales));
|
||||
}
|
||||
|
||||
$this->assertEquals('1.2', $compiler->repr(1.2)->getSource());
|
||||
$this->assertStringContainsString('fr', strtolower(setlocale(LC_NUMERIC, 0)));
|
||||
$this->assertStringContainsString('fr', strtolower(setlocale(\LC_NUMERIC, 0)));
|
||||
|
||||
setlocale(LC_NUMERIC, $locale);
|
||||
setlocale(\LC_NUMERIC, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -285,14 +285,14 @@ EOHTML
|
||||
|
||||
public function testTwigLeakOutputInDebugMode()
|
||||
{
|
||||
$output = exec(sprintf('%s %s debug', PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php')));
|
||||
$output = exec(sprintf('%s %s debug', \PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php')));
|
||||
|
||||
$this->assertSame('Hello OOPS', $output);
|
||||
}
|
||||
|
||||
public function testDoesNotTwigLeakOutput()
|
||||
{
|
||||
$output = exec(sprintf('%s %s', PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php')));
|
||||
$output = exec(sprintf('%s %s', \PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php')));
|
||||
|
||||
$this->assertSame('', $output);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Twig\Tests\Extension;
|
||||
|
||||
use Twig\Environment;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\StringLoaderExtension;
|
||||
|
||||
class StringLoaderExtensionTest extends TestCase
|
||||
@@ -21,6 +21,6 @@ class StringLoaderExtensionTest extends TestCase
|
||||
{
|
||||
$twig = new Environment($this->createMock('\Twig\Loader\LoaderInterface'));
|
||||
$twig->addExtension(new StringLoaderExtension());
|
||||
$this->assertSame('something', twig_include($twig, [], twig_template_from_string($twig, "something")));
|
||||
$this->assertSame('something', twig_include($twig, [], twig_template_from_string($twig, 'something')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ function test_foo($value = 'foo')
|
||||
|
||||
class TwigTestFoo implements \Iterator
|
||||
{
|
||||
const BAR_NAME = 'bar';
|
||||
public const BAR_NAME = 'bar';
|
||||
|
||||
public $position = 0;
|
||||
public $array = [1, 2];
|
||||
|
||||
Reference in New Issue
Block a user