Skip to content

Commit

Permalink
coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 6, 2018
1 parent aa54845 commit 2e6dda0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/Latte/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ private function processHtmlTagEnd(Token $token): void
if ($htmlNode->closing) {
$this->htmlNode = $this->htmlNode->parentNode;

} elseif ((($lower = strtolower($htmlNode->name)) === 'script' || $lower === 'style')
} elseif (
(($lower = strtolower($htmlNode->name)) === 'script' || $lower === 'style')
&& (!isset($htmlNode->attrs['type']) || preg_match('#(java|j|ecma|live)script|json|css#i', $htmlNode->attrs['type']))
) {
$this->context = $lower === 'script' ? self::CONTEXT_HTML_JS : self::CONTEXT_HTML_CSS;
Expand Down Expand Up @@ -427,7 +428,8 @@ private function processHtmlAttributeBegin(Token $token): void
$this->context = self::CONTEXT_HTML_TAG;
}

if (in_array($this->contentType, [self::CONTENT_HTML, self::CONTENT_XHTML], true)
if (
in_array($this->contentType, [self::CONTENT_HTML, self::CONTENT_XHTML], true)
&& (in_array($lower, ['href', 'src', 'action', 'formaction'], true)
|| ($lower === 'data' && strtolower($this->htmlNode->name) === 'object'))
) {
Expand Down Expand Up @@ -495,7 +497,10 @@ public function closeMacro(string $name, string $args = null, string $modifiers
{
$node = $this->macroNode;

if (!$node || ($node->name !== $name && $name !== '') || $modifiers
if (
!$node
|| ($node->name !== $name && $name !== '')
|| $modifiers
|| ($args && $node->args && !Helpers::startsWith("$node->args ", "$args "))
|| $nPrefix !== $node->prefix
) {
Expand Down
7 changes: 5 additions & 2 deletions src/Latte/Compiler/PhpWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ public function validateTokens(MacroTokens $tokens): void
} elseif ($tokens->isCurrent(')', ']', '}') && $tokens->currentValue() !== array_pop($brackets)) {
throw new CompileException('Unexpected ' . $tokens->currentValue());

} elseif ($tokens->isCurrent('function', 'class', 'interface', 'trait') && $tokens->isNext($tokens::T_SYMBOL, '&')
|| $tokens->isCurrent('return', 'yield') && !$brackets
} elseif (
$tokens->isCurrent('function', 'class', 'interface', 'trait')
&& $tokens->isNext($tokens::T_SYMBOL, '&')
|| $tokens->isCurrent('return', 'yield')
&& !$brackets
) {
throw new CompileException("Forbidden keyword '{$tokens->currentValue()}' inside macro.");
}
Expand Down
12 changes: 10 additions & 2 deletions src/Latte/Macros/BlockMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ public function macroInclude(MacroNode $node, PhpWriter $writer)
$destination = ltrim($destination, '#');
$parent = $destination === 'parent';
if ($destination === 'parent' || $destination === 'this') {
for ($item = $node->parentNode; $item && $item->name !== 'block' && !isset($item->data->name); $item = $item->parentNode);
for (
$item = $node->parentNode;
$item && $item->name !== 'block' && !isset($item->data->name);
$item = $item->parentNode
);
if (!$item) {
throw new CompileException("Cannot include $destination block outside of any block.");
}
Expand Down Expand Up @@ -222,7 +226,11 @@ public function macroBlock(MacroNode $node, PhpWriter $writer)

} elseif (strpos($name, '$') !== false) { // dynamic block/snippet
if ($node->name === 'snippet') {
for ($parent = $node->parentNode; $parent && !($parent->name === 'snippet' || $parent->name === 'snippetArea'); $parent = $parent->parentNode);
for (
$parent = $node->parentNode;
$parent && !($parent->name === 'snippet' || $parent->name === 'snippetArea');
$parent = $parent->parentNode
);
if (!$parent) {
throw new CompileException('Dynamic snippets are allowed only inside static snippet/snippetArea.');
}
Expand Down
3 changes: 2 additions & 1 deletion src/Latte/Macros/CoreMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ public function macroExpr(MacroNode $node, PhpWriter $writer)
*/
public function macroContentType(MacroNode $node, PhpWriter $writer)
{
if (!$this->getCompiler()->isInHead()
if (
!$this->getCompiler()->isInHead()
&& !($node->htmlNode && strtolower($node->htmlNode->name) === 'script' && strpos($node->args, 'html') !== false)
) {
throw new CompileException($node->getNotation() . ' is allowed only in template header.');
Expand Down
6 changes: 4 additions & 2 deletions src/Latte/Macros/MacroSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ public function nodeOpened(MacroNode $node)
[$begin, $end, $attr] = $this->macros[$node->name];
$node->empty = !$end;

if ($node->modifiers
if (
$node->modifiers
&& (!$begin || (is_string($begin) && strpos($begin, '%modify') === false))
&& (!$end || (is_string($end) && strpos($end, '%modify') === false))
&& (!$attr || (is_string($attr) && strpos($attr, '%modify') === false))
) {
throw new CompileException('Modifiers are not allowed in ' . $node->getNotation());
}

if ($node->args
if (
$node->args
&& (!$begin || (is_string($begin) && strpos($begin, '%node') === false))
&& (!$end || (is_string($end) && strpos($end, '%node') === false))
&& (!$attr || (is_string($attr) && strpos($attr, '%node') === false))
Expand Down
3 changes: 2 additions & 1 deletion src/Latte/Runtime/SnippetDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function enter(string $name, string $type): void
return;
}
$obStarted = false;
if (($this->nestingLevel === 0 && $this->bridge->needsRedraw($name))
if (
($this->nestingLevel === 0 && $this->bridge->needsRedraw($name))
|| ($type === self::TYPE_DYNAMIC && ($previous = end($this->stack)) && $previous[1] === true)
) {
ob_start(function () {});
Expand Down

0 comments on commit 2e6dda0

Please sign in to comment.