diff --git a/src/Jade/Compiler.php b/src/Jade/Compiler.php index 2a504a97..0386767e 100644 --- a/src/Jade/Compiler.php +++ b/src/Jade/Compiler.php @@ -52,7 +52,7 @@ class Compiler extends Options /** * @param array/Jade $options - * @param array $filters + * @param array $filters */ public function __construct($options = array(), array $filters = array(), $filename = null, $jsPhpize = null) { @@ -389,9 +389,11 @@ protected function createPhpBlock($code, $statements = null) */ protected function createCode($code) { - return $this->createPhpBlock($code, func_num_args() > 1 - ? $this->apply('createStatements', array_slice(func_get_args(), 1)) - : null + return $this->createPhpBlock( + $code, + func_num_args() > 1 + ? $this->apply('createStatements', array_slice(func_get_args(), 1)) + : null ); } } diff --git a/src/Jade/Compiler/AttributesCompiler.php b/src/Jade/Compiler/AttributesCompiler.php index ef34a00f..55774fbd 100644 --- a/src/Jade/Compiler/AttributesCompiler.php +++ b/src/Jade/Compiler/AttributesCompiler.php @@ -21,9 +21,10 @@ protected function getAttributeDisplayCode($key, $value, $valueCheck) protected function getBooleanAttributeDisplayCode($key) { - return ' ' . $key . ($this->terse - ? '' - : '=' . $this->quote . $key . $this->quote + return ' ' . $key . ( + $this->terse + ? '' + : '=' . $this->quote . $key . $this->quote ); } @@ -64,7 +65,8 @@ protected function getAndAttributeCode($attr, &$classes, &$classesCheck) 'unset($__attributes["class"]); ' . '} ' . '} ' . - '\\Jade\\Compiler::displayAttributes($__attributes, ' . var_export($this->quote, true) . ', ' . var_export($this->terse, true) . ');'); + '\\Jade\\Compiler::displayAttributes($__attributes, ' . var_export($this->quote, true) . ', ' . var_export($this->terse, true) . ');' + ); } protected function getClassAttribute($value, &$classesCheck) @@ -117,7 +119,8 @@ protected function compileAttributeValue($key, $value, $attr, $valueCheck) { return $value === true || $attr['value'] === true ? $this->getBooleanAttributeDisplayCode($key) - : ($value !== false && $attr['value'] !== false && $value !== 'null' && $value !== 'undefined' + : ( + $value !== false && $attr['value'] !== false && $value !== 'null' && $value !== 'undefined' ? $this->getAttributeDisplayCode( $key, $this->escapeValueIfNeeded($value, $attr['escaped'], $valueCheck), diff --git a/src/Jade/Compiler/CacheHelper.php b/src/Jade/Compiler/CacheHelper.php index 369bff4e..1fda846b 100644 --- a/src/Jade/Compiler/CacheHelper.php +++ b/src/Jade/Compiler/CacheHelper.php @@ -65,7 +65,7 @@ protected function hashPrint($input) * Return true if the file or content is up to date in the cache folder, * false else. * - * @param string $input file or pug code + * @param string $input file or pug code * @param &string $path to be filled * * @return bool diff --git a/src/Jade/Compiler/CompilerFacade.php b/src/Jade/Compiler/CompilerFacade.php index 751d9d8c..f0115dcd 100644 --- a/src/Jade/Compiler/CompilerFacade.php +++ b/src/Jade/Compiler/CompilerFacade.php @@ -82,9 +82,11 @@ public static function getPropertyFromObject($anything, $key) { return isset($anything->$key) ? $anything->$key - : (method_exists($anything, $method = 'get' . ucfirst($key)) + : ( + method_exists($anything, $method = 'get' . ucfirst($key)) ? $anything->$method() - : (method_exists($anything, $key) + : ( + method_exists($anything, $key) ? array($anything, $key) : null ) @@ -102,10 +104,12 @@ public static function getPropertyFromObject($anything, $key) public static function getPropertyFromAnything($anything, $key) { return is_array($anything) - ? (isset($anything[$key]) + ? ( + isset($anything[$key]) ? $anything[$key] : null - ) : (is_object($anything) + ) : ( + is_object($anything) ? static::getPropertyFromObject($anything, $key) : null ); diff --git a/src/Jade/Compiler/KeywordsCompiler.php b/src/Jade/Compiler/KeywordsCompiler.php index c9516f3e..f0fae61a 100644 --- a/src/Jade/Compiler/KeywordsCompiler.php +++ b/src/Jade/Compiler/KeywordsCompiler.php @@ -104,19 +104,24 @@ protected function visitEach(Each $node) if (isset($node->alternative)) { $this->buffer($this->createCode( 'if (isset(%s) && %s) {', - $node->obj, $node->obj + $node->obj, + $node->obj )); $this->indents++; } - $this->buffer(isset($node->key) && strlen($node->key) > 0 + $this->buffer( + isset($node->key) && strlen($node->key) > 0 ? $this->createCode( 'foreach (%s as %s => %s) {', - $node->obj, $node->key, $node->value + $node->obj, + $node->key, + $node->value ) : $this->createCode( 'foreach (%s as %s) {', - $node->obj, $node->value + $node->obj, + $node->value ) ); @@ -175,10 +180,12 @@ protected function visitCustomKeyword(CustomKeyword $node) } foreach (array('begin', 'end') as $key) { - $data[$key] = (isset($data[$key . 'Php']) + $data[$key] = ( + isset($data[$key . 'Php']) ? $this->createCode($data[$key . 'Php']) : '' - ) . (isset($data[$key]) + ) . ( + isset($data[$key]) ? $data[$key] : '' ); diff --git a/src/Jade/Engine/PugJsEngine.php b/src/Jade/Engine/PugJsEngine.php index 28efa72b..6a7f198e 100644 --- a/src/Jade/Engine/PugJsEngine.php +++ b/src/Jade/Engine/PugJsEngine.php @@ -90,7 +90,8 @@ protected function getHtml($file, array &$options) $directory = dirname($file); $renderFile = './render.' . time() . mt_rand(0, 999999999) . '.js'; chdir($directory); - file_put_contents($renderFile, + file_put_contents( + $renderFile, 'console.log(require(' . json_encode($realPath) . ')' . '(' . (empty($options['obj']) ? '{}' : (!$this->options['localsJsonFile'] ? $options['obj'] : 'require(' . json_encode($options['obj']) . ')')) . '));' ); diff --git a/src/Jade/Lexer/Attributes.php b/src/Jade/Lexer/Attributes.php index 09cb9d9c..c80772a9 100644 --- a/src/Jade/Lexer/Attributes.php +++ b/src/Jade/Lexer/Attributes.php @@ -42,7 +42,9 @@ protected function parseSpace($states, $escapedAttribute, &$key, &$val, $char, $ } $key = preg_replace( - array('/^[\'\"]|[\'\"]$/', '/\!/'), '', $key + array('/^[\'\"]|[\'\"]$/', '/\!/'), + '', + $key ); $this->token->escaped[$key] = $escapedAttribute; @@ -58,12 +60,12 @@ protected function replaceInterpolationsInStrings($match) return str_replace('\\#{', '#{', preg_replace_callback('/(?identRE) ? array($this->identRE) - : ($this->allowMixedIndent + : ( + $this->allowMixedIndent ? array('[\\t ]*') : array('\\t+', ' *') ); diff --git a/src/Jade/Parser.php b/src/Jade/Parser.php index ad61430d..d94c7ab4 100644 --- a/src/Jade/Parser.php +++ b/src/Jade/Parser.php @@ -70,7 +70,8 @@ protected function getTemplatePath($path) throw new \ErrorException("The 'basedir' option need to be set to use absolute path like $path", 29); } - $path = ($isAbsolutePath + $path = ( + $isAbsolutePath ? rtrim($this->options['basedir'], '/\\') : dirname($this->filename) ) . DIRECTORY_SEPARATOR . $path; @@ -415,7 +416,8 @@ protected function parseBlock() $block = 'indent' === $this->peekType() ? $this->block() - : new Nodes\Block(empty($name) + : new Nodes\Block( + empty($name) ? new Nodes\MixinBlock() : new Nodes\Literal('') ); diff --git a/src/Pug/Filter/AbstractFilter.php b/src/Pug/Filter/AbstractFilter.php index 5c0ba11e..7c2c4eb8 100644 --- a/src/Pug/Filter/AbstractFilter.php +++ b/src/Pug/Filter/AbstractFilter.php @@ -24,10 +24,11 @@ abstract class AbstractFilter implements JadeFilterInterface protected function getNodeString(Filter $node, Compiler $compiler = null) { return array_reduce($node->block->nodes, function ($result, $line) use ($compiler) { - return $result . ($compiler + return $result . ( + $compiler ? $compiler->interpolate($line->value) : $line->value - ) . "\n"; + ) . "\n"; }); }