From d8e0a30b2a90c7c2f6e92aeec411b7130aefc806 Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 8 Sep 2023 01:03:37 +0200 Subject: [PATCH] Use strict in_array checks in formatter (#110) * Use strict in_array checks in formatter * Use strict in_array checks in formatter * Use strict in_array checks in formatter * Upgrade multi-tester * Update multitester.yml --- .github/workflows/multitester.yml | 6 +++--- composer.json | 2 +- src/Phug/Formatter/Formatter.php | 2 +- src/Phug/Formatter/Formatter/AbstractFormat.php | 8 ++++---- src/Phug/Formatter/Formatter/Element/CodeElement.php | 2 +- src/Phug/Formatter/Formatter/Format/XmlFormat.php | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/multitester.yml b/.github/workflows/multitester.yml index cd0678ac..5becbb81 100644 --- a/.github/workflows/multitester.yml +++ b/.github/workflows/multitester.yml @@ -31,15 +31,15 @@ jobs: uses: actions/cache@v2 with: path: vendor - key: ${{ runner.os }}-php-multi-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-php-multi-v2-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} restore-keys: | - ${{ runner.os }}-php-multi-${{ matrix.php }}- + ${{ runner.os }}-php-multi-v2-${{ matrix.php }}- - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' run: | composer config version 1.9.0 - composer require kylekatarnls/multi-tester:^1.1 --no-update --no-interaction + composer require kylekatarnls/multi-tester:^2.3 --no-update --no-interaction composer update --prefer-dist --prefer-${{ matrix.setup }} --no-progress --no-interaction - name: Run test suites diff --git a/composer.json b/composer.json index 6294f5f5..ff9e9d5f 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "nodejs-php-fallback/uglify": "^1.0.4", "nodejs-php-fallback/stylus": "^1.0.4", "cebe/markdown": "^1.1", - "kylekatarnls/multi-tester": "^1.4" + "kylekatarnls/multi-tester": "^2.3" }, "replace": { "phug/ast": "self.version", diff --git a/src/Phug/Formatter/Formatter.php b/src/Phug/Formatter/Formatter.php index 1d1f7eae..307177ab 100644 --- a/src/Phug/Formatter/Formatter.php +++ b/src/Phug/Formatter/Formatter.php @@ -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); } } diff --git a/src/Phug/Formatter/Formatter/AbstractFormat.php b/src/Phug/Formatter/Formatter/AbstractFormat.php index 10fa316d..d49365cf 100644 --- a/src/Phug/Formatter/Formatter/AbstractFormat.php +++ b/src/Phug/Formatter/Formatter/AbstractFormat.php @@ -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" : ''; @@ -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; } } @@ -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;', ' }', ' }', @@ -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;', diff --git a/src/Phug/Formatter/Formatter/Element/CodeElement.php b/src/Phug/Formatter/Formatter/Element/CodeElement.php index 77ef73dd..d240a77c 100644 --- a/src/Phug/Formatter/Formatter/Element/CodeElement.php +++ b/src/Phug/Formatter/Formatter/Element/CodeElement.php @@ -106,7 +106,7 @@ public function needAccolades() $this->isCodeBlockOpening() && !$this->hasBlockContent() ) - ) && !in_array(end($tokens), [';', '{']); + ) && !in_array(end($tokens), [';', '{'], true); } /** diff --git a/src/Phug/Formatter/Formatter/Format/XmlFormat.php b/src/Phug/Formatter/Formatter/Format/XmlFormat.php index 6b61c928..e7b885df 100644 --- a/src/Phug/Formatter/Formatter/Format/XmlFormat.php +++ b/src/Phug/Formatter/Formatter/Format/XmlFormat.php @@ -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') { @@ -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 ''; } }