Skip to content

Commit

Permalink
Use strict in_array
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Aug 29, 2023
1 parent 5b09677 commit 70fd86f
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/JsPhpize/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected function visitFunctionCall(FunctionCall $functionCall, $indent)

$functions = str_replace(["\n", "\t", "\r", ' '], '', static::STATIC_CALL_FUNCTIONS);

if ($applicant === 'new' || in_array($name, explode(',', $functions))) {
if ($applicant === 'new' || in_array($name, explode(',', $functions), true)) {
return $staticCall;
}

Expand Down Expand Up @@ -368,7 +368,7 @@ protected function wrapVariableChildren($children, $indent, $php, $options)
protected function visitVariable(Variable $variable, $indent, $options = 0)
{
$name = $variable->name;
if (in_array($name, ['Math', 'RegExp'])) {
if (in_array($name, ['Math', 'RegExp'], true)) {
$this->requireHelper(lcfirst($name) . 'Class');
}
if ($variable->scope) {
Expand Down
2 changes: 1 addition & 1 deletion src/JsPhpize/Compiler/DyiadeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function compileLazyDyiade($helper, $leftHand, $rightHand)
'$_SESSION',
'$_REQUEST',
'$_ENV',
]);
], true);
}));
$variables = array_map('strval', $variables);
$use = count($variables) ? ' use (&' . implode(', &', array_unique($variables)) . ')' : '';
Expand Down
4 changes: 2 additions & 2 deletions src/JsPhpize/Compiler/Helpers/MathClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ isset($Math) ? $Math : ($Math = [
return unpack('f', pack('f', $value))[1];
},
'fscale' => function ($value, $inLow, $inHigh, $outLow, $outHigh) {
if (in_array(NAN, [$value, $inLow, $inHigh, $outLow, $outHigh])) {
if (in_array(NAN, [$value, $inLow, $inHigh, $outLow, $outHigh], true)) {
return NAN;
}
return unpack('f', pack('f', (
Expand Down Expand Up @@ -108,7 +108,7 @@ isset($Math) ? $Math : ($Math = [
},
'round' => 'round',
'scale' => function ($value, $inLow, $inHigh, $outLow, $outHigh) {
if (in_array(NAN, [$value, $inLow, $inHigh, $outLow, $outHigh])) {
if (in_array(NAN, [$value, $inLow, $inHigh, $outLow, $outHigh], true)) {
return NAN;
}
if ($value === INF || $value === -INF) {
Expand Down
6 changes: 3 additions & 3 deletions src/JsPhpize/Lexer/DataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public function __construct($type, array $data)

public function is($value)
{
return in_array($value, [$this->type, $this->value]);
return in_array($value, [$this->type, $this->value], true);
}

public function typeIn($values)
{
return in_array($this->type, $values);
return in_array($this->type, $values, true);
}

public function valueIn($values)
{
return in_array($this->value, $values);
return in_array($this->value, $values, true);
}

public function __get($key)
Expand Down
2 changes: 1 addition & 1 deletion src/JsPhpize/Lexer/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function next()
$this->tokenGenerator = $pattern->lexWith($this);

if ($token = $this->pullFromCurrentTokenGenerator()) {
if (in_array($pattern->type, $this->disallow)) {
if (in_array($pattern->type, $this->disallow, true)) {
throw new Exception($pattern->type . ' is disallowed.', 3);
}

Expand Down
2 changes: 1 addition & 1 deletion src/JsPhpize/Lexer/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function isNeutral()

public function expectNoLeftMember()
{
return in_array($this->type, ['!', '~']) || $this->isVarOperator();
return in_array($this->type, ['!', '~'], true) || $this->isVarOperator();
}

public function isFunction()
Expand Down
6 changes: 3 additions & 3 deletions src/JsPhpize/Nodes/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getLetVariables()

public function isLet($variable)
{
return in_array($variable, $this->letVariables);
return in_array($variable, $this->letVariables, true);
}

public function handleInstructions()
Expand All @@ -84,7 +84,7 @@ public function handleInstructions()
'interface',
'class',
'switch',
]);
], true);
}

public function needParenthesis()
Expand All @@ -96,7 +96,7 @@ public function needParenthesis()
'for',
'while',
'function',
]);
], true);
}

public function addInstructions($instructions)
Expand Down
4 changes: 2 additions & 2 deletions src/JsPhpize/Nodes/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Constant extends Value implements Assignable
*/
public function __construct($type, $value, $dotChild = false)
{
if (!in_array($type, ['constant', 'number', 'string', 'regexp'])) {
if (!in_array($type, ['constant', 'number', 'string', 'regexp'], true)) {
throw new Exception("The given type [$type] is not a valid constant type.", 23);
}

Expand All @@ -54,7 +54,7 @@ public function getNonAssignableReason()
return "{$this->type} is not assignable.";
}

if (in_array($this->value, ['NAN', 'INF'])) {
if (in_array($this->value, ['NAN', 'INF'], true)) {
return "{$this->value} is not assignable.";
}

Expand Down
4 changes: 2 additions & 2 deletions src/JsPhpize/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ protected function parseParentheses($allowedSeparators = [',', ';'])
}

if ($expectComma) {
if ($token->is('in') && in_array('in', $allowedSeparators)) {
if ($token->is('in') && in_array('in', $allowedSeparators, true)) {
$parentheses->setSeparator('in');
$expectComma = false;

continue;
}

if ($token->isIn(',', ';') && in_array($token->type, $allowedSeparators)) {
if ($token->isIn(',', ';') && in_array($token->type, $allowedSeparators, true)) {
$expectComma = false;

continue;
Expand Down
2 changes: 1 addition & 1 deletion src/JsPhpize/Parser/TokenExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected function appendFunctionsCalls(&$value, $previousToken = null, $applica
$nextValue = new Constant('constant', $nextValue->name);
}

$value = $nextValue instanceof Constant && in_array($nextValue->value, ['Array', 'Object', 'String'])
$value = $nextValue instanceof Constant && in_array($nextValue->value, ['Array', 'Object', 'String'], true)
? new FunctionCall(new Variable('is_' . strtolower($nextValue->value), []), [$value], [])
: new Dyiade('instanceof', $value, $nextValue);

Expand Down
1 change: 1 addition & 0 deletions tests/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function caseProvider()

/**
* @group array
*
* @dataProvider caseProvider
*/
public function testArrayResult($expected, $code)
Expand Down
1 change: 1 addition & 0 deletions tests/compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function caseProvider()

/**
* @group examples
*
* @dataProvider caseProvider
*/
public function testJsPhpizeGeneration($phpFile, $jsFile)
Expand Down
2 changes: 1 addition & 1 deletion tests/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function testPatternsException()
'tokenClass' => 'TestToken',
]);
$jsPhpize->removePatterns(function (Pattern $pattern) {
return !in_array($pattern->type, ['number', 'operator']);
return !in_array($pattern->type, ['number', 'operator'], true);
});
$jsPhpize->compile('1 + 1');
}
Expand Down
1 change: 1 addition & 0 deletions tests/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function caseProvider()

/**
* @group examples
*
* @dataProvider caseProvider
*/
public function testJsPhpizeGeneration($returnFile, $jsFile)
Expand Down

0 comments on commit 70fd86f

Please sign in to comment.