Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 16, 2025
1 parent 9d3ad2a commit 4db7de1
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Latte/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function acquireLock(string $file, int $mode)

public function generateFileName(string $name, string $hash): string
{
$base = preg_match('#([/\\\\][\[email protected]]{3,35}){1,3}$#D', '/' . $name, $m)
$base = preg_match('#([/\\\][\[email protected]]{3,35}){1,3}$#D', '/' . $name, $m)
? preg_replace('#[^\[email protected]]+#', '-', substr($m[0], 1)) . '--'
: '';
return $this->directory . '/' . $base . $hash . '.php';
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Compiler/PhpHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static function decodeEscapeSequences(string $str, ?string $quote): strin
}

return preg_replace_callback(
'~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u\{([0-9a-fA-F]+)\})~',
'~\\\([\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u\{([0-9a-fA-F]+)\})~',
function ($matches) {
$ch = $matches[1];
$replacements = [
Expand Down
4 changes: 2 additions & 2 deletions src/Latte/Compiler/TagLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function tokenizeUnquotedString(string $input, Position $position, bool $
{
preg_match(
$colon
? '~ ( [./@_a-z0-9#!-] | :(?!:) | \{\$ [_a-z0-9\[\]()>-]+ })++ (?=\s+[!"\'$(\[{,\\\\|\~\w-] | [,|] | \s*$) ~xAi'
: '~ ( [./@_a-z0-9#!-] | \{\$ [_a-z0-9\[\]()>-]+ })++ (?=\s+[!"\'$(\[{,\\\\|\~\w-] | [,:|] | \s*$) ~xAi',
? '~ ( [./@_a-z0-9#!-] | :(?!:) | \{\$ [_a-z0-9\[\]()>-]+ })++ (?=\s+[!"\'$(\[{,\\\|\~\w-] | [,|] | \s*$) ~xAi'
: '~ ( [./@_a-z0-9#!-] | \{\$ [_a-z0-9\[\]()>-]+ })++ (?=\s+[!"\'$(\[{,\\\|\~\w-] | [,:|] | \s*$) ~xAi',
$input,
$match,
offset: $position->offset - $offsetDelta,
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Compiler/TemplateLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function stateLatteTag(): array
{
$tokens[] = $this->match('~
(?<Slash>/)?
(?<Latte_Name> = | _(?!_) | [a-z]\w*+(?:[.:-]\w+)*+(?!::|\(|\\\\))? # name, /name, but not function( or class:: or namespace\
(?<Latte_Name> = | _(?!_) | [a-z]\w*+(?:[.:-]\w+)*+(?!::|\(|\\\))? # name, /name, but not function( or class:: or namespace\
~xsiAu');

$tokens[] = $this->tagLexer->tokenizePartially($this->input, $this->position);
Expand Down
4 changes: 3 additions & 1 deletion src/Latte/Essential/Nodes/IfNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static function create(Tag $tag, TemplateParser $parser): \Generator
: $tag->parser->parseExpression();
}

[$node->then, $nextTag] = yield $node->capture ? ['else'] : ['else', 'elseif', 'elseifset'];
[$node->then, $nextTag] = yield $node->capture
? ['else']
: ['else', 'elseif', 'elseifset'];

if ($nextTag?->name === 'else') {
if ($nextTag->parser->stream->is('if')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Essential/Nodes/IncludeBlockNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function create(Tag $tag, TemplateParser $parser): static
} elseif ($node->parent || $tokenName->is('this')) {
$item = $tag->closestTag(
[BlockNode::class, DefineNode::class],
fn($item) => $item->node?->block && !$item->node->block->isDynamic() && $item->node->block->name !== ''
fn($item) => $item->node?->block && !$item->node->block->isDynamic() && $item->node->block->name !== '',
);
if (!$item) {
throw new CompileException("Cannot include $tokenName->text block outside of any block.", $tag->position);
Expand Down
2 changes: 1 addition & 1 deletion src/Latte/Loaders/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function isExpired(string $file, int $time): bool
*/
public function getReferredName(string $file, string $referringFile): string
{
if ($this->baseDir || !preg_match('#/|\\\\|[a-z]:|phar:#iA', $file)) {
if ($this->baseDir || !preg_match('#/|\\\|[a-z]:|phar:#iA', $file)) {
$file = $this->normalizePath($referringFile . '/../' . $file);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function scanDirectory(string $path): bool
$errors = 0;
foreach ($files as $file) {
$file = (string) $file;
echo preg_replace('~\.?[/\\\\]~A', '', $file), "\x0D";
echo preg_replace('~\.?[/\\\]~A', '', $file), "\x0D";
$errors += $this->lintLatte($file) ? 0 : 1;
echo str_pad('...', strlen($file)), "\x0D";
$counter++;
Expand Down
4 changes: 2 additions & 2 deletions tests/common/AuxiliaryNode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $node = new Nodes\AuxiliaryNode(

$node = (new NodeTraverser)->traverse(
$node,
fn(Node $node) => $node instanceof StringNode ? new StringNode('new') : $node
fn(Node $node) => $node instanceof StringNode ? new StringNode('new') : $node,
);
Assert::same("'new' 'new'", $node->print(new PrintContext));

Expand All @@ -32,6 +32,6 @@ $node = new Expression\AuxiliaryNode(

$node = (new NodeTraverser)->traverse(
$node,
fn(Node $node) => $node instanceof StringNode ? new StringNode('new') : $node
fn(Node $node) => $node instanceof StringNode ? new StringNode('new') : $node,
);
Assert::same("'new' 'new'", $node->print(new PrintContext));
2 changes: 1 addition & 1 deletion tests/common/Loaders.FileLoader.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require __DIR__ . '/../bootstrap.php';
$loader = new FileLoader;
Assert::same(file_get_contents(__FILE__), $loader->getContent(__FILE__));

Assert::same('/a/b/inner', strtr($loader->getReferredName('inner', '/a\\b/c'), '\\', '/'));
Assert::same('/a/b/inner', strtr($loader->getReferredName('inner', '/a\b/c'), '\\', '/'));
Assert::same('/a/b/c', strtr($loader->getReferredName('/a/b/c', '/a/b/c'), '\\', '/'));
Assert::same('/a/c', strtr($loader->getReferredName('../c', '/a/b/c'), '\\', '/'));

Expand Down
2 changes: 1 addition & 1 deletion tests/common/TagParser.parseModifier().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('common', function () {
test('arguments', function () {
Assert::same("(\$this->filters->mod)(@, 'arg1', 2, \$var['pocet'])", format('|mod,arg1,2,$var["pocet"]'));
Assert::same("(\$this->filters->mod)(@, ' ,a,b,c', '', 3, '')", @format('|mod:" ,a,b,c", "", 3, ""'));
Assert::same("(\$this->filters->mod)(@, '\",a,b,c')", format('|mod:"\\",a,b,c"'));
Assert::same("(\$this->filters->mod)(@, '\",a,b,c')", format('|mod:"\",a,b,c"'));
Assert::same("(\$this->filters->mod)(@, '\\',a,b,c')", format("|mod:'\\',a,b,c'"));
Assert::same("(\$this->filters->mod)(@, 'param', 'param')", @format('|mod , param , param'));
Assert::same("(\$this->filters->mod)(@, \$var, 0, -0.0, 'str', 'str')", format('|mod, $var, 0, -0.0, "str", \'str\''));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Assert::same('$var', format('$var'));
Assert::same("'symbol'", format('symbol$var')); // bc break
Assert::same("'var'", format("'var'"));
Assert::same("'var'", format('"var"'));
Assert::same("'v\"ar'", format('"v\\"ar"'));
Assert::same("'v\"ar'", format('"v\"ar"'));
Assert::same("'var' . 'var'", format("var.'var'"));
Assert::same("\$var['var']", format('$var[var]'));
Assert::same("\$x['[x]']", format('$x["[x]"]'));
Expand Down
4 changes: 2 additions & 2 deletions tests/filters/sort.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('re-iteration', function () {
test('user comparison + array', function () {
Assert::same(
[2 => 33, 0 => 22, 1 => 11],
(new Filters)->sort([22, 11, 33], fn($a, $b) => $b <=> $a)
(new Filters)->sort([22, 11, 33], fn($a, $b) => $b <=> $a),
);
});

Expand Down Expand Up @@ -115,7 +115,7 @@ test('iterator + by', function () {
test('callback + array + by', function () {
Assert::same(
[1 => 11, 0 => 22, 33],
(new Filters)->sort([22, 11, 33], by: fn($a) => $a * 11)
(new Filters)->sort([22, 11, 33], by: fn($a) => $a * 11),
);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function getTempDir(): string
{
$dir = __DIR__ . '/tmp/' . getmypid();

if (empty($GLOBALS['\\lock'])) {
if (empty($GLOBALS['\lock'])) {
// garbage collector
$GLOBALS['\\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
$GLOBALS['\lock'] = $lock = fopen(__DIR__ . '/lock', 'w');
if (rand(0, 100)) {
flock($lock, LOCK_SH);
@mkdir(dirname($dir));
Expand Down
2 changes: 1 addition & 1 deletion tests/sandbox/Policy.invocations.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ $latte->compile($template);
Assert::equal(
[
'tags' => Expect::type('array'),
'functions' => ['trim', 'trim', 'ns\\test'],
'functions' => ['trim', 'trim', 'ns\test'],
],
$policy->log,
);
Expand Down

0 comments on commit 4db7de1

Please sign in to comment.