Skip to content

Commit

Permalink
Use strict in_array checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Aug 29, 2023
1 parent 83ee812 commit ed50c8c
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Phug/Compiler/Compiler/Element/BlockElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getName()
*/
public function addCompiler(CompilerInterface $compiler)
{
if (!in_array($compiler, $this->compilers)) {
if (!in_array($compiler, $this->compilers, true)) {
$blocks = &$compiler->getBlocksByName($this->name);
$blocks[] = $this;
$this->compilers[] = $compiler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function isPugImport($path)
$extensions = $compiler->getOption('extensions');

if ($extension === '') {
return in_array('', $extensions);
return in_array('', $extensions, true);
}

if (!$compiler->getOption('allow_composite_extensions')) {
Expand Down Expand Up @@ -135,7 +135,7 @@ public function compileNode(NodeInterface $node, ElementInterface $parent = null
'input',
'meta',
'hr',
])) {
], true)) {
$yield = $yield->getParent();
}
if ($compiler->getImportNode()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/DependencyInjection/DependencyInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function get($name, array $exclude = [])
return call_user_func_array($this->cache[$cacheKey], func_get_args());
};
$arguments = array_map(function ($dependencyName) use ($exclude, $callee) {
return in_array($dependencyName, $exclude)
return in_array($dependencyName, $exclude, true)
? $callee
: $this->get($dependencyName, $exclude);
}, $dependency->getDependencies());
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public function formatDependencies()
}

foreach ($this->mixins->getRequirementsStates() as $key => $value) {
if ($value || $this->mixinsAllRequired || in_array($key, $this->mixinsPreCalled)) {
if ($value || $this->mixinsAllRequired || in_array($key, $this->mixinsPreCalled, true)) {
$dependencies .= $this->mixins->get($key);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Phug/Formatter/Formatter/AbstractFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function format($element, $noDebug = false)
if (is_a($element, $className)) {
$elementCode = $handler($element);
$debugCode = $debug ? $this->getDebugInfo($element) : '';
$glue = mb_strlen($debugCode) && in_array(mb_substr($elementCode, 0, 1), ["\n", "\r"])
$glue = mb_strlen($debugCode) && in_array(mb_substr($elementCode, 0, 1), ["\n", "\r"], true)
? "\n"
: '';

Expand Down Expand Up @@ -463,7 +463,7 @@ protected function formatDynamicValue($formattedName, $value)
if ($value instanceof ExpressionElement) {
$code = strtolower($value->getValue());

if (in_array($code, ['true', 'false', 'null', 'undefined'])) {
if (in_array($code, ['true', 'false', 'null', 'undefined'], true)) {
return $code;
}
}
Expand Down Expand Up @@ -770,7 +770,7 @@ protected function formatMixinElement(MixinElement $mixin)
' }',
' }',
' foreach ($__pug_mixin_vars as $__pug_key => &$__pug_value) {',
' if (!in_array($__pug_key, $__pug_names)) {',
' if (!in_array($__pug_key, $__pug_names, true)) {',
' $$__pug_key = &$__pug_value;',
' }',
' }',
Expand Down Expand Up @@ -869,7 +869,7 @@ protected function formatMixinCallElement(MixinCallElement $mixinCall)
'$__pug_mixin_vars = [];',
'foreach (array_keys(get_defined_vars()) as $__local_pug_key) {',
' if (mb_substr($__local_pug_key, 0, 6) === \'__pug_\' || '.
'in_array($__local_pug_key, [\'attributes\', \'block\', \''.$variablesVariable.'\'])) {',
'in_array($__local_pug_key, [\'attributes\', \'block\', \''.$variablesVariable.'\'], true)) {',
' continue;',
' }',
' $'.$variablesVariable.'[$__local_pug_key] = &$$__local_pug_key;',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractMarkupElement extends AbstractAssignmentContainerElement
public function belongsTo(array $tagList)
{
if (is_string($this->getName())) {
return in_array(strtolower($this->getName()), $tagList);
return in_array(strtolower($this->getName()), $tagList, true);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Phug/Formatter/Formatter/Element/CodeElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function isCodeBlockOpening()
T_TRAIT,
T_TRY,
T_WHILE,
]);
], true);
}

public function hasBlockContent()
Expand All @@ -106,7 +106,7 @@ public function needAccolades()
$this->isCodeBlockOpening() &&
!$this->hasBlockContent()
)
) && !in_array(end($tokens), [';', '{']);
) && !in_array(end($tokens), [';', '{', true]);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Phug/Formatter/Formatter/Format/XmlFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ protected function formatAttributeElement(AttributeElement $element)
if ($nonEmptyAttribute && (
!$value ||
($value instanceof TextElement && ((string) $value->getValue()) === '') ||
(is_string($value) && in_array(trim($value), ['', '""', "''"]))
(is_string($value) && in_array(trim($value), ['', '""', "''"], true))
)) {
return '';
}
if ($value instanceof ExpressionElement) {
if ($nonEmptyAttribute && in_array(trim($value->getValue()), ['', '""', "''"])) {
if ($nonEmptyAttribute && in_array(trim($value->getValue()), ['', '""', "''"], true)) {
return '';
}
if (strtolower($value->getValue()) === 'true') {
Expand Down Expand Up @@ -204,7 +204,7 @@ protected function formatAttributeElement(AttributeElement $element)
$formattedValue
);
}
if (in_array(strtolower($value->getValue()), ['false', 'null', 'undefined'])) {
if (in_array(strtolower($value->getValue()), ['false', 'null', 'undefined'], true)) {
return '';
}
}
Expand Down Expand Up @@ -487,7 +487,9 @@ protected function hasDuplicateAttributeNames(MarkupInterface $element)
$names = [];
foreach ($element->getAttributes() as $attribute) {
$name = $attribute->getName();
if (($name instanceof ExpressionElement && !$name->hasStaticValue()) || in_array($name, $names)) {
if (($name instanceof ExpressionElement && !$name->hasStaticValue()) ||
in_array($name, $names, true)
) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function provideAttributeAssignments()
'get_helper',
function ($availableAssignments, $getHelper) {
return function (&$attributes, $name, $value) use ($availableAssignments, $getHelper) {
if (!in_array($name, $availableAssignments)) {
if (!in_array($name, $availableAssignments, true)) {
return $value;
}

Expand Down Expand Up @@ -143,7 +143,7 @@ protected function provideArrayEscape()
'pattern.html_text_escape',
function ($arrayEscape, $escape) {
return function ($name, $input) use ($arrayEscape, $escape) {
if (is_array($input) && in_array(strtolower($name), ['class', 'style'])) {
if (is_array($input) && in_array(strtolower($name), ['class', 'style'], true)) {
$result = [];
foreach ($input as $key => $value) {
$result[$escape($key)] = $arrayEscape($name, $value);
Expand Down Expand Up @@ -183,7 +183,7 @@ protected function provideClassAttributeAssignment()
$input = $key;
}
foreach ($split($input) as $class) {
if (!in_array($class, $classes)) {
if (!in_array($class, $classes, true)) {
$classes[] = $class;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Phug/Formatter/Formatter/Partial/HandleVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private function isInFunctionParams(&$tokens, $index)
{
$afterOpen = false;
for ($i = $index - 1; $i >= 0; $i--) {
if (in_array($tokens[$i], [')', '}'])) {
if (in_array($tokens[$i], [')', '}'], true)) {
break;
}
if ($tokens[$i] === '(') {
Expand All @@ -34,7 +34,7 @@ private function isInFunctionParams(&$tokens, $index)
if ($afterOpen && is_array($tokens[$i]) && in_array($tokens[$i][0], [
T_FUNCTION,
T_USE,
])) {
], true)) {
return true;
}
}
Expand Down Expand Up @@ -102,13 +102,13 @@ private function isInExclusionContext(&$tokens, $index)
T_COMMENT,
T_DOC_COMMENT,
T_WHITESPACE,
])) {
], true)) {
continue;
}
break;
}

if (in_array($tokenId, $exclusions)) {
if (in_array($tokenId, $exclusions, true)) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Lexer/Lexer/Partial/IndentStyleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getIndentStyle()
*/
public function setIndentStyle($indentStyle)
{
if (!in_array($indentStyle, [null, Lexer::INDENT_TAB, Lexer::INDENT_SPACE])) {
if (!in_array($indentStyle, [null, Lexer::INDENT_TAB, Lexer::INDENT_SPACE], true)) {
throw new \InvalidArgumentException(
'indentStyle needs to be null or one of the INDENT_* constants of the lexer'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Lexer/Lexer/Scanner/ConditionalScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function scan(State $state)
//Make sure spaces are replaced from `elseif`/`else if` to make a final keyword, "elseif"
$token->setName(preg_replace('/[ \t]/', '', $token->getName()));

if ($token->getName() === 'else' && !in_array($token->getSubject(), ['', false, null])) {
if ($token->getName() === 'else' && !in_array($token->getSubject(), ['', false, null], true)) {
$state->throwException(
'The `else`-conditional statement can\'t have a subject'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Lexer/Lexer/Scanner/KeywordScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function scan(State $state)
)) {
$name = $reader->getMatch('name');

if (in_array($name, $keywords)) {
if (in_array($name, $keywords, true)) {
$value = $reader->getMatch('value');
if (mb_substr($value, 0, 1) === ' ') {
$value = mb_substr($value, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Lexer/Lexer/Scanner/TextScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TextScanner implements ScannerInterface

private function isTextStartToTrim(State $state, $text)
{
return in_array(mb_substr((string) $text, 0, 1), [' ', "\t"]) && !$state->isAfterInterpolation();
return in_array(mb_substr((string) $text, 0, 1), [' ', "\t"], true) && !$state->isAfterInterpolation();
}

private function leftTrimValueIfNotAfterInterpolation(State $state, TextToken $token)
Expand Down
4 changes: 2 additions & 2 deletions src/Phug/Phug/Phug/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function run($arguments)
return false;
}

if (!in_array($method, iterator_to_array($this->getAvailableMethods($customMethods)))) {
if (!in_array($method, iterator_to_array($this->getAvailableMethods($customMethods)), true)) {
echo "The method $action is not available as CLI command in the $facade facade.\n";
$this->listAvailableMethods($customMethods);

Expand Down Expand Up @@ -166,7 +166,7 @@ protected function execute($facade, $method, $arguments, $outputFile)
{
$callable = [$facade, $method];
$arguments = array_map(function ($argument) {
return in_array(substr((string) $argument, 0, 1), ['[', '{'])
return in_array(substr((string) $argument, 0, 1), ['[', '{'], true)
? json_decode($argument, true)
: $argument;
}, $arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Phug/Phug/Partial/ExtensionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function getExtensionsOptions(array $extensions, array $options =
*/
public static function hasExtension($extensionClassName)
{
return in_array(static::normalizeExtensionClassName($extensionClassName), static::getExtensionIds());
return in_array(static::normalizeExtensionClassName($extensionClassName), static::getExtensionIds(), true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Phug/Phug/Partial/FacadeOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected static function isOptionMethod($method)
'setOptionsRecursive',
'setOptionsDefaults',
'unsetOption',
]);
], true);
}

protected static function getFacadeOptions()
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Renderer/Renderer/Partial/AdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function getSandboxCall(&$source, $method, $path, $input, callable $getS
$adapter->displayCached($path, $input, $getSource, $parameters);
};

return in_array($method, ['display', 'displayFile'])
return in_array($method, ['display', 'displayFile'], true)
? $display()
: $adapter->captureBuffer($display);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function enableModule($moduleClassName, $className, ModuleContainerInt
{
/* @var ModuleContainerInterface $this */

if (in_array($className, class_implements($moduleClassName)) &&
if (in_array($className, class_implements($moduleClassName), true) &&
!$container->hasModule($moduleClassName)
) {
$container->addModule($moduleClassName);
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Renderer/Renderer/Profiler/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function dumpValue($object, $deep, $maxDeep = 3)
'string',
'resource',
'NULL',
])) {
], true)) {
return var_export($object, true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Renderer/Renderer/Profiler/ProfilerModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function initialize()

$this->eventDump = $this->getContainer()->getOption('profiler.dump_event');

if (in_array($this->eventDump, ['var_dump', 'print_r'])) {
if (in_array($this->eventDump, ['var_dump', 'print_r'], true)) {
$function = $this->eventDump;
$this->eventDump = function ($value) use ($function) {
return $this->getFunctionDump($value, $function);
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Util/Util/Partial/OptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function setOptionArrays(array $arrays, $functionName)

private function mergeOptionValue($name, $current, $addedValue, $functionName)
{
if ($functionName === $this->recursiveReplaceFunction && in_array($name, $this->nonDeepOptions)) {
if ($functionName === $this->recursiveReplaceFunction && in_array($name, $this->nonDeepOptions, true)) {
$functionName = $this->replaceFunction;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Util/Util/Partial/StaticMemberTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function hasStaticMember($member)
return
count($tokens) === 1 &&
is_array($tokens[0]) &&
in_array($tokens[0][0], [T_CONSTANT_ENCAPSED_STRING, T_DNUMBER, T_LNUMBER]);
in_array($tokens[0][0], [T_CONSTANT_ENCAPSED_STRING, T_DNUMBER, T_LNUMBER], true);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion tests/Phug/Ast/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public function testFind()
$nameIn = function ($node, $names) {
$pieces = preg_split('`[/\\\\]`', get_class($node));

return in_array(end($pieces), $names);
return in_array(end($pieces), $names, true);
};

self::assertSame([$a, $b, $c], $a->findArray(function ($node) use ($nameIn) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Phug/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public function testImplement()
*/
public function testAddModuleAsExtension()
{
$compilerHas1 = in_array(CompilerModule::class, Phug::getRenderer()->getCompiler()->getOption('modules'));
$compilerHas1 = in_array(CompilerModule::class, Phug::getRenderer()->getCompiler()->getOption('modules'), true);
$has1 = Phug::hasExtension(CompilerModule::class);
Phug::addExtension(CompilerModule::class);
$compilerHas2 = in_array(CompilerModule::class, Phug::getRenderer()->getCompiler()->getOption('modules'));
$compilerHas2 = in_array(CompilerModule::class, Phug::getRenderer()->getCompiler()->getOption('modules'), true);
$has2 = Phug::hasExtension(CompilerModule::class);
Phug::removeExtension(CompilerModule::class);
$compilerHas3 = in_array(CompilerModule::class, Phug::getRenderer()->getCompiler()->getOption('modules'));
$compilerHas3 = in_array(CompilerModule::class, Phug::getRenderer()->getCompiler()->getOption('modules'), true);
$has3 = Phug::hasExtension(CompilerModule::class);

self::assertFalse($has1);
Expand Down

0 comments on commit ed50c8c

Please sign in to comment.