Skip to content

Commit

Permalink
Apply fixes from StyleCI (#252)
Browse files Browse the repository at this point in the history
* Apply fixes from StyleCI

* Indent

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
kylekatarnls and StyleCIBot authored Sep 28, 2022
1 parent 88f8b0d commit 02fb8b9
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 33 deletions.
10 changes: 6 additions & 4 deletions src/Jade/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
);
}
}
13 changes: 8 additions & 5 deletions src/Jade/Compiler/AttributesCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/Jade/Compiler/CacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/Jade/Compiler/CompilerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
);
Expand Down
19 changes: 13 additions & 6 deletions src/Jade/Compiler/KeywordsCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);

Expand Down Expand Up @@ -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]
: ''
);
Expand Down
3 changes: 2 additions & 1 deletion src/Jade/Engine/PugJsEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) . ')')) . '));'
);
Expand Down
16 changes: 9 additions & 7 deletions src/Jade/Lexer/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ protected function parseSpace($states, $escapedAttribute, &$key, &$val, $char, $
}

$key = preg_replace(
array('/^[\'\"]|[\'\"]$/', '/\!/'), '', $key
array('/^[\'\"]|[\'\"]$/', '/\!/'),
'',
$key
);
$this->token->escaped[$key] = $escapedAttribute;

Expand All @@ -58,12 +60,12 @@ protected function replaceInterpolationsInStrings($match)

return str_replace('\\#{', '#{', preg_replace_callback('/(?<!\\\\)#{([^}]+)}/', function ($match) use ($quote) {
return $quote . ' . ' . CommonUtils::addDollarIfNeeded(preg_replace_callback(
'/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/',
function ($match) {
return CommonUtils::getGetter($match[1], $match[2]);
},
$match[1]
)) . ' . ' . $quote;
'/(?<![a-zA-Z0-9_\$])(\$?[a-zA-Z_][a-zA-Z0-9_]*)\.([a-zA-Z_][a-zA-Z0-9_]*)(?![a-zA-Z0-9_])/',
function ($match) {
return CommonUtils::getGetter($match[1], $match[2]);
},
$match[1]
)) . ' . ' . $quote;
}, $match[0]));
}

Expand Down
3 changes: 2 additions & 1 deletion src/Jade/Lexer/InputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ protected function getNextIndent()

$indents = isset($this->identRE)
? array($this->identRE)
: ($this->allowMixedIndent
: (
$this->allowMixedIndent
? array('[\\t ]*')
: array('\\t+', ' *')
);
Expand Down
6 changes: 4 additions & 2 deletions src/Jade/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('')
);
Expand Down
5 changes: 3 additions & 2 deletions src/Pug/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
});
}

Expand Down

0 comments on commit 02fb8b9

Please sign in to comment.