\>(?:(?!\)/g', match: [ - 'match', - 'quote', - 'href', - ]), + actual: get_match( + subject: " Tempest ", + pattern: '/(?\ [\"\'])(? .+)\k \>(?:(?!\)/g', + match: [ + 'match', + 'quote', + 'href', + ], + ), ); } diff --git a/packages/support/tests/Str/ManipulatesStringTest.php b/packages/support/tests/Str/ManipulatesStringTest.php index 059f9f781..64778ab8a 100644 --- a/packages/support/tests/Str/ManipulatesStringTest.php +++ b/packages/support/tests/Str/ManipulatesStringTest.php @@ -328,10 +328,13 @@ public function test_replace_regex(): void public function test_match_all(): void { - $this->assertSame([ - ['Hello'], - ['Hello'], - ], str('Hello world, Hello universe')->matchAll('/Hello/')->toArray()); + $this->assertSame( + expected: [ + ['Hello'], + ['Hello'], + ], + actual: str('Hello world, Hello universe')->matchAll('/Hello/')->toArray(), + ); $this->assertSame( [ diff --git a/packages/upgrade/config/sets/tempest20.php b/packages/upgrade/config/sets/tempest20.php index e7f9c5018..f0fab4aa3 100644 --- a/packages/upgrade/config/sets/tempest20.php +++ b/packages/upgrade/config/sets/tempest20.php @@ -46,7 +46,7 @@ 'Tempest\Validation\Rules\NotNull' => 'Tempest\Validation\Rules\IsNotNull', 'Tempest\Validation\Rules\Numeric' => 'Tempest\Validation\Rules\IsNumeric', 'Tempest\Validation\Rules\Odd' => 'Tempest\Validation\Rules\IsOddNumber', - 'Tempest\Validation\Rules\Password' => 'Tempest\Validation\Rules\IsPassword', // @mago-expect security/no-literal-password + 'Tempest\Validation\Rules\Password' => 'Tempest\Validation\Rules\IsPassword', // @mago-expect lint:no-literal-password 'Tempest\Validation\Rules\PhoneNumber' => 'Tempest\Validation\Rules\IsPhoneNumber', 'Tempest\Validation\Rules\RegEx' => 'Tempest\Validation\Rules\MatchesRegEx', 'Tempest\Validation\Rules\Time' => 'Tempest\Validation\Rules\IsTime', diff --git a/packages/upgrade/src/Tempest2/MigrationRector.php b/packages/upgrade/src/Tempest2/MigrationRector.php index b2551ac9a..414cfe2c4 100644 --- a/packages/upgrade/src/Tempest2/MigrationRector.php +++ b/packages/upgrade/src/Tempest2/MigrationRector.php @@ -18,7 +18,7 @@ public function getNodeTypes(): array public function refactor(Node $node): void { - if (! ($node instanceof Node\Stmt\Class_)) { + if (! $node instanceof Node\Stmt\Class_) { return; } @@ -47,11 +47,11 @@ public function refactor(Node $node): void $migratesDown = true; foreach ($downStatements as $statement) { - if (! ($statement instanceof Node\Stmt\Return_)) { + if (! $statement instanceof Node\Stmt\Return_) { continue; } - if (! ($statement->expr instanceof Node\Expr\ConstFetch)) { + if (! $statement->expr instanceof Node\Expr\ConstFetch) { continue; } @@ -69,7 +69,7 @@ public function refactor(Node $node): void $statements = $node->stmts; foreach ($node->stmts as $key => $statement) { - if (! ($statement instanceof ClassMethod)) { + if (! $statement instanceof ClassMethod) { continue; } diff --git a/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php b/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php index a19846e05..c6d627480 100644 --- a/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php +++ b/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php @@ -17,7 +17,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?int { - if (! ($node instanceof Node\UseItem)) { + if (! $node instanceof Node\UseItem) { return null; } diff --git a/packages/upgrade/src/Tempest2/RemoveIdImportRector.php b/packages/upgrade/src/Tempest2/RemoveIdImportRector.php index 1bd81e465..d8b5ccf28 100644 --- a/packages/upgrade/src/Tempest2/RemoveIdImportRector.php +++ b/packages/upgrade/src/Tempest2/RemoveIdImportRector.php @@ -17,7 +17,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?int { - if (! ($node instanceof Node\UseItem)) { + if (! $node instanceof Node\UseItem) { return null; } diff --git a/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php b/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php index b57d3d958..0ee1a6f0c 100644 --- a/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php +++ b/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php @@ -16,7 +16,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?int { - if (! ($node instanceof Node\UseItem)) { + if (! $node instanceof Node\UseItem) { return null; } diff --git a/packages/validation/src/Rules/HasDateTimeFormat.php b/packages/validation/src/Rules/HasDateTimeFormat.php index 450c113fe..6e53f1287 100644 --- a/packages/validation/src/Rules/HasDateTimeFormat.php +++ b/packages/validation/src/Rules/HasDateTimeFormat.php @@ -54,7 +54,7 @@ private function validateNativeFormat(string $value): bool public function getTranslationVariables(): array { return [ - 'format' => ($this->format instanceof FormatPattern) + 'format' => $this->format instanceof FormatPattern ? $this->format->value : $this->format, ]; diff --git a/packages/validation/src/Rules/IsEnum.php b/packages/validation/src/Rules/IsEnum.php index 16a95d048..5f0d91a3e 100644 --- a/packages/validation/src/Rules/IsEnum.php +++ b/packages/validation/src/Rules/IsEnum.php @@ -80,7 +80,7 @@ public function getTranslationVariables(): array { $values = arr($this->enum::cases()) ->filter(fn (UnitEnum $case) => $this->isDesirable($case)) - ->map(static fn (UnitEnum $enum) => ($enum instanceof BackedEnum) ? $enum->value : $enum->name) + ->map(static fn (UnitEnum $enum) => $enum instanceof BackedEnum ? $enum->value : $enum->name) ->toArray(); return [ @@ -91,7 +91,7 @@ public function getTranslationVariables(): array ]; } - private function isDesirable($value): bool + private function isDesirable(mixed $value): bool { return match (true) { $this->only !== [] => in_array(needle: $value, haystack: $this->only, strict: true), diff --git a/packages/validation/src/Rules/IsFloat.php b/packages/validation/src/Rules/IsFloat.php index 2391d6ebd..27b0813c4 100644 --- a/packages/validation/src/Rules/IsFloat.php +++ b/packages/validation/src/Rules/IsFloat.php @@ -28,7 +28,7 @@ public function isValid(mixed $value): bool return false; } - // @mago-expect strictness/require-identity-comparison + // @mago-expect lint:identity-comparison return is_float($value) || floatval($value) == $value; } diff --git a/packages/validation/src/Rules/IsInteger.php b/packages/validation/src/Rules/IsInteger.php index 3177a684e..883647deb 100644 --- a/packages/validation/src/Rules/IsInteger.php +++ b/packages/validation/src/Rules/IsInteger.php @@ -28,7 +28,7 @@ public function isValid(mixed $value): bool return false; } - // @mago-expect strictness/require-identity-comparison + // @mago-expect lint:identity-comparison return is_int($value) || intval($value) == $value; } diff --git a/packages/view/src/Attributes/ElseAttribute.php b/packages/view/src/Attributes/ElseAttribute.php index 8c97d8288..250170834 100644 --- a/packages/view/src/Attributes/ElseAttribute.php +++ b/packages/view/src/Attributes/ElseAttribute.php @@ -16,7 +16,7 @@ public function apply(Element $element): Element { $previous = $element->getPrevious()?->unwrap(PhpIfElement::class); - if (! ($previous instanceof PhpIfElement)) { + if (! $previous instanceof PhpIfElement) { throw new ElementWasInvalid('There needs to be an if or elseif element before an else element.'); } diff --git a/packages/view/src/Attributes/ElseIfAttribute.php b/packages/view/src/Attributes/ElseIfAttribute.php index f7e7e9344..3649e2a2b 100644 --- a/packages/view/src/Attributes/ElseIfAttribute.php +++ b/packages/view/src/Attributes/ElseIfAttribute.php @@ -18,7 +18,7 @@ public function apply(Element $element): Element { $previous = $element->getPrevious()?->unwrap(PhpIfElement::class); - if (! ($previous instanceof PhpIfElement)) { + if (! $previous instanceof PhpIfElement) { throw new ElementWasInvalid('There needs to be an if or elseif element before an elseif element.'); } diff --git a/packages/view/src/Attributes/ForelseAttribute.php b/packages/view/src/Attributes/ForelseAttribute.php index 7e612c8d3..68133eec2 100644 --- a/packages/view/src/Attributes/ForelseAttribute.php +++ b/packages/view/src/Attributes/ForelseAttribute.php @@ -16,7 +16,7 @@ public function apply(Element $element): Element { $previous = $element->getPrevious()?->unwrap(PhpForeachElement::class); - if (! ($previous instanceof PhpForeachElement)) { + if (! $previous instanceof PhpForeachElement) { throw new ElementWasInvalid('There needs to be a foreach element before an forelse element.'); } diff --git a/packages/view/src/Elements/ElementFactory.php b/packages/view/src/Elements/ElementFactory.php index 8e368929f..6fd944376 100644 --- a/packages/view/src/Elements/ElementFactory.php +++ b/packages/view/src/Elements/ElementFactory.php @@ -43,10 +43,10 @@ public function make(Token $token): ?Element private function makeElement(Token $token, ?Element $parent): ?Element { if ( - $token->type === TokenType::OPEN_TAG_END || - $token->type === TokenType::ATTRIBUTE_NAME || - $token->type === TokenType::ATTRIBUTE_VALUE || - $token->type === TokenType::SELF_CLOSING_TAG_END + $token->type === TokenType::OPEN_TAG_END + || $token->type === TokenType::ATTRIBUTE_NAME + || $token->type === TokenType::ATTRIBUTE_VALUE + || $token->type === TokenType::SELF_CLOSING_TAG_END ) { return null; } diff --git a/packages/view/src/Elements/PhpDataElement.php b/packages/view/src/Elements/PhpDataElement.php index 3f1b2f059..9783210d5 100644 --- a/packages/view/src/Elements/PhpDataElement.php +++ b/packages/view/src/Elements/PhpDataElement.php @@ -42,8 +42,9 @@ public function compile(): string $localVariableName, $localVariableName, $isExpression + // @mago-expect lint:no-nested-ternary ? ($value ?: 'null') - : var_export($value, true), // @mago-expect best-practices/no-debug-symbols + : var_export($value, return: true), ); // And we'll remove it right after the element, this way we've created a "local scope" diff --git a/packages/view/src/Elements/ViewComponentElement.php b/packages/view/src/Elements/ViewComponentElement.php index bd9dd0db3..85f97735e 100644 --- a/packages/view/src/Elements/ViewComponentElement.php +++ b/packages/view/src/Elements/ViewComponentElement.php @@ -142,9 +142,9 @@ public function compile(): string // Open the current scope sprintf( '', - $this->dataAttributes->isNotEmpty() ? (', ' . $this->dataAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ')) : '', - $this->expressionAttributes->isNotEmpty() ? (', ' . $this->expressionAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ')) : '', - $this->scopedVariables->isNotEmpty() ? (', ' . $this->scopedVariables->map(fn (string $name) => "\${$name}")->implode(', ')) : '', + $this->dataAttributes->isNotEmpty() ? ', ' . $this->dataAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', + $this->expressionAttributes->isNotEmpty() ? ', ' . $this->expressionAttributes->map(fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', + $this->scopedVariables->isNotEmpty() ? ', ' . $this->scopedVariables->map(fn (string $name) => "\${$name}")->implode(', ') : '', ), ) ->append( @@ -157,10 +157,10 @@ public function compile(): string ? $this->scopedVariables->map(fn (string $name) => "'{$name}' => \${$name}")->implode(', ') : '', $this->dataAttributes->isNotEmpty() - ? (', ' . $this->dataAttributes->map(fn (mixed $value, string $key) => "{$key}: " . ViewObjectExporter::exportValue($value))->implode(', ')) + ? ', ' . $this->dataAttributes->map(fn (mixed $value, string $key) => "{$key}: " . ViewObjectExporter::exportValue($value))->implode(', ') : '', $this->expressionAttributes->isNotEmpty() - ? (', ' . $this->expressionAttributes->map(fn (mixed $value, string $key) => "{$key}: " . $value)->implode(', ')) + ? ', ' . $this->expressionAttributes->map(fn (mixed $value, string $key) => "{$key}: " . $value)->implode(', ') : '', ), ); @@ -183,7 +183,7 @@ public function compile(): string // A slot doesn't have any content, so we'll comment it out. // This is to prevent DOM parsing errors (slots in tags is one example, see #937) - return $this->environment->isProduction() ? '' : (''); + return $this->environment->isProduction() ? '' : ''; } $slotElement = $this->getSlotElement($slot->name); @@ -211,7 +211,7 @@ private function getSlotElement(string $name): SlotElement|CollectionElement|nul return $childElement; } - if (! ($childElement instanceof SlotElement)) { + if (! $childElement instanceof SlotElement) { $defaultElements[] = $childElement; } } diff --git a/packages/view/src/Export/ViewObjectExporter.php b/packages/view/src/Export/ViewObjectExporter.php index 1253f5dd7..9d736e3f7 100644 --- a/packages/view/src/Export/ViewObjectExporter.php +++ b/packages/view/src/Export/ViewObjectExporter.php @@ -40,7 +40,7 @@ public static function exportValue(mixed $value): string })->implode(', '), ), is_string($value) => "<<<'STRING'" . PHP_EOL . $value . PHP_EOL . 'STRING', - default => var_export($value, true), // @mago-expect best-practices/no-debug-symbols + default => var_export($value, return: true), }; } } diff --git a/packages/view/src/Parser/TempestViewCompiler.php b/packages/view/src/Parser/TempestViewCompiler.php index 39d9caf76..f2db687c3 100644 --- a/packages/view/src/Parser/TempestViewCompiler.php +++ b/packages/view/src/Parser/TempestViewCompiler.php @@ -73,7 +73,7 @@ private function removeComments(string $template): string private function retrieveTemplate(string|View $view): string { - $path = ($view instanceof View) ? $view->path : $view; + $path = $view instanceof View ? $view->path : $view; if (! str_ends_with($path, '.php')) { return $path; diff --git a/packages/view/tests/TempestViewLexerTest.php b/packages/view/tests/TempestViewLexerTest.php index 5ccbd5e9b..390f4d81a 100644 --- a/packages/view/tests/TempestViewLexerTest.php +++ b/packages/view/tests/TempestViewLexerTest.php @@ -20,20 +20,23 @@ public function test_lexer(): void $tokens = new TempestViewLexer($html)->lex(); - $this->assertTokens([ - new Token('', TokenType::OPEN_TAG_END), - new Token('', TokenType::OPEN_TAG_END), - new Token('hello', TokenType::CONTENT), - new Token(' ', TokenType::SELF_CLOSING_TAG), - new Token('', TokenType::CLOSING_TAG), - new Token("= 'hi' ?>", TokenType::PHP), - new Token('', TokenType::COMMENT), - new Token('', TokenType::CLOSING_TAG), - ], $tokens); + $this->assertTokens( + expected: [ + new Token('', TokenType::OPEN_TAG_END), + new Token('', TokenType::OPEN_TAG_END), + new Token('hello', TokenType::CONTENT), + new Token(' ', TokenType::SELF_CLOSING_TAG), + new Token('', TokenType::CLOSING_TAG), + new Token("= 'hi' ?>", TokenType::PHP), + new Token('', TokenType::COMMENT), + new Token('', TokenType::CLOSING_TAG), + ], + actual: $tokens, + ); } public function test_lex_php(): void @@ -42,9 +45,12 @@ public function test_lex_php(): void $tokens = new TempestViewLexer($code)->lex(); - $this->assertTokens([ - new Token($code, TokenType::PHP), - ], $tokens); + $this->assertTokens( + expected: [ + new Token($code, TokenType::PHP), + ], + actual: $tokens, + ); } public function test_lex_comment(): void @@ -53,9 +59,12 @@ public function test_lex_comment(): void $tokens = new TempestViewLexer($code)->lex(); - $this->assertTokens([ - new Token($code, TokenType::COMMENT), - ], $tokens); + $this->assertTokens( + expected: [ + new Token($code, TokenType::COMMENT), + ], + actual: $tokens, + ); } #[TestWith([' '])] @@ -63,31 +72,40 @@ public function test_lex_comment(): void #[TestWith([' '])] public function test_self_closing_tag_with_and_without_space(string $tag): void { - $this->assertTokens([ - new Token($tag, TokenType::SELF_CLOSING_TAG), - ], new TempestViewLexer($tag)->lex()); + $this->assertTokens( + expected: [ + new Token($tag, TokenType::SELF_CLOSING_TAG), + ], + actual: new TempestViewLexer($tag)->lex(), + ); } public function test_self_closing_tag_with_attributes(): void { $tokens = new TempestViewLexer(' ')->lex(); - $this->assertTokens([ - new Token(' ', TokenType::SELF_CLOSING_TAG_END), - ], $tokens); + $this->assertTokens( + expected: [ + new Token(' ', TokenType::SELF_CLOSING_TAG_END), + ], + actual: $tokens, + ); } #[TestWith([''])] public function test_closing_tag(string $tag): void { - $this->assertTokens([ - new Token($tag, TokenType::CLOSING_TAG), - ], new TempestViewLexer($tag)->lex()); + $this->assertTokens( + expected: [ + new Token($tag, TokenType::CLOSING_TAG), + ], + actual: new TempestViewLexer($tag)->lex(), + ); } public function test_multiline_attributes(): void @@ -105,25 +123,28 @@ class="abc" $tokens = new TempestViewLexer($html)->lex(); - $this->assertTokens([ - new Token(' assertTokens( + expected: [ + new Token('', TokenType::CLOSING_TAG), + ], + actual: $tokens, + ); } public function test_lexer_with_falsy_values(): void @@ -134,9 +155,12 @@ public function test_lexer_with_falsy_values(): void $tokens = new TempestViewLexer($html)->lex(); - $this->assertTokens([ - new Token('a0a', TokenType::CONTENT), - ], $tokens); + $this->assertTokens( + expected: [ + new Token('a0a', TokenType::CONTENT), + ], + actual: $tokens, + ); } public function test_lexer_attribute_values(): void @@ -144,7 +168,7 @@ public function test_lexer_attribute_values(): void $tokens = new TempestViewLexer('", TokenType::OPEN_TAG_END), - new Token(' + new Token(' :baz=', TokenType::ATTRIBUTE_NAME), + new Token('"true"', TokenType::ATTRIBUTE_VALUE), + new Token("\n>", TokenType::OPEN_TAG_END), + new Token(' ', TokenType::CONTENT), - new Token('', TokenType::CLOSING_TAG), - ], $tokens); + new Token('