From 7b27be06a94f18354bc68ebdbd37fbec1eac968c Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:10:50 +0100 Subject: [PATCH 01/14] Update mago --- composer.json | 2 +- mago.toml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index ce22082b6..72713f265 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "aws/aws-sdk-php": "^3.338.0", "azure-oss/storage-blob-flysystem": "^1.2", "brianium/paratest": "^7.14", - "carthage-software/mago": "1.0.0-beta.28", + "carthage-software/mago": "^1.0", "guzzlehttp/psr7": "^2.6.1", "league/flysystem-aws-s3-v3": "^3.25.1", "league/flysystem-ftp": "^3.25.1", diff --git a/mago.toml b/mago.toml index 2dd509090..f4bb4ab79 100644 --- a/mago.toml +++ b/mago.toml @@ -42,12 +42,12 @@ trait-name = { psr = false } class-name = { psr = false } literal-named-argument = { enabled = false } # todo no-error-control-operator = { enabled = false } -no-boolean-literal-comparison = { enabled = false } +#no-boolean-literal-comparison = { enabled = false } too-many-methods = { enabled = false } kan-defect = { enabled = false } cyclomatic-complexity = { enabled = false } -return-type = { ignore-arrow-function = true, ignore-closure = true } -parameter-type = { ignore-arrow-function = true, ignore-closure = true } +#return-type = { ignore-arrow-function = true, ignore-closure = true } +#parameter-type = { ignore-arrow-function = true, ignore-closure = true } too-many-enum-cases = { enabled = false } no-redundant-file = { enabled = false } assertion-style = { style = "this" } From ef0fad18e8939764fbdc5a57af1ffc2986abaf91 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:11:42 +0100 Subject: [PATCH 02/14] Run mago --- .../src/Authentication/Authenticatable.php | 4 +- .../Exceptions/AuthenticationException.php | 4 +- .../src/Exceptions/OAuthStateWasInvalid.php | 4 +- packages/auth/src/OAuth/OAuthConfig.php | 16 +- packages/cache/src/Cache.php | 5 +- packages/cache/src/CacheCouldNotBeCleared.php | 4 +- packages/cache/src/CacheException.php | 4 +- packages/cache/src/Lock.php | 12 +- packages/command-bus/src/Async.php | 4 +- packages/console/src/CanOpenInEditor.php | 4 +- packages/console/src/Console.php | 4 +- packages/console/src/HasStaticComponent.php | 4 +- .../console/src/Scheduler/NullScheduler.php | 4 +- packages/console/tests/TextBufferTest.php | 40 +- packages/container/src/Autowire.php | 4 +- .../src/Exceptions/ContainerException.php | 4 +- packages/container/src/HasTag.php | 4 +- packages/container/src/Proxy.php | 4 +- packages/container/tests/ContainerTest.php | 6 +- .../CannotAutowireExceptionTest.php | 10 +- .../CircularDependencyExceptionTest.php | 22 +- .../tests/Fixtures/ContainerObjectA.php | 4 +- .../tests/Fixtures/DecoratedClass.php | 4 +- .../tests/Fixtures/DecoratedInterface.php | 4 +- .../Fixtures/DecoratorWithoutConstructor.php | 4 +- .../tests/Fixtures/ImplementsInterfaceA.php | 4 +- packages/container/tests/Fixtures/InjectB.php | 4 +- .../container/tests/Fixtures/InterfaceA.php | 4 +- .../tests/Fixtures/UnionImplementation.php | 4 +- .../tests/Fixtures/UnionInterfaceA.php | 4 +- .../tests/Fixtures/UnionInterfaceB.php | 4 +- .../src/ComposerJsonCouldNotBeLocated.php | 4 +- packages/core/src/InsightsProvider.php | 4 +- packages/core/src/Installer.php | 4 +- packages/core/src/Kernel.php | 30 +- .../cryptography/src/Encryption/Encrypter.php | 4 +- .../Exceptions/EncryptionException.php | 4 +- .../Exceptions/PasswordHashingException.php | 4 +- .../src/Password/PasswordHasher.php | 4 +- .../src/Password/PasswordHashingConfig.php | 8 +- .../Signing/Exceptions/SigningException.php | 4 +- packages/cryptography/src/Signing/Signer.php | 4 +- .../src/Builder/QueryBuilders/BuildsQuery.php | 12 +- .../Builder/QueryBuilders/QueryBuilder.php | 6 +- .../QueryBuilders/SelectQueryBuilder.php | 3 +- .../Builder/QueryBuilders/SupportsJoins.php | 4 +- .../QueryBuilders/SupportsRelations.php | 4 +- .../QueryBuilders/SupportsWhereStatements.php | 4 +- .../database/src/Config/DatabaseConfig.php | 32 +- packages/database/src/Database.php | 8 +- packages/database/src/Eager.php | 4 +- .../src/Exceptions/DatabaseException.php | 4 +- .../database/src/HasLeadingStatements.php | 4 +- .../database/src/HasTrailingStatements.php | 4 +- packages/database/src/Lazy.php | 4 +- packages/database/src/MigratesDown.php | 4 +- packages/database/src/MigratesUp.php | 4 +- .../src/Migrations/MigrationException.php | 4 +- .../CreateEnumTypeStatement.php | 4 +- .../QueryStatements/DropEnumTypeStatement.php | 4 +- .../QueryStatements/HasWhereStatements.php | 4 +- .../QueryStatements/ShowTablesStatement.php | 10 +- packages/database/src/Relation.php | 4 +- packages/database/src/Uuid.php | 4 +- packages/database/src/Virtual.php | 4 +- .../CreateTableStatementTest.php | 170 ++-- .../QueryBuilderGenericsTypeAssertions.php | 4 +- .../src/Exception/DateTimeException.php | 4 +- .../src/Exception/OverflowException.php | 4 +- .../src/Exception/ParserException.php | 4 +- .../src/Exception/RuntimeException.php | 4 +- .../src/Exception/UnderflowException.php | 4 +- packages/debug/src/Debug.php | 20 +- packages/event-bus/src/StopsPropagation.php | 4 +- .../tests/Fixtures/EventInterface.php | 4 +- .../Fixtures/EventInterfaceImplementation.php | 4 +- .../event-bus/tests/Fixtures/ItHappened.php | 4 +- .../Exceptions/FileGenerationException.php | 4 +- .../Exceptions/FileGenerationWasAborted.php | 4 +- packages/generation/src/TypeScript/AsType.php | 4 +- .../TypeScript/TypeScriptGenerationConfig.php | 14 +- .../tests/Php/ClassGeneratorTest.php | 32 +- .../tests/Php/Fixtures/ClassFromFile.php | 4 +- .../ClassWithMethodParameterAttributes.php | 3 +- .../Fixtures/SampleNamespace/DummyFqcn.php | 4 +- .../Fixtures/SampleNamespace/ExampleTrait.php | 4 +- .../SampleParameterAttribute.php | 4 +- .../tests/Php/Fixtures/TestAttribute.php | 4 +- packages/http/src/Request.php | 36 +- packages/http/src/Response.php | 12 +- packages/http/src/Responses/Download.php | 3 +- packages/http/src/Responses/File.php | 3 +- packages/http/src/SensitiveField.php | 4 +- packages/http/src/ServerSentEvent.php | 16 +- packages/http/src/Session/SessionConfig.php | 4 +- .../src/Exceptions/IdempotencyException.php | 4 +- .../tests/IdempotentCommandMiddlewareTest.php | 4 +- packages/intl/bin/plural-rules.php | 188 ++--- .../src/MessageFormat/FormattingFunction.php | 4 +- .../Parser/Node/Declaration/Declaration.php | 4 +- .../src/MessageFormat/Parser/Node/Key/Key.php | 4 +- .../Parser/Node/Key/WildcardKey.php | 4 +- .../Parser/Node/Literal/QuotedLiteral.php | 4 +- .../Parser/Node/Literal/UnquotedLiteral.php | 4 +- .../src/MessageFormat/Parser/Node/Node.php | 4 +- .../Parser/Node/Pattern/Placeholder.php | 4 +- .../Parser/Node/SimpleMessage.php | 4 +- .../src/MessageFormat/SelectorFunction.php | 4 +- packages/intl/tests/FormatterTest.php | 222 ++--- packages/intl/tests/GenericTranslatorTest.php | 12 +- packages/intl/tests/ParserTest.php | 22 +- .../kv-store/src/Redis/RedisException.php | 4 +- packages/log/src/LogConfig.php | 8 +- packages/log/src/Logger.php | 4 +- packages/mail/src/Email.php | 8 +- .../mail/src/Exceptions/MailerException.php | 4 +- packages/mail/src/HasAttachments.php | 4 +- packages/mail/src/HasTextContent.php | 4 +- packages/mail/src/MailerConfig.php | 4 +- .../src/Transports/ProvidesDefaultSender.php | 4 +- packages/mapper/src/Context.php | 4 +- packages/mapper/src/Hidden.php | 4 +- packages/mapper/src/ProvidesCaster.php | 4 +- packages/mapper/src/ProvidesSerializer.php | 4 +- packages/mapper/src/Strict.php | 4 +- packages/mapper/src/UnknownValue.php | 4 +- .../src/Exceptions/ProcessException.php | 4 +- packages/process/src/InvokedProcess.php | 16 +- packages/reflection/src/PropertyAttribute.php | 5 +- .../reflection/tests/EnumReflectorTest.php | 4 +- .../tests/Fixtures/AnnulledInvoice.php | 4 +- .../Fixtures/ChildWithRecursiveAttribute.php | 4 +- ...assWithInterfaceWithRecursiveAttribute.php | 4 +- .../InterfaceWithRecursiveAttribute.php | 4 +- .../tests/Fixtures/NullableClass.php | 4 +- .../Fixtures/ParentWithRecursiveAttribute.php | 4 +- .../tests/Fixtures/RecursiveAttribute.php | 4 +- .../tests/Fixtures/TestBackedEnum.php | 4 +- .../reflection/tests/Fixtures/TestEnum.php | 4 +- .../src/Exceptions/RouteBindingFailed.php | 4 +- .../router/src/Exceptions/RouterException.php | 4 +- packages/router/src/IsBindingValue.php | 4 +- packages/router/src/Route.php | 20 +- .../Static/Exceptions/StaticPageException.php | 4 +- packages/router/tests/FakeRouteBuilder.php | 4 +- .../FakeRouteBuilderWithOptionalParams.php | 16 +- packages/storage/src/Config/StorageConfig.php | 9 +- packages/storage/src/StorageException.php | 4 +- .../support/src/Arr/OffsetDidNotExist.php | 4 +- .../Exceptions/FilesystemException.php | 4 +- .../Exceptions/RuntimeException.php | 4 +- .../support/src/JavaScript/PackageManager.php | 6 +- .../Json/Exception/JsonCouldNotBeDecoded.php | 4 +- .../Json/Exception/JsonCouldNotBeEncoded.php | 4 +- .../src/Json/Exception/JsonException.php | 4 +- .../Math/Exception/ArithmeticException.php | 4 +- .../Exception/DivisionByZeroException.php | 4 +- .../Exception/InvalidArgumentException.php | 4 +- .../src/Math/Exception/MathException.php | 4 +- .../src/Math/Exception/OverflowException.php | 4 +- packages/support/src/Namespace/functions.php | 8 +- .../Exceptions/ArgumentWasInvalid.php | 4 +- .../Exceptions/PaginationException.php | 4 +- .../src/Regex/InvalidPatternException.php | 4 +- packages/support/src/Str/StringInterface.php | 4 +- .../src/VarExport/EmptyFileNameException.php | 4 +- .../VarExport/FileDoesNotExistException.php | 4 +- .../src/VarExport/VarExportPhpFile.php | 6 +- packages/support/tests/Json/JsonTest.php | 28 +- packages/validation/src/SkipValidation.php | 4 +- .../view/src/Components/x-component.view.php | 8 +- .../view/src/Export/ExportableViewObject.php | 4 +- packages/view/src/ShouldBeRemoved.php | 4 +- packages/view/src/View.php | 12 +- packages/view/src/WithToken.php | 4 +- .../view/tests/FallthroughAttributesTest.php | 10 +- .../view/tests/StandaloneViewRendererTest.php | 24 +- packages/view/tests/TempestViewLexerTest.php | 52 +- packages/view/tests/TempestViewParserTest.php | 40 +- .../EntrypointNotFoundException.php | 4 +- .../vite/src/Exceptions/ViteException.php | 4 +- .../TagsResolver/DevelopmentTagsResolver.php | 16 +- .../src/TagsResolver/ManifestTagsResolver.php | 66 +- .../Framework/Testing/IntegrationTest.php | 3 +- .../Benchmark/Extension/MarkdownExtension.php | 4 +- .../Extension/MarkdownRendererTest.php | 34 +- .../Commands/HelloWorldTestCommand.php | 4 +- tests/Fixtures/Commands/MyBrokenCommand.php | 4 +- tests/Fixtures/Commands/MyCommand.php | 4 +- .../Console/CommandWithDifferentArguments.php | 3 +- tests/Fixtures/Console/StylingCommand.php | 3 +- tests/Fixtures/Controllers/DocsController.php | 4 +- .../EventForListenerWithoutPropagation.php | 4 +- tests/Fixtures/Events/EventInterface.php | 4 +- .../Events/EventInterfaceImplementation.php | 4 +- .../Events/EventWithoutPropagation.php | 4 +- tests/Fixtures/Events/ItHappened.php | 4 +- tests/Fixtures/GlobalHiddenDiscovery.php | 4 +- tests/Fixtures/GlobalHiddenPathDiscovery.php | 4 +- tests/Fixtures/Handlers/MyCommandHandler.php | 4 +- tests/Fixtures/TestInstallerClass.php | 4 +- .../Static/StaticProgressBarComponentTest.php | 10 +- .../Static/StaticSearchComponentTest.php | 32 +- .../Fixtures/CommandWithNonCommandMethods.php | 12 +- .../Fixtures/CompletionTestCommand.php | 3 +- .../Console/Fixtures/MyConsole.php | 3 +- .../Integration/Console/Fixtures/Package.php | 7 +- .../Console/Fixtures/TestConsoleException.php | 4 +- .../Scheduler/GenericSchedulerTest.php | 8 +- .../Scheduler/HandlerInvocationTest.php | 4 +- .../Core/Config/LoadConfigTest.php | 12 +- .../Integration/Core/Fixtures/MiddlewareA.php | 4 +- .../Integration/Core/Fixtures/MiddlewareB.php | 4 +- .../Integration/Core/Fixtures/MiddlewareC.php | 4 +- .../Core/Fixtures/MiddlewareFramework.php | 4 +- .../Core/Fixtures/MiddlewareHigh.php | 4 +- .../Core/Fixtures/MiddlewareHighest.php | 4 +- .../Core/Fixtures/MiddlewareLow.php | 4 +- .../Core/Fixtures/MiddlewareLowest.php | 4 +- .../Core/Fixtures/MiddlewareNormal.php | 4 +- .../Builder/InsertQueryBuilderTest.php | 8 +- .../Builder/SelectQueryBuilderTest.php | 16 +- .../Builder/UpdateQueryBuilderTest.php | 8 +- .../Database/GenericDatabaseTest.php | 6 +- .../QueryStatements/CompoundStatementTest.php | 6 +- .../CreateEnumTypeStatementTest.php | 4 +- .../DropEnumTypeStatementTest.php | 4 +- .../Commands/MetaViewComponentCommandTest.php | 54 +- .../Http/Exceptions/ExceptionRendererTest.php | 4 +- tests/Integration/Mailer/SentEmailTest.php | 30 +- .../View/BladeViewRendererTest.php | 8 +- .../View/Components/MarkdownComponentTest.php | 8 +- tests/Integration/View/ElementFactoryTest.php | 20 +- ...estViewRendererCombinedExpressionsTest.php | 66 +- .../TempestViewRendererDataPassingTest.php | 152 ++-- .../View/TempestViewRendererTest.php | 440 +++++----- .../Integration/View/TwigViewRendererTest.php | 8 +- .../View/ViewComponentDiscoveryTest.php | 8 +- tests/Integration/View/ViewComponentTest.php | 796 +++++++++--------- tests/Integration/View/ViewTest.php | 4 +- .../Vite/ManifestTagsResolverTest.php | 4 +- .../Vite/ViteTagsComponentTest.php | 148 ++-- 242 files changed, 1717 insertions(+), 2186 deletions(-) diff --git a/packages/auth/src/Authentication/Authenticatable.php b/packages/auth/src/Authentication/Authenticatable.php index 6abf1008f..6db39727e 100644 --- a/packages/auth/src/Authentication/Authenticatable.php +++ b/packages/auth/src/Authentication/Authenticatable.php @@ -7,6 +7,4 @@ /** * Represents an entity that may be authenticated. */ -interface Authenticatable -{ -} +interface Authenticatable {} diff --git a/packages/auth/src/Exceptions/AuthenticationException.php b/packages/auth/src/Exceptions/AuthenticationException.php index c7c62e082..acaea6737 100644 --- a/packages/auth/src/Exceptions/AuthenticationException.php +++ b/packages/auth/src/Exceptions/AuthenticationException.php @@ -2,6 +2,4 @@ namespace Tempest\Auth\Exceptions; -interface AuthenticationException -{ -} +interface AuthenticationException {} diff --git a/packages/auth/src/Exceptions/OAuthStateWasInvalid.php b/packages/auth/src/Exceptions/OAuthStateWasInvalid.php index deecb77be..06243d4c2 100644 --- a/packages/auth/src/Exceptions/OAuthStateWasInvalid.php +++ b/packages/auth/src/Exceptions/OAuthStateWasInvalid.php @@ -6,6 +6,4 @@ use Exception; -final class OAuthStateWasInvalid extends Exception implements AuthenticationException -{ -} +final class OAuthStateWasInvalid extends Exception implements AuthenticationException {} diff --git a/packages/auth/src/OAuth/OAuthConfig.php b/packages/auth/src/OAuth/OAuthConfig.php index 250bd851a..6722f7c42 100644 --- a/packages/auth/src/OAuth/OAuthConfig.php +++ b/packages/auth/src/OAuth/OAuthConfig.php @@ -14,32 +14,24 @@ interface OAuthConfig extends HasTag /** * The OAuth provider class name. */ - public string $provider { - get; - } + public string $provider { get; } /** * The authorization scopes for this OAuth provider. * * @return string[] */ - public array $scopes { - get; - } + public array $scopes { get; } /** * The client ID for the OAuth provider. */ - public string $clientId { - get; - } + public string $clientId { get; } /** * The controller action to redirect to after the user authorizes the application. */ - public string|array $redirectTo { - get; - } + public string|array $redirectTo { get; } /** * Creates the OAuth provider instance. diff --git a/packages/cache/src/Cache.php b/packages/cache/src/Cache.php index e46f189e9..19647a714 100644 --- a/packages/cache/src/Cache.php +++ b/packages/cache/src/Cache.php @@ -15,10 +15,7 @@ interface Cache /** * Whether the cache is enabled. */ - public bool $enabled { - get; - set; - } + public bool $enabled { get; set; } /** * Returns a lock for the specified key. The lock is not acquired until `acquire()` is called. diff --git a/packages/cache/src/CacheCouldNotBeCleared.php b/packages/cache/src/CacheCouldNotBeCleared.php index f7e3c2214..c74d7dba1 100644 --- a/packages/cache/src/CacheCouldNotBeCleared.php +++ b/packages/cache/src/CacheCouldNotBeCleared.php @@ -6,6 +6,4 @@ use Exception; -final class CacheCouldNotBeCleared extends Exception implements CacheException -{ -} +final class CacheCouldNotBeCleared extends Exception implements CacheException {} diff --git a/packages/cache/src/CacheException.php b/packages/cache/src/CacheException.php index 56297fdd4..3b72346ea 100644 --- a/packages/cache/src/CacheException.php +++ b/packages/cache/src/CacheException.php @@ -2,6 +2,4 @@ namespace Tempest\Cache; -interface CacheException -{ -} +interface CacheException {} diff --git a/packages/cache/src/Lock.php b/packages/cache/src/Lock.php index 908df168b..e6ad9fc2e 100644 --- a/packages/cache/src/Lock.php +++ b/packages/cache/src/Lock.php @@ -12,23 +12,17 @@ interface Lock /** * The key used to identify the lock. This should be unique across all locks. */ - public string $key { - get; - } + public string $key { get; } /** * The duration of the lock. If null, the lock will not expire. */ - public ?Duration $duration { - get; - } + public ?Duration $duration { get; } /** * The owner of the lock. This is used to verify that the lock is being released by the correct owner. */ - public string $owner { - get; - } + public string $owner { get; } /** * Attempts to acquire a lock. diff --git a/packages/command-bus/src/Async.php b/packages/command-bus/src/Async.php index eb1b35a49..b3b6b5852 100644 --- a/packages/command-bus/src/Async.php +++ b/packages/command-bus/src/Async.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute] -final readonly class Async -{ -} +final readonly class Async {} diff --git a/packages/console/src/CanOpenInEditor.php b/packages/console/src/CanOpenInEditor.php index 3ff635bb0..f39561b98 100644 --- a/packages/console/src/CanOpenInEditor.php +++ b/packages/console/src/CanOpenInEditor.php @@ -4,6 +4,4 @@ namespace Tempest\Console; -interface CanOpenInEditor -{ -} +interface CanOpenInEditor {} diff --git a/packages/console/src/Console.php b/packages/console/src/Console.php index 056ce5584..57875c72d 100644 --- a/packages/console/src/Console.php +++ b/packages/console/src/Console.php @@ -161,7 +161,5 @@ public function disablePrompting(): self; /** * Whether the console is in forced mode (skipping confirmations). */ - public bool $isForced { - get; - } + public bool $isForced { get; } } diff --git a/packages/console/src/HasStaticComponent.php b/packages/console/src/HasStaticComponent.php index c23fa81ac..ef896911c 100644 --- a/packages/console/src/HasStaticComponent.php +++ b/packages/console/src/HasStaticComponent.php @@ -6,7 +6,5 @@ interface HasStaticComponent { - public StaticConsoleComponent $staticComponent { - get; - } + public StaticConsoleComponent $staticComponent { get; } } diff --git a/packages/console/src/Scheduler/NullScheduler.php b/packages/console/src/Scheduler/NullScheduler.php index 7cd1d58ad..3ca9e1eb6 100644 --- a/packages/console/src/Scheduler/NullScheduler.php +++ b/packages/console/src/Scheduler/NullScheduler.php @@ -9,7 +9,5 @@ final class NullScheduler implements Scheduler { - public function run(?DateTime $date = null): void - { - } + public function run(?DateTime $date = null): void {} } diff --git a/packages/console/tests/TextBufferTest.php b/packages/console/tests/TextBufferTest.php index af26f5b62..76b6a5267 100644 --- a/packages/console/tests/TextBufferTest.php +++ b/packages/console/tests/TextBufferTest.php @@ -137,10 +137,10 @@ public function test_move_cursor_to_start(): void $this->assertSame(0, $buffer->cursor); $buffer = new TextBuffer(<<moveCursorX(100); $buffer->moveCursorToStart(); $this->assertSame(0, $buffer->cursor); @@ -155,10 +155,10 @@ public function test_move_cursor_to_end(): void $this->assertSame(13, $buffer->cursor); $buffer = new TextBuffer(<<setCursorIndex(0); $buffer->moveCursorToEnd(); $this->assertSame(48, $buffer->cursor); @@ -185,10 +185,10 @@ public function test_move_cursor_to_start_of_line(): void public function test_move_cursor_to_start_of_line_multiline(int $initial, int $expected): void { $buffer = new TextBuffer(<<setCursorIndex($initial); $buffer->moveCursorToStartOfLine(); @@ -217,10 +217,10 @@ public function test_move_cursor_to_end_of_line(): void public function test_move_cursor_to_end_of_line_multiline(int $initial, int $expected): void { $buffer = new TextBuffer(<<setCursorIndex($initial); $buffer->moveCursorToEndOfLine(); @@ -258,10 +258,10 @@ public function test_move_cursor_x(int $initialCursor, int $offsetX, int $expect public function move_cursor_y(int $initialCursor, int $offsetY, int $expectedPosition): void { $buffer = new TextBuffer(<<setCursorIndex($initialCursor); $buffer->moveCursorY($offsetY); diff --git a/packages/container/src/Autowire.php b/packages/container/src/Autowire.php index 8297e2d2e..adc5f433e 100644 --- a/packages/container/src/Autowire.php +++ b/packages/container/src/Autowire.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS)] -final class Autowire -{ -} +final class Autowire {} diff --git a/packages/container/src/Exceptions/ContainerException.php b/packages/container/src/Exceptions/ContainerException.php index 02809f491..aac08af63 100644 --- a/packages/container/src/Exceptions/ContainerException.php +++ b/packages/container/src/Exceptions/ContainerException.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Exceptions; -interface ContainerException -{ -} +interface ContainerException {} diff --git a/packages/container/src/HasTag.php b/packages/container/src/HasTag.php index 0aa252f6a..535bccf5a 100644 --- a/packages/container/src/HasTag.php +++ b/packages/container/src/HasTag.php @@ -6,7 +6,5 @@ interface HasTag { - public null|string|UnitEnum $tag { - get; - } + public null|string|UnitEnum $tag { get; } } diff --git a/packages/container/src/Proxy.php b/packages/container/src/Proxy.php index 10cfee429..7fa29f7c6 100644 --- a/packages/container/src/Proxy.php +++ b/packages/container/src/Proxy.php @@ -12,6 +12,4 @@ * The container may then decide to do lazy initialization */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] -final readonly class Proxy -{ -} +final readonly class Proxy {} diff --git a/packages/container/tests/ContainerTest.php b/packages/container/tests/ContainerTest.php index effa97435..1431f0f2a 100644 --- a/packages/container/tests/ContainerTest.php +++ b/packages/container/tests/ContainerTest.php @@ -325,9 +325,9 @@ public function test_autowired_tagged_dependency_exception(): void } catch (TaggedDependencyCouldNotBeResolved $cannotResolveTaggedDependency) { $this->assertStringContainsStringIgnoringLineEndings( <<<'TXT' - ┌── DependencyWithTaggedDependency::__construct(TaggedDependency $dependency) - └── Tempest\Container\Tests\Fixtures\TaggedDependency - TXT, + ┌── DependencyWithTaggedDependency::__construct(TaggedDependency $dependency) + └── Tempest\Container\Tests\Fixtures\TaggedDependency + TXT, $cannotResolveTaggedDependency->getMessage(), ); } diff --git a/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php b/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php index 58e8f2cb0..349fd2dd3 100644 --- a/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php +++ b/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php @@ -26,11 +26,11 @@ public function test_autowire_without_exception(): void $this->assertStringContainsString('Cannot autowire ' . AutowireA::class . '::__construct because string cannot be resolved', $cannotAutowireException->getMessage()); $expected = <<<'TXT' - ┌── AutowireA::__construct(AutowireB $b) - ├── AutowireB::__construct(AutowireC $c) - └── AutowireC::__construct(ContainerObjectA $other, string $unknown) - ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + ┌── AutowireA::__construct(AutowireB $b) + ├── AutowireB::__construct(AutowireC $c) + └── AutowireC::__construct(ContainerObjectA $other, string $unknown) + ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $cannotAutowireException->getMessage()); $this->assertStringContainsString('CannotAutowireExceptionTest.php:24', $cannotAutowireException->getMessage()); diff --git a/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php b/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php index 6ec8887d5..147f28acc 100644 --- a/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php +++ b/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php @@ -30,11 +30,11 @@ public function test_circular_dependency_test(): void ); $expected = <<<'TXT' - ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) - │ CircularB::__construct(CircularC $c) - │ CircularC::__construct(ContainerObjectA $other, CircularA $a) - └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) + │ CircularB::__construct(CircularC $c) + │ CircularC::__construct(ContainerObjectA $other, CircularA $a) + └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $circularDependencyException->getMessage()); @@ -59,12 +59,12 @@ public function test_circular_dependency_as_a_child_test(): void ); $expected = <<<'TXT' - CircularZ::__construct(CircularA $a) - ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) - │ CircularB::__construct(CircularC $c) - │ CircularC::__construct(ContainerObjectA $other, CircularA $a) - └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + CircularZ::__construct(CircularA $a) + ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) + │ CircularB::__construct(CircularC $c) + │ CircularC::__construct(ContainerObjectA $other, CircularA $a) + └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $circularDependencyException->getMessage()); diff --git a/packages/container/tests/Fixtures/ContainerObjectA.php b/packages/container/tests/Fixtures/ContainerObjectA.php index aceae4de0..8f616a804 100644 --- a/packages/container/tests/Fixtures/ContainerObjectA.php +++ b/packages/container/tests/Fixtures/ContainerObjectA.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final class ContainerObjectA -{ -} +final class ContainerObjectA {} diff --git a/packages/container/tests/Fixtures/DecoratedClass.php b/packages/container/tests/Fixtures/DecoratedClass.php index da11df34a..5e1cee022 100644 --- a/packages/container/tests/Fixtures/DecoratedClass.php +++ b/packages/container/tests/Fixtures/DecoratedClass.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final class DecoratedClass implements DecoratedInterface -{ -} +final class DecoratedClass implements DecoratedInterface {} diff --git a/packages/container/tests/Fixtures/DecoratedInterface.php b/packages/container/tests/Fixtures/DecoratedInterface.php index ddae1db5a..1a9d08396 100644 --- a/packages/container/tests/Fixtures/DecoratedInterface.php +++ b/packages/container/tests/Fixtures/DecoratedInterface.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface DecoratedInterface -{ -} +interface DecoratedInterface {} diff --git a/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php b/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php index 6adabcc37..de30c8b5e 100644 --- a/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php +++ b/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php @@ -7,6 +7,4 @@ use Tempest\Container\Decorates; #[Decorates(DecoratedInterface::class)] -final class DecoratorWithoutConstructor implements DecoratedInterface -{ -} +final class DecoratorWithoutConstructor implements DecoratedInterface {} diff --git a/packages/container/tests/Fixtures/ImplementsInterfaceA.php b/packages/container/tests/Fixtures/ImplementsInterfaceA.php index 81404be60..9b14c30f7 100644 --- a/packages/container/tests/Fixtures/ImplementsInterfaceA.php +++ b/packages/container/tests/Fixtures/ImplementsInterfaceA.php @@ -6,7 +6,5 @@ final class ImplementsInterfaceA implements InterfaceA { - public function __invoke(): void - { - } + public function __invoke(): void {} } diff --git a/packages/container/tests/Fixtures/InjectB.php b/packages/container/tests/Fixtures/InjectB.php index 81e0ddc78..f7564219b 100644 --- a/packages/container/tests/Fixtures/InjectB.php +++ b/packages/container/tests/Fixtures/InjectB.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final readonly class InjectB -{ -} +final readonly class InjectB {} diff --git a/packages/container/tests/Fixtures/InterfaceA.php b/packages/container/tests/Fixtures/InterfaceA.php index 81206885f..86e374a17 100644 --- a/packages/container/tests/Fixtures/InterfaceA.php +++ b/packages/container/tests/Fixtures/InterfaceA.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface InterfaceA -{ -} +interface InterfaceA {} diff --git a/packages/container/tests/Fixtures/UnionImplementation.php b/packages/container/tests/Fixtures/UnionImplementation.php index ce931a18b..e663b1906 100644 --- a/packages/container/tests/Fixtures/UnionImplementation.php +++ b/packages/container/tests/Fixtures/UnionImplementation.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final readonly class UnionImplementation implements UnionInterfaceA, UnionInterfaceB -{ -} +final readonly class UnionImplementation implements UnionInterfaceA, UnionInterfaceB {} diff --git a/packages/container/tests/Fixtures/UnionInterfaceA.php b/packages/container/tests/Fixtures/UnionInterfaceA.php index 6574213e8..e64583989 100644 --- a/packages/container/tests/Fixtures/UnionInterfaceA.php +++ b/packages/container/tests/Fixtures/UnionInterfaceA.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface UnionInterfaceA -{ -} +interface UnionInterfaceA {} diff --git a/packages/container/tests/Fixtures/UnionInterfaceB.php b/packages/container/tests/Fixtures/UnionInterfaceB.php index 061913934..1cb98985b 100644 --- a/packages/container/tests/Fixtures/UnionInterfaceB.php +++ b/packages/container/tests/Fixtures/UnionInterfaceB.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface UnionInterfaceB -{ -} +interface UnionInterfaceB {} diff --git a/packages/core/src/ComposerJsonCouldNotBeLocated.php b/packages/core/src/ComposerJsonCouldNotBeLocated.php index 10bf4b2c7..4c3bcd1dc 100644 --- a/packages/core/src/ComposerJsonCouldNotBeLocated.php +++ b/packages/core/src/ComposerJsonCouldNotBeLocated.php @@ -6,6 +6,4 @@ use Exception; -final class ComposerJsonCouldNotBeLocated extends Exception -{ -} +final class ComposerJsonCouldNotBeLocated extends Exception {} diff --git a/packages/core/src/InsightsProvider.php b/packages/core/src/InsightsProvider.php index c361318ed..2c9fbed89 100644 --- a/packages/core/src/InsightsProvider.php +++ b/packages/core/src/InsightsProvider.php @@ -10,9 +10,7 @@ interface InsightsProvider /** * Display name of this provider. */ - public string $name { - get; - } + public string $name { get; } /** * Gets insights in the form of key/value pairs. diff --git a/packages/core/src/Installer.php b/packages/core/src/Installer.php index 9f8cb3cf0..cb9698b2a 100644 --- a/packages/core/src/Installer.php +++ b/packages/core/src/Installer.php @@ -6,9 +6,7 @@ interface Installer { - public string $name { - get; - } + public string $name { get; } public function install(): void; } diff --git a/packages/core/src/Kernel.php b/packages/core/src/Kernel.php index 65f45fb96..7a8b97cf9 100644 --- a/packages/core/src/Kernel.php +++ b/packages/core/src/Kernel.php @@ -10,27 +10,15 @@ interface Kernel { public const string VERSION = '3.3.1'; - public string $root { - get; - } - - public string $internalStorage { - get; - } - - public array $discoveryLocations { - get; - set; - } - - public array $discoveryClasses { - get; - set; - } - - public Container $container { - get; - } + public string $root { get; } + + public string $internalStorage { get; } + + public array $discoveryLocations { get; set; } + + public array $discoveryClasses { get; set; } + + public Container $container { get; } public static function boot( string $root, diff --git a/packages/cryptography/src/Encryption/Encrypter.php b/packages/cryptography/src/Encryption/Encrypter.php index 20f3087e5..84b78c34b 100644 --- a/packages/cryptography/src/Encryption/Encrypter.php +++ b/packages/cryptography/src/Encryption/Encrypter.php @@ -4,9 +4,7 @@ interface Encrypter { - public EncryptionAlgorithm $algorithm { - get; - } + public EncryptionAlgorithm $algorithm { get; } /** * Encrypts the specified data. diff --git a/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php b/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php index b590b3c2b..bc252de37 100644 --- a/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php +++ b/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php @@ -2,6 +2,4 @@ namespace Tempest\Cryptography\Encryption\Exceptions; -interface EncryptionException -{ -} +interface EncryptionException {} diff --git a/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php b/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php index 7a993a6d0..0bc2a05c6 100644 --- a/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php +++ b/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php @@ -2,6 +2,4 @@ namespace Tempest\Cryptography\Password\Exceptions; -interface PasswordHashingException -{ -} +interface PasswordHashingException {} diff --git a/packages/cryptography/src/Password/PasswordHasher.php b/packages/cryptography/src/Password/PasswordHasher.php index e2a256765..bafe7fb9d 100644 --- a/packages/cryptography/src/Password/PasswordHasher.php +++ b/packages/cryptography/src/Password/PasswordHasher.php @@ -4,9 +4,7 @@ interface PasswordHasher { - public HashingAlgorithm $algorithm { - get; - } + public HashingAlgorithm $algorithm { get; } /** * Hashes the specified password. diff --git a/packages/cryptography/src/Password/PasswordHashingConfig.php b/packages/cryptography/src/Password/PasswordHashingConfig.php index a561ed49b..683dac6a4 100644 --- a/packages/cryptography/src/Password/PasswordHashingConfig.php +++ b/packages/cryptography/src/Password/PasswordHashingConfig.php @@ -4,14 +4,10 @@ interface PasswordHashingConfig { - public HashingAlgorithm $algorithm { - get; - } + public HashingAlgorithm $algorithm { get; } /** * Options for PHP's `password_hash` and `password_verify` functions. */ - public array $options { - get; - } + public array $options { get; } } diff --git a/packages/cryptography/src/Signing/Exceptions/SigningException.php b/packages/cryptography/src/Signing/Exceptions/SigningException.php index 48e42aab5..89dad5655 100644 --- a/packages/cryptography/src/Signing/Exceptions/SigningException.php +++ b/packages/cryptography/src/Signing/Exceptions/SigningException.php @@ -2,6 +2,4 @@ namespace Tempest\Cryptography\Signing\Exceptions; -interface SigningException -{ -} +interface SigningException {} diff --git a/packages/cryptography/src/Signing/Signer.php b/packages/cryptography/src/Signing/Signer.php index 6d40b6108..88002be90 100644 --- a/packages/cryptography/src/Signing/Signer.php +++ b/packages/cryptography/src/Signing/Signer.php @@ -4,9 +4,7 @@ interface Signer { - public SigningAlgorithm $algorithm { - get; - } + public SigningAlgorithm $algorithm { get; } /** * Signs the given data. diff --git a/packages/database/src/Builder/QueryBuilders/BuildsQuery.php b/packages/database/src/Builder/QueryBuilders/BuildsQuery.php index 712ac65b2..9ec20e885 100644 --- a/packages/database/src/Builder/QueryBuilders/BuildsQuery.php +++ b/packages/database/src/Builder/QueryBuilders/BuildsQuery.php @@ -16,23 +16,17 @@ interface BuildsQuery * * @return array */ - public array $bindings { - get; - } + public array $bindings { get; } /** * The model inspector for this query builder. */ - public ModelInspector $model { - get; - } + public ModelInspector $model { get; } /** * The database tag for targeting a specific database connection. */ - public null|string|UnitEnum $onDatabase { - get; - } + public null|string|UnitEnum $onDatabase { get; } /** * Creates a {@see Query} instance with the specified optional bindings. diff --git a/packages/database/src/Builder/QueryBuilders/QueryBuilder.php b/packages/database/src/Builder/QueryBuilders/QueryBuilder.php index d725161a4..9cb558dd1 100644 --- a/packages/database/src/Builder/QueryBuilders/QueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/QueryBuilder.php @@ -200,7 +200,8 @@ public function get(string|int|PrimaryKey $id, array $relations = []): ?object default => new PrimaryKey($id), }; - return $this->select() + return $this + ->select() ->with(...$relations) ->get($id); } @@ -212,7 +213,8 @@ public function get(string|int|PrimaryKey $id, array $relations = []): ?object */ public function all(array $relations = []): array { - return $this->select() + return $this + ->select() ->with(...$relations) ->all(); } diff --git a/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php index e05fc333e..c194309f2 100644 --- a/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php @@ -203,7 +203,8 @@ public function chunk(Closure $closure, int $amountPerChunk = 200): void $offset = 0; do { - $data = $this->clone() + $data = $this + ->clone() ->limit($amountPerChunk) ->offset($offset) ->all(); diff --git a/packages/database/src/Builder/QueryBuilders/SupportsJoins.php b/packages/database/src/Builder/QueryBuilders/SupportsJoins.php index 7e6dd4182..28ef8fe10 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsJoins.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsJoins.php @@ -14,7 +14,5 @@ interface SupportsJoins * * @return array */ - public array $joins { - get; - } + public array $joins { get; } } diff --git a/packages/database/src/Builder/QueryBuilders/SupportsRelations.php b/packages/database/src/Builder/QueryBuilders/SupportsRelations.php index 17bccd029..366aedd93 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsRelations.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsRelations.php @@ -14,9 +14,7 @@ interface SupportsRelations * * @return array */ - public array $relations { - get; - } + public array $relations { get; } /** * Gets all resolved relations with their join statements. diff --git a/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php b/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php index ce48e8dbe..90eb7158e 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php @@ -17,9 +17,7 @@ interface SupportsWhereStatements * * @var ImmutableArray */ - public ImmutableArray $wheres { - get; - } + public ImmutableArray $wheres { get; } /** * Adds a WHERE condition to the query. diff --git a/packages/database/src/Config/DatabaseConfig.php b/packages/database/src/Config/DatabaseConfig.php index 581a5b878..ced0c3d8c 100644 --- a/packages/database/src/Config/DatabaseConfig.php +++ b/packages/database/src/Config/DatabaseConfig.php @@ -13,56 +13,40 @@ interface DatabaseConfig extends HasTag /** * PDO data source name connection string. */ - public string $dsn { - get; - } + public string $dsn { get; } /** * The naming strategy for database tables and columns. */ - public NamingStrategy $namingStrategy { - get; - } + public NamingStrategy $namingStrategy { get; } /** * The naming strategy for migration file prefixes. */ - public MigrationNamingStrategy $migrationNamingStrategy { - get; - } + public MigrationNamingStrategy $migrationNamingStrategy { get; } /** * The database dialect (MySQL, PostgreSQL, SQLite). */ - public DatabaseDialect $dialect { - get; - } + public DatabaseDialect $dialect { get; } /** * The database username for authentication. */ - public ?string $username { - get; - } + public ?string $username { get; } /** * The database password for authentication. */ - public ?string $password { - get; - } + public ?string $password { get; } /** * Whether to use persistent database connections. */ - public bool $usePersistentConnection { - get; - } + public bool $usePersistentConnection { get; } /** * PDO connection options built from configuration properties. */ - public array $options { - get; - } + public array $options { get; } } diff --git a/packages/database/src/Database.php b/packages/database/src/Database.php index 6f12cf132..966e492de 100644 --- a/packages/database/src/Database.php +++ b/packages/database/src/Database.php @@ -17,16 +17,12 @@ interface Database /** * The dialect of this database. */ - public DatabaseDialect $dialect { - get; - } + public DatabaseDialect $dialect { get; } /** * The tag associated with this database, if any. */ - public null|string|UnitEnum $tag { - get; - } + public null|string|UnitEnum $tag { get; } /** * Executes the given query. diff --git a/packages/database/src/Eager.php b/packages/database/src/Eager.php index cd3767dc6..9efd7e34e 100644 --- a/packages/database/src/Eager.php +++ b/packages/database/src/Eager.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Eager -{ -} +final readonly class Eager {} diff --git a/packages/database/src/Exceptions/DatabaseException.php b/packages/database/src/Exceptions/DatabaseException.php index f7ae18e52..c9e7b4a99 100644 --- a/packages/database/src/Exceptions/DatabaseException.php +++ b/packages/database/src/Exceptions/DatabaseException.php @@ -4,6 +4,4 @@ namespace Tempest\Database\Exceptions; -interface DatabaseException -{ -} +interface DatabaseException {} diff --git a/packages/database/src/HasLeadingStatements.php b/packages/database/src/HasLeadingStatements.php index d6f126fe1..42946c0ae 100644 --- a/packages/database/src/HasLeadingStatements.php +++ b/packages/database/src/HasLeadingStatements.php @@ -4,7 +4,5 @@ interface HasLeadingStatements { - public array $leadingStatements { - get; - } + public array $leadingStatements { get; } } diff --git a/packages/database/src/HasTrailingStatements.php b/packages/database/src/HasTrailingStatements.php index 081220705..b91b4ce66 100644 --- a/packages/database/src/HasTrailingStatements.php +++ b/packages/database/src/HasTrailingStatements.php @@ -4,7 +4,5 @@ interface HasTrailingStatements { - public array $trailingStatements { - get; - } + public array $trailingStatements { get; } } diff --git a/packages/database/src/Lazy.php b/packages/database/src/Lazy.php index b112d9e03..a43fcc67f 100644 --- a/packages/database/src/Lazy.php +++ b/packages/database/src/Lazy.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Lazy -{ -} +final readonly class Lazy {} diff --git a/packages/database/src/MigratesDown.php b/packages/database/src/MigratesDown.php index a18004d87..a3414f14d 100644 --- a/packages/database/src/MigratesDown.php +++ b/packages/database/src/MigratesDown.php @@ -6,9 +6,7 @@ interface MigratesDown { - public string $name { - get; - } + public string $name { get; } public function down(): QueryStatement; } diff --git a/packages/database/src/MigratesUp.php b/packages/database/src/MigratesUp.php index 9a436fb8b..c25a08409 100644 --- a/packages/database/src/MigratesUp.php +++ b/packages/database/src/MigratesUp.php @@ -6,9 +6,7 @@ interface MigratesUp { - public string $name { - get; - } + public string $name { get; } public function up(): QueryStatement; } diff --git a/packages/database/src/Migrations/MigrationException.php b/packages/database/src/Migrations/MigrationException.php index c9e7cb307..96d065eca 100644 --- a/packages/database/src/Migrations/MigrationException.php +++ b/packages/database/src/Migrations/MigrationException.php @@ -4,6 +4,4 @@ namespace Tempest\Database\Migrations; -interface MigrationException -{ -} +interface MigrationException {} diff --git a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php index 9640b4e8e..bf359c437 100644 --- a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php @@ -30,8 +30,8 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', DatabaseDialect::POSTGRESQL => sprintf( <<<'PSQL' - CREATE TYPE "%s" AS ENUM (%s); - PSQL, + CREATE TYPE "%s" AS ENUM (%s); + PSQL, str($this->enumClass)->replace('\\\\', '_'), $cases->implode(', '), ), diff --git a/packages/database/src/QueryStatements/DropEnumTypeStatement.php b/packages/database/src/QueryStatements/DropEnumTypeStatement.php index 35fddb0da..16396dcf7 100644 --- a/packages/database/src/QueryStatements/DropEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/DropEnumTypeStatement.php @@ -24,8 +24,8 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', DatabaseDialect::POSTGRESQL => sprintf( <<<'PSQL' - DROP TYPE IF EXISTS "%s"; - PSQL, + DROP TYPE IF EXISTS "%s"; + PSQL, str($this->enumClass)->replace('\\\\', '_'), ), }; diff --git a/packages/database/src/QueryStatements/HasWhereStatements.php b/packages/database/src/QueryStatements/HasWhereStatements.php index 91869b104..def527731 100644 --- a/packages/database/src/QueryStatements/HasWhereStatements.php +++ b/packages/database/src/QueryStatements/HasWhereStatements.php @@ -7,7 +7,5 @@ interface HasWhereStatements { /** @var ImmutableArray */ - public ImmutableArray $where { - get; - } + public ImmutableArray $where { get; } } diff --git a/packages/database/src/QueryStatements/ShowTablesStatement.php b/packages/database/src/QueryStatements/ShowTablesStatement.php index 23d79dd54..c29826f74 100644 --- a/packages/database/src/QueryStatements/ShowTablesStatement.php +++ b/packages/database/src/QueryStatements/ShowTablesStatement.php @@ -23,11 +23,11 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL => "SHOW FULL TABLES WHERE table_type = 'BASE TABLE'", DatabaseDialect::SQLITE => "select type, name from sqlite_master where type = 'table' and name not like 'sqlite_%'", DatabaseDialect::POSTGRESQL => << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, <<', $queryBuilder); diff --git a/packages/datetime/src/Exception/DateTimeException.php b/packages/datetime/src/Exception/DateTimeException.php index f2a011621..465fb7fad 100644 --- a/packages/datetime/src/Exception/DateTimeException.php +++ b/packages/datetime/src/Exception/DateTimeException.php @@ -4,6 +4,4 @@ namespace Tempest\DateTime\Exception; -interface DateTimeException -{ -} +interface DateTimeException {} diff --git a/packages/datetime/src/Exception/OverflowException.php b/packages/datetime/src/Exception/OverflowException.php index 889ff5d0c..aac737522 100644 --- a/packages/datetime/src/Exception/OverflowException.php +++ b/packages/datetime/src/Exception/OverflowException.php @@ -6,6 +6,4 @@ use OverflowException as PhpOverflowException; -final class OverflowException extends PhpOverflowException implements DateTimeException -{ -} +final class OverflowException extends PhpOverflowException implements DateTimeException {} diff --git a/packages/datetime/src/Exception/ParserException.php b/packages/datetime/src/Exception/ParserException.php index 199391651..62edddb61 100644 --- a/packages/datetime/src/Exception/ParserException.php +++ b/packages/datetime/src/Exception/ParserException.php @@ -4,6 +4,4 @@ namespace Tempest\DateTime\Exception; -final class ParserException extends RuntimeException -{ -} +final class ParserException extends RuntimeException {} diff --git a/packages/datetime/src/Exception/RuntimeException.php b/packages/datetime/src/Exception/RuntimeException.php index a3228748a..709ce27ed 100644 --- a/packages/datetime/src/Exception/RuntimeException.php +++ b/packages/datetime/src/Exception/RuntimeException.php @@ -7,6 +7,4 @@ use RuntimeException as PhpRuntimeException; // @phpstan-ignore-next-line -class RuntimeException extends PhpRuntimeException implements DateTimeException -{ -} +class RuntimeException extends PhpRuntimeException implements DateTimeException {} diff --git a/packages/datetime/src/Exception/UnderflowException.php b/packages/datetime/src/Exception/UnderflowException.php index a29986966..87b6c2936 100644 --- a/packages/datetime/src/Exception/UnderflowException.php +++ b/packages/datetime/src/Exception/UnderflowException.php @@ -6,6 +6,4 @@ use UnderflowException as PhpUnderflowException; -final class UnderflowException extends PhpUnderflowException implements DateTimeException -{ -} +final class UnderflowException extends PhpUnderflowException implements DateTimeException {} diff --git a/packages/debug/src/Debug.php b/packages/debug/src/Debug.php index cd17c4ef2..4899fb2f0 100644 --- a/packages/debug/src/Debug.php +++ b/packages/debug/src/Debug.php @@ -97,16 +97,16 @@ private function writeToOut(array $items, string $callPath): void echo vsprintf( <<%s (%s) - HTML, + %s (%s) + HTML, [ 'Source Code Pro, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace', $key, diff --git a/packages/event-bus/src/StopsPropagation.php b/packages/event-bus/src/StopsPropagation.php index ac3241e03..a296547f9 100644 --- a/packages/event-bus/src/StopsPropagation.php +++ b/packages/event-bus/src/StopsPropagation.php @@ -5,6 +5,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] -final readonly class StopsPropagation -{ -} +final readonly class StopsPropagation {} diff --git a/packages/event-bus/tests/Fixtures/EventInterface.php b/packages/event-bus/tests/Fixtures/EventInterface.php index 0cfc74c27..1be684456 100644 --- a/packages/event-bus/tests/Fixtures/EventInterface.php +++ b/packages/event-bus/tests/Fixtures/EventInterface.php @@ -4,6 +4,4 @@ namespace Tempest\EventBus\Tests\Fixtures; -interface EventInterface -{ -} +interface EventInterface {} diff --git a/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php b/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php index 9b9fa7921..8f56d225d 100644 --- a/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php +++ b/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php @@ -4,6 +4,4 @@ namespace Tempest\EventBus\Tests\Fixtures; -final readonly class EventInterfaceImplementation implements EventInterface -{ -} +final readonly class EventInterfaceImplementation implements EventInterface {} diff --git a/packages/event-bus/tests/Fixtures/ItHappened.php b/packages/event-bus/tests/Fixtures/ItHappened.php index 37fcd827c..2dd32f315 100644 --- a/packages/event-bus/tests/Fixtures/ItHappened.php +++ b/packages/event-bus/tests/Fixtures/ItHappened.php @@ -4,6 +4,4 @@ namespace Tempest\EventBus\Tests\Fixtures; -final readonly class ItHappened -{ -} +final readonly class ItHappened {} diff --git a/packages/generation/src/Php/Exceptions/FileGenerationException.php b/packages/generation/src/Php/Exceptions/FileGenerationException.php index 6c9e18f78..00d8bac3f 100644 --- a/packages/generation/src/Php/Exceptions/FileGenerationException.php +++ b/packages/generation/src/Php/Exceptions/FileGenerationException.php @@ -4,6 +4,4 @@ namespace Tempest\Generation\Php\Exceptions; -interface FileGenerationException -{ -} +interface FileGenerationException {} diff --git a/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php b/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php index 1e3004432..9a08bb47e 100644 --- a/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php +++ b/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php @@ -6,6 +6,4 @@ use Exception; -final class FileGenerationWasAborted extends Exception implements FileGenerationException -{ -} +final class FileGenerationWasAborted extends Exception implements FileGenerationException {} diff --git a/packages/generation/src/TypeScript/AsType.php b/packages/generation/src/TypeScript/AsType.php index dd4fc72e4..b4b18db82 100644 --- a/packages/generation/src/TypeScript/AsType.php +++ b/packages/generation/src/TypeScript/AsType.php @@ -8,6 +8,4 @@ * Marks this class as a source for TypeScript type generation. */ #[Attribute(Attribute::TARGET_CLASS)] -final class AsType -{ -} +final class AsType {} diff --git a/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php b/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php index fdcc7c892..3294dcf56 100644 --- a/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php +++ b/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php @@ -11,27 +11,19 @@ interface TypeScriptGenerationConfig * * @var class-string */ - public string $writer { - get; - } + public string $writer { get; } /** * The list of source classes to generate types for. * * @var array */ - public array $sources { - get; - set; - } + public array $sources { get; set; } /** * The list of type resolvers for property-level type mapping. * * @var array> */ - public array $resolvers { - get; - set; - } + public array $resolvers { get; set; } } diff --git a/packages/generation/tests/Php/ClassGeneratorTest.php b/packages/generation/tests/Php/ClassGeneratorTest.php index 2a3072e46..b18bc5d65 100644 --- a/packages/generation/tests/Php/ClassGeneratorTest.php +++ b/packages/generation/tests/Php/ClassGeneratorTest.php @@ -28,14 +28,14 @@ public function creates_class_from_scratch(): void $class->setReadOnly(); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $class->addMethod('getName', body: <<assertMatchesSnapshot($class->print()); } @@ -50,8 +50,8 @@ public function creates_methods_with_parameters(): void $class->setReadOnly(); $class->addMethod('findById', body: << 'int'], returnType: '?App\\Models\\User'); + // + PHP, parameters: ['id' => 'int'], returnType: '?App\\Models\\User'); $this->assertMatchesSnapshot($class->print()); } @@ -73,10 +73,10 @@ public function simplify_class_names_by_default(): void $class = new ClassGenerator('CreateUsersTable', namespace: 'App'); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $this->assertMatchesSnapshot($class->print()); } @@ -88,10 +88,10 @@ public function does_not_simplify_class_names(): void $class->simplifyClassNamesInMethodBodies(false); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $this->assertMatchesSnapshot($class->print()); } diff --git a/packages/generation/tests/Php/Fixtures/ClassFromFile.php b/packages/generation/tests/Php/Fixtures/ClassFromFile.php index 724347072..2ca7a96e4 100644 --- a/packages/generation/tests/Php/Fixtures/ClassFromFile.php +++ b/packages/generation/tests/Php/Fixtures/ClassFromFile.php @@ -4,6 +4,4 @@ namespace Tempest\Generation\Tests\Php\Fixtures; -final readonly class ClassFromFile -{ -} +final readonly class ClassFromFile {} diff --git a/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php b/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php index 98ce82e66..5cdf78f0e 100644 --- a/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php +++ b/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php @@ -11,6 +11,5 @@ final class ClassWithMethodParameterAttributes public function example( #[SampleParameterAttribute] string $parameter, - ): void { - } + ): void {} } diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php index ae38bb730..179cd4746 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php @@ -4,6 +4,4 @@ namespace Tempest\Generation\Tests\Php\Fixtures\SampleNamespace; -final class DummyFqcn -{ -} +final class DummyFqcn {} diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php index 7205acca8..811dbc7d2 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php @@ -6,7 +6,5 @@ trait ExampleTrait { - public function traitMethod(): void - { - } + public function traitMethod(): void {} } diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php index 9d2bf3318..5ac1bc345 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PARAMETER)] -final class SampleParameterAttribute -{ -} +final class SampleParameterAttribute {} diff --git a/packages/generation/tests/Php/Fixtures/TestAttribute.php b/packages/generation/tests/Php/Fixtures/TestAttribute.php index 91486e42b..4eace3257 100644 --- a/packages/generation/tests/Php/Fixtures/TestAttribute.php +++ b/packages/generation/tests/Php/Fixtures/TestAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS)] -final class TestAttribute -{ -} +final class TestAttribute {} diff --git a/packages/http/src/Request.php b/packages/http/src/Request.php index 794d42c86..7193d4f57 100644 --- a/packages/http/src/Request.php +++ b/packages/http/src/Request.php @@ -8,43 +8,25 @@ interface Request { - public Method $method { - get; - } + public Method $method { get; } - public string $uri { - get; - } + public string $uri { get; } - public ?string $raw { - get; - } + public ?string $raw { get; } - public array $body { - get; - } + public array $body { get; } - public RequestHeaders $headers { - get; - } + public RequestHeaders $headers { get; } - public string $path { - get; - } + public string $path { get; } - public array $query { - get; - } + public array $query { get; } /** @var \Tempest\Http\Upload[] $files */ - public array $files { - get; - } + public array $files { get; } /** @var Cookie[] $cookies */ - public array $cookies { - get; - } + public array $cookies { get; } public function has(string $key): bool; diff --git a/packages/http/src/Response.php b/packages/http/src/Response.php index ea7bac8b3..2c92b36b6 100644 --- a/packages/http/src/Response.php +++ b/packages/http/src/Response.php @@ -15,25 +15,19 @@ interface Response /** * Gets the status code of the response. */ - public Status $status { - get; - } + public Status $status { get; } /** * Gets the headers of the response. * * @var \Tempest\Http\Header[] $headers */ - public array $headers { - get; - } + public array $headers { get; } /** * Gets the body of the response. */ - public View|string|array|Generator|JsonSerializable|null $body { - get; - } + public View|string|array|Generator|JsonSerializable|null $body { get; } /** * Gets a header by its name, case insensitive. diff --git a/packages/http/src/Responses/Download.php b/packages/http/src/Responses/Download.php index 75b08fcd0..a5ee7f9e2 100644 --- a/packages/http/src/Responses/Download.php +++ b/packages/http/src/Responses/Download.php @@ -16,7 +16,8 @@ public function __construct(string $path, ?string $filename = null) { $filename ??= pathinfo($path, PATHINFO_BASENAME); - $this->addHeader('Content-Disposition', "attachment; filename=\"{$filename}\"") + $this + ->addHeader('Content-Disposition', "attachment; filename=\"{$filename}\"") ->setContentType(ContentType::fromPath($path)) ->removeHeader('Transfer-Encoding'); diff --git a/packages/http/src/Responses/File.php b/packages/http/src/Responses/File.php index f940def4d..c75213a39 100644 --- a/packages/http/src/Responses/File.php +++ b/packages/http/src/Responses/File.php @@ -16,7 +16,8 @@ public function __construct(string $path, ?string $filename = null) { $filename ??= pathinfo($path, PATHINFO_BASENAME); - $this->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"") + $this + ->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"") ->setContentType(ContentType::fromPath($path)) ->removeHeader('Transfer-Encoding'); diff --git a/packages/http/src/SensitiveField.php b/packages/http/src/SensitiveField.php index 0a01792cc..2204b7f0d 100644 --- a/packages/http/src/SensitiveField.php +++ b/packages/http/src/SensitiveField.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class SensitiveField -{ -} +final class SensitiveField {} diff --git a/packages/http/src/ServerSentEvent.php b/packages/http/src/ServerSentEvent.php index 8a8c8d5d2..847bb0aaa 100644 --- a/packages/http/src/ServerSentEvent.php +++ b/packages/http/src/ServerSentEvent.php @@ -11,16 +11,12 @@ interface ServerSentEvent /** * Defines the ID of this event, which sets the `Last-Event-ID` header in case of a reconnection. */ - public ?int $id { - get; - } + public ?int $id { get; } /** * Defines the event stream's reconnection time in case of a reconnection attempt. */ - public null|Duration|int $retryAfter { - get; - } + public null|Duration|int $retryAfter { get; } /** * The name of the event, which may be listened to by `EventSource#addEventListener`. @@ -33,14 +29,10 @@ interface ServerSentEvent * }) * ``` */ - public ?string $event { - get; - } + public ?string $event { get; } /** * Content of the event. */ - public JsonSerializable|Stringable|string|iterable $data { - get; - } + public JsonSerializable|Stringable|string|iterable $data { get; } } diff --git a/packages/http/src/Session/SessionConfig.php b/packages/http/src/Session/SessionConfig.php index 6bbc9264c..425d34025 100644 --- a/packages/http/src/Session/SessionConfig.php +++ b/packages/http/src/Session/SessionConfig.php @@ -10,9 +10,7 @@ interface SessionConfig /** * Time required for a session to expire. */ - public Duration $expiration { - get; - } + public Duration $expiration { get; } public function createManager(Container $container): SessionManager; } diff --git a/packages/idempotency/src/Exceptions/IdempotencyException.php b/packages/idempotency/src/Exceptions/IdempotencyException.php index 989122683..5f0eed9ce 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyException.php +++ b/packages/idempotency/src/Exceptions/IdempotencyException.php @@ -6,6 +6,4 @@ use Exception; -abstract class IdempotencyException extends Exception -{ -} +abstract class IdempotencyException extends Exception {} diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index 52c9c11f4..e0bf1d171 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -338,7 +338,5 @@ final class SyncInventoryHandler { #[Idempotent] #[CommandHandler] - public function handle(SyncInventoryCommand $command): void - { - } + public function handle(SyncInventoryCommand $command): void {} } diff --git a/packages/intl/bin/plural-rules.php b/packages/intl/bin/plural-rules.php index 0a79e7795..9d2957b84 100755 --- a/packages/intl/bin/plural-rules.php +++ b/packages/intl/bin/plural-rules.php @@ -52,130 +52,130 @@ public function generate(): string private function generateHelperMethods(bool $includeMatchesValues): string { $helpers = <<<'PHP' - /** - * Extracts the integer part of a number. - */ - private static function getIntegerPart(float|int $n): int - { - return (int) abs($n); - } - - /** - * Counts visible fractional digits. - */ - private static function getVisibleFractionalDigits(float|int $n): int - { - $str = (string) $n; - - if (! str_contains($str, '.')) { - return 0; + /** + * Extracts the integer part of a number. + */ + private static function getIntegerPart(float|int $n): int + { + return (int) abs($n); } - return strlen(rtrim(explode('.', $str)[1], '0')); - } + /** + * Counts visible fractional digits. + */ + private static function getVisibleFractionalDigits(float|int $n): int + { + $str = (string) $n; - /** - * Gets fractional digits as integer. - */ - private static function getFractionalDigits(float|int $n): int - { - $str = (string) $n; + if (! str_contains($str, '.')) { + return 0; + } - if (! str_contains($str, '.')) { - return 0; + return strlen(rtrim(explode('.', $str)[1], '0')); } - return (int) rtrim(explode('.', $str)[1], '0') ?: 0; - } + /** + * Gets fractional digits as integer. + */ + private static function getFractionalDigits(float|int $n): int + { + $str = (string) $n; - /** - * Gets compact decimal exponent (magnitude). - */ - private static function getCompactExponent(float|int $n): int - { - if ($n === 0 || $n === 0.0) { - return 0; + if (! str_contains($str, '.')) { + return 0; + } + + return (int) rtrim(explode('.', $str)[1], '0') ?: 0; } - $abs = abs($n); + /** + * Gets compact decimal exponent (magnitude). + */ + private static function getCompactExponent(float|int $n): int + { + if ($n === 0 || $n === 0.0) { + return 0; + } - if ($abs >= 1000000) { - return 6; - } + $abs = abs($n); - if ($abs >= 1000) { - return 3; - } + if ($abs >= 1000000) { + return 6; + } - return 0; - } + if ($abs >= 1000) { + return 3; + } - /** - * Gets the exponent for scientific notation. - */ - private static function getExponent(float|int $n): int - { - if ($n === 0 || $n === 0.0) { return 0; } - return (int) floor(log10(abs($n))); - } + /** + * Gets the exponent for scientific notation. + */ + private static function getExponent(float|int $n): int + { + if ($n === 0 || $n === 0.0) { + return 0; + } - /** - * Checks if number is in range. - */ - private static function inRange(int|float $value, int|float $start, int|float $end): bool - { - return $value >= $start && $value <= $end; - } + return (int) floor(log10(abs($n))); + } - /** - * Checks whether two numeric values are equal. - */ - private static function isEqual(int|float $left, int|float $right): bool - { - return $left === $right; - } + /** + * Checks if number is in range. + */ + private static function inRange(int|float $value, int|float $start, int|float $end): bool + { + return $value >= $start && $value <= $end; + } + + /** + * Checks whether two numeric values are equal. + */ + private static function isEqual(int|float $left, int|float $right): bool + { + return $left === $right; + } - PHP; + PHP; if (! $includeMatchesValues) { return $helpers; } return $helpers . <<<'PHP' - /** - * Checks if number matches any value in comma-separated list. - */ - private static function matchesValues(int|float $value, string $values): bool - { - $parts = explode(',', $values); - - foreach ($parts as $part) { - $part = trim($part); - - if (str_contains($part, '~')) { - [$start, $end] = explode('~', $part); - - if (self::inRange($value, (float) trim($start), (float) trim($end))) { - return true; - } - } elseif (str_contains($part, '..')) { - [$start, $end] = explode('..', $part); - - if (self::inRange($value, (float) trim($start), (float) trim($end))) { + /** + * Checks if number matches any value in comma-separated list. + */ + private static function matchesValues(int|float $value, string $values): bool + { + $parts = explode(',', $values); + + foreach ($parts as $part) { + $part = trim($part); + + if (str_contains($part, '~')) { + [$start, $end] = explode('~', $part); + + if (self::inRange($value, (float) trim($start), (float) trim($end))) { + return true; + } + } elseif (str_contains($part, '..')) { + [$start, $end] = explode('..', $part); + + if (self::inRange($value, (float) trim($start), (float) trim($end))) { + return true; + } + } elseif ((float) $part === (float) $value) { return true; } - } elseif ((float) $part === (float) $value) { - return true; } - } - return false; - } + return false; + } - PHP; + PHP; } private function generateLanguageMethod(string $locale, array $rules): string diff --git a/packages/intl/src/MessageFormat/FormattingFunction.php b/packages/intl/src/MessageFormat/FormattingFunction.php index 126884408..fc15e67d3 100644 --- a/packages/intl/src/MessageFormat/FormattingFunction.php +++ b/packages/intl/src/MessageFormat/FormattingFunction.php @@ -9,9 +9,7 @@ interface FormattingFunction /** * Identifier of the formatting function. */ - public string $name { - get; - } + public string $name { get; } /** * Formats the given value with the given parameters. diff --git a/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php b/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php index df661703f..b5a039765 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php @@ -4,6 +4,4 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Declaration extends Node -{ -} +interface Declaration extends Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php b/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php index 5cb1a7378..815996002 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php @@ -4,6 +4,4 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Key extends Node -{ -} +interface Key extends Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php b/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php index 81d144d04..4512d0147 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Key; -final class WildcardKey implements Key -{ -} +final class WildcardKey implements Key {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php b/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php index a50fdfae6..109673762 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Literal; -final class QuotedLiteral extends Literal -{ -} +final class QuotedLiteral extends Literal {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php b/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php index 7fda533db..7b1109096 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Literal; -final class UnquotedLiteral extends Literal -{ -} +final class UnquotedLiteral extends Literal {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Node.php b/packages/intl/src/MessageFormat/Parser/Node/Node.php index bea306511..675f8bda3 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Node.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Node.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -interface Node -{ -} +interface Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php b/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php index 30b38dbd4..94fb62f9b 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php @@ -4,6 +4,4 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Placeholder extends Node -{ -} +interface Placeholder extends Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php b/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php index dbc597e90..b0fb3b404 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php +++ b/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -final class SimpleMessage extends MessageNode -{ -} +final class SimpleMessage extends MessageNode {} diff --git a/packages/intl/src/MessageFormat/SelectorFunction.php b/packages/intl/src/MessageFormat/SelectorFunction.php index 0d2a31207..e3020b3a9 100644 --- a/packages/intl/src/MessageFormat/SelectorFunction.php +++ b/packages/intl/src/MessageFormat/SelectorFunction.php @@ -7,9 +7,7 @@ interface SelectorFunction /** * Identifier of the selector function. */ - public string $name { - get; - } + public string $name { get; } /** * Defines whether the matcher key matches with the given value. diff --git a/packages/intl/tests/FormatterTest.php b/packages/intl/tests/FormatterTest.php index e7428c305..3bfc6da4e 100644 --- a/packages/intl/tests/FormatterTest.php +++ b/packages/intl/tests/FormatterTest.php @@ -44,8 +44,8 @@ public function test_placeholder_variable(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Hello, {$name}! - TXT, name: 'Jon'); + Hello, {$name}! + TXT, name: 'Jon'); $this->assertSame('Hello, Jon!', $value); } @@ -59,8 +59,8 @@ public function test_format_datetime_function_and_parameters(): void $formatter = new MessageFormatter([$this->createDateTimeFunction()]); $value = $formatter->format(<<<'TXT' - Today is {$today :datetime pattern=|yyyy/MM/dd|}. - TXT, today: '2024-01-01'); + Today is {$today :datetime pattern=|yyyy/MM/dd|}. + TXT, today: '2024-01-01'); $this->assertSame('Today is 2024/01/01.', $value); } @@ -70,8 +70,8 @@ public function test_format_number_function(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - The total was {31 :number style=percent}. - TXT); + The total was {31 :number style=percent}. + TXT); $this->assertSame('The total was 31%.', $value); } @@ -84,12 +84,12 @@ public function test_match_number(int $count, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$aircraft :number} - .match $aircraft - 0 {{pas d‘avion}} - 1 {{un avion}} - * {{{$aircraft} avions}} - TXT, aircraft: $count); + .input {$aircraft :number} + .match $aircraft + 0 {{pas d‘avion}} + 1 {{un avion}} + * {{{$aircraft} avions}} + TXT, aircraft: $count); $this->assertSame($expected, $value); } @@ -99,16 +99,16 @@ public function test_default_input(): void $formatter = new MessageFormatter([]); $value = $formatter->format(<<<'TXT' - .input {$field :string default=unknown} - field is {$field} - TXT); + .input {$field :string default=unknown} + field is {$field} + TXT); $this->assertSame('field is unknown', $value); $value = $formatter->format(<<<'TXT' - .input {$field :string default=unknown} - field is {$field} - TXT, field: 'here'); + .input {$field :string default=unknown} + field is {$field} + TXT, field: 'here'); $this->assertSame('field is here', $value); } @@ -117,8 +117,8 @@ public function test_unquoted_text(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Hello, {world}! - TXT); + Hello, {world}! + TXT); $this->assertSame('Hello, world!', $value); } @@ -127,8 +127,8 @@ public function test_quoted_text(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - My name is {|John Doe|}. - TXT); + My name is {|John Doe|}. + TXT); $this->assertSame('My name is John Doe.', $value); } @@ -137,11 +137,11 @@ public function test_number_matcher(): void { $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number} - .match $count - one {{You have {$count} notification.}} - * {{You have {$count} notifications.}} - TXT, count: 1); + .input {$count :number} + .match $count + one {{You have {$count} notification.}} + * {{You have {$count} notifications.}} + TXT, count: 1); $this->assertSame('You have 1 notification.', $value); } @@ -150,11 +150,11 @@ public function test_number_matcher_exact(): void { $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number select=exact} - .match $count - one {{You have {$count} notification.}} - * {{You have {$count} notifications.}} - TXT, count: 1); + .input {$count :number select=exact} + .match $count + one {{You have {$count} notification.}} + * {{You have {$count} notifications.}} + TXT, count: 1); $this->assertSame('You have 1 notifications.', $value); } @@ -163,12 +163,12 @@ public function test_local_declaration(): void { $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<<'TXT' - .local $val = {foo2 :string} - .match $val - foo {{Foo}} - bar {{Bar}} - * {{No match}} - TXT); + .local $val = {foo2 :string} + .match $val + foo {{Foo}} + bar {{Bar}} + * {{No match}} + TXT); $this->assertSame('No match', $value); } @@ -177,11 +177,11 @@ public function test_local_declarations_unquoted_literals(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .local $x = {42} - .local $y = {number42} - .local $z = {_number} - {{{$x} {$y} {$z}}} - TXT); + .local $x = {42} + .local $y = {number42} + .local $z = {_number} + {{{$x} {$y} {$z}}} + TXT); $this->assertSame('42 number42 _number', $value); } @@ -190,11 +190,11 @@ public function test_local_declarations_quoted_literals(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .local $x = {|@literal|} - .local $y = {|white space|} - .local $z = {|{{curly braces}}|} - {{{$x} {$y} {$z} {|and \\, a backslash|}}} - TXT); + .local $x = {|@literal|} + .local $y = {|white space|} + .local $z = {|{{curly braces}}|} + {{{$x} {$y} {$z} {|and \\, a backslash|}}} + TXT); $this->assertSame('@literal white space {{curly braces}} and \, a backslash', $value); } @@ -203,9 +203,9 @@ public function test_whitespace(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .input {$num :number} - {{ This is the {$num} pattern }} - TXT, num: 5); + .input {$num :number} + {{ This is the {$num} pattern }} + TXT, num: 5); $this->assertSame(' This is the 5 pattern ', $value); } @@ -214,8 +214,8 @@ public function test_escape(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Backslash: \\, left curly brace \{, right curly brace \} - TXT); + Backslash: \\, left curly brace \{, right curly brace \} + TXT); $this->assertSame('Backslash: \, left curly brace {, right curly brace }', $value); } @@ -224,12 +224,12 @@ public function test_matchers_escape(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .input {$char :string} - .match $char - | | {{You entered a space character.}} - |\|| {{You entered a pipe character.}} - * {{You entered something else.}} - TXT, char: '|'); + .input {$char :string} + .match $char + | | {{You entered a space character.}} + |\|| {{You entered a pipe character.}} + * {{You entered something else.}} + TXT, char: '|'); $this->assertSame('You entered a pipe character.', $value); } @@ -239,12 +239,12 @@ public function test_matchers_number_exact_match(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$numDays :number select=exact} - .match $numDays - 1 {{{$numDays} one}} - 2 {{{$numDays} two}} - 3 {{{$numDays} three}} - TXT, numDays: 2); + .input {$numDays :number select=exact} + .match $numDays + 1 {{{$numDays} one}} + 2 {{{$numDays} two}} + 3 {{{$numDays} three}} + TXT, numDays: 2); $this->assertSame('2 two', $value); } @@ -260,13 +260,13 @@ public function test_matchers_czech(int|float $days, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$days :number} - .match $days - one {{{$days} den}} - few {{{$days} dny}} - many {{{$days} dne}} - * {{{$days} dní}} - TXT, days: $days); + .input {$days :number} + .match $days + one {{{$days} den}} + few {{{$days} dny}} + many {{{$days} dne}} + * {{{$days} dní}} + TXT, days: $days); $this->assertSame($expected, $value); } @@ -279,12 +279,12 @@ public function test_string_function(): void ]); $value = $formatter->format(<<<'TXT' - .input {$operand :string} - .match $operand - 1 {{Number 1}} - one {{String "one"}} - * {{Something else}} - TXT, operand: 1); + .input {$operand :string} + .match $operand + 1 {{Number 1}} + one {{String "one"}} + * {{Something else}} + TXT, operand: 1); $this->assertSame('Number 1', $value); } @@ -298,8 +298,8 @@ public function test_string_formatting(mixed $input, string $expected): void $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<<'TXT' - {$value :string} - TXT, value: $input); + {$value :string} + TXT, value: $input); $this->assertSame($expected, $value); } @@ -316,8 +316,8 @@ public function test_string_formatting_options(mixed $input, string $expected, s $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<assertSame($expected, $value); } @@ -327,8 +327,8 @@ public function test_number_currency(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - You have {42 :number style=currency currency=$currency}. - TXT, currency: Currency::USD); + You have {42 :number style=currency currency=$currency}. + TXT, currency: Currency::USD); $this->assertSame('You have $42.00.', $value); } @@ -338,9 +338,9 @@ public function test_shadowing(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .local $count = {42} - {{The count is: {$count}}} - TXT, count: 32); + .local $count = {42} + {{The count is: {$count}}} + TXT, count: 32); $this->assertSame('The count is: 42', $value); } @@ -353,12 +353,12 @@ public function test_pluralization(int $count, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number} - .match $count - 0 {{No items.}} - one {{1 item.}} - * {{{$count} items.}} - TXT, count: $count); + .input {$count :number} + .match $count + 0 {{No items.}} + one {{1 item.}} + * {{{$count} items.}} + TXT, count: $count); $this->assertSame($expected, $value); } @@ -371,22 +371,22 @@ public function test_multiple_selectors(): void ]); $value = $formatter->format(<<<'TXT' - .input {$hostGender :string} - .input {$guestCount :number} - .match $hostGender $guestCount - female 0 {{{$hostName} does not give a party.}} - female 1 {{{$hostName} invites {$guestName} to her party.}} - female 2 {{{$hostName} invites {$guestName} and one other person to her party.}} - female * {{{$hostName} invites {$guestCount} people, including {$guestName}, to her party.}} - male 0 {{{$hostName} does not give a party.}} - male 1 {{{$hostName} invites {$guestName} to his party.}} - male 2 {{{$hostName} invites {$guestName} and one other person to his party.}} - male * {{{$hostName} invites {$guestCount} people, including {$guestName}, to his party.}} - * 0 {{{$hostName} does not give a party.}} - * 1 {{{$hostName} invites {$guestName} to their party.}} - * 2 {{{$hostName} invites {$guestName} and one other person to their party.}} - * * {{{$hostName} invites {$guestCount} people, including {$guestName}, to their party.}} - TXT, hostGender: 'female', hostName: 'Alice', guestCount: 2, guestName: 'Bob'); + .input {$hostGender :string} + .input {$guestCount :number} + .match $hostGender $guestCount + female 0 {{{$hostName} does not give a party.}} + female 1 {{{$hostName} invites {$guestName} to her party.}} + female 2 {{{$hostName} invites {$guestName} and one other person to her party.}} + female * {{{$hostName} invites {$guestCount} people, including {$guestName}, to her party.}} + male 0 {{{$hostName} does not give a party.}} + male 1 {{{$hostName} invites {$guestName} to his party.}} + male 2 {{{$hostName} invites {$guestName} and one other person to his party.}} + male * {{{$hostName} invites {$guestCount} people, including {$guestName}, to his party.}} + * 0 {{{$hostName} does not give a party.}} + * 1 {{{$hostName} invites {$guestName} to their party.}} + * 2 {{{$hostName} invites {$guestName} and one other person to their party.}} + * * {{{$hostName} invites {$guestCount} people, including {$guestName}, to their party.}} + TXT, hostGender: 'female', hostName: 'Alice', guestCount: 2, guestName: 'Bob'); $this->assertSame('Alice invites Bob and one other person to her party.', $value); } @@ -405,8 +405,8 @@ public function format(mixed $value, array $parameters): FormattedValue ]); $value = $formatter->format(<<<'TXT' - Check out {MessageFormat :uppercase}. - TXT); + Check out {MessageFormat :uppercase}. + TXT); $this->assertSame('Check out MESSAGEFORMAT.', $value); } diff --git a/packages/intl/tests/GenericTranslatorTest.php b/packages/intl/tests/GenericTranslatorTest.php index fcc76a9f8..bbbb82e73 100644 --- a/packages/intl/tests/GenericTranslatorTest.php +++ b/packages/intl/tests/GenericTranslatorTest.php @@ -66,12 +66,12 @@ public function test_complex_message(): void $this->config->currentLocale = Locale::FRENCH; $this->catalog->add(Locale::FRENCH, 'aircraft_count', <<<'MF2' - .input {$aircraft :number} - .match $aircraft - 0 {{pas d'avion}} - 1 {{un avion}} - * {{{$aircraft} avions}} - MF2); + .input {$aircraft :number} + .match $aircraft + 0 {{pas d'avion}} + 1 {{un avion}} + * {{{$aircraft} avions}} + MF2); $this->assertSame("pas d'avion", $this->translator->translate('aircraft_count', aircraft: 0)); $this->assertSame('un avion', $this->translator->translate('aircraft_count', aircraft: 1)); diff --git a/packages/intl/tests/ParserTest.php b/packages/intl/tests/ParserTest.php index 986091839..913803459 100644 --- a/packages/intl/tests/ParserTest.php +++ b/packages/intl/tests/ParserTest.php @@ -30,9 +30,9 @@ public function test_local_declaration(): void { /** @var ComplexMessage $ast */ $ast = new MessageFormatParser(<<<'MF2' - .local $time = {$launch_date :datetime style=|medium|} - Launch time: {$time} - MF2)->parse(); + .local $time = {$launch_date :datetime style=|medium|} + Launch time: {$time} + MF2)->parse(); $this->assertInstanceOf(ComplexMessage::class, $ast); $this->assertInstanceOf(Text::class, $ast->pattern->elements[0]); @@ -53,12 +53,12 @@ public function test_input_declaration(): void { /** @var ComplexMessage $ast */ $ast = new MessageFormatParser(<<<'MF2' - .input {$numDays :number select=exact} - .match $numDays - 1 {{{$numDays} one}} - 2 {{{$numDays} two}} - 3 {{{$numDays} three}} - MF2)->parse(); + .input {$numDays :number select=exact} + .match $numDays + 1 {{{$numDays} one}} + 2 {{{$numDays} two}} + 3 {{{$numDays} three}} + MF2)->parse(); $this->assertInstanceOf(ComplexMessage::class, $ast); $this->assertInstanceOf(InputDeclaration::class, $ast->declarations[0]); @@ -88,8 +88,8 @@ public function test_input_declaration(): void public function test_function_with_option_quoted_literal(): void { $ast = new MessageFormatParser(<<<'MF2' - Today is {$today :datetime pattern=|yyyy/MM/dd|}. - MF2)->parse(); + Today is {$today :datetime pattern=|yyyy/MM/dd|}. + MF2)->parse(); $this->assertInstanceOf(SimpleMessage::class, $ast); $this->assertInstanceOf(VariableExpression::class, $ast->pattern->elements[1]); diff --git a/packages/kv-store/src/Redis/RedisException.php b/packages/kv-store/src/Redis/RedisException.php index ea92d27bd..4e1d824d8 100644 --- a/packages/kv-store/src/Redis/RedisException.php +++ b/packages/kv-store/src/Redis/RedisException.php @@ -4,6 +4,4 @@ use Throwable; -interface RedisException extends Throwable -{ -} +interface RedisException extends Throwable {} diff --git a/packages/log/src/LogConfig.php b/packages/log/src/LogConfig.php index 4e3502073..f78d94106 100644 --- a/packages/log/src/LogConfig.php +++ b/packages/log/src/LogConfig.php @@ -11,16 +11,12 @@ interface LogConfig extends HasTag /** * An optional prefix displayed in all log messages. By default, the current environment is used. */ - public ?string $prefix { - get; - } + public ?string $prefix { get; } /** * The log channels to which log messages will be sent. * * @var LogChannel[] */ - public array $logChannels { - get; - } + public array $logChannels { get; } } diff --git a/packages/log/src/Logger.php b/packages/log/src/Logger.php index 0ebe03df3..e8ba8017e 100644 --- a/packages/log/src/Logger.php +++ b/packages/log/src/Logger.php @@ -6,6 +6,4 @@ use Psr\Log\LoggerInterface; -interface Logger extends LoggerInterface -{ -} +interface Logger extends LoggerInterface {} diff --git a/packages/mail/src/Email.php b/packages/mail/src/Email.php index d8221cfdb..74a856af4 100644 --- a/packages/mail/src/Email.php +++ b/packages/mail/src/Email.php @@ -12,14 +12,10 @@ interface Email /** * The envelope of the email. */ - public Envelope $envelope { - get; - } + public Envelope $envelope { get; } /** * The content of the email can be a path to a view file, raw HTML, or a View object */ - public string|View $html { - get; - } + public string|View $html { get; } } diff --git a/packages/mail/src/Exceptions/MailerException.php b/packages/mail/src/Exceptions/MailerException.php index fc51bd89c..0a4747668 100644 --- a/packages/mail/src/Exceptions/MailerException.php +++ b/packages/mail/src/Exceptions/MailerException.php @@ -2,6 +2,4 @@ namespace Tempest\Mail\Exceptions; -interface MailerException -{ -} +interface MailerException {} diff --git a/packages/mail/src/HasAttachments.php b/packages/mail/src/HasAttachments.php index 70423315c..6ef8742ff 100644 --- a/packages/mail/src/HasAttachments.php +++ b/packages/mail/src/HasAttachments.php @@ -7,7 +7,5 @@ interface HasAttachments /** * @var \Tempest\Mail\Attachment[] $attachments */ - public array $attachments { - get; - } + public array $attachments { get; } } diff --git a/packages/mail/src/HasTextContent.php b/packages/mail/src/HasTextContent.php index d1e5e6f95..d4b6a33c6 100644 --- a/packages/mail/src/HasTextContent.php +++ b/packages/mail/src/HasTextContent.php @@ -6,7 +6,5 @@ interface HasTextContent { - public string|View|null $text { - get; - } + public string|View|null $text { get; } } diff --git a/packages/mail/src/MailerConfig.php b/packages/mail/src/MailerConfig.php index 4cbfbb618..28c1ac6f4 100644 --- a/packages/mail/src/MailerConfig.php +++ b/packages/mail/src/MailerConfig.php @@ -11,9 +11,7 @@ interface MailerConfig * * @var class-string */ - public string $transport { - get; - } + public string $transport { get; } /** * Creates the transport. diff --git a/packages/mail/src/Transports/ProvidesDefaultSender.php b/packages/mail/src/Transports/ProvidesDefaultSender.php index 20486a443..fceb3701a 100644 --- a/packages/mail/src/Transports/ProvidesDefaultSender.php +++ b/packages/mail/src/Transports/ProvidesDefaultSender.php @@ -9,7 +9,5 @@ interface ProvidesDefaultSender /** * The default address from which emails will be sent. */ - public null|string|EmailAddress $defaultSender { - get; - } + public null|string|EmailAddress $defaultSender { get; } } diff --git a/packages/mapper/src/Context.php b/packages/mapper/src/Context.php index 917e1d8b7..444d8f179 100644 --- a/packages/mapper/src/Context.php +++ b/packages/mapper/src/Context.php @@ -10,7 +10,5 @@ interface Context /** * A unique name for this context. */ - public string $name { - get; - } + public string $name { get; } } diff --git a/packages/mapper/src/Hidden.php b/packages/mapper/src/Hidden.php index 9c9e94f05..964c4379c 100644 --- a/packages/mapper/src/Hidden.php +++ b/packages/mapper/src/Hidden.php @@ -10,6 +10,4 @@ * Hidden properties are excluded from SELECT queries and serialization. */ #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Hidden -{ -} +final readonly class Hidden {} diff --git a/packages/mapper/src/ProvidesCaster.php b/packages/mapper/src/ProvidesCaster.php index 921357c6a..9d23e9aa5 100644 --- a/packages/mapper/src/ProvidesCaster.php +++ b/packages/mapper/src/ProvidesCaster.php @@ -8,7 +8,5 @@ interface ProvidesCaster { /** @var class-string */ - public string $caster { - get; - } + public string $caster { get; } } diff --git a/packages/mapper/src/ProvidesSerializer.php b/packages/mapper/src/ProvidesSerializer.php index 86efbfb38..0f9cab41b 100644 --- a/packages/mapper/src/ProvidesSerializer.php +++ b/packages/mapper/src/ProvidesSerializer.php @@ -8,7 +8,5 @@ interface ProvidesSerializer { /** @var class-string */ - public string $serializer { - get; - } + public string $serializer { get; } } diff --git a/packages/mapper/src/Strict.php b/packages/mapper/src/Strict.php index 35a389a17..5f2593655 100644 --- a/packages/mapper/src/Strict.php +++ b/packages/mapper/src/Strict.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] -final readonly class Strict -{ -} +final readonly class Strict {} diff --git a/packages/mapper/src/UnknownValue.php b/packages/mapper/src/UnknownValue.php index 170a5c712..e7b599665 100644 --- a/packages/mapper/src/UnknownValue.php +++ b/packages/mapper/src/UnknownValue.php @@ -4,6 +4,4 @@ namespace Tempest\Mapper; -final readonly class UnknownValue -{ -} +final readonly class UnknownValue {} diff --git a/packages/process/src/Exceptions/ProcessException.php b/packages/process/src/Exceptions/ProcessException.php index 00c0f6925..7d00205de 100644 --- a/packages/process/src/Exceptions/ProcessException.php +++ b/packages/process/src/Exceptions/ProcessException.php @@ -4,6 +4,4 @@ use Throwable; -interface ProcessException extends Throwable -{ -} +interface ProcessException extends Throwable {} diff --git a/packages/process/src/InvokedProcess.php b/packages/process/src/InvokedProcess.php index 7465f258c..216abf422 100644 --- a/packages/process/src/InvokedProcess.php +++ b/packages/process/src/InvokedProcess.php @@ -9,30 +9,22 @@ interface InvokedProcess /** * Gets the process identifier. */ - public ?int $pid { - get; - } + public ?int $pid { get; } /** * Whether the process is running. */ - public bool $running { - get; - } + public bool $running { get; } /** * Gets the output of the process. */ - public string $output { - get; - } + public string $output { get; } /** * Gets the error output of the process. */ - public string $errorOutput { - get; - } + public string $errorOutput { get; } /** * Sends a signal to the process. diff --git a/packages/reflection/src/PropertyAttribute.php b/packages/reflection/src/PropertyAttribute.php index 0e669c9ce..8b5683076 100644 --- a/packages/reflection/src/PropertyAttribute.php +++ b/packages/reflection/src/PropertyAttribute.php @@ -4,8 +4,5 @@ interface PropertyAttribute { - public PropertyReflector $property { - set; - get; - } + public PropertyReflector $property { set; get; } } diff --git a/packages/reflection/tests/EnumReflectorTest.php b/packages/reflection/tests/EnumReflectorTest.php index 2af7df7d4..d316b271d 100644 --- a/packages/reflection/tests/EnumReflectorTest.php +++ b/packages/reflection/tests/EnumReflectorTest.php @@ -271,9 +271,7 @@ enum TestIntBackedEnum: int case SECOND = 2; } -interface TestInterface -{ -} +interface TestInterface {} enum TestEnumWithInterface: string implements TestInterface { diff --git a/packages/reflection/tests/Fixtures/AnnulledInvoice.php b/packages/reflection/tests/Fixtures/AnnulledInvoice.php index f5d5c7f8f..76bb96e17 100644 --- a/packages/reflection/tests/Fixtures/AnnulledInvoice.php +++ b/packages/reflection/tests/Fixtures/AnnulledInvoice.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final readonly class AnnulledInvoice -{ -} +final readonly class AnnulledInvoice {} diff --git a/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php index 1483015ae..622d60770 100644 --- a/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute -{ -} +final class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php index 39ecc50d5..9558fb05f 100644 --- a/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute -{ -} +final class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php index 7282e5687..d8f1f2c52 100644 --- a/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php @@ -5,6 +5,4 @@ namespace Tempest\Reflection\Tests\Fixtures; #[RecursiveAttribute] -interface InterfaceWithRecursiveAttribute -{ -} +interface InterfaceWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/NullableClass.php b/packages/reflection/tests/Fixtures/NullableClass.php index a2af1e599..6f745ad02 100644 --- a/packages/reflection/tests/Fixtures/NullableClass.php +++ b/packages/reflection/tests/Fixtures/NullableClass.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final readonly class NullableClass -{ -} +final readonly class NullableClass {} diff --git a/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php index 9cf1cfe57..76cd13221 100644 --- a/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php @@ -5,6 +5,4 @@ namespace Tempest\Reflection\Tests\Fixtures; #[RecursiveAttribute] -abstract class ParentWithRecursiveAttribute -{ -} +abstract class ParentWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/RecursiveAttribute.php b/packages/reflection/tests/Fixtures/RecursiveAttribute.php index 32d3856c7..cd6814e67 100644 --- a/packages/reflection/tests/Fixtures/RecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/RecursiveAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute] -final class RecursiveAttribute -{ -} +final class RecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/TestBackedEnum.php b/packages/reflection/tests/Fixtures/TestBackedEnum.php index e33bbd8d9..6d300b899 100644 --- a/packages/reflection/tests/Fixtures/TestBackedEnum.php +++ b/packages/reflection/tests/Fixtures/TestBackedEnum.php @@ -2,6 +2,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -enum TestBackedEnum: string -{ -} +enum TestBackedEnum: string {} diff --git a/packages/reflection/tests/Fixtures/TestEnum.php b/packages/reflection/tests/Fixtures/TestEnum.php index b9f6052b5..9d1c8b629 100644 --- a/packages/reflection/tests/Fixtures/TestEnum.php +++ b/packages/reflection/tests/Fixtures/TestEnum.php @@ -2,6 +2,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -enum TestEnum -{ -} +enum TestEnum {} diff --git a/packages/router/src/Exceptions/RouteBindingFailed.php b/packages/router/src/Exceptions/RouteBindingFailed.php index dbd261b54..879ca6d9a 100644 --- a/packages/router/src/Exceptions/RouteBindingFailed.php +++ b/packages/router/src/Exceptions/RouteBindingFailed.php @@ -6,6 +6,4 @@ use Exception; -final class RouteBindingFailed extends Exception implements RouterException -{ -} +final class RouteBindingFailed extends Exception implements RouterException {} diff --git a/packages/router/src/Exceptions/RouterException.php b/packages/router/src/Exceptions/RouterException.php index 3f357efb2..e4ecbde43 100644 --- a/packages/router/src/Exceptions/RouterException.php +++ b/packages/router/src/Exceptions/RouterException.php @@ -2,6 +2,4 @@ namespace Tempest\Router\Exceptions; -interface RouterException -{ -} +interface RouterException {} diff --git a/packages/router/src/IsBindingValue.php b/packages/router/src/IsBindingValue.php index d2f633936..a345c6096 100644 --- a/packages/router/src/IsBindingValue.php +++ b/packages/router/src/IsBindingValue.php @@ -5,6 +5,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class IsBindingValue -{ -} +final class IsBindingValue {} diff --git a/packages/router/src/Route.php b/packages/router/src/Route.php index 3387556c1..082d0ed84 100644 --- a/packages/router/src/Route.php +++ b/packages/router/src/Route.php @@ -8,25 +8,13 @@ interface Route { - public Method $method { - get; - set; - } + public Method $method { get; set; } - public string $uri { - get; - set; - } + public string $uri { get; set; } /** @var class-string[] */ - public array $middleware { - get; - set; - } + public array $middleware { get; set; } /** @var class-string[] */ - public array $without { - get; - set; - } + public array $without { get; set; } } diff --git a/packages/router/src/Static/Exceptions/StaticPageException.php b/packages/router/src/Static/Exceptions/StaticPageException.php index d6c563afc..44810abb4 100644 --- a/packages/router/src/Static/Exceptions/StaticPageException.php +++ b/packages/router/src/Static/Exceptions/StaticPageException.php @@ -4,7 +4,5 @@ interface StaticPageException { - public string $uri { - get; - } + public string $uri { get; } } diff --git a/packages/router/tests/FakeRouteBuilder.php b/packages/router/tests/FakeRouteBuilder.php index 1d041c799..08f523e8f 100644 --- a/packages/router/tests/FakeRouteBuilder.php +++ b/packages/router/tests/FakeRouteBuilder.php @@ -47,7 +47,5 @@ public function asDiscoveredRoute(): DiscoveredRoute return DiscoveredRoute::fromRoute($this, [], $this->handler); } - public function handler(): void - { - } + public function handler(): void {} } diff --git a/packages/router/tests/FakeRouteBuilderWithOptionalParams.php b/packages/router/tests/FakeRouteBuilderWithOptionalParams.php index ed03e644e..95e71f316 100644 --- a/packages/router/tests/FakeRouteBuilderWithOptionalParams.php +++ b/packages/router/tests/FakeRouteBuilderWithOptionalParams.php @@ -53,19 +53,11 @@ public function asDiscoveredRoute(): DiscoveredRoute return DiscoveredRoute::fromRoute($this, [], $this->handler); } - public function handler(): void - { - } + public function handler(): void {} - public function handlerWithOptionalId(string $id = 'default-id'): void - { - } + public function handlerWithOptionalId(string $id = 'default-id'): void {} - public function handlerWithTwoOptionalParams(string $id = 'default-id', string $slug = 'default-slug'): void - { - } + public function handlerWithTwoOptionalParams(string $id = 'default-id', string $slug = 'default-slug'): void {} - public function handlerWithRequiredAndOptional(string $id, string $slug = 'default-slug'): void - { - } + public function handlerWithRequiredAndOptional(string $id, string $slug = 'default-slug'): void {} } diff --git a/packages/storage/src/Config/StorageConfig.php b/packages/storage/src/Config/StorageConfig.php index 1c0b4b921..33b8b33f9 100644 --- a/packages/storage/src/Config/StorageConfig.php +++ b/packages/storage/src/Config/StorageConfig.php @@ -10,17 +10,12 @@ interface StorageConfig extends HasTag /** * Whether the storage is read-only. */ - public bool $readonly { - get; - set; - } + public bool $readonly { get; set; } /** * The adapter class. */ - public string $adapter { - get; - } + public string $adapter { get; } /** * Creates the adapter. diff --git a/packages/storage/src/StorageException.php b/packages/storage/src/StorageException.php index 9136ec1d7..f4a4bcb0c 100644 --- a/packages/storage/src/StorageException.php +++ b/packages/storage/src/StorageException.php @@ -2,6 +2,4 @@ namespace Tempest\Storage; -interface StorageException -{ -} +interface StorageException {} diff --git a/packages/support/src/Arr/OffsetDidNotExist.php b/packages/support/src/Arr/OffsetDidNotExist.php index e99cd224e..6099e582f 100644 --- a/packages/support/src/Arr/OffsetDidNotExist.php +++ b/packages/support/src/Arr/OffsetDidNotExist.php @@ -6,6 +6,4 @@ use Exception; -final class OffsetDidNotExist extends Exception -{ -} +final class OffsetDidNotExist extends Exception {} diff --git a/packages/support/src/Filesystem/Exceptions/FilesystemException.php b/packages/support/src/Filesystem/Exceptions/FilesystemException.php index 4a0ffcf5d..574811e3c 100644 --- a/packages/support/src/Filesystem/Exceptions/FilesystemException.php +++ b/packages/support/src/Filesystem/Exceptions/FilesystemException.php @@ -2,6 +2,4 @@ namespace Tempest\Support\Filesystem\Exceptions; -interface FilesystemException -{ -} +interface FilesystemException {} diff --git a/packages/support/src/Filesystem/Exceptions/RuntimeException.php b/packages/support/src/Filesystem/Exceptions/RuntimeException.php index 145b290ee..de5084684 100644 --- a/packages/support/src/Filesystem/Exceptions/RuntimeException.php +++ b/packages/support/src/Filesystem/Exceptions/RuntimeException.php @@ -6,6 +6,4 @@ use RuntimeException as PhpRuntimeException; -final class RuntimeException extends PhpRuntimeException implements FilesystemException -{ -} +final class RuntimeException extends PhpRuntimeException implements FilesystemException {} diff --git a/packages/support/src/JavaScript/PackageManager.php b/packages/support/src/JavaScript/PackageManager.php index f354f743f..b2649ff8a 100644 --- a/packages/support/src/JavaScript/PackageManager.php +++ b/packages/support/src/JavaScript/PackageManager.php @@ -62,9 +62,9 @@ public static function detect(string $cwd): ?self { return array_find( array: PackageManager::cases(), - callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file($cwd - . '/' - . $lockFile)), + callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file( + $cwd . '/' . $lockFile, + )), ); } } diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php index 9b2c4ac99..54e0cb013 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php @@ -7,6 +7,4 @@ use InvalidArgumentException; use Tempest\Support\Json\Exception\JsonException; -final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException -{ -} +final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php index 5548f1f33..643d92ddd 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php @@ -7,6 +7,4 @@ use InvalidArgumentException; use Tempest\Support\Json\Exception\JsonException; -final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException -{ -} +final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonException.php b/packages/support/src/Json/Exception/JsonException.php index 43a580f29..39462316d 100644 --- a/packages/support/src/Json/Exception/JsonException.php +++ b/packages/support/src/Json/Exception/JsonException.php @@ -4,6 +4,4 @@ namespace Tempest\Support\Json\Exception; -interface JsonException -{ -} +interface JsonException {} diff --git a/packages/support/src/Math/Exception/ArithmeticException.php b/packages/support/src/Math/Exception/ArithmeticException.php index 8ea8a23a9..76c4f935e 100644 --- a/packages/support/src/Math/Exception/ArithmeticException.php +++ b/packages/support/src/Math/Exception/ArithmeticException.php @@ -7,6 +7,4 @@ use InvalidArgumentException; // @phpstan-ignore-next-line -class ArithmeticException extends InvalidArgumentException implements MathException -{ -} +class ArithmeticException extends InvalidArgumentException implements MathException {} diff --git a/packages/support/src/Math/Exception/DivisionByZeroException.php b/packages/support/src/Math/Exception/DivisionByZeroException.php index 24ad58821..517aed1d7 100644 --- a/packages/support/src/Math/Exception/DivisionByZeroException.php +++ b/packages/support/src/Math/Exception/DivisionByZeroException.php @@ -4,6 +4,4 @@ namespace Tempest\Support\Math\Exception; -final class DivisionByZeroException extends ArithmeticException -{ -} +final class DivisionByZeroException extends ArithmeticException {} diff --git a/packages/support/src/Math/Exception/InvalidArgumentException.php b/packages/support/src/Math/Exception/InvalidArgumentException.php index ade156b76..0279d738c 100644 --- a/packages/support/src/Math/Exception/InvalidArgumentException.php +++ b/packages/support/src/Math/Exception/InvalidArgumentException.php @@ -6,6 +6,4 @@ use InvalidArgumentException as PhpInvalidArgumentException; -final class InvalidArgumentException extends PhpInvalidArgumentException implements MathException -{ -} +final class InvalidArgumentException extends PhpInvalidArgumentException implements MathException {} diff --git a/packages/support/src/Math/Exception/MathException.php b/packages/support/src/Math/Exception/MathException.php index da1558aeb..7537b33a3 100644 --- a/packages/support/src/Math/Exception/MathException.php +++ b/packages/support/src/Math/Exception/MathException.php @@ -4,6 +4,4 @@ namespace Tempest\Support\Math\Exception; -interface MathException -{ -} +interface MathException {} diff --git a/packages/support/src/Math/Exception/OverflowException.php b/packages/support/src/Math/Exception/OverflowException.php index bfbd53e39..3415a9403 100644 --- a/packages/support/src/Math/Exception/OverflowException.php +++ b/packages/support/src/Math/Exception/OverflowException.php @@ -6,6 +6,4 @@ use OverflowException as PhpOverflowException; -final class OverflowException extends PhpOverflowException implements MathException -{ -} +final class OverflowException extends PhpOverflowException implements MathException {} diff --git a/packages/support/src/Namespace/functions.php b/packages/support/src/Namespace/functions.php index 06bc5ba26..22308bdb1 100644 --- a/packages/support/src/Namespace/functions.php +++ b/packages/support/src/Namespace/functions.php @@ -123,9 +123,11 @@ function prepare_namespace(Stringable|string $path, null|Stringable|string $root // If the path is a to a PHP file, we exclude the file name. Otherwise, // it's a path to a directory, which should be included in the namespace. if ($normalized->endsWith('.php')) { - return $normalized->contains(['/', '\\']) - ? $normalized->beforeLast(['/', '\\']) - : new ImmutableString(); + return ( + $normalized->contains(['/', '\\']) + ? $normalized->beforeLast(['/', '\\']) + : new ImmutableString() + ); } return $normalized; diff --git a/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php b/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php index 8d332b2bc..e4462f07e 100644 --- a/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php +++ b/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php @@ -4,6 +4,4 @@ use InvalidArgumentException as PhpInvalidArgumentException; -final class ArgumentWasInvalid extends PhpInvalidArgumentException implements PaginationException -{ -} +final class ArgumentWasInvalid extends PhpInvalidArgumentException implements PaginationException {} diff --git a/packages/support/src/Paginator/Exceptions/PaginationException.php b/packages/support/src/Paginator/Exceptions/PaginationException.php index 261508265..1baf9d68a 100644 --- a/packages/support/src/Paginator/Exceptions/PaginationException.php +++ b/packages/support/src/Paginator/Exceptions/PaginationException.php @@ -2,6 +2,4 @@ namespace Tempest\Support\Paginator\Exceptions; -interface PaginationException -{ -} +interface PaginationException {} diff --git a/packages/support/src/Regex/InvalidPatternException.php b/packages/support/src/Regex/InvalidPatternException.php index c607821b7..6814b90a1 100644 --- a/packages/support/src/Regex/InvalidPatternException.php +++ b/packages/support/src/Regex/InvalidPatternException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class InvalidPatternException extends RuntimeException -{ -} +final class InvalidPatternException extends RuntimeException {} diff --git a/packages/support/src/Str/StringInterface.php b/packages/support/src/Str/StringInterface.php index 1fc7f43f2..c56f72700 100644 --- a/packages/support/src/Str/StringInterface.php +++ b/packages/support/src/Str/StringInterface.php @@ -10,6 +10,4 @@ /** * @internal This interface is not meant to be used in userland. */ -interface StringInterface extends Stringable, JsonSerializable -{ -} +interface StringInterface extends Stringable, JsonSerializable {} diff --git a/packages/support/src/VarExport/EmptyFileNameException.php b/packages/support/src/VarExport/EmptyFileNameException.php index ea0c884e9..971c27016 100644 --- a/packages/support/src/VarExport/EmptyFileNameException.php +++ b/packages/support/src/VarExport/EmptyFileNameException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class EmptyFileNameException extends RuntimeException -{ -} +final class EmptyFileNameException extends RuntimeException {} diff --git a/packages/support/src/VarExport/FileDoesNotExistException.php b/packages/support/src/VarExport/FileDoesNotExistException.php index 4b60ade07..42e029314 100644 --- a/packages/support/src/VarExport/FileDoesNotExistException.php +++ b/packages/support/src/VarExport/FileDoesNotExistException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class FileDoesNotExistException extends RuntimeException -{ -} +final class FileDoesNotExistException extends RuntimeException {} diff --git a/packages/support/src/VarExport/VarExportPhpFile.php b/packages/support/src/VarExport/VarExportPhpFile.php index 3cc625266..fb17b7e3a 100644 --- a/packages/support/src/VarExport/VarExportPhpFile.php +++ b/packages/support/src/VarExport/VarExportPhpFile.php @@ -47,9 +47,9 @@ public function export(mixed $data): void $serializedData = VarExporter::export($data); $phpFileContent = <<filename, $phpFileContent, LOCK_EX); } diff --git a/packages/support/tests/Json/JsonTest.php b/packages/support/tests/Json/JsonTest.php index f8b746760..d50a98ca4 100644 --- a/packages/support/tests/Json/JsonTest.php +++ b/packages/support/tests/Json/JsonTest.php @@ -65,20 +65,20 @@ public function test_pretty_encode(): void ], true); $json = Str\replace(<<assertSame($json, $actual); } diff --git a/packages/validation/src/SkipValidation.php b/packages/validation/src/SkipValidation.php index dddf690fc..0ae0fa7b1 100644 --- a/packages/validation/src/SkipValidation.php +++ b/packages/validation/src/SkipValidation.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class SkipValidation -{ -} +final class SkipValidation {} diff --git a/packages/view/src/Components/x-component.view.php b/packages/view/src/Components/x-component.view.php index c35181f9d..7847fd8c4 100644 --- a/packages/view/src/Components/x-component.view.php +++ b/packages/view/src/Components/x-component.view.php @@ -17,10 +17,10 @@ $content = $slots[Slot::DEFAULT]->content ?? ''; $template = sprintf(<<<'HTML' -<%s %s> -%s - -HTML, $is, $attributeString, $content, $is); + <%s %s> + %s + + HTML, $is, $attributeString, $content, $is); $data = $scopedVariables ?? $_data ?? []; $data = is_array($data) ? $data : []; diff --git a/packages/view/src/Export/ExportableViewObject.php b/packages/view/src/Export/ExportableViewObject.php index c05f64774..4be43a25a 100644 --- a/packages/view/src/Export/ExportableViewObject.php +++ b/packages/view/src/Export/ExportableViewObject.php @@ -6,9 +6,7 @@ interface ExportableViewObject { - public ImmutableArray $exportData { - get; - } + public ImmutableArray $exportData { get; } public static function restore(mixed ...$data): self; } diff --git a/packages/view/src/ShouldBeRemoved.php b/packages/view/src/ShouldBeRemoved.php index 017adba67..318373f37 100644 --- a/packages/view/src/ShouldBeRemoved.php +++ b/packages/view/src/ShouldBeRemoved.php @@ -2,6 +2,4 @@ namespace Tempest\View; -interface ShouldBeRemoved -{ -} +interface ShouldBeRemoved {} diff --git a/packages/view/src/View.php b/packages/view/src/View.php index 0f9695dc0..9a585116d 100644 --- a/packages/view/src/View.php +++ b/packages/view/src/View.php @@ -6,17 +6,11 @@ interface View { - public string $path { - get; - } + public string $path { get; } - public ?string $relativeRootPath { - get; - } + public ?string $relativeRootPath { get; } - public array $data { - get; - } + public array $data { get; } public function get(string $key): mixed; diff --git a/packages/view/src/WithToken.php b/packages/view/src/WithToken.php index 23e4fe2ab..20922797e 100644 --- a/packages/view/src/WithToken.php +++ b/packages/view/src/WithToken.php @@ -8,7 +8,5 @@ interface WithToken { - public Token $token { - get; - } + public Token $token { get; } } diff --git a/packages/view/tests/FallthroughAttributesTest.php b/packages/view/tests/FallthroughAttributesTest.php index 89a6f8475..d6670dec6 100644 --- a/packages/view/tests/FallthroughAttributesTest.php +++ b/packages/view/tests/FallthroughAttributesTest.php @@ -29,10 +29,10 @@ public function render(): void ); $this->assertEquals(str_replace([' ', PHP_EOL], '', <<<'HTML' -
-
-
-
- HTML), str_replace([' ', PHP_EOL], '', $html)); +
+
+
+
+ HTML), str_replace([' ', PHP_EOL], '', $html)); } } diff --git a/packages/view/tests/StandaloneViewRendererTest.php b/packages/view/tests/StandaloneViewRendererTest.php index 0a8ab7910..6630e9d21 100644 --- a/packages/view/tests/StandaloneViewRendererTest.php +++ b/packages/view/tests/StandaloneViewRendererTest.php @@ -33,10 +33,10 @@ public function test_render(): void ); $this->assertSnippetsMatch(<<<'HTML' -
- Hi -
- HTML, $html); +
+ Hi +
+ HTML, $html); } public function test_invalid_view_component_paths(): void @@ -86,10 +86,10 @@ public function test_with_cache_enabled(): void ); $this->assertSnippetsMatch(<<<'HTML' - - Hi - - HTML, $html); + + Hi + + HTML, $html); } public function test_with_cache_disabled(): void @@ -103,10 +103,10 @@ public function test_with_cache_disabled(): void ); $this->assertSnippetsMatch(<<<'HTML' - - Hi - - HTML, $html); + + Hi + + HTML, $html); } public function test_xml_declaration_with_short_open_tag(): void diff --git a/packages/view/tests/TempestViewLexerTest.php b/packages/view/tests/TempestViewLexerTest.php index 0ba62e288..53e27d922 100644 --- a/packages/view/tests/TempestViewLexerTest.php +++ b/packages/view/tests/TempestViewLexerTest.php @@ -14,8 +14,8 @@ final class TempestViewLexerTest extends TestCase public function test_lexer(): void { $html = <<hello - HTML; + hello + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -144,15 +144,15 @@ public function test_closing_tag(string $tag): void public function test_multiline_attributes(): void { $html = <<<'HTML' -
+
-
- HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -183,8 +183,8 @@ class=', TokenType::ATTRIBUTE_NAME), public function test_whitespace(): void { $html = <<<'HTML' -

Test Test

- HTML; +

Test Test

+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -210,8 +210,8 @@ public function test_whitespace(): void public function test_lexer_with_falsy_values(): void { $html = <<<'HTML' - a0a - HTML; + a0a + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -245,8 +245,8 @@ public function test_lexer_attribute_values(): void public function test_php_within_tag(): void { $html = <<<'HTML' -
class="foo" >
- HTML; +
class="foo" >
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -267,8 +267,8 @@ public function test_php_within_tag(): void public function test_doctype(): void { $html = <<<'HTML' - - HTML; + + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -283,8 +283,8 @@ public function test_doctype(): void ); $html = <<<'HTML' - - HTML; + + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -343,8 +343,8 @@ public function test_unclosed_comment_tag(): void public function test_cdata(): void { $tokens = new TempestViewLexer(<<<'RSS' - <![CDATA[ {{ $post['title'] }} ]]> - RSS)->lex(); + <![CDATA[ {{ $post['title'] }} ]]> + RSS)->lex(); $this->assertTokens( expected: [ @@ -362,8 +362,8 @@ public function test_cdata(): void public function test_xml(): void { $tokens = new TempestViewLexer(<<<'XML' - - XML)->lex(); + + XML)->lex(); $this->assertTokens( expected: [ @@ -376,8 +376,8 @@ public function test_xml(): void public function test_single_quote_attributes(): void { $html = << - HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); diff --git a/packages/view/tests/TempestViewParserTest.php b/packages/view/tests/TempestViewParserTest.php index c38135f41..0b1cff5e1 100644 --- a/packages/view/tests/TempestViewParserTest.php +++ b/packages/view/tests/TempestViewParserTest.php @@ -34,8 +34,8 @@ public function test_parser(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - hello - HTML, $parsed->compile()); + hello + HTML, $parsed->compile()); } public function test_parse_self_closing_tag_with_attributes(): void @@ -52,8 +52,8 @@ public function test_parse_self_closing_tag_with_attributes(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $parsed->compile()); + + HTML, $parsed->compile()); } public function test_self_closing_tags_with_attributes(): void @@ -63,8 +63,8 @@ public function test_self_closing_tags_with_attributes(): void $ast = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $ast->compile()); + + HTML, $ast->compile()); } public function test_invalid_closing_tag(): void @@ -79,19 +79,19 @@ public function test_invalid_closing_tag(): void public function test_invalid_closing_tag_ignores_commented_out_code(): void { $tokens = new TempestViewLexer(<< - - - HTML)->lex(); +

+ +

+ HTML)->lex(); $compiled = new TempestViewParser($tokens)->parse()->compile(); $this->assertSame(<< - - - HTML, $compiled); +

+ +

+ HTML, $compiled); } public function test_doctype(): void @@ -106,15 +106,15 @@ public function test_doctype(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $parsed->compile()); + + HTML, $parsed->compile()); } public function test_void_tags(): void { $html = <<<'HTML' -
- HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); diff --git a/packages/vite/src/Exceptions/EntrypointNotFoundException.php b/packages/vite/src/Exceptions/EntrypointNotFoundException.php index 980fc9464..f81400d09 100644 --- a/packages/vite/src/Exceptions/EntrypointNotFoundException.php +++ b/packages/vite/src/Exceptions/EntrypointNotFoundException.php @@ -4,6 +4,4 @@ namespace Tempest\Vite\Exceptions; -interface EntrypointNotFoundException extends ViteException -{ -} +interface EntrypointNotFoundException extends ViteException {} diff --git a/packages/vite/src/Exceptions/ViteException.php b/packages/vite/src/Exceptions/ViteException.php index e65746b26..4d176327d 100644 --- a/packages/vite/src/Exceptions/ViteException.php +++ b/packages/vite/src/Exceptions/ViteException.php @@ -4,6 +4,4 @@ namespace Tempest\Vite\Exceptions; -interface ViteException -{ -} +interface ViteException {} diff --git a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php index 9e86e52d1..ab8b83a1c 100644 --- a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php +++ b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php @@ -71,13 +71,13 @@ private function fileToAssetPath(string $file): string private function createReactRefreshTag(): string { return << - import RefreshRuntime from '{$this->bridgeFile->url}/@react-refresh'; - RefreshRuntime.injectIntoGlobalHook(window); - window.\$RefreshReg$ = () => {}; - window.\$RefreshSig$ = () => (type) => type; - window.__vite_plugin_react_preamble_installed__ = true; - - HTML; + + HTML; } } diff --git a/packages/vite/src/TagsResolver/ManifestTagsResolver.php b/packages/vite/src/TagsResolver/ManifestTagsResolver.php index 17da4e616..f5f526307 100644 --- a/packages/vite/src/TagsResolver/ManifestTagsResolver.php +++ b/packages/vite/src/TagsResolver/ManifestTagsResolver.php @@ -191,48 +191,48 @@ private function resolvePrefetchingScript(Chunk $chunk): ?string $script = match ($this->viteConfig->prefetching->strategy) { PrefetchStrategy::AGGRESSIVE => <<viteConfig->prefetching->prefetchEvent}', () => window.setTimeout(() => { - function makeLink(asset) { - const link = document.createElement('link') - Object.keys(asset).forEach((attribute) => link.setAttribute(attribute, asset[attribute])) - return link - } + window.addEventListener('{$this->viteConfig->prefetching->prefetchEvent}', () => window.setTimeout(() => { + function makeLink(asset) { + const link = document.createElement('link') + Object.keys(asset).forEach((attribute) => link.setAttribute(attribute, asset[attribute])) + return link + } - const fragment = new DocumentFragment(); - {$assets}.forEach((asset) => fragment.append(makeLink(asset))) - document.head.append(fragment) - })) - JS, + const fragment = new DocumentFragment(); + {$assets}.forEach((asset) => fragment.append(makeLink(asset))) + document.head.append(fragment) + })) + JS, PrefetchStrategy::WATERFALL => <<viteConfig->prefetching->prefetchEvent}', () => { - function makeLink(asset) { - const link = document.createElement('link') - Object.entries(asset).forEach(([key, value]) => link.setAttribute(key, value)) - return link - } + window.addEventListener('{$this->viteConfig->prefetching->prefetchEvent}', () => { + function makeLink(asset) { + const link = document.createElement('link') + Object.entries(asset).forEach(([key, value]) => link.setAttribute(key, value)) + return link + } - function loadNext(assets, count) { - if (!assets.length) return + function loadNext(assets, count) { + if (!assets.length) return - const fragment = new DocumentFragment() - const limit = Math.min(count, assets.length) + const fragment = new DocumentFragment() + const limit = Math.min(count, assets.length) - for (let i = 0; i < limit; i++) { - const link = makeLink(assets.shift()) - fragment.append(link) + for (let i = 0; i < limit; i++) { + const link = makeLink(assets.shift()) + fragment.append(link) - if (assets.length) { - link.onload = () => loadNext(assets, 1) - link.onerror = () => loadNext(assets, 1) + if (assets.length) { + link.onload = () => loadNext(assets, 1) + link.onerror = () => loadNext(assets, 1) + } } - } - document.head.append(fragment) - } + document.head.append(fragment) + } - setTimeout(() => loadNext({$assets}, {$this->viteConfig->prefetching->concurrent})) - }) - JS, + setTimeout(() => loadNext({$assets}, {$this->viteConfig->prefetching->concurrent})) + }) + JS, PrefetchStrategy::NONE => '', }; diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index 7c600b78b..ef3d79d1d 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -120,7 +120,8 @@ protected function setUp(): void { parent::setUp(); - $this->setupKernel() + $this + ->setupKernel() ->setupConsole() ->setupTesters() ->setupBaseRequest(); diff --git a/tests/Benchmark/Extension/MarkdownExtension.php b/tests/Benchmark/Extension/MarkdownExtension.php index e0108766e..bcb2472b7 100644 --- a/tests/Benchmark/Extension/MarkdownExtension.php +++ b/tests/Benchmark/Extension/MarkdownExtension.php @@ -13,9 +13,7 @@ final class MarkdownExtension implements ExtensionInterface { - public function configure(OptionsResolver $resolver): void - { - } + public function configure(OptionsResolver $resolver): void {} public function load(Container $container): void { diff --git a/tests/Benchmark/Extension/MarkdownRendererTest.php b/tests/Benchmark/Extension/MarkdownRendererTest.php index 4faae9d60..fc0efaee5 100644 --- a/tests/Benchmark/Extension/MarkdownRendererTest.php +++ b/tests/Benchmark/Extension/MarkdownRendererTest.php @@ -40,14 +40,14 @@ public function it_renders_a_compact_aggregate_report_table(): void $renderer->render($reports, new Config('markdown', ['file' => null])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - | Benchmark | Set | Mem. Peak | Time | Variability | - | --------- | --- | --------- | ---- | ----------- | - | ContainerBench(benchAutowireSimple) | - | 3.952mb 0.00% | 4.187μs +0.17% | ±2.05% +108.06% | + | Benchmark | Set | Mem. Peak | Time | Variability | + | --------- | --- | --------- | ---- | ----------- | + | ContainerBench(benchAutowireSimple) | - | 3.952mb 0.00% | 4.187μs +0.17% | ±2.05% +108.06% | - MARKDOWN, + MARKDOWN, $output->fetch()); } @@ -70,12 +70,12 @@ public function it_keeps_non_aggregate_table_columns_unchanged(): void $renderer->render($reports, new Config('markdown', ['file' => null])); $this->assertSame(<<<'MARKDOWN' - | name | value | - | ---- | ----- | - | Example | 123 | + | name | value | + | ---- | ----- | + | Example | 123 | - MARKDOWN, $output->fetch()); + MARKDOWN, $output->fetch()); } #[Test] @@ -113,14 +113,14 @@ public function it_can_filter_compact_rows_by_minimum_time_difference(): void $renderer->render($reports, new Config('markdown', ['file' => null, 'outlier_min_diff' => 1.0])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - | Benchmark | Set | Mem. Peak | Time | Variability | - | --------- | --- | --------- | ---- | ----------- | - | ContainerBench(benchAutowireNested) | - | 3.952mb +0.10% | 14.791μs +1.55% | ±0.69% +0.50% | + | Benchmark | Set | Mem. Peak | Time | Variability | + | --------- | --- | --------- | ---- | ----------- | + | ContainerBench(benchAutowireNested) | - | 3.952mb +0.10% | 14.791μs +1.55% | ±0.69% +0.50% | - MARKDOWN, + MARKDOWN, $output->fetch()); } @@ -160,12 +160,12 @@ public function it_shows_an_informative_message_when_no_outliers_match(): void $renderer->render($reports, new Config('markdown', ['file' => null, 'outlier_min_diff' => 5.0])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - _No benchmark changes above ±5%._ + _No benchmark changes above ±5%._ - MARKDOWN, + MARKDOWN, $output->fetch()); } diff --git a/tests/Fixtures/Commands/HelloWorldTestCommand.php b/tests/Fixtures/Commands/HelloWorldTestCommand.php index 313d75eb9..88a406a09 100644 --- a/tests/Fixtures/Commands/HelloWorldTestCommand.php +++ b/tests/Fixtures/Commands/HelloWorldTestCommand.php @@ -9,7 +9,5 @@ final readonly class HelloWorldTestCommand { #[ConsoleCommand] - public function __invoke(): void - { - } + public function __invoke(): void {} } diff --git a/tests/Fixtures/Commands/MyBrokenCommand.php b/tests/Fixtures/Commands/MyBrokenCommand.php index 29aad2368..3bf5bb19e 100644 --- a/tests/Fixtures/Commands/MyBrokenCommand.php +++ b/tests/Fixtures/Commands/MyBrokenCommand.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Commands; -final class MyBrokenCommand -{ -} +final class MyBrokenCommand {} diff --git a/tests/Fixtures/Commands/MyCommand.php b/tests/Fixtures/Commands/MyCommand.php index 24ea8316d..6bc340bee 100644 --- a/tests/Fixtures/Commands/MyCommand.php +++ b/tests/Fixtures/Commands/MyCommand.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Commands; -final class MyCommand -{ -} +final class MyCommand {} diff --git a/tests/Fixtures/Console/CommandWithDifferentArguments.php b/tests/Fixtures/Console/CommandWithDifferentArguments.php index 3bcf7c6cb..3a488f0e0 100644 --- a/tests/Fixtures/Console/CommandWithDifferentArguments.php +++ b/tests/Fixtures/Console/CommandWithDifferentArguments.php @@ -21,6 +21,5 @@ public function __invoke( string $camelCaseStringWithDefault = 'foo', bool $camelCaseBoolWithTrueDefault = true, bool $camelCaseBoolWithFalseDefault = false, - ): void { - } + ): void {} } diff --git a/tests/Fixtures/Console/StylingCommand.php b/tests/Fixtures/Console/StylingCommand.php index 3d5f252cf..475490226 100644 --- a/tests/Fixtures/Console/StylingCommand.php +++ b/tests/Fixtures/Console/StylingCommand.php @@ -14,7 +14,8 @@ #[ConsoleCommand(name: 'test:style')] public function __invoke(): void { - $this->info('info') + $this + ->info('info') ->success('success') ->warning('warning') ->error('error'); diff --git a/tests/Fixtures/Controllers/DocsController.php b/tests/Fixtures/Controllers/DocsController.php index 56d4ccda0..d8367974b 100644 --- a/tests/Fixtures/Controllers/DocsController.php +++ b/tests/Fixtures/Controllers/DocsController.php @@ -9,7 +9,5 @@ final readonly class DocsController { #[Get('/docs/{category}/{slug}')] - public function __invoke(string $category, string $slug): void - { - } + public function __invoke(string $category, string $slug): void {} } diff --git a/tests/Fixtures/Events/EventForListenerWithoutPropagation.php b/tests/Fixtures/Events/EventForListenerWithoutPropagation.php index 3dc5f4037..ccf11b102 100644 --- a/tests/Fixtures/Events/EventForListenerWithoutPropagation.php +++ b/tests/Fixtures/Events/EventForListenerWithoutPropagation.php @@ -2,6 +2,4 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class EventForListenerWithoutPropagation -{ -} +final readonly class EventForListenerWithoutPropagation {} diff --git a/tests/Fixtures/Events/EventInterface.php b/tests/Fixtures/Events/EventInterface.php index 55882c827..8af3a0201 100644 --- a/tests/Fixtures/Events/EventInterface.php +++ b/tests/Fixtures/Events/EventInterface.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Events; -interface EventInterface -{ -} +interface EventInterface {} diff --git a/tests/Fixtures/Events/EventInterfaceImplementation.php b/tests/Fixtures/Events/EventInterfaceImplementation.php index 3f6002b47..d0d06f3a0 100644 --- a/tests/Fixtures/Events/EventInterfaceImplementation.php +++ b/tests/Fixtures/Events/EventInterfaceImplementation.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class EventInterfaceImplementation implements EventInterface -{ -} +final readonly class EventInterfaceImplementation implements EventInterface {} diff --git a/tests/Fixtures/Events/EventWithoutPropagation.php b/tests/Fixtures/Events/EventWithoutPropagation.php index c18a33a2b..63674a320 100644 --- a/tests/Fixtures/Events/EventWithoutPropagation.php +++ b/tests/Fixtures/Events/EventWithoutPropagation.php @@ -5,6 +5,4 @@ use Tempest\EventBus\StopsPropagation; #[StopsPropagation] -final readonly class EventWithoutPropagation -{ -} +final readonly class EventWithoutPropagation {} diff --git a/tests/Fixtures/Events/ItHappened.php b/tests/Fixtures/Events/ItHappened.php index 09dac2f71..5b7a4df83 100644 --- a/tests/Fixtures/Events/ItHappened.php +++ b/tests/Fixtures/Events/ItHappened.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class ItHappened -{ -} +final readonly class ItHappened {} diff --git a/tests/Fixtures/GlobalHiddenDiscovery.php b/tests/Fixtures/GlobalHiddenDiscovery.php index dc75910e7..a784f8c7e 100644 --- a/tests/Fixtures/GlobalHiddenDiscovery.php +++ b/tests/Fixtures/GlobalHiddenDiscovery.php @@ -13,9 +13,7 @@ final class GlobalHiddenDiscovery implements Discovery use IsDiscovery; - public function discover(DiscoveryLocation $location, ClassReflector $class): void - { - } + public function discover(DiscoveryLocation $location, ClassReflector $class): void {} public function apply(): void { diff --git a/tests/Fixtures/GlobalHiddenPathDiscovery.php b/tests/Fixtures/GlobalHiddenPathDiscovery.php index 737b4694c..7c12bcf71 100644 --- a/tests/Fixtures/GlobalHiddenPathDiscovery.php +++ b/tests/Fixtures/GlobalHiddenPathDiscovery.php @@ -13,9 +13,7 @@ final class GlobalHiddenPathDiscovery implements Discovery use IsDiscovery; - public function discover(DiscoveryLocation $location, ClassReflector $class): void - { - } + public function discover(DiscoveryLocation $location, ClassReflector $class): void {} public function apply(): void { diff --git a/tests/Fixtures/Handlers/MyCommandHandler.php b/tests/Fixtures/Handlers/MyCommandHandler.php index 4b6a9d1e3..be53f3b94 100644 --- a/tests/Fixtures/Handlers/MyCommandHandler.php +++ b/tests/Fixtures/Handlers/MyCommandHandler.php @@ -10,7 +10,5 @@ final class MyCommandHandler { #[CommandHandler] - public function __invoke(MyCommand $command): void - { - } + public function __invoke(MyCommand $command): void {} } diff --git a/tests/Fixtures/TestInstallerClass.php b/tests/Fixtures/TestInstallerClass.php index 25e10c22c..e3a6abdbc 100644 --- a/tests/Fixtures/TestInstallerClass.php +++ b/tests/Fixtures/TestInstallerClass.php @@ -7,6 +7,4 @@ use Tempest\Discovery\SkipDiscovery; #[SkipDiscovery] -final readonly class TestInstallerClass -{ -} +final readonly class TestInstallerClass {} diff --git a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php index e4cb3ac20..c5d6358b6 100644 --- a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php @@ -25,11 +25,11 @@ public function test_progress_bar(): void }) ->assertContains( << ] (1/3) - [====================> ] (2/3) - [===============================] (3/3) - ["aa","bb","cc"] - TXT, + [==========> ] (1/3) + [====================> ] (2/3) + [===============================] (3/3) + ["aa","bb","cc"] + TXT, true, ); } diff --git a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php index 447de2dce..c1608c974 100644 --- a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php @@ -26,22 +26,22 @@ public function test_search_component(): void ->submit('a') ->assertContains( <<submit(1) ->submit('b') ->assertContains( <<submit(2) @@ -62,9 +62,9 @@ public function test_no_answer(): void ->submit() ->assertContains( text: <<submit(0) @@ -86,9 +86,9 @@ public function test_default_answer(): void ->submit() ->assertContains( text: <<submit(0) diff --git a/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php b/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php index 48118f0f0..ec9b88813 100644 --- a/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php +++ b/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php @@ -8,16 +8,10 @@ final class CommandWithNonCommandMethods { - public function __invoke(): void - { - } + public function __invoke(): void {} #[ConsoleCommand('test:not-empty')] - public function do(): void - { - } + public function do(): void {} - public function empty(): void - { - } + public function empty(): void {} } diff --git a/tests/Integration/Console/Fixtures/CompletionTestCommand.php b/tests/Integration/Console/Fixtures/CompletionTestCommand.php index a41a36690..9cc3c6c42 100644 --- a/tests/Integration/Console/Fixtures/CompletionTestCommand.php +++ b/tests/Integration/Console/Fixtures/CompletionTestCommand.php @@ -13,6 +13,5 @@ public function __invoke( string $value, bool $flag = false, array $items = [], - ): void { - } + ): void {} } diff --git a/tests/Integration/Console/Fixtures/MyConsole.php b/tests/Integration/Console/Fixtures/MyConsole.php index d45b635e8..453fd2454 100644 --- a/tests/Integration/Console/Fixtures/MyConsole.php +++ b/tests/Integration/Console/Fixtures/MyConsole.php @@ -17,6 +17,5 @@ public function handle( int $times = 1, bool $force = false, ?string $optional = null, - ): void { - } + ): void {} } diff --git a/tests/Integration/Console/Fixtures/Package.php b/tests/Integration/Console/Fixtures/Package.php index 56dd3b7b5..44239f29e 100644 --- a/tests/Integration/Console/Fixtures/Package.php +++ b/tests/Integration/Console/Fixtures/Package.php @@ -10,9 +10,7 @@ final readonly class Package { #[ConsoleCommand] - public function list(): void - { - } + public function list(): void {} #[ConsoleCommand(help: 'help text')] public function info( @@ -23,6 +21,5 @@ public function info( aliases: ['n'], )] string $name, - ): void { - } + ): void {} } diff --git a/tests/Integration/Console/Fixtures/TestConsoleException.php b/tests/Integration/Console/Fixtures/TestConsoleException.php index 5ba91f6e1..e8f42d415 100644 --- a/tests/Integration/Console/Fixtures/TestConsoleException.php +++ b/tests/Integration/Console/Fixtures/TestConsoleException.php @@ -9,7 +9,5 @@ final class TestConsoleException extends ConsoleException { - public function render(Console $console): void - { - } + public function render(Console $console): void {} } diff --git a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php index 341f23e52..552c26c26 100644 --- a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php +++ b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php @@ -117,12 +117,8 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v } // dummy handler for testing - public function handler(): void - { - } + public function handler(): void {} // dummy command for testing - public function command(): void - { - } + public function command(): void {} } diff --git a/tests/Integration/Console/Scheduler/HandlerInvocationTest.php b/tests/Integration/Console/Scheduler/HandlerInvocationTest.php index 30e697d49..54c058a4f 100644 --- a/tests/Integration/Console/Scheduler/HandlerInvocationTest.php +++ b/tests/Integration/Console/Scheduler/HandlerInvocationTest.php @@ -30,7 +30,5 @@ public function test_name_gets_constructed_properly(): void } // dummy handler method - public function handler(): void - { - } + public function handler(): void {} } diff --git a/tests/Integration/Core/Config/LoadConfigTest.php b/tests/Integration/Core/Config/LoadConfigTest.php index 365fff006..d3b51d6b3 100644 --- a/tests/Integration/Core/Config/LoadConfigTest.php +++ b/tests/Integration/Core/Config/LoadConfigTest.php @@ -117,14 +117,14 @@ private function setupFixtures(array $configs): void $db = str_replace('.php', '.sqlite', $config); Filesystem\write_file(__DIR__ . '/Fixtures/' . $config, << <<<'SQL' - INSERT INTO authors (name) VALUES (?) RETURNING * - SQL, + INSERT INTO authors (name) VALUES (?) RETURNING * + SQL, default => <<<'SQL' - INSERT INTO `authors` (`name`) VALUES (?) - SQL, + INSERT INTO `authors` (`name`) VALUES (?) + SQL, }; $this->assertSame($expected, $query->compile()->toString()); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index c4d257591..1c3c26212 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -316,9 +316,11 @@ public function test_chunk(): void $this->assertCount(4, $results); $results = []; - Book::select()->whereRaw("title <> 'A'")->chunk(function (array $chunk) use (&$results): void { - $results = [...$results, ...$chunk]; - }, 2); + Book::select() + ->whereRaw("title <> 'A'") + ->chunk(function (array $chunk) use (&$results): void { + $results = [...$results, ...$chunk]; + }, 2); $this->assertCount(3, $results); } @@ -337,9 +339,11 @@ public function test_chunk_with_relation(): void Book::new(title: 'B', author: $author)->save(); $results = []; - Book::select()->with('author')->chunk(function (array $chunk) use (&$results): void { - $results = [...$results, ...$chunk]; - }, 1); + Book::select() + ->with('author') + ->chunk(function (array $chunk) use (&$results): void { + $results = [...$results, ...$chunk]; + }, 1); $this->assertCount(2, $results); } diff --git a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php index 0fd8271db..a81f9a998 100644 --- a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php @@ -310,11 +310,11 @@ public function test_update_mapping(): void $expected = match ($dialect) { DatabaseDialect::POSTGRESQL => <<<'SQL' - UPDATE authors SET name = ? WHERE authors.id = ? - SQL, + UPDATE authors SET name = ? WHERE authors.id = ? + SQL, default => <<<'SQL' - UPDATE `authors` SET `name` = ? WHERE `authors`.`id` = ? - SQL, + UPDATE `authors` SET `name` = ? WHERE `authors`.`id` = ? + SQL, }; $this->assertSame($expected, $query->compile()->toString()); diff --git a/tests/Integration/Database/GenericDatabaseTest.php b/tests/Integration/Database/GenericDatabaseTest.php index a8a257101..8ca68639f 100644 --- a/tests/Integration/Database/GenericDatabaseTest.php +++ b/tests/Integration/Database/GenericDatabaseTest.php @@ -65,9 +65,9 @@ public function test_query_with_semicolons(): void $db = $this->container->get(Database::class); $db->execute( new Query(<<assertSame(1, query(Publisher::class)->count()->execute()); diff --git a/tests/Integration/Database/QueryStatements/CompoundStatementTest.php b/tests/Integration/Database/QueryStatements/CompoundStatementTest.php index ad98a5e17..6090a01d4 100644 --- a/tests/Integration/Database/QueryStatements/CompoundStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CompoundStatementTest.php @@ -18,9 +18,9 @@ public function test_it_can_compile_create_enum_type_statement(): void $this->assertSame( <<compile(DatabaseDialect::SQLITE), ); } diff --git a/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php b/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php index 3fa2f5928..f8dddf12f 100644 --- a/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php @@ -16,8 +16,8 @@ enumClass: CreateEnumTypeStatementTestEnumForCreateTable::class, $this->assertSame( <<compile(DatabaseDialect::POSTGRESQL), ); } diff --git a/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php b/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php index 83a0fccd0..191efae8a 100644 --- a/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php +++ b/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php @@ -16,8 +16,8 @@ enumClass: DropEnumTypeStatementTestEnumForCreateTable::class, $this->assertSame( <<compile(DatabaseDialect::POSTGRESQL), ); } diff --git a/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php b/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php index 7be91e7e8..ad74ad792 100644 --- a/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php +++ b/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php @@ -29,33 +29,33 @@ public function test_show_meta_for_view_component(): void ->assertSee('x-view-component-with-named-slots.view.php') ->assertSee('"name": "x-view-component-with-named-slots",') ->assertSee(<<<'JSON' - "variables": [ - { - "type": "string", - "name": "$title", - "attributeName": "title", - "description": null - }, - { - "type": "\\Tests\\Tempest\\Fixtures\\Modules\\Books\\Models\\Book", - "name": "$book", - "attributeName": "book", - "description": "Any kind of book will work" - }, - { - "type": "string", - "name": "$dataFoo", - "attributeName": "data-foo", - "description": null - } - ] - JSON) + "variables": [ + { + "type": "string", + "name": "$title", + "attributeName": "title", + "description": null + }, + { + "type": "\\Tests\\Tempest\\Fixtures\\Modules\\Books\\Models\\Book", + "name": "$book", + "attributeName": "book", + "description": "Any kind of book will work" + }, + { + "type": "string", + "name": "$dataFoo", + "attributeName": "data-foo", + "description": null + } + ] + JSON) ->assertSee(<<<'JSON' - "slots": [ - "default", - "foo", - "bar" - ], - JSON); + "slots": [ + "default", + "foo", + "bar" + ], + JSON); } } diff --git a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php index 653695a58..2b7cde3b9 100644 --- a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php +++ b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php @@ -201,9 +201,7 @@ private function callExceptionHandler(Closure $callback): void } } -final class CustomValidationException extends Exception -{ -} +final class CustomValidationException extends Exception {} #[Priority(Priority::HIGH)] final readonly class CustomJsonValidationRenderer implements ExceptionRenderer diff --git a/tests/Integration/Mailer/SentEmailTest.php b/tests/Integration/Mailer/SentEmailTest.php index 79e4b0168..39d396cb9 100644 --- a/tests/Integration/Mailer/SentEmailTest.php +++ b/tests/Integration/Mailer/SentEmailTest.php @@ -68,10 +68,11 @@ public function test_with_default_sender(): void public function test_send_to_address_vo(): void { - $this->sendTestEmail( - to: [new EmailAddress('recipient1@example.com', 'Jon Doe'), 'recipient2@example.com'], - from: 'no-reply@tempestphp.com', - ) + $this + ->sendTestEmail( + to: [new EmailAddress('recipient1@example.com', 'Jon Doe'), 'recipient2@example.com'], + from: 'no-reply@tempestphp.com', + ) ->assertSentTo('recipient1@example.com') ->assertSentTo('recipient2@example.com'); } @@ -89,10 +90,11 @@ public function test_send_to_address_with_brackets(): void public function test_assert_sent_to(): void { - $this->sendTestEmail( - to: ['recipient1@example.com', 'recipient2@example.com'], - from: 'no-reply@tempestphp.com', - ) + $this + ->sendTestEmail( + to: ['recipient1@example.com', 'recipient2@example.com'], + from: 'no-reply@tempestphp.com', + ) ->assertSentTo('recipient1@example.com') ->assertSentTo('recipient2@example.com') ->assertSentTo(['recipient1@example.com', 'recipient2@example.com']) @@ -205,12 +207,12 @@ private function sendTestEmail( $content = match (true) { $html instanceof View => $html, $html !== null => << - -

{$html}

- - - HTML_WRAP, + + +

{$html}

+ + + HTML_WRAP, $text !== null => $text, default => 'Hello Jon in Text', }; diff --git a/tests/Integration/View/BladeViewRendererTest.php b/tests/Integration/View/BladeViewRendererTest.php index 3aec90c9c..9492407f9 100644 --- a/tests/Integration/View/BladeViewRendererTest.php +++ b/tests/Integration/View/BladeViewRendererTest.php @@ -33,10 +33,10 @@ public function test_blade(): void $html = $renderer->render(view('index')); $this->assertSame(<< - Hi - + + Hi + - HTML, $html); + HTML, $html); } } diff --git a/tests/Integration/View/Components/MarkdownComponentTest.php b/tests/Integration/View/Components/MarkdownComponentTest.php index 77faeaaf1..4bf287c90 100644 --- a/tests/Integration/View/Components/MarkdownComponentTest.php +++ b/tests/Integration/View/Components/MarkdownComponentTest.php @@ -9,8 +9,8 @@ final class MarkdownComponentTest extends FrameworkIntegrationTestCase public function test_render_markdown_as_content(): void { $html = $this->view->render(<<<'HTML' - # hi - HTML); + # hi + HTML); $this->assertSame('

hi

', $html); } @@ -18,8 +18,8 @@ public function test_render_markdown_as_content(): void public function test_render_markdown_as_variable(): void { $html = $this->view->render(<<<'HTML' - - HTML, text: '# hi'); + + HTML, text: '# hi'); $this->assertSame('

hi

', $html); } diff --git a/tests/Integration/View/ElementFactoryTest.php b/tests/Integration/View/ElementFactoryTest.php index c9f1aa76a..603fa9072 100644 --- a/tests/Integration/View/ElementFactoryTest.php +++ b/tests/Integration/View/ElementFactoryTest.php @@ -24,16 +24,16 @@ public function test_parental_relations(): void { // See https://github.com/php/php-src/issues/16960 $contents = <<<'HTML' - - - - Hello - - - - - - HTML; + + + + Hello + + + + + + HTML; $ast = TempestViewParser::ast($contents); diff --git a/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php b/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php index 57389816a..636856210 100644 --- a/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php +++ b/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php @@ -24,44 +24,44 @@ protected function setUp(): void public function test_if_with_data_expression(): void { $view = <<<'HTML' - - {{ $label }} - - - {{ $label }} - -
Nothing
- HTML; + + {{ $label }} + + + {{ $label }} + +
Nothing
+ HTML; $html = $this->view->render(view($view, href: '#', label: 'Label')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - - Label - HTML, $html); + + Label + HTML, $html); $html = $this->view->render(view($view, label: 'Label')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - - Label - HTML, $html); + + Label + HTML, $html); $html = $this->view->render(view($view)); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
Nothing
- HTML, $html); +
Nothing
+ HTML, $html); } public function test_foreach_with_if_and_else_expression(): void { $view = <<<'HTML' -
- {{ $label }} {{ $item }} -
- - No label - - HTML; +
+ {{ $label }} {{ $item }} +
+ + No label + + HTML; $html = $this->view->render(view($view, items: ['a', 'b'], label: 'Label')); $this->assertStringContainsString('Label a', $html); @@ -76,16 +76,16 @@ public function test_foreach_with_if_and_else_expression(): void public function test_foreach_with_if_and_forelse_expression(): void { $view = <<<'HTML' -
- {{ $label }} {{ $item }} -
- - No items - - - No label - - HTML; +
+ {{ $label }} {{ $item }} +
+ + No items + + + No label + + HTML; $html = $this->view->render(view($view)); $this->assertStringNotContainsString('Label a', $html); diff --git a/tests/Integration/View/TempestViewRendererDataPassingTest.php b/tests/Integration/View/TempestViewRendererDataPassingTest.php index 1bd3d479b..f9df80e92 100644 --- a/tests/Integration/View/TempestViewRendererDataPassingTest.php +++ b/tests/Integration/View/TempestViewRendererDataPassingTest.php @@ -63,8 +63,8 @@ public function test_normal_attribute_with_php_short_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://', ), ); @@ -77,8 +77,8 @@ public function test_normal_attribute_with_view_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://&', ), ); @@ -91,8 +91,8 @@ public function test_normal_attribute_with_raw_view_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://&', ), ); @@ -105,8 +105,8 @@ public function test_expression_attribute_with_view_echo_not_allowed(): void $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -117,8 +117,8 @@ public function test_expression_attribute_with_raw_view_echo_not_allowed(): void $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -129,8 +129,8 @@ public function test_expression_attribute_with_short_php_echo_not_allowed(): voi $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -141,8 +141,8 @@ public function test_expression_attribute_with_object_without_view_component_not $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() {}, ); } @@ -154,16 +154,16 @@ public function test_expression_attribute_with_object_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() { public string $url = 'https://'; }, @@ -178,16 +178,16 @@ public function test_expression_attribute_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://', ), ); @@ -200,16 +200,16 @@ public function test_normal_attribute_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ), ); } @@ -221,8 +221,8 @@ public function test_expression_attribute_with_same_name(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); /* There's a name collision here: @@ -237,8 +237,8 @@ public function test_expression_attribute_with_same_name(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() { public string $url = 'https://'; }, @@ -251,15 +251,15 @@ public function test_boolean_attributes(): void $this->assertSame( '', $this->view->render(<<<'HTML' - - HTML, value: 'value', selected: true, name: 'name'), + + HTML, value: 'value', selected: true, name: 'name'), ); $this->assertSame( '', $this->view->render(<<<'HTML' - - HTML, value: 'value', selected: false, name: 'name'), + + HTML, value: 'value', selected: false, name: 'name'), ); $this->assertSame( @@ -275,12 +275,12 @@ public function test_boolean_attributes(): void public function test_falsy_bool_attribute(mixed $value): void { $html = $this->view->render(<< - HTML, show: false); +
+ HTML, show: false); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } #[TestWith(['true'])] @@ -288,23 +288,23 @@ public function test_falsy_bool_attribute(mixed $value): void public function test_truthy_bool_attribute(mixed $value): void { $html = $this->view->render(<< - HTML, show: true); +
+ HTML, show: true); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_multiple_boolean_attribute(): void { $html = $this->view->render(<< - HTML); +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_expression_attribute_in_raw_element(): void @@ -312,20 +312,20 @@ public function test_expression_attribute_in_raw_element(): void $this->view->registerViewComponent( 'x-test', <<<'HTML' -
- HTML, +
+ HTML, ); $html = $this->view->render(<<<'HTML' - -
foo

bar

-
- HTML, language: 'php'); + +
foo

bar

+
+ HTML, language: 'php'); $this->assertSnippetsMatch( <<<'HTML' -
foo

bar

- HTML, +
foo

bar

+ HTML, $html, ); } @@ -335,31 +335,31 @@ public function test_echo_in_attributes(): void $this->assertSame( '
', $this->view->render(<< - HTML), +
+ HTML), ); $this->assertSame( '
', $this->view->render(<< - HTML), +
+ HTML), ); } public function test_boolean_attributes_in_view_component(): void { $this->view->registerViewComponent('x-test', << - -
- HTML); +
+ +
+ HTML); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertStringContainsString(' href="hi"', $html); } @@ -367,19 +367,19 @@ public function test_boolean_attributes_in_view_component(): void public function test_global_variables_are_kept(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
{{ $item }}
- HTML); +
{{ $item }}
+ HTML); $html = $this->view->render(<<<'HTML' - - - - HTML, item: 'foo'); + + + + HTML, item: 'foo'); $this->assertSnippetsMatch(<<<'HTML' -
foo
-
foo
-
foo
- HTML, $html); +
foo
+
foo
+
foo
+ HTML, $html); } } diff --git a/tests/Integration/View/TempestViewRendererTest.php b/tests/Integration/View/TempestViewRendererTest.php index cbd9aaf58..cd516aa04 100644 --- a/tests/Integration/View/TempestViewRendererTest.php +++ b/tests/Integration/View/TempestViewRendererTest.php @@ -270,9 +270,9 @@ public function test_foreach_attribute(): void { $this->assertStringEqualsStringIgnoringLineEndings( <<<'HTML' -
a
-
b
- HTML, +
a
+
b
+ HTML, $this->view->render(view('
{{ $foo }}
')->data(items: ['a', 'b'])), ); } @@ -281,39 +281,39 @@ public function test_foreach_consumes_attribute(): void { $html = $this->view->render( <<<'HTML' - - - - - -
{{ $item }}
-
- HTML, + + + + + +
{{ $item }}
+
+ HTML, items: ['a', 'b'], ); $this->assertSnippetsMatch( <<<'HTML' - - - Home - - - - - - - - - - - -
a
b
- - - - - HTML, + + + Home + + + + + + + + + + + +
a
b
+ + + + + HTML, $html, ); } @@ -322,15 +322,15 @@ public function test_forelse_attribute(): void { $this->assertSame( <<<'HTML' -
Empty
- HTML, +
Empty
+ HTML, $this->view->render(view('
{{ $foo }}
Empty
')->data(items: [])), ); $this->assertSame( <<<'HTML' -
a
- HTML, +
a
+ HTML, $this->view->render(view('
{{ $foo }}
Empty
')->data(items: ['a'])), ); } @@ -339,8 +339,8 @@ public function test_forelse_with_other_expression_attribute(): void { $this->assertSame( <<<'HTML' -
Empty
- HTML, +
Empty
+ HTML, $this->view->render('
{{ $foo }}
Empty
', items: [], data: 'test'), ); } @@ -349,14 +349,14 @@ public function test_default_slot(): void { $this->assertSnippetsMatch( <<<'HTML' -
Test
- HTML, +
Test
+ HTML, $this->view->render( <<<'HTML' - - Test - - HTML, + + Test + + HTML, ), ); } @@ -365,18 +365,18 @@ public function test_implicit_default_slot(): void { $this->assertSnippetsMatch( <<<'HTML' -
- - Test +
+ + Test -
- HTML, +
+ HTML, $this->view->render( <<<'HTML' - - Test - - HTML, + + Test + + HTML, ), ); } @@ -385,41 +385,41 @@ public function test_multiple_slots(): void { $this->assertSnippetsMatch( <<<'HTML' - injected scripts - + injected scripts + -
- - Test - - +
+ + Test + + - - Hi + + Hi -
+
- injected styles - HTML, - $this->view->render( - <<<'HTML' - - Test - - - injected scripts - - - injected styles - - - Hi - HTML, + $this->view->render( + <<<'HTML' + + Test + + + injected scripts + + + + injected styles + + + Hi + + HTML, ), ); } @@ -428,18 +428,18 @@ public function test_pre(): void { $this->assertStringEqualsStringIgnoringLineEndings( <<<'HTML' -
a
-                    b
-                c
-            
- HTML, - $this->view->render( - <<<'HTML'
a
                         b
                     c
                 
HTML, + $this->view->render( + <<<'HTML' +
a
+                            b
+                        c
+                    
+ HTML, ), ); } @@ -456,10 +456,10 @@ public function test_raw_and_escaped(): void $html = $this->view->render(view(__DIR__ . '/../../Fixtures/Views/raw-escaped.view.php', var: '

hi

')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - <h1>hi</h1> - <H1>HI</H1> -

hi

- HTML, $html); + <h1>hi</h1> + <H1>HI</H1> +

hi

+ HTML, $html); } public function test_html_string(): void @@ -468,10 +468,10 @@ public function test_html_string(): void $this->assertStringEqualsStringIgnoringLineEndings( expected: <<<'HTML' -

hi

- <H1>HI</H1> -

hi

- HTML, +

hi

+ <H1>HI</H1> +

hi

+ HTML, actual: $html, ); } @@ -482,10 +482,10 @@ public function test_no_double_else_attributes(): void $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); } @@ -493,25 +493,25 @@ public function test_else_must_be_after_if_or_elseif(): void { $this->view->render( <<<'HTML' -
-
- HTML, +
+
+ HTML, ); $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -519,18 +519,18 @@ public function test_elseif_must_be_after_if_or_elseif(): void { $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -538,17 +538,17 @@ public function test_forelse_must_be_before_foreach(): void { $this->view->render( view(<<<'HTML' -
-
- HTML, foo: []), +
+
+ HTML, foo: []), ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -556,19 +556,19 @@ public function test_no_double_forelse_attributes(): void { $this->view->render( view(<<<'HTML' -
-
- HTML, foo: []), +
+
+ HTML, foo: []), ); $this->expectException(ElementWasInvalid::class); $this->view->render( view(<<<'HTML' -
-
-
- HTML, foo: []), +
+
+
+ HTML, foo: []), ); } @@ -576,8 +576,8 @@ public function test_render_element_with_attribute_with_dash(): void { $view = view( <<
- HTML, +
+ HTML, ); $html = $this->view->render($view); @@ -612,19 +612,19 @@ public function test_slot_with_comment(): void { $this->assertSnippetsMatch( <<<'HTML' -
+
- Test + Test -
- HTML, +
+ HTML, $this->view->render( <<<'HTML' - - - Test - - HTML, + + + Test + + HTML, ), ); } @@ -652,21 +652,21 @@ public function test_self_closing_component_tags_are_compiled(): void public function test_html_tags(): void { $view = <<<'HTML' - - - - - Tempest - - - - - - -

Tempest

- - - HTML; + + + + + Tempest + + + + + + +

Tempest

+ + + HTML; $html = $this->view->render($view); @@ -693,8 +693,8 @@ public function test_with_at_symbol_in_html_tag(): void $this->assertStringEqualsStringIgnoringLineEndings( <<test - HTML, + + HTML, $rendered, ); } @@ -707,8 +707,8 @@ public function test_with_colon_symbol_in_html_tag(): void $this->assertStringEqualsStringIgnoringLineEndings( <<test - HTML, + + HTML, $rendered, ); } @@ -718,10 +718,10 @@ public function test_loop_variable_can_be_used_within_the_looped_tag(): void $html = $this->view->render( view( <<<'HTML' - - {{ $item->title }} - - HTML, + + {{ $item->title }} + + HTML, ) ->data(items: [ new class { @@ -738,16 +738,16 @@ public function test_loop_variable_can_be_used_within_the_looped_tag(): void ); $this->assertSnippetsMatch(<<<'HTML' - Item 1Item 2 - HTML, $html); + Item 1Item 2 + HTML, $html); } public function test_if_and_foreach_precedence(): void { $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, items: [ (object) ['name' => 'A', 'show' => true], (object) ['name' => 'B', 'show' => false], @@ -759,8 +759,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: true, items: [ (object) ['name' => 'A', 'show' => true], @@ -773,8 +773,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: true, items: [ (object) ['name' => 'A', 'show' => true], @@ -787,8 +787,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: false, items: [ (object) ['name' => 'A', 'show' => true], @@ -801,8 +801,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: false, items: [ (object) ['name' => 'A', 'show' => true], @@ -815,8 +815,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, item: (object) ['show' => true], items: [ (object) ['name' => 'A', 'show' => true], @@ -829,8 +829,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, items: [ (object) ['name' => 'A', 'show' => true], (object) ['name' => 'B', 'show' => false], @@ -851,8 +851,8 @@ public function test_escape_expression_attribute(): void public function test_unclosed_php_tag(): void { $html = $this->view->render(<<<'HTML' - assertSame('hi', $html); } @@ -860,8 +860,8 @@ public function test_unclosed_php_tag(): void public function test_view_comments(): void { $html = $this->view->render(<<<'HTML' -

{{-- this is a comment --}}this is rendered text

{{-- this is a comment --}} - HTML); +

{{-- this is a comment --}}this is rendered text

{{-- this is a comment --}} + HTML); $this->assertSnippetsMatch('

this is rendered text

', $html); } @@ -869,19 +869,19 @@ public function test_view_comments(): void public function test_multiline_view_comments(): void { $html = $this->view->render(<<<'HTML' - {{-- this is a comment -
- - {{ Tempest\Intl\translate('test_2') }} - - -
- --}} -

This should be rendered

- HTML); + {{-- this is a comment +
+ + {{ Tempest\Intl\translate('test_2') }} + + +
+ --}} +

This should be rendered

+ HTML); $this->assertSnippetsMatch('

This should be rendered

', $html); } @@ -893,17 +893,17 @@ public function test_parse_rss_feed(): void } $rss = <<<'XML' - - - https://tempestphp.com/rss - - Tempest - - <![CDATA[ {!! $post['title'] !!} ]]> - - - - XML; + + + https://tempestphp.com/rss + + Tempest + + <![CDATA[ {!! $post['title'] !!} ]]> + + + + XML; $parsed = $this->view->render($rss, posts: [ ['title' => '

A

', 'url' => 'https://tempestphp.com/a'], @@ -911,27 +911,27 @@ public function test_parse_rss_feed(): void ]); $this->assertSnippetsMatch(<<<'RSS' - - - https://tempestphp.com/rss - - Tempest - - <![CDATA[ <h1>A</h1> ]]> - - - <![CDATA[ B ]]> - - - - RSS, $parsed); + + + https://tempestphp.com/rss + + Tempest + + <![CDATA[ <h1>A</h1> ]]> + + + <![CDATA[ B ]]> + + + + RSS, $parsed); } public function test_attributes_with_single_quotes(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch('
', $html); } @@ -939,8 +939,8 @@ public function test_attributes_with_single_quotes(): void public function test_zero_in_attribute(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch('
', $html); } diff --git a/tests/Integration/View/TwigViewRendererTest.php b/tests/Integration/View/TwigViewRendererTest.php index 68fbb9b2f..0a009df02 100644 --- a/tests/Integration/View/TwigViewRendererTest.php +++ b/tests/Integration/View/TwigViewRendererTest.php @@ -33,9 +33,9 @@ public function test_twig(): void $html = $renderer->render(view('index.twig', ...['foo' => 'bar'])); $this->assertStringEqualsStringIgnoringLineEndings(<< - bar - - HTML, $html); + + bar + + HTML, $html); } } diff --git a/tests/Integration/View/ViewComponentDiscoveryTest.php b/tests/Integration/View/ViewComponentDiscoveryTest.php index 5953dff51..117daef48 100644 --- a/tests/Integration/View/ViewComponentDiscoveryTest.php +++ b/tests/Integration/View/ViewComponentDiscoveryTest.php @@ -87,8 +87,8 @@ public function test_auto_registration(): void $discovery->apply(); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('Hello World', $html); } @@ -101,8 +101,8 @@ public function test_auto_registration_with_x_component(): void $discovery->apply(); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('Hello World', $html); } diff --git a/tests/Integration/View/ViewComponentTest.php b/tests/Integration/View/ViewComponentTest.php index 5b1a47103..2ed4064ed 100644 --- a/tests/Integration/View/ViewComponentTest.php +++ b/tests/Integration/View/ViewComponentTest.php @@ -59,8 +59,8 @@ public function test_view_component_with_php_code_in_attribute(): void expected: '
', actual: $this->view->render( <<<'HTML' - - HTML, + + HTML, input: 'hello', ), ); @@ -77,47 +77,47 @@ public function test_view_component_with_php_code_in_slot(): void public function test_view_can_access_dynamic_slots(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
-
{{ $slot->name }}
-
{{ $slot->attributes['language'] }}
-
{{ $slot->language }}
-
{!! $slot->content !!}
-
- HTML); +
+
{{ $slot->name }}
+
{{ $slot->attributes['language'] }}
+
{{ $slot->language }}
+
{!! $slot->content !!}
+
+ HTML); $html = $this->view->render(<<<'HTML_WRAP' - - PHP Body - HTML Body - - HTML_WRAP); + + PHP Body + HTML Body + + HTML_WRAP); $this->assertSnippetsMatch(<<<'HTML_WRAP' -
slot-php
PHP
PHP
PHP Body
-
slot-html
HTML
HTML
HTML Body
- HTML_WRAP, $html); +
slot-php
PHP
PHP
PHP Body
+
slot-html
HTML
HTML
HTML Body
+ HTML_WRAP, $html); } public function test_dynamic_slots_are_cleaned_up(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
-
{{ $slot->name }}
-
- - HTML); +
+
{{ $slot->name }}
+
+ + HTML); $html = $this->view->render(<<<'HTML' - - - -
internal slots still here
-
internal slots are cleared
-
+ + + +
internal slots still here
+
internal slots are cleared
+
-
slots still here
-
slots are cleared
- HTML); +
slots still here
+
slots are cleared
+ HTML); $this->assertStringContainsString('
internal slots still here
', $html); $this->assertStringContainsString('
slots are cleared
', $html); @@ -126,17 +126,17 @@ public function test_dynamic_slots_are_cleaned_up(): void public function test_dynamic_slots_include_the_default_slot(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
{{ $slots['default']->name }}
-
{{ $slots['default']->content }}
- HTML); +
{{ $slots['default']->name }}
+
{{ $slots['default']->content }}
+ HTML); $html = $this->view->render('Hello'); $this->assertSnippetsMatch( <<<'HTML' -
default
-
Hello
- HTML, +
default
+
Hello
+ HTML, $html, ); } @@ -144,29 +144,29 @@ public function test_dynamic_slots_include_the_default_slot(): void public function test_slots_with_nested_view_components(): void { $this->view->registerViewComponent('x-a', <<<'HTML' - -
-
A{{ $slot->name }}
-
- HTML); + +
+
A{{ $slot->name }}
+
+ HTML); $this->view->registerViewComponent('x-b', <<<'HTML' -
-
B{{ $slot->name }}
-
- HTML); +
+
B{{ $slot->name }}
+
+ HTML); $html = $this->view->render(<<<'HTML' - - - - - + + + + + - - - - HTML); + + + + HTML); $this->assertStringContainsString('
B1
', $html); $this->assertStringContainsString('
B2
', $html); @@ -185,9 +185,9 @@ public function test_slots_is_a_reserved_variable(): void public function test_scope_does_not_leak_data(): void { $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertStringContainsString('', $html); $this->assertStringContainsString('view->render(''); $this->assertSnippetsMatch(<<<'HTML' - hi + hi - -
- HTML, $html); + +
+ HTML, $html); } public function test_component_with_anther_component_included_with_slot(): void @@ -213,13 +213,13 @@ public function test_component_with_anther_component_included_with_slot(): void $html = $this->view->render('test'); $this->assertSnippetsMatch(<<<'HTML' - hi + hi - -
- test -
- HTML, $html); + +
+ test +
+ HTML, $html); } public function test_view_component_with_injected_view(): void @@ -238,8 +238,8 @@ public function test_view_component_with_injected_view(): void $html = $this->view->render(view( <<<'HTML' - - HTML, + + HTML, )); $validator = $this->container->get(Validator::class); @@ -265,8 +265,8 @@ public function test_component_with_if(): void public function test_component_with_foreach(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch( expected: '
a
b
', @@ -278,8 +278,8 @@ public function test_anonymous_view_component(): void { $this->assertSame( <<hi - HTML, +
hi
+ HTML, $this->view->render('hi'), ); } @@ -302,8 +302,8 @@ public function test_with_passed_variable(): void $this->assertSnippetsMatch( <<test - HTML, +
test
+ HTML, $rendered, ); } @@ -316,8 +316,8 @@ public function test_with_passed_data(): void $this->assertSnippetsMatch( <<test - HTML, +
test
+ HTML, $rendered, ); } @@ -326,14 +326,14 @@ public function test_with_passed_php_data(): void { $rendered = $this->view->render( view(<< - HTML), + + HTML), ); $this->assertSnippetsMatch( <<TEST - HTML, +
TEST
+ HTML, $rendered, ); } @@ -360,8 +360,8 @@ public function test_with_passed_variable_within_loop(): void { $rendered = $this->view->render( <<<'HTML' - - HTML, + + HTML, variables: ['a', 'b', 'c'], ); @@ -386,8 +386,8 @@ public function test_view_component_attribute_variables_without_this(): void $html = $this->view->render(view(__DIR__ . '/../../Fixtures/Views/view-component-attribute-without-this-b.view.php')); $this->assertSame(<<view->render(view(__DIR__ . '/../../Fixtures/Views/view-component-with-non-self-closing-slot-b.view.php')); $this->assertSnippetsMatch(<<view->registerViewComponent('x-test', <<<'HTML' - {{ $metaType ?? 'nothing' }} - HTML); + {{ $metaType ?? 'nothing' }} + HTML); $this->assertSame('test', $this->view->render('')); $this->assertSame('test', $this->view->render('')); @@ -432,19 +432,19 @@ public function test_template_component(): void { $html = $this->view->render( <<<'HTML' - -
item {{ $item }}
-
boo
-
- HTML, + +
item {{ $item }}
+
boo
+
+ HTML, items: ['a', 'b', 'c'], ); $this->assertSnippetsMatch(<<<'HTML' -
item a
boo
-
item b
boo
-
item c
boo
- HTML, $html); +
item a
boo
+
item b
boo
+
item c
boo
+ HTML, $html); } public static function view_components(): Generator @@ -480,29 +480,29 @@ public static function view_components(): Generator public function test_full_html_document_as_component(): void { $this->view->registerViewComponent('x-layout', <<<'HTML' - - - Tempest View - - - - - - HTML); + + + Tempest View + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - Hello World - - HTML); + + Hello World + + HTML); $this->assertStringContainsString(<<<'HTML' - - - Tempest View - - - HTML, $html); + + + Tempest View + + + HTML, $html); $this->assertStringContainsString('Hello World', $html); $this->assertStringContainsString('', $html); $this->assertStringContainsString('', $html); @@ -513,23 +513,23 @@ public function test_empty_slots_are_commented_out(): void $this->container->singleton(Environment::class, Environment::LOCAL); $this->view->registerViewComponent('x-layout', <<<'HTML' - - - - - - - - HTML); + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_empty_slots_are_removed_in_production(): void @@ -537,131 +537,131 @@ public function test_empty_slots_are_removed_in_production(): void $this->container->singleton(Environment::class, Environment::PRODUCTION); $this->view->registerViewComponent('x-layout', <<<'HTML' - - - - - - - - HTML); + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_custom_components_in_head(): void { $this->view->registerViewComponent('x-custom-link', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - - HTML, $html); + + + HTML, $html); } public function test_head_injection(): void { $this->view->registerViewComponent('x-custom-link', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - - Foo - - - - - b - - HTML); + + + + Foo + + + + + b + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - Foo - b - - HTML, $html); + + Foo + b + + HTML, $html); } public function test_attributes_variable_in_view_component(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_fallthrough_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merged_fallthrough_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_fallthrough_attributes_with_other_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_file_name_component(): void @@ -674,79 +674,79 @@ public function test_file_name_component(): void public function test_array_attribute(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merge_class(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merge_class_from_template_to_component(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_does_not_duplicate_br(): void { $this->view->registerViewComponent('x-html-base', <<<'HTML' - - - - - - - - - HTML); + + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - -
-
-
- HTML); + +
+
+
+ HTML); $this->assertSnippetsMatch(<<<'HTML' - -

- HTML, $html); + +

+ HTML, $html); } public function test_renders_minified_html_with_void_elements(): void { $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_multiple_instances_of_custom_component_using_slots(): void @@ -754,48 +754,48 @@ public function test_multiple_instances_of_custom_component_using_slots(): void $this->view->registerViewComponent('x-foo-bar', 'FOO-BAR'); $this->view->registerViewComponent('x-test', <<<'HTML' -
- - -
- HTML); +
+ + +
+ HTML); $html = $this->view->render(<<<'HTML' - - - - - - HTML); + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
FOO-BAR - FOO-BAR -
- HTML, $html); +
FOO-BAR + FOO-BAR +
+ HTML, $html); } public function test_slots_with_hyphens(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- -
- HTML); +
+ +
+ HTML); $html = $this->view->render(<<<'HTML' - - - Hi - - - HTML); + + + Hi + + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- Hi -
- HTML, $html); +
+ Hi +
+ HTML, $html); } public function test_nested_table_components(): void @@ -807,34 +807,34 @@ public function test_nested_table_components(): void $this->view->registerViewComponent('x-my-table-th', ''); $html = $this->view->render(<<<'HTML' - - - - Header 1 - - - - - Row 1, Cell 1 - - -
- HTML); - - $this->assertSnippetsMatch(<<<'HTML' - - - - - - - - - - + + + Header 1 + + + + + Row 1, Cell 1 + +
Header1
Row 1, Cell 1
- HTML, $html); + HTML); + + $this->assertSnippetsMatch(<<<'HTML' + + + + + + + + + + + +
Header1
Row 1, Cell 1
+ HTML, $html); } public function test_dynamic_view_component_with_string_name(): void @@ -842,8 +842,8 @@ public function test_dynamic_view_component_with_string_name(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('
test
', $html); } @@ -853,8 +853,8 @@ public function test_dynamic_view_component_with_expression_name(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML, name: 'x-test'); + + HTML, name: 'x-test'); $this->assertSame('
test
', $html); } @@ -864,8 +864,8 @@ public function test_dynamic_view_component_with_variable_attribute(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML, name: 'x-test', input: 'test'); + + HTML, name: 'x-test', input: 'test'); $this->assertSame('
test
', $html); } @@ -875,8 +875,8 @@ public function test_dynamic_view_component_with_slot(): void $this->view->registerViewComponent('x-test', '
'); $html = $this->view->render(<<<'HTML' - test - HTML, name: 'x-test'); + test + HTML, name: 'x-test'); $this->assertSnippetsMatch('
test
', $html); } @@ -888,8 +888,8 @@ public function dynamic_view_component_keeps_foreach_scope(): void $html = $this->view->render( <<<'HTML' - {{ $item }} - HTML, + {{ $item }} + HTML, name: 'x-test', items: ['a', 'b'], ); @@ -903,10 +903,10 @@ public function test_nested_slots(): void $this->view->registerViewComponent('x-b', ''); $html = $this->view->render(<<<'HTML' - - hi - - HTML); + + hi + + HTML); $this->assertSnippetsMatch('hi', $html); } @@ -915,18 +915,18 @@ public function test_nested_slots_with_escaping(): void { $this->view->registerViewComponent('x-a', ''); $this->view->registerViewComponent('x-b', <<<'HTML' - - {{ get(Environment::class)->value }} - HTML); + + {{ get(Environment::class)->value }} + HTML); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertSnippetsMatch('testing', $html); } @@ -936,10 +936,10 @@ public function test_repeated_local_var_across_view_components(): void $this->view->registerViewComponent('x-test', '
{{ $thing }}
'); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertSnippetsMatch('
a
@@ -960,17 +960,17 @@ public function test_escape_expression_attribute_in_view_components(): void public function test_default_slot_value(): void { $this->view->registerViewComponent('x-test', <<<'HTML' - Default - Default A - Default B - HTML); + Default + Default A + Default B + HTML); $this->assertSnippetsMatch( <<<'HTML' - Overwritten - Overwritten A - Overwritten B - HTML, + Overwritten + Overwritten A + Overwritten B + HTML, $this->view->render(' Overwritten Overwritten A @@ -980,10 +980,10 @@ public function test_default_slot_value(): void $this->assertSnippetsMatch( <<<'HTML' - Overwritten - Default A - Overwritten B - HTML, + Overwritten + Default A + Overwritten B + HTML, $this->view->render(' Overwritten Overwritten B @@ -991,10 +991,10 @@ public function test_default_slot_value(): void ); $this->assertSnippetsMatch(<<<'HTML' - Default - Default A - Default B - HTML, $this->view->render('')); + Default + Default A + Default B + HTML, $this->view->render('')); } public function test_view_variables_are_passed_into_the_component(): void @@ -1002,10 +1002,10 @@ public function test_view_variables_are_passed_into_the_component(): void $this->view->registerViewComponent('x-a', ''); $html = $this->view->render(<<<'HTML' - - {{ $title }} - - HTML, title: 'test'); + + {{ $title }} + + HTML, title: 'test'); $this->assertSnippetsMatch('test', $html); } @@ -1017,12 +1017,12 @@ public function test_capture_outer_scope_view_component_variables(): void $html = $this->view->render( <<<'HTML' - - - {{ $item }} - - - HTML, + + + {{ $item }} + + + HTML, items: ['a', 'b'], ); @@ -1042,13 +1042,13 @@ public function test_imports_in_slots_from_root_node(): void $this->view->registerViewComponent('x-test', '
'); $html = $this->view->render(<<<'HTML' - + - {{ uri(HomeController::class) }} - HTML); + {{ uri(HomeController::class) }} + HTML); $this->assertSame('
/
', $html); } @@ -1056,25 +1056,25 @@ public function test_imports_in_slots_from_root_node(): void public function test_combined_imports_from_root_node_and_view_component(): void { $this->view->registerViewComponent('x-parent', <<<'HTML' -
- HTML); +
+ HTML); $this->view->registerViewComponent('x-child', <<<'HTML' - -
- HTML); + +
+ HTML); $html = $this->view->render(<<<'HTML' - + - - {{ uri(HomeController::class) }} - - HTML); + + {{ uri(HomeController::class) }} + + HTML); $this->assertSnippetsMatch('
/
', $html); } @@ -1173,22 +1173,22 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { public function test_imports_with_nested_view_components(): void { $this->view->registerViewComponent('x-card', <<<'HTML' -
- HTML); +
+ HTML); $this->view->registerViewComponent('x-footer', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - {{ uri(HomeController::class) }} - - HTML); + + + {{ uri(HomeController::class) }} + + HTML); $this->assertSnippetsMatch('
/
', $html); } @@ -1199,18 +1199,18 @@ public function test_imports_in_nested_html_elements(): void $this->view->registerViewComponent('x-b', '
">'); $html = $this->view->render(<<<'HTML' - - -
- - {{ uri(HomeController::class) }} - -
-
- HTML); + + +
+ + {{ uri(HomeController::class) }} + +
+
+ HTML); $this->assertSnippetsMatch('
/
">
">', $html); } diff --git a/tests/Integration/View/ViewTest.php b/tests/Integration/View/ViewTest.php index 90a8c587d..317043aa1 100644 --- a/tests/Integration/View/ViewTest.php +++ b/tests/Integration/View/ViewTest.php @@ -41,8 +41,8 @@ public function test_render_with_view_model(): void $html = $this->view->render($view); $expected = <<assertEquals($expected, $html); } diff --git a/tests/Integration/Vite/ManifestTagsResolverTest.php b/tests/Integration/Vite/ManifestTagsResolverTest.php index e335ea58a..ceb9e025b 100644 --- a/tests/Integration/Vite/ManifestTagsResolverTest.php +++ b/tests/Integration/Vite/ManifestTagsResolverTest.php @@ -81,8 +81,8 @@ public function test_resolve_script_with_prefetching(PrefetchStrategy $strategy) $this->assertStringContainsString('nonce="123', $tags[3]); $this->assertStringContainsString( needle: <<view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -63,19 +63,19 @@ public function test_dev_entrypoints(): void )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -96,19 +96,19 @@ public function test_dev_entrypoints_from_config(): void )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -129,26 +129,26 @@ public function test_dev_entrypoints_from_config_and_react_refresh_from_bridgefi )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: << - Foo - - HTML, + + Foo + + HTML, actual: $html, ); }, @@ -173,17 +173,17 @@ public function test_production_entrypoint_from_config(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), @@ -201,17 +201,17 @@ public function test_production_entrypoint(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), @@ -229,17 +229,17 @@ public function test_production_entrypoints(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), From 4792f58487bdc90708f9575678dc636d3ecb5ea7 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:12:08 +0100 Subject: [PATCH 03/14] Run mago --- .../PolicyBasedAccessControl.php | 6 +- .../src/AccessControl/PolicyDiscovery.php | 1 - .../auth/src/Installer/OAuthInstaller.php | 8 +- .../Installer/oauth/OAuthControllerStub.php | 2 +- .../src/OAuth/Config/DiscordOAuthConfig.php | 1 + .../src/OAuth/Config/FacebookOAuthConfig.php | 1 + .../src/OAuth/Config/GenericOAuthConfig.php | 2 + .../src/OAuth/Config/GitHubOAuthConfig.php | 1 + .../src/OAuth/Config/GoogleOAuthConfig.php | 1 + .../src/OAuth/Config/InstagramOAuthConfig.php | 1 + .../src/OAuth/Config/LinkedInOAuthConfig.php | 1 + .../src/OAuth/Config/MicrosoftOAuthConfig.php | 1 + .../src/OAuth/Config/SlackOAuthConfig.php | 1 + .../src/OAuth/Config/TwitchOAuthConfig.php | 1 + .../auth/src/OAuth/GenericOAuthClient.php | 2 +- packages/auth/src/OAuth/OAuthClient.php | 2 +- packages/auth/src/OAuth/OAuthProvider.php | 2 +- .../src/OAuth/Testing/TestingOAuthClient.php | 6 +- packages/auth/tests/OAuthTest.php | 2 +- .../cache/src/Commands/CacheClearCommand.php | 4 +- packages/cache/src/GenericCache.php | 2 +- .../FileCommandRepository.php | 2 +- .../command-bus/src/MonitorAsyncCommands.php | 48 ++++++----- packages/command-bus/src/functions.php | 1 - .../src/Actions/RenderConsoleCommand.php | 2 +- .../src/Actions/ResolveConsoleCommand.php | 2 +- .../console/src/Commands/AboutCommand.php | 4 +- .../src/Commands/MakeCommandCommand.php | 2 +- .../Commands/MakeGeneratorCommandCommand.php | 2 +- .../src/Commands/MakeMiddlewareCommand.php | 2 +- .../src/Completion/CompletionEngine.php | 6 +- .../Components/Concerns/RendersControls.php | 2 +- .../Interactive/ProgressBarComponent.php | 2 +- .../Components/Interactive/TaskComponent.php | 10 ++- .../InteractiveComponentRenderer.php | 6 +- .../src/Components/OptionCollection.php | 12 +-- .../Renderers/InstructionsRenderer.php | 2 +- .../Components/Renderers/KeyValueRenderer.php | 6 +- .../Components/Renderers/MessageRenderer.php | 2 +- .../src/Components/Renderers/TaskRenderer.php | 2 +- .../Renderers/TextInputRenderer.php | 4 +- .../Static/StaticMultipleChoiceComponent.php | 8 +- .../Static/StaticProgressBarComponent.php | 2 +- .../Static/StaticSingleChoiceComponent.php | 2 +- .../Components/Static/StaticTaskComponent.php | 2 +- packages/console/src/ConsoleInputBuilder.php | 2 +- .../Exceptions/ConsoleExceptionHandler.php | 4 +- .../Exceptions/InvalidCommandException.php | 2 +- .../src/Exceptions/InvalidEnumArgument.php | 2 +- .../Exceptions/UnknownArgumentsException.php | 2 +- .../Injections/DynamicInjection.php | 2 +- .../Injections/FileInjection.php | 2 +- .../Injections/LinkInjection.php | 2 +- .../src/Highlight/TempestTerminalTheme.php | 2 +- .../ConsoleApplicationInitializer.php | 2 +- .../console/src/Input/ConsoleArgumentBag.php | 36 ++++---- .../console/src/Input/MemoryInputBuffer.php | 2 +- .../src/Installers/ConsoleInstaller.php | 2 +- .../console/src/Middleware/HelpMiddleware.php | 6 +- .../src/Middleware/OverviewMiddleware.php | 6 +- .../Middleware/ResolveOrRescueMiddleware.php | 6 +- .../ValidateNamedArgumentsMiddleware.php | 10 +-- .../console/src/Output/MemoryOutputBuffer.php | 2 +- packages/console/src/Output/TailReader.php | 2 +- .../src/Scheduler/GenericScheduler.php | 2 +- .../src/Stubs/GeneratorCommandStub.php | 2 +- packages/console/src/Terminal/Terminal.php | 4 +- .../console/src/Testing/ConsoleTester.php | 4 +- .../console/tests/CompletionHelperPhpTest.php | 2 +- .../console/tests/OptionCollectionTest.php | 6 +- .../src/Commands/MakeInitializerCommand.php | 2 +- .../CircularDependencyEncountered.php | 2 +- .../DependencyCouldNotBeAutowired.php | 2 +- .../TaggedDependencyCouldNotBeResolved.php | 2 +- packages/container/src/functions.php | 1 - packages/container/tests/ContainerTest.php | 50 +++++------ .../tests/Fixtures/SlowDependency.php | 2 +- packages/core/src/Commands/InstallCommand.php | 4 +- packages/core/src/Composer.php | 20 +++-- .../core/src/EnvironmentValueWasInvalid.php | 2 +- .../EnvironmentVariableValidationFailed.php | 2 +- .../core/src/Exceptions/ExceptionTester.php | 2 +- packages/core/src/FrameworkKernel.php | 6 +- .../core/src/InsightsProviderDiscovery.php | 1 - packages/core/src/IsComponentInstaller.php | 2 +- packages/core/src/Kernel/LoadConfig.php | 4 +- .../core/src/Kernel/LoadDiscoveryClasses.php | 6 +- packages/core/src/Middleware.php | 6 +- packages/core/src/PublishesFiles.php | 10 ++- packages/core/src/functions.php | 1 - packages/cryptography/tests/TimelockTest.php | 10 +-- .../database/src/Builder/ModelInspector.php | 8 +- .../QueryBuilders/CountQueryBuilder.php | 2 +- .../HasConvenientWhereMethods.php | 6 +- .../src/Commands/MakeMigrationCommand.php | 2 +- packages/database/src/DatabaseInitializer.php | 2 +- .../Exceptions/InsertColumnsMismatched.php | 4 +- packages/database/src/IsDatabaseModel.php | 14 ++- .../src/Mappers/SelectModelMapper.php | 2 +- .../src/Migrations/MigrationManager.php | 4 +- .../src/Migrations/RunnableMigrations.php | 12 ++- .../QueryStatements/AlterTableStatement.php | 4 +- .../src/QueryStatements/CompoundStatement.php | 2 +- .../src/QueryStatements/CountStatement.php | 4 +- .../CreateEnumTypeStatement.php | 6 +- .../QueryStatements/CreateTableStatement.php | 4 +- .../src/QueryStatements/DeleteStatement.php | 4 +- .../src/QueryStatements/EnumStatement.php | 6 +- .../src/QueryStatements/FieldStatement.php | 4 +- .../src/QueryStatements/InsertStatement.php | 6 +- .../src/QueryStatements/SelectStatement.php | 14 +-- .../src/QueryStatements/UpdateStatement.php | 6 +- .../QueryStatements/WhereGroupStatement.php | 4 +- .../DataTransferObjectSerializer.php | 2 +- packages/database/src/functions.php | 4 +- .../tests/Config/DatabaseConfigTest.php | 2 +- .../database/tests/GenericDatabaseTest.php | 4 +- packages/datetime/src/SecondsStyle.php | 2 +- packages/datetime/src/functions.php | 8 -- packages/datetime/tests/DateTimeTest.php | 38 ++++---- packages/datetime/tests/DurationTest.php | 58 ++++++------- packages/datetime/tests/SecondsStyleTest.php | 2 +- packages/datetime/tests/TimestampTest.php | 52 +++++------ packages/datetime/tests/TimezoneTest.php | 14 +-- packages/debug/src/Debug.php | 2 +- packages/debug/src/Stacktrace/Frame.php | 2 +- packages/debug/src/Stacktrace/Stacktrace.php | 6 +- packages/debug/tests/StacktraceTest.php | 6 +- .../src/Commands/MakeDiscoveryCommand.php | 2 +- packages/discovery/src/DiscoveryItems.php | 2 +- .../event-bus/src/Testing/EventBusTester.php | 2 +- packages/event-bus/src/functions.php | 2 - packages/event-bus/tests/EventBusTest.php | 12 +-- .../src/Php/ManipulatesPhpClasses.php | 6 +- .../src/Php/SimplifiesClassNames.php | 10 ++- .../generation/src/Php/StubFileGenerator.php | 7 +- .../src/TypeScript/TypeResolverDiscovery.php | 4 +- .../TypeScript/Writers/DirectoryWriter.php | 38 ++++---- .../tests/Php/ClassManipulatorTest.php | 4 +- packages/http/src/Input/StdinInputStream.php | 2 +- packages/http/src/IsResponse.php | 2 +- .../PsrRequestToGenericRequestMapper.php | 4 +- .../src/Mappers/RequestToObjectMapper.php | 4 +- packages/http/src/RequestHeaders.php | 4 +- .../Session/SessionIdResolverInitializer.php | 1 - .../PsrRequestToGenericRequestMapperTest.php | 4 +- .../tests/IdempotencyMiddlewareTest.php | 24 +++--- .../tests/IdempotentCommandMiddlewareTest.php | 18 ++-- packages/intl/src/GenericTranslator.php | 2 - packages/intl/src/IntlConfig.php | 1 - .../Formatter/MessageFormatter.php | 16 ++-- .../Parser/MessageFormatParser.php | 2 +- .../src/PluralRules/PluralRulesMatcher.php | 26 +++--- packages/intl/src/TranslationFailure.php | 2 - .../intl/src/TranslationMessageDiscovery.php | 3 +- packages/intl/src/TranslationMiss.php | 2 - packages/intl/src/Translator.php | 2 - packages/intl/src/TranslatorInitializer.php | 1 - packages/intl/src/functions.php | 2 - packages/intl/tests/FunctionsTest.php | 82 +++++++++--------- packages/intl/tests/LocaleTest.php | 24 ++++-- .../kv-store/src/Redis/Config/RedisConfig.php | 1 + .../kv-store/src/Redis/PhpRedisClient.php | 2 +- packages/kv-store/src/Redis/PredisClient.php | 2 +- packages/log/src/TailLogsCommand.php | 9 +- packages/mail/src/Attachment.php | 4 +- .../mail/src/EmailToSymfonyEmailMapper.php | 2 +- packages/mail/src/MailerInitializer.php | 1 - packages/mail/src/Testing/MailTester.php | 28 +++--- .../src/Transports/RoundRobinMailerConfig.php | 2 +- .../src/Transports/Ses/SesMailerConfig.php | 1 + .../Transports/Ses/SesSmtpMailerConfig.php | 1 + .../src/Transports/Smtp/SmtpMailerConfig.php | 1 + .../src/Mappers/ObjectToArrayMapper.php | 6 +- packages/mapper/src/functions.php | 1 - packages/process/src/InvokedProcessPool.php | 12 +-- packages/process/src/InvokedSystemProcess.php | 2 +- packages/process/src/ProcessPoolResults.php | 12 +-- .../src/Testing/InvokedProcessDescription.php | 2 +- .../src/Testing/InvokedTestingProcess.php | 12 ++- .../process/src/Testing/ProcessTester.php | 12 ++- .../tests/GenericProcessExecutorTest.php | 2 +- packages/reflection/src/ClassReflector.php | 8 +- packages/reflection/src/EnumReflector.php | 2 +- packages/reflection/src/FunctionReflector.php | 2 +- packages/reflection/src/MethodReflector.php | 2 +- packages/reflection/src/TypeReflector.php | 2 +- packages/reflection/src/functions.php | 2 - .../tests/Fixtures/NoReturnType.php | 1 - .../tests/FunctionReflectorTest.php | 2 +- .../src/Commands/MakeControllerCommand.php | 2 +- .../src/Exceptions/HtmlExceptionRenderer.php | 6 +- .../src/Exceptions/JsonExceptionRenderer.php | 2 +- packages/router/src/GenericRouter.php | 2 +- .../src/HandleRouteSpecificMiddleware.php | 2 +- packages/router/src/MatchRouteMiddleware.php | 15 ++-- .../router/src/RouteBindingInitializer.php | 10 ++- .../RouteMatchingRegexBuilder.php | 2 +- .../router/src/Static/StaticCleanCommand.php | 6 +- packages/router/src/functions.php | 1 - .../storage/src/Config/FTPStorageConfig.php | 1 + .../storage/src/Config/S3StorageConfig.php | 1 + .../storage/src/Config/SFTPStorageConfig.php | 1 + packages/support/src/Arr/ManipulatesArray.php | 2 +- packages/support/src/Arr/functions.php | 26 +++--- packages/support/src/IsEnumHelper.php | 2 +- .../src/JavaScript/DependencyInstaller.php | 2 +- .../support/src/JavaScript/PackageManager.php | 2 +- .../Json/Exception/JsonCouldNotBeDecoded.php | 1 - .../Json/Exception/JsonCouldNotBeEncoded.php | 1 - packages/support/src/Math/constants.php | 30 +++---- packages/support/src/Math/functions.php | 24 ++++-- packages/support/src/Uri/Uri.php | 10 +-- packages/support/src/Uri/functions.php | 2 +- .../tests/Arr/ManipulatesArrayTest.php | 86 +++++++++---------- .../tests/Conditions/HasConditionsTest.php | 10 +-- packages/support/tests/Math/MathsTest.php | 86 +++++++++---------- .../tests/Paginator/PaginatedDataTest.php | 2 +- .../support/tests/Paginator/PaginatorTest.php | 2 +- packages/support/tests/Path/PathTest.php | 2 +- .../support/tests/Regex/FunctionsTest.php | 6 +- packages/support/tests/Str/FunctionsTest.php | 2 +- .../tests/Str/ManipulatesStringTest.php | 4 +- packages/validation/src/Validator.php | 4 +- .../tests/Rules/IsJsonStringTest.php | 2 +- .../validation/tests/Rules/IsPasswordTest.php | 4 +- .../tests/Rules/ValidateWithTest.php | 4 +- packages/validation/tests/ValidatorTest.php | 12 +-- packages/view/src/Elements/ElementFactory.php | 2 +- packages/view/src/Elements/GenericElement.php | 1 + packages/view/src/Elements/IsElement.php | 8 +- packages/view/src/Elements/PhpElement.php | 1 + packages/view/src/Elements/RawElement.php | 1 + packages/view/src/Elements/RootElement.php | 6 +- packages/view/src/Elements/SlotElement.php | 1 + .../view/src/Elements/TemplateElement.php | 1 + packages/view/src/Elements/TextElement.php | 4 +- .../src/Elements/ViewComponentElement.php | 43 +++++----- .../view/src/Export/ViewObjectExporter.php | 4 +- .../src/Initializers/ViewCacheInitializer.php | 4 +- packages/view/src/Parser/TempestViewAst.php | 4 +- .../view/src/Parser/TempestViewCompiler.php | 4 +- .../view/src/Parser/TempestViewParser.php | 2 +- packages/view/src/Parser/Token.php | 8 +- packages/view/src/Parser/TokenCollection.php | 4 +- packages/view/src/Slot.php | 2 +- packages/view/src/ViewCachePool.php | 2 +- packages/view/src/functions.php | 3 - packages/view/tests/ViewCachePoolTest.php | 2 +- packages/vite/src/Installer/ViteInstaller.php | 2 +- packages/vite/src/Manifest/Manifest.php | 4 +- .../TagsResolver/DevelopmentTagsResolver.php | 4 +- .../src/TagsResolver/ManifestTagsResolver.php | 8 +- packages/vite/src/ViteDiscovery.php | 1 - packages/vite/src/functions.php | 2 - .../Framework/Commands/ConfigShowCommand.php | 4 +- .../Commands/MetaViewComponentCommand.php | 16 ++-- .../Installers/FrameworkInstaller.php | 2 +- .../Installers/ViewComponentsInstaller.php | 2 +- .../Testing/Http/HttpRouterTester.php | 2 +- .../Testing/Http/TestResponseHelper.php | 6 +- .../Framework/Testing/IntegrationTest.php | 10 +-- src/Tempest/Framework/Testing/ViteTester.php | 4 +- tests/Benchmark/Container/ContainerBench.php | 10 +-- .../Benchmark/Extension/MarkdownExtension.php | 2 +- .../Benchmark/Extension/MarkdownRenderer.php | 6 +- tests/Benchmark/Http/GenericRouterBench.php | 12 +-- .../Fixtures/Controllers/DeferController.php | 2 +- .../Auth/AccessControl/HasPolicyTests.php | 6 +- .../Auth/OAuth/TestingOAuthClientTest.php | 2 +- tests/Integration/Cache/CacheTest.php | 16 ++-- tests/Integration/Cache/LockTest.php | 6 +- .../CommandBus/AsyncCommandTest.php | 6 +- .../Actions/ExecuteConsoleCommandTest.php | 2 +- .../Commands/MakeMiddlewareCommandTest.php | 4 +- .../Components/ProgressBarComponentTest.php | 6 +- .../Components/SearchComponentTest.php | 2 +- .../Static/StaticConfirmComponentTest.php | 10 +-- .../StaticMultipleChoiceComponentTest.php | 12 +-- .../Static/StaticProgressBarComponentTest.php | 4 +- .../Static/StaticSearchComponentTest.php | 2 +- .../StaticSingleChoiceComponentTest.php | 16 ++-- .../Static/StaticTextBoxComponentTest.php | 6 +- .../Console/Components/TaskComponentTest.php | 4 +- .../Console/ConsoleArgumentBagTest.php | 6 +- .../Console/Fixtures/InteractiveCommand.php | 8 +- .../Input/ConsoleInputArgumentTest.php | 8 +- .../ResolveOrRescueMiddlewareTest.php | 4 +- .../Console/Testing/ConsoleTesterTest.php | 12 +-- tests/Integration/Core/DeferredTasksTest.php | 4 +- .../Core/LoadDiscoveryClassesTest.php | 2 +- .../Core/ViewComponentsInstallerTest.php | 4 +- .../Integration/Cryptography/TimelockTest.php | 2 +- .../Builder/ConvenientWhereMethodsTest.php | 8 +- .../Builder/CountQueryBuilderTest.php | 8 +- .../Builder/DeleteQueryBuilderTest.php | 6 +- .../Builder/InsertQueryBuilderTest.php | 4 +- .../Database/Builder/NestedWhereTest.php | 18 ++-- .../Builder/SelectQueryBuilderTest.php | 16 ++-- .../Builder/TransformsQueryBuilderTest.php | 12 +-- .../Builder/UpdateQueryBuilderTest.php | 6 +- .../Database/Builder/WhereOperatorTest.php | 4 +- .../ConvenientDateWhereMethodsTest.php | 6 +- ...ustomPrimaryKeyRelationshipLoadingTest.php | 2 +- .../Database/EncryptedAttributeTest.php | 2 + .../Database/GenericDatabaseTest.php | 8 +- .../Database/GroupedWhereMethodsTest.php | 34 ++++---- .../Database/HashedAttributeTest.php | 2 + .../Database/MultiDatabaseTest.php | 4 +- tests/Integration/Database/ToRawSqlTest.php | 2 +- tests/Integration/Debug/DebugTest.php | 2 +- .../EventBus/EventBusTesterTest.php | 18 ++-- .../FrameworkIntegrationTestCase.php | 4 +- .../Http/Exceptions/ExceptionRendererTest.php | 14 +-- .../Exceptions/HttpExceptionHandlerTest.php | 4 +- .../Http/GenericResponseSenderTest.php | 10 +-- .../Http/HeaderSessionIdResolverTest.php | 4 +- .../Http/TrackPreviousUrlMiddlewareTest.php | 12 +-- tests/Integration/Icon/IconTest.php | 2 +- tests/Integration/Intl/TranslatorTest.php | 4 +- tests/Integration/Log/GenericLoggerTest.php | 6 +- tests/Integration/Mailer/AttachmentTest.php | 2 +- tests/Integration/Mailer/MailerTesterTest.php | 8 +- tests/Integration/Mailer/SentEmailTest.php | 8 +- .../Mapper/Fixtures/SerializableObject.php | 4 - .../Integration/Mapper/ObjectFactoryTest.php | 2 +- .../Process/ProcessExecutorTest.php | 2 +- .../Process/ProcessTesterAssertNotRanTest.php | 6 +- .../Process/ProcessTesterAssertRanTest.php | 14 +-- .../Integration/Process/ProcessTesterTest.php | 6 +- tests/Integration/Route/ClientTest.php | 2 +- .../Route/RequestToObjectMapperTest.php | 4 +- .../Integration/Storage/StorageTesterTest.php | 4 +- .../Integration/Validator/ExistsRuleTest.php | 6 +- .../View/Components/IconComponentTest.php | 26 +++--- tests/Integration/View/ElementFactoryTest.php | 2 +- tests/Integration/View/ViewCacheTest.php | 8 +- .../View/ViewComponentDiscoveryTest.php | 2 +- tests/Integration/View/ViewComponentTest.php | 6 +- tests/Integration/Vite/ViteTesterTest.php | 6 +- 340 files changed, 1165 insertions(+), 1121 deletions(-) diff --git a/packages/auth/src/AccessControl/PolicyBasedAccessControl.php b/packages/auth/src/AccessControl/PolicyBasedAccessControl.php index 3751de141..cfb7e2c88 100644 --- a/packages/auth/src/AccessControl/PolicyBasedAccessControl.php +++ b/packages/auth/src/AccessControl/PolicyBasedAccessControl.php @@ -85,7 +85,7 @@ private function findPoliciesForResourceAction(object|string $resource, UnitEnum $actionBeingEvaluated = Str\parse($action); return new ImmutableArray($this->authConfig->policies[$resource] ?? []) - ->filter(fn ($_, string $action) => $action === $actionBeingEvaluated) + ->filter(static fn ($_, string $action) => $action === $actionBeingEvaluated) ->flatten(); } @@ -96,13 +96,13 @@ private function evaluatePolicy(MethodReflector $policy, ?object $resource, ?obj $this->ensureParameterAcceptsInput( reflector: $policy->getParameter(key: 0), input: $resource, - throw: fn (string $expected) => throw PolicyMethodWasInvalid::resourceParameterIsInvalid($policyName, $expected), + throw: static fn (string $expected) => throw PolicyMethodWasInvalid::resourceParameterIsInvalid($policyName, $expected), ); $this->ensureParameterAcceptsInput( reflector: $policy->getParameter(key: 1), input: $subject, - throw: fn (string $expected) => throw PolicyMethodWasInvalid::subjectParameterIsInvalid($policyName, $expected), + throw: static fn (string $expected) => throw PolicyMethodWasInvalid::subjectParameterIsInvalid($policyName, $expected), ); $decision = $policy->invokeArgs( diff --git a/packages/auth/src/AccessControl/PolicyDiscovery.php b/packages/auth/src/AccessControl/PolicyDiscovery.php index 92f28c4aa..85319bdff 100644 --- a/packages/auth/src/AccessControl/PolicyDiscovery.php +++ b/packages/auth/src/AccessControl/PolicyDiscovery.php @@ -2,7 +2,6 @@ namespace Tempest\Auth\AccessControl; -use Tempest\Auth\AccessControl\Policy; use Tempest\Auth\AuthConfig; use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; diff --git a/packages/auth/src/Installer/OAuthInstaller.php b/packages/auth/src/Installer/OAuthInstaller.php index 8915b44d3..2cf5c3ab4 100644 --- a/packages/auth/src/Installer/OAuthInstaller.php +++ b/packages/auth/src/Installer/OAuthInstaller.php @@ -53,7 +53,7 @@ public function install(): void '3. Review and customize the published files if needed', '', 'Published files', - ...arr($this->publishedFiles)->map(fn (string $file) => '→ ' . $file), + ...arr($this->publishedFiles)->map(static fn (string $file) => '→ ' . $file), ]); } @@ -108,7 +108,7 @@ private function publishController(SupportedOAuthProvider $provider): void $this->update( path: $destination, - callback: fn (ImmutableString $contents) => $contents->replace( + callback: static fn (ImmutableString $contents) => $contents->replace( search: [ "'tag_name'", 'redirect-route', @@ -132,7 +132,7 @@ private function publishController(SupportedOAuthProvider $provider): void private function installComposerDependencies(SupportedOAuthProvider ...$providers): void { $packages = arr($providers) - ->map(fn (SupportedOAuthProvider $provider) => $provider->composerPackage()) + ->map(static fn (SupportedOAuthProvider $provider) => $provider->composerPackage()) ->filter(); if ($packages->isNotEmpty()) { @@ -167,7 +167,7 @@ private function extractSettings(SupportedOAuthProvider $provider): array try { return str(read_file($configPath)) ->matchAll("/env\('(OAUTH_[^']*)'/", matches: 1) - ->map(fn (array $matches) => $matches[1] ?? null) + ->map(static fn (array $matches) => $matches[1] ?? null) ->filter() ->toArray(); } catch (PathWasNotFound|PathWasNotReadable) { diff --git a/packages/auth/src/Installer/oauth/OAuthControllerStub.php b/packages/auth/src/Installer/oauth/OAuthControllerStub.php index 293ab874f..cd7be2d0e 100644 --- a/packages/auth/src/Installer/oauth/OAuthControllerStub.php +++ b/packages/auth/src/Installer/oauth/OAuthControllerStub.php @@ -36,7 +36,7 @@ public function callback(Request $request): Redirect $this->oauth->authenticate( request: $request, - map: fn (OAuthUser $user): Authenticatable => query('user-model-fqcn')->updateOrCreate([ + map: static fn (OAuthUser $user): Authenticatable => query('user-model-fqcn')->updateOrCreate([ 'provider_db_column' => $user->id, ], [ 'provider_db_column' => $user->id, diff --git a/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php b/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php index b1adf3e75..e0b4e6137 100644 --- a/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * The client secret for the Discord OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php b/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php index 376e19b86..27ce451e9 100644 --- a/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php @@ -26,6 +26,7 @@ public function __construct( /** * The client secret for the Facebook OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/GenericOAuthConfig.php b/packages/auth/src/OAuth/Config/GenericOAuthConfig.php index 9f296e5f4..2b9e3973d 100644 --- a/packages/auth/src/OAuth/Config/GenericOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/GenericOAuthConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * The client secret for the OAuth provider. */ + #[\SensitiveParameter] public string $clientSecret, /** @@ -40,6 +41,7 @@ public function __construct( /** * The access token URL for the OAuth provider. */ + #[\SensitiveParameter] public string $urlAccessToken, /** diff --git a/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php b/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php index cd0d3e82c..092b7fc39 100644 --- a/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php @@ -26,6 +26,7 @@ public function __construct( /** * The client secret for the GitHub OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php b/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php index c1a0d8f5c..88bfa1a60 100644 --- a/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php @@ -26,6 +26,7 @@ public function __construct( /** * The client secret for the Google OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php b/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php index 42a39e4b7..e06d5565f 100644 --- a/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * The client secret for the Instagram OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php b/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php index 839b24dd2..68a7bb661 100644 --- a/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * The client secret for the LinkedIn OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php b/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php index 943c82090..d2967d007 100644 --- a/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * The client secret for the Microsoft OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/SlackOAuthConfig.php b/packages/auth/src/OAuth/Config/SlackOAuthConfig.php index 212f40a4e..513091bae 100644 --- a/packages/auth/src/OAuth/Config/SlackOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/SlackOAuthConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * The client secret for the Slack OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php b/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php index e48e268f9..8b2bf25b8 100644 --- a/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php @@ -26,6 +26,7 @@ public function __construct( /** * The client secret for the Twitch OAuth application. */ + #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/GenericOAuthClient.php b/packages/auth/src/OAuth/GenericOAuthClient.php index 9b591f26e..41286a336 100644 --- a/packages/auth/src/OAuth/GenericOAuthClient.php +++ b/packages/auth/src/OAuth/GenericOAuthClient.php @@ -101,7 +101,7 @@ public function requestAccessToken(string $code): AccessToken } } - public function fetchUser(AccessToken $token): OAuthUser + public function fetchUser(#[\SensitiveParameter] AccessToken $token): OAuthUser { try { return $this->config->mapUser( diff --git a/packages/auth/src/OAuth/OAuthClient.php b/packages/auth/src/OAuth/OAuthClient.php index 63eb5566f..bceef9c51 100644 --- a/packages/auth/src/OAuth/OAuthClient.php +++ b/packages/auth/src/OAuth/OAuthClient.php @@ -38,7 +38,7 @@ public function requestAccessToken(string $code): AccessToken; /** * Gets user information from an OAuth provider using an access token. */ - public function fetchUser(AccessToken $token): OAuthUser; + public function fetchUser(#[\SensitiveParameter] AccessToken $token): OAuthUser; /** * Authenticates a user based on the given OAuth callback request. diff --git a/packages/auth/src/OAuth/OAuthProvider.php b/packages/auth/src/OAuth/OAuthProvider.php index 5bb8dcaba..4339dad98 100644 --- a/packages/auth/src/OAuth/OAuthProvider.php +++ b/packages/auth/src/OAuth/OAuthProvider.php @@ -27,5 +27,5 @@ public function getAccessToken(string $code): AccessToken; /** * Gets the resource owner information using an access token. */ - public function getResourceOwner(AccessToken $token): ResourceOwnerInterface; + public function getResourceOwner(#[\SensitiveParameter] AccessToken $token): ResourceOwnerInterface; } diff --git a/packages/auth/src/OAuth/Testing/TestingOAuthClient.php b/packages/auth/src/OAuth/Testing/TestingOAuthClient.php index 470cf0ccd..20892876b 100644 --- a/packages/auth/src/OAuth/Testing/TestingOAuthClient.php +++ b/packages/auth/src/OAuth/Testing/TestingOAuthClient.php @@ -107,7 +107,7 @@ public function requestAccessToken(string $code): AccessToken return $token; } - public function fetchUser(AccessToken $token): OAuthUser + public function fetchUser(#[\SensitiveParameter] AccessToken $token): OAuthUser { $this->users[] = [ 'token' => $token, @@ -217,7 +217,7 @@ public function assertAuthorizationUrlGenerated(?array $scopes = null, ?array $o public function assertUserFetched(string $code): void { Assert::assertNotEmpty( - actual: array_filter($this->users, fn (array $user) => $user['code'] === $code), + actual: array_filter($this->users, static fn (array $user) => $user['code'] === $code), message: sprintf('User with code "%s" was not handled.', $code), ); } @@ -231,7 +231,7 @@ public function assertAccessTokenRetrieved(?string $code = null): void if ($code !== null) { Assert::assertNotEmpty( - actual: array_filter($this->accessTokens, fn (array $token) => $token['code'] === $code), + actual: array_filter($this->accessTokens, static fn (#[\SensitiveParameter] array $token) => $token['code'] === $code), message: sprintf('No access token was retrieved for code "%s".', $code), ); } diff --git a/packages/auth/tests/OAuthTest.php b/packages/auth/tests/OAuthTest.php index 8f9271d55..503f16643 100644 --- a/packages/auth/tests/OAuthTest.php +++ b/packages/auth/tests/OAuthTest.php @@ -185,7 +185,7 @@ public function oauth_user_creation(): void avatar: 'https://example.com/avatar.jpg', provider: 'github', raw: [ - 'id' => 123456, + 'id' => 123_456, 'login' => 'frieren', 'name' => 'Frieren the Mage', 'email' => 'frieren@elven-mage.magic', diff --git a/packages/cache/src/Commands/CacheClearCommand.php b/packages/cache/src/Commands/CacheClearCommand.php index fb1c7b13c..61ba781ae 100644 --- a/packages/cache/src/Commands/CacheClearCommand.php +++ b/packages/cache/src/Commands/CacheClearCommand.php @@ -93,8 +93,8 @@ private function clearUserCaches(?string $tag = null, bool $all = false): void /** @var GenericContainer $container */ $container = $this->container; $cacheTags = arr($container->getSingletons(CacheConfig::class)) - ->map(fn ($_, string $key) => $key === CacheConfig::class ? self::DEFAULT_CACHE : Str\after_last($key, '#')) - ->filter(fn (string $value) => $tag === null || $value === $tag) + ->map(static fn ($_, string $key) => $key === CacheConfig::class ? self::DEFAULT_CACHE : Str\after_last($key, '#')) + ->filter(static fn (string $value) => $tag === null || $value === $tag) ->values(); if ($all === false && count($cacheTags) > 1) { diff --git a/packages/cache/src/GenericCache.php b/packages/cache/src/GenericCache.php index 2023dd58b..1576223a7 100644 --- a/packages/cache/src/GenericCache.php +++ b/packages/cache/src/GenericCache.php @@ -133,7 +133,7 @@ public function getMany(iterable $key): array if (! $this->enabled) { return Arr\map_with_keys( array: $key, - map: fn (string|Stringable $key) => yield (string) $key => null, + map: static fn (string|Stringable $key) => yield (string) $key => null, ); } diff --git a/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php b/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php index b7759e982..cfa7c47f3 100644 --- a/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php +++ b/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php @@ -52,7 +52,7 @@ public function markAsFailed(string $uuid): void public function getPendingCommands(): array { return arr(glob(__DIR__ . '/../stored-commands/*.pending.txt')) - ->mapWithKeys(function (string $path) { + ->mapWithKeys(static function (string $path) { if (! Filesystem\is_file($path)) { return; } diff --git a/packages/command-bus/src/MonitorAsyncCommands.php b/packages/command-bus/src/MonitorAsyncCommands.php index 03187e00b..f28ed0033 100644 --- a/packages/command-bus/src/MonitorAsyncCommands.php +++ b/packages/command-bus/src/MonitorAsyncCommands.php @@ -35,33 +35,35 @@ public function __invoke(): void while (true) { // @phpstan-ignore-line foreach ($processes as $uuid => $process) { - if ($process->isTerminated()) { - if ($process->isSuccessful()) { - $this->console->keyValue( - key: "{$uuid}", - value: "SUCCESS", - ); - } else { - $this->console->keyValue( - key: "{$uuid}", - value: "FAILED", - ); - } - - if ($output = trim($process->getOutput())) { - $this->writeln($output); - } - - if ($errorOutput = trim($process->getErrorOutput())) { - $this->writeln($errorOutput); - } - - unset($processes[$uuid]); + if (! $process->isTerminated()) { + continue; } + + if ($process->isSuccessful()) { + $this->console->keyValue( + key: "{$uuid}", + value: "SUCCESS", + ); + } else { + $this->console->keyValue( + key: "{$uuid}", + value: "FAILED", + ); + } + + if ($output = trim($process->getOutput())) { + $this->writeln($output); + } + + if ($errorOutput = trim($process->getErrorOutput())) { + $this->writeln($errorOutput); + } + + unset($processes[$uuid]); } $availableCommands = arr($this->repository->getPendingCommands()) - ->filter(fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes)); + ->filter(static fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes)); if (count($processes) === 5) { $this->sleep(0.5); diff --git a/packages/command-bus/src/functions.php b/packages/command-bus/src/functions.php index e9dfbceda..3333d44a5 100644 --- a/packages/command-bus/src/functions.php +++ b/packages/command-bus/src/functions.php @@ -4,7 +4,6 @@ namespace Tempest\CommandBus; -use Tempest\CommandBus\CommandBus; use Tempest\Container; /** diff --git a/packages/console/src/Actions/RenderConsoleCommand.php b/packages/console/src/Actions/RenderConsoleCommand.php index 8015f7293..72d6778c8 100644 --- a/packages/console/src/Actions/RenderConsoleCommand.php +++ b/packages/console/src/Actions/RenderConsoleCommand.php @@ -77,7 +77,7 @@ private function renderArgument(ConsoleArgumentDefinition $argument): string private function renderEnumArgument(ConsoleArgumentDefinition $argument): string { $parts = array_map( - callback: fn (BackedEnum $case) => $case->value, + callback: static fn (BackedEnum $case) => $case->value, array: $argument->type::cases(), ); diff --git a/packages/console/src/Actions/ResolveConsoleCommand.php b/packages/console/src/Actions/ResolveConsoleCommand.php index 6ff6da1f7..1fc5795a8 100644 --- a/packages/console/src/Actions/ResolveConsoleCommand.php +++ b/packages/console/src/Actions/ResolveConsoleCommand.php @@ -27,7 +27,7 @@ public function __invoke(array|string $command): ConsoleCommand if (is_array($command)) { $command = array_find( array: $this->consoleConfig->commands, - callback: fn (ConsoleCommand $consoleCommand) => ( + callback: static fn (ConsoleCommand $consoleCommand) => ( $consoleCommand->handler->getDeclaringClass()->getName() === $command[0] && $consoleCommand->handler->getName() === $command[1] ), diff --git a/packages/console/src/Commands/AboutCommand.php b/packages/console/src/Commands/AboutCommand.php index c5ca55399..13957bf6d 100644 --- a/packages/console/src/Commands/AboutCommand.php +++ b/packages/console/src/Commands/AboutCommand.php @@ -76,7 +76,7 @@ private function formatInsight(Stringable|Insight|array|string $value): string { return arr($value) ->filter() - ->map(function (Stringable|Insight|string $value) { + ->map(static function (Stringable|Insight|string $value) { if ($value instanceof Insight) { return $value->formattedValue; } @@ -91,7 +91,7 @@ private function rawInsight(Stringable|Insight|array|string $value): array { return arr($value) ->filter() - ->map(function (Stringable|Insight|string $value) { + ->map(static function (Stringable|Insight|string $value) { if ($value instanceof Insight) { return $value->value; } diff --git a/packages/console/src/Commands/MakeCommandCommand.php b/packages/console/src/Commands/MakeCommandCommand.php index ff03458bf..34b177d59 100644 --- a/packages/console/src/Commands/MakeCommandCommand.php +++ b/packages/console/src/Commands/MakeCommandCommand.php @@ -39,7 +39,7 @@ public function __invoke( 'dummy-command-slug' => str($className)->kebab()->toString(), ], manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Commands/MakeGeneratorCommandCommand.php b/packages/console/src/Commands/MakeGeneratorCommandCommand.php index b3ef45c23..5c3e70e12 100644 --- a/packages/console/src/Commands/MakeGeneratorCommandCommand.php +++ b/packages/console/src/Commands/MakeGeneratorCommandCommand.php @@ -39,7 +39,7 @@ public function __invoke( 'dummy-command-slug' => str($className)->kebab()->toString(), ], manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Commands/MakeMiddlewareCommand.php b/packages/console/src/Commands/MakeMiddlewareCommand.php index 9a041f721..070bc1bb4 100644 --- a/packages/console/src/Commands/MakeMiddlewareCommand.php +++ b/packages/console/src/Commands/MakeMiddlewareCommand.php @@ -42,7 +42,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Completion/CompletionEngine.php b/packages/console/src/Completion/CompletionEngine.php index ecc53dc37..9c8ab469c 100644 --- a/packages/console/src/Completion/CompletionEngine.php +++ b/packages/console/src/Completion/CompletionEngine.php @@ -131,9 +131,11 @@ private function selectCompletionValue(CompletionFlag $flag, string $current): ? $candidates[] = $flag->flag; foreach ($flag->aliases as $alias) { - if (str_starts_with($alias, '--')) { - $candidates[] = $alias; + if (! str_starts_with($alias, '--')) { + continue; } + + $candidates[] = $alias; } } elseif (str_starts_with($current, '-')) { foreach ($flag->aliases as $alias) { diff --git a/packages/console/src/Components/Concerns/RendersControls.php b/packages/console/src/Components/Concerns/RendersControls.php index 5e42d13d9..6dbf6b006 100644 --- a/packages/console/src/Components/Concerns/RendersControls.php +++ b/packages/console/src/Components/Concerns/RendersControls.php @@ -43,7 +43,7 @@ private function renderControls(array $controls, int $maxWidth): string $separator = ' · '; $marginLeft = ' '; $render = arr($controls) - ->map(fn (string $label, string $shortcut) => "{$shortcut} {$label}") + ->map(static fn (string $label, string $shortcut) => "{$shortcut} {$label}") ->implode($separator) ->prepend($marginLeft); diff --git a/packages/console/src/Components/Interactive/ProgressBarComponent.php b/packages/console/src/Components/Interactive/ProgressBarComponent.php index c6bc4a07c..897fefe5e 100644 --- a/packages/console/src/Components/Interactive/ProgressBarComponent.php +++ b/packages/console/src/Components/Interactive/ProgressBarComponent.php @@ -43,7 +43,7 @@ public function render(Terminal $terminal): Generator $count = iterator_count($this->data); $step = 1; - $format = $this->format ?? function (int $step, int $count): string { + $format = $this->format ?? static function (int $step, int $count): string { $width = 30; $progress = (int) round(($step / $count) * $width); diff --git a/packages/console/src/Components/Interactive/TaskComponent.php b/packages/console/src/Components/Interactive/TaskComponent.php index 4ccb73ede..e75b288b8 100644 --- a/packages/console/src/Components/Interactive/TaskComponent.php +++ b/packages/console/src/Components/Interactive/TaskComponent.php @@ -139,9 +139,11 @@ private function renderTask(Terminal $terminal, ?string $line = null): string private function cleanupSockets(): void { foreach ($this->sockets as $socket) { - if (is_resource($socket)) { - @fclose($socket); + if (! is_resource($socket)) { + continue; } + + @fclose($socket); } $this->sockets = []; @@ -151,7 +153,7 @@ private function executeHandler(): never { $log = function (string ...$lines): void { arr($lines) - ->flatMap(fn (string $line) => explode("\n", $line)) + ->flatMap(static fn (string $line) => explode("\n", $line)) ->each(function (string $line): void { fwrite($this->sockets[0], $line); }); @@ -172,7 +174,7 @@ private function resolveHandler(null|Process|Closure $handler): ?Closure if ($handler instanceof Process) { return static function (Closure $log) use ($handler): bool { - return $handler->run(function (string $type, string $buffer) use ($log): void { + return $handler->run(static function (string $type, string $buffer) use ($log): void { if ($type === Process::ERR) { return; } diff --git a/packages/console/src/Components/InteractiveComponentRenderer.php b/packages/console/src/Components/InteractiveComponentRenderer.php index 63bb076d2..3c7806863 100644 --- a/packages/console/src/Components/InteractiveComponentRenderer.php +++ b/packages/console/src/Components/InteractiveComponentRenderer.php @@ -108,14 +108,14 @@ private function applyKey(InteractiveConsoleComponent $component, Console $conso // If we have multiple handlers, we put the ones that return nothing // first because the ones that return something will be overridden otherwise. - usort($handlersForKey, fn (MethodReflector $a, MethodReflector $b) => $b->getReturnType()->equals('void') <=> $a->getReturnType()->equals('void')); + usort($handlersForKey, static fn (MethodReflector $a, MethodReflector $b) => $b->getReturnType()->equals('void') <=> $a->getReturnType()->equals('void')); // CTRL+C and CTRL+D means we exit the CLI, but only if there is no custom // handler. When we exit, we want one last render to display pretty // styles, so we will throw the exception in the next loop. if ($handlersForKey === [] && ($key === Key::CTRL_C->value || $key === Key::CTRL_D->value)) { $component->setState(ComponentState::CANCELLED); - $this->afterRenderCallbacks[] = fn () => throw new InterruptException(); + $this->afterRenderCallbacks[] = static fn () => throw new InterruptException(); $this->shouldRerender = true; Fiber::suspend(); @@ -242,7 +242,7 @@ private function validate(mixed $value, array $validation): ?string public function isComponentSupported(Console $console, InteractiveConsoleComponent $component): bool { - if (! arr($component->extensions ?? [])->every(fn (string $ext) => extension_loaded($ext))) { + if (! arr($component->extensions ?? [])->every(static fn (string $ext) => extension_loaded($ext))) { return false; } diff --git a/packages/console/src/Components/OptionCollection.php b/packages/console/src/Components/OptionCollection.php index 16243f1be..4d76724d4 100644 --- a/packages/console/src/Components/OptionCollection.php +++ b/packages/console/src/Components/OptionCollection.php @@ -38,7 +38,7 @@ public function setCollection(iterable $options): void $this->preserveKeys = $options->isAssociative(); $this->options = $options - ->map(fn (mixed $value, string|int $key) => new Option($key, $value)) + ->map(static fn (mixed $value, string|int $key) => new Option($key, $value)) ->toArray(); $this->filter(null); @@ -50,11 +50,11 @@ public function filter(?string $query): void $previouslySelectedOptions = $this->selectedOptions; $this->filteredOptions = arr($this->options) - ->filter(fn (Option $option) => ! $query || str_contains(mb_strtolower((string) $option->value), mb_strtolower(trim($query)))) + ->filter(static fn (Option $option) => ! $query || str_contains(mb_strtolower((string) $option->value), mb_strtolower(trim($query)))) ->values() ->toArray(); - $this->selectedOptions = array_filter($this->filteredOptions, fn (Option $option) => in_array($option, $previouslySelectedOptions, strict: true)); + $this->selectedOptions = array_filter($this->filteredOptions, static fn (Option $option) => in_array($option, $previouslySelectedOptions, strict: true)); $this->activeOption = array_search($previouslyActiveOption ?? $this->filteredOptions[0] ?? '', $this->filteredOptions, strict: true) ?: 0; } @@ -90,7 +90,7 @@ public function toggleCurrent(): void if (! $this->isSelected($active)) { $this->selectedOptions[] = $active; } else { - $this->selectedOptions = array_filter($this->selectedOptions, fn (Option $option) => ! $active->equals($option)); + $this->selectedOptions = array_filter($this->selectedOptions, static fn (Option $option) => ! $active->equals($option)); } } @@ -160,7 +160,7 @@ public function getCurrentIndex(): int public function isSelected(Option $option): bool { - return (bool) arr($this->selectedOptions)->first(fn (Option $other) => $option->equals($other)); + return (bool) arr($this->selectedOptions)->first(static fn (Option $other) => $option->equals($other)); } public function isActive(Option $option): bool @@ -186,7 +186,7 @@ public function setActive(null|Stringable|UnitEnum|string $value): void }; $this->activeOption = array_search( - array_find($this->filteredOptions, fn (Option $option) => $option->key === $value || $option->value === $value), + array_find($this->filteredOptions, static fn (Option $option) => $option->key === $value || $option->value === $value), $this->filteredOptions, strict: true, ) ?: 0; diff --git a/packages/console/src/Components/Renderers/InstructionsRenderer.php b/packages/console/src/Components/Renderers/InstructionsRenderer.php index d2d8b57e9..165211594 100644 --- a/packages/console/src/Components/Renderers/InstructionsRenderer.php +++ b/packages/console/src/Components/Renderers/InstructionsRenderer.php @@ -15,7 +15,7 @@ public function render(string|array $lines): string { $lines = arr($lines) ->filter() - ->flatMap(fn (string $string) => str($string)->chunk(self::MAX_WIDTH)->toArray()) + ->flatMap(static fn (string $string) => str($string)->chunk(self::MAX_WIDTH)->toArray()) ->toArray(); $text = str(PHP_EOL); diff --git a/packages/console/src/Components/Renderers/KeyValueRenderer.php b/packages/console/src/Components/Renderers/KeyValueRenderer.php index 98a96f1f2..1720411d7 100644 --- a/packages/console/src/Components/Renderers/KeyValueRenderer.php +++ b/packages/console/src/Components/Renderers/KeyValueRenderer.php @@ -20,8 +20,8 @@ public function render(Stringable|string $key, null|Stringable|string $value = n { $key = $this->cleanText($key)->append(' '); $value = $this->cleanText($value)->when( - condition: fn ($s) => $s->stripTags()->length() !== 0, - callback: fn ($s) => $s->prepend(' '), + condition: static fn ($s) => $s->stripTags()->length() !== 0, + callback: static fn ($s) => $s->prepend(' '), ); $maximumWidth = $useAvailableWidth @@ -58,7 +58,7 @@ private function cleanText(null|Stringable|string $text): ImmutableString return $text ->replaceRegex('/\[([^]]+)]/', '[$1]') - ->when(fn ($s) => $s->endsWith(['.', '?', '!', ':']), fn ($s) => $s->replaceAt(-1, 1, '')) + ->when(static fn ($s) => $s->endsWith(['.', '?', '!', ':']), static fn ($s) => $s->replaceAt(-1, 1, '')) ->erase(root_path()) ->trim(); } diff --git a/packages/console/src/Components/Renderers/MessageRenderer.php b/packages/console/src/Components/Renderers/MessageRenderer.php index 398725c4f..2941e8ec1 100644 --- a/packages/console/src/Components/Renderers/MessageRenderer.php +++ b/packages/console/src/Components/Renderers/MessageRenderer.php @@ -19,7 +19,7 @@ public function render(string $contents, ?string $title = null): string { $title = str($title ?? $this->label)->toString(); $lines = ImmutableArray::explode($contents, "\n") - ->map(fn ($s, $i) => str_repeat(' ', $i === 0 ? 1 : strlen($title) + 4) . $s) + ->map(static fn ($s, $i) => str_repeat(' ', $i === 0 ? 1 : strlen($title) + 4) . $s) ->implode("\n"); return str() diff --git a/packages/console/src/Components/Renderers/TaskRenderer.php b/packages/console/src/Components/Renderers/TaskRenderer.php index 0e73f87a9..2e0535aef 100644 --- a/packages/console/src/Components/Renderers/TaskRenderer.php +++ b/packages/console/src/Components/Renderers/TaskRenderer.php @@ -23,7 +23,7 @@ public function render(Terminal $terminal, ComponentState $state, float $started $this->prepareRender($terminal, $state); $this->label($this->label); - $runtime = fn (float $finishedAt) => $finishedAt + $runtime = static fn (float $finishedAt) => $finishedAt ? number_format(($finishedAt - $startedAt) / 1_000_000, decimals: 0) : null; diff --git a/packages/console/src/Components/Renderers/TextInputRenderer.php b/packages/console/src/Components/Renderers/TextInputRenderer.php index 5d6006811..028e18c21 100644 --- a/packages/console/src/Components/Renderers/TextInputRenderer.php +++ b/packages/console/src/Components/Renderers/TextInputRenderer.php @@ -53,8 +53,8 @@ public function render( // if there is nothing to display after the component is done, show "no input" // TODO(innocenzi): clean up - if ($this->state->isFinished() && $lines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) { - $displayLines = $displayLines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty()); + if ($this->state->isFinished() && $lines->filter(static fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) { + $displayLines = $displayLines->filter(static fn (ImmutableString $line) => $line->trim()->isNotEmpty()); $this->line($this->style('italic dim', 'No input.'))->newLine(); } diff --git a/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php b/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php index 76e3a8a0d..1679e60e4 100644 --- a/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php @@ -35,7 +35,7 @@ public function render(Console $console): array $answers = $this->askQuestion($console); $answerAsString = arr($answers) - ->map(fn (Option $option) => $option->displayValue) + ->map(static fn (Option $option) => $option->displayValue) ->join(', ', ' and ') ->trim() ->toString() ?: 'no option'; @@ -52,7 +52,7 @@ public function render(Console $console): array return $this->default; } - return array_map(fn (Option $option) => $option->value, $answers); + return array_map(static fn (Option $option) => $option->value, $answers); } private function askQuestion(Console $console): array @@ -66,7 +66,7 @@ private function askQuestion(Console $console): array fn (Option $option, int $index) => str($index) ->when( condition: in_array($option->value, $this->default, strict: true), - callback: fn ($s) => $s->wrap('', ''), + callback: static fn ($s) => $s->wrap('', ''), ) ->wrap('[', ']') ->prepend('- ') @@ -105,7 +105,7 @@ private function askQuestion(Console $console): array }); }) ->filter() - ->unique(fn (Option $option) => $option->value) + ->unique(static fn (Option $option) => $option->value) ->toArray(); } } diff --git a/packages/console/src/Components/Static/StaticProgressBarComponent.php b/packages/console/src/Components/Static/StaticProgressBarComponent.php index 0cdeaf8ce..426899e4a 100644 --- a/packages/console/src/Components/Static/StaticProgressBarComponent.php +++ b/packages/console/src/Components/Static/StaticProgressBarComponent.php @@ -24,7 +24,7 @@ public function render(Console $console): array $count = iterator_count($this->data); $step = 1; - $format = $this->format ?? function (int $step, int $count): string { + $format = $this->format ?? static function (int $step, int $count): string { $width = 30; $progress = (int) round(($step / $count) * $width); diff --git a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php index 8010ad1cd..0da8f6d0a 100644 --- a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php @@ -38,7 +38,7 @@ public function render(Console $console): null|int|UnitEnum|string fn (Option $option, int $index) => str($index) ->when( condition: $option->key === $this->default || $option->value === $this->default, - callback: fn ($s) => $s->wrap('', ''), + callback: static fn ($s) => $s->wrap('', ''), ) ->wrap('[', ']') ->prepend('- ') diff --git a/packages/console/src/Components/Static/StaticTaskComponent.php b/packages/console/src/Components/Static/StaticTaskComponent.php index ff92978aa..7d9313855 100644 --- a/packages/console/src/Components/Static/StaticTaskComponent.php +++ b/packages/console/src/Components/Static/StaticTaskComponent.php @@ -39,7 +39,7 @@ public function render(Console $console): bool private function executeClosureHandler(Closure $handler): bool { try { - return $handler(fn () => null) !== false; + return $handler(static fn () => null) !== false; } catch (Throwable) { return false; } diff --git a/packages/console/src/ConsoleInputBuilder.php b/packages/console/src/ConsoleInputBuilder.php index 2b8f0aad9..6b3df2093 100644 --- a/packages/console/src/ConsoleInputBuilder.php +++ b/packages/console/src/ConsoleInputBuilder.php @@ -59,7 +59,7 @@ public function build(): array } return array_map( - callback: fn (ConsoleInputArgument $argument) => $argument->value, + callback: static fn (ConsoleInputArgument $argument) => $argument->value, array: $validArguments, ); } diff --git a/packages/console/src/Exceptions/ConsoleExceptionHandler.php b/packages/console/src/Exceptions/ConsoleExceptionHandler.php index 3c9d20f9f..0a178e54a 100644 --- a/packages/console/src/Exceptions/ConsoleExceptionHandler.php +++ b/packages/console/src/Exceptions/ConsoleExceptionHandler.php @@ -41,7 +41,7 @@ public function handle(Throwable $throwable): void ->error($throwable::class) ->when( condition: $throwable->getMessage(), - callback: fn (Console $console) => $console->error($throwable->getMessage()), + callback: static fn (Console $console) => $console->error($throwable->getMessage()), ) ->writeln() ->writeln('In ' . $this->formatFileWithLine($throwable->getFile() . ':' . $throwable->getLine())) @@ -81,7 +81,7 @@ private function getSnippet(string $file, int $lineNumber): string $lines = explode(PHP_EOL, $code); $lines[$lineNumber - 1] = str($lines[$lineNumber - 1]) - ->replaceRegex('/^\d+/', fn (array $match) => "{$match[0]}") + ->replaceRegex('/^\d+/', static fn (array $match) => "{$match[0]}") ->append(' <<<') ->toString(); diff --git a/packages/console/src/Exceptions/InvalidCommandException.php b/packages/console/src/Exceptions/InvalidCommandException.php index cff1141f9..709ea01f2 100644 --- a/packages/console/src/Exceptions/InvalidCommandException.php +++ b/packages/console/src/Exceptions/InvalidCommandException.php @@ -20,7 +20,7 @@ public function __construct( public function render(Console $console): void { $missingArguments = implode(', ', array_map( - fn (ConsoleArgumentDefinition $argumentDefinition) => $argumentDefinition->name, + static fn (ConsoleArgumentDefinition $argumentDefinition) => $argumentDefinition->name, $this->invalidArguments, )); diff --git a/packages/console/src/Exceptions/InvalidEnumArgument.php b/packages/console/src/Exceptions/InvalidEnumArgument.php index 7c6a04f87..8b998e8a5 100644 --- a/packages/console/src/Exceptions/InvalidEnumArgument.php +++ b/packages/console/src/Exceptions/InvalidEnumArgument.php @@ -32,7 +32,7 @@ public function render(Console $console): void } $cases = array_map( - callback: fn (BackedEnum $case) => $case->value, + callback: static fn (BackedEnum $case) => $case->value, array: $this->argumentType::cases(), ); diff --git a/packages/console/src/Exceptions/UnknownArgumentsException.php b/packages/console/src/Exceptions/UnknownArgumentsException.php index 1d2beb269..03f0a710a 100644 --- a/packages/console/src/Exceptions/UnknownArgumentsException.php +++ b/packages/console/src/Exceptions/UnknownArgumentsException.php @@ -20,7 +20,7 @@ public function render(Console $console): void $console->error(sprintf( 'Unknown arguments: %s', $this->invalidArguments - ->map(fn (ConsoleInputArgument $argument) => sprintf( + ->map(static fn (ConsoleInputArgument $argument) => sprintf( '%s', $argument->name, )) diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php index cbaae269b..07706f574 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php @@ -21,7 +21,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio $content = preg_replace_callback( subject: $content, pattern: $pattern, - callback: function ($matches) use ($highlighter) { + callback: static function ($matches) use ($highlighter) { $theme = $highlighter->getTheme(); $quote = $matches['quote']; $match = $matches['match']; diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php index b455eb5d3..4a84427af 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php @@ -20,7 +20,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio return new ParsedInjection(preg_replace_callback( subject: $content, pattern: '/(?\[\"\'])(?.+)\k\s*\/?>)/', - callback: function (array $matches) { + callback: static function (array $matches) { $href = $matches['file']; $exists = Filesystem\normalize_path($href) !== null; $file = $exists diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php index cc5d3a47f..f62b597f5 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php @@ -17,7 +17,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio return new ParsedInjection(preg_replace_callback( subject: $content, pattern: '/(?\[\"\'])(?.+)\k\>(?:(?!\)/', - callback: function (array $matches) { + callback: static function (array $matches) { $quote = $matches['quote']; $match = $matches['match']; $href = $matches['href']; diff --git a/packages/console/src/Highlight/TempestTerminalTheme.php b/packages/console/src/Highlight/TempestTerminalTheme.php index 1d8c4666e..a4ae82577 100644 --- a/packages/console/src/Highlight/TempestTerminalTheme.php +++ b/packages/console/src/Highlight/TempestTerminalTheme.php @@ -55,7 +55,7 @@ private function style(TerminalStyle ...$styles): string return implode( '', array_map( - fn (TerminalStyle $style) => TerminalStyle::ESC->value . $style->value, + static fn (TerminalStyle $style) => TerminalStyle::ESC->value . $style->value, $styles, ), ); diff --git a/packages/console/src/Initializers/ConsoleApplicationInitializer.php b/packages/console/src/Initializers/ConsoleApplicationInitializer.php index 6fd620ee5..caa6367e8 100644 --- a/packages/console/src/Initializers/ConsoleApplicationInitializer.php +++ b/packages/console/src/Initializers/ConsoleApplicationInitializer.php @@ -21,7 +21,7 @@ public function initialize(Container $container): ConsoleApplication argumentBag: $container->get(ConsoleArgumentBag::class), ); - $container->singleton(Application::class, fn () => $application); + $container->singleton(Application::class, static fn () => $application); return $application; } diff --git a/packages/console/src/Input/ConsoleArgumentBag.php b/packages/console/src/Input/ConsoleArgumentBag.php index 6cb10bbca..b8d396b53 100644 --- a/packages/console/src/Input/ConsoleArgumentBag.php +++ b/packages/console/src/Input/ConsoleArgumentBag.php @@ -117,9 +117,11 @@ public function findArrayFor(ConsoleArgumentDefinition $argumentDefinition): Con $values = []; foreach ($this->arguments as $argument) { - if ($argumentDefinition->matchesArgument($argument)) { - $values[] = $argument->value; + if (! $argumentDefinition->matchesArgument($argument)) { + continue; } + + $values[] = $argument->value; } return new ConsoleInputArgument( @@ -137,13 +139,15 @@ public function findForVariadicArgument(ConsoleArgumentDefinition $argumentDefin $arguments = []; foreach ($this->arguments as $argument) { - if ($argument->position >= $argumentDefinition->position) { - $arguments[] = new ConsoleInputArgument( - name: $argumentDefinition->name, - position: $argument->position, - value: $this->resolveArgumentValue($argumentDefinition, $argument)->value, - ); + if ($argument->position < $argumentDefinition->position) { + continue; } + + $arguments[] = new ConsoleInputArgument( + name: $argumentDefinition->name, + position: $argument->position, + value: $this->resolveArgumentValue($argumentDefinition, $argument)->value, + ); } return $arguments; @@ -173,16 +177,18 @@ public function addMany(array $arguments): self // Otherwise, $arguments is an array of flags or positional argument. foreach ($arguments as $key => $argument) { - if (str_starts_with($argument, '-') && ! str_starts_with($argument, '--')) { - $flags = str_split($argument); - unset($flags[0]); + if (! (str_starts_with($argument, '-') && ! str_starts_with($argument, '--'))) { + continue; + } - foreach ($flags as $flag) { - $arguments[] = "-{$flag}"; - } + $flags = str_split($argument); + unset($flags[0]); - unset($arguments[$key]); + foreach ($flags as $flag) { + $arguments[] = "-{$flag}"; } + + unset($arguments[$key]); } $position = count($this->arguments); diff --git a/packages/console/src/Input/MemoryInputBuffer.php b/packages/console/src/Input/MemoryInputBuffer.php index 63676ce4e..01e6162a5 100644 --- a/packages/console/src/Input/MemoryInputBuffer.php +++ b/packages/console/src/Input/MemoryInputBuffer.php @@ -34,7 +34,7 @@ public function add(int|string|Key ...$input): void implode( separator: ', ', array: array_map( - callback: fn (int|string|Key $i) => is_string($i) + callback: static fn (int|string|Key $i) => is_string($i) ? rtrim($i) : $i->value, array: $input, diff --git a/packages/console/src/Installers/ConsoleInstaller.php b/packages/console/src/Installers/ConsoleInstaller.php index 99c17608e..1adee4a7b 100644 --- a/packages/console/src/Installers/ConsoleInstaller.php +++ b/packages/console/src/Installers/ConsoleInstaller.php @@ -22,7 +22,7 @@ public function install(): void $this->publish( source: __DIR__ . '/tempest', destination: root_path('tempest'), - callback: function (string $_, string $destination): void { + callback: static function (string $_, string $destination): void { if (PHP_OS_FAMILY !== 'Windows') { /** @phpstan-ignore-next-line */ exec("chmod +x {$destination}"); diff --git a/packages/console/src/Middleware/HelpMiddleware.php b/packages/console/src/Middleware/HelpMiddleware.php index fdc1731ea..884b3b760 100644 --- a/packages/console/src/Middleware/HelpMiddleware.php +++ b/packages/console/src/Middleware/HelpMiddleware.php @@ -55,9 +55,9 @@ private function renderHelp(ConsoleCommand $consoleCommand): void $this->console ->writeln() ->write("{$argumentDefinition->name}") - ->when($argumentDefinition->aliases !== [], fn (Console $console) => $console->write(' (' . implode(', ', $argumentDefinition->aliases) . ')')) - ->when($argumentDefinition->description, fn (Console $console) => $console->writeln()->writeln($argumentDefinition->description)) - ->when($argumentDefinition->help, fn (Console $console) => $console->writeln()->writeln('' . $argumentDefinition->help . '')); + ->when($argumentDefinition->aliases !== [], static fn (Console $console) => $console->write(' (' . implode(', ', $argumentDefinition->aliases) . ')')) + ->when($argumentDefinition->description, static fn (Console $console) => $console->writeln()->writeln($argumentDefinition->description)) + ->when($argumentDefinition->help, static fn (Console $console) => $console->writeln()->writeln('' . $argumentDefinition->help . '')); } $this->console->writeln(); diff --git a/packages/console/src/Middleware/OverviewMiddleware.php b/packages/console/src/Middleware/OverviewMiddleware.php index f68ce8227..7b9eb94c7 100644 --- a/packages/console/src/Middleware/OverviewMiddleware.php +++ b/packages/console/src/Middleware/OverviewMiddleware.php @@ -73,8 +73,8 @@ private function renderOverview(bool $showHidden = false): void $longestCommandName = max( arr($commands) - ->flatMap(fn (array $group) => $group) - ->map(fn (ConsoleCommand $command) => mb_strlen($command->getName())) + ->flatMap(static fn (array $group) => $group) + ->map(static fn (ConsoleCommand $command) => mb_strlen($command->getName())) ->toArray(), ) + 4; @@ -96,7 +96,7 @@ private function renderOverview(bool $showHidden = false): void $this->console ->unless( condition: $this->discoveryCache->valid, - callback: fn (Console $console) => $console->writeln()->error('Discovery cache invalid. Run discovery:generate to enable discovery caching.'), + callback: static fn (Console $console) => $console->writeln()->error('Discovery cache invalid. Run discovery:generate to enable discovery caching.'), ); } } diff --git a/packages/console/src/Middleware/ResolveOrRescueMiddleware.php b/packages/console/src/Middleware/ResolveOrRescueMiddleware.php index 1f252fc2e..d87d997fc 100644 --- a/packages/console/src/Middleware/ResolveOrRescueMiddleware.php +++ b/packages/console/src/Middleware/ResolveOrRescueMiddleware.php @@ -93,7 +93,7 @@ private function getSimilarCommands(ImmutableString $search): ImmutableArray // `dis:st` will match `discovery:status` if ($searchParts->count() === $currentParts->count()) { - if ($searchParts->every(fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) { + if ($searchParts->every(static fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) { $suggestions[$currentName->toString()] = $currentName; continue; @@ -151,8 +151,8 @@ private function getSimilarCommands(ImmutableString $search): ImmutableArray } return $sorted - ->sortByCallback(fn (array $a, array $b) => $a['levenshtein'] <=> $b['levenshtein']) - ->map(fn (array $item) => $item['suggestion']); + ->sortByCallback(static fn (array $a, array $b) => $a['levenshtein'] <=> $b['levenshtein']) + ->map(static fn (array $item) => $item['suggestion']); } private function runIntendedCommand(Stringable $commandName): ExitCode|int diff --git a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php index c7b4cd143..e56f5d531 100644 --- a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php +++ b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php @@ -24,17 +24,17 @@ public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next } $allowedParameterNames = arr($invocation->consoleCommand->getArgumentDefinitions()) - ->flatMap(function (ConsoleArgumentDefinition $definition) { + ->flatMap(static function (ConsoleArgumentDefinition $definition) { return [$definition->name, ...$definition->aliases]; }) - ->map(function (string $name) { + ->map(static function (string $name) { return ltrim($name, '-'); }); $invalidInput = arr($invocation->argumentBag->arguments) - ->filter(fn (ConsoleInputArgument $argument) => $argument->name !== null) - ->filter(fn (ConsoleInputArgument $argument) => ! $allowedParameterNames->hasValue(ltrim($argument->name, '-'))) - ->filter(fn (ConsoleInputArgument $argument) => ! in_array($argument->name, GlobalFlags::values(), strict: true)); + ->filter(static fn (ConsoleInputArgument $argument) => $argument->name !== null) + ->filter(static fn (ConsoleInputArgument $argument) => ! $allowedParameterNames->hasValue(ltrim($argument->name, '-'))) + ->filter(static fn (ConsoleInputArgument $argument) => ! in_array($argument->name, GlobalFlags::values(), strict: true)); if ($invalidInput->isNotEmpty()) { throw new UnknownArgumentsException( diff --git a/packages/console/src/Output/MemoryOutputBuffer.php b/packages/console/src/Output/MemoryOutputBuffer.php index d7d182497..a92a97767 100644 --- a/packages/console/src/Output/MemoryOutputBuffer.php +++ b/packages/console/src/Output/MemoryOutputBuffer.php @@ -25,7 +25,7 @@ public function getBufferWithFormatting(): array public function getBufferWithoutFormatting(): array { return array_map( - fn (string $line) => preg_replace('/\x1b\[[0-9;]*m/', '', $line), + static fn (string $line) => preg_replace('/\x1b\[[0-9;]*m/', '', $line), $this->buffer, ); } diff --git a/packages/console/src/Output/TailReader.php b/packages/console/src/Output/TailReader.php index 4191a8128..591fa0b32 100644 --- a/packages/console/src/Output/TailReader.php +++ b/packages/console/src/Output/TailReader.php @@ -11,7 +11,7 @@ { public function tail(string $path, ?Closure $format = null): void { - $format ??= fn (string $text) => $text; + $format ??= static fn (string $text) => $text; $handle = fopen($path, 'r'); diff --git a/packages/console/src/Scheduler/GenericScheduler.php b/packages/console/src/Scheduler/GenericScheduler.php index b98c1bec8..fea67c26b 100644 --- a/packages/console/src/Scheduler/GenericScheduler.php +++ b/packages/console/src/Scheduler/GenericScheduler.php @@ -66,7 +66,7 @@ private function getInvocationsToRun(DateTime $date): array $eligibleToRun = array_filter( $this->config->scheduledInvocations, - fn (ScheduledInvocation $invocation) => $invocation->canRunAt( + static fn (ScheduledInvocation $invocation) => $invocation->canRunAt( date: $date, lastRunTimestamp: $previousRuns[$invocation->handler->getName()] ?? null, ), diff --git a/packages/console/src/Stubs/GeneratorCommandStub.php b/packages/console/src/Stubs/GeneratorCommandStub.php index 246fff407..a608f82ee 100644 --- a/packages/console/src/Stubs/GeneratorCommandStub.php +++ b/packages/console/src/Stubs/GeneratorCommandStub.php @@ -30,7 +30,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Terminal/Terminal.php b/packages/console/src/Terminal/Terminal.php index 186b862fd..54627408a 100644 --- a/packages/console/src/Terminal/Terminal.php +++ b/packages/console/src/Terminal/Terminal.php @@ -96,7 +96,7 @@ public function render(InteractiveConsoleComponent $component, array $validation ->render($this); if (! $rendered instanceof Generator) { - $rendered = (function (string $content): Generator { + $rendered = (static function (string $content): Generator { yield $content; return null; @@ -108,7 +108,7 @@ public function render(InteractiveConsoleComponent $component, array $validation if (! $component->getState()->isFinished() && $validationErrors) { $content .= PHP_EOL . arr($validationErrors) - ->map(fn (string $error) => " {$error}") + ->map(static fn (string $error) => " {$error}") ->implode(PHP_EOL) ->append(PHP_EOL) ->toString(); diff --git a/packages/console/src/Testing/ConsoleTester.php b/packages/console/src/Testing/ConsoleTester.php index 088f695c5..aeaed7781 100644 --- a/packages/console/src/Testing/ConsoleTester.php +++ b/packages/console/src/Testing/ConsoleTester.php @@ -78,7 +78,7 @@ public function call(string|Closure|array $command, string|array $arguments = [] $clone->input = $memoryInputBuffer; if ($command instanceof Closure) { - $fiber = new Fiber(function () use ($clone, $command, $console): void { + $fiber = new Fiber(static function () use ($clone, $command, $console): void { $clone->exitCode = $command($console) ?? ExitCode::SUCCESS; }); } else { @@ -107,7 +107,7 @@ public function complete(?string $command = null): self $input = explode(' ', $command); $inputString = implode(' ', array_map( - fn (string $item) => "--input=\"{$item}\"", + static fn (string $item) => "--input=\"{$item}\"", $input, )); } else { diff --git a/packages/console/tests/CompletionHelperPhpTest.php b/packages/console/tests/CompletionHelperPhpTest.php index 4940f6095..1e5965834 100644 --- a/packages/console/tests/CompletionHelperPhpTest.php +++ b/packages/console/tests/CompletionHelperPhpTest.php @@ -228,7 +228,7 @@ private function parseMetadata(array $metadata): CompletionMetadata private function mapCompletions(array $completions): array { return array_map( - fn (CompletionCandidate $completion): array => [ + static fn (CompletionCandidate $completion): array => [ 'value' => $completion->value, 'display' => $completion->display, ], diff --git a/packages/console/tests/OptionCollectionTest.php b/packages/console/tests/OptionCollectionTest.php index 2a4f86da8..fe15cf3c0 100644 --- a/packages/console/tests/OptionCollectionTest.php +++ b/packages/console/tests/OptionCollectionTest.php @@ -31,7 +31,7 @@ public function test_filter(): void $options->filter('ergljherkigjerg'); $this->assertCount(0, $options->getOptions()); - $this->assertSame(null, $options->getActive()); + $this->assertNull($options->getActive()); } public function test_keeps_active_on_filter(): void @@ -50,7 +50,7 @@ public function test_keeps_active_on_filter(): void $this->assertSame('baz', $options->getActive()->value); $options->filter('bazz'); - $this->assertSame(null, $options->getActive()); + $this->assertNull($options->getActive()); } public function test_navigate(): void @@ -168,6 +168,6 @@ public function test_set_active_enum(): void private function toValues(array $options): array { - return array_map(fn (Option $option) => $option->value, array_values($options)); + return array_map(static fn (Option $option) => $option->value, array_values($options)); } } diff --git a/packages/container/src/Commands/MakeInitializerCommand.php b/packages/container/src/Commands/MakeInitializerCommand.php index dff9019d0..e43ad69dc 100644 --- a/packages/container/src/Commands/MakeInitializerCommand.php +++ b/packages/container/src/Commands/MakeInitializerCommand.php @@ -38,7 +38,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - function (ClassManipulator $stubClass) use ($isSingleton) { + static function (ClassManipulator $stubClass) use ($isSingleton) { $stubClass->removeClassAttribute(SkipDiscovery::class); if ($isSingleton) { diff --git a/packages/container/src/Exceptions/CircularDependencyEncountered.php b/packages/container/src/Exceptions/CircularDependencyEncountered.php index d4ed8de8b..6cf5c901f 100644 --- a/packages/container/src/Exceptions/CircularDependencyEncountered.php +++ b/packages/container/src/Exceptions/CircularDependencyEncountered.php @@ -35,7 +35,7 @@ public function __construct(DependencyChain $chain, Dependency $circularDependen $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $circularDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: function ($matches) { + callback: static function ($matches) { return '└' . str_repeat('─', strlen($matches['prefix']) + 3) . str_repeat('▒', strlen($matches['selection'])); }, subject: $chain->last()->getShortName(), diff --git a/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php b/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php index 8a6e33be7..8ac0cefa7 100644 --- a/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php +++ b/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php @@ -34,7 +34,7 @@ public function __construct(DependencyChain $chain, Dependency $brokenDependency $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $brokenDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: function ($matches) { + callback: static function ($matches) { return str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])); }, subject: $chain->last()->getShortName(), diff --git a/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php b/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php index f9541f850..142eec4de 100644 --- a/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php +++ b/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php @@ -47,7 +47,7 @@ public function __construct(DependencyChain $chain, Dependency $brokenDependency $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $brokenDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: function ($matches) { + callback: static function ($matches) { return str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])); }, subject: $chain->last()->getShortName(), diff --git a/packages/container/src/functions.php b/packages/container/src/functions.php index 32eee772b..a58062e56 100644 --- a/packages/container/src/functions.php +++ b/packages/container/src/functions.php @@ -4,7 +4,6 @@ namespace Tempest\Container; -use Tempest\Container\GenericContainer; use Tempest\Reflection\FunctionReflector; use Tempest\Reflection\MethodReflector; diff --git a/packages/container/tests/ContainerTest.php b/packages/container/tests/ContainerTest.php index 1431f0f2a..9edc51d92 100644 --- a/packages/container/tests/ContainerTest.php +++ b/packages/container/tests/ContainerTest.php @@ -89,7 +89,7 @@ public function test_get_with_definition(): void $container->register( ContainerObjectC::class, - fn () => new ContainerObjectC(prop: 'test'), + static fn () => new ContainerObjectC(prop: 'test'), ); $c = $container->get(ContainerObjectC::class); @@ -112,7 +112,7 @@ public function test_singleton(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); $instance = $container->get(SingletonClass::class); @@ -349,18 +349,18 @@ public function test_singleton_on_class(): void public function test_invoke_callable(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); $this->assertEquals('foo', $container->invoke(InvokableClass::class)); $this->assertEquals('foobar', $container->invoke([new InvokableClass(), 'execute'])); $this->assertEquals('bar', $container->invoke(InvokableClassWithParameters::class, param: 'bar')); - $this->assertInstanceOf(ReflectionClass::class, $container->invoke(fn (SingletonClass $class) => new ReflectionClass($class))); + $this->assertInstanceOf(ReflectionClass::class, $container->invoke(static fn (SingletonClass $class) => new ReflectionClass($class))); } public function test_invoke_invokable_class(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); $result = $container->invoke(new ClassReflector(InvokableClassWithDependencies::class), param: 'bar'); @@ -370,10 +370,10 @@ public function test_invoke_invokable_class(): void public function test_call_function_with_parameters(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); $result = $container->invoke( - method: fn (SingletonClass $class, string $prefix) => $prefix . $class::class, + method: static fn (SingletonClass $class, string $prefix) => $prefix . $class::class, prefix: 'My resolved class is ', ); @@ -384,7 +384,7 @@ public function test_call_function_with_dependencies_and_parameters(): void { $container = new GenericContainer(); - $result = $container->invoke(fn (string $param) => $param, param: 'foo'); + $result = $container->invoke(static fn (string $param) => $param, param: 'foo'); $this->assertEquals('foo', $result); } @@ -395,7 +395,7 @@ public function test_call_function_with_unresolvable_parameters(): void $this->expectExceptionMessageMatches('/because string cannot be resolved/'); $container = new GenericContainer(); - $container->invoke(fn (string $param) => $param); + $container->invoke(static fn (string $param) => $param); } public function test_call_invalid_closure(): void @@ -410,9 +410,9 @@ public function test_call_invalid_closure(): void public function test_invoke_closure_with_function(): void { GenericContainer::setInstance($container = new GenericContainer()); - $container->singleton(SingletonClass::class, fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); - $result = Container\invoke(fn (SingletonClass $class) => $class::class); + $result = Container\invoke(static fn (SingletonClass $class) => $class::class); $this->assertEquals(SingletonClass::class, $result); } @@ -448,7 +448,7 @@ public function test_unregister(): void { $container = new GenericContainer(); - $container->register(InterfaceA::class, fn () => new ImplementsInterfaceA()); + $container->register(InterfaceA::class, static fn () => new ImplementsInterfaceA()); $this->assertInstanceOf(ImplementsInterfaceA::class, $container->get(InterfaceA::class)); @@ -500,7 +500,7 @@ public function test_has(): void $this->assertFalse($container->has(InterfaceA::class)); - $container->register(InterfaceA::class, fn () => new ImplementsInterfaceA()); + $container->register(InterfaceA::class, static fn () => new ImplementsInterfaceA()); $this->assertTrue($container->has(InterfaceA::class)); } @@ -570,23 +570,23 @@ public function test_lazy_dependency(): void $delay = 0.01; $counter = 1; - $container->register(SlowDependency::class, function () use ($delay, &$counter) { + $container->register(SlowDependency::class, static function () use ($delay, &$counter) { return new SlowDependency($delay, $counter++); }); // Normal example, this is slow during initialization, fast during use - $instance1 = $this->assertSlowerThan(fn () => $container->get(ClassWithSlowDependency::class), $delay); + $instance1 = $this->assertSlowerThan(static fn () => $container->get(ClassWithSlowDependency::class), $delay); $this->assertInstanceOf(ClassWithSlowDependency::class, $instance1); $this->assertInstanceOf(SlowDependency::class, $instance1->dependency); - $this->assertSame('value1', $this->assertFasterThan(fn () => $instance1->dependency->value, $delay)); + $this->assertSame('value1', $this->assertFasterThan(static fn () => $instance1->dependency->value, $delay)); // Lazy example, this is fast during initialization, slow during (first) use - $instance2 = $this->assertFasterThan(fn () => $container->get(ClassWithLazySlowDependency::class), $delay); + $instance2 = $this->assertFasterThan(static fn () => $container->get(ClassWithLazySlowDependency::class), $delay); $this->assertInstanceOf(ClassWithLazySlowDependency::class, $instance2); $this->assertInstanceOf(SlowDependency::class, $instance2->dependency); - $this->assertSame('value2', $this->assertSlowerThan(fn () => $instance2->dependency->value, $delay)); + $this->assertSame('value2', $this->assertSlowerThan(static fn () => $instance2->dependency->value, $delay)); } public function test_lazy_property_dependency(): void @@ -600,14 +600,14 @@ public function test_lazy_property_dependency(): void $delay = 0.01; $counter = 1; - $container->register(SlowDependency::class, function () use ($delay, &$counter) { + $container->register(SlowDependency::class, static function () use ($delay, &$counter) { return new SlowDependency($delay, $counter++); }); - $instance = $this->assertFasterThan(fn () => $container->get(ClassWithLazySlowPropertyDependency::class), $delay); + $instance = $this->assertFasterThan(static fn () => $container->get(ClassWithLazySlowPropertyDependency::class), $delay); $this->assertInstanceOf(SlowDependency::class, $instance->dependency); - $this->assertSame('value1', $this->assertSlowerThan(fn () => $instance->dependency->value, $delay)); + $this->assertSame('value1', $this->assertSlowerThan(static fn () => $instance->dependency->value, $delay)); } public function test_has_tags_support(): void @@ -646,7 +646,7 @@ public function test_tag_attribute_with_enum(): void public function test_returns_decorated_instance(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); $container->addDecorator(DecoratorClass::class, DecoratedInterface::class); $instance = $container->get(DecoratedInterface::class); @@ -658,7 +658,7 @@ public function test_returns_decorated_instance(): void public function test_returns_multiple_decorated_instance(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); $container->addDecorator(DecoratorClass::class, DecoratedInterface::class); $container->addDecorator(DecoratorSecondClass::class, DecoratedInterface::class); @@ -672,7 +672,7 @@ public function test_returns_multiple_decorated_instance(): void public function test_throws_on_decorator_not_implementing_interface(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); $container->addDecorator(DecoratorInvalid::class, DecoratedInterface::class); $this->expectException(DecoratorDidNotImplementInterface::class); @@ -683,7 +683,7 @@ public function test_throws_on_decorator_not_implementing_interface(): void public function test_returns_decorator_without_constructor(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); $container->addDecorator(DecoratorWithoutConstructor::class, DecoratedInterface::class); $instance = $container->get(DecoratedInterface::class); diff --git a/packages/container/tests/Fixtures/SlowDependency.php b/packages/container/tests/Fixtures/SlowDependency.php index 087c27502..868ab2700 100644 --- a/packages/container/tests/Fixtures/SlowDependency.php +++ b/packages/container/tests/Fixtures/SlowDependency.php @@ -12,7 +12,7 @@ public function __construct(float $delay = 0.1, int $counter = 0) // usleep apparently is buggy on windows... $start = microtime(true); while ((microtime(true) - $start) < $delay) { - usleep(intval($delay * 1000000)); + usleep(intval($delay * 1_000_000)); } $this->value = 'value' . $counter; diff --git a/packages/core/src/Commands/InstallCommand.php b/packages/core/src/Commands/InstallCommand.php index 1b49eea04..f54bd28d3 100644 --- a/packages/core/src/Commands/InstallCommand.php +++ b/packages/core/src/Commands/InstallCommand.php @@ -59,11 +59,11 @@ private function resolveInstaller(?string $search): ?Installer if (! $search) { $search = $this->ask( question: 'Please choose an installer', - options: $installers->mapWithKeys(fn (Installer $installer) => yield $installer::class => $installer->name)->toArray(), + options: $installers->mapWithKeys(static fn (Installer $installer) => yield $installer::class => $installer->name)->toArray(), ); } - return $installers->first(fn (Installer $installer) => $installer::class === $search || $installer->name === $search); + return $installers->first(static fn (Installer $installer) => $installer::class === $search || $installer->name === $search); } } } diff --git a/packages/core/src/Composer.php b/packages/core/src/Composer.php index e3c6917b9..4346ee4c9 100644 --- a/packages/core/src/Composer.php +++ b/packages/core/src/Composer.php @@ -38,17 +38,19 @@ public function load(): self $this->composer = $this->loadComposerFile($this->composerPath); $this->namespaces = arr($this->composer) ->get('autoload.psr-4', default: arr()) - ->map(fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) - ->sortByCallback(fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) + ->map(static fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) + ->sortByCallback(static fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) ->values() ->toArray(); foreach ($this->namespaces as $namespace) { - if (Str\starts_with(Str\ensure_ends_with($namespace->path, '/'), ['app/', 'src/', 'source/', 'lib/'])) { - $this->mainNamespace = $namespace; - - break; + if (! Str\starts_with(Str\ensure_ends_with($namespace->path, '/'), ['app/', 'src/', 'source/', 'lib/'])) { + continue; } + + $this->mainNamespace = $namespace; + + break; } if (! isset($this->mainNamespace) && count($this->namespaces)) { @@ -60,13 +62,13 @@ public function load(): self ...$this->namespaces, ]) ->filter() - ->unique(fn (Psr4Namespace $ns) => $ns->namespace) + ->unique(static fn (Psr4Namespace $ns) => $ns->namespace) ->toArray(); $this->devNamespaces = arr($this->composer) ->get('autoload-dev.psr-4', default: arr()) - ->map(fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) - ->sortByCallback(fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) + ->map(static fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) + ->sortByCallback(static fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) ->values() ->toArray(); diff --git a/packages/core/src/EnvironmentValueWasInvalid.php b/packages/core/src/EnvironmentValueWasInvalid.php index 77fd56a13..fd12a4a0f 100644 --- a/packages/core/src/EnvironmentValueWasInvalid.php +++ b/packages/core/src/EnvironmentValueWasInvalid.php @@ -13,7 +13,7 @@ final class EnvironmentValueWasInvalid extends Exception public function __construct(string $value) { $possibleValues = arr(Environment::cases()) - ->map(fn (Environment $environment) => $environment->value) + ->map(static fn (Environment $environment) => $environment->value) ->join(); parent::__construct("Invalid environment [{$value}]. Possible values are {$possibleValues}."); diff --git a/packages/core/src/EnvironmentVariableValidationFailed.php b/packages/core/src/EnvironmentVariableValidationFailed.php index 696278f1b..634b96e78 100644 --- a/packages/core/src/EnvironmentVariableValidationFailed.php +++ b/packages/core/src/EnvironmentVariableValidationFailed.php @@ -22,7 +22,7 @@ public function __construct( parent::__construct(vsprintf("Environment variable [%s] is not valid:\n- %s", [ $name, arr($failingRules) - ->map(fn (FailingRule $failingRule) => $validator->getErrorMessage($failingRule, $name)) + ->map(static fn (FailingRule $failingRule) => $validator->getErrorMessage($failingRule, $name)) ->implode("\n- ") ->toString(), ])); diff --git a/packages/core/src/Exceptions/ExceptionTester.php b/packages/core/src/Exceptions/ExceptionTester.php index 0290234cd..caff59a4d 100644 --- a/packages/core/src/Exceptions/ExceptionTester.php +++ b/packages/core/src/Exceptions/ExceptionTester.php @@ -87,7 +87,7 @@ public function assertNothingProcessed(): self private function findRecordedProcessings(string|object $exception): array { - return array_filter($this->processor->processed, function (string|object $reported) use ($exception) { + return array_filter($this->processor->processed, static function (string|object $reported) use ($exception) { if ($reported === $exception) { return true; } diff --git a/packages/core/src/FrameworkKernel.php b/packages/core/src/FrameworkKernel.php index 9fb47ddfe..8d1b87d43 100644 --- a/packages/core/src/FrameworkKernel.php +++ b/packages/core/src/FrameworkKernel.php @@ -99,7 +99,7 @@ public function createContainer(): Container GenericContainer::setInstance($container); - $container->singleton(Container::class, fn () => $container); + $container->singleton(Container::class, static fn () => $container); return $container; } @@ -143,7 +143,7 @@ public function registerShutdownFunction(): self // Fix for classes that don't have a proper PSR-4 namespace, // they break discovery with an unrecoverable error, // but you don't know why because PHP simply says "duplicate classname" instead of something reasonable. - register_shutdown_function(function (): void { + register_shutdown_function(static function (): void { $error = error_get_last(); $message = $error['message'] ?? ''; @@ -247,7 +247,7 @@ public function registerExceptionHandler(): self ini_set('display_errors', 'Off'); // @mago-expect lint:no-ini-set set_exception_handler($handler->handle(...)); - set_error_handler(function (int $code, string $message, string $filename, int $line) use ($handler): bool { + set_error_handler(static function (int $code, string $message, string $filename, int $line) use ($handler): bool { $handler->handle(new ErrorException( message: $message, code: $code, diff --git a/packages/core/src/InsightsProviderDiscovery.php b/packages/core/src/InsightsProviderDiscovery.php index f456bf22b..bad000651 100644 --- a/packages/core/src/InsightsProviderDiscovery.php +++ b/packages/core/src/InsightsProviderDiscovery.php @@ -4,7 +4,6 @@ namespace Tempest\Core; -use Tempest\Core\AppConfig; use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; diff --git a/packages/core/src/IsComponentInstaller.php b/packages/core/src/IsComponentInstaller.php index 98883f28a..313509a82 100644 --- a/packages/core/src/IsComponentInstaller.php +++ b/packages/core/src/IsComponentInstaller.php @@ -31,7 +31,7 @@ private function installMainNamespace(): void ->replaceStart(root_path(), '') ->trim('/') ->explode('/') - ->map(fn (string $part) => ucfirst($part)) + ->map(static fn (string $part) => ucfirst($part)) ->implode('\\') ->append('\\') ->toString(); diff --git a/packages/core/src/Kernel/LoadConfig.php b/packages/core/src/Kernel/LoadConfig.php index 6c916f166..5af8d201a 100644 --- a/packages/core/src/Kernel/LoadConfig.php +++ b/packages/core/src/Kernel/LoadConfig.php @@ -60,8 +60,8 @@ public function find(): array $this->environment->isStaging() => ! Str\contains($path, [...$suffixes['testing'], ...$suffixes['development'], ...$suffixes['production']]), default => true, }) - ->sortByCallback(function (string $path1, string $path2) use ($suffixes): int { - $getPriority = fn (string $path): int => match (true) { + ->sortByCallback(static function (string $path1, string $path2) use ($suffixes): int { + $getPriority = static fn (string $path): int => match (true) { Str\contains($path, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) => 0, ! Str\contains($path, root_path()) => 0, Str\contains($path, $suffixes['testing']) => 6, diff --git a/packages/core/src/Kernel/LoadDiscoveryClasses.php b/packages/core/src/Kernel/LoadDiscoveryClasses.php index f6ae0b8cf..178b72382 100644 --- a/packages/core/src/Kernel/LoadDiscoveryClasses.php +++ b/packages/core/src/Kernel/LoadDiscoveryClasses.php @@ -256,9 +256,11 @@ private function discoverPath(string $input, DiscoveryLocation $location, array } foreach ($discoveries as $discovery) { - if ($discovery instanceof DiscoversPath) { - $discovery->discoverPath($location, $input); + if (! $discovery instanceof DiscoversPath) { + continue; } + + $discovery->discoverPath($location, $input); } } diff --git a/packages/core/src/Middleware.php b/packages/core/src/Middleware.php index 1ff506df6..5e0b3445c 100644 --- a/packages/core/src/Middleware.php +++ b/packages/core/src/Middleware.php @@ -64,7 +64,7 @@ public function unwrap(): Generator /** @return self */ private function sort(): self { - uasort($this->middlewareClasses, function (ClassReflector $a, ClassReflector $b): int { + uasort($this->middlewareClasses, static function (ClassReflector $a, ClassReflector $b): int { $priorityA = $a->getAttribute(Priority::class)->priority ?? Priority::NORMAL; $priorityB = $b->getAttribute(Priority::class)->priority ?? Priority::NORMAL; @@ -78,7 +78,7 @@ public function __serialize(): array { return [ 'middlewareClasses' => arr($this->middlewareClasses) - ->map(fn (ClassReflector $class) => $class->getName()) + ->map(static fn (ClassReflector $class) => $class->getName()) ->toArray(), ]; } @@ -86,7 +86,7 @@ public function __serialize(): array public function __unserialize(array $data): void { $this->middlewareClasses = arr($data['middlewareClasses']) - ->map(fn (string $className) => new ClassReflector($className)) + ->map(static fn (string $className) => new ClassReflector($className)) ->toArray(); } } diff --git a/packages/core/src/PublishesFiles.php b/packages/core/src/PublishesFiles.php index 410d5d156..716ece1ff 100644 --- a/packages/core/src/PublishesFiles.php +++ b/packages/core/src/PublishesFiles.php @@ -83,7 +83,7 @@ public function publish(string $source, string $destination, ?Closure $callback targetPath: $destination, shouldOverride: true, manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); @@ -248,14 +248,16 @@ function (string $content) use ($callback) { // PHP will output empty arrays for empty dependencies, // which is invalid and will make package managers crash. foreach (['dependencies', 'devDependencies', 'peerDependencies'] as $key) { - if (isset($json[$key]) && ! $json[$key]) { - unset($json[$key]); + if (! (isset($json[$key]) && ! $json[$key])) { + continue; } + + unset($json[$key]); } $content = preg_replace_callback( '/^ +/m', - fn ($m) => str_repeat($indent, strlen($m[0]) / 4), + static fn ($m) => str_repeat($indent, strlen($m[0]) / 4), Json\encode($json, pretty: true), ); diff --git a/packages/core/src/functions.php b/packages/core/src/functions.php index 3e93e0267..4d64ccfd4 100644 --- a/packages/core/src/functions.php +++ b/packages/core/src/functions.php @@ -6,7 +6,6 @@ use Closure; use Stringable; -use Tempest\Container; use Tempest\Core\Composer; use Tempest\Core\DeferredTasks; use Tempest\Core\EnvironmentVariableValidationFailed; diff --git a/packages/cryptography/tests/TimelockTest.php b/packages/cryptography/tests/TimelockTest.php index 08c073905..aa3ebe7c4 100644 --- a/packages/cryptography/tests/TimelockTest.php +++ b/packages/cryptography/tests/TimelockTest.php @@ -15,7 +15,7 @@ final class TimelockTest extends TestCase public function test_callback_is_executed(): void { $clock = new GenericClock(); - $result = new Timelock($clock)->invoke(fn () => 'hello', Duration::zero()); + $result = new Timelock($clock)->invoke(static fn () => 'hello', Duration::zero()); $this->assertSame('hello', $result); } @@ -26,7 +26,7 @@ public function test_locks_for_duration(): void $start = microtime(true); $timelock = new Timelock($clock); - $timelock->invoke(fn () => null, Duration::milliseconds(100)); + $timelock->invoke(static fn () => null, Duration::milliseconds(100)); $elapsed = microtime(true) - $start; @@ -40,7 +40,7 @@ public function test_return_early(): void $start = microtime(true); $timelock->invoke( - callback: fn (Timelock $lock) => $lock->canReturnEarly = true, + callback: static fn (Timelock $lock) => $lock->canReturnEarly = true, duration: Duration::milliseconds(100), ); $elapsed = microtime(true) - $start; @@ -57,7 +57,7 @@ public function test_throws_exception_after_delay(): void try { $timelock->invoke( - callback: fn () => throw new \RuntimeException('This is an error.'), + callback: static fn () => throw new \RuntimeException('This is an error.'), duration: Duration::milliseconds(100), ); } catch (\RuntimeException) { @@ -74,7 +74,7 @@ public function test_uses_clock_to_sleep(): void $ms = $clock->timestamp()->getMilliseconds(); $timelock->invoke( - callback: fn () => null, + callback: static fn () => null, duration: Duration::milliseconds(300), ); diff --git a/packages/database/src/Builder/ModelInspector.php b/packages/database/src/Builder/ModelInspector.php index d39dab76d..9284c2b60 100644 --- a/packages/database/src/Builder/ModelInspector.php +++ b/packages/database/src/Builder/ModelInspector.php @@ -311,9 +311,11 @@ public function getRelations(): ImmutableArray $relationFields = arr(); foreach ($this->reflector->getPublicProperties() as $property) { - if ($relation = $this->getRelation($property->getName())) { - $relationFields[] = $relation; + if (! ($relation = $this->getRelation($property->getName()))) { + continue; } + + $relationFields[] = $relation; } return $relationFields; @@ -570,7 +572,7 @@ public function getPrimaryKeyProperty(): ?PropertyReflector } $primaryKeys = arr($this->reflector->getProperties()) - ->filter(fn (PropertyReflector $property) => $property->getType()->matches(PrimaryKey::class)); + ->filter(static fn (PropertyReflector $property) => $property->getType()->matches(PrimaryKey::class)); return match ($primaryKeys->count()) { 0 => null, diff --git a/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php index d665ec45e..7b85dc893 100644 --- a/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php @@ -144,7 +144,7 @@ public function build(mixed ...$bindings): Query { if ($this->joins !== []) { $this->count->joins = arr($this->joins) - ->map(fn (JoinStatement|string $join) => $join instanceof JoinStatement ? $join : new JoinStatement($join)); + ->map(static fn (JoinStatement|string $join) => $join instanceof JoinStatement ? $join : new JoinStatement($join)); } return new Query($this->count, [...$this->bindings, ...$bindings])->onDatabase($this->onDatabase); diff --git a/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php b/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php index 30f94d730..50834df42 100644 --- a/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php +++ b/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php @@ -45,7 +45,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat throw new \InvalidArgumentException("{$operator->value} operator requires an array of values"); } - $value = array_map(fn (mixed $value) => match (true) { + $value = array_map(static fn (mixed $value) => match (true) { $value instanceof BackedEnum => $value->value, $value instanceof UnitEnum => $value->name, $value instanceof ArrayAccess => (array) $value, @@ -65,7 +65,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat $sql .= " {$operator->value} ? AND ?"; $bindings = array_map( - fn (DateTimeInterface|string|float|int|Countable $value) => match (true) { + static fn (DateTimeInterface|string|float|int|Countable $value) => match (true) { $value instanceof Countable => count($value), default => $value, }, @@ -99,7 +99,7 @@ private function looksLikeWhereRawStatement(string $statement, array $bindings): return false; } - if (! Str\contains($statement, [' ', ...array_map(fn (WhereOperator $op) => $op->value, WhereOperator::cases())])) { + if (! Str\contains($statement, [' ', ...array_map(static fn (WhereOperator $op) => $op->value, WhereOperator::cases())])) { return false; } diff --git a/packages/database/src/Commands/MakeMigrationCommand.php b/packages/database/src/Commands/MakeMigrationCommand.php index 7e6c09507..eb3d211d0 100644 --- a/packages/database/src/Commands/MakeMigrationCommand.php +++ b/packages/database/src/Commands/MakeMigrationCommand.php @@ -176,7 +176,7 @@ private function generateClassFile(string $name, StubFile $stub, string $classNa $classFileName = str($className) ->when( condition: str($name)->contains(['\\', '/']), - callback: fn ($path) => $path->prepend(str($name)->beforeLast(['\\', '/'])->toString(), '/'), + callback: static fn ($path) => $path->prepend(str($name)->beforeLast(['\\', '/'])->toString(), '/'), ) ->toString(); diff --git a/packages/database/src/DatabaseInitializer.php b/packages/database/src/DatabaseInitializer.php index c7a7fd187..ddf1c1b17 100644 --- a/packages/database/src/DatabaseInitializer.php +++ b/packages/database/src/DatabaseInitializer.php @@ -27,7 +27,7 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con { $container->singleton( className: Connection::class, - definition: function () use ($tag, $container) { + definition: static function () use ($tag, $container) { $config = $container->get(DatabaseConfig::class, $tag); $connection = new PDOConnection($config); diff --git a/packages/database/src/Exceptions/InsertColumnsMismatched.php b/packages/database/src/Exceptions/InsertColumnsMismatched.php index 121c463f9..4f5f00dfb 100644 --- a/packages/database/src/Exceptions/InsertColumnsMismatched.php +++ b/packages/database/src/Exceptions/InsertColumnsMismatched.php @@ -11,8 +11,8 @@ public function __construct( ImmutableArray $expected, ImmutableArray $actual, ) { - $expected = $expected->map(fn ($column) => "`{$column}`")->join(); - $actual = $actual->map(fn ($column) => "`{$column}`")->join(); + $expected = $expected->map(static fn ($column) => "`{$column}`")->join(); + $actual = $actual->map(static fn ($column) => "`{$column}`")->join(); parent::__construct("Expected columns {$expected}; but got {$actual}"); } diff --git a/packages/database/src/IsDatabaseModel.php b/packages/database/src/IsDatabaseModel.php index ebb837d6a..643227fdf 100644 --- a/packages/database/src/IsDatabaseModel.php +++ b/packages/database/src/IsDatabaseModel.php @@ -52,9 +52,7 @@ public function onDatabase(null|string|UnitEnum $databaseTag): self protected static function queryBuilder(): QueryBuilder { /** @var QueryBuilder $query */ - $query = query(self::class); - - return $query; + return query(self::class); } /** @@ -64,9 +62,7 @@ protected static function queryBuilder(): QueryBuilder */ public static function select(): SelectQueryBuilder { - $query = self::queryBuilder()->select(); - - return $query; + return self::queryBuilder()->select(); } /** @@ -209,7 +205,7 @@ public function refresh(): self $loadedRelations = $model ->getRelations() - ->filter(fn (Relation $relation) => $model->isRelationLoaded($relation)); + ->filter(static fn (Relation $relation) => $model->isRelationLoaded($relation)); $primaryKeyProperty = $model->getPrimaryKeyProperty(); $primaryKeyValue = $primaryKeyProperty->getValue($this); @@ -217,7 +213,7 @@ public function refresh(): self $new = self::queryBuilder() ->onDatabase($this->onDatabase) ->select() - ->with(...$loadedRelations->map(fn (Relation $relation) => $relation->name)) + ->with(...$loadedRelations->map(static fn (Relation $relation) => $relation->name)) ->get($primaryKeyValue); foreach ($loadedRelations as $relation) { @@ -252,7 +248,7 @@ public function load(string ...$relations): self ->get($primaryKeyValue, $relations); $fieldsToUpdate = arr($relations) - ->map(fn (string $relation) => str($relation)->before('.')->toString()) + ->map(static fn (string $relation) => str($relation)->before('.')->toString()) ->unique(); foreach ($fieldsToUpdate as $fieldToUpdate) { diff --git a/packages/database/src/Mappers/SelectModelMapper.php b/packages/database/src/Mappers/SelectModelMapper.php index 12d8477d9..adc47cdf3 100644 --- a/packages/database/src/Mappers/SelectModelMapper.php +++ b/packages/database/src/Mappers/SelectModelMapper.php @@ -34,7 +34,7 @@ public function map(mixed $from, mixed $to): array $idField = $model->getQualifiedPrimaryKey(); $parsed = arr($from) - ->groupBy(fn (array $data, int|string $i) => $idField !== null ? $data[$idField] ?? $i : $i) + ->groupBy(static fn (array $data, int|string $i) => $idField !== null ? $data[$idField] ?? $i : $i) ->map(fn (array $rows) => $this->normalizeFields($model, $rows)) ->values(); diff --git a/packages/database/src/Migrations/MigrationManager.php b/packages/database/src/Migrations/MigrationManager.php index bfcabca2a..308e59e62 100644 --- a/packages/database/src/Migrations/MigrationManager.php +++ b/packages/database/src/Migrations/MigrationManager.php @@ -326,8 +326,6 @@ private function getMinifiedSqlFromStatement(?QueryStatement $statement): string $sql = preg_replace('/\/\*[\s\S]*?\*\//', '', $sql); // Remove block comments // Remove blank lines and excessive spaces - $sql = preg_replace('/\s+/', ' ', trim($sql)); - - return $sql; + return preg_replace('/\s+/', ' ', trim($sql)); } } diff --git a/packages/database/src/Migrations/RunnableMigrations.php b/packages/database/src/Migrations/RunnableMigrations.php index c90a8de19..1fabaa706 100644 --- a/packages/database/src/Migrations/RunnableMigrations.php +++ b/packages/database/src/Migrations/RunnableMigrations.php @@ -36,9 +36,11 @@ public function getIterator(): Traversable public function up(): Traversable { foreach ($this->getIterator() as $migration) { - if ($migration instanceof MigratesUp) { - yield $migration; + if (! $migration instanceof MigratesUp) { + continue; } + + yield $migration; } } @@ -48,9 +50,11 @@ public function up(): Traversable public function down(): Traversable { foreach ($this->getIterator() as $migration) { - if ($migration instanceof MigratesDown) { - yield $migration; + if (! $migration instanceof MigratesDown) { + continue; } + + yield $migration; } } } diff --git a/packages/database/src/QueryStatements/AlterTableStatement.php b/packages/database/src/QueryStatements/AlterTableStatement.php index 1ba8b7421..bf9139aa8 100644 --- a/packages/database/src/QueryStatements/AlterTableStatement.php +++ b/packages/database/src/QueryStatements/AlterTableStatement.php @@ -94,8 +94,8 @@ public function compile(DatabaseDialect $dialect): string 'ALTER TABLE %s %s;', new TableDefinition($this->tableName), arr($this->statements) - ->map(fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) - ->filter(fn (ImmutableString $line) => $line->isNotEmpty()) + ->map(static fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) + ->filter(static fn (ImmutableString $line) => $line->isNotEmpty()) ->implode(', ' . PHP_EOL . ' ') ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), diff --git a/packages/database/src/QueryStatements/CompoundStatement.php b/packages/database/src/QueryStatements/CompoundStatement.php index afb75d04f..df088afab 100644 --- a/packages/database/src/QueryStatements/CompoundStatement.php +++ b/packages/database/src/QueryStatements/CompoundStatement.php @@ -22,7 +22,7 @@ public function __construct(QueryStatement ...$statements) public function compile(DatabaseDialect $dialect): string { return arr($this->statements) - ->map(fn (QueryStatement $statement) => $statement->compile($dialect)) + ->map(static fn (QueryStatement $statement) => $statement->compile($dialect)) ->implode(';' . PHP_EOL) ->append(';') ->toString(); diff --git a/packages/database/src/QueryStatements/CountStatement.php b/packages/database/src/QueryStatements/CountStatement.php index 353d1f354..aa170b3a4 100644 --- a/packages/database/src/QueryStatements/CountStatement.php +++ b/packages/database/src/QueryStatements/CountStatement.php @@ -44,8 +44,8 @@ public function compile(DatabaseDialect $dialect): string if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(fn (QueryStatement $where) => $where->compile($dialect)) - ->filter(fn (string $compiled) => $compiled !== '') + ->map(static fn (QueryStatement $where) => $where->compile($dialect)) + ->filter(static fn (string $compiled) => $compiled !== '') ->implode(' '); } diff --git a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php index bf359c437..4f6f38a89 100644 --- a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php @@ -22,9 +22,9 @@ public function __construct( public function compile(DatabaseDialect $dialect): string { $cases = arr($this->enumClass::cases()) - ->map(fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) - ->map(fn (string $value) => str_replace('\\', '\\\\', $value)) - ->map(fn (string $value) => "'{$value}'"); + ->map(static fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) + ->map(static fn (string $value) => str_replace('\\', '\\\\', $value)) + ->map(static fn (string $value) => "'{$value}'"); return match ($dialect) { DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', diff --git a/packages/database/src/QueryStatements/CreateTableStatement.php b/packages/database/src/QueryStatements/CreateTableStatement.php index 3e759a985..28e9b2d6e 100644 --- a/packages/database/src/QueryStatements/CreateTableStatement.php +++ b/packages/database/src/QueryStatements/CreateTableStatement.php @@ -395,7 +395,7 @@ public function raw(string $statement): self public function compile(DatabaseDialect $dialect): string { - $createTable = sprintf( + return sprintf( 'CREATE TABLE %s (%s);', new TableDefinition($this->tableName), arr($this->statements) @@ -407,7 +407,5 @@ public function compile(DatabaseDialect $dialect): string ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), ); - - return $createTable; } } diff --git a/packages/database/src/QueryStatements/DeleteStatement.php b/packages/database/src/QueryStatements/DeleteStatement.php index a8a880a5d..b93e7c321 100644 --- a/packages/database/src/QueryStatements/DeleteStatement.php +++ b/packages/database/src/QueryStatements/DeleteStatement.php @@ -30,8 +30,8 @@ public function compile(DatabaseDialect $dialect): string if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(fn (QueryStatement $where) => $where->compile($dialect)) - ->filter(fn (string $compiled) => $compiled !== '') + ->map(static fn (QueryStatement $where) => $where->compile($dialect)) + ->filter(static fn (string $compiled) => $compiled !== '') ->implode(' '); } diff --git a/packages/database/src/QueryStatements/EnumStatement.php b/packages/database/src/QueryStatements/EnumStatement.php index 29d05bcd8..109310f7b 100644 --- a/packages/database/src/QueryStatements/EnumStatement.php +++ b/packages/database/src/QueryStatements/EnumStatement.php @@ -25,9 +25,9 @@ public function __construct( public function compile(DatabaseDialect $dialect): string { $cases = arr($this->enumClass::cases()) - ->map(fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) - ->map(fn (string $value) => str_replace('\\', '\\\\', $value)) - ->map(fn (string $value) => "'{$value}'"); + ->map(static fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) + ->map(static fn (string $value) => str_replace('\\', '\\\\', $value)) + ->map(static fn (string $value) => "'{$value}'"); if ($this->default !== null) { $defaultValue = $this->default instanceof BackedEnum ? $this->default->value : $this->default->name; diff --git a/packages/database/src/QueryStatements/FieldStatement.php b/packages/database/src/QueryStatements/FieldStatement.php index 9492b1397..5dbc066e2 100644 --- a/packages/database/src/QueryStatements/FieldStatement.php +++ b/packages/database/src/QueryStatements/FieldStatement.php @@ -45,9 +45,9 @@ public function compile(DatabaseDialect $dialect): string } $field = arr(explode('.', $field)) - ->map(fn (string $part) => trim($part, '` ')) + ->map(static fn (string $part) => trim($part, '` ')) ->map( - function (string $part) use ($dialect) { + static function (string $part) use ($dialect) { // Function calls are never wrapped in backticks. if (str_contains($part, '(')) { return $part; diff --git a/packages/database/src/QueryStatements/InsertStatement.php b/packages/database/src/QueryStatements/InsertStatement.php index 8b95d0c6f..cabdb1a48 100644 --- a/packages/database/src/QueryStatements/InsertStatement.php +++ b/packages/database/src/QueryStatements/InsertStatement.php @@ -30,7 +30,7 @@ public function compile(DatabaseDialect $dialect): string $columns = arr($this->entries->first())->keys(); $entryPlaceholders = $this->entries - ->map(function (array|ImmutableArray $row) use ($columns) { + ->map(static function (array|ImmutableArray $row) use ($columns) { $row = arr($row); $rowColumns = $row->keys(); @@ -41,7 +41,7 @@ public function compile(DatabaseDialect $dialect): string return sprintf( '(%s)', - $row->map(fn () => '?')->implode(', '), + $row->map(static fn () => '?')->implode(', '), ); }) ->implode(', '); @@ -55,7 +55,7 @@ public function compile(DatabaseDialect $dialect): string $sql = sprintf( 'INSERT INTO %s (%s) VALUES %s', $this->table, - $columns->map(fn (string $column) => "`{$column}`")->implode(', '), + $columns->map(static fn (string $column) => "`{$column}`")->implode(', '), $entryPlaceholders, ); } diff --git a/packages/database/src/QueryStatements/SelectStatement.php b/packages/database/src/QueryStatements/SelectStatement.php index 926b5afc5..6c294cc98 100644 --- a/packages/database/src/QueryStatements/SelectStatement.php +++ b/packages/database/src/QueryStatements/SelectStatement.php @@ -71,32 +71,32 @@ public function compile(DatabaseDialect $dialect): string if ($this->join->isNotEmpty()) { $query[] = $this->join - ->map(fn (JoinStatement $join) => $join->compile($dialect)) + ->map(static fn (JoinStatement $join) => $join->compile($dialect)) ->implode(' '); } if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) - ->filter(fn (string $compiled) => $compiled !== '') + ->map(static fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) + ->filter(static fn (string $compiled) => $compiled !== '') ->implode(' '); } if ($this->groupBy->isNotEmpty()) { $query[] = 'GROUP BY ' . $this->groupBy - ->map(fn (GroupByStatement $groupBy) => $groupBy->compile($dialect)) + ->map(static fn (GroupByStatement $groupBy) => $groupBy->compile($dialect)) ->implode(', '); } if ($this->having->isNotEmpty()) { $query[] = 'HAVING ' . $this->having - ->map(fn (HavingStatement $having) => $having->compile($dialect)) + ->map(static fn (HavingStatement $having) => $having->compile($dialect)) ->implode(' '); } if ($this->orderBy->isNotEmpty()) { $query[] = 'ORDER BY ' . $this->orderBy - ->map(fn (OrderByStatement $orderBy) => $orderBy->compile($dialect)) + ->map(static fn (OrderByStatement $orderBy) => $orderBy->compile($dialect)) ->implode(', '); } @@ -110,7 +110,7 @@ public function compile(DatabaseDialect $dialect): string if ($this->raw->isNotEmpty()) { $query[] = $this->raw - ->map(fn (RawStatement $raw) => $raw->compile($dialect)) + ->map(static fn (RawStatement $raw) => $raw->compile($dialect)) ->implode(' ') ->toString(); } diff --git a/packages/database/src/QueryStatements/UpdateStatement.php b/packages/database/src/QueryStatements/UpdateStatement.php index 0a46b886d..4811473e2 100644 --- a/packages/database/src/QueryStatements/UpdateStatement.php +++ b/packages/database/src/QueryStatements/UpdateStatement.php @@ -35,13 +35,13 @@ public function compile(DatabaseDialect $dialect): string } $query[] = 'SET ' . $this->values - ->map(fn (mixed $_, mixed $key) => "`{$key}` = ?") + ->map(static fn (mixed $_, mixed $key) => "`{$key}` = ?") ->implode(', '); if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) - ->filter(fn (string $compiled) => $compiled !== '') + ->map(static fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) + ->filter(static fn (string $compiled) => $compiled !== '') ->implode(' '); } diff --git a/packages/database/src/QueryStatements/WhereGroupStatement.php b/packages/database/src/QueryStatements/WhereGroupStatement.php index 2bdc2d95c..3f1a2e5d5 100644 --- a/packages/database/src/QueryStatements/WhereGroupStatement.php +++ b/packages/database/src/QueryStatements/WhereGroupStatement.php @@ -22,8 +22,8 @@ public function compile(DatabaseDialect $dialect): string } $compiled = $this->conditions - ->map(fn (QueryStatement $condition) => $condition->compile($dialect)) - ->filter(fn (string $condition) => $condition !== ''); + ->map(static fn (QueryStatement $condition) => $condition->compile($dialect)) + ->filter(static fn (string $condition) => $condition !== ''); if ($compiled->isEmpty()) { return ''; diff --git a/packages/database/src/Serializers/DataTransferObjectSerializer.php b/packages/database/src/Serializers/DataTransferObjectSerializer.php index a9aacf5f0..2a02e846b 100644 --- a/packages/database/src/Serializers/DataTransferObjectSerializer.php +++ b/packages/database/src/Serializers/DataTransferObjectSerializer.php @@ -99,7 +99,7 @@ private function extractObjectData(object $input): array return Arr\map_with_keys( array: new ClassReflector($input)->getPublicProperties(), - map: fn (PropertyReflector $property) => yield $property->getName() => $property->getValue($input), + map: static fn (PropertyReflector $property) => yield $property->getName() => $property->getValue($input), ); } } diff --git a/packages/database/src/functions.php b/packages/database/src/functions.php index 73c135a17..44e466b43 100644 --- a/packages/database/src/functions.php +++ b/packages/database/src/functions.php @@ -15,9 +15,7 @@ function query(string|object $model): QueryBuilder { /** @var QueryBuilder $query */ - $query = new QueryBuilder($model); - - return $query; + return new QueryBuilder($model); } /** diff --git a/packages/database/tests/Config/DatabaseConfigTest.php b/packages/database/tests/Config/DatabaseConfigTest.php index 02df0a722..08d72ae66 100644 --- a/packages/database/tests/Config/DatabaseConfigTest.php +++ b/packages/database/tests/Config/DatabaseConfigTest.php @@ -22,7 +22,7 @@ final class DatabaseConfigTest extends TestCase { #[DataProvider('provide_database_drivers')] #[Test] - public function driver_has_the_correct_dsn(DatabaseConfig $driver, string $dsn, ?string $username, ?string $password): void + public function driver_has_the_correct_dsn(DatabaseConfig $driver, string $dsn, ?string $username, #[\SensitiveParameter] ?string $password): void { $this->assertSame($dsn, $driver->dsn); $this->assertSame($username, $driver->username); diff --git a/packages/database/tests/GenericDatabaseTest.php b/packages/database/tests/GenericDatabaseTest.php index ead08fdd6..b7f898394 100644 --- a/packages/database/tests/GenericDatabaseTest.php +++ b/packages/database/tests/GenericDatabaseTest.php @@ -37,7 +37,7 @@ public function test_it_executes_transactions(): void new SerializerFactory(new GenericContainer()), ); - $result = $database->withinTransaction(function () { + $result = $database->withinTransaction(static function () { return true; }); @@ -64,7 +64,7 @@ public function test_it_rolls_back_transactions_on_failure(): void new SerializerFactory(new GenericContainer()), ); - $result = $database->withinTransaction(function (): never { + $result = $database->withinTransaction(static function (): never { throw new Exception(); }); diff --git a/packages/datetime/src/SecondsStyle.php b/packages/datetime/src/SecondsStyle.php index ed6bb914a..5b2b82540 100644 --- a/packages/datetime/src/SecondsStyle.php +++ b/packages/datetime/src/SecondsStyle.php @@ -38,7 +38,7 @@ public static function fromTimestamp(Timestamp $timestamp): SecondsStyle return match (true) { $nanoseconds === 0 => static::Seconds, - ($nanoseconds % 1000000) === 0 => static::Milliseconds, + ($nanoseconds % 1_000_000) === 0 => static::Milliseconds, ($nanoseconds % 1000) === 0 => static::Microseconds, default => static::Nanoseconds, }; diff --git a/packages/datetime/src/functions.php b/packages/datetime/src/functions.php index 63233bcf7..b60d23a84 100644 --- a/packages/datetime/src/functions.php +++ b/packages/datetime/src/functions.php @@ -6,14 +6,8 @@ use IntlDateFormatter; use IntlTimeZone; use RuntimeException; -use Tempest\DateTime\DateStyle; use Tempest\DateTime\Exception\OverflowException; use Tempest\DateTime\Exception\ParserException; -use Tempest\DateTime\FormatPattern; -use Tempest\DateTime\SecondsStyle; -use Tempest\DateTime\Timestamp; -use Tempest\DateTime\TimeStyle; -use Tempest\DateTime\Timezone; use Tempest\Intl\Locale; use ValueError; @@ -21,8 +15,6 @@ use function microtime; use function Tempest\Intl\current_locale; -use const Tempest\DateTime\NANOSECONDS_PER_SECOND; - /** * Get the current date and time as a {@see \Tempest\DateTime\DateTime} object. */ diff --git a/packages/datetime/tests/DateTimeTest.php b/packages/datetime/tests/DateTimeTest.php index ba7428573..26f1342e5 100644 --- a/packages/datetime/tests/DateTimeTest.php +++ b/packages/datetime/tests/DateTimeTest.php @@ -242,13 +242,13 @@ public function test_parse_icu(): void $parsed = DateTime::fromPattern('2025-01-01 10:00', pattern: 'yyyy-MM-dd HH:mm'); $this->assertEquals('2025-01-01 10:00', $parsed->format(pattern: 'yyyy-MM-dd HH:mm')); - $this->assertEquals(1735725600, $parsed->getTimestamp()->getSeconds()); + $this->assertEquals(1_735_725_600, $parsed->getTimestamp()->getSeconds()); } public function test_parse_timestamp(): void { - $expected = DateTime::fromTimestamp(1747670452940); - $parsed = DateTime::parse(1747670452940); + $expected = DateTime::fromTimestamp(1_747_670_452_940); + $parsed = DateTime::parse(1_747_670_452_940); $this->assertEquals($expected->getTimestamp(), $parsed->getTimestamp()); $this->assertSame($expected->getTimezone(), $parsed->getTimezone()); @@ -629,7 +629,7 @@ public function test_end_of_day(): void $this->assertSame(23, $new->getHours()); $this->assertSame(59, $new->getMinutes()); $this->assertSame(59, $new->getSeconds()); - $this->assertSame(999999999, $new->getNanoseconds()); + $this->assertSame(999_999_999, $new->getNanoseconds()); } public function test_start_of_week(): void @@ -696,7 +696,7 @@ public function test_convert_time_zone(): void public function test_is_same_year(): void { $date1 = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 12, 0, 0, 0); - $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999999999); + $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); $date3 = DateTime::fromParts(Timezone::default(), 2025, Month::JANUARY, 1, 0, 0, 0, 0); $this->assertTrue($date1->isSameYear($date2)); @@ -707,7 +707,7 @@ public function test_is_same_year(): void public function test_is_same_month(): void { $date1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 1, 12, 0, 0, 0); - $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 29, 23, 59, 59, 999999999); + $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 29, 23, 59, 59, 999_999_999); $date3 = DateTime::fromParts(Timezone::default(), 2024, Month::MARCH, 1, 0, 0, 0, 0); $date4 = DateTime::fromParts(Timezone::default(), 2025, Month::FEBRUARY, 15, 12, 0, 0, 0); @@ -733,7 +733,7 @@ public function test_is_same_week(): void public function test_is_same_day(): void { $morning = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 8, 30, 0, 0); - $evening = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 20, 45, 30, 123456789); + $evening = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 20, 45, 30, 123_456_789); $nextDay = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 8, 30, 0, 0); $this->assertTrue($morning->isSameDay($evening)); @@ -744,7 +744,7 @@ public function test_is_same_day(): void public function test_is_same_hour(): void { $time1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 15, 30, 0); - $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 45, 59, 999999999); + $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 45, 59, 999_999_999); $time3 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 15, 15, 30, 0); $differentDay = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 14, 15, 30, 0); @@ -757,7 +757,7 @@ public function test_is_same_hour(): void public function test_is_same_minute(): void { $time1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 15, 0); - $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 45, 999999999); + $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 45, 999_999_999); $time3 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 31, 15, 0); $differentHour = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 15, 30, 15, 0); @@ -770,7 +770,7 @@ public function test_is_same_minute(): void public function test_is_next_day(): void { $today = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $tomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 15, 30, 45, 123456789); + $tomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 15, 30, 45, 123_456_789); $dayAfterTomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 7, 8, 0, 0, 0); $this->assertTrue($tomorrow->isNextDay($today)); @@ -782,7 +782,7 @@ public function test_is_next_day(): void public function test_is_previous_day(): void { $today = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $yesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 4, 8, 15, 30, 987654321); + $yesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 4, 8, 15, 30, 987_654_321); $dayBeforeYesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 3, 20, 0, 0, 0); $this->assertTrue($yesterday->isPreviousDay($today)); @@ -846,9 +846,9 @@ public function test_is_last_day_of_month(): void public function test_is_first_day_of_year(): void { $newYearsDay = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 0, 0, 0, 0); - $newYearsDayDifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 23, 59, 59, 999999999); + $newYearsDayDifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 23, 59, 59, 999_999_999); $secondDay = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 2, 0, 0, 0, 0); - $december31 = DateTime::fromParts(Timezone::default(), 2023, Month::DECEMBER, 31, 23, 59, 59, 999999999); + $december31 = DateTime::fromParts(Timezone::default(), 2023, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); $this->assertTrue($newYearsDay->isFirstDayOfYear()); $this->assertTrue($newYearsDayDifferentTime->isFirstDayOfYear()); @@ -859,8 +859,8 @@ public function test_is_first_day_of_year(): void public function test_is_last_day_of_year(): void { $december31 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 0, 0, 0, 0); - $december31DifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999999999); - $december30 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 30, 23, 59, 59, 999999999); + $december31DifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); + $december30 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 30, 23, 59, 59, 999_999_999); $january1 = DateTime::fromParts(Timezone::default(), 2025, Month::JANUARY, 1, 0, 0, 0, 0); $this->assertTrue($december31->isLastDayOfYear()); @@ -917,13 +917,13 @@ public function test_time_of_day_methods(): void public function test_time_edge_cases(): void { - $boundary5_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 5, 59, 59, 999999999); + $boundary5_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 5, 59, 59, 999_999_999); $boundary6_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 6, 0, 0, 0); - $boundary11_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 11, 59, 59, 999999999); + $boundary11_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 11, 59, 59, 999_999_999); $boundary12_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $boundary17_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 17, 59, 59, 999999999); + $boundary17_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 17, 59, 59, 999_999_999); $boundary18_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 18, 0, 0, 0); - $boundary21_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 21, 59, 59, 999999999); + $boundary21_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 21, 59, 59, 999_999_999); $boundary22_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 22, 0, 0, 0); $this->assertTrue($boundary5_59->isNight()); diff --git a/packages/datetime/tests/DurationTest.php b/packages/datetime/tests/DurationTest.php index 7d58f9929..348b6a2bc 100644 --- a/packages/datetime/tests/DurationTest.php +++ b/packages/datetime/tests/DurationTest.php @@ -48,13 +48,13 @@ public function test_named_constructors(): void } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 2.777777777777778E-13])] + #[TestWith([0, 0, 0, 1, 2.777_777_777_777_778E-13])] #[TestWith([1, 0, 0, 0, 1.0])] #[TestWith([1, 30, 0, 0, 1.5])] - #[TestWith([2, 15, 30, 0, 2.2583333333333333])] + #[TestWith([2, 15, 30, 0, 2.258_333_333_333_333_3])] #[TestWith([-1, 0, 0, 0, -1.0])] #[TestWith([-1, -30, 0, 0, -1.5])] - #[TestWith([-2, -15, -30, 0, -2.2583333333333333])] + #[TestWith([-2, -15, -30, 0, -2.258_333_333_333_333_3])] public function test_get_total_hours( int $hours, int $minutes, @@ -67,7 +67,7 @@ public function test_get_total_hours( } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 1.6666666666666667E-11])] + #[TestWith([0, 0, 0, 1, 1.666_666_666_666_666_7E-11])] #[TestWith([1, 0, 0, 0, 60.0])] #[TestWith([1, 30, 0, 0, 90.0])] #[TestWith([2, 15, 30, 0, 135.5])] @@ -81,7 +81,7 @@ public function test_get_total_minutes(int $hours, int $minutes, int $seconds, i } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 0.000000001])] + #[TestWith([0, 0, 0, 1, 0.000_000_001])] #[TestWith([1, 0, 0, 0, 3600.0])] #[TestWith([1, 30, 0, 0, 5400.0])] #[TestWith([2, 15, 30, 0, 8130.0])] @@ -95,13 +95,13 @@ public function test_get_total_seconds(int $hours, int $minutes, int $seconds, i } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 0.000001])] - #[TestWith([1, 0, 0, 0, 3600000.0])] - #[TestWith([1, 30, 0, 0, 5400000.0])] - #[TestWith([2, 15, 30, 0, 8130000.0])] - #[TestWith([-1, 0, 0, 0, -3600000.0])] - #[TestWith([-1, -30, 0, 0, -5400000.0])] - #[TestWith([-2, -15, -30, 0, -8130000.0])] + #[TestWith([0, 0, 0, 1, 0.000_001])] + #[TestWith([1, 0, 0, 0, 3_600_000.0])] + #[TestWith([1, 30, 0, 0, 5_400_000.0])] + #[TestWith([2, 15, 30, 0, 8_130_000.0])] + #[TestWith([-1, 0, 0, 0, -3_600_000.0])] + #[TestWith([-1, -30, 0, 0, -5_400_000.0])] + #[TestWith([-2, -15, -30, 0, -8_130_000.0])] public function test_get_total_milliseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMilliseconds): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); @@ -110,12 +110,12 @@ public function test_get_total_milliseconds(int $hours, int $minutes, int $secon #[TestWith([0, 0, 0, 0, 0.0])] #[TestWith([0, 0, 0, 1, 0.001])] - #[TestWith([1, 0, 0, 0, 3600000000.0])] - #[TestWith([1, 30, 0, 0, 5400000000.0])] - #[TestWith([2, 15, 30, 0, 8130000000.0])] - #[TestWith([-1, 0, 0, 0, -3600000000.0])] - #[TestWith([-1, -30, 0, 0, -5400000000.0])] - #[TestWith([-2, -15, -30, 0, -8130000000.0])] + #[TestWith([1, 0, 0, 0, 3_600_000_000.0])] + #[TestWith([1, 30, 0, 0, 5_400_000_000.0])] + #[TestWith([2, 15, 30, 0, 8_130_000_000.0])] + #[TestWith([-1, 0, 0, 0, -3_600_000_000.0])] + #[TestWith([-1, -30, 0, 0, -5_400_000_000.0])] + #[TestWith([-2, -15, -30, 0, -8_130_000_000.0])] public function test_get_total_microseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMicroseconds): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); @@ -144,10 +144,10 @@ public function test_fractions_of_second(): void [0, 0, 1, 42], DateTime\Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts(), ); - $this->assertSame([0, 0, 0, 42000], DateTime\Duration::microseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42000], DateTime\Duration::microseconds(1000042)->getParts()); - $this->assertSame([0, 0, 0, 42000000], DateTime\Duration::milliseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42000000], DateTime\Duration::milliseconds(1042)->getParts()); + $this->assertSame([0, 0, 0, 42_000], DateTime\Duration::microseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42_000], DateTime\Duration::microseconds(1_000_042)->getParts()); + $this->assertSame([0, 0, 0, 42_000_000], DateTime\Duration::milliseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42_000_000], DateTime\Duration::milliseconds(1042)->getParts()); } #[TestWith([0, 0, 0, 0])] @@ -271,15 +271,15 @@ public function test_operations(): void #[TestWith([0, 0, 0, 0, '0 second(s)'])] #[TestWith([0, 0, 0, 42, '0 second(s)'])] #[TestWith([0, 0, 1, 42, '1 second(s)'])] - #[TestWith([0, 0, 1, 20000000, '1.02 second(s)'])] + #[TestWith([0, 0, 1, 20_000_000, '1.02 second(s)'])] #[TestWith([1, 2, 0, 0, '1 hour(s), 2 minute(s)'])] #[TestWith([1, 0, 3, 0, '1 hour(s), 0 minute(s), 3 second(s)'])] #[TestWith([0, 2, 3, 0, '2 minute(s), 3 second(s)'])] #[TestWith([1, 2, 3, 0, '1 hour(s), 2 minute(s), 3 second(s)'])] - #[TestWith([1, 0, 0, 42000000, '1 hour(s), 0 minute(s), 0.042 second(s)'])] + #[TestWith([1, 0, 0, 42_000_000, '1 hour(s), 0 minute(s), 0.042 second(s)'])] #[TestWith([-42, 0, -42, 0, '-42 hour(s), 0 minute(s), -42 second(s)'])] - #[TestWith([-42, 0, -42, -420000000, '-42 hour(s), 0 minute(s), -42.42 second(s)'])] - #[TestWith([0, 0, 0, -420000000, '-0.42 second(s)'])] + #[TestWith([-42, 0, -42, -420_000_000, '-42 hour(s), 0 minute(s), -42.42 second(s)'])] + #[TestWith([0, 0, 0, -420_000_000, '-0.42 second(s)'])] public function test_to_string(int $h, int $m, int $s, int $ns, string $expected): void { $this->assertSame($expected, DateTime\Duration::fromParts($h, $m, $s, $ns)->toString()); @@ -287,7 +287,7 @@ public function test_to_string(int $h, int $m, int $s, int $ns, string $expected public function test_serialization(): void { - $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500000000); + $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500_000_000); $serialized = serialize($timeInterval); $deserialized = unserialize($serialized); @@ -296,10 +296,10 @@ public function test_serialization(): void public function test_json_encoding(): void { - $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500000000); + $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500_000_000); $jsonEncoded = Json\encode($timeInterval); $jsonDecoded = Json\decode($jsonEncoded, associative: true); - $this->assertSame(['hours' => 1, 'minutes' => 30, 'seconds' => 45, 'nanoseconds' => 500000000], $jsonDecoded); + $this->assertSame(['hours' => 1, 'minutes' => 30, 'seconds' => 45, 'nanoseconds' => 500_000_000], $jsonDecoded); } } diff --git a/packages/datetime/tests/SecondsStyleTest.php b/packages/datetime/tests/SecondsStyleTest.php index a0efa3c9f..b2c092dbb 100644 --- a/packages/datetime/tests/SecondsStyleTest.php +++ b/packages/datetime/tests/SecondsStyleTest.php @@ -23,7 +23,7 @@ public static function provide_from_timestamp_data(): array { return [ [SecondsStyle::Seconds, Timestamp::fromParts(0)], - [SecondsStyle::Milliseconds, Timestamp::fromParts(0, 1000000)], + [SecondsStyle::Milliseconds, Timestamp::fromParts(0, 1_000_000)], [SecondsStyle::Microseconds, Timestamp::fromParts(0, 1000)], [SecondsStyle::Nanoseconds, Timestamp::fromParts(0, 1)], ]; diff --git a/packages/datetime/tests/TimestampTest.php b/packages/datetime/tests/TimestampTest.php index 297abff2a..42ba40ed5 100644 --- a/packages/datetime/tests/TimestampTest.php +++ b/packages/datetime/tests/TimestampTest.php @@ -144,50 +144,50 @@ public function test_parse_fails(): void public static function provide_format_parsing_data(): iterable { yield [ - 1711917897, + 1_711_917_897, FormatPattern::FULL_DATE_TIME, Timezone::UTC, Locale::ENGLISH, 'Sunday, March 31, 2024 20:44:57', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::FULL_DATE_TIME, Timezone::ASIA_SHANGHAI, Locale::CHINESE_TRADITIONAL, '星期一, 4月 01, 2024 04:44:57', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::COOKIE, Timezone::AMERICA_NEW_YORK, Locale::ENGLISH_UNITED_STATES, 'Sunday, 31-Mar-2024 16:44:57 EDT', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::HTTP, Timezone::EUROPE_VIENNA, Locale::GERMAN_AUSTRIA, 'So., 31 März 2024 22:44:57 MESZ', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::EMAIL, Timezone::EUROPE_MADRID, Locale::SPANISH_SPAIN, 'dom, 31 mar 2024 22:44:57 GMT+02:00', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::SQL_DATE_TIME, Timezone::AFRICA_TUNIS, Locale::ARABIC_TUNISIA, '2024-03-31 21:44:57', ]; - yield [1711832400, FormatPattern::ISO_ORDINAL_DATE, Timezone::EUROPE_MOSCOW, Locale::RUSSIAN_RUSSIA, '2024-091']; + yield [1_711_832_400, FormatPattern::ISO_ORDINAL_DATE, Timezone::EUROPE_MOSCOW, Locale::RUSSIAN_RUSSIA, '2024-091']; yield [ - 1711917897, + 1_711_917_897, FormatPattern::ISO8601, Timezone::EUROPE_LONDON, Locale::ENGLISH_UNITED_KINGDOM, @@ -444,15 +444,15 @@ public function test_convert_to_timezone(): void public function test_json_serialization(): void { - $serialized = Timestamp::fromParts(1711917232, 12)->jsonSerialize(); + $serialized = Timestamp::fromParts(1_711_917_232, 12)->jsonSerialize(); - $this->assertSame(1711917232, $serialized['seconds']); + $this->assertSame(1_711_917_232, $serialized['seconds']); $this->assertSame(12, $serialized['nanoseconds']); } public function test_to_rfc3999(): void { - $timestamp = Timestamp::fromParts(1711917232, 12); + $timestamp = Timestamp::fromParts(1_711_917_232, 12); $this->assertSame('2024-03-31T20:33:52.12+00:00', $timestamp->toRfc3339()); $this->assertSame('2024-03-31T20:33:52+00:00', $timestamp->toRfc3339(secondsStyle: SecondsStyle::Seconds)); @@ -494,9 +494,9 @@ public function test_temporal_convenience_methods(): void public function test_at_the_same_time_edge_cases(): void { - $timestamp1 = Timestamp::fromParts(1234567890, 123456789); - $timestamp2 = Timestamp::fromParts(1234567890, 123456789); - $timestamp3 = Timestamp::fromParts(1234567890, 123456790); + $timestamp1 = Timestamp::fromParts(1_234_567_890, 123_456_789); + $timestamp2 = Timestamp::fromParts(1_234_567_890, 123_456_789); + $timestamp3 = Timestamp::fromParts(1_234_567_890, 123_456_790); $this->assertTrue($timestamp1->atTheSameTime($timestamp2)); $this->assertFalse($timestamp1->atTheSameTime($timestamp3)); @@ -547,9 +547,9 @@ public function test_between_time_reversed_parameters(): void public function test_nano_precision_temporal_comparisons(): void { - $base = Timestamp::fromParts(1234567890, 0); - $plusOneNano = Timestamp::fromParts(1234567890, 1); - $minusOneNano = Timestamp::fromParts(1234567889, 999999999); + $base = Timestamp::fromParts(1_234_567_890, 0); + $plusOneNano = Timestamp::fromParts(1_234_567_890, 1); + $minusOneNano = Timestamp::fromParts(1_234_567_889, 999_999_999); $this->assertTrue($base->isAfter($minusOneNano)); $this->assertTrue($base->isBefore($plusOneNano)); @@ -592,20 +592,20 @@ public function test_future_past_comprehensive(): void public function test_since_and_between_duration_methods(): void { - $start = Timestamp::fromParts(1000, 500000000); - $end = Timestamp::fromParts(1005, 750000000); + $start = Timestamp::fromParts(1000, 500_000_000); + $end = Timestamp::fromParts(1005, 750_000_000); $duration = $end->since($start); $this->assertSame(5, $duration->getSeconds()); - $this->assertSame(250000000, $duration->getNanoseconds()); + $this->assertSame(250_000_000, $duration->getNanoseconds()); $reverseDuration = $start->since($end); $this->assertSame(-5, $reverseDuration->getSeconds()); - $this->assertSame(-250000000, $reverseDuration->getNanoseconds()); + $this->assertSame(-250_000_000, $reverseDuration->getNanoseconds()); $betweenDuration = $start->between($end); $this->assertSame(-5, $betweenDuration->getSeconds()); - $this->assertSame(-250000000, $betweenDuration->getNanoseconds()); + $this->assertSame(-250_000_000, $betweenDuration->getNanoseconds()); $sameDuration = $start->since($start); $this->assertSame(0, $sameDuration->getSeconds()); @@ -614,8 +614,8 @@ public function test_since_and_between_duration_methods(): void public function test_temporal_comparison_with_large_values(): void { - $large1 = Timestamp::fromParts(9223372036, 999999999); - $large2 = Timestamp::fromParts(9223372036, 999999998); + $large1 = Timestamp::fromParts(9_223_372_036, 999_999_999); + $large2 = Timestamp::fromParts(9_223_372_036, 999_999_998); $this->assertTrue($large1->isAfter($large2)); $this->assertFalse($large1->isBefore($large2)); @@ -626,8 +626,8 @@ public function test_temporal_comparison_with_large_values(): void public function test_temporal_comparison_edge_case_overflow_boundary(): void { - $maxSeconds = Timestamp::fromParts(9223372036854775806, 0); - $nearMax = Timestamp::fromParts(9223372036854775805, 999999999); + $maxSeconds = Timestamp::fromParts(9_223_372_036_854_775_806, 0); + $nearMax = Timestamp::fromParts(9_223_372_036_854_775_805, 999_999_999); $this->assertTrue($maxSeconds->isAfter($nearMax)); $this->assertFalse($maxSeconds->isBefore($nearMax)); diff --git a/packages/datetime/tests/TimezoneTest.php b/packages/datetime/tests/TimezoneTest.php index 526e83a48..73d8ebca1 100644 --- a/packages/datetime/tests/TimezoneTest.php +++ b/packages/datetime/tests/TimezoneTest.php @@ -24,13 +24,13 @@ public function test_default(): void public function test_get_offset(): void { - $temporal = Timestamp::fromParts(seconds: 1716956903); + $temporal = Timestamp::fromParts(seconds: 1_716_956_903); $this->assertSame(3600., Timezone::EUROPE_LONDON->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(-14400., Timezone::AMERICA_NEW_YORK->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(28800., Timezone::ASIA_SHANGHAI->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(12600., Timezone::PLUS_0330->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(-12600., Timezone::MINUS_0330->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(-14_400., Timezone::AMERICA_NEW_YORK->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(28_800., Timezone::ASIA_SHANGHAI->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(12_600., Timezone::PLUS_0330->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(-12_600., Timezone::MINUS_0330->getOffset($temporal)->getTotalSeconds()); $this->assertSame(3600., Timezone::PLUS_0100->getOffset($temporal)->getTotalSeconds()); $this->assertSame(-3600., Timezone::MINUS_0100->getOffset($temporal)->getTotalSeconds()); @@ -45,8 +45,8 @@ public function test_get_offset(): void } #[TestWith([Timezone::EUROPE_LONDON, 0])] - #[TestWith([Timezone::AMERICA_NEW_YORK, -18000])] - #[TestWith([Timezone::ASIA_SHANGHAI, 28800])] + #[TestWith([Timezone::AMERICA_NEW_YORK, -18_000])] + #[TestWith([Timezone::ASIA_SHANGHAI, 28_800])] public function test_raw_offset(Timezone $timezone, int $expected): void { $this->assertSame($expected, (int) $timezone->getRawOffset()->getTotalSeconds()); diff --git a/packages/debug/src/Debug.php b/packages/debug/src/Debug.php index 4899fb2f0..d08f34da2 100644 --- a/packages/debug/src/Debug.php +++ b/packages/debug/src/Debug.php @@ -125,7 +125,7 @@ private function createCliDump(mixed $input): string $cloner = new VarCloner(); $output = ''; - $dumper = new CliDumper(function ($line, $depth) use (&$output): void { + $dumper = new CliDumper(static function ($line, $depth) use (&$output): void { if ($depth < 0) { return; } diff --git a/packages/debug/src/Stacktrace/Frame.php b/packages/debug/src/Stacktrace/Frame.php index 95592f450..381e34e17 100644 --- a/packages/debug/src/Stacktrace/Frame.php +++ b/packages/debug/src/Stacktrace/Frame.php @@ -71,7 +71,7 @@ public static function extractArguments(array $frame): array : new ReflectionFunction(function: $frame['function']); $parameterNames = array_map( - callback: fn (ReflectionParameter $param) => $param->getName(), + callback: static fn (ReflectionParameter $param) => $param->getName(), array: $reflection->getParameters(), ); } catch (\Throwable) { diff --git a/packages/debug/src/Stacktrace/Stacktrace.php b/packages/debug/src/Stacktrace/Stacktrace.php index 16ad4cd00..f00e51369 100644 --- a/packages/debug/src/Stacktrace/Stacktrace.php +++ b/packages/debug/src/Stacktrace/Stacktrace.php @@ -14,7 +14,7 @@ final class Stacktrace public array $applicationFrames { get => array_values(array_filter( array: $this->frames, - callback: fn (Frame $frame) => ! $frame->isVendor, + callback: static fn (Frame $frame) => ! $frame->isVendor, )); } @@ -22,7 +22,7 @@ final class Stacktrace public array $vendorFrames { get => array_values(array_filter( array: $this->frames, - callback: fn (Frame $frame) => $frame->isVendor, + callback: static fn (Frame $frame) => $frame->isVendor, )); } @@ -103,7 +103,7 @@ function: $frame->function, index: 1, ), // and shift the frame index by one for each frame - ...array_map(fn (Frame $frame) => new Frame( + ...array_map(static fn (Frame $frame) => new Frame( line: $frame->line, class: $frame->class, function: $frame->function, diff --git a/packages/debug/tests/StacktraceTest.php b/packages/debug/tests/StacktraceTest.php index 6edf46f7b..5e78c6afd 100644 --- a/packages/debug/tests/StacktraceTest.php +++ b/packages/debug/tests/StacktraceTest.php @@ -213,9 +213,11 @@ public function stacktrace_uses_root_path_for_vendor_detection(): void $this->assertNotEmpty($frames); foreach ($frames as $frame) { - if (str_starts_with($frame->absoluteFile, $rootPath)) { - $this->assertFalse($frame->isVendor); + if (! str_starts_with($frame->absoluteFile, $rootPath)) { + continue; } + + $this->assertFalse($frame->isVendor); } } diff --git a/packages/discovery/src/Commands/MakeDiscoveryCommand.php b/packages/discovery/src/Commands/MakeDiscoveryCommand.php index ddbb81295..e1b5d3944 100644 --- a/packages/discovery/src/Commands/MakeDiscoveryCommand.php +++ b/packages/discovery/src/Commands/MakeDiscoveryCommand.php @@ -35,7 +35,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/discovery/src/DiscoveryItems.php b/packages/discovery/src/DiscoveryItems.php index 8b5e1b30c..4de868ec0 100644 --- a/packages/discovery/src/DiscoveryItems.php +++ b/packages/discovery/src/DiscoveryItems.php @@ -59,7 +59,7 @@ public function onlyVendor(): self { return new self( arr($this->items) - ->filter(fn (array $_, string $path) => str_contains($path, '/vendor/') || str_contains($path, '\\vendor\\')) + ->filter(static fn (array $_, string $path) => str_contains($path, '/vendor/') || str_contains($path, '\\vendor\\')) ->toArray(), ); } diff --git a/packages/event-bus/src/Testing/EventBusTester.php b/packages/event-bus/src/Testing/EventBusTester.php index 668e4651b..17c9e5dd7 100644 --- a/packages/event-bus/src/Testing/EventBusTester.php +++ b/packages/event-bus/src/Testing/EventBusTester.php @@ -106,7 +106,7 @@ public function assertListeningTo(string $event, ?int $count = null): self private function findDispatches(string|object $event): array { - return array_filter($this->fakeEventBus->dispatched, function (string|object $dispatched) use ($event) { + return array_filter($this->fakeEventBus->dispatched, static function (string|object $dispatched) use ($event) { if ($dispatched === $event) { return true; } diff --git a/packages/event-bus/src/functions.php b/packages/event-bus/src/functions.php index 3869d85c1..01a7064ad 100644 --- a/packages/event-bus/src/functions.php +++ b/packages/event-bus/src/functions.php @@ -6,8 +6,6 @@ use Closure; use Tempest\Container; -use Tempest\EventBus\EventBus; -use Tempest\EventBus\EventBusConfig; /** * Dispatches the given `$event`, triggering all associated event listeners. diff --git a/packages/event-bus/tests/EventBusTest.php b/packages/event-bus/tests/EventBusTest.php index f667779a9..0918b2fa2 100644 --- a/packages/event-bus/tests/EventBusTest.php +++ b/packages/event-bus/tests/EventBusTest.php @@ -91,14 +91,14 @@ public function test_middleware_is_only_triggered_once_per_event_dispatch(): voi public function test_closure_based_handlers(): void { $container = new GenericContainer(); - $container->singleton(MyService::class, fn () => new MyService('bar')); + $container->singleton(MyService::class, static fn () => new MyService('bar')); $called = null; $config = new EventBusConfig( handlers: [ ItHappened::class => [ - new CallableEventHandler(ItHappened::class, function (ItHappened $event, MyService $service) use (&$called): void { + new CallableEventHandler(ItHappened::class, static function (ItHappened $event, MyService $service) use (&$called): void { $called = $service->value; }), ], @@ -125,7 +125,7 @@ public function test_closure_based_handlers_using_listen_method(): void $eventBus = new GenericEventBus($container, $config); $hasHappened = false; - $eventBus->listen(function (string $event) use (&$hasHappened): void { + $eventBus->listen(static function (string $event) use (&$hasHappened): void { $hasHappened = true; }, event: 'my-event'); @@ -141,7 +141,7 @@ public function test_closure_based_handlers_using_listen_method_and_first_parame $eventBus = new GenericEventBus($container, $config); $hasHappened = false; - $eventBus->listen(function (ItHappened $event) use (&$hasHappened): void { + $eventBus->listen(static function (ItHappened $event) use (&$hasHappened): void { $hasHappened = true; }); @@ -159,7 +159,7 @@ public function test_closure_based_handlers_using_function(): void $hasHappened = false; - listen(function (string $event) use (&$hasHappened): void { + listen(static function (string $event) use (&$hasHappened): void { $hasHappened = true; }, event: 'my-event'); @@ -199,7 +199,7 @@ public function test_closure_based_handlers_using_listen_method_and_enums(): voi $eventBus = new GenericEventBus($container, $config); $hasHappened = false; - $eventBus->listen(function () use (&$hasHappened): void { + $eventBus->listen(static function () use (&$hasHappened): void { $hasHappened = true; }, EventEnum::TWO); diff --git a/packages/generation/src/Php/ManipulatesPhpClasses.php b/packages/generation/src/Php/ManipulatesPhpClasses.php index c4eeea3e8..fb9e1221f 100644 --- a/packages/generation/src/Php/ManipulatesPhpClasses.php +++ b/packages/generation/src/Php/ManipulatesPhpClasses.php @@ -89,9 +89,11 @@ public function removeClassAttribute(string $attributeName): self $attributes = $this->classType->getAttributes(); foreach ($attributes as $key => $attribute) { - if ($attribute->getName() === $attributeName) { - unset($attributes[$key]); + if ($attribute->getName() !== $attributeName) { + continue; } + + unset($attributes[$key]); } $this->classType->setAttributes($attributes); diff --git a/packages/generation/src/Php/SimplifiesClassNames.php b/packages/generation/src/Php/SimplifiesClassNames.php index 20aff5779..bc7a53756 100644 --- a/packages/generation/src/Php/SimplifiesClassNames.php +++ b/packages/generation/src/Php/SimplifiesClassNames.php @@ -118,7 +118,7 @@ private function simplifyClassNames(PhpFile $file): PhpFile } array_map( - function ($param) use (&$types): void { + static function ($param) use (&$types): void { $types[] = $param->getType(true); }, $class->getProperties(), @@ -136,9 +136,11 @@ function ($param) use (&$types): void { } foreach ($type->getTypes() as $subtype) { - if ($subtype->isClass() && ! $subtype->isClassKeyword()) { - $namespace->addUse((string) $subtype); + if (! ($subtype->isClass() && ! $subtype->isClassKeyword())) { + continue; } + + $namespace->addUse((string) $subtype); } } } @@ -152,7 +154,7 @@ private function extractFqcnFromBody(string $body): array preg_match_all('/(?:\\\\?[A-Za-z_][\w\d_]*\\\\)+[A-Za-z_][\w\d_]*/', $body, $matches); return array_filter(array_unique( - array_map(fn (string $fqcn) => rtrim(ltrim($fqcn, '\\'), ':'), $matches[0]), + array_map(static fn (string $fqcn) => rtrim(ltrim($fqcn, '\\'), ':'), $matches[0]), )); } } diff --git a/packages/generation/src/Php/StubFileGenerator.php b/packages/generation/src/Php/StubFileGenerator.php index 61a7e0fee..991753cf3 100644 --- a/packages/generation/src/Php/StubFileGenerator.php +++ b/packages/generation/src/Php/StubFileGenerator.php @@ -8,7 +8,6 @@ use Tempest\Generation\Php\DataObjects\StubFile; use Tempest\Generation\Php\Exceptions\FileGenerationFailedException; use Tempest\Generation\Php\Exceptions\FileGenerationWasAborted; -use Tempest\Generation\Php\StubFileType; use Tempest\Support\Filesystem; use Tempest\Support\Str\ImmutableString; use Throwable; @@ -66,13 +65,13 @@ public function generateClassFile( continue; } - $classManipulator->manipulate(fn (ImmutableString $code) => $code->replace($placeholder, $replacement)); + $classManipulator->manipulate(static fn (ImmutableString $code) => $code->replace($placeholder, $replacement)); } // Run all manipulations $classManipulator = array_reduce( array: $manipulations, - callback: fn (ClassManipulator $manipulator, Closure $manipulation) => $manipulation($manipulator), + callback: static fn (ClassManipulator $manipulator, Closure $manipulation) => $manipulation($manipulator), initial: $classManipulator, ); @@ -130,7 +129,7 @@ public function generateRawFile( $fileContent = array_reduce( array: $manipulations, initial: $fileContent, - callback: fn (ImmutableString $content, Closure $manipulation) => $manipulation($content), + callback: static fn (ImmutableString $content, Closure $manipulation) => $manipulation($content), ); if (Filesystem\is_file($targetPath) && $shouldOverride) { diff --git a/packages/generation/src/TypeScript/TypeResolverDiscovery.php b/packages/generation/src/TypeScript/TypeResolverDiscovery.php index 1761028c4..eba7c518a 100644 --- a/packages/generation/src/TypeScript/TypeResolverDiscovery.php +++ b/packages/generation/src/TypeScript/TypeResolverDiscovery.php @@ -33,8 +33,8 @@ public function discover(DiscoveryLocation $location, ClassReflector $class): vo public function apply(): void { $this->config->resolvers = arr([...$this->discoveryItems]) - ->sortByCallback(fn (array $a, array $b) => $a[1] <=> $b[1]) - ->map(fn (array $item) => $item[0]) + ->sortByCallback(static fn (array $a, array $b) => $a[1] <=> $b[1]) + ->map(static fn (array $item) => $item[0]) ->toArray(); } } diff --git a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php index 647d0cbf8..a9bf98614 100644 --- a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php +++ b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php @@ -88,24 +88,26 @@ private function collectImports(array $namespaces, TypeScriptOutput $output): ar foreach ($namespaces as $namespace => $definitions) { foreach ($definitions as $definition) { - if ($definition instanceof InterfaceDefinition) { - foreach ($definition->properties as $property) { - if ($property->fqcn === null) { - continue; - } - - $targetNamespace = Str\before_last($property->fqcn, '\\'); + if (! $definition instanceof InterfaceDefinition) { + continue; + } - if (in_array($targetNamespace, $currentNamespaces, strict: true)) { - continue; - } + foreach ($definition->properties as $property) { + if ($property->fqcn === null) { + continue; + } - $typeName = Str\after_last($property->fqcn, '\\'); - $importPath = $this->computeImportPath($namespace, $targetNamespace); - $importKey = "{$importPath}::{$typeName}"; + $targetNamespace = Str\before_last($property->fqcn, '\\'); - $imports[$importKey] ??= "import type { {$typeName} } from '{$importPath}';"; + if (in_array($targetNamespace, $currentNamespaces, strict: true)) { + continue; } + + $typeName = Str\after_last($property->fqcn, '\\'); + $importPath = $this->computeImportPath($namespace, $targetNamespace); + $importKey = "{$importPath}::{$typeName}"; + + $imports[$importKey] ??= "import type { {$typeName} } from '{$importPath}';"; } } } @@ -153,7 +155,7 @@ private function resolveTypeReference(PropertyDefinition $property): string private function namespaceToFilePath(string $namespace): string { $parts = explode('\\', $namespace); - $kebabParts = Arr\map($parts, fn (string $part) => Str\to_kebab_case($part)); + $kebabParts = Arr\map($parts, static fn (string $part) => Str\to_kebab_case($part)); $path = (string) Arr\implode($kebabParts, glue: '/'); return $this->config->directory . '/' . $path . '/index.ts'; @@ -177,7 +179,7 @@ private function computeImportPath(string $sourceNamespace, string $targetNamesp $upLevels = count($sourceParts) - $commonLength; $targetDiff = array_slice($targetParts, $commonLength); - $targetKebab = Arr\map($targetDiff, fn (string $part) => Str\to_kebab_case($part)); + $targetKebab = Arr\map($targetDiff, static fn (string $part) => Str\to_kebab_case($part)); if ($upLevels === 0 && count($targetKebab) === 0) { return './'; @@ -186,8 +188,6 @@ private function computeImportPath(string $sourceNamespace, string $targetNamesp $upPath = $upLevels > 0 ? str_repeat('../', $upLevels) : './'; $downPath = count($targetKebab) > 0 ? (string) Arr\implode($targetKebab, glue: '/') : ''; - $fullPath = rtrim($upPath . $downPath, '/'); - - return $fullPath; + return rtrim($upPath . $downPath, '/'); } } diff --git a/packages/generation/tests/Php/ClassManipulatorTest.php b/packages/generation/tests/Php/ClassManipulatorTest.php index 3c918215a..042d05cce 100644 --- a/packages/generation/tests/Php/ClassManipulatorTest.php +++ b/packages/generation/tests/Php/ClassManipulatorTest.php @@ -165,7 +165,7 @@ public function manipulates_classes(): void $class = new ClassManipulator(WelcomeController::class); $class->setNamespace('App\\Controllers'); $class->setClassName('WelcomeController'); - $class->manipulate(fn (ImmutableString $string) => $string->replace('welcome', 'home')); + $class->manipulate(static fn (ImmutableString $string) => $string->replace('welcome', 'home')); $this->assertMatchesSnapshot($class->print()); } @@ -190,7 +190,7 @@ public function simplifies_method_parameter_attributes(): void public function make_replacements_before_converting_fqcn(): void { $class = new ClassManipulator(ClassWithDummyStringToBeReplacedByFqcn::class); - $class->manipulate(fn (ImmutableString $string) => $string->replace("'fqcn-to-be-replaced'", sprintf('%s::class', DummyFqcn::class))); + $class->manipulate(static fn (ImmutableString $string) => $string->replace("'fqcn-to-be-replaced'", sprintf('%s::class', DummyFqcn::class))); $this->assertMatchesSnapshot($class->print()); } diff --git a/packages/http/src/Input/StdinInputStream.php b/packages/http/src/Input/StdinInputStream.php index 5a5a2871f..64a0b1585 100644 --- a/packages/http/src/Input/StdinInputStream.php +++ b/packages/http/src/Input/StdinInputStream.php @@ -20,7 +20,7 @@ public function parse(): array $inputStreamData = str($input) ->explode('&') - ->mapWithKeys(function (string $item) { + ->mapWithKeys(static function (string $item) { $parts = explode('=', $item, 2); $key = urldecode($parts[0]); diff --git a/packages/http/src/IsResponse.php b/packages/http/src/IsResponse.php index 0eda90fb7..3c7c82108 100644 --- a/packages/http/src/IsResponse.php +++ b/packages/http/src/IsResponse.php @@ -38,7 +38,7 @@ public function getHeader(string $name): ?Header { return array_find( array: $this->headers, - callback: fn (Header $header) => strcasecmp($header->name, $name) === 0, + callback: static fn (Header $header) => strcasecmp($header->name, $name) === 0, ); } diff --git a/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php b/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php index 0dd427855..42d004189 100644 --- a/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php +++ b/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php @@ -43,14 +43,14 @@ public function map(mixed $from, mixed $to): GenericRequest } $headersAsString = array_map( - fn (array $items) => implode(',', $items), + static fn (array $items) => implode(',', $items), $from->getHeaders(), ); parse_str($from->getUri()->getQuery(), $query); $uploads = array_map( - fn (UploadedFileInterface $uploadedFile) => new Upload($uploadedFile), + static fn (UploadedFileInterface $uploadedFile) => new Upload($uploadedFile), $from->getUploadedFiles(), ); diff --git a/packages/http/src/Mappers/RequestToObjectMapper.php b/packages/http/src/Mappers/RequestToObjectMapper.php index e79e482bb..ddd6c9712 100644 --- a/packages/http/src/Mappers/RequestToObjectMapper.php +++ b/packages/http/src/Mappers/RequestToObjectMapper.php @@ -33,8 +33,8 @@ public function map(mixed $from, mixed $to): array|object if (is_a($to, Request::class, true)) { $invalidReservedProperties = arr(new ClassReflector(Request::class)->getProperties()) - ->map(fn (PropertyReflector $property) => $property->getName()) - ->filter(fn (string $property) => array_key_exists($property, $data)); + ->map(static fn (PropertyReflector $property) => $property->getName()) + ->filter(static fn (string $property) => array_key_exists($property, $data)); if ($invalidReservedProperties->isNotEmpty()) { throw new RequestParametersIncludedReservedNames($to, $invalidReservedProperties); diff --git a/packages/http/src/RequestHeaders.php b/packages/http/src/RequestHeaders.php index 9221155fb..a0ee7da05 100644 --- a/packages/http/src/RequestHeaders.php +++ b/packages/http/src/RequestHeaders.php @@ -20,7 +20,7 @@ public static function normalizeFromArray(array $headers): self { return new self(array_combine( array_map(strtolower(...), array_keys($headers)), - array_values(array_map(fn (mixed $value) => Str\parse($value), $headers)), + array_values(array_map(static fn (mixed $value) => Str\parse($value), $headers)), )); } @@ -45,7 +45,7 @@ public function get(string $name, ?string $default = null): ?string { $header = array_find( array: $this->headers, - callback: fn (mixed $_, string $header) => strcasecmp($header, $name) === 0, + callback: static fn (mixed $_, string $header) => strcasecmp($header, $name) === 0, ); return $header ?? $default; diff --git a/packages/http/src/Session/SessionIdResolverInitializer.php b/packages/http/src/Session/SessionIdResolverInitializer.php index 1fb27a9b2..72c9cc2de 100644 --- a/packages/http/src/Session/SessionIdResolverInitializer.php +++ b/packages/http/src/Session/SessionIdResolverInitializer.php @@ -11,7 +11,6 @@ use Tempest\Http\Cookie\CookieManager; use Tempest\Http\Request; use Tempest\Http\Session\Resolvers\CookieSessionIdResolver; -use Tempest\Http\Session\SessionConfig; final readonly class SessionIdResolverInitializer implements Initializer { diff --git a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php index 0d94bb81e..2b9bcb890 100644 --- a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php +++ b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php @@ -145,8 +145,6 @@ private function createServerRequest(string $method, array $body = []): ServerRe } $stream = new Stream('php://temp', 'r+'); - $request = $request->withBody($stream); - - return $request; + return $request->withBody($stream); } } diff --git a/packages/idempotency/tests/IdempotencyMiddlewareTest.php b/packages/idempotency/tests/IdempotencyMiddlewareTest.php index 1abdaf995..89ab200a0 100644 --- a/packages/idempotency/tests/IdempotencyMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotencyMiddlewareTest.php @@ -69,7 +69,7 @@ public function requires_an_idempotency_key_by_default(): void $response = $middleware( new GenericRequest(Method::POST, '/orders', body: ['amount' => 100]), - new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['ok' => true]); @@ -93,7 +93,7 @@ public function replays_the_original_response_for_the_same_key_and_payload(): vo headers: ['Idempotency-Key' => 'order-100'], ); - $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -115,7 +115,7 @@ public function rejects_the_same_key_when_the_payload_changes(): void $middleware = $this->createMiddleware('create'); $calls = 0; - $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -176,7 +176,7 @@ public function scopes_idempotency_keys_per_route_when_a_handler_has_multiple_ro ); $calls = 0; - $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-' . $calls]); @@ -238,7 +238,7 @@ public function isolates_idempotency_keys_per_scope_resolver_identity(): void ); $calls = 0; - $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-' . $calls]); @@ -269,7 +269,7 @@ public function can_skip_key_requirement_for_specific_routes(): void $response = $middleware( new GenericRequest(Method::POST, '/drafts', body: ['draft' => true]), - new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['ok' => true]); @@ -375,7 +375,7 @@ public function replays_a_non_serializable_body_as_fallback_text_instead_of_null headers: ['Idempotency-Key' => 'non-serializable-body'], ); - $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse( @@ -408,7 +408,7 @@ public function replays_a_json_serializable_body(): void headers: ['Idempotency-Key' => 'json-serializable-body'], ); - $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, new SerializableBody('order-1')); @@ -454,14 +454,14 @@ public function takes_over_a_pending_record_owned_by_a_dead_process(): void key: 'stale-order', fingerprint: new RequestFingerprintGenerator()->generate($request), ttlInSeconds: 120, - pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99999999, 'stale-owner'), + pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99_999_999, 'stale-owner'), pendingHeartbeatAt: time(), ); $calls = 0; $response = $middleware( $request, - new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -510,7 +510,7 @@ public function takes_over_a_pending_record_owned_by_another_host_when_the_heart $calls = 0; $response = $middleware( $request, - new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -559,7 +559,7 @@ public function does_not_take_over_a_pending_record_owned_by_another_host_when_t $calls = 0; $response = $middleware( $request, - new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index e0bf1d171..1eadacc79 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -42,7 +42,7 @@ public function ignores_commands_without_idempotent_attribute(): void $calls = 0; $command = new CreateDraftCommand('A'); - $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }); @@ -67,7 +67,7 @@ public function supports_idempotent_attribute_on_handler_method(): void $calls = 0; $command = new SyncInventoryCommand(warehouse: 'east', sku: 'WIDGET-1'); - $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }); @@ -84,7 +84,7 @@ public function executes_an_idempotent_command_only_once_for_equal_payloads(): v $calls = 0; $command = new ImportInvoicesCommand(tenant: 'acme', month: '2026-01'); - $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }); @@ -100,7 +100,7 @@ public function throws_when_the_same_explicit_key_is_used_for_different_payloads $middleware = $this->createMiddleware(); $calls = 0; - $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }); @@ -118,7 +118,7 @@ public function allows_replay_for_same_explicit_key_and_same_payload(): void $calls = 0; $command = new CreatePayoutCommand('payout-1', 100); - $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }); @@ -181,14 +181,14 @@ public function takes_over_a_pending_record_owned_by_a_dead_process(): void key: $fingerprint, fingerprint: $fingerprint, ttlInSeconds: 120, - pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99999999, 'stale-owner'), + pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99_999_999, 'stale-owner'), pendingHeartbeatAt: time(), ); $calls = 0; $middleware( $command, - new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }), ); @@ -229,7 +229,7 @@ public function takes_over_a_pending_record_owned_by_another_host_when_the_heart $calls = 0; $middleware( $command, - new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }), ); @@ -270,7 +270,7 @@ public function does_not_take_over_a_pending_record_owned_by_another_host_when_t $calls = 0; $middleware( $command, - new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { + new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { $calls++; }), ); diff --git a/packages/intl/src/GenericTranslator.php b/packages/intl/src/GenericTranslator.php index 338f5eb85..76a8f25c5 100644 --- a/packages/intl/src/GenericTranslator.php +++ b/packages/intl/src/GenericTranslator.php @@ -4,8 +4,6 @@ use Tempest\EventBus\EventBus; use Tempest\Intl\Catalog\Catalog; -use Tempest\Intl\IntlConfig; -use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; final readonly class GenericTranslator implements Translator diff --git a/packages/intl/src/IntlConfig.php b/packages/intl/src/IntlConfig.php index 2d141be77..d7e4ad2e9 100644 --- a/packages/intl/src/IntlConfig.php +++ b/packages/intl/src/IntlConfig.php @@ -2,7 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\FormattingFunction; use Tempest\Intl\MessageFormat\MarkupFormatter; use Tempest\Intl\MessageFormat\SelectorFunction; diff --git a/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php b/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php index c0acb0f83..f42f2abc0 100644 --- a/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php +++ b/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php @@ -375,8 +375,8 @@ private function getMarkupFormatter(?string $tag): ?MarkupFormatter } return arr($this->markupFormatters) - ->filter(fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof MarkupFormatter) - ->first(fn (MarkupFormatter $fn) => $fn->supportsTag($tag)); + ->filter(static fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof MarkupFormatter) + ->first(static fn (MarkupFormatter $fn) => $fn->supportsTag($tag)); } private function getStandaloneMarkupFormatter(?string $tag): ?StandaloneMarkupFormatter @@ -386,8 +386,8 @@ private function getStandaloneMarkupFormatter(?string $tag): ?StandaloneMarkupFo } return arr($this->markupFormatters) - ->filter(fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof StandaloneMarkupFormatter) - ->first(fn (StandaloneMarkupFormatter $fn) => $fn->supportsTag($tag)); + ->filter(static fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof StandaloneMarkupFormatter) + ->first(static fn (StandaloneMarkupFormatter $fn) => $fn->supportsTag($tag)); } private function getSelectorFunction(?string $name): ?SelectorFunction @@ -397,8 +397,8 @@ private function getSelectorFunction(?string $name): ?SelectorFunction } return arr($this->functions) - ->filter(fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof SelectorFunction) - ->first(fn (SelectorFunction $fn) => $fn->name === $name); + ->filter(static fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof SelectorFunction) + ->first(static fn (SelectorFunction $fn) => $fn->name === $name); } private function getFormattingFunction(?string $name): ?FormattingFunction @@ -408,7 +408,7 @@ private function getFormattingFunction(?string $name): ?FormattingFunction } return arr($this->functions) - ->filter(fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof FormattingFunction) - ->first(fn (FormattingFunction $fn) => $fn->name === $name); + ->filter(static fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof FormattingFunction) + ->first(static fn (FormattingFunction $fn) => $fn->name === $name); } } diff --git a/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php b/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php index 95f288065..6f6ee0ef9 100644 --- a/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php +++ b/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php @@ -129,7 +129,7 @@ private function parseInputDeclaration(): InputDeclaration $optional = (bool) array_find( array: $expression->function->options ?? [], - callback: fn (Option $option) => $option->identifier->name === 'default', + callback: static fn (Option $option) => $option->identifier->name === 'default', ); return new InputDeclaration($expression, $optional); diff --git a/packages/intl/src/PluralRules/PluralRulesMatcher.php b/packages/intl/src/PluralRules/PluralRulesMatcher.php index eb89ced57..3ed30faa4 100644 --- a/packages/intl/src/PluralRules/PluralRulesMatcher.php +++ b/packages/intl/src/PluralRules/PluralRulesMatcher.php @@ -57,7 +57,7 @@ private static function getCompactExponent(float|int $n): int $abs = abs($n); - if ($abs >= 1000000) { + if ($abs >= 1_000_000) { return 6; } @@ -518,7 +518,7 @@ private static function getPluralCategoryBr(float|int $n): string return 'few'; } - if (! self::isEqual($n, 0) && self::isEqual($n % 1000000, 0)) { + if (! self::isEqual($n, 0) && self::isEqual($n % 1_000_000, 0)) { return 'many'; } @@ -580,7 +580,7 @@ private static function getPluralCategoryCa(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -980,7 +980,7 @@ private static function getPluralCategoryEs(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -1132,7 +1132,7 @@ private static function getPluralCategoryFr(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -1639,7 +1639,7 @@ private static function getPluralCategoryIt(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -2098,8 +2098,8 @@ private static function getPluralCategoryKw(float|int $n): string || self::isEqual($n % 100, 62) || self::isEqual($n % 100, 82) || self::isEqual($n % 1000, 0) - && (self::inRange($n % 100000, 1000, 20000) || self::isEqual($n % 100000, 40000) || self::isEqual($n % 100000, 60000) || self::isEqual($n % 100000, 80000)) - || self::isEqual($n % 1000000, 100000) + && (self::inRange($n % 100_000, 1000, 20_000) || self::isEqual($n % 100_000, 40_000) || self::isEqual($n % 100_000, 60_000) || self::isEqual($n % 100_000, 80_000)) + || self::isEqual($n % 1_000_000, 100_000) ) { return 'two'; } @@ -2238,7 +2238,7 @@ private static function getPluralCategoryLld(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -2998,7 +2998,7 @@ private static function getPluralCategoryPt(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -3020,7 +3020,7 @@ private static function getPluralCategoryPt_PT(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -3216,7 +3216,7 @@ private static function getPluralCategoryScn(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -4150,7 +4150,7 @@ private static function getPluralCategoryVec(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } diff --git a/packages/intl/src/TranslationFailure.php b/packages/intl/src/TranslationFailure.php index 810e7a8cc..b7b8b570f 100644 --- a/packages/intl/src/TranslationFailure.php +++ b/packages/intl/src/TranslationFailure.php @@ -2,8 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; - final readonly class TranslationFailure { public function __construct( diff --git a/packages/intl/src/TranslationMessageDiscovery.php b/packages/intl/src/TranslationMessageDiscovery.php index 9f3a88466..e3ef0af76 100644 --- a/packages/intl/src/TranslationMessageDiscovery.php +++ b/packages/intl/src/TranslationMessageDiscovery.php @@ -8,7 +8,6 @@ use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; -use Tempest\Intl\Locale; use Tempest\Reflection\ClassReflector; use function Tempest\Support\arr; @@ -55,7 +54,7 @@ public function apply(): void private function isLocale(string $candidate): bool { $locale = arr(Locale::cases()) - ->first(function (Locale $locale) use ($candidate) { + ->first(static function (Locale $locale) use ($candidate) { if (strtolower($locale->value) === strtolower($candidate)) { return true; } diff --git a/packages/intl/src/TranslationMiss.php b/packages/intl/src/TranslationMiss.php index 394a1647d..fe86fead2 100644 --- a/packages/intl/src/TranslationMiss.php +++ b/packages/intl/src/TranslationMiss.php @@ -2,8 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; - final readonly class TranslationMiss { public function __construct( diff --git a/packages/intl/src/Translator.php b/packages/intl/src/Translator.php index def5ead83..e4e25c316 100644 --- a/packages/intl/src/Translator.php +++ b/packages/intl/src/Translator.php @@ -2,8 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; - interface Translator { /** diff --git a/packages/intl/src/TranslatorInitializer.php b/packages/intl/src/TranslatorInitializer.php index 477b7a77d..4f1a1cbbe 100644 --- a/packages/intl/src/TranslatorInitializer.php +++ b/packages/intl/src/TranslatorInitializer.php @@ -7,7 +7,6 @@ use Tempest\Container\Singleton; use Tempest\EventBus\EventBus; use Tempest\Intl\Catalog\Catalog; -use Tempest\Intl\IntlConfig; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; final class TranslatorInitializer implements Initializer diff --git a/packages/intl/src/functions.php b/packages/intl/src/functions.php index 768d7ce0d..ac45bd815 100644 --- a/packages/intl/src/functions.php +++ b/packages/intl/src/functions.php @@ -5,9 +5,7 @@ use Countable; use Stringable; use Tempest\Container\GenericContainer; -use Tempest\Intl\Locale; use Tempest\Intl\Pluralizer\Pluralizer; -use Tempest\Intl\Translator; use function Tempest\Container\get; diff --git a/packages/intl/tests/FunctionsTest.php b/packages/intl/tests/FunctionsTest.php index 3d3c1914d..1bce00620 100644 --- a/packages/intl/tests/FunctionsTest.php +++ b/packages/intl/tests/FunctionsTest.php @@ -21,12 +21,12 @@ public function test_format_number(): void $this->assertSame('10', Number\format(10)); $this->assertSame('25', Number\format(25)); $this->assertSame('100', Number\format(100)); - $this->assertSame('100,000', Number\format(100000)); - $this->assertSame('100,000.00', Number\format(100000, precision: 2)); - $this->assertSame('100,000.12', Number\format(100000.123, precision: 2)); - $this->assertSame('100,000.123', Number\format(100000.1234, maxPrecision: 3)); - $this->assertSame('100,000.124', Number\format(100000.1236, maxPrecision: 3)); - $this->assertSame('123,456,789', Number\format(123456789)); + $this->assertSame('100,000', Number\format(100_000)); + $this->assertSame('100,000.00', Number\format(100_000, precision: 2)); + $this->assertSame('100,000.12', Number\format(100_000.123, precision: 2)); + $this->assertSame('100,000.123', Number\format(100_000.123_4, maxPrecision: 3)); + $this->assertSame('100,000.124', Number\format(100_000.123_6, maxPrecision: 3)); + $this->assertSame('123,456,789', Number\format(123_456_789)); $this->assertSame('-1', Number\format(-1)); $this->assertSame('-10', Number\format(-10)); @@ -77,8 +77,8 @@ public function test_spellout_with_threshold(): void $this->assertSame('10', Number\spell_out(10, until: 10)); $this->assertSame('11', Number\spell_out(11, until: 10)); - $this->assertSame('ten thousand', Number\spell_out(10000, until: 50000)); - $this->assertSame('100,000', Number\spell_out(100000, until: 50000)); + $this->assertSame('ten thousand', Number\spell_out(10_000, until: 50_000)); + $this->assertSame('100,000', Number\spell_out(100_000, until: 50_000)); } #[RequiresPhpExtension('intl')] @@ -114,10 +114,10 @@ public function test_to_percent(): void $this->assertSame('2%', Number\to_percentage(1.75)); $this->assertSame('1.75%', Number\to_percentage(1.75, precision: 2)); $this->assertSame('1.750%', Number\to_percentage(1.75, precision: 3)); - $this->assertSame('0%', Number\to_percentage(0.12345)); + $this->assertSame('0%', Number\to_percentage(0.123_45)); $this->assertSame('0.00%', Number\to_percentage(0, precision: 2)); - $this->assertSame('0.12%', Number\to_percentage(0.12345, precision: 2)); - $this->assertSame('0.1235%', Number\to_percentage(0.12345, precision: 4)); + $this->assertSame('0.12%', Number\to_percentage(0.123_45, precision: 2)); + $this->assertSame('0.1235%', Number\to_percentage(0.123_45, precision: 4)); } #[RequiresPhpExtension('intl')] @@ -147,8 +147,8 @@ public function test_to_currency_with_different_locale(): void $this->assertSame('1,00 $', Number\currency(1, Currency::USD, Locale::GERMAN)); $this->assertSame('1,00 £', Number\currency(1, Currency::GBP, Locale::GERMAN)); - $this->assertSame('123.456.789,12 $', Number\currency(123456789.12345, Currency::USD, Locale::GERMAN)); - $this->assertSame('123.456.789,12 €', Number\currency(123456789.12345, Currency::EUR, Locale::GERMAN)); + $this->assertSame('123.456.789,12 $', Number\currency(123_456_789.123_45, Currency::USD, Locale::GERMAN)); + $this->assertSame('123.456.789,12 €', Number\currency(123_456_789.123_45, Currency::EUR, Locale::GERMAN)); $this->assertSame('1 234,56 $US', Number\currency(1234.56, Currency::USD, Locale::FRENCH)); } @@ -180,7 +180,7 @@ public function test_bytes_to_human(): void $this->assertSame('2 KiB', Number\to_file_size(2048, useBinaryPrefix: true)); $this->assertSame('2.00 KiB', Number\to_file_size(2048, precision: 2, useBinaryPrefix: true)); $this->assertSame('1.23 KiB', Number\to_file_size(1264, precision: 2, useBinaryPrefix: true)); - $this->assertSame('1.234 KiB', Number\to_file_size(1264.12345, maxPrecision: 3, useBinaryPrefix: true)); + $this->assertSame('1.234 KiB', Number\to_file_size(1_264.123_45, maxPrecision: 3, useBinaryPrefix: true)); $this->assertSame('1.234 KiB', Number\to_file_size(1264, 3, useBinaryPrefix: true)); $this->assertSame('5 GiB', Number\to_file_size(1024 * 1024 * 1024 * 5, useBinaryPrefix: true)); $this->assertSame('10 TiB', Number\to_file_size((1024 ** 4) * 10, useBinaryPrefix: true)); @@ -204,31 +204,31 @@ public function test_summarize(): void $this->assertSame('1K', Number\to_human_readable(1000, maxPrecision: 2)); $this->assertSame('1K', Number\to_human_readable(1230)); $this->assertSame('1.2K', Number\to_human_readable(1230, maxPrecision: 1)); - $this->assertSame('1M', Number\to_human_readable(1000000)); - $this->assertSame('1B', Number\to_human_readable(1000000000)); - $this->assertSame('1T', Number\to_human_readable(1000000000000)); - $this->assertSame('1Q', Number\to_human_readable(1000000000000000)); - $this->assertSame('1KQ', Number\to_human_readable(1000000000000000000)); + $this->assertSame('1M', Number\to_human_readable(1_000_000)); + $this->assertSame('1B', Number\to_human_readable(1_000_000_000)); + $this->assertSame('1T', Number\to_human_readable(1_000_000_000_000)); + $this->assertSame('1Q', Number\to_human_readable(1_000_000_000_000_000)); + $this->assertSame('1KQ', Number\to_human_readable(1_000_000_000_000_000_000)); $this->assertSame('123', Number\to_human_readable(123)); $this->assertSame('1K', Number\to_human_readable(1234)); $this->assertSame('1.23K', Number\to_human_readable(1234, precision: 2)); - $this->assertSame('12K', Number\to_human_readable(12345)); - $this->assertSame('1M', Number\to_human_readable(1234567)); - $this->assertSame('1B', Number\to_human_readable(1234567890)); - $this->assertSame('1T', Number\to_human_readable(1234567890123)); - $this->assertSame('1.23T', Number\to_human_readable(1234567890123, precision: 2)); - $this->assertSame('1Q', Number\to_human_readable(1234567890123456)); - $this->assertSame('1.23KQ', Number\to_human_readable(1234567890123456789, precision: 2)); - $this->assertSame('490K', Number\to_human_readable(489939)); - $this->assertSame('489.9390K', Number\to_human_readable(489939, precision: 4)); - $this->assertSame('500.00000M', Number\to_human_readable(500000000, precision: 5)); - - $this->assertSame('1MQ', Number\to_human_readable(1000000000000000000000)); - $this->assertSame('1BQ', Number\to_human_readable(1000000000000000000000000)); - $this->assertSame('1TQ', Number\to_human_readable(1000000000000000000000000000)); - $this->assertSame('1QQ', Number\to_human_readable(1000000000000000000000000000000)); - $this->assertSame('1KQQ', Number\to_human_readable(1000000000000000000000000000000000)); + $this->assertSame('12K', Number\to_human_readable(12_345)); + $this->assertSame('1M', Number\to_human_readable(1_234_567)); + $this->assertSame('1B', Number\to_human_readable(1_234_567_890)); + $this->assertSame('1T', Number\to_human_readable(1_234_567_890_123)); + $this->assertSame('1.23T', Number\to_human_readable(1_234_567_890_123, precision: 2)); + $this->assertSame('1Q', Number\to_human_readable(1_234_567_890_123_456)); + $this->assertSame('1.23KQ', Number\to_human_readable(1_234_567_890_123_456_789, precision: 2)); + $this->assertSame('490K', Number\to_human_readable(489_939)); + $this->assertSame('489.9390K', Number\to_human_readable(489_939, precision: 4)); + $this->assertSame('500.00000M', Number\to_human_readable(500_000_000, precision: 5)); + + $this->assertSame('1MQ', Number\to_human_readable(1_000_000_000_000_000_000_000)); + $this->assertSame('1BQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000)); + $this->assertSame('1TQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000)); + $this->assertSame('1QQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000_000)); + $this->assertSame('1KQQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000_000_000)); $this->assertSame('0', Number\to_human_readable(0)); $this->assertSame('0', Number\to_human_readable(0.0)); @@ -241,12 +241,12 @@ public function test_summarize(): void $this->assertSame('-1K', Number\to_human_readable(-1000)); $this->assertSame('-1.23K', Number\to_human_readable(-1234, precision: 2)); $this->assertSame('-1.2K', Number\to_human_readable(-1234, maxPrecision: 1)); - $this->assertSame('-1M', Number\to_human_readable(-1000000)); - $this->assertSame('-1B', Number\to_human_readable(-1000000000)); - $this->assertSame('-1T', Number\to_human_readable(-1000000000000)); - $this->assertSame('-1.1T', Number\to_human_readable(-1100000000000, maxPrecision: 1)); - $this->assertSame('-1Q', Number\to_human_readable(-1000000000000000)); - $this->assertSame('-1KQ', Number\to_human_readable(-1000000000000000000)); + $this->assertSame('-1M', Number\to_human_readable(-1_000_000)); + $this->assertSame('-1B', Number\to_human_readable(-1_000_000_000)); + $this->assertSame('-1T', Number\to_human_readable(-1_000_000_000_000)); + $this->assertSame('-1.1T', Number\to_human_readable(-1_100_000_000_000, maxPrecision: 1)); + $this->assertSame('-1Q', Number\to_human_readable(-1_000_000_000_000_000)); + $this->assertSame('-1KQ', Number\to_human_readable(-1_000_000_000_000_000_000)); } public function test_parse_int(): void diff --git a/packages/intl/tests/LocaleTest.php b/packages/intl/tests/LocaleTest.php index e914d8632..cc9ae82d8 100644 --- a/packages/intl/tests/LocaleTest.php +++ b/packages/intl/tests/LocaleTest.php @@ -174,9 +174,11 @@ public function test_it_returns_the_language_and_human_readable_name(Locale $loc public static function getLocalesWithScript(): Generator { foreach (Locale::cases() as $locale) { - if ($locale->hasScript()) { - yield $locale->value => [$locale]; + if (! $locale->hasScript()) { + continue; } + + yield $locale->value => [$locale]; } return null; @@ -195,9 +197,11 @@ public function test_it_returns_the_script(Locale $locale): void public static function getLocalesWithoutScript(): Generator { foreach (Locale::cases() as $locale) { - if (! $locale->hasScript()) { - yield $locale->value => [$locale]; + if ($locale->hasScript()) { + continue; } + + yield $locale->value => [$locale]; } return null; @@ -216,9 +220,11 @@ public function test_it_does_not_returns_the_script(Locale $locale): void public static function getLocalesWithRegion(): Generator { foreach (Locale::cases() as $locale) { - if ($locale->hasRegion()) { - yield $locale->value => [$locale]; + if (! $locale->hasRegion()) { + continue; } + + yield $locale->value => [$locale]; } return null; @@ -238,9 +244,11 @@ public function test_it_returns_the_region(Locale $locale): void public static function getLocalesWithoutRegion(): Generator { foreach (Locale::cases() as $locale) { - if (! $locale->hasRegion()) { - yield $locale->value => [$locale]; + if ($locale->hasRegion()) { + continue; } + + yield $locale->value => [$locale]; } return null; diff --git a/packages/kv-store/src/Redis/Config/RedisConfig.php b/packages/kv-store/src/Redis/Config/RedisConfig.php index 5356b67fe..8558ef4af 100644 --- a/packages/kv-store/src/Redis/Config/RedisConfig.php +++ b/packages/kv-store/src/Redis/Config/RedisConfig.php @@ -18,6 +18,7 @@ public function __construct( /** * Password to the Redis instance. */ + #[\SensitiveParameter] public ?string $password = null, /** diff --git a/packages/kv-store/src/Redis/PhpRedisClient.php b/packages/kv-store/src/Redis/PhpRedisClient.php index 8002e1486..f65fa2512 100644 --- a/packages/kv-store/src/Redis/PhpRedisClient.php +++ b/packages/kv-store/src/Redis/PhpRedisClient.php @@ -82,7 +82,7 @@ public function command(Stringable|string $command, Stringable|string ...$argume } $command = (string) $command; - $arguments = array_map(fn (Stringable|string $argument) => (string) $argument, $arguments); + $arguments = array_map(static fn (Stringable|string $argument) => (string) $argument, $arguments); $startedAt = DateTime::now(); $result = $this->client->rawcommand($command, ...$arguments); diff --git a/packages/kv-store/src/Redis/PredisClient.php b/packages/kv-store/src/Redis/PredisClient.php index d2f01d377..3b36b3064 100644 --- a/packages/kv-store/src/Redis/PredisClient.php +++ b/packages/kv-store/src/Redis/PredisClient.php @@ -45,7 +45,7 @@ public function flush(): void public function command(Stringable|string $command, Stringable|string ...$arguments): mixed { $command = (string) $command; - $arguments = array_map(fn (Stringable|string $argument) => (string) $argument, $arguments); + $arguments = array_map(static fn (Stringable|string $argument) => (string) $argument, $arguments); $startedAt = DateTime::now(); $result = $this->client->executeRaw(array_merge([$command], $arguments)); diff --git a/packages/log/src/TailLogsCommand.php b/packages/log/src/TailLogsCommand.php index b4cd35543..f0a6dea27 100644 --- a/packages/log/src/TailLogsCommand.php +++ b/packages/log/src/TailLogsCommand.php @@ -11,7 +11,6 @@ use Tempest\Container\Tag; use Tempest\Highlight\Highlighter; use Tempest\Log\Channels\AppendLogChannel; -use Tempest\Log\LogConfig; use Tempest\Support\Filesystem; final readonly class TailLogsCommand @@ -29,10 +28,12 @@ public function __invoke(): void $appendLogChannel = null; foreach ($this->config->logChannels as $channel) { - if ($channel instanceof AppendLogChannel) { - $appendLogChannel = $channel; - break; + if (! $channel instanceof AppendLogChannel) { + continue; } + + $appendLogChannel = $channel; + break; } if ($appendLogChannel === null) { diff --git a/packages/mail/src/Attachment.php b/packages/mail/src/Attachment.php index b0a88f980..85a3c8389 100644 --- a/packages/mail/src/Attachment.php +++ b/packages/mail/src/Attachment.php @@ -47,7 +47,7 @@ public static function fromStorage(Storage $storage, string $path, ?string $name $path = Path\normalize($path); return new self( - resolve: fn () => $storage->readStream($path), + resolve: static fn () => $storage->readStream($path), name: $name ?? basename($path), contentType: $contentType ?? $storage->mimeType($path), ); @@ -65,7 +65,7 @@ public static function fromFilesystem(string $path, ?string $name = null, ?strin } return new self( - resolve: fn () => Filesystem\read_file($path), + resolve: static fn () => Filesystem\read_file($path), name: $name ?? basename($path), contentType: $contentType ?? finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path), ); diff --git a/packages/mail/src/EmailToSymfonyEmailMapper.php b/packages/mail/src/EmailToSymfonyEmailMapper.php index d6f862b62..7bd89a3e1 100644 --- a/packages/mail/src/EmailToSymfonyEmailMapper.php +++ b/packages/mail/src/EmailToSymfonyEmailMapper.php @@ -119,7 +119,7 @@ public function map(mixed $from, mixed $to): SymfonyEmail private function convertAddresses(null|string|array|EmailAddress $addresses): array { return arr($addresses) - ->map(fn (string|EmailAddress|SymfonyAddress $address) => match (true) { + ->map(static fn (string|EmailAddress|SymfonyAddress $address) => match (true) { $address instanceof SymfonyAddress => $address, $address instanceof EmailAddress => new SymfonyAddress($address->email, $address->name ?? ''), default => SymfonyAddress::create($address), diff --git a/packages/mail/src/MailerInitializer.php b/packages/mail/src/MailerInitializer.php index 3a5da65eb..3869579ac 100644 --- a/packages/mail/src/MailerInitializer.php +++ b/packages/mail/src/MailerInitializer.php @@ -6,7 +6,6 @@ use Tempest\Container\Initializer; use Tempest\Container\Singleton; use Tempest\EventBus\EventBus; -use Tempest\Mail\MailerConfig; final class MailerInitializer implements Initializer { diff --git a/packages/mail/src/Testing/MailTester.php b/packages/mail/src/Testing/MailTester.php index 1d19951bc..ab786b670 100644 --- a/packages/mail/src/Testing/MailTester.php +++ b/packages/mail/src/Testing/MailTester.php @@ -45,7 +45,7 @@ public function assertSent(string $email, ?Closure $callback = null): self { $this->assertClassStringIsEmail($email); - $sentEmail = Arr\first($this->mailer->sent, filter: fn (Email $sent) => $sent instanceof $email); + $sentEmail = Arr\first($this->mailer->sent, filter: static fn (Email $sent) => $sent instanceof $email); Assert::assertTrue( condition: (bool) $sentEmail, @@ -78,7 +78,7 @@ public function assertNotSent(string $email): self $this->assertClassStringIsEmail($email); Assert::assertFalse( - condition: (bool) Arr\first($this->mailer->sent, filter: fn (Email $sent) => $sent instanceof $email), + condition: (bool) Arr\first($this->mailer->sent, filter: static fn (Email $sent) => $sent instanceof $email), message: sprintf('Email `%s` was unexpectedly sent.', $email), ); @@ -92,22 +92,22 @@ public function assertNotSent(string $email): self public array $from { get => Arr\map( array: $this->sentSymfonyEmail->getFrom(), - map: fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), + map: static fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), ); } public array $to { get => Arr\map( array: $this->sentSymfonyEmail->getTo(), - map: fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), + map: static fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), ); } public array $attachments { get => Arr\map( array: $this->sentSymfonyEmail->getAttachments(), - map: fn (DataPart $attachment) => new Attachment( - resolve: fn () => $attachment->getBody(), + map: static fn (DataPart $attachment) => new Attachment( + resolve: static fn () => $attachment->getBody(), name: $attachment->getFilename(), contentType: $attachment->getMediaType() . '/' . $attachment->getMediaSubtype(), ), @@ -369,19 +369,21 @@ public function assertAttached(string $filename, ?Closure $callback = null): sel ); foreach ($attachments as $attachment) { - if ($attachment->getFilename() === $filename) { - if ($callback && $callback(new AttachmentTester($attachment)) === false) { - Assert::fail(sprintf('The assertion callback returned `false` for attachment `%s`.', $filename)); - } + if ($attachment->getFilename() !== $filename) { + continue; + } - return $this; + if ($callback && $callback(new AttachmentTester($attachment)) === false) { + Assert::fail(sprintf('The assertion callback returned `false` for attachment `%s`.', $filename)); } + + return $this; } Assert::fail(sprintf( 'Failed asserting that the email has an attachment named `%s`. Existing attachments: %s.', $filename, - Arr\join(Arr\map($attachments, fn (DataPart $attachment) => $attachment->getName())), + Arr\join(Arr\map($attachments, static fn (DataPart $attachment) => $attachment->getName())), )); } @@ -444,7 +446,7 @@ private function assertAddressListDoesNotContain(null|string|array|EmailAddress private function convertAddresses(null|string|array|EmailAddress $addresses): array { return arr($addresses) - ->map(function (string|EmailAddress|SymfonyAddress $address) { + ->map(static function (string|EmailAddress|SymfonyAddress $address) { return match (true) { $address instanceof SymfonyAddress => $address->getAddress(), $address instanceof EmailAddress => $address->email, diff --git a/packages/mail/src/Transports/RoundRobinMailerConfig.php b/packages/mail/src/Transports/RoundRobinMailerConfig.php index 59f4b78f4..5b41abfaa 100644 --- a/packages/mail/src/Transports/RoundRobinMailerConfig.php +++ b/packages/mail/src/Transports/RoundRobinMailerConfig.php @@ -42,6 +42,6 @@ public function createTransport(): TransportInterface /** @return TransportInterface[] */ private function buildTransports(): array { - return Arr\map($this->transports, fn (MailerConfig $config) => $config->createTransport()); + return Arr\map($this->transports, static fn (MailerConfig $config) => $config->createTransport()); } } diff --git a/packages/mail/src/Transports/Ses/SesMailerConfig.php b/packages/mail/src/Transports/Ses/SesMailerConfig.php index f2f46a13f..879e790f2 100644 --- a/packages/mail/src/Transports/Ses/SesMailerConfig.php +++ b/packages/mail/src/Transports/Ses/SesMailerConfig.php @@ -47,6 +47,7 @@ public function __construct( /** * An optional Amazon SES session token. */ + #[\SensitiveParameter] public ?string $sessionToken = null, /** diff --git a/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php b/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php index 59352766b..12b116b65 100644 --- a/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php +++ b/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php @@ -25,6 +25,7 @@ public function __construct( /** * Secret key used for authenticating to the SES API. */ + #[\SensitiveParameter] public string $password, /** diff --git a/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php b/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php index 5ee46e98e..52b22cbcf 100644 --- a/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php +++ b/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php @@ -41,6 +41,7 @@ public function __construct( /** * Password used for connecting to the SMTP server. */ + #[\SensitiveParameter] public ?string $password, /** diff --git a/packages/mapper/src/Mappers/ObjectToArrayMapper.php b/packages/mapper/src/Mappers/ObjectToArrayMapper.php index f72f411d2..c195e15a2 100644 --- a/packages/mapper/src/Mappers/ObjectToArrayMapper.php +++ b/packages/mapper/src/Mappers/ObjectToArrayMapper.php @@ -64,9 +64,11 @@ private function resolvePropertyValue(PropertyReflector $property, object $objec if ($property->getIterableType()?->isClass()) { foreach ($propertyValue as $key => $value) { - if (is_object($value)) { - $propertyValue[$key] = map($value)->toArray(); + if (! is_object($value)) { + continue; } + + $propertyValue[$key] = map($value)->toArray(); } return $propertyValue; diff --git a/packages/mapper/src/functions.php b/packages/mapper/src/functions.php index 59aeb2f29..1329d2398 100644 --- a/packages/mapper/src/functions.php +++ b/packages/mapper/src/functions.php @@ -5,7 +5,6 @@ namespace Tempest\Mapper; use Tempest\Container; -use Tempest\Mapper\ObjectFactory; /** * Creates a factory which allows instantiating `$objectOrClass` with the data specified by the {@see \Tempest\Mapper\ObjectFactory::from()} method. diff --git a/packages/process/src/InvokedProcessPool.php b/packages/process/src/InvokedProcessPool.php index 1e8598bb1..10322764b 100644 --- a/packages/process/src/InvokedProcessPool.php +++ b/packages/process/src/InvokedProcessPool.php @@ -16,7 +16,7 @@ final class InvokedProcessPool implements Countable public ImmutableArray $running { get => $this->processes ->toImmutableArray() - ->filter(fn (InvokedProcess $process) => $process->running); + ->filter(static fn (InvokedProcess $process) => $process->running); } /** @@ -38,7 +38,7 @@ public function __construct( */ public function signal(int $signal): ImmutableArray { - return $this->running->each(fn (InvokedProcess $process) => $process->signal($signal)); + return $this->running->each(static fn (InvokedProcess $process) => $process->signal($signal)); } /** @@ -46,7 +46,7 @@ public function signal(int $signal): ImmutableArray */ public function stop(float|int|Duration $timeout = 10, ?int $signal = null): ImmutableArray { - return $this->running->each(fn (InvokedProcess $process) => $process->stop($timeout, $signal)); + return $this->running->each(static fn (InvokedProcess $process) => $process->stop($timeout, $signal)); } /** @@ -55,7 +55,7 @@ public function stop(float|int|Duration $timeout = 10, ?int $signal = null): Imm public function wait(): ProcessPoolResults { return new ProcessPoolResults( - $this->all->map(fn (InvokedProcess $process) => $process->wait()), + $this->all->map(static fn (InvokedProcess $process) => $process->wait()), ); } @@ -66,7 +66,7 @@ public function wait(): ProcessPoolResults */ public function forEachRunning(\Closure $callback): self { - $this->running->each(fn (InvokedProcess $process) => $callback($process)); + $this->running->each(static fn (InvokedProcess $process) => $callback($process)); return $this; } @@ -78,7 +78,7 @@ public function forEachRunning(\Closure $callback): self */ public function forEach(\Closure $callback): self { - $this->processes->each(fn (InvokedProcess $process) => $callback($process)); + $this->processes->each(static fn (InvokedProcess $process) => $callback($process)); return $this; } diff --git a/packages/process/src/InvokedSystemProcess.php b/packages/process/src/InvokedSystemProcess.php index dada1c23a..0f42edf5f 100644 --- a/packages/process/src/InvokedSystemProcess.php +++ b/packages/process/src/InvokedSystemProcess.php @@ -66,7 +66,7 @@ public function wait(?callable $output = null): ProcessResult { try { $callback = $output - ? fn (string $type, mixed $data) => $output(OutputChannel::fromSymfonyOutputType($type), $data) + ? static fn (string $type, mixed $data) => $output(OutputChannel::fromSymfonyOutputType($type), $data) : null; $this->process->wait($callback); diff --git a/packages/process/src/ProcessPoolResults.php b/packages/process/src/ProcessPoolResults.php index 5bf7a55fa..021b0d5a1 100644 --- a/packages/process/src/ProcessPoolResults.php +++ b/packages/process/src/ProcessPoolResults.php @@ -19,7 +19,7 @@ public function __construct( */ public function allSuccessful(): bool { - return $this->results->every(fn (ProcessResult $result) => $result->successful()); + return $this->results->every(static fn (ProcessResult $result) => $result->successful()); } /** @@ -27,7 +27,7 @@ public function allSuccessful(): bool */ public function allFailed(): bool { - return $this->results->every(fn (ProcessResult $result) => $result->failed()); + return $this->results->every(static fn (ProcessResult $result) => $result->failed()); } /** @@ -35,7 +35,7 @@ public function allFailed(): bool */ public function someSuccessful(): bool { - return $this->results->filter(fn (ProcessResult $result) => $result->successful())->count() > 0; + return $this->results->filter(static fn (ProcessResult $result) => $result->successful())->count() > 0; } /** @@ -43,7 +43,7 @@ public function someSuccessful(): bool */ public function someFailed(): bool { - return $this->results->filter(fn (ProcessResult $result) => $result->failed())->count() > 0; + return $this->results->filter(static fn (ProcessResult $result) => $result->failed())->count() > 0; } /** @@ -51,7 +51,7 @@ public function someFailed(): bool */ public function successful(): ImmutableArray { - return $this->results->filter(fn (ProcessResult $result) => $result->successful()); + return $this->results->filter(static fn (ProcessResult $result) => $result->successful()); } /** @@ -59,7 +59,7 @@ public function successful(): ImmutableArray */ public function failed(): ImmutableArray { - return $this->results->filter(fn (ProcessResult $result) => ! $result->successful()); + return $this->results->filter(static fn (ProcessResult $result) => ! $result->successful()); } public function toImmutableArray(): ImmutableArray diff --git a/packages/process/src/Testing/InvokedProcessDescription.php b/packages/process/src/Testing/InvokedProcessDescription.php index fa0a942d7..80d62e707 100644 --- a/packages/process/src/Testing/InvokedProcessDescription.php +++ b/packages/process/src/Testing/InvokedProcessDescription.php @@ -113,7 +113,7 @@ public function resolveOutput(bool $error = false): string ->filter(static fn (array $output) => $output['type'] === $expectedType) ->map(static fn (array $output) => rtrim($output['buffer'], "\n")) ->implode("\n") - ->when(fn ($s) => $s->isNotEmpty(), fn ($s) => $s->finish("\n")) + ->when(static fn ($s) => $s->isNotEmpty(), static fn ($s) => $s->finish("\n")) ->toString(); } } diff --git a/packages/process/src/Testing/InvokedTestingProcess.php b/packages/process/src/Testing/InvokedTestingProcess.php index 9a1938302..c0614c40f 100644 --- a/packages/process/src/Testing/InvokedTestingProcess.php +++ b/packages/process/src/Testing/InvokedTestingProcess.php @@ -42,9 +42,11 @@ final class InvokedTestingProcess implements InvokedProcess $output = []; for ($i = 0; $i < $this->nextOutputIndex; $i++) { - if ($this->description->output[$i]['type'] === OutputChannel::OUTPUT) { - $output[] = $this->description->output[$i]['buffer']; + if ($this->description->output[$i]['type'] !== OutputChannel::OUTPUT) { + continue; } + + $output[] = $this->description->output[$i]['buffer']; } return rtrim(implode('', $output), "\n") . "\n"; @@ -58,9 +60,11 @@ final class InvokedTestingProcess implements InvokedProcess $output = []; for ($i = 0; $i < $this->nextErrorOutputIndex; $i++) { - if ($this->description->output[$i]['type'] === OutputChannel::ERROR) { - $output[] = $this->description->output[$i]['buffer']; + if ($this->description->output[$i]['type'] !== OutputChannel::ERROR) { + continue; } + + $output[] = $this->description->output[$i]['buffer']; } return rtrim(implode('', $output), "\n") . "\n"; diff --git a/packages/process/src/Testing/ProcessTester.php b/packages/process/src/Testing/ProcessTester.php index ba75c8d33..eaa22aa5e 100644 --- a/packages/process/src/Testing/ProcessTester.php +++ b/packages/process/src/Testing/ProcessTester.php @@ -246,9 +246,11 @@ public function assertRanTimes(string|\Closure $command, int $times): self $count = 0; foreach ($this->executor->executions as $executions) { foreach ($executions as [$process, $result]) { - if ($command($process, $result) === true) { - $count++; + if ($command($process, $result) !== true) { + continue; } + + $count++; } } } else { // @mago-expects linter:no-else-clause @@ -274,9 +276,11 @@ private function findExecutionsByPattern(string $pattern): array $executions = []; foreach ($this->executor->executions as $command => $commandExecutions) { - if ($this->executor->commandMatchesPattern($command, $pattern)) { - $executions[] = $commandExecutions; + if (! $this->executor->commandMatchesPattern($command, $pattern)) { + continue; } + + $executions[] = $commandExecutions; } return Arr\flatten($executions, depth: 1); diff --git a/packages/process/tests/GenericProcessExecutorTest.php b/packages/process/tests/GenericProcessExecutorTest.php index cc73cf7b4..32a59237a 100644 --- a/packages/process/tests/GenericProcessExecutorTest.php +++ b/packages/process/tests/GenericProcessExecutorTest.php @@ -64,7 +64,7 @@ public function test_wait_callback(): void $process = $executor->start('echo hello'); $output = []; - $process->wait(function (OutputChannel $channel, string $data) use (&$output) { + $process->wait(static function (OutputChannel $channel, string $data) use (&$output) { $output[$channel->value] ??= []; $output[$channel->value][] = $data; }); diff --git a/packages/reflection/src/ClassReflector.php b/packages/reflection/src/ClassReflector.php index 3a388beef..2cf530860 100644 --- a/packages/reflection/src/ClassReflector.php +++ b/packages/reflection/src/ClassReflector.php @@ -56,7 +56,7 @@ public function getParent(): ?ClassReflector public function getInterfaces(): array { return array_map( - fn (PHPReflectionClass $interface) => new TypeReflector($interface), + static fn (PHPReflectionClass $interface) => new TypeReflector($interface), $this->reflectionClass->getInterfaces(), ); } @@ -65,7 +65,7 @@ public function getInterfaces(): array public function getPublicProperties(): array { return array_map( - fn (PHPReflectionProperty $property) => new PropertyReflector($property), + static fn (PHPReflectionProperty $property) => new PropertyReflector($property), $this->reflectionClass->getProperties(PHPReflectionProperty::IS_PUBLIC), ); } @@ -74,7 +74,7 @@ public function getPublicProperties(): array public function getProperties(): array { return array_map( - fn (PHPReflectionProperty $property) => new PropertyReflector($property), + static fn (PHPReflectionProperty $property) => new PropertyReflector($property), $this->reflectionClass->getProperties(), ); } @@ -85,7 +85,7 @@ public function getPublicMethods(): array return $this->memoize( 'public_methods', fn () => array_map( - fn (PHPReflectionMethod $method) => new MethodReflector($method), + static fn (PHPReflectionMethod $method) => new MethodReflector($method), $this->reflectionClass->getMethods(PHPReflectionMethod::IS_PUBLIC), ), ); diff --git a/packages/reflection/src/EnumReflector.php b/packages/reflection/src/EnumReflector.php index f1d204b56..4dade5c18 100644 --- a/packages/reflection/src/EnumReflector.php +++ b/packages/reflection/src/EnumReflector.php @@ -88,7 +88,7 @@ public function getCases(): array return $this->memoize( key: 'cases', closure: fn () => array_map( - callback: fn (ReflectionEnumUnitCase $case) => $case->getValue(), + callback: static fn (ReflectionEnumUnitCase $case) => $case->getValue(), array: $this->getReflectionCases(), ), ); diff --git a/packages/reflection/src/FunctionReflector.php b/packages/reflection/src/FunctionReflector.php index c7cb027b0..ac1b39d1a 100644 --- a/packages/reflection/src/FunctionReflector.php +++ b/packages/reflection/src/FunctionReflector.php @@ -37,7 +37,7 @@ public function getParameter(int|string $key): ?ParameterReflector { $parameter = array_find( array: $this->reflectionFunction->getParameters(), - callback: fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, + callback: static fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, ); if ($parameter === null) { diff --git a/packages/reflection/src/MethodReflector.php b/packages/reflection/src/MethodReflector.php index 6667e8cb0..6dfc9f2fc 100644 --- a/packages/reflection/src/MethodReflector.php +++ b/packages/reflection/src/MethodReflector.php @@ -38,7 +38,7 @@ public function getParameter(int|string $key): ?ParameterReflector { $parameter = array_find( array: $this->reflectionMethod->getParameters(), - callback: fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, + callback: static fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, ); if ($parameter === null) { diff --git a/packages/reflection/src/TypeReflector.php b/packages/reflection/src/TypeReflector.php index 739cfd4e5..5cac70624 100644 --- a/packages/reflection/src/TypeReflector.php +++ b/packages/reflection/src/TypeReflector.php @@ -236,7 +236,7 @@ public function isIntersection(): bool public function split(): array { return array_map( - fn (string $part) => new self($part), + static fn (string $part) => new self($part), preg_split('/[&|]/', $this->definition), ); } diff --git a/packages/reflection/src/functions.php b/packages/reflection/src/functions.php index 20f07a96e..ee66d5e29 100644 --- a/packages/reflection/src/functions.php +++ b/packages/reflection/src/functions.php @@ -6,8 +6,6 @@ use ReflectionClass as PHPReflectionClass; use ReflectionProperty as PHPReflectionProperty; -use Tempest\Reflection\ClassReflector; -use Tempest\Reflection\PropertyReflector; /** * Creates a new {@see Reflector} instance based on the given `$classOrProperty`. diff --git a/packages/reflection/tests/Fixtures/NoReturnType.php b/packages/reflection/tests/Fixtures/NoReturnType.php index bf5dbbb1d..9d686184c 100644 --- a/packages/reflection/tests/Fixtures/NoReturnType.php +++ b/packages/reflection/tests/Fixtures/NoReturnType.php @@ -6,7 +6,6 @@ final class NoReturnType { - // @mago-expect lint:return-type public function noReturnType() { return 2137; diff --git a/packages/reflection/tests/FunctionReflectorTest.php b/packages/reflection/tests/FunctionReflectorTest.php index d9a40d637..86aeb94e7 100644 --- a/packages/reflection/tests/FunctionReflectorTest.php +++ b/packages/reflection/tests/FunctionReflectorTest.php @@ -9,7 +9,7 @@ final class FunctionReflectorTest extends TestCase { public function test_get_parameter(): void { - $reflector = new FunctionReflector(fn (string $_test) => null); + $reflector = new FunctionReflector(static fn (string $_test) => null); $this->assertSame('_test', $reflector->getParameter(key: '_test')->getName()); $this->assertSame('_test', $reflector->getParameter(key: 0)->getName()); diff --git a/packages/router/src/Commands/MakeControllerCommand.php b/packages/router/src/Commands/MakeControllerCommand.php index 5052d4aed..73f5e246a 100644 --- a/packages/router/src/Commands/MakeControllerCommand.php +++ b/packages/router/src/Commands/MakeControllerCommand.php @@ -43,7 +43,7 @@ public function __invoke( 'dummy-view' => $controllerView, ], manipulations: [ - fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/router/src/Exceptions/HtmlExceptionRenderer.php b/packages/router/src/Exceptions/HtmlExceptionRenderer.php index e4bf13fbc..68e01594b 100644 --- a/packages/router/src/Exceptions/HtmlExceptionRenderer.php +++ b/packages/router/src/Exceptions/HtmlExceptionRenderer.php @@ -163,9 +163,11 @@ private function filterSensitiveFields(Request $request, ?string $targetClass): $reflector = new ClassReflector($targetClass); foreach ($reflector->getPublicProperties() as $property) { - if ($property->hasAttribute(SensitiveField::class)) { - unset($body[$property->getName()]); + if (! $property->hasAttribute(SensitiveField::class)) { + continue; } + + unset($body[$property->getName()]); } return $body; diff --git a/packages/router/src/Exceptions/JsonExceptionRenderer.php b/packages/router/src/Exceptions/JsonExceptionRenderer.php index 9a3c247be..735398ad8 100644 --- a/packages/router/src/Exceptions/JsonExceptionRenderer.php +++ b/packages/router/src/Exceptions/JsonExceptionRenderer.php @@ -96,7 +96,7 @@ private function renderErrorResponse(Status $status, ?string $message = null, ?T 'line' => $throwable->getLine(), 'trace' => Arr\map( array: $throwable->getTrace(), - map: fn (array $trace) => Arr\remove_keys($trace, 'args'), + map: static fn (array $trace) => Arr\remove_keys($trace, 'args'), ), ]); } diff --git a/packages/router/src/GenericRouter.php b/packages/router/src/GenericRouter.php index 6bedfe0e0..69ad507cc 100644 --- a/packages/router/src/GenericRouter.php +++ b/packages/router/src/GenericRouter.php @@ -29,7 +29,7 @@ public function dispatch(Request|PsrRequest $request): Response $request = map($request)->with(PsrRequestToGenericRequestMapper::class)->do(); } - $this->container->singleton(Request::class, fn () => $request); + $this->container->singleton(Request::class, static fn () => $request); $callable = $this->getCallable(); diff --git a/packages/router/src/HandleRouteSpecificMiddleware.php b/packages/router/src/HandleRouteSpecificMiddleware.php index 9e27c96da..145495031 100644 --- a/packages/router/src/HandleRouteSpecificMiddleware.php +++ b/packages/router/src/HandleRouteSpecificMiddleware.php @@ -20,7 +20,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon { $middlewareStack = new Middleware(...$this->matchedRoute->route->middleware); - $callable = new HttpMiddlewareCallable(fn (Request $request) => $next($request)); + $callable = new HttpMiddlewareCallable(static fn (Request $request) => $next($request)); foreach ($middlewareStack->unwrap() as $middlewareClass) { $callable = new HttpMiddlewareCallable(function (Request $request) use ($middlewareClass, $callable) { diff --git a/packages/router/src/MatchRouteMiddleware.php b/packages/router/src/MatchRouteMiddleware.php index ab8a44a32..33ecc45d8 100644 --- a/packages/router/src/MatchRouteMiddleware.php +++ b/packages/router/src/MatchRouteMiddleware.php @@ -35,7 +35,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon } // We register the matched route in the container, some internal framework components will need it - $this->container->singleton(MatchedRoute::class, fn () => $matchedRoute); + $this->container->singleton(MatchedRoute::class, static fn () => $matchedRoute); // Convert the request to a specific request implementation, if needed $request = $this->resolveRequest($request, $matchedRoute); @@ -43,7 +43,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon // We register this newly created request object in the container // This makes it so that RequestInitializer is bypassed entirely when the controller action needs the request class // Making it so that we don't need to set any $_SERVER variables and stuff like that - $this->container->singleton($request::class, fn () => $request); + $this->container->singleton($request::class, static fn () => $request); return $next($request); } @@ -56,12 +56,13 @@ private function resolveRequest(Request $request, MatchedRoute $matchedRoute): R // We'll loop over all the handler's parameters foreach ($matchedRoute->route->handler->getParameters() as $parameter) { // If the parameter's type is an instance of Request… - if ($parameter->getType()->matches(Request::class)) { - // We'll use that specific request class - $requestClass = $parameter->getType()->getName(); - - break; + if (! $parameter->getType()->matches(Request::class)) { + continue; } + + $requestClass = $parameter->getType()->getName(); + + break; } if ($requestClass !== Request::class && $requestClass !== GenericRequest::class) { diff --git a/packages/router/src/RouteBindingInitializer.php b/packages/router/src/RouteBindingInitializer.php index b9f3b00fc..027e83d49 100644 --- a/packages/router/src/RouteBindingInitializer.php +++ b/packages/router/src/RouteBindingInitializer.php @@ -24,11 +24,13 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con $parameter = null; foreach ($matchedRoute->route->handler->getParameters() as $searchParameter) { - if ($searchParameter->getType()->equals($class->getType())) { - $parameter = $searchParameter; - - break; + if (! $searchParameter->getType()->equals($class->getType())) { + continue; } + + $parameter = $searchParameter; + + break; } if ($parameter === null) { diff --git a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php index 7a71c6c7e..7a50389ad 100644 --- a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php +++ b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php @@ -9,7 +9,7 @@ final readonly class RouteMatchingRegexBuilder { // This limit is guesstimated using a small script with an ever in pattern feed into preg_match - private const int PREG_REGEX_SIZE_LIMIT = 32768; + private const int PREG_REGEX_SIZE_LIMIT = 32_768; private const int REGEX_SIZE_MARGIN = 256; diff --git a/packages/router/src/Static/StaticCleanCommand.php b/packages/router/src/Static/StaticCleanCommand.php index a85a569a4..057fd0f75 100644 --- a/packages/router/src/Static/StaticCleanCommand.php +++ b/packages/router/src/Static/StaticCleanCommand.php @@ -56,9 +56,11 @@ private function removeFiles(RecursiveDirectoryIterator $directoryIterator): voi /** @var SplFileInfo $file */ foreach (new RecursiveIteratorIterator($directoryIterator) as $file) { - if ($file->getExtension() === 'html') { - $files[] = $file; + if ($file->getExtension() !== 'html') { + continue; } + + $files[] = $file; } foreach ($files as $file) { diff --git a/packages/router/src/functions.php b/packages/router/src/functions.php index 083c5f837..fa96034e9 100644 --- a/packages/router/src/functions.php +++ b/packages/router/src/functions.php @@ -7,7 +7,6 @@ use Tempest\DateTime\DateTime; use Tempest\DateTime\Duration; use Tempest\Reflection\MethodReflector; -use Tempest\Router\UriGenerator; use function Tempest\Container\get; diff --git a/packages/storage/src/Config/FTPStorageConfig.php b/packages/storage/src/Config/FTPStorageConfig.php index 9bc200661..02fc9571a 100644 --- a/packages/storage/src/Config/FTPStorageConfig.php +++ b/packages/storage/src/Config/FTPStorageConfig.php @@ -19,6 +19,7 @@ public function __construct( public string $host, public string $root, public string $username, + #[\SensitiveParameter] public string $password, public int $port = 21, public bool $ssl = false, diff --git a/packages/storage/src/Config/S3StorageConfig.php b/packages/storage/src/Config/S3StorageConfig.php index f1f17f70f..120797d0a 100644 --- a/packages/storage/src/Config/S3StorageConfig.php +++ b/packages/storage/src/Config/S3StorageConfig.php @@ -35,6 +35,7 @@ public function __construct( /** * AWS session token (typically used with temporary credentials). If null, the SDK will attempt to use the default credential provider chain. */ + #[\SensitiveParameter] public ?string $sessionToken = null, /** diff --git a/packages/storage/src/Config/SFTPStorageConfig.php b/packages/storage/src/Config/SFTPStorageConfig.php index c2bfaae16..28b4978ab 100644 --- a/packages/storage/src/Config/SFTPStorageConfig.php +++ b/packages/storage/src/Config/SFTPStorageConfig.php @@ -15,6 +15,7 @@ public function __construct( public string $host, public string $root, public string $username, + #[\SensitiveParameter] public string $password, public ?string $privateKey = null, public ?string $passphrase = null, diff --git a/packages/support/src/Arr/ManipulatesArray.php b/packages/support/src/Arr/ManipulatesArray.php index e038d9f17..b9aa7cfd8 100644 --- a/packages/support/src/Arr/ManipulatesArray.php +++ b/packages/support/src/Arr/ManipulatesArray.php @@ -90,7 +90,7 @@ public function findKey(mixed $value, bool $strict = false): int|string|null */ public function chunk(int $size, bool $preserveKeys = true): self { - return $this->createOrModify(array_map(fn (array $array) => new static($array), namespace\chunk($this->value, $size, $preserveKeys))); + return $this->createOrModify(array_map(static fn (array $array) => new static($array), namespace\chunk($this->value, $size, $preserveKeys))); } /** diff --git a/packages/support/src/Arr/functions.php b/packages/support/src/Arr/functions.php index 96c97c720..12dcd732b 100644 --- a/packages/support/src/Arr/functions.php +++ b/packages/support/src/Arr/functions.php @@ -202,9 +202,11 @@ function forget_values(array &$array, mixed $values): array $values = is_array($values) ? $values : [$values]; foreach ($values as $value) { - if (! is_null($key = array_find_key($array, fn (mixed $match) => $value === $match))) { - unset($array[$key]); + if (is_null($key = array_find_key($array, fn (mixed $match) => $value === $match))) { + continue; } + + unset($array[$key]); } return $array; @@ -757,9 +759,7 @@ function implode(iterable $array, string $glue): ImmutableString function keys(iterable $array): array { /** @var list $result */ - $result = array_keys(to_array($array)); - - return $result; + return array_keys(to_array($array)); } /** @@ -775,9 +775,7 @@ function keys(iterable $array): array function values(iterable $array): array { /** @var list $result */ - $result = array_values(to_array($array)); - - return $result; + return array_values(to_array($array)); } /** @@ -798,9 +796,11 @@ function filter(iterable $array, ?Closure $filter = null): array $filter ??= static fn (mixed $value, mixed $_) => ! in_array($value, [false, null], strict: true); foreach (to_array($array) as $key => $value) { - if ($filter($value, $key)) { - $result[$key] = $value; + if (! $filter($value, $key)) { + continue; } + + $result[$key] = $value; } return $result; @@ -1534,9 +1534,11 @@ function to_array(mixed $input): array $result = []; for ($i = 0; $i < $count; $i++) { - if (isset($input[$i])) { - $result[$i] = $input[$i]; + if (! isset($input[$i])) { + continue; } + + $result[$i] = $input[$i]; } return $result; diff --git a/packages/support/src/IsEnumHelper.php b/packages/support/src/IsEnumHelper.php index a8fe25859..24fcbb3fc 100644 --- a/packages/support/src/IsEnumHelper.php +++ b/packages/support/src/IsEnumHelper.php @@ -39,7 +39,7 @@ public static function tryFromName(string $name): ?static { $cases = array_filter( static::cases(), - fn (UnitEnum $case) => $case->name === $name, + static fn (UnitEnum $case) => $case->name === $name, ); return array_shift($cases); diff --git a/packages/support/src/JavaScript/DependencyInstaller.php b/packages/support/src/JavaScript/DependencyInstaller.php index 762c68755..8621ea2e5 100644 --- a/packages/support/src/JavaScript/DependencyInstaller.php +++ b/packages/support/src/JavaScript/DependencyInstaller.php @@ -75,7 +75,7 @@ private function getInstallProcess(PackageManager $packageManager, string $cwd, $dev ? '-D' : null, ...$dependencies, ], - fn (?string $arg): bool => $arg !== null, + static fn (?string $arg): bool => $arg !== null, )); return new Process( diff --git a/packages/support/src/JavaScript/PackageManager.php b/packages/support/src/JavaScript/PackageManager.php index b2649ff8a..1eb0b23d2 100644 --- a/packages/support/src/JavaScript/PackageManager.php +++ b/packages/support/src/JavaScript/PackageManager.php @@ -62,7 +62,7 @@ public static function detect(string $cwd): ?self { return array_find( array: PackageManager::cases(), - callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file( + callback: static fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), static fn (string $lockFile): bool => Filesystem\is_file( $cwd . '/' . $lockFile, )), ); diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php index 54e0cb013..73d53c7af 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php @@ -5,6 +5,5 @@ namespace Tempest\Support\Json\Exception; use InvalidArgumentException; -use Tempest\Support\Json\Exception\JsonException; final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php index 643d92ddd..9148a3c7b 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php @@ -5,6 +5,5 @@ namespace Tempest\Support\Json\Exception; use InvalidArgumentException; -use Tempest\Support\Json\Exception\JsonException; final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Math/constants.php b/packages/support/src/Math/constants.php index 8d296b290..3c6f7b403 100644 --- a/packages/support/src/Math/constants.php +++ b/packages/support/src/Math/constants.php @@ -26,21 +26,21 @@ * * @var float */ -const E = 2.7182818284590452353602875; +const E = 2.718_281_828_459_045_235_360_287_5; /** * The ratio of the circumference of a circle to its diameter, or approximately 3.141592653589793238462643. * * @var float */ -const PI = 3.141592653589793238462643; +const PI = 3.141_592_653_589_793_238_462_643; /** * The maximum integer value representable in a 64-bit binary-coded decimal. * * @var int */ -const INT64_MAX = 9223372036854775807; +const INT64_MAX = 9_223_372_036_854_775_807; /** * The minimum integer value representable in a 64-bit binary-coded decimal. @@ -54,42 +54,42 @@ * * @var int */ -const INT53_MAX = 9007199254740992; +const INT53_MAX = 9_007_199_254_740_992; /** * The minimum integer value representable in a 53-bit binary-coded decimal. * * @var int */ -const INT53_MIN = -9007199254740993; +const INT53_MIN = -9_007_199_254_740_993; /** * The maximum integer value representable in a 32-bit binary-coded decimal. * * @var int */ -const INT32_MAX = 2147483647; +const INT32_MAX = 2_147_483_647; /** * The minimum integer value representable in a 32-bit binary-coded decimal. * * @var int */ -const INT32_MIN = -2147483648; +const INT32_MIN = -2_147_483_648; /** * The maximum integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const INT16_MAX = 32767; +const INT16_MAX = 32_767; /** * The minimum integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const INT16_MIN = -32768; +const INT16_MIN = -32_768; /** * The maximum integer value representable in a 8-bit binary-coded decimal. @@ -110,14 +110,14 @@ * * @var int */ -const UINT32_MAX = 4294967295; +const UINT32_MAX = 4_294_967_295; /** * The maximum unsigned integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const UINT16_MAX = 65535; +const UINT16_MAX = 65_535; /** * The maximum unsigned integer value representable in a 8-bit binary-coded decimal. @@ -131,25 +131,25 @@ * * @var float */ -const FLOAT32_MAX = 3.40282347E+38; +const FLOAT32_MAX = 3.402_823_47E+38; /** * The minimum floating point value representable in a 32-bit binary-coded decimal. * * @var float */ -const FLOAT32_MIN = -3.40282347E+38; +const FLOAT32_MIN = -3.402_823_47E+38; /** * The maximum floating point value representable in a 64-bit binary-coded decimal. * * @var float */ -const FLOAT64_MAX = 1.7976931348623157E+308; +const FLOAT64_MAX = 1.797_693_134_862_315_7E+308; /** * The minimum floating point value representable in a 64-bit binary-coded decimal. * * @var float */ -const FLOAT64_MIN = -1.7976931348623157E+308; +const FLOAT64_MIN = -1.797_693_134_862_315_7E+308; diff --git a/packages/support/src/Math/functions.php b/packages/support/src/Math/functions.php index 9fbc60373..d24925656 100644 --- a/packages/support/src/Math/functions.php +++ b/packages/support/src/Math/functions.php @@ -356,9 +356,11 @@ function max(array $numbers): null|int|float $max = null; foreach ($numbers as $number) { - if (null === $max || $number > $max) { - $max = $number; + if (! (null === $max || $number > $max)) { + continue; } + + $max = $number; } return $max; @@ -380,9 +382,11 @@ function maxva(int|float $first, int|float $second, int|float ...$rest): int|flo $max = \max($first, $second); foreach ($rest as $number) { - if ($number > $max) { - $max = $number; + if ($number <= $max) { + continue; } + + $max = $number; } return $max; @@ -488,9 +492,11 @@ function min(array $numbers): null|float|int $min = null; foreach ($numbers as $number) { - if (null === $min || $number < $min) { - $min = $number; + if (! (null === $min || $number < $min)) { + continue; } + + $min = $number; } return $min; @@ -512,9 +518,11 @@ function minva(int|float $first, int|float $second, int|float ...$rest): int|flo $min = \min($first, $second); foreach ($rest as $number) { - if ($number < $min) { - $min = $number; + if ($number >= $min) { + continue; } + + $min = $number; } return $min; diff --git a/packages/support/src/Uri/Uri.php b/packages/support/src/Uri/Uri.php index aedf22f6d..15df9336f 100644 --- a/packages/support/src/Uri/Uri.php +++ b/packages/support/src/Uri/Uri.php @@ -21,7 +21,7 @@ final class Uri return []; } - return array_values(array_filter(explode('/', $this->path), fn (string $segment) => $segment !== '')); + return array_values(array_filter(explode('/', $this->path), static fn (string $segment) => $segment !== '')); } } @@ -53,6 +53,7 @@ final class Uri public function __construct( public readonly ?string $scheme = null, public readonly ?string $user = null, + #[\SensitiveParameter] public readonly ?string $password = null, public readonly ?string $host = null, public readonly ?int $port = null, @@ -103,7 +104,7 @@ public function withUser(string $user): self /** * Returns a new Uri with the provided password. */ - public function withPassword(string $password): self + public function withPassword(#[\SensitiveParameter] string $password): self { return $this->with( user: $this->user ?? '', @@ -215,6 +216,7 @@ public function withFragment(string $fragment): self private function with( ?string $scheme = null, ?string $user = null, + #[\SensitiveParameter] ?string $password = null, ?string $host = null, ?int $port = null, @@ -263,9 +265,7 @@ private function buildQueryString(array $query): ?string } $queryString = http_build_query($processedQuery, arg_separator: '&', encoding_type: PHP_QUERY_RFC3986); - $queryString = preg_replace('/([^=&]+)=(?=&|$)/', replacement: '$1', subject: $queryString); - - return $queryString; + return preg_replace('/([^=&]+)=(?=&|$)/', replacement: '$1', subject: $queryString); } /** diff --git a/packages/support/src/Uri/functions.php b/packages/support/src/Uri/functions.php index 325c5308a..deef4b786 100644 --- a/packages/support/src/Uri/functions.php +++ b/packages/support/src/Uri/functions.php @@ -123,7 +123,7 @@ function get_user(string $uri): ?string /** * Updates the given URI to use the provided password. */ -function set_password(string $uri, string $password): string +function set_password(string $uri, #[\SensitiveParameter] string $password): string { return Uri::from($uri)->withPassword($password)->toString(); } diff --git a/packages/support/tests/Arr/ManipulatesArrayTest.php b/packages/support/tests/Arr/ManipulatesArrayTest.php index 46744bc84..a7cb4dc13 100644 --- a/packages/support/tests/Arr/ManipulatesArrayTest.php +++ b/packages/support/tests/Arr/ManipulatesArrayTest.php @@ -203,7 +203,7 @@ public function test_unshift(): void public function test_last(): void { - $this->assertSame(null, arr()->last()); + $this->assertNull(arr()->last()); $this->assertSame('c', arr(['a', 'b', 'c'])->last()); $this->assertSame('foo', arr()->last(default: 'foo')); @@ -213,7 +213,7 @@ public function test_last(): void public function test_first(): void { $this->assertSame('a', arr(['a', 'b', 'c'])->first()); - $this->assertSame(null, arr()->first()); + $this->assertNull(arr()->first()); $this->assertSame('foo', arr()->first(default: 'foo')); $this->assertSame(1, arr([1, 2])->first(default: 'foo')); @@ -229,13 +229,13 @@ public function test_map(): void { $this->assertTrue( arr(['a', 'b']) - ->map(fn (string $value) => $value . 'x') + ->map(static fn (string $value) => $value . 'x') ->equals(['ax', 'bx']), ); $this->assertTrue( arr(['a', 'b']) - ->map(fn (string $value, mixed $key) => $value . $key) + ->map(static fn (string $value, mixed $key) => $value . $key) ->equals(['a0', 'b1']), ); } @@ -244,13 +244,13 @@ public function test_map_with_keys(): void { $this->assertTrue( arr(['a', 'b']) - ->mapWithKeys(fn (mixed $value, mixed $_) => yield $value => $value) + ->mapWithKeys(static fn (mixed $value, mixed $_) => yield $value => $value) ->equals(['a' => 'a', 'b' => 'b']), ); $this->assertTrue( arr(['a' => 'a', 'b' => 'b']) - ->mapWithKeys(fn (mixed $value, mixed $_) => yield $value) + ->mapWithKeys(static fn (mixed $value, mixed $_) => yield $value) ->equals(['b']), ); } @@ -260,7 +260,7 @@ public function test_map_with_keys_without_generator(): void $this->expectException(MapWithKeysDidNotUseAGenerator::class); arr(['a', 'b']) - ->mapWithKeys(fn (mixed $value, mixed $_) => $value); + ->mapWithKeys(static fn (mixed $value, mixed $_) => $value); } public function test_values(): void @@ -284,14 +284,14 @@ public function test_filter(): void $this->assertTrue( arr(['a', 'b', 'c']) - ->filter(fn (mixed $value) => $value === 'b') + ->filter(static fn (mixed $value) => $value === 'b') ->values() ->equals(['b']), ); $this->assertTrue( arr(['a', 'b', 'c']) - ->filter(fn (mixed $_, mixed $key) => $key === 1) + ->filter(static fn (mixed $_, mixed $key) => $key === 1) ->values() ->equals(['b']), ); @@ -311,7 +311,7 @@ public function test_each(): void $string = ''; arr(['a', 'b', 'c']) - ->each(function (mixed $value) use (&$string): void { + ->each(static function (mixed $value) use (&$string): void { $string .= $value; }); @@ -320,7 +320,7 @@ public function test_each(): void $string = ''; arr(['a', 'b', 'c']) - ->each(function (mixed $_, mixed $key) use (&$string): void { + ->each(static function (mixed $_, mixed $key) use (&$string): void { $string .= $key; }); @@ -338,14 +338,14 @@ public function test_contains(): void $this->assertTrue(arr(['a', 'b', 'c'])->hasValue('b')); $this->assertFalse(arr(['a', 'b', 'c'])->hasValue('d')); - $this->assertTrue(arr(['a', 'b', 'c'])->contains(fn (string $v) => $v === 'b')); - $this->assertFalse(arr(['a', 'b', 'c'])->contains(fn (string $v) => $v === 'd')); + $this->assertTrue(arr(['a', 'b', 'c'])->contains(static fn (string $v) => $v === 'b')); + $this->assertFalse(arr(['a', 'b', 'c'])->contains(static fn (string $v) => $v === 'd')); - $this->assertTrue(arr(['a', 'b', 'c'])->hasValue(fn (string $v) => $v === 'b')); - $this->assertFalse(arr(['a', 'b', 'c'])->hasValue(fn (string $v) => $v === 'd')); + $this->assertTrue(arr(['a', 'b', 'c'])->hasValue(static fn (string $v) => $v === 'b')); + $this->assertFalse(arr(['a', 'b', 'c'])->hasValue(static fn (string $v) => $v === 'd')); - $this->assertTrue(arr(['a', 'b', 'c'])->includes(fn (string $v) => $v === 'b')); - $this->assertFalse(arr(['a', 'b', 'c'])->includes(fn (string $v) => $v === 'd')); + $this->assertTrue(arr(['a', 'b', 'c'])->includes(static fn (string $v) => $v === 'b')); + $this->assertFalse(arr(['a', 'b', 'c'])->includes(static fn (string $v) => $v === 'd')); } public function test_explode(): void @@ -609,7 +609,7 @@ public function test_unique_callback(): void ]); $current = $collection - ->unique(fn (string $item) => $item[0]) + ->unique(static fn (string $item) => $item[0]) ->values() ->toArray(); @@ -1353,18 +1353,18 @@ public function test_sort_by_callback(): void // Test auto-detects key preservation $this->assertSame( ['a', 'b', 'c'], - arr(['c', 'a', 'b'])->sortByCallback(fn ($a, $b) => $a <=> $b)->toArray(), + arr(['c', 'a', 'b'])->sortByCallback(static fn ($a, $b) => $a <=> $b)->toArray(), ); $this->assertSame( [2 => 'a', 3 => 'b', 1 => 'c'], - $array->sortByCallback(fn ($a, $b) => $a <=> $b)->toArray(), + $array->sortByCallback(static fn ($a, $b) => $a <=> $b)->toArray(), ); $this->assertSame( expected: ['a', 'b', 'c'], actual: $array ->sortByCallback( - callback: fn ($a, $b) => $a <=> $b, + callback: static fn ($a, $b) => $a <=> $b, preserveKeys: false, ) ->toArray(), @@ -1373,7 +1373,7 @@ public function test_sort_by_callback(): void expected: [2 => 'a', 3 => 'b', 1 => 'c'], actual: $array ->sortByCallback( - callback: fn ($a, $b) => $a <=> $b, + callback: static fn ($a, $b) => $a <=> $b, preserveKeys: true, ) ->toArray(), @@ -1400,7 +1400,7 @@ public function test_sort_keys_by_callback(): void $this->assertSame( [1 => 'c', 2 => 'a', 3 => 'b'], - $array->sortKeysByCallback(fn ($a, $b) => $a <=> $b)->toArray(), + $array->sortKeysByCallback(static fn ($a, $b) => $a <=> $b)->toArray(), ); } @@ -1425,7 +1425,7 @@ public function test_flatmap(): void ['name' => 'Makise', 'hobbies' => ['Science', 'Programming']], ['name' => 'Okabe', 'hobbies' => ['Science', 'Anime']], ]) - ->flatMap(fn (array $person) => $person['hobbies']) + ->flatMap(static fn (array $person) => $person['hobbies']) ->equals(['Science', 'Programming', 'Science', 'Anime']), ); @@ -1449,7 +1449,7 @@ public function test_flatmap(): void $this->assertTrue( $likes - ->flatMap(fn (array $person) => $person['likes'], depth: 1) + ->flatMap(static fn (array $person) => $person['likes'], depth: 1) ->equals([ ['Tower of God', 'The Beginning After The End'], ['PHP', 'TypeScript'], @@ -1460,7 +1460,7 @@ public function test_flatmap(): void $this->assertTrue( $likes - ->flatMap(fn (array $person) => $person['likes'], depth: INF) + ->flatMap(static fn (array $person) => $person['likes'], depth: INF) ->equals([ 'Tower of God', 'The Beginning After The End', @@ -1482,7 +1482,7 @@ public function test_basic_reduce(): void ]); $this->assertSame( - $collection->reduce(fn ($carry, $value) => $carry . ' ' . $value, 'Hello'), + $collection->reduce(static fn ($carry, $value) => $carry . ' ' . $value, 'Hello'), 'Hello John Doe 42', ); } @@ -1504,7 +1504,7 @@ public function test_reduce_with_existing_function(): void public function test_empty_array_reduce(): void { $this->assertSame( - arr()->reduce(fn ($carry, $value) => $carry . ' ' . $value, 'default'), + arr()->reduce(static fn ($carry, $value) => $carry . ' ' . $value, 'default'), 'default', ); } @@ -1516,7 +1516,7 @@ public function test_chunk(): void $this->assertSame( $collection ->chunk(2, preserveKeys: false) - ->map(fn ($chunk) => $chunk->toArray()) + ->map(static fn ($chunk) => $chunk->toArray()) ->toArray(), [ [1, 2], @@ -1530,7 +1530,7 @@ public function test_chunk(): void $this->assertSame( $collection ->chunk(3, preserveKeys: false) - ->map(fn ($chunk) => $chunk->toArray()) + ->map(static fn ($chunk) => $chunk->toArray()) ->toArray(), [ [1, 2, 3], @@ -1548,7 +1548,7 @@ public function test_chunk_preserve_keys(): void $this->assertSame( $collection ->chunk(2) - ->map(fn ($chunk) => $chunk->toArray()) + ->map(static fn ($chunk) => $chunk->toArray()) ->toArray(), [ [0 => 1, 1 => 2], @@ -1562,7 +1562,7 @@ public function test_chunk_preserve_keys(): void $this->assertSame( $collection ->chunk(3) - ->map(fn ($chunk) => $chunk->toArray()) + ->map(static fn ($chunk) => $chunk->toArray()) ->toArray(), [ [0 => 1, 1 => 2, 2 => 3], @@ -1601,13 +1601,13 @@ public function test_find_key_with_closure(): void ['id' => 3, 'name' => 'Bob'], ]); - $result = $collection->findKey(fn ($item) => $item['name'] === 'Jane'); + $result = $collection->findKey(static fn ($item) => $item['name'] === 'Jane'); $this->assertSame(1, $result); - $result = $collection->findKey(fn ($_, $key) => $key === 2); + $result = $collection->findKey(static fn ($_, $key) => $key === 2); $this->assertSame(2, $result); - $result = $collection->findKey(fn ($item) => $item['name'] === 'Alice'); + $result = $collection->findKey(static fn ($item) => $item['name'] === 'Alice'); $this->assertNull($result); } @@ -1639,7 +1639,7 @@ public function test_find_key_with_complex_closure(): void ['age' => 35, 'active' => true], ]); - $result = $collection->findKey(function ($item) { + $result = $collection->findKey(static function ($item) { return $item['age'] > 28 && $item['active'] === true; }); @@ -1651,7 +1651,7 @@ public function test_find_key_with_empty_array(): void $collection = arr([]); $this->assertNull($collection->findKey('anything')); - $this->assertNull($collection->findKey(fn () => true)); + $this->assertNull($collection->findKey(static fn () => true)); } public function test_slice(): void @@ -1686,9 +1686,9 @@ public function test_slice(): void public function test_every(): void { - $this->assertTrue(arr([])->every(fn (int $value) => ($value % 2) === 0)); - $this->assertTrue(arr([2, 4, 6])->every(fn (int $value) => ($value % 2) === 0)); - $this->assertFalse(arr([1, 2, 4, 6])->every(fn (int $value) => ($value % 2) === 0)); + $this->assertTrue(arr([])->every(static fn (int $value) => ($value % 2) === 0)); + $this->assertTrue(arr([2, 4, 6])->every(static fn (int $value) => ($value % 2) === 0)); + $this->assertFalse(arr([1, 2, 4, 6])->every(static fn (int $value) => ($value % 2) === 0)); $this->assertTrue(arr([0, 1, true, false, ''])->every()); $this->assertFalse(arr([0, 1, true, false, '', null])->every()); } @@ -1738,7 +1738,7 @@ public function test_tap(): void $collection = arr(['foo']); $log = []; - $result = $collection->tap(function (ImmutableArray $array) use (&$log): void { + $result = $collection->tap(static function (ImmutableArray $array) use (&$log): void { $log[] = $array->first(); }); @@ -1786,7 +1786,7 @@ public function test_group_by(): void ['brand' => 'brand2', 'model' => 'model4'], ], ]) - ->equals($array->groupBy(fn ($item) => $item['brand'])), + ->equals($array->groupBy(static fn ($item) => $item['brand'])), ); } @@ -1809,7 +1809,7 @@ public function test_at(array $input, int $index, mixed $expected, mixed $defaul public function test_partition(): void { - $this->assertSame([[true, true], [false]], arr([true, true, false])->partition(fn (bool $value) => $value === true)->toArray()); + $this->assertSame([[true, true], [false]], arr([true, true, false])->partition(static fn (bool $value) => $value === true)->toArray()); } public function test_json_encode(): void diff --git a/packages/support/tests/Conditions/HasConditionsTest.php b/packages/support/tests/Conditions/HasConditionsTest.php index ee994570e..f76687938 100644 --- a/packages/support/tests/Conditions/HasConditionsTest.php +++ b/packages/support/tests/Conditions/HasConditionsTest.php @@ -20,7 +20,7 @@ public function test_when(): void public bool $value = false; }; - $class->when(true, fn ($c) => $c->value = true); + $class->when(true, static fn ($c) => $c->value = true); $this->assertTrue($class->value); } @@ -33,7 +33,7 @@ public function test_when_with_callback(): void public bool $value = false; }; - $class->when(fn () => true, fn ($c) => $c->value = true); + $class->when(static fn () => true, static fn ($c) => $c->value = true); $this->assertTrue($class->value); } @@ -46,7 +46,7 @@ public function test_unless(): void public bool $value = false; }; - $class->unless(true, fn ($c) => $c->value = true); + $class->unless(true, static fn ($c) => $c->value = true); $this->assertFalse($class->value); } @@ -59,7 +59,7 @@ public function test_unless_with_callback(): void public bool $value = false; }; - $class->unless(fn () => true, fn ($c) => $c->value = true); + $class->unless(static fn () => true, static fn ($c) => $c->value = true); $this->assertFalse($class->value); } @@ -80,7 +80,7 @@ public function append(string $string): self } }; - $class->when(true, function ($c): void { + $class->when(true, static function ($c): void { $c->append('bar'); }); diff --git a/packages/support/tests/Math/MathsTest.php b/packages/support/tests/Math/MathsTest.php index 937195336..994bbcf43 100644 --- a/packages/support/tests/Math/MathsTest.php +++ b/packages/support/tests/Math/MathsTest.php @@ -23,37 +23,37 @@ public function test_abs(int|float $expected, int|float $number): void } #[TestWith([0.0, 1.0])] - #[TestWith([1.2661036727794992, 0.3])] - #[TestWith([1.0471975511965979, 0.5])] + #[TestWith([1.266_103_672_779_499_2, 0.3])] + #[TestWith([1.047_197_551_196_597_9, 0.5])] public function test_acos(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\acos($number)); } - #[TestWith([0.5235987755982989, 0.5])] - #[TestWith([0.9272952180016123, 0.8])] + #[TestWith([0.523_598_775_598_298_9, 0.5])] + #[TestWith([0.927_295_218_001_612_3, 0.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.41151684606748806, 0.4])] + #[TestWith([0.411_516_846_067_488_06, 0.4])] public function test_asin(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\asin($number)); } - #[TestWith([0.7853981633974483, 1.0, 1.0])] - #[TestWith([0.8960553845713439, 1.0, 0.8])] + #[TestWith([0.785_398_163_397_448_3, 1.0, 1.0])] + #[TestWith([0.896_055_384_571_343_9, 1.0, 0.8])] #[TestWith([0.0, 0.0, 0.0])] - #[TestWith([0.7853981633974483, 0.4, 0.4])] - #[TestWith([-2.260001062633476, -0.5, -0.412])] + #[TestWith([0.785_398_163_397_448_3, 0.4, 0.4])] + #[TestWith([-2.260_001_062_633_476, -0.5, -0.412])] public function test_atan2(float $expected, float $y, float $x): void { $this->assertFloatEquals($expected, Math\atan2($y, $x)); } - #[TestWith([0.7853981633974483, 1.0])] - #[TestWith([0.6747409422235527, 0.8])] + #[TestWith([0.785_398_163_397_448_3, 1.0])] + #[TestWith([0.674_740_942_223_552_7, 0.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.3805063771123649, 0.4])] - #[TestWith([-0.4636476090008061, -0.5])] + #[TestWith([0.380_506_377_112_364_9, 0.4])] + #[TestWith([-0.463_647_609_000_806_1, -0.5])] public function test_atan(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\atan($number)); @@ -102,11 +102,11 @@ public function test_clamp_invalid_min_max(): void Math\clamp(10, 20, 10); } - #[TestWith([0.5403023058681398, 1.0])] + #[TestWith([0.540_302_305_868_139_8, 1.0])] #[TestWith([1.0, 0.0])] - #[TestWith([0.10291095660695612, 45.45])] - #[TestWith([0.28366218546322625, -5])] - #[TestWith([-0.9983206000589924, -15.65])] + #[TestWith([0.102_910_956_606_956_12, 45.45])] + #[TestWith([0.283_662_185_463_226_25, -5])] + #[TestWith([-0.998_320_600_058_992_4, -15.65])] public function test_cos(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\cos($number)); @@ -137,9 +137,9 @@ public function test_div_int64_min_by_minus_one(): void Math\div(Math\INT64_MIN, -1); } - #[TestWith([162754.79141900392, 12.0])] - #[TestWith([298.8674009670603, 5.7])] - #[TestWith([Math\INFINITY, 1000000])] + #[TestWith([162_754.791_419_003_92, 12.0])] + #[TestWith([298.867_400_967_060_3, 5.7])] + #[TestWith([Math\INFINITY, 1_000_000])] public function test_exp(float $expected, float $number): void { $this->assertSame($expected, Math\exp($number)); @@ -156,7 +156,7 @@ public function test_floor(float $expected, float $number): void } #[TestWith([5497, '1010101111001', 2])] - #[TestWith([2014587925987, 'pphlmw9v', 36])] + #[TestWith([2_014_587_925_987, 'pphlmw9v', 36])] #[TestWith([Math\INT32_MAX, 'zik0zj', 36])] #[TestWith([15, 'F', 16])] public function test_from_base(int $expected, string $value, int $from_base): void @@ -190,9 +190,9 @@ public function test_throws_for_overflow(): void Math\from_base($number, 32); } - #[TestWith([1.6863989535702288, 5.4, null])] - #[TestWith([0.6574784600188808, 5.4, 13])] - #[TestWith([1.7323937598229686, 54.0, 10])] + #[TestWith([1.686_398_953_570_228_8, 5.4, null])] + #[TestWith([0.657_478_460_018_880_8, 5.4, 13])] + #[TestWith([1.732_393_759_822_968_6, 54.0, 10])] #[TestWith([0, 1, null])] public function test_log(float $expected, float $number, ?float $base = null): void { @@ -293,8 +293,8 @@ public static function provide_mean_cases(): array { return [ [5.0, [10, 5, 0, 2, 4, 6, 8]], - [7.357142857142858, [18, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]], - [26.785714285714285, [19, 15, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 52, 64]], + [7.357_142_857_142_858, [18, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]], + [26.785_714_285_714_285, [19, 15, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 52, 64]], [100.0, array_fill(0, 100, 100)], [null, []], ]; @@ -384,33 +384,33 @@ public static function provide_min_va_cases(): array ]; } - #[TestWith([5.46, 5.45663, 2])] + #[TestWith([5.46, 5.456_63, 2])] #[TestWith([4.8, 4.811, 1])] #[TestWith([5.0, 5.42, 0])] #[TestWith([5.0, 4.8, 0])] #[TestWith([0.0, 0.4242, 0])] #[TestWith([0.5, 0.4634, 1])] - #[TestWith([-6.57778, -6.5777777777, 5])] + #[TestWith([-6.577_78, -6.577_777_777_7, 5])] public function test_round(float $expected, float $number, int $precision = 0): void { $this->assertSame($expected, Math\round($number, $precision)); } - #[TestWith([-0.9589242746631385, 5.0])] - #[TestWith([-0.9961646088358407, 4.8])] + #[TestWith([-0.958_924_274_663_138_5, 5.0])] + #[TestWith([-0.996_164_608_835_840_7, 4.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.3894183423086505, 0.4])] - #[TestWith([-0.21511998808781552, -6.5])] + #[TestWith([0.389_418_342_308_650_5, 0.4])] + #[TestWith([-0.215_119_988_087_815_52, -6.5])] public function test_sin(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\sin($number)); } - #[TestWith([2.23606797749979, 5.0])] - #[TestWith([2.1908902300206643, 4.8])] - #[TestWith([0.6324555320336759, 0.4])] - #[TestWith([2.5495097567963922, 6.5])] - #[TestWith([1.4142135623730951, 2])] + #[TestWith([2.236_067_977_499_79, 5.0])] + #[TestWith([2.190_890_230_020_664_3, 4.8])] + #[TestWith([0.632_455_532_033_675_9, 0.4])] + #[TestWith([2.549_509_756_796_392_2, 6.5])] + #[TestWith([1.414_213_562_373_095_1, 2])] #[TestWith([1, 1])] public function test_sqrt(float $expected, float $number): void { @@ -426,7 +426,7 @@ public function test_sum_floats(float $expected, array $numbers): void public static function provide_sum_floats_data(): array { return [ - [116.70000000000005, [10.9, 5, ...range(0, 9.8798, 0.48)]], + [116.700_000_000_000_05, [10.9, 5, ...range(0, 9.8798, 0.48)]], [103.0, [18, 15, ...range(0, 10), 15]], [323.54, [19.5, 15.8, ...range(0.5, 45, 5.98), 52.8, 64]], ]; @@ -447,18 +447,18 @@ public static function provide_sum_data(): array ]; } - #[TestWith([-3.380515006246586, 5.0, 0.00000000000001])] - #[TestWith([-11.384870654242922, 4.8])] + #[TestWith([-3.380_515_006_246_586, 5.0, 0.000_000_000_000_01])] + #[TestWith([-11.384_870_654_242_922, 4.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.4227932187381618, 0.4])] - #[TestWith([-0.22027720034589682, -6.5])] + #[TestWith([0.422_793_218_738_161_8, 0.4])] + #[TestWith([-0.220_277_200_345_896_82, -6.5])] public function test_tan(float $expected, float $number, float $epsilon = PHP_FLOAT_EPSILON): void { $this->assertFloatEquals($expected, Math\tan($number), $epsilon); } #[TestWith(['1010101111001', 5497, 2])] - #[TestWith(['pphlmw9v', 2014587925987, 36])] + #[TestWith(['pphlmw9v', 2_014_587_925_987, 36])] #[TestWith(['zik0zj', Math\INT32_MAX, 36])] #[TestWith(['f', 15, 16])] public function test_to_base(string $expected, int $value, int $to_base): void diff --git a/packages/support/tests/Paginator/PaginatedDataTest.php b/packages/support/tests/Paginator/PaginatedDataTest.php index 48a1c7ea1..af99fb09e 100644 --- a/packages/support/tests/Paginator/PaginatedDataTest.php +++ b/packages/support/tests/Paginator/PaginatedDataTest.php @@ -65,7 +65,7 @@ public function it_checks_empty_status(): void public function it_maps_data_while_preserving_pagination(): void { $original = $this->createSamplePaginatedData([1, 2, 3]); - $mapped = $original->map(fn ($x) => $x * 2); + $mapped = $original->map(static fn ($x) => $x * 2); $this->assertSame([2, 4, 6], $mapped->data); $this->assertSame($original->currentPage, $mapped->currentPage); diff --git a/packages/support/tests/Paginator/PaginatorTest.php b/packages/support/tests/Paginator/PaginatorTest.php index c93a7b3fd..bba3dca08 100644 --- a/packages/support/tests/Paginator/PaginatorTest.php +++ b/packages/support/tests/Paginator/PaginatorTest.php @@ -140,7 +140,7 @@ public function test_it_creates_paginated_data_with_callback(): void { $paginator = $this->createPaginator(totalItems: 100, itemsPerPage: 10, currentPage: 3); - $dataFetcher = function (int $_limit, int $offset): array { + $dataFetcher = static function (int $_limit, int $offset): array { return ["item_{$offset}_1", "item_{$offset}_2"]; }; diff --git a/packages/support/tests/Path/PathTest.php b/packages/support/tests/Path/PathTest.php index 16fd78264..6a4fec6d1 100644 --- a/packages/support/tests/Path/PathTest.php +++ b/packages/support/tests/Path/PathTest.php @@ -15,7 +15,7 @@ public function test_glob(array $expected, string $input, string $glob): void $expected, new Path($input) ->glob($glob) - ->map(fn (string $path) => basename($path)) + ->map(static fn (string $path) => basename($path)) ->toArray(), ); } diff --git a/packages/support/tests/Regex/FunctionsTest.php b/packages/support/tests/Regex/FunctionsTest.php index 47e4b2033..50c471a30 100644 --- a/packages/support/tests/Regex/FunctionsTest.php +++ b/packages/support/tests/Regex/FunctionsTest.php @@ -53,8 +53,8 @@ public function test_replace(string $expected, string $subject, string $pattern, public function test_replace_with_callback(): void { - $this->assertSame('Hello, Jon!', replace('Hello, World!', '/World/', fn () => 'Jon')); - $this->assertSame('Count: 2', replace('Count: 1', '/\d/', fn (array $matches) => $matches[0] + 1)); + $this->assertSame('Hello, Jon!', replace('Hello, World!', '/World/', static fn () => 'Jon')); + $this->assertSame('Count: 2', replace('Count: 1', '/\d/', static fn (array $matches) => $matches[0] + 1)); } public function test_replace_with_invalid_pattern(): void @@ -87,7 +87,7 @@ public function test_get_match(): void $this->assertSame('10', get_match('10-abc', '/(\d+)-.*/', match: 1)); $this->assertSame([0 => '10-abc', 1 => '10'], get_match('10-abc', '/(\d+)-.*/')); $this->assertSame('10-abc', get_match('10-abc', '/\d+-.*/', match: 0)); - $this->assertSame(null, get_match('10-abc', '/\d+-.*/', match: 1)); + $this->assertNull(get_match('10-abc', '/\d+-.*/', match: 1)); $this->assertSame( expected: [ diff --git a/packages/support/tests/Str/FunctionsTest.php b/packages/support/tests/Str/FunctionsTest.php index 0f8278043..ee16f2315 100644 --- a/packages/support/tests/Str/FunctionsTest.php +++ b/packages/support/tests/Str/FunctionsTest.php @@ -16,7 +16,7 @@ public function test_parse(): void $this->assertSame('1', Str\parse('1')); $this->assertSame('1', Str\parse(1)); $this->assertSame('', Str\parse(new stdClass())); - $this->assertSame(null, Str\parse(new stdClass(), default: null)); + $this->assertNull(Str\parse(new stdClass(), default: null)); $this->assertSame('', Str\parse(new stdClass(), default: '')); $this->assertSame('foo', Str\parse(new stdClass(), default: 'foo')); $this->assertSame('foo', Str\parse(new MutableString('foo'))); diff --git a/packages/support/tests/Str/ManipulatesStringTest.php b/packages/support/tests/Str/ManipulatesStringTest.php index 64778ab8a..82627fff6 100644 --- a/packages/support/tests/Str/ManipulatesStringTest.php +++ b/packages/support/tests/Str/ManipulatesStringTest.php @@ -322,7 +322,7 @@ public function test_matches(): void public function test_replace_regex(): void { $this->assertTrue(str('10-abc')->replaceRegex('/(?\d+-)/', '')->equals('abc')); - $this->assertTrue(str('10-abc')->replaceRegex('/(?\d+-)/', fn () => '')->equals('abc')); + $this->assertTrue(str('10-abc')->replaceRegex('/(?\d+-)/', static fn () => '')->equals('abc')); $this->assertTrue(str('10-abc')->replaceRegex(['/\d/', '/\w/'], ['#', 'X'])->equals('##-XXX')); } @@ -594,7 +594,7 @@ public function test_tap(): void $string = str('foo'); $log = ''; - $result = $string->tap(function (ImmutableString $string) use (&$log): void { + $result = $string->tap(static function (ImmutableString $string) use (&$log): void { $log .= $string->toString(); }); diff --git a/packages/validation/src/Validator.php b/packages/validation/src/Validator.php index 7c692884f..a4dd9c2b0 100644 --- a/packages/validation/src/Validator.php +++ b/packages/validation/src/Validator.php @@ -157,7 +157,7 @@ public function validateValueForProperty(PropertyReflector $property, mixed $val return Arr\map( array: $this->validateValue($value, $rules), - map: fn (FailingRule $rule) => $rule->withKey($key), + map: static fn (FailingRule $rule) => $rule->withKey($key), ); } @@ -264,7 +264,7 @@ private function getTranslationKey(Rule|FailingRule $rule): string 'i_pv4' => 'ipv4', 'reg_ex' => 'regex', ]) - ->when($key !== '', fn ($s) => $s->append('.', $key)) + ->when($key !== '', static fn ($s) => $s->append('.', $key)) ->toString(); } diff --git a/packages/validation/tests/Rules/IsJsonStringTest.php b/packages/validation/tests/Rules/IsJsonStringTest.php index 0003c143f..dc94da5f0 100644 --- a/packages/validation/tests/Rules/IsJsonStringTest.php +++ b/packages/validation/tests/Rules/IsJsonStringTest.php @@ -37,7 +37,7 @@ public function test_it_allows_to_specify_flags(): void { // Not sure if there is a better way of asserting that a php function was called with a given argument $this->expectException(ValueError::class); - $rule = new IsJsonString(flags: 232312312); // we intentionally send something that is not valid + $rule = new IsJsonString(flags: 232_312_312); // we intentionally send something that is not valid $rule->isValid('{"test": "test"}'); } } diff --git a/packages/validation/tests/Rules/IsPasswordTest.php b/packages/validation/tests/Rules/IsPasswordTest.php index 09b306e65..964d5d84a 100644 --- a/packages/validation/tests/Rules/IsPasswordTest.php +++ b/packages/validation/tests/Rules/IsPasswordTest.php @@ -23,8 +23,8 @@ public function test_defaults(): void public function test_invalid_input(): void { $rule = new IsPassword(); - $this->assertFalse($rule->isValid(123456789012)); - $this->assertFalse($rule->isValid([123456789012])); + $this->assertFalse($rule->isValid(123_456_789_012)); + $this->assertFalse($rule->isValid([123_456_789_012])); } public function test_minimum(): void diff --git a/packages/validation/tests/Rules/ValidateWithTest.php b/packages/validation/tests/Rules/ValidateWithTest.php index 8e7b9996b..62323e3db 100644 --- a/packages/validation/tests/Rules/ValidateWithTest.php +++ b/packages/validation/tests/Rules/ValidateWithTest.php @@ -45,7 +45,7 @@ public function test_non_string_value_fails(): void { $rule = new ValidateWith(static fn (mixed $value): bool => str_contains((string) $value, '@')); - $this->assertFalse($rule->isValid(12345)); + $this->assertFalse($rule->isValid(12_345)); $this->assertFalse($rule->isValid(null)); $this->assertFalse($rule->isValid(false)); } @@ -54,6 +54,6 @@ public function test_static_closure_required(): void { $this->expectException(\InvalidArgumentException::class); - new ValidateWith(fn (mixed $value): bool => str_contains((string) $value, '@')); + new ValidateWith(static fn (mixed $value): bool => str_contains((string) $value, '@')); } } diff --git a/packages/validation/tests/ValidatorTest.php b/packages/validation/tests/ValidatorTest.php index 6631364a9..fbd48a5fb 100644 --- a/packages/validation/tests/ValidatorTest.php +++ b/packages/validation/tests/ValidatorTest.php @@ -51,7 +51,7 @@ public function test_validate_value(): void public function test_closure_fails_with_false_response(): void { - $failingRules = $this->validator->validateValue('a', function (mixed $_) { + $failingRules = $this->validator->validateValue('a', static function (mixed $_) { return false; }); @@ -60,7 +60,7 @@ public function test_closure_fails_with_false_response(): void public function test_closure_fails_with_string_response(): void { - $failingRules = $this->validator->validateValue('a', function (mixed $_) { + $failingRules = $this->validator->validateValue('a', static function (mixed $_) { return 'I expected b'; }); @@ -74,7 +74,7 @@ public function test_closure_fails_with_string_response(): void public function test_closure_passes_with_null_response(): void { $validator = $this->validator; - $validator->validateValue('a', function (mixed $_) { + $validator->validateValue('a', static function (mixed $_) { return null; }); @@ -84,7 +84,7 @@ public function test_closure_passes_with_null_response(): void public function test_closure_passes_with_true_response(): void { $validator = $this->validator; - $validator->validateValue('a', function (mixed $_) { + $validator->validateValue('a', static function (mixed $_) { return true; }); @@ -95,11 +95,11 @@ public function test_closure_passes(): void { $validator = $this->validator; - $validator->validateValue('a', function (mixed $value) { + $validator->validateValue('a', static function (mixed $value) { return $value === 'a'; }); - $validator->validateValue('a', function (mixed $value) { + $validator->validateValue('a', static function (mixed $value) { if ($value === 'a') { return true; } diff --git a/packages/view/src/Elements/ElementFactory.php b/packages/view/src/Elements/ElementFactory.php index 2ee353519..dc0ad9b19 100644 --- a/packages/view/src/Elements/ElementFactory.php +++ b/packages/view/src/Elements/ElementFactory.php @@ -42,7 +42,7 @@ public function withIsHtml(bool $isHtml): self return $clone; } - public function make(Token $token, Element $parent): ?Element + public function make(#[\SensitiveParameter] Token $token, Element $parent): ?Element { if ( $token->type === TokenType::OPEN_TAG_END diff --git a/packages/view/src/Elements/GenericElement.php b/packages/view/src/Elements/GenericElement.php index b0266a9b7..ff2e25f6e 100644 --- a/packages/view/src/Elements/GenericElement.php +++ b/packages/view/src/Elements/GenericElement.php @@ -15,6 +15,7 @@ final class GenericElement implements Element, WithToken use IsElement; public function __construct( + #[\SensitiveParameter] public readonly Token $token, private readonly string $tag, private readonly bool $isHtml, diff --git a/packages/view/src/Elements/IsElement.php b/packages/view/src/Elements/IsElement.php index 415566d21..e41eeeb84 100644 --- a/packages/view/src/Elements/IsElement.php +++ b/packages/view/src/Elements/IsElement.php @@ -37,10 +37,12 @@ public function getAttributes(): array $tailingAttributes = []; foreach ($attributes as $name => $value) { - if ($name === ':foreach' || $name === ':if') { - unset($attributes[$name]); - $tailingAttributes[$name] = $value; + if (! ($name === ':foreach' || $name === ':if')) { + continue; } + + unset($attributes[$name]); + $tailingAttributes[$name] = $value; } // Tailing attributes are reversed because they need to be applied in reverse order diff --git a/packages/view/src/Elements/PhpElement.php b/packages/view/src/Elements/PhpElement.php index a75cb3577..db5f2c1a2 100644 --- a/packages/view/src/Elements/PhpElement.php +++ b/packages/view/src/Elements/PhpElement.php @@ -13,6 +13,7 @@ final class PhpElement implements Element, WithToken use IsElement; public function __construct( + #[\SensitiveParameter] public readonly Token $token, private readonly string $content, ) {} diff --git a/packages/view/src/Elements/RawElement.php b/packages/view/src/Elements/RawElement.php index cb071cea8..08ee565de 100644 --- a/packages/view/src/Elements/RawElement.php +++ b/packages/view/src/Elements/RawElement.php @@ -15,6 +15,7 @@ final class RawElement implements Element, WithToken use IsElement; public function __construct( + #[\SensitiveParameter] public readonly Token $token, private readonly ?string $tag, private readonly string $content, diff --git a/packages/view/src/Elements/RootElement.php b/packages/view/src/Elements/RootElement.php index ec54f92a3..088d6a875 100644 --- a/packages/view/src/Elements/RootElement.php +++ b/packages/view/src/Elements/RootElement.php @@ -29,9 +29,11 @@ public function getImports(): array $this->mergeImports($imports, $this->inheritedImports); foreach ($this->children as $child) { - if ($child instanceof PhpElement) { - $this->mergeImports($imports, $child->getImports()); + if (! $child instanceof PhpElement) { + continue; } + + $this->mergeImports($imports, $child->getImports()); } return array_values($imports); diff --git a/packages/view/src/Elements/SlotElement.php b/packages/view/src/Elements/SlotElement.php index c40a65e81..ab751db8c 100644 --- a/packages/view/src/Elements/SlotElement.php +++ b/packages/view/src/Elements/SlotElement.php @@ -13,6 +13,7 @@ final class SlotElement implements Element, WithToken use IsElement; public function __construct( + #[\SensitiveParameter] public readonly Token $token, public readonly string $name, array $attributes = [], diff --git a/packages/view/src/Elements/TemplateElement.php b/packages/view/src/Elements/TemplateElement.php index ed14d8357..596792c1c 100644 --- a/packages/view/src/Elements/TemplateElement.php +++ b/packages/view/src/Elements/TemplateElement.php @@ -13,6 +13,7 @@ final class TemplateElement implements Element, WithToken use IsElement; public function __construct( + #[\SensitiveParameter] public readonly Token $token, array $attributes = [], ) { diff --git a/packages/view/src/Elements/TextElement.php b/packages/view/src/Elements/TextElement.php index 41db6c590..56d38ad18 100644 --- a/packages/view/src/Elements/TextElement.php +++ b/packages/view/src/Elements/TextElement.php @@ -22,14 +22,14 @@ public function compile(): string // Render {{ ->replaceRegex( regex: '/{{(?.*?)}}/', - replace: function (array $matches): string { + replace: static function (array $matches): string { return sprintf('escape(%s); ?>', $matches['match']); }, ) // Render {!! ->replaceRegex( regex: '/{!!(?.*?)!!}/', - replace: function (array $matches): string { + replace: static function (array $matches): string { return sprintf('', $matches['match']); }, ) diff --git a/packages/view/src/Elements/ViewComponentElement.php b/packages/view/src/Elements/ViewComponentElement.php index 4f42d0627..02292a935 100644 --- a/packages/view/src/Elements/ViewComponentElement.php +++ b/packages/view/src/Elements/ViewComponentElement.php @@ -34,6 +34,7 @@ final class ViewComponentElement implements Element, WithToken private ImmutableArray $viewComponentAttributes; public function __construct( + #[\SensitiveParameter] public readonly Token $token, private readonly Environment $environment, private readonly TempestViewCompiler $compiler, @@ -44,16 +45,16 @@ public function __construct( $this->attributes = $attributes; $this->viewComponentAttributes = arr($attributes) - ->mapWithKeys(fn (string $value, string $key) => yield str($key)->ltrim(':')->toString() => $value); + ->mapWithKeys(static fn (string $value, string $key) => yield str($key)->ltrim(':')->toString() => $value); $this->dataAttributes = arr($attributes) - ->filter(fn (string $_, string $key) => ! str_starts_with($key, ':')) - ->mapWithKeys(fn (string $value, string $key) => yield str($key)->camel()->toString() => $value); + ->filter(static fn (string $_, string $key) => ! str_starts_with($key, ':')) + ->mapWithKeys(static fn (string $value, string $key) => yield str($key)->camel()->toString() => $value); $this->expressionAttributes = arr($attributes) - ->filter(fn (string $_, string $key) => str_starts_with($key, ':')) - ->filter(fn (string $_, string $key) => ! in_array($key, [':if', ':else', ':elseif', ':foreach', ':forelse'], strict: true)) - ->mapWithKeys(fn (string $value, string $key) => yield str($key)->camel()->ltrim(':')->toString() => $value ?: 'true'); + ->filter(static fn (string $_, string $key) => str_starts_with($key, ':')) + ->filter(static fn (string $_, string $key) => ! in_array($key, [':if', ':else', ':elseif', ':foreach', ':forelse'], strict: true)) + ->mapWithKeys(static fn (string $value, string $key) => yield str($key)->camel()->ltrim(':')->toString() => $value ?: 'true'); $this->scopedVariables = arr(); } @@ -106,9 +107,9 @@ public function compile(): string ->prepend( 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(static fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', + $this->expressionAttributes->isNotEmpty() ? ', ' . $this->expressionAttributes->map(static fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', + $this->scopedVariables->isNotEmpty() ? ', ' . $this->scopedVariables->map(static fn (string $name) => "\${$name}")->implode(', ') : '', ), ) ->append('viewCache->getCachedViewPath( $cacheKey, - fn () => $compiledView->content, + static fn () => $compiledView->content, ); $this->viewCache->saveSourceMap($cachePath, $compiledView->sourcePath, $compiledView->lineMap); @@ -171,16 +172,16 @@ public function compile(): string $this->exportAttributesArray(), ViewObjectExporter::export($slots), $this->scopedVariables->isNotEmpty() - ? $this->scopedVariables->map(fn (string $name) => "'{$name}' => \${$name}")->implode(', ') + ? $this->scopedVariables->map(static 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(static 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(static fn (mixed $value, string $key) => "{$key}: " . $value)->implode(', ') : '', $this->scopedVariables->isNotEmpty() - ? ', ' . $this->scopedVariables->map(fn (string $name) => "{$name}: \${$name}")->implode(', ') + ? ', ' . $this->scopedVariables->map(static fn (string $name) => "{$name}: \${$name}")->implode(', ') : '', ); } @@ -215,18 +216,18 @@ private function applyFallthroughAttributes(ImmutableString $compiled): Immutabl $token = TempestViewParser::ast($matches[0])[0]; $attributes = arr($token->htmlAttributes) - ->map(fn (string $value) => new MutableString($value)); + ->map(static fn (string $value) => new MutableString($value)); foreach (['class', 'style', 'id'] as $name) { $attributes = $this->applyFallthroughAttribute($attributes, $name); } $attributeString = $attributes - ->map(fn (MutableString $value, string $key) => sprintf('%s="%s"', $key, $value->trim())) + ->map(static fn (MutableString $value, string $key) => sprintf('%s="%s"', $key, $value->trim())) ->implode(' ') ->when( - fn (ImmutableString $s) => $s->isNotEmpty(), - fn (ImmutableString $s) => $s->prepend(' '), + static fn (ImmutableString $s) => $s->isNotEmpty(), + static fn (ImmutableString $s) => $s->prepend(' '), ); return sprintf('<%s%s>', $matches['tag'], $attributeString); @@ -288,9 +289,11 @@ public function getImports(): array } foreach ($this->getChildren() as $child) { - if ($child instanceof PhpElement) { - $imports = [...$imports, ...$child->getImports()]; + if (! $child instanceof PhpElement) { + continue; } + + $imports = [...$imports, ...$child->getImports()]; } return $imports; diff --git a/packages/view/src/Export/ViewObjectExporter.php b/packages/view/src/Export/ViewObjectExporter.php index 9d736e3f7..6b4c588d0 100644 --- a/packages/view/src/Export/ViewObjectExporter.php +++ b/packages/view/src/Export/ViewObjectExporter.php @@ -17,7 +17,7 @@ public static function export(ExportableViewObject|ImmutableArray $object): stri $object::class, $object ->exportData - ->map(function (mixed $value, string $key) { + ->map(static function (mixed $value, string $key) { $value = self::exportValue($value); return "{$key} : {$value}"; @@ -33,7 +33,7 @@ public static function exportValue(mixed $value): string $value instanceof ImmutableArray => sprintf( 'new \%s([%s])', ImmutableArray::class, - $value->map(function (mixed $value, string|int $key) { + $value->map(static function (mixed $value, string|int $key) { $key = is_int($key) ? $key : "'{$key}'"; return $key . ' => ' . rtrim(self::exportValue($value), ';'); diff --git a/packages/view/src/Initializers/ViewCacheInitializer.php b/packages/view/src/Initializers/ViewCacheInitializer.php index 14befdca9..f1e3c888c 100644 --- a/packages/view/src/Initializers/ViewCacheInitializer.php +++ b/packages/view/src/Initializers/ViewCacheInitializer.php @@ -15,11 +15,9 @@ final class ViewCacheInitializer implements Initializer #[Singleton] public function initialize(Container $container): ViewCache { - $viewCache = new ViewCache( + return new ViewCache( enabled: $this->shouldCacheBeEnabled(), ); - - return $viewCache; } private function shouldCacheBeEnabled(): bool diff --git a/packages/view/src/Parser/TempestViewAst.php b/packages/view/src/Parser/TempestViewAst.php index 379e9564c..5921e892a 100644 --- a/packages/view/src/Parser/TempestViewAst.php +++ b/packages/view/src/Parser/TempestViewAst.php @@ -14,7 +14,7 @@ public function __construct( private(set) bool $isHtml = true; - public function add(Token $token): self + public function add(#[\SensitiveParameter] Token $token): self { if ($token->type === TokenType::XML) { $this->isHtml = false; @@ -28,7 +28,7 @@ public function add(Token $token): self public function compile(): string { return implode('', array_map( - fn (Token $token) => $token->compile(), + static fn (#[\SensitiveParameter] Token $token) => $token->compile(), iterator_to_array($this->tokens), )); } diff --git a/packages/view/src/Parser/TempestViewCompiler.php b/packages/view/src/Parser/TempestViewCompiler.php index 0a7b21d70..65bb9e5d6 100644 --- a/packages/view/src/Parser/TempestViewCompiler.php +++ b/packages/view/src/Parser/TempestViewCompiler.php @@ -118,7 +118,7 @@ private function retrieveTemplate(string|View $view): array $searchPathOptions = [ ...$searchPathOptions, ...arr($this->discoveryLocations) - ->map(fn (DiscoveryLocation $discoveryLocation) => path($discoveryLocation->path, $path)->toString()) + ->map(static fn (DiscoveryLocation $discoveryLocation) => path($discoveryLocation->path, $path)->toString()) ->toArray(), ]; @@ -273,7 +273,7 @@ private function cleanupCompiled(string $compiled, ?string $sourcePath, array $i $imports[$import] = $import; } - $compiled = $compiled->replaceRegex("/^\s*use (function )?.*;/m", function (array $matches) use (&$imports) { + $compiled = $compiled->replaceRegex("/^\s*use (function )?.*;/m", static function (array $matches) use (&$imports) { // The import contains escaped slashes, meaning it's a var_exported string; we can ignore those if (str_contains($matches[0], '\\\\')) { return $matches[0]; diff --git a/packages/view/src/Parser/TempestViewParser.php b/packages/view/src/Parser/TempestViewParser.php index 77309107b..85455a22b 100644 --- a/packages/view/src/Parser/TempestViewParser.php +++ b/packages/view/src/Parser/TempestViewParser.php @@ -66,7 +66,7 @@ public function parse(): TempestViewAst return $ast; } - private function openScope(Token $token): void + private function openScope(#[\SensitiveParameter] Token $token): void { $this->scope[] = $token; } diff --git a/packages/view/src/Parser/Token.php b/packages/view/src/Parser/Token.php index 007196160..3ae394733 100644 --- a/packages/view/src/Parser/Token.php +++ b/packages/view/src/Parser/Token.php @@ -60,7 +60,7 @@ public function getAttribute(string $name): null|string|bool return $this->htmlAttributes[$name] ?? null; } - public function addAttribute(Token $token): void + public function addAttribute(#[\SensitiveParameter] Token $token): void { $this->rawAttributes[] = $token; @@ -71,18 +71,18 @@ public function addAttribute(Token $token): void } } - public function setAttributeValue(string $name, Token $token): void + public function setAttributeValue(string $name, #[\SensitiveParameter] Token $token): void { $this->rawAttributes[] = $token; $this->htmlAttributes[$this->attributeName($name)] = $this->attributeValue($token->content); } - public function setEndingToken(Token $endingToken): void + public function setEndingToken(#[\SensitiveParameter] Token $endingToken): void { $this->endingToken = $endingToken; } - public function setClosingToken(Token $closingToken): void + public function setClosingToken(#[\SensitiveParameter] Token $closingToken): void { if ($closingToken->tag && $this->tag !== $closingToken->tag) { throw new ClosingTagWasInvalid($this->tag, $closingToken->tag); diff --git a/packages/view/src/Parser/TokenCollection.php b/packages/view/src/Parser/TokenCollection.php index b2f63a95a..4044d4088 100644 --- a/packages/view/src/Parser/TokenCollection.php +++ b/packages/view/src/Parser/TokenCollection.php @@ -16,7 +16,7 @@ public function __construct( private array $tokens = [], ) {} - public function add(Token $token): self + public function add(#[\SensitiveParameter] Token $token): self { $this->tokens[] = $token; @@ -33,7 +33,7 @@ public function __debugInfo(): array return [ implode( ', ' . PHP_EOL, - array_map(fn (Token $token) => $token->__debugInfo()[0], $this->tokens), + array_map(static fn (#[\SensitiveParameter] Token $token) => $token->__debugInfo()[0], $this->tokens), ), ]; } diff --git a/packages/view/src/Slot.php b/packages/view/src/Slot.php index 6d65f56f8..28108e485 100644 --- a/packages/view/src/Slot.php +++ b/packages/view/src/Slot.php @@ -49,7 +49,7 @@ public function __get(string $name): mixed return $this->attributes[$name] ?? null; } - public static function named(Token $token): self + public static function named(#[\SensitiveParameter] Token $token): self { $name = $token->getAttribute('name'); $attributes = $token->htmlAttributes; diff --git a/packages/view/src/ViewCachePool.php b/packages/view/src/ViewCachePool.php index 81e68393d..c0063ace6 100644 --- a/packages/view/src/ViewCachePool.php +++ b/packages/view/src/ViewCachePool.php @@ -58,7 +58,7 @@ public function clear(): bool $path = path($this->directory); if ($path->isDirectory()) { - $path->glob('/*.php')->each(fn (string $file) => unlink($file)); + $path->glob('/*.php')->each(static fn (string $file) => unlink($file)); Filesystem\delete_directory($this->directory); } diff --git a/packages/view/src/functions.php b/packages/view/src/functions.php index 49c43d5f0..ce34bc3fd 100644 --- a/packages/view/src/functions.php +++ b/packages/view/src/functions.php @@ -4,9 +4,6 @@ namespace Tempest\View; -use Tempest\View\GenericView; -use Tempest\View\View; - /** * Returns a {@see View} instance for the specified `$path`. */ diff --git a/packages/view/tests/ViewCachePoolTest.php b/packages/view/tests/ViewCachePoolTest.php index bb87c8c71..5e9029ede 100644 --- a/packages/view/tests/ViewCachePoolTest.php +++ b/packages/view/tests/ViewCachePoolTest.php @@ -33,7 +33,7 @@ protected function tearDown(): void $directory = path(self::DIRECTORY); if ($directory->isDirectory()) { - $directory->glob('/*.php')->each(fn (string $file) => unlink($file)); + $directory->glob('/*.php')->each(static fn (string $file) => unlink($file)); rmdir(self::DIRECTORY); } diff --git a/packages/vite/src/Installer/ViteInstaller.php b/packages/vite/src/Installer/ViteInstaller.php index 4c428a5cd..8110132ca 100644 --- a/packages/vite/src/Installer/ViteInstaller.php +++ b/packages/vite/src/Installer/ViteInstaller.php @@ -69,7 +69,7 @@ public function install(): void } // Installs package.json scripts - $this->updateJson(root_path('package.json'), function (array $json) { + $this->updateJson(root_path('package.json'), static function (array $json) { $json['type'] = 'module'; $json['scripts'] ??= []; $json['scripts'] = [ diff --git a/packages/vite/src/Manifest/Manifest.php b/packages/vite/src/Manifest/Manifest.php index 1f82888e3..98026bd2b 100644 --- a/packages/vite/src/Manifest/Manifest.php +++ b/packages/vite/src/Manifest/Manifest.php @@ -25,11 +25,11 @@ private function __construct( public static function fromArray(array $chunks): self { - $chunks = arr($chunks)->map(fn (array $value) => Chunk::fromArray($value)); + $chunks = arr($chunks)->map(static fn (array $value) => Chunk::fromArray($value)); return new self( chunks: $chunks, - entrypoints: $chunks->filter(fn (Chunk $entry) => $entry->isEntry), + entrypoints: $chunks->filter(static fn (Chunk $entry) => $entry->isEntry), ); } } diff --git a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php index ab8b83a1c..8ce64d27f 100644 --- a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php +++ b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php @@ -59,8 +59,8 @@ private function fileToAssetPath(string $file): string { return str($file) ->when( - condition: fn ($file) => $file->startsWith('./'), - callback: fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), + condition: static fn ($file) => $file->startsWith('./'), + callback: static fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), ) ->replace('\\', '/') // `realpath` makes slashes backwards, so replacements below wouldn't work ->replaceStart(root_path('public'), '') diff --git a/packages/vite/src/TagsResolver/ManifestTagsResolver.php b/packages/vite/src/TagsResolver/ManifestTagsResolver.php index f5f526307..42ee96247 100644 --- a/packages/vite/src/TagsResolver/ManifestTagsResolver.php +++ b/packages/vite/src/TagsResolver/ManifestTagsResolver.php @@ -91,7 +91,7 @@ private function getStyleTags(Chunk $chunk): array return array_merge( $styleChunks, - array_map(fn (string $path) => ['file' => $path], $chunk->css), + array_map(static fn (string $path) => ['file' => $path], $chunk->css), ); }; @@ -179,7 +179,7 @@ private function resolvePrefetchingScript(Chunk $chunk): ?string }; $assets = array_values(array_map( - callback: fn (array $asset) => array_map('strval', $asset), + callback: static fn (array $asset) => array_map('strval', $asset), array: array_unique($findPrefetchableAssets($chunk), flags: SORT_REGULAR), )); @@ -253,8 +253,8 @@ private function fileToAssetPath(string $file): string { return str($file) ->when( - condition: fn ($file) => $file->startsWith('./'), - callback: fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), + condition: static fn ($file) => $file->startsWith('./'), + callback: static fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), ) ->replaceStart(root_path('public'), '') ->replaceStart(root_path(), '') diff --git a/packages/vite/src/ViteDiscovery.php b/packages/vite/src/ViteDiscovery.php index ffbde22b3..4ab4d0ed2 100644 --- a/packages/vite/src/ViteDiscovery.php +++ b/packages/vite/src/ViteDiscovery.php @@ -9,7 +9,6 @@ use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; use Tempest\Reflection\ClassReflector; -use Tempest\Vite\ViteConfig; use function Tempest\Support\str; diff --git a/packages/vite/src/functions.php b/packages/vite/src/functions.php index b217c0504..217fb0e4d 100644 --- a/packages/vite/src/functions.php +++ b/packages/vite/src/functions.php @@ -4,8 +4,6 @@ namespace Tempest\Vite; -use Tempest\Vite\Vite; - use function Tempest\Container\get; /** diff --git a/src/Tempest/Framework/Commands/ConfigShowCommand.php b/src/Tempest/Framework/Commands/ConfigShowCommand.php index aba4447db..90427dab7 100644 --- a/src/Tempest/Framework/Commands/ConfigShowCommand.php +++ b/src/Tempest/Framework/Commands/ConfigShowCommand.php @@ -103,14 +103,14 @@ private function searchConfigFile(array $configs): string $return = $this->console->search( label: 'Which configuration file would you like to view?', - search: function (string $query) use ($data): array { + search: static function (string $query) use ($data): array { if ($query === '') { return $data; } return array_filter( array: $data, - callback: fn (string $path) => str_contains($path, $query), + callback: static fn (string $path) => str_contains($path, $query), ); }, default: $data[0], diff --git a/src/Tempest/Framework/Commands/MetaViewComponentCommand.php b/src/Tempest/Framework/Commands/MetaViewComponentCommand.php index 1ce98f187..5f47752cd 100644 --- a/src/Tempest/Framework/Commands/MetaViewComponentCommand.php +++ b/src/Tempest/Framework/Commands/MetaViewComponentCommand.php @@ -62,7 +62,7 @@ private function resolveViewComponent(string $viewComponent): ?ViewComponent if (is_file($viewComponent)) { return array_find( array: $this->viewConfig->viewComponents, - callback: fn ($registeredViewComponent) => $registeredViewComponent->file === $viewComponent, + callback: static fn ($registeredViewComponent) => $registeredViewComponent->file === $viewComponent, ); } @@ -74,7 +74,7 @@ private function resolveSlots(ViewComponent $viewComponent): ImmutableArray preg_match_all('/[\w-]+)")?((\s*\/>)|>(?(.|\n)*?)<\/x-slot>)/', $viewComponent->contents, $matches); return arr($matches['name']) - ->mapWithKeys(fn (string $name) => yield $name => $name === '' ? Slot::DEFAULT : $name) + ->mapWithKeys(static fn (string $name) => yield $name => $name === '' ? Slot::DEFAULT : $name) ->values(); } @@ -82,19 +82,19 @@ private function resolveVariables(ViewComponent $viewComponent): ImmutableArray { return str($viewComponent->contents) ->matchAll('/^\s*\*\s*@var.*$/m') - ->map(fn (array $matches) => str($matches[0])) - ->map(fn (ImmutableString $line) => $line->replaceRegex('/^\s*\*\s*@var\s*/', '')) - ->map(fn (ImmutableString $line) => $line->trim()) - ->map(fn (ImmutableString $line) => $line->explode(limit: 3)) + ->map(static fn (array $matches) => str($matches[0])) + ->map(static fn (ImmutableString $line) => $line->replaceRegex('/^\s*\*\s*@var\s*/', '')) + ->map(static fn (ImmutableString $line) => $line->trim()) + ->map(static fn (ImmutableString $line) => $line->explode(limit: 3)) ->mapWithKeys( - fn (ImmutableArray $parts) => yield $parts[1] => [ + static fn (ImmutableArray $parts) => yield $parts[1] => [ 'type' => $parts[0], 'name' => $parts[1], 'attributeName' => str($parts[1])->kebab()->ltrim('$'), 'description' => $parts[2] ?? null, ], ) - ->filter(fn (array $parts) => ! in_array($parts['name'], ['$this', '$attributes', '$slots'], strict: true)) + ->filter(static fn (array $parts) => ! in_array($parts['name'], ['$this', '$attributes', '$slots'], strict: true)) ->values(); } } diff --git a/src/Tempest/Framework/Installers/FrameworkInstaller.php b/src/Tempest/Framework/Installers/FrameworkInstaller.php index b6174f248..966531470 100644 --- a/src/Tempest/Framework/Installers/FrameworkInstaller.php +++ b/src/Tempest/Framework/Installers/FrameworkInstaller.php @@ -37,7 +37,7 @@ public function install(): void $this->publish( source: __DIR__ . '/tempest', destination: root_path('tempest'), - callback: function (string $_, string $destination): void { + callback: static function (string $_, string $destination): void { if (PHP_OS_FAMILY !== 'Windows') { /** @phpstan-ignore-next-line */ exec("chmod +x {$destination}"); diff --git a/src/Tempest/Framework/Installers/ViewComponentsInstaller.php b/src/Tempest/Framework/Installers/ViewComponentsInstaller.php index 630036b32..7313c371f 100644 --- a/src/Tempest/Framework/Installers/ViewComponentsInstaller.php +++ b/src/Tempest/Framework/Installers/ViewComponentsInstaller.php @@ -25,7 +25,7 @@ public function __construct( public function install(): void { $searchOptions = arr($this->viewConfig->viewComponents) - ->filter(fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent); + ->filter(static fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent); if ($searchOptions->isEmpty()) { $this->error('No installable view vendor components found.'); diff --git a/src/Tempest/Framework/Testing/Http/HttpRouterTester.php b/src/Tempest/Framework/Testing/Http/HttpRouterTester.php index f5bf6cddf..10a377bff 100644 --- a/src/Tempest/Framework/Testing/Http/HttpRouterTester.php +++ b/src/Tempest/Framework/Testing/Http/HttpRouterTester.php @@ -275,7 +275,7 @@ private function createHeaders(array $headers = []): array { $key = array_find_key( array: $headers, - callback: fn (mixed $_, string $headerKey): bool => strcasecmp($headerKey, 'accept') === 0, + callback: static fn (mixed $_, string $headerKey): bool => strcasecmp($headerKey, 'accept') === 0, ); if ($this->contentType !== null) { diff --git a/src/Tempest/Framework/Testing/Http/TestResponseHelper.php b/src/Tempest/Framework/Testing/Http/TestResponseHelper.php index 497669ed0..11e2533b7 100644 --- a/src/Tempest/Framework/Testing/Http/TestResponseHelper.php +++ b/src/Tempest/Framework/Testing/Http/TestResponseHelper.php @@ -214,7 +214,7 @@ public function assertHasCookie(string $key, null|string|Closure $value = null): /** @var array */ $cookies = Arr\map_with_keys( array: $this->response->getHeader('set-cookie')->values, - map: function (string $cookie) { + map: static function (string $cookie) { $cookie = Cookie::createFromString($cookie); yield $cookie->key => $cookie; }, @@ -247,7 +247,7 @@ public function assertDoesNotHaveCookie(string $key, null|string|Closure $value /** @var array */ $cookies = Arr\map_with_keys( array: $this->response->getHeader('set-cookie')->values ?? [], - map: function (string $cookie) { + map: static function (string $cookie) { $cookie = Cookie::createFromString($cookie); yield $cookie->key => $cookie; }, @@ -367,7 +367,7 @@ public function assertHasNoValidationsErrors(): self Assert::assertEmpty( actual: $validationErrors, message: arr($validationErrors) - ->map(fn (array $failingRules, string $key) => $key . ': ' . arr($failingRules)->map(fn (Rule $rule) => $rule::class)->implode(', ')) + ->map(static fn (array $failingRules, string $key) => $key . ': ' . arr($failingRules)->map(static fn (Rule $rule) => $rule::class)->implode(', ')) ->implode(', ') ->prepend('There should be no validation errors, but there were: ') ->toString(), diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index ef3d79d1d..58f7347e4 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -168,8 +168,8 @@ protected function setupKernel(): self protected function setupConsole(): self { $this->console = new ConsoleTester($this->container); - $this->container->singleton(OutputBuffer::class, fn () => new MemoryOutputBuffer()); - $this->container->singleton(StdoutOutputBuffer::class, fn () => new MemoryOutputBuffer()); + $this->container->singleton(OutputBuffer::class, static fn () => new MemoryOutputBuffer()); + $this->container->singleton(StdoutOutputBuffer::class, static fn () => new MemoryOutputBuffer()); return $this; } @@ -203,8 +203,8 @@ protected function setupTesters(): self protected function setupBaseRequest(): self { $request = new GenericRequest(Method::GET, '/', []); - $this->container->singleton(Request::class, fn () => $request); - $this->container->singleton(GenericRequest::class, fn () => $request); + $this->container->singleton(Request::class, static fn () => $request); + $this->container->singleton(GenericRequest::class, static fn () => $request); return $this; } @@ -213,7 +213,7 @@ protected function clock(DateTimeInterface|string $now = 'now'): MockClock { $clock = new MockClock($now); - $this->container->singleton(Clock::class, fn () => $clock); + $this->container->singleton(Clock::class, static fn () => $clock); return $clock; } diff --git a/src/Tempest/Framework/Testing/ViteTester.php b/src/Tempest/Framework/Testing/ViteTester.php index cb9b5341c..0d5868d87 100644 --- a/src/Tempest/Framework/Testing/ViteTester.php +++ b/src/Tempest/Framework/Testing/ViteTester.php @@ -54,7 +54,7 @@ public function clearCaches(): self */ public function preventTagResolution(): self { - $this->container->register(TagsResolver::class, fn () => new NullTagsResolver()); + $this->container->register(TagsResolver::class, static fn () => new NullTagsResolver()); return $this; } @@ -150,7 +150,7 @@ public function call(callable $callback, array $files, bool $manifest = false, ? $this->container->config($actualViteConfig); if ($tagsResolver) { - $this->container->register(TagsResolver::class, fn () => $tagsResolver); + $this->container->register(TagsResolver::class, static fn () => $tagsResolver); } delete_directory($temporaryRootDirectory); diff --git a/tests/Benchmark/Container/ContainerBench.php b/tests/Benchmark/Container/ContainerBench.php index 8dedc0ae4..203c7f9bc 100644 --- a/tests/Benchmark/Container/ContainerBench.php +++ b/tests/Benchmark/Container/ContainerBench.php @@ -88,7 +88,7 @@ public function benchRegisterDefinition(): void { $container = new GenericContainer(); - $container->register(ContainerObjectA::class, fn () => new ContainerObjectA()); + $container->register(ContainerObjectA::class, static fn () => new ContainerObjectA()); } #[BeforeMethods('setUpInitializer')] @@ -145,7 +145,7 @@ public function benchRegisterClosureSingleton(): void { $container = new GenericContainer(); - $container->singleton(ContainerObjectA::class, fn () => new ContainerObjectA()); + $container->singleton(ContainerObjectA::class, static fn () => new ContainerObjectA()); } #[BeforeMethods('setUp')] @@ -154,7 +154,7 @@ public function benchRegisterClosureSingleton(): void #[Warmup(10)] public function benchInvokeClosure(): void { - $this->container->invoke(fn (ContainerObjectA $a) => $a); + $this->container->invoke(static fn (ContainerObjectA $a) => $a); } public function setUpSingletonInstance(): void @@ -166,7 +166,7 @@ public function setUpSingletonInstance(): void public function setUpDefinition(): void { $this->setUp(); - $this->container->register(ContainerObjectA::class, fn () => new ContainerObjectA()); + $this->container->register(ContainerObjectA::class, static fn () => new ContainerObjectA()); } public function setUpInitializer(): void @@ -184,6 +184,6 @@ public function setUpDynamicInitializer(): void public function setUpClosureSingleton(): void { $this->setUp(); - $this->container->singleton(ContainerObjectA::class, fn () => new ContainerObjectA()); + $this->container->singleton(ContainerObjectA::class, static fn () => new ContainerObjectA()); } } diff --git a/tests/Benchmark/Extension/MarkdownExtension.php b/tests/Benchmark/Extension/MarkdownExtension.php index bcb2472b7..07ed61a88 100644 --- a/tests/Benchmark/Extension/MarkdownExtension.php +++ b/tests/Benchmark/Extension/MarkdownExtension.php @@ -19,7 +19,7 @@ public function load(Container $container): void { $container->register( MarkdownRenderer::class, - function (Container $container) { + static function (Container $container) { return new MarkdownRenderer( $container->get(ConsoleExtension::SERVICE_OUTPUT_STD), $container->get(ExpressionExtension::SERVICE_PLAIN_PRINTER), diff --git a/tests/Benchmark/Extension/MarkdownRenderer.php b/tests/Benchmark/Extension/MarkdownRenderer.php index 565c59c2a..6d045065d 100644 --- a/tests/Benchmark/Extension/MarkdownRenderer.php +++ b/tests/Benchmark/Extension/MarkdownRenderer.php @@ -110,7 +110,7 @@ private function renderRow(array $cells): string private function renderSeparatorRow(array $columns): string { return $this->renderRow(array_map( - fn (string $column): string => str_repeat('-', max(3, mb_strlen($column))), + static fn (string $column): string => str_repeat('-', max(3, mb_strlen($column))), $columns, )); } @@ -128,7 +128,7 @@ private function compactAggregateReportTable(array $columns, array $rows): array return [$columns, $rows, false]; } - $rows = array_map(function (array $row) use ($columnIndexes): array { + $rows = array_map(static function (array $row) use ($columnIndexes): array { $set = trim((string) $row[$columnIndexes['set']]); return [ @@ -189,7 +189,7 @@ private function resolveCompactSourceColumnIndexes(array $columns): ?array { $columnIndexes = array_flip($columns); - if (array_any(self::COMPACT_SOURCE_COLUMNS, fn ($column) => ! array_key_exists($column, $columnIndexes))) { + if (array_any(self::COMPACT_SOURCE_COLUMNS, static fn ($column) => ! array_key_exists($column, $columnIndexes))) { return null; } diff --git a/tests/Benchmark/Http/GenericRouterBench.php b/tests/Benchmark/Http/GenericRouterBench.php index d99bcb26d..44bcb60ce 100644 --- a/tests/Benchmark/Http/GenericRouterBench.php +++ b/tests/Benchmark/Http/GenericRouterBench.php @@ -47,9 +47,9 @@ public function setUp(): void $matcher = new GenericRouteMatcher($routeConfig); - $container->singleton(Container::class, fn () => $container); - $container->singleton(RouteMatcher::class, fn () => $matcher); - $container->singleton(RouteConfig::class, fn () => $routeConfig); + $container->singleton(Container::class, static fn () => $container); + $container->singleton(RouteMatcher::class, static fn () => $matcher); + $container->singleton(RouteConfig::class, static fn () => $routeConfig); $this->router = new GenericRouter($container, $routeConfig); @@ -61,9 +61,9 @@ public function setUp(): void $containerWithoutExceptionMiddleware = new GenericContainer(); $matcherWithoutExceptionMiddleware = new GenericRouteMatcher($routeConfigWithoutExceptionMiddleware); - $containerWithoutExceptionMiddleware->singleton(Container::class, fn () => $containerWithoutExceptionMiddleware); - $containerWithoutExceptionMiddleware->singleton(RouteMatcher::class, fn () => $matcherWithoutExceptionMiddleware); - $containerWithoutExceptionMiddleware->singleton(RouteConfig::class, fn () => $routeConfigWithoutExceptionMiddleware); + $containerWithoutExceptionMiddleware->singleton(Container::class, static fn () => $containerWithoutExceptionMiddleware); + $containerWithoutExceptionMiddleware->singleton(RouteMatcher::class, static fn () => $matcherWithoutExceptionMiddleware); + $containerWithoutExceptionMiddleware->singleton(RouteConfig::class, static fn () => $routeConfigWithoutExceptionMiddleware); $this->routerWithoutExceptionMiddleware = new GenericRouter($containerWithoutExceptionMiddleware, $routeConfigWithoutExceptionMiddleware); } diff --git a/tests/Fixtures/Controllers/DeferController.php b/tests/Fixtures/Controllers/DeferController.php index 8a0b6bb27..a486357b9 100644 --- a/tests/Fixtures/Controllers/DeferController.php +++ b/tests/Fixtures/Controllers/DeferController.php @@ -17,7 +17,7 @@ final class DeferController #[Get('/defer')] public function __invoke(): Response { - defer(function (): void { + defer(static function (): void { // ll('defer start'); // sleep(2); // ll('defer done'); diff --git a/tests/Integration/Auth/AccessControl/HasPolicyTests.php b/tests/Integration/Auth/AccessControl/HasPolicyTests.php index e0dfdae9c..493e3a20f 100644 --- a/tests/Integration/Auth/AccessControl/HasPolicyTests.php +++ b/tests/Integration/Auth/AccessControl/HasPolicyTests.php @@ -16,9 +16,11 @@ public function registerPoliciesFrom(string|object $class): self $config = $this->container->get(AuthConfig::class); foreach (new ClassReflector($class)->getPublicMethods() as $method) { - if ($policy = $method->getAttribute(Policy::class)) { - $config->registerPolicy($method, $policy); + if (! ($policy = $method->getAttribute(Policy::class))) { + continue; } + + $config->registerPolicy($method, $policy); } return $this; diff --git a/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php b/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php index 87279d839..a48c45181 100644 --- a/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php +++ b/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php @@ -246,7 +246,7 @@ public function abstracted_flow(): void method: Method::GET, uri: Uri\set_query('/oauth/callback', code: 'authorization-code-from-github', state: $client->getState()), ), - map: fn (OAuthUser $user): User => query(User::class)->updateOrCreate([ + map: static fn (OAuthUser $user): User => query(User::class)->updateOrCreate([ 'github_id' => $user->id, ], [ 'email' => $user->email, diff --git a/tests/Integration/Cache/CacheTest.php b/tests/Integration/Cache/CacheTest.php index 3d11de9e6..3486a68e6 100644 --- a/tests/Integration/Cache/CacheTest.php +++ b/tests/Integration/Cache/CacheTest.php @@ -38,7 +38,7 @@ public function test_put(): void $item = $pool->getItem('a'); $this->assertFalse($item->isHit()); - $this->assertSame(null, $item->get()); + $this->assertNull($item->get()); $item = $pool->getItem('b'); $this->assertTrue($item->isHit()); @@ -152,7 +152,7 @@ public function test_get(): void $clock->plus($interval); - $this->assertSame(null, $cache->get('a')); + $this->assertNull($cache->get('a')); $this->assertSame('b', $cache->get('b')); } @@ -171,7 +171,7 @@ public function test_get_many(): void $values = $cache->getMany(['foo2', 'foo3']); $this->assertSame('bar2', $values['foo2']); - $this->assertSame(null, $values['foo3']); + $this->assertNull($values['foo3']); } public function test_resolve(): void @@ -180,18 +180,18 @@ public function test_resolve(): void $clock = $this->clock(); $cache = new GenericCache(new ArrayAdapter(clock: $clock->toPsrClock())); - $a = $cache->resolve('a', fn () => 'a', $clock->now()->plus($interval)); + $a = $cache->resolve('a', static fn () => 'a', $clock->now()->plus($interval)); $this->assertSame('a', $a); - $b = $cache->resolve('b', fn () => 'b'); + $b = $cache->resolve('b', static fn () => 'b'); $this->assertSame('b', $b); $clock->plus($interval); - $this->assertSame(null, $cache->get('a')); + $this->assertNull($cache->get('a')); $this->assertSame('b', $cache->get('b')); - $b = $cache->resolve('b', fn () => 'b'); + $b = $cache->resolve('b', static fn () => 'b'); $this->assertSame('b', $b); } @@ -227,7 +227,7 @@ public function test_stale_while_revalidate(): void ); // Cache value can be stale for 1min, but will be refreshed in the background - $retrieve = fn (string $value) => $cache->resolve('test', fn () => $value, expiration: Duration::minute(), stale: Duration::minute()); + $retrieve = static fn (string $value) => $cache->resolve('test', static fn () => $value, expiration: Duration::minute(), stale: Duration::minute()); // We fetch the value within the allowed duration, there is no deferring $this->assertSame('update1', $retrieve('update1')); diff --git a/tests/Integration/Cache/LockTest.php b/tests/Integration/Cache/LockTest.php index 63db4ce91..38f6f210c 100644 --- a/tests/Integration/Cache/LockTest.php +++ b/tests/Integration/Cache/LockTest.php @@ -82,7 +82,7 @@ public function test_lock_execution_without_timeout(): void $lock = $cache->lock('processing'); - $this->assertTrue($lock->execute(fn () => true)); // @phpstan-ignore method.alreadyNarrowedType + $this->assertTrue($lock->execute(static fn () => true)); // @phpstan-ignore method.alreadyNarrowedType $this->assertFalse($lock->release()); } @@ -97,7 +97,7 @@ public function test_lock_execution_when_already_locked_by_another_owner(): void $externalLock->acquire(); // Try executing a callback, should timeout instantly - $cache->lock('processing')->execute(fn () => true); + $cache->lock('processing')->execute(static fn () => true); } public function test_lock_execution_when_already_locked_by_another_owner_with_timeout(): void @@ -114,7 +114,7 @@ public function test_lock_execution_when_already_locked_by_another_owner_with_ti // Try executing a callback for the specified duration /** @phpstan-ignore-next-line */ - $this->assertTrue($cache->lock('processing')->execute(fn () => true, wait: Duration::hours(1))); + $this->assertTrue($cache->lock('processing')->execute(static fn () => true, wait: Duration::hours(1))); } public function test_lock_can_be_reacquired_after_expiration(): void diff --git a/tests/Integration/CommandBus/AsyncCommandTest.php b/tests/Integration/CommandBus/AsyncCommandTest.php index 2899542c3..0cc58baa5 100644 --- a/tests/Integration/CommandBus/AsyncCommandTest.php +++ b/tests/Integration/CommandBus/AsyncCommandTest.php @@ -26,7 +26,7 @@ public function test_async_commands_are_stored_and_handled_afterwards(): void $this->container->singleton( CommandRepository::class, - fn () => $repository, + static fn () => $repository, ); MyAsyncCommandHandler::$isHandled = false; @@ -75,7 +75,7 @@ public function test_async_failed_command_monitor(): void $process->stop(); arr(glob(__DIR__ . '/../../../packages/command-bus/src/stored-commands/*.failed.txt')) - ->each(function (string $filename): void { + ->each(static function (string $filename): void { unlink($filename); }); } @@ -83,7 +83,7 @@ public function test_async_failed_command_monitor(): void private function getOutput(Process $process): string { $pattern = array_map( - fn (TerminalStyle $consoleStyle) => TerminalStyle::ESC->value . $consoleStyle->value, + static fn (TerminalStyle $consoleStyle) => TerminalStyle::ESC->value . $consoleStyle->value, TerminalStyle::cases(), ); diff --git a/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php b/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php index ed0d6ccbf..9d1063c61 100644 --- a/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php +++ b/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php @@ -25,7 +25,7 @@ public function test_command_specific_middleware(): void public function test_command_specific_middleware_through_console(): void { $this->console - ->call(fn (GenericConsole $console) => $console->call('with:middleware')) + ->call(static fn (GenericConsole $console) => $console->call('with:middleware')) ->assertContains('from middleware') ->assertContains('from command'); } diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index 2c84475c4..eb919e0f2 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -94,8 +94,8 @@ public static function middleware_type_provider(): array $cases = MiddlewareType::cases(); return array_combine( - keys: array_map(fn (MiddlewareType $case) => $case->value, $cases), - values: array_map(fn (MiddlewareType $case) => [ + keys: array_map(static fn (MiddlewareType $case) => $case->value, $cases), + values: array_map(static fn (MiddlewareType $case) => [ 'middlewareType' => $case, 'middlewareInterface' => $case->relatedInterface(), ], $cases), diff --git a/tests/Integration/Console/Components/ProgressBarComponentTest.php b/tests/Integration/Console/Components/ProgressBarComponentTest.php index c28781e44..704e0f819 100644 --- a/tests/Integration/Console/Components/ProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/ProgressBarComponentTest.php @@ -22,7 +22,7 @@ public function test_progress_bar_component(): void $terminal = new Terminal($console); $component = new ProgressBarComponent( data: ['a', 'b', 'c', 'd'], - handler: fn (string $input) => $input . $input, + handler: static fn (string $input) => $input . $input, ); $generator = $component->render($terminal); @@ -55,8 +55,8 @@ public function test_progress_bar_with_format(): void $terminal = new Terminal($console); $component = new ProgressBarComponent( data: ['a', 'b', 'c', 'd'], - handler: fn (string $input) => $input, - format: fn (int $step) => str_repeat(':', $step), + handler: static fn (string $input) => $input, + format: static fn (int $step) => str_repeat(':', $step), ); $generator = $component->render($terminal); diff --git a/tests/Integration/Console/Components/SearchComponentTest.php b/tests/Integration/Console/Components/SearchComponentTest.php index 3fa3deb9b..b0024ef54 100644 --- a/tests/Integration/Console/Components/SearchComponentTest.php +++ b/tests/Integration/Console/Components/SearchComponentTest.php @@ -173,7 +173,7 @@ public function search(string $query): array return array_filter( $data, - fn (string $name) => str_contains(strtolower($name), strtolower($query)), + static fn (string $name) => str_contains(strtolower($name), strtolower($query)), ); } } diff --git a/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php b/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php index 36a0c8027..66d0ffd3f 100644 --- a/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php @@ -16,7 +16,7 @@ final class StaticConfirmComponentTest extends FrameworkIntegrationTestCase public function test_confirm(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { if ($console->confirm('continue')) { $console->writeln('continued'); } else { @@ -30,7 +30,7 @@ public function test_confirm(): void public function test_not_confirm(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { if ($console->confirm('continue')) { $console->writeln('continued'); } else { @@ -44,7 +44,7 @@ public function test_not_confirm(): void public function test_with_default(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { if ($console->confirm('continue', default: true)) { $console->writeln('continued'); } else { @@ -58,7 +58,7 @@ public function test_with_default(): void public function test_without_default(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { if ($console->confirm('continue')) { $console->writeln('continued'); } else { @@ -73,7 +73,7 @@ public function test_with_default_without_prompting(): void { $this->console ->withoutPrompting() - ->call(function (Console $console): void { + ->call(static function (Console $console): void { if ($console->confirm('continue', default: true)) { $console->writeln('continued'); } else { diff --git a/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php b/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php index a652862d3..e260e6298 100644 --- a/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php @@ -16,7 +16,7 @@ final class StaticMultipleChoiceComponentTest extends FrameworkIntegrationTestCa public function test_ask(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $console->ask('test', ['a', 'b', 'c'], multiple: true); }) ->submit('0,1') @@ -26,7 +26,7 @@ public function test_ask(): void public function test_with_invalid_options(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $console->ask('test', ['a', 'b', 'c'], multiple: true); }) ->submit('0,4,c,2') @@ -36,7 +36,7 @@ public function test_with_invalid_options(): void public function test_confirm(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask('test', ['a', 'b', 'c'], multiple: true); $console->writeln(json_encode($answer)); @@ -54,7 +54,7 @@ public function test_confirm(): void public function test_supports_defaults(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask( question: 'test', options: ['foo', 'bar'], @@ -72,7 +72,7 @@ public function test_supports_defaults(): void public function test_supports_enum(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask( question: 'test', options: TestStringEnum::cases(), @@ -92,7 +92,7 @@ public function test_supports_enum(): void public function test_supports_enum_with_default(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask( question: 'test', options: TestStringEnum::cases(), diff --git a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php index c5d6358b6..0953b879b 100644 --- a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php @@ -15,10 +15,10 @@ final class StaticProgressBarComponentTest extends FrameworkIntegrationTestCase public function test_progress_bar(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $output = $console->progressBar( ['a', 'b', 'c'], - fn (string $input) => $input . $input, + static fn (string $input) => $input . $input, ); $console->write(json_encode($output)); diff --git a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php index c1608c974..49b996065 100644 --- a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php @@ -136,7 +136,7 @@ private function search(?string $query): array return array_filter( $data, - fn (string $name) => str_contains(strtolower($name), strtolower($query)), + static fn (string $name) => str_contains(strtolower($name), strtolower($query)), ); } } diff --git a/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php b/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php index 3f0df9bca..c3bb1f892 100644 --- a/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php @@ -17,7 +17,7 @@ final class StaticSingleChoiceComponentTest extends FrameworkIntegrationTestCase public function test_with_options(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask('test', ['a', 'b']); $console->writeln("picked {$answer}"); @@ -31,7 +31,7 @@ public function test_with_options(): void public function test_with_default_option(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask('test', ['a', 'b'], default: 'b'); $console->writeln("picked {$answer}"); @@ -44,7 +44,7 @@ public function test_with_default_option_without_prompting(): void { $this->console ->withoutPrompting() - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask('test', ['a', 'b'], default: 'b'); $console->writeln("picked {$answer}"); @@ -55,7 +55,7 @@ public function test_with_default_option_without_prompting(): void public function test_assoc_submit_key(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask('test', ['a' => 'A', 'b' => 'B']); $console->writeln("picked {$answer}"); @@ -67,7 +67,7 @@ public function test_assoc_submit_key(): void public function test_assoc_submit_value(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $answer = $console->ask('test', ['a' => 'A', 'b' => 'B']); $console->writeln("picked {$answer}"); @@ -79,7 +79,7 @@ public function test_assoc_submit_value(): void public function test_enum_submit_value(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { /** @var TestStringEnum $answer */ $answer = $console->ask('test', options: TestStringEnum::cases()); @@ -92,7 +92,7 @@ public function test_enum_submit_value(): void public function test_enum_submit_index(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { /** @var TestStringEnum $answer */ $answer = $console->ask('test', options: TestStringEnum::cases()); @@ -105,7 +105,7 @@ public function test_enum_submit_index(): void public function test_enum_default_value(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { /** @var TestStringEnum $answer */ $answer = $console->ask('test', options: TestStringEnum::cases(), default: TestStringEnum::B); diff --git a/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php b/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php index bb6fa62b4..54b0b0966 100644 --- a/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php @@ -15,7 +15,7 @@ final class StaticTextBoxComponentTest extends FrameworkIntegrationTestCase public function test_text_box(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $name = $console->ask('test'); $console->writeln("Hello {$name}"); @@ -27,7 +27,7 @@ public function test_text_box(): void public function test_supports_default(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $name = $console->ask('test', default: 'Brent'); $console->writeln("Hello {$name}"); @@ -40,7 +40,7 @@ public function test_supports_default_without_prompting(): void { $this->console ->withoutPrompting() - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $name = $console->ask('test', default: 'Brent'); $console->writeln("Hello {$name}"); diff --git a/tests/Integration/Console/Components/TaskComponentTest.php b/tests/Integration/Console/Components/TaskComponentTest.php index 68428409e..f00b0a385 100644 --- a/tests/Integration/Console/Components/TaskComponentTest.php +++ b/tests/Integration/Console/Components/TaskComponentTest.php @@ -76,7 +76,7 @@ public function test_successful_task(): void ->withoutPrompting() ->call(function (Console $console): void { $terminal = new Terminal($console); - $component = new TaskComponent('Task in progress', function (): void {}); + $component = new TaskComponent('Task in progress', static function (): void {}); $frames = iterator_to_array($component->render($terminal)); @@ -93,7 +93,7 @@ public function test_failing_task(): void ->withoutPrompting() ->call(function (Console $console): void { $terminal = new Terminal($console); - $component = new TaskComponent('Task in progress', function (): never { + $component = new TaskComponent('Task in progress', static function (): never { throw new Exception('Failure'); }); diff --git a/tests/Integration/Console/ConsoleArgumentBagTest.php b/tests/Integration/Console/ConsoleArgumentBagTest.php index b9999ac95..8423d1358 100644 --- a/tests/Integration/Console/ConsoleArgumentBagTest.php +++ b/tests/Integration/Console/ConsoleArgumentBagTest.php @@ -36,13 +36,13 @@ public function test_argument_bag_works(): void $this->assertNull($firstArg->name); $forceFlag = $bag->all()[1]; - $this->assertSame(true, $forceFlag->value); - $this->assertSame(null, $forceFlag->position); + $this->assertTrue($forceFlag->value); + $this->assertNull($forceFlag->position); $this->assertSame('force', $forceFlag->name); $timesFlag = $bag->all()[2]; $this->assertSame('2', $timesFlag->value); - $this->assertSame(null, $timesFlag->position); + $this->assertNull($timesFlag->position); $this->assertSame('times', $timesFlag->name); $this->assertSame( diff --git a/tests/Integration/Console/Fixtures/InteractiveCommand.php b/tests/Integration/Console/Fixtures/InteractiveCommand.php index afa941cbb..8eb6712d7 100644 --- a/tests/Integration/Console/Fixtures/InteractiveCommand.php +++ b/tests/Integration/Console/Fixtures/InteractiveCommand.php @@ -131,8 +131,8 @@ public function progress(): void { $result = $this->console->progressBar( data: array_fill(0, 10, 'a'), - handler: function ($i) { - usleep(100000); + handler: static function ($i) { + usleep(100_000); return $i . $i; }, @@ -148,14 +148,14 @@ public function searchCommand(): void $result = $this->console->search( 'Search', - function (string $query) use ($data): array { + static function (string $query) use ($data): array { if ($query === '') { return []; } return array_filter( $data, - fn (string $name) => str_contains(strtolower($name), strtolower($query)), + static fn (string $name) => str_contains(strtolower($name), strtolower($query)), ); }, ); diff --git a/tests/Integration/Console/Input/ConsoleInputArgumentTest.php b/tests/Integration/Console/Input/ConsoleInputArgumentTest.php index 6f53ef679..e708acc1c 100644 --- a/tests/Integration/Console/Input/ConsoleInputArgumentTest.php +++ b/tests/Integration/Console/Input/ConsoleInputArgumentTest.php @@ -41,19 +41,19 @@ public function test_parse_named_arguments(): void $input = ConsoleInputArgument::fromString('--noFooBar'); $this->assertSame('foo-bar', $input->name); - $this->assertSame(false, $input->value); + $this->assertFalse($input->value); $input = ConsoleInputArgument::fromString('--no-interaction'); $this->assertSame('interaction', $input->name); - $this->assertSame(false, $input->value); + $this->assertFalse($input->value); $input = ConsoleInputArgument::fromString('--no-interaction=true'); $this->assertSame('interaction', $input->name); - $this->assertSame(false, $input->value); + $this->assertFalse($input->value); $input = ConsoleInputArgument::fromString('--no-interaction=false'); $this->assertSame('interaction', $input->name); - $this->assertSame(true, $input->value); + $this->assertTrue($input->value); $input = ConsoleInputArgument::fromString('--no-foo=baz'); $this->assertSame('no-foo', $input->name); diff --git a/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php b/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php index 09c4955b3..8b07cb28b 100644 --- a/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php +++ b/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php @@ -60,12 +60,12 @@ public function it_does_not_duplicate_completed_commands(): void $formatOutput = static fn (string $buffer) => str($buffer) ->trim() ->explode("\n") - ->map(fn (string $line) => str($line)->afterLast(' ')->trim()->toString()) + ->map(static fn (string $line) => str($line)->afterLast(' ')->trim()->toString()) ->toArray(); $output = $this->console ->call('discovery') - ->getBuffer(fn (array $buffer) => $formatOutput(array_pop($buffer))); + ->getBuffer(static fn (array $buffer) => $formatOutput(array_pop($buffer))); $this->assertContains('discovery:status', $output); $this->assertContains('discovery:clear', $output); diff --git a/tests/Integration/Console/Testing/ConsoleTesterTest.php b/tests/Integration/Console/Testing/ConsoleTesterTest.php index 76803a3f8..614645d37 100644 --- a/tests/Integration/Console/Testing/ConsoleTesterTest.php +++ b/tests/Integration/Console/Testing/ConsoleTesterTest.php @@ -26,7 +26,7 @@ public function test_call_with_invokable(): void public function test_call_with_closure(): void { $this->console - ->call(function (Console $console): void { + ->call(static function (Console $console): void { $console->writeln('hi'); }) ->assertContains('hi'); @@ -49,35 +49,35 @@ public function test_call_with_command(): void public function test_exit_code_success(): void { $this->console - ->call(fn () => ExitCode::SUCCESS) + ->call(static fn () => ExitCode::SUCCESS) ->assertSuccess(); } public function test_exit_code_invalid(): void { $this->console - ->call(fn () => ExitCode::INVALID) + ->call(static fn () => ExitCode::INVALID) ->assertInvalid(); } public function test_exit_code_error(): void { $this->console - ->call(fn () => ExitCode::ERROR) + ->call(static fn () => ExitCode::ERROR) ->assertError(); } public function test_exit_code_cancelled(): void { $this->console - ->call(fn () => ExitCode::CANCELLED) + ->call(static fn () => ExitCode::CANCELLED) ->assertCancelled(); } public function test_exit_code_success_default(): void { $this->console - ->call(fn () => null) + ->call(static fn () => null) ->assertSuccess(); } diff --git a/tests/Integration/Core/DeferredTasksTest.php b/tests/Integration/Core/DeferredTasksTest.php index 129040906..6c68f3ee6 100644 --- a/tests/Integration/Core/DeferredTasksTest.php +++ b/tests/Integration/Core/DeferredTasksTest.php @@ -36,8 +36,8 @@ public function test_deferred_tasks_are_executed_with_container_parameters(): vo { $executed = false; - defer(function (Container $container) use (&$executed): void { - $container->invoke(function () use (&$executed): void { + defer(static function (Container $container) use (&$executed): void { + $container->invoke(static function () use (&$executed): void { $executed = true; }); }); diff --git a/tests/Integration/Core/LoadDiscoveryClassesTest.php b/tests/Integration/Core/LoadDiscoveryClassesTest.php index 29a21db43..228af9925 100644 --- a/tests/Integration/Core/LoadDiscoveryClassesTest.php +++ b/tests/Integration/Core/LoadDiscoveryClassesTest.php @@ -28,7 +28,7 @@ public function do_not_discover(): void { $migrations = $this->container->get(RunnableMigrations::class); - $this->assertFalse(Arr\contains($migrations, fn ($m) => $m instanceof HiddenDatabaseMigration)); + $this->assertFalse(Arr\contains($migrations, static fn ($m) => $m instanceof HiddenDatabaseMigration)); } #[Test] diff --git a/tests/Integration/Core/ViewComponentsInstallerTest.php b/tests/Integration/Core/ViewComponentsInstallerTest.php index 7ebbb5bcb..88aedfdcc 100644 --- a/tests/Integration/Core/ViewComponentsInstallerTest.php +++ b/tests/Integration/Core/ViewComponentsInstallerTest.php @@ -39,8 +39,8 @@ protected function setUp(): void ); $this->searchOptionCount = arr($this->get(ViewConfig::class)->viewComponents) - ->filter(fn (mixed $input) => $input instanceof ViewComponent) - ->filter(fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent) + ->filter(static fn (mixed $input) => $input instanceof ViewComponent) + ->filter(static fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent) ->count(); } diff --git a/tests/Integration/Cryptography/TimelockTest.php b/tests/Integration/Cryptography/TimelockTest.php index d514bab1a..f48669055 100644 --- a/tests/Integration/Cryptography/TimelockTest.php +++ b/tests/Integration/Cryptography/TimelockTest.php @@ -15,7 +15,7 @@ public function test_uses_mocked_clock(): void $ms = $clock->timestamp()->getMilliseconds(); $timelock->invoke( - callback: fn () => null, + callback: static fn () => null, duration: Duration::milliseconds(10_000), ); $elapsed = $clock->timestamp()->getMilliseconds() - $ms; diff --git a/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php b/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php index 85ee98dc1..923de0cfc 100644 --- a/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php +++ b/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php @@ -218,12 +218,12 @@ public function test_convenient_methods_in_where_groups(): void $query = query('books') ->select() ->where('published', true) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereIn('category', ['fiction', 'mystery']) ->orWhereNull('featured_at'); }) - ->orWhereGroup(function ($group): void { + ->orWhereGroup(static function ($group): void { $group ->whereBetween('rating', 4.0, 5.0) ->whereNotLike('title', '%draft%'); @@ -241,10 +241,10 @@ public function test_nested_where_groups_with_convenient_methods(): void $query = query('books') ->select() ->whereIn('status', ['published', 'featured']) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereNotNull('published_at') - ->orWhereGroup(function ($innerGroup): void { + ->orWhereGroup(static function ($innerGroup): void { $innerGroup ->whereBetween('rating', 4.0, 5.0) ->whereNotIn('category', ['children']); diff --git a/tests/Integration/Database/Builder/CountQueryBuilderTest.php b/tests/Integration/Database/Builder/CountQueryBuilderTest.php index f580585ef..162386e93 100644 --- a/tests/Integration/Database/Builder/CountQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/CountQueryBuilderTest.php @@ -113,14 +113,14 @@ public function test_count_query_with_conditions(): void ->count() ->when( true, - fn (CountQueryBuilder $query) => $query + static fn (CountQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Taxi') ->andWhereRaw('`index` <> ?', '1') ->orWhereRaw('`createdAt` > ?', '2025-01-01'), ) ->when( false, - fn (CountQueryBuilder $query) => $query + static fn (CountQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Uber') ->andWhereRaw('`index` <> ?', '2') ->orWhereRaw('`createdAt` > ?', '2025-01-02'), @@ -498,7 +498,7 @@ public function test_convenient_where_methods_in_groups(): void $query = query('books') ->count() ->whereIn('status', ['published', 'featured']) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereNotNull('published_at') ->orWhereBetween('rating', 4.0, 5.0); @@ -516,7 +516,7 @@ public function test_nested_where_with_count_query(): void $query = query('books') ->count() ->whereRaw('published = ?', true) - ->orWhereGroup(function ($group): void { + ->orWhereGroup(static function ($group): void { $group ->whereRaw('status = ?', 'featured') ->andWhereRaw('rating >= ?', 4.5); diff --git a/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php b/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php index 74fb24eb4..72a00c604 100644 --- a/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php @@ -72,11 +72,11 @@ public function test_delete_on_plain_table_with_conditions(): void ->delete() ->when( true, - fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'boo'), + static fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'boo'), ) ->when( false, - fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'foo'), + static fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'foo'), ) ->build(); @@ -142,7 +142,7 @@ public function test_nested_where_with_delete_query(): void $query = query('books') ->delete() ->whereRaw('status = ?', 'draft') - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereRaw('created_at < ?', '2022-01-01') ->andWhereRaw('author_id IS NULL'); diff --git a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php index c367d1d95..3804db94a 100644 --- a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php @@ -134,11 +134,11 @@ public function test_then_method(): void $id = query(Book::class) ->insert(title: 'Timeline Taxi') ->then( - fn (PrimaryKey $id) => query(Chapter::class)->insert( + static fn (PrimaryKey $id) => query(Chapter::class)->insert( ['title' => 'Chapter 01', 'book_id' => $id], ['title' => 'Chapter 02', 'book_id' => $id], ), - fn (PrimaryKey $id) => query(Chapter::class)->insert( + static fn (PrimaryKey $id) => query(Chapter::class)->insert( ['title' => 'Chapter 03', 'book_id' => $id], ), ) diff --git a/tests/Integration/Database/Builder/NestedWhereTest.php b/tests/Integration/Database/Builder/NestedWhereTest.php index 94be9fdda..9b723052c 100644 --- a/tests/Integration/Database/Builder/NestedWhereTest.php +++ b/tests/Integration/Database/Builder/NestedWhereTest.php @@ -15,7 +15,7 @@ public function test_nested_where_with_and_group(): void $query = query('books') ->select() ->whereRaw('title = ?', 'test') - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereRaw('author_id = ?', 1) ->orWhereRaw('author_id = ?', 2); @@ -33,7 +33,7 @@ public function test_nested_where_with_or_group(): void $query = query('books') ->select() ->whereRaw('status = ?', 'active') - ->orWhereGroup(function ($group): void { + ->orWhereGroup(static function ($group): void { $group ->whereRaw('priority = ?', 'high') ->andWhereRaw('urgent = ?', true); @@ -51,10 +51,10 @@ public function test_deeply_nested_where_groups(): void $query = query('books') ->select() ->whereRaw('published = ?', true) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereRaw('category = ?', 'fiction') - ->orWhereGroup(function ($innerGroup): void { + ->orWhereGroup(static function ($innerGroup): void { $innerGroup ->whereRaw('author_name = ?', 'Tolkien') ->andWhereRaw('rating > ?', 4.5); @@ -81,14 +81,14 @@ public function test_complex_nested_where_scenario(): void $query = query('books') ->select() ->whereRaw('status = ?', 'published') - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group - ->andWhereGroup(function ($innerGroup): void { + ->andWhereGroup(static function ($innerGroup): void { $innerGroup ->whereRaw('category = ?', 'fiction') ->andWhereRaw('rating > ?', 4.0); }) - ->orWhereGroup(function ($innerGroup): void { + ->orWhereGroup(static function ($innerGroup): void { $innerGroup ->whereRaw('category = ?', 'non-fiction') ->andWhereRaw('author_id IN (?, ?, ?)', 1, 2, 3); @@ -119,7 +119,7 @@ public function test_where_group_without_existing_conditions(): void { $query = query('books') ->select() - ->whereGroup(function ($group): void { + ->whereGroup(static function ($group): void { $group ->whereRaw('title LIKE ?', '%test%') ->orWhereRaw('description LIKE ?', '%test%'); @@ -137,7 +137,7 @@ public function test_nested_where_with_where(): void $query = query('books') ->select() ->where('published', true) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereRaw('category = ?', 'fiction') ->orWhereRaw('priority = ?', 'high'); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index 1c3c26212..0c6eb4a7d 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -310,7 +310,7 @@ public function test_chunk(): void Book::new(title: 'D')->save(); $results = []; - Book::select()->chunk(function (array $chunk) use (&$results): void { + Book::select()->chunk(static function (array $chunk) use (&$results): void { $results = [...$results, ...$chunk]; }, 2); $this->assertCount(4, $results); @@ -318,7 +318,7 @@ public function test_chunk(): void $results = []; Book::select() ->whereRaw("title <> 'A'") - ->chunk(function (array $chunk) use (&$results): void { + ->chunk(static function (array $chunk) use (&$results): void { $results = [...$results, ...$chunk]; }, 2); $this->assertCount(3, $results); @@ -341,7 +341,7 @@ public function test_chunk_with_relation(): void $results = []; Book::select() ->with('author') - ->chunk(function (array $chunk) use (&$results): void { + ->chunk(static function (array $chunk) use (&$results): void { $results = [...$results, ...$chunk]; }, 1); $this->assertCount(2, $results); @@ -370,14 +370,14 @@ public function test_select_query_with_conditions(): void ->select('title', 'index') ->when( true, - fn (SelectQueryBuilder $query) => $query + static fn (SelectQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Taxi') ->andWhereRaw('`index` <> ?', '1') ->orWhereRaw('`createdAt` > ?', '2025-01-01'), ) ->when( false, - fn (SelectQueryBuilder $query) => $query + static fn (SelectQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Uber') ->andWhereRaw('`index` <> ?', '2') ->orWhereRaw('`createdAt` > ?', '2025-01-02'), @@ -534,9 +534,9 @@ public function test_paginate(): void $this->assertSame(0, $page1->offset); $this->assertSame(2, $page1->limit); $this->assertSame(2, $page1->nextPage); - $this->assertSame(null, $page1->previousPage); - $this->assertSame(true, $page1->hasNext); - $this->assertSame(false, $page1->hasPrevious); + $this->assertNull($page1->previousPage); + $this->assertTrue($page1->hasNext); + $this->assertFalse($page1->hasPrevious); $this->assertSame('LOTR 1.1', $page1->data[0]->title); $this->assertSame('LOTR 1.2', $page1->data[1]->title); diff --git a/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php b/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php index 8ee939d87..92246be2c 100644 --- a/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php @@ -18,7 +18,7 @@ public function test_select_query_builder_transform(): void { $query = query(Author::class) ->select() - ->transform(fn ($builder) => $builder->where('name', 'Frieren')); + ->transform(static fn ($builder) => $builder->where('name', 'Frieren')); $bindings = $query->build()->bindings; @@ -29,7 +29,7 @@ public function test_count_query_builder_transform(): void { $query = query(Author::class) ->count() - ->transform(fn ($builder) => $builder->where('name', 'Himmel')); + ->transform(static fn ($builder) => $builder->where('name', 'Himmel')); $bindings = $query->build()->bindings; @@ -40,7 +40,7 @@ public function test_update_query_builder_transform(): void { $query = query(Author::class) ->update(name: 'Heiter') - ->transform(fn ($builder) => $builder->where('id', 1)); + ->transform(static fn ($builder) => $builder->where('id', 1)); $bindings = $query->build()->bindings; @@ -51,7 +51,7 @@ public function test_delete_query_builder_transform(): void { $query = query(Author::class) ->delete() - ->transform(fn ($builder) => $builder->where('name', 'Eisen')); + ->transform(static fn ($builder) => $builder->where('name', 'Eisen')); $bindings = $query->build()->bindings; @@ -62,7 +62,7 @@ public function test_insert_query_builder_transform(): void { $query = query(Author::class) ->insert(['name' => 'Stark']) - ->transform(fn ($builder) => $builder->then(fn () => null)); + ->transform(static fn ($builder) => $builder->then(static fn () => null)); $bindings = $query->build()->bindings; @@ -73,7 +73,7 @@ public function test_transform_returns_new_instance(): void { $original = query(Author::class)->select(); - $transformed = $original->transform(fn ($builder) => $builder); + $transformed = $original->transform(static fn ($builder) => $builder); $this->assertNotSame($original, $transformed); } diff --git a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php index a81f9a998..312ffac01 100644 --- a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php @@ -206,11 +206,11 @@ public function test_update_on_plain_table_with_conditions(): void ) ->when( true, - fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 10), + static fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 10), ) ->when( false, - fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 20), + static fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 20), ) ->build(); @@ -285,7 +285,7 @@ public function test_nested_where_with_update_query(): void $query = query('books') ->update(status: 'archived') ->whereRaw('published = ?', true) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereRaw('views < ?', 100) ->orWhereRaw('last_accessed < ?', '2023-01-01'); diff --git a/tests/Integration/Database/Builder/WhereOperatorTest.php b/tests/Integration/Database/Builder/WhereOperatorTest.php index 3389effd9..5c2b5ee39 100644 --- a/tests/Integration/Database/Builder/WhereOperatorTest.php +++ b/tests/Integration/Database/Builder/WhereOperatorTest.php @@ -189,7 +189,7 @@ public function test_nested_where_groups_with_new_api(): void $query = query('books') ->select() ->where('published', true) - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->where('category', 'fiction') ->orWhere('rating', 4.5, WhereOperator::GREATER_THAN); @@ -207,7 +207,7 @@ public function test_mixed_raw_and_typed_conditions_in_groups(): void $query = query('books') ->select() ->where('status', 'published') - ->andWhereGroup(function ($group): void { + ->andWhereGroup(static function ($group): void { $group ->whereField('category', ['fiction', 'mystery'], WhereOperator::IN) ->orWhereRaw('custom_field IS NOT NULL'); diff --git a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php index 39ee9049a..a3b798550 100644 --- a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php +++ b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php @@ -226,9 +226,11 @@ public function test_where_this_year(): void $this->assertCount(10, $events); foreach ($events as $event) { - if ($event->name !== 'Last year event') { - $this->assertTrue($event->event_date->isCurrentYear()); + if ($event->name === 'Last year event') { + continue; } + + $this->assertTrue($event->event_date->isCurrentYear()); } } diff --git a/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php b/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php index 4e9cc58cc..a157aa435 100644 --- a/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php +++ b/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php @@ -87,7 +87,7 @@ public function test_has_many_relationship_with_uuid_primary_keys(): void $this->assertCount(2, $loadedMage->spells); - $spellNames = array_map(fn (SpellWithUuid $spell) => $spell->name, $loadedMage->spells); + $spellNames = array_map(static fn (SpellWithUuid $spell) => $spell->name, $loadedMage->spells); $this->assertContains('Zoltraak', $spellNames); $this->assertContains('Volzandia', $spellNames); diff --git a/tests/Integration/Database/EncryptedAttributeTest.php b/tests/Integration/Database/EncryptedAttributeTest.php index 68e17694d..a984e4642 100644 --- a/tests/Integration/Database/EncryptedAttributeTest.php +++ b/tests/Integration/Database/EncryptedAttributeTest.php @@ -108,6 +108,7 @@ final class UserWithEncryptedData public function __construct( public string $email, + #[\SensitiveParameter] #[Encrypted] public string $secret, ) {} @@ -122,6 +123,7 @@ final class UserWithNullableEncryptedData public function __construct( public string $email, + #[\SensitiveParameter] #[Encrypted] public ?string $secret, ) {} diff --git a/tests/Integration/Database/GenericDatabaseTest.php b/tests/Integration/Database/GenericDatabaseTest.php index 8ca68639f..36f44a8e0 100644 --- a/tests/Integration/Database/GenericDatabaseTest.php +++ b/tests/Integration/Database/GenericDatabaseTest.php @@ -28,7 +28,7 @@ public function test_transaction_manager_execute(): void $db = $this->container->get(Database::class); - $db->withinTransaction(function (): void { + $db->withinTransaction(static function (): void { query(Author::class) ->insert( name: 'Brent', @@ -45,7 +45,7 @@ public function test_transaction_manager_fails(): void $db = $this->container->get(Database::class); - $db->withinTransaction(function (): never { + $db->withinTransaction(static function (): never { query(Author::class) ->insert( name: 'Brent', @@ -75,14 +75,14 @@ public function test_query_with_semicolons(): void public function test_query_was_invalid_exception_is_thrown_on_fetch(): void { - $this->assertException(QueryWasInvalid::class, function (): void { + $this->assertException(QueryWasInvalid::class, static function (): void { query('books')->select()->orderByRaw('title DES')->first(); }); } public function test_query_was_invalid_exception_is_thrown_on_execute(): void { - $this->assertException(QueryWasInvalid::class, function (): void { + $this->assertException(QueryWasInvalid::class, static function (): void { query('books')->update(title: 'Timeline Taxi')->whereRaw('title = ?')->execute(); }); } diff --git a/tests/Integration/Database/GroupedWhereMethodsTest.php b/tests/Integration/Database/GroupedWhereMethodsTest.php index 2814f08af..a865a662b 100644 --- a/tests/Integration/Database/GroupedWhereMethodsTest.php +++ b/tests/Integration/Database/GroupedWhereMethodsTest.php @@ -60,7 +60,7 @@ public function test_simple_where_group(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('category', 'electronics') ->where('in_stock', true); @@ -78,7 +78,7 @@ public function test_and_where_group(): void $products = query(Product::class) ->select() ->where('category', 'electronics') - ->andWhereGroup(function ($query): void { + ->andWhereGroup(static function ($query): void { $query ->whereField('price', 100.0, WhereOperator::GREATER_THAN) ->where('in_stock', true); @@ -97,7 +97,7 @@ public function test_or_where_group(): void $products = query(Product::class) ->select() ->where('category', 'furniture') - ->orWhereGroup(function ($query): void { + ->orWhereGroup(static function ($query): void { $query ->whereField('price', 500.0, WhereOperator::GREATER_THAN) ->where('brand', 'TechCorp'); @@ -125,10 +125,10 @@ public function test_nested_where_groups(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('category', 'electronics') - ->orWhereGroup(function ($subQuery): void { + ->orWhereGroup(static function ($subQuery): void { $subQuery ->where('category', 'furniture') ->whereField('price', 200.0, WhereOperator::LESS_THAN); @@ -149,12 +149,12 @@ public function test_complex_grouped_conditions(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('brand', 'TechCorp') ->orWhere('brand', 'ViewPro'); }) - ->andWhereGroup(function ($query): void { + ->andWhereGroup(static function ($query): void { $query ->where('rating', 4.0, WhereOperator::GREATER_THAN_OR_EQUAL) ->where('price', 300.0, WhereOperator::LESS_THAN); @@ -174,7 +174,7 @@ public function test_where_group_with_convenient_methods(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->whereIn('category', ['electronics', 'furniture']) ->whereBetween('price', 50.0, 250.0) @@ -194,7 +194,7 @@ public function test_where_group_with_raw_conditions(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->whereRaw('price > ?', 100.0) ->andWhereRaw('rating >= ?', 4.0); @@ -211,7 +211,7 @@ public function test_where_group_with_or_raw_conditions(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('brand', 'TechCorp') ->orWhereRaw('rating > ?', 4.5); @@ -238,7 +238,7 @@ public function test_empty_where_group_is_ignored(): void $products = query(Product::class) ->select() ->where('category', 'electronics') - ->whereGroup(function (): void {}) + ->whereGroup(static function (): void {}) ->all(); foreach ($products as $product) { @@ -250,12 +250,12 @@ public function test_multiple_where_groups(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('category', 'electronics') ->orWhere('category', 'furniture'); }) - ->andWhereGroup(function ($query): void { + ->andWhereGroup(static function ($query): void { $query ->where('in_stock', true) ->orWhere('rating', 4.5, WhereOperator::GREATER_THAN); @@ -272,7 +272,7 @@ public function test_where_group_with_all_logical_operators(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('brand', 'TechCorp') ->andWhere('category', 'electronics') @@ -301,13 +301,13 @@ public function test_deeply_nested_where_groups(): void { $products = query(Product::class) ->select() - ->whereGroup(function ($query): void { + ->whereGroup(static function ($query): void { $query ->where('category', 'electronics') - ->orWhereGroup(function ($subQuery): void { + ->orWhereGroup(static function ($subQuery): void { $subQuery ->where('category', 'furniture') - ->andWhereGroup(function ($deepQuery): void { + ->andWhereGroup(static function ($deepQuery): void { $deepQuery ->whereField('price', 150.0, WhereOperator::GREATER_THAN) ->orWhere('brand', 'LightUp'); diff --git a/tests/Integration/Database/HashedAttributeTest.php b/tests/Integration/Database/HashedAttributeTest.php index c0e76986d..dfa1a061b 100644 --- a/tests/Integration/Database/HashedAttributeTest.php +++ b/tests/Integration/Database/HashedAttributeTest.php @@ -103,6 +103,7 @@ final class UserWithHash public function __construct( public string $email, + #[\SensitiveParameter] #[Hashed] public string $password, ) {} @@ -116,6 +117,7 @@ final class UserWithNullablePassword public function __construct( public string $email, + #[\SensitiveParameter] #[Hashed] public ?string $password, ) {} diff --git a/tests/Integration/Database/MultiDatabaseTest.php b/tests/Integration/Database/MultiDatabaseTest.php index 4ae4a94b3..02644ed12 100644 --- a/tests/Integration/Database/MultiDatabaseTest.php +++ b/tests/Integration/Database/MultiDatabaseTest.php @@ -337,7 +337,7 @@ public function test_migrate_fresh_seed_on_selected_database(): void query(Book::class)->select()->onDatabase('main')->where('title', 'Timeline Taxi')->first()->title, ); - $this->assertException(QueryWasInvalid::class, function (): void { + $this->assertException(QueryWasInvalid::class, static function (): void { query(Book::class)->select()->onDatabase('backup')->first(); }); @@ -360,7 +360,7 @@ private function assertTableDoesNotExist(string $tableName, string $onDatabase): { $this->assertException( expectedExceptionClass: QueryWasInvalid::class, - handler: fn () => query($tableName)->count()->onDatabase($onDatabase)->execute(), + handler: static fn () => query($tableName)->count()->onDatabase($onDatabase)->execute(), message: "Table `{$tableName}` exists in database `{$onDatabase}`", ); } diff --git a/tests/Integration/Database/ToRawSqlTest.php b/tests/Integration/Database/ToRawSqlTest.php index b014d3b60..e25d69ca2 100644 --- a/tests/Integration/Database/ToRawSqlTest.php +++ b/tests/Integration/Database/ToRawSqlTest.php @@ -235,7 +235,7 @@ public function test_complex_select_query_with_groups_to_raw_sql(): void $rawSql = query('books') ->select() ->where('published', true) - ->whereGroup(function ($group): void { + ->whereGroup(static function ($group): void { $group ->where('category', 'fiction') ->orWhere('rating', 4.5, WhereOperator::GREATER_THAN_OR_EQUAL); diff --git a/tests/Integration/Debug/DebugTest.php b/tests/Integration/Debug/DebugTest.php index d366dc80b..048c2fa25 100644 --- a/tests/Integration/Debug/DebugTest.php +++ b/tests/Integration/Debug/DebugTest.php @@ -34,7 +34,7 @@ public function recursive_debug_inside_event_listener_does_not_cause_infinite_lo $dispatchCount = 0; $eventBus = $this->container->get(EventBus::class); - $eventBus->listen(function (ItemsDebugged $event) use (&$dispatchCount): void { + $eventBus->listen(static function (ItemsDebugged $event) use (&$dispatchCount): void { $dispatchCount++; Debug::resolve()->log(['recursive call'], writeToLog: false, writeToOut: false); diff --git a/tests/Integration/EventBus/EventBusTesterTest.php b/tests/Integration/EventBus/EventBusTesterTest.php index 1c4c41900..ca9b6cd1b 100644 --- a/tests/Integration/EventBus/EventBusTesterTest.php +++ b/tests/Integration/EventBus/EventBusTesterTest.php @@ -56,12 +56,12 @@ public function assert_dispatched_with_callback(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch('event-bus-fake-event'); - $this->eventBus->assertDispatched('event-bus-fake-event', function (string $event) { + $this->eventBus->assertDispatched('event-bus-fake-event', static function (string $event) { return $event === 'event-bus-fake-event'; }); $this->bus->dispatch(new FakeEvent('foo')); - $this->eventBus->assertDispatched(FakeEvent::class, function (FakeEvent $event) { + $this->eventBus->assertDispatched(FakeEvent::class, static function (FakeEvent $event) { return $event->value === 'foo'; }); } @@ -108,7 +108,7 @@ public function assert_dispatched_with_callback_failure(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch('event-bus-fake-event'); - $this->eventBus->assertDispatched('event-bus-fake-event', function (string $event) { + $this->eventBus->assertDispatched('event-bus-fake-event', static function (string $event) { return $event !== 'event-bus-fake-event'; }); } @@ -122,7 +122,7 @@ public function assert_dispatched_object_with_callback_failure(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch(new FakeEvent('foo')); - $this->eventBus->assertDispatched(FakeEvent::class, function (FakeEvent $event) { + $this->eventBus->assertDispatched(FakeEvent::class, static function (FakeEvent $event) { return $event->value === 'foobar'; }); } @@ -178,7 +178,7 @@ public function assert_listening_to(): void { $this->eventBus->preventEventHandling(); - $this->bus->listen(function (FakeEvent $_): never { + $this->bus->listen(static function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); @@ -191,13 +191,13 @@ public function assert_listening_to_count(): void { $this->eventBus->preventEventHandling(); - $this->bus->listen(function (FakeEvent $_): never { + $this->bus->listen(static function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); $this->eventBus->assertListeningTo(FakeEvent::class, count: 1); - $this->bus->listen(function (FakeEvent $_): never { + $this->bus->listen(static function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); @@ -223,7 +223,7 @@ public function assert_listening_to_count_failure(): void $this->eventBus->preventEventHandling(); - $this->bus->listen(function (FakeEvent $_): never { + $this->bus->listen(static function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); @@ -235,7 +235,7 @@ public function allows_handling(): void $this->eventBus->recordEventDispatches(); $handled = false; - $this->bus->listen(function (FakeEvent $_) use (&$handled): void { + $this->bus->listen(static function (FakeEvent $_) use (&$handled): void { $handled = true; }); diff --git a/tests/Integration/FrameworkIntegrationTestCase.php b/tests/Integration/FrameworkIntegrationTestCase.php index 87ce6e656..f051ddb2a 100644 --- a/tests/Integration/FrameworkIntegrationTestCase.php +++ b/tests/Integration/FrameworkIntegrationTestCase.php @@ -60,10 +60,10 @@ protected function assertSnippetsMatch(string $expected, string $actual): void protected function assertSameWithoutBackticks(Stringable|string $expected, Stringable|string $actual): void { - $clean = function (string $string): string { + $clean = static function (string $string): string { return str($string) ->replace('`', '') - ->replaceRegex('/AS \"(?.*?)\"/', fn (array $matches) => "AS {$matches['alias']}") + ->replaceRegex('/AS \"(?.*?)\"/', static fn (array $matches) => "AS {$matches['alias']}") ->toString(); }; diff --git a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php index 2b7cde3b9..d14f866d0 100644 --- a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php +++ b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php @@ -35,7 +35,7 @@ final class ExceptionRendererTest extends FrameworkIntegrationTestCase #[PreCondition] protected function configure(): void { - $this->container->singleton(Kernel::class, fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { + $this->container->singleton(Kernel::class, static fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { public const string VERSION = '1.0.0-alpha.6'; public string $root; @@ -68,7 +68,7 @@ public function shutdown(int|string $status = ''): never } }); - $this->container->singleton(ResponseSender::class, fn () => new class($this) implements ResponseSender { + $this->container->singleton(ResponseSender::class, static fn () => new class($this) implements ResponseSender { public function __construct( private ExceptionRendererTest $case, ) {} @@ -90,7 +90,7 @@ public function custom_json_exception_renderer(): void $this->container->singleton( Request::class, - fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), + static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), ); $this->callExceptionHandler(function (): void { @@ -114,7 +114,7 @@ public function custom_html_exception_renderer(): void $this->container->singleton( Request::class, - fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), + static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), ); $this->callExceptionHandler(function (): void { @@ -135,7 +135,7 @@ public function falls_back_to_default_renderer_when_no_custom_match(): void $this->container->singleton( Request::class, - fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), + static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), ); $this->callExceptionHandler(function (): void { @@ -157,7 +157,7 @@ public function priority_ordering(): void $this->container->singleton( Request::class, - fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), + static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), ); $this->callExceptionHandler(function (): void { @@ -179,7 +179,7 @@ public function custom_404_renderer(): void $this->container->singleton( Request::class, - fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), + static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), ); $this->callExceptionHandler(function (): void { diff --git a/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php b/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php index 370c7d9e1..f96d9e138 100644 --- a/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php +++ b/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->container->singleton( Kernel::class, - fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { + static fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { public const string VERSION = '1.0.0-alpha.6'; public string $root; @@ -67,7 +67,7 @@ public function shutdown(int|string $status = ''): never $this->container->singleton( ResponseSender::class, - fn () => new class($this) implements ResponseSender { + static fn () => new class($this) implements ResponseSender { public function __construct( private HttpExceptionHandlerTest $case, ) {} diff --git a/tests/Integration/Http/GenericResponseSenderTest.php b/tests/Integration/Http/GenericResponseSenderTest.php index 7102f293e..3554b2c1a 100644 --- a/tests/Integration/Http/GenericResponseSenderTest.php +++ b/tests/Integration/Http/GenericResponseSenderTest.php @@ -158,7 +158,7 @@ public function test_view_body(): void public function test_stream(): void { ob_start(); - $response = new EventStream(fn () => yield 'hello'); + $response = new EventStream(static fn () => yield 'hello'); $responseSender = $this->container->get(GenericResponseSender::class); $responseSender->send($response); @@ -172,7 +172,7 @@ public function test_stream(): void public function test_stream_with_custom_event(): void { ob_start(); - $response = new EventStream(function () { + $response = new EventStream(static function () { yield new ServerSentMessage(data: 'hello', event: 'first'); yield new ServerSentMessage(data: 'goodbye', event: 'last'); }); @@ -191,7 +191,7 @@ public function test_stream_with_custom_event(): void public function test_stream_with_custom_id(): void { ob_start(); - $response = new EventStream(function () { + $response = new EventStream(static function () { yield new ServerSentMessage(data: 'hello', id: 123); yield new ServerSentMessage(data: 'goodbye', id: 456); }); @@ -210,7 +210,7 @@ public function test_stream_with_custom_id(): void public function test_stream_with_custom_retry(): void { ob_start(); - $response = new EventStream(function () { + $response = new EventStream(static function () { yield new ServerSentMessage(data: 'hello', retryAfter: 1000); yield new ServerSentMessage(data: 'goodbye', retryAfter: Duration::minute()); }); @@ -229,7 +229,7 @@ public function test_stream_with_custom_retry(): void public function test_stream_with_custom_implementation(): void { ob_start(); - $response = new EventStream(function () { + $response = new EventStream(static function () { yield new class implements ServerSentEvent { public ?int $id = 1; diff --git a/tests/Integration/Http/HeaderSessionIdResolverTest.php b/tests/Integration/Http/HeaderSessionIdResolverTest.php index 41ffec6d4..3ab488a6c 100644 --- a/tests/Integration/Http/HeaderSessionIdResolverTest.php +++ b/tests/Integration/Http/HeaderSessionIdResolverTest.php @@ -43,7 +43,7 @@ private function setSessionId(string $id): void { $request = new GenericRequest(Method::GET, '/', [], ['tempest_session_id' => $id]); - $this->container->singleton(Request::class, fn () => $request); - $this->container->singleton(GenericRequest::class, fn () => $request); + $this->container->singleton(Request::class, static fn () => $request); + $this->container->singleton(GenericRequest::class, static fn () => $request); } } diff --git a/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php b/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php index a51c48580..3c7521c12 100644 --- a/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php +++ b/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php @@ -32,7 +32,7 @@ public function middleware_tracks_request_url(): void { $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/dashboard'), - next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), ); $this->assertEquals('/dashboard', $this->previousUrl->get()); @@ -45,7 +45,7 @@ public function middleware_calls_next_handler(): void $response = $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/test'), - next: new HttpMiddlewareCallable(fn () => $expected), + next: new HttpMiddlewareCallable(static fn () => $expected), ); $this->assertSame($expected, $response); @@ -56,7 +56,7 @@ public function middleware_does_not_track_post_requests(): void { $this->middleware->__invoke( request: new GenericRequest(method: Method::POST, uri: '/form-submit'), - next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), ); $this->assertEquals('/', $this->previousUrl->get()); @@ -65,7 +65,7 @@ public function middleware_does_not_track_post_requests(): void #[Test] public function middleware_tracks_multiple_requests_in_sequence(): void { - $next = new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)); + $next = new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)); $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/page1'), @@ -94,7 +94,7 @@ public function middleware_ignores_ajax_requests(): void { $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/dashboard'), - next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), ); $this->middleware->__invoke( @@ -103,7 +103,7 @@ public function middleware_ignores_ajax_requests(): void uri: '/api/data', headers: ['X-Requested-With' => 'XMLHttpRequest'], ), - next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), ); $this->assertEquals('/dashboard', $this->previousUrl->get()); diff --git a/tests/Integration/Icon/IconTest.php b/tests/Integration/Icon/IconTest.php index a5b040b79..c1fc76cbf 100644 --- a/tests/Integration/Icon/IconTest.php +++ b/tests/Integration/Icon/IconTest.php @@ -134,7 +134,7 @@ private function registerMocks( ->with('https://api.iconify.test/mdi/tsunami.svg') ->willReturn($response ?? new GenericResponse(status: Status::OK, body: '')); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->container->singleton(Icon\IconCache::class, new Icon\IconCache( enabled: true, diff --git a/tests/Integration/Intl/TranslatorTest.php b/tests/Integration/Intl/TranslatorTest.php index b364e022e..7eff90bf4 100644 --- a/tests/Integration/Intl/TranslatorTest.php +++ b/tests/Integration/Intl/TranslatorTest.php @@ -50,7 +50,7 @@ public function test_event_miss(): void $received = null; $eventbus = $this->container->get(EventBus::class); - $eventbus->listen(function (TranslationMiss $event) use (&$received): void { + $eventbus->listen(static function (TranslationMiss $event) use (&$received): void { $received = $event; }); @@ -68,7 +68,7 @@ public function test_event_fail(): void $received = null; $eventbus = $this->container->get(EventBus::class); - $eventbus->listen(function (TranslationFailure $event) use (&$received): void { + $eventbus->listen(static function (TranslationFailure $event) use (&$received): void { $received = $event; }); diff --git a/tests/Integration/Log/GenericLoggerTest.php b/tests/Integration/Log/GenericLoggerTest.php index 05d392c27..18d9763d1 100644 --- a/tests/Integration/Log/GenericLoggerTest.php +++ b/tests/Integration/Log/GenericLoggerTest.php @@ -179,12 +179,12 @@ public function different_log_levels(): void public static function tempestLevelProvider(): array { - return array_map(fn (LogLevel $level) => [$level, strtoupper($level->value)], LogLevel::cases()); + return array_map(static fn (LogLevel $level) => [$level, strtoupper($level->value)], LogLevel::cases()); } public static function monologLevelProvider(): array { - return array_map(fn (Level $level) => [$level, strtoupper($level->name)], Level::cases()); + return array_map(static fn (Level $level) => [$level, strtoupper($level->name)], Level::cases()); } public static function psrLogLevelProvider(): array @@ -192,6 +192,6 @@ public static function psrLogLevelProvider(): array $reflection = new ReflectionClass(PsrLogLevel::class); $levels = $reflection->getConstants(); - return array_map(fn (string $level) => [$level, strtoupper($level)], array_values($levels)); + return array_map(static fn (string $level) => [$level, strtoupper($level)], array_values($levels)); } } diff --git a/tests/Integration/Mailer/AttachmentTest.php b/tests/Integration/Mailer/AttachmentTest.php index 0caa8cd6e..76c5564e0 100644 --- a/tests/Integration/Mailer/AttachmentTest.php +++ b/tests/Integration/Mailer/AttachmentTest.php @@ -48,7 +48,7 @@ public function test_from_path_throws_when_file_does_not_exist(): void public function test_from_closure(): void { $attachment = Attachment::fromClosure( - fn () => 'Hello, world!', + static fn () => 'Hello, world!', 'greeting.txt', 'text/plain', ); diff --git a/tests/Integration/Mailer/MailerTesterTest.php b/tests/Integration/Mailer/MailerTesterTest.php index f13b88f34..7c1b9b205 100644 --- a/tests/Integration/Mailer/MailerTesterTest.php +++ b/tests/Integration/Mailer/MailerTesterTest.php @@ -39,12 +39,12 @@ public function test_assert_sent_with_class_string_and_callback(): void $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage("Email `Tests\Tempest\Integration\Mailer\Fixtures\TextEmail` was sent but failed the assertion."); - $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, fn (Email $_email) => false); + $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, static fn (Email $_email) => false); } public function test_assert_sent_with_class_string_and_truthy_callback(): void { - $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, fn (Email $_email) => true); + $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, static fn (Email $_email) => true); } public function test_assert_not_sent_with_class_string(): void @@ -72,7 +72,7 @@ public function test_assertions(): void html: 'Hello Jon', from: 'no-reply@tempestphp.com', attachments: [ - Attachment::fromClosure(fn () => 'hello!'), + Attachment::fromClosure(static fn () => 'hello!'), ], )) ->assertSent(GenericEmail::class, function (GenericEmail $email): void { @@ -92,7 +92,7 @@ public function test_email_was_sent_event_was_dispatched(): void html: 'Hello Jon', from: 'no-reply@tempestphp.com', attachments: [ - Attachment::fromClosure(callable: fn () => 'hello!'), + Attachment::fromClosure(callable: static fn () => 'hello!'), ], )); diff --git a/tests/Integration/Mailer/SentEmailTest.php b/tests/Integration/Mailer/SentEmailTest.php index 39d396cb9..d2da25fb6 100644 --- a/tests/Integration/Mailer/SentEmailTest.php +++ b/tests/Integration/Mailer/SentEmailTest.php @@ -123,9 +123,9 @@ public function test_assert_attachment_from_closure(): void $this->sendTestEmail( text: 'Hello', attachments: [ - Attachment::fromClosure(fn () => 'hey', name: 'file.txt', contentType: 'text/plain'), + Attachment::fromClosure(static fn () => 'hey', name: 'file.txt', contentType: 'text/plain'), ], - )->assertAttached('file.txt', function (AttachmentTester $attachment): void { + )->assertAttached('file.txt', static function (AttachmentTester $attachment): void { $attachment->assertNamed('file.txt'); $attachment->assertNotNamed('foo.txt'); $attachment->assertType('text'); @@ -140,7 +140,7 @@ public function test_assert_attachment_from_filesystem(): void attachments: [ Attachment::fromFilesystem(__FILE__), ], - )->assertAttached('SentEmailTest.php', function (AttachmentTester $attachment): void { + )->assertAttached('SentEmailTest.php', static function (AttachmentTester $attachment): void { $attachment->assertNamed('SentEmailTest.php'); $attachment->assertNotNamed('foo.txt'); $attachment->assertType('text'); @@ -160,7 +160,7 @@ public function test_assert_attachment_from_storage(): void attachments: [ Attachment::fromStorage($storage, 'file.txt'), ], - )->assertAttached('file.txt', function (AttachmentTester $attachment): void { + )->assertAttached('file.txt', static function (AttachmentTester $attachment): void { $attachment->assertNamed('file.txt'); $attachment->assertNotNamed('foo.txt'); $attachment->assertType('text'); diff --git a/tests/Integration/Mapper/Fixtures/SerializableObject.php b/tests/Integration/Mapper/Fixtures/SerializableObject.php index 3c61c6a39..eb50d53f8 100644 --- a/tests/Integration/Mapper/Fixtures/SerializableObject.php +++ b/tests/Integration/Mapper/Fixtures/SerializableObject.php @@ -6,10 +6,6 @@ final class SerializableObject implements Serializable { - /* - * @mago-expect lint:return-type - * @phpstan-ignore return.unusedType - */ public function serialize() { return 'a'; diff --git a/tests/Integration/Mapper/ObjectFactoryTest.php b/tests/Integration/Mapper/ObjectFactoryTest.php index 05d8ef995..341e09c91 100644 --- a/tests/Integration/Mapper/ObjectFactoryTest.php +++ b/tests/Integration/Mapper/ObjectFactoryTest.php @@ -78,7 +78,7 @@ public function test_cannot_map_exception(): void public function test_map_with(): void { $result = map(['a' => 'a', 'b' => 'b'])->with( - fn (ArrayToObjectMapper $mapper, mixed $from) => $mapper->map($from, ObjectA::class), + static fn (ArrayToObjectMapper $mapper, mixed $from) => $mapper->map($from, ObjectA::class), ObjectToArrayMapper::class, ArrayToJsonMapper::class, )->do(); diff --git a/tests/Integration/Process/ProcessExecutorTest.php b/tests/Integration/Process/ProcessExecutorTest.php index d25cd36fb..71c81809e 100644 --- a/tests/Integration/Process/ProcessExecutorTest.php +++ b/tests/Integration/Process/ProcessExecutorTest.php @@ -93,7 +93,7 @@ public function test_pool(): void while ($invocation->running->isNotEmpty()) { $output = $invocation ->all - ->map(fn (InvokedProcess $process) => $process->output) + ->map(static fn (InvokedProcess $process) => $process->output) ->toArray(); } diff --git a/tests/Integration/Process/ProcessTesterAssertNotRanTest.php b/tests/Integration/Process/ProcessTesterAssertNotRanTest.php index 61e992a6a..de326ad13 100644 --- a/tests/Integration/Process/ProcessTesterAssertNotRanTest.php +++ b/tests/Integration/Process/ProcessTesterAssertNotRanTest.php @@ -22,7 +22,7 @@ public function test_succeeds_when_command_is_not_ran(): void public function test_succeeds_with_callback_when_no_command_ran(): void { $this->process->recordProcessExecutions(); - $this->process->assertCommandDidNotRun(function (): void {}); + $this->process->assertCommandDidNotRun(static function (): void {}); } public function test_succeeds_with_callback_when_other_commands_ran(): void @@ -30,7 +30,7 @@ public function test_succeeds_with_callback_when_other_commands_ran(): void $this->process->mockProcessResult('echo *', 'hello'); $this->executor->run('echo "hello"'); - $this->process->assertCommandDidNotRun(function (PendingProcess $process) { + $this->process->assertCommandDidNotRun(static function (PendingProcess $process) { // this returns false, so expectation succeeds return $process->command === 'echo "world"'; }); @@ -44,7 +44,7 @@ public function test_fails_with_callback_when_returning_false(): void $this->process->mockProcessResult('echo *', 'hello'); $this->executor->run('echo "hello"'); - $this->process->assertCommandDidNotRun(function (PendingProcess $process) { + $this->process->assertCommandDidNotRun(static function (PendingProcess $process) { // this returns true, so expectation fails return $process->command === 'echo "hello"'; }); diff --git a/tests/Integration/Process/ProcessTesterAssertRanTest.php b/tests/Integration/Process/ProcessTesterAssertRanTest.php index 3e0472bec..7a38f4749 100644 --- a/tests/Integration/Process/ProcessTesterAssertRanTest.php +++ b/tests/Integration/Process/ProcessTesterAssertRanTest.php @@ -29,7 +29,7 @@ public function test_expectation_succeeds_when_command_is_ran_and_callback_retur { $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', function (ProcessResult $result) { + $this->process->assertCommandRan('echo *', static function (ProcessResult $result) { return $result->output === "hello\n"; }); } @@ -51,7 +51,7 @@ public function test_expectation_fails_when_command_is_ran_and_callback_returns_ $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', function (ProcessResult $result) { + $this->process->assertCommandRan('echo *', static function (ProcessResult $result) { return $result->output !== "hello\n"; }); } @@ -60,7 +60,7 @@ public function test_expectation_succeeds_when_callback_returns_nothing(): void { $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', function (): void {}); + $this->process->assertCommandRan('echo *', static function (): void {}); } public function test_expectation_succeeds_when_callback_returns_true(): void @@ -68,7 +68,7 @@ public function test_expectation_succeeds_when_callback_returns_true(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(function (PendingProcess $process): bool { + $this->process->assertRan(static function (PendingProcess $process): bool { return $process->command === 'echo "hello"'; }); } @@ -81,7 +81,7 @@ public function test_returning_false_from_callback_fails_expectation(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(function (PendingProcess $_process): bool { + $this->process->assertRan(static function (PendingProcess $_process): bool { return false; }); } @@ -92,7 +92,7 @@ public function test_returning_true_from_callback_skips_other_iterations(): void $this->executor->run('echo "hello"'); $this->executor->run('echo "world"'); - $this->process->assertRan(function (PendingProcess $process): bool { + $this->process->assertRan(static function (PendingProcess $process): bool { if ($process->command === 'echo "hello"') { return true; } @@ -109,7 +109,7 @@ public function test_never_returning_fails_expectation(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(function (PendingProcess $_process): void { + $this->process->assertRan(static function (PendingProcess $_process): void { // This callback never returns. }); } diff --git a/tests/Integration/Process/ProcessTesterTest.php b/tests/Integration/Process/ProcessTesterTest.php index 4280a9969..6cb8d8192 100644 --- a/tests/Integration/Process/ProcessTesterTest.php +++ b/tests/Integration/Process/ProcessTesterTest.php @@ -94,7 +94,7 @@ public function test_assert_ran_times_with_callback(): void $this->executor->run('echo "hello"'); $this->executor->run('echo "hello"'); - $this->process->assertRanTimes(fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 2); + $this->process->assertRanTimes(static fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 2); } public function test_assert_ran_times_with_string_failure(): void @@ -118,7 +118,7 @@ public function test_assert_ran_times_with_callback_failure(): void $this->executor->run('echo "hello"'); $this->executor->run('echo "hello"'); - $this->process->assertRanTimes(fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 1); + $this->process->assertRanTimes(static fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 1); } public function test_assert_ran_times_with_unrelated_callback(): void @@ -128,7 +128,7 @@ public function test_assert_ran_times_with_unrelated_callback(): void $this->executor->run('echo "hello"'); $this->process->assertRanTimes('echo *', times: 2); - $this->process->assertRanTimes(fn (PendingProcess $process) => $process->command === 'echo "world"', times: 0); + $this->process->assertRanTimes(static fn (PendingProcess $process) => $process->command === 'echo "world"', times: 0); } public function test_register_multiple_process_results(): void diff --git a/tests/Integration/Route/ClientTest.php b/tests/Integration/Route/ClientTest.php index e5e93dbf1..f8ccf0357 100644 --- a/tests/Integration/Route/ClientTest.php +++ b/tests/Integration/Route/ClientTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->server->start(); // Server needs to start - usleep(100000); + usleep(100_000); // We'll use the client interface directly because we want to write raw post data in this test $this->driver = $this->container->get(ClientInterface::class); diff --git a/tests/Integration/Route/RequestToObjectMapperTest.php b/tests/Integration/Route/RequestToObjectMapperTest.php index 176ccc11f..12297cb41 100644 --- a/tests/Integration/Route/RequestToObjectMapperTest.php +++ b/tests/Integration/Route/RequestToObjectMapperTest.php @@ -81,7 +81,7 @@ public function test_query_params_with_types(): void $this->assertSame(1, $request->intParam); $this->assertSame('a', $request->stringParam); - $this->assertSame(true, $request->boolParam); + $this->assertTrue($request->boolParam); $this->assertSame(0.1, $request->floatParam); } @@ -115,7 +115,7 @@ public function test_reserved_properties_cannot_be_mapped(): void { $this->assertException( expectedExceptionClass: RequestParametersIncludedReservedNames::class, - handler: function (): void { + handler: static function (): void { map(new GenericRequest( method: Method::GET, uri: '/books?uri=invalid', diff --git a/tests/Integration/Storage/StorageTesterTest.php b/tests/Integration/Storage/StorageTesterTest.php index 00599b7e1..286a1857d 100644 --- a/tests/Integration/Storage/StorageTesterTest.php +++ b/tests/Integration/Storage/StorageTesterTest.php @@ -133,7 +133,7 @@ public function test_public_url(): void { $storage = $this->storage->fake(); - $storage->createPublicUrlsUsing(fn (string $path) => sprintf('https://localhost/%s', $path)); + $storage->createPublicUrlsUsing(static fn (string $path) => sprintf('https://localhost/%s', $path)); $storage = $this->container->get(Storage::class); $storage->write('foo.txt', 'bar'); @@ -145,7 +145,7 @@ public function test_temporary_urls(): void { $storage = $this->storage->fake(); - $storage->createTemporaryUrlsUsing(fn (string $path, DateTimeInterface $expiresAt) => sprintf( + $storage->createTemporaryUrlsUsing(static fn (string $path, DateTimeInterface $expiresAt) => sprintf( 'https://localhost/%s?expires=%s', $path, $expiresAt->format(DateTimeInterface::RFC3339), diff --git a/tests/Integration/Validator/ExistsRuleTest.php b/tests/Integration/Validator/ExistsRuleTest.php index c4f328521..fe0d38849 100644 --- a/tests/Integration/Validator/ExistsRuleTest.php +++ b/tests/Integration/Validator/ExistsRuleTest.php @@ -45,8 +45,8 @@ public function non_existent_record_returns_false(): void { Book::create(title: 'Timeline Taxi'); - $this->assertFalse(new Exists(Book::class)->isValid(99999)); - $this->assertFalse(new Exists(Book::class)->isValid(12345)); + $this->assertFalse(new Exists(Book::class)->isValid(99_999)); + $this->assertFalse(new Exists(Book::class)->isValid(12_345)); $this->assertFalse(new Exists(Book::class, column: 'title')->isValid('Timeline Taxi 2')); } @@ -60,6 +60,6 @@ public function validates_multiple_existing_records(): void $this->assertTrue(new Exists(Book::class)->isValid($book1->id)); $this->assertTrue(new Exists(Book::class)->isValid($book2->id)); $this->assertTrue(new Exists(Book::class)->isValid($book3->id)); - $this->assertFalse(new Exists(Book::class)->isValid(99999)); + $this->assertFalse(new Exists(Book::class)->isValid(99_999)); } } diff --git a/tests/Integration/View/Components/IconComponentTest.php b/tests/Integration/View/Components/IconComponentTest.php index 2221b9842..2d99078ac 100644 --- a/tests/Integration/View/Components/IconComponentTest.php +++ b/tests/Integration/View/Components/IconComponentTest.php @@ -41,7 +41,7 @@ public function test_it_renders_an_icon(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->assertSame( '', @@ -61,11 +61,11 @@ public function test_it_downloads_the_icon_from_a_custom_api(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->container->singleton( IconConfig::class, - fn () => new IconConfig(iconifyApiUrl: 'https://api.iconify.test', retryAfter: Duration::hours(12)), + static fn () => new IconConfig(iconifyApiUrl: 'https://api.iconify.test', retryAfter: Duration::hours(12)), ); $this->assertSame( @@ -94,7 +94,7 @@ public function test_it_caches_icons_on_the_first_render(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->view->render(''); @@ -120,7 +120,7 @@ public function test_it_renders_an_icon_from_cache(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); // Trigger first render, which should cache the icon $this->view->render(''); @@ -140,7 +140,7 @@ public function test_it_renders_a_debug_comment_in_local_env_when_icon_does_not_ ->with('https://api.iconify.design/material-symbols/php.svg') ->willReturn(new GenericResponse(status: Status::NOT_FOUND, body: '')); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->container->singleton(Environment::class, Environment::LOCAL); $this->assertSame( @@ -158,7 +158,7 @@ public function test_it_renders_an_empty_string__in_non_local_env_when_icon_does ->with('https://api.iconify.design/material-symbols/php.svg') ->willReturn(new GenericResponse(status: Status::NOT_FOUND, body: '')); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->container->singleton(Environment::class, Environment::PRODUCTION); $this->assertSame( @@ -179,7 +179,7 @@ public function test_it_forwards_the_class_attribute(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->assertSame( '', @@ -201,7 +201,7 @@ public function test_it_forwards_the_style_attribute(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->assertSame( '', @@ -223,7 +223,7 @@ public function test_it_handles_width_and_height_together_props(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->assertSame( '', @@ -245,7 +245,7 @@ public function test_fallback_dimensions_when_none_defined_in_any_supported_meth body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $this->assertSame( '', @@ -267,7 +267,7 @@ public function test_with_dynamic_data(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $rendered = $this->view->render( '', @@ -294,7 +294,7 @@ public function test_icon_renders_inside_named_slot_in_a_layout(): void body: '', )); - $this->container->register(HttpClient::class, fn () => $mockHttpClient); + $this->container->register(HttpClient::class, static fn () => $mockHttpClient); $view = view(__DIR__ . '/../../../Fixtures/Views/view-with-icon-inside-named-slot.view.php'); $html = $this->view->render($view); diff --git a/tests/Integration/View/ElementFactoryTest.php b/tests/Integration/View/ElementFactoryTest.php index 603fa9072..bab9f7b74 100644 --- a/tests/Integration/View/ElementFactoryTest.php +++ b/tests/Integration/View/ElementFactoryTest.php @@ -77,7 +77,7 @@ public function test_parental_relations(): void private function withoutWhitespace(array $elements): array { return arr($elements) - ->filter(fn (Element $element) => ! $element instanceof WhitespaceElement) + ->filter(static fn (Element $element) => ! $element instanceof WhitespaceElement) ->values() ->toArray(); } diff --git a/tests/Integration/View/ViewCacheTest.php b/tests/Integration/View/ViewCacheTest.php index 0a805812f..4a5cae0f2 100644 --- a/tests/Integration/View/ViewCacheTest.php +++ b/tests/Integration/View/ViewCacheTest.php @@ -37,7 +37,7 @@ protected function tearDown(): void $directory = path(self::DIRECTORY); if ($directory->isDirectory()) { - $directory->glob('/*.php')->each(fn (string $file) => unlink($file)); + $directory->glob('/*.php')->each(static fn (string $file) => unlink($file)); rmdir(self::DIRECTORY); } @@ -103,7 +103,7 @@ public function overriden_by_view_cache_locally(): void public function test_view_cache(): void { - $path = $this->viewCache->getCachedViewPath('path', fn () => 'hi'); + $path = $this->viewCache->getCachedViewPath('path', static fn () => 'hi'); $this->assertFileExists($path); $this->assertSame('hi', file_get_contents($path)); @@ -115,7 +115,7 @@ public function test_view_cache_when_disabled(): void $this->viewCache->enabled = false; - $compileFunction = function () use (&$hit) { + $compileFunction = static function () use (&$hit) { $hit += 1; return 'hi'; @@ -135,7 +135,7 @@ public function test_view_cache_when_enabled(): void $this->viewCache->enabled = true; - $compileFunction = function () use (&$hit) { + $compileFunction = static function () use (&$hit) { $hit += 1; return 'hi'; diff --git a/tests/Integration/View/ViewComponentDiscoveryTest.php b/tests/Integration/View/ViewComponentDiscoveryTest.php index 117daef48..5a074ff43 100644 --- a/tests/Integration/View/ViewComponentDiscoveryTest.php +++ b/tests/Integration/View/ViewComponentDiscoveryTest.php @@ -46,7 +46,7 @@ public function test_project_view_components_cannot_be_overwritten_by_other_proj $this->assertException( ViewComponentWasAlreadyRegistered::class, - function () use ($viewConfig): void { + static function () use ($viewConfig): void { $viewConfig->addViewComponent(new ViewComponent( name: 'x-form', contents: 'b', diff --git a/tests/Integration/View/ViewComponentTest.php b/tests/Integration/View/ViewComponentTest.php index 2ed4064ed..4e5ef900a 100644 --- a/tests/Integration/View/ViewComponentTest.php +++ b/tests/Integration/View/ViewComponentTest.php @@ -1107,7 +1107,7 @@ public function does_not_duplicate_view_compilation_frames_in_stacktrace(): void $this->assertException( ViewCompilationFailed::class, - function () use ($viewRenderer): void { + static function () use ($viewRenderer): void { $viewRenderer->render(view(__DIR__ . '/Fixtures/stacktrace-standalone-error.view.php')); }, function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { @@ -1121,7 +1121,7 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { $renderCompiledFrames = array_values(array_filter( $stacktrace['applicationFrames'], - fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', + static fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', )); $this->assertCount(1, $renderCompiledFrames); @@ -1160,7 +1160,7 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { $renderCompiledFrames = array_values(array_filter( $stacktrace['applicationFrames'], - fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', + static fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', )); $this->assertCount(1, $renderCompiledFrames); diff --git a/tests/Integration/Vite/ViteTesterTest.php b/tests/Integration/Vite/ViteTesterTest.php index 34a6dc9eb..5e6e53fd5 100644 --- a/tests/Integration/Vite/ViteTesterTest.php +++ b/tests/Integration/Vite/ViteTesterTest.php @@ -73,17 +73,17 @@ public function test_call_requires_root(): void $this->expectException(InvalidArgumentException::class); $this->vite->call( - callback: fn () => null, + callback: static fn () => null, files: [], ); } public function test_retains_tags_resolver(): void { - $this->container->register(TagsResolver::class, fn () => new NullTagsResolver()); + $this->container->register(TagsResolver::class, static fn () => new NullTagsResolver()); $this->vite->call( - callback: fn () => null, + callback: static fn () => null, files: [], root: __DIR__ . '/Fixtures/tmp', ); From fff8ce70b7834ca05abd7c8394e9e9ca2abf19d3 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:15:10 +0100 Subject: [PATCH 04/14] Run mago and rector --- mago.toml | 4 ++++ .../database/src/QueryStatements/CreateTableStatement.php | 6 +++--- rector.php | 1 + tests/Integration/Database/Builder/IsDatabaseModelTest.php | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mago.toml b/mago.toml index f4bb4ab79..2e54179da 100644 --- a/mago.toml +++ b/mago.toml @@ -15,6 +15,7 @@ excludes = [ "**/*.expected.php", "**/.tempest", "./vendor/rector", #see https://github.com/carthage-software/mago/issues/1237 rector clashes and throws errors in tests + "packages/intl/bin/plural-rules.php", ] [formatter] @@ -65,3 +66,6 @@ prefer-first-class-callable = { enabled = false } # enable when arguments are fi strict-behavior = { allow-loose-behavior = true } no-redundant-use = { enabled = true } no-empty-comment = { enabled = false } +single-class-per-file = { enabled = false } +no-isset = { enabled = false } +instanceof-stringable = { enabled = false } diff --git a/packages/database/src/QueryStatements/CreateTableStatement.php b/packages/database/src/QueryStatements/CreateTableStatement.php index 28e9b2d6e..75159004d 100644 --- a/packages/database/src/QueryStatements/CreateTableStatement.php +++ b/packages/database/src/QueryStatements/CreateTableStatement.php @@ -400,9 +400,9 @@ public function compile(DatabaseDialect $dialect): string new TableDefinition($this->tableName), arr($this->statements) // Remove BelongsTo for sqlLite as it does not support those queries - ->filter(fn (QueryStatement $queryStatement) => ! ($dialect === DatabaseDialect::SQLITE && $queryStatement instanceof BelongsToStatement)) - ->map(fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) - ->filter(fn (ImmutableString $str) => $str->isNotEmpty()) + ->filter(static fn (QueryStatement $queryStatement) => ! ($dialect === DatabaseDialect::SQLITE && $queryStatement instanceof BelongsToStatement)) + ->map(static fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) + ->filter(static fn (ImmutableString $str) => $str->isNotEmpty()) ->implode(', ' . PHP_EOL . ' ') ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), diff --git a/rector.php b/rector.php index b511c8c6c..5f13cad10 100644 --- a/rector.php +++ b/rector.php @@ -29,6 +29,7 @@ __DIR__ . '/src', __DIR__ . '/tests', ]) + ->withSkipPath(__DIR__ . '/tests/PHPStan/QueryFunctionDynamicReturnTypeExtension.php') ->withConfiguredRule(AddSensitiveParameterAttributeRector::class, [ 'sensitive_parameters' => [ 'password', diff --git a/tests/Integration/Database/Builder/IsDatabaseModelTest.php b/tests/Integration/Database/Builder/IsDatabaseModelTest.php index 1a312bad0..f3a60efe7 100644 --- a/tests/Integration/Database/Builder/IsDatabaseModelTest.php +++ b/tests/Integration/Database/Builder/IsDatabaseModelTest.php @@ -771,6 +771,7 @@ public function test_on_database_does_not_mutate_original(): void // Original still works against default database $foo->update(bar: 'updated'); + $refreshed = Foo::get($foo->id); $this->assertSame('updated', $refreshed->bar); From a02fddb15419d50fde4cd1bad8ae2880816d2579 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:17:16 +0100 Subject: [PATCH 05/14] Fix CI action --- .github/workflows/coding-conventions.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/coding-conventions.yml b/.github/workflows/coding-conventions.yml index 8a69535a1..913f97d80 100644 --- a/.github/workflows/coding-conventions.yml +++ b/.github/workflows/coding-conventions.yml @@ -24,7 +24,6 @@ jobs: - name: Install dependencies run: | composer update --prefer-dist --no-interaction --ignore-platform-reqs - composer mago:install-binary - name: Run Mago run: | From 3642d7a04c8d259a30d0060d3b65aa90466eb266 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:31:59 +0100 Subject: [PATCH 06/14] WIP --- packages/validation/tests/Rules/ValidateWithTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/validation/tests/Rules/ValidateWithTest.php b/packages/validation/tests/Rules/ValidateWithTest.php index 62323e3db..82ea0a373 100644 --- a/packages/validation/tests/Rules/ValidateWithTest.php +++ b/packages/validation/tests/Rules/ValidateWithTest.php @@ -49,11 +49,4 @@ public function test_non_string_value_fails(): void $this->assertFalse($rule->isValid(null)); $this->assertFalse($rule->isValid(false)); } - - public function test_static_closure_required(): void - { - $this->expectException(\InvalidArgumentException::class); - - new ValidateWith(static fn (mixed $value): bool => str_contains((string) $value, '@')); - } } From 2c11b1400b98cf13b664ec4edfdce3f10795dfa8 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:37:55 +0100 Subject: [PATCH 07/14] WIP --- mago.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/mago.toml b/mago.toml index 2e54179da..b67ba28df 100644 --- a/mago.toml +++ b/mago.toml @@ -69,3 +69,4 @@ no-empty-comment = { enabled = false } single-class-per-file = { enabled = false } no-isset = { enabled = false } instanceof-stringable = { enabled = false } +prefer-static-closure = { enabled = false } From 23a0666879bad01111765969530d5ea3067e92fe Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:38:38 +0100 Subject: [PATCH 08/14] Revert "Run mago and rector" This reverts commit fff8ce70b7834ca05abd7c8394e9e9ca2abf19d3. # Conflicts: # mago.toml --- .../database/src/QueryStatements/CreateTableStatement.php | 6 +++--- rector.php | 1 - tests/Integration/Database/Builder/IsDatabaseModelTest.php | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/database/src/QueryStatements/CreateTableStatement.php b/packages/database/src/QueryStatements/CreateTableStatement.php index 75159004d..28e9b2d6e 100644 --- a/packages/database/src/QueryStatements/CreateTableStatement.php +++ b/packages/database/src/QueryStatements/CreateTableStatement.php @@ -400,9 +400,9 @@ public function compile(DatabaseDialect $dialect): string new TableDefinition($this->tableName), arr($this->statements) // Remove BelongsTo for sqlLite as it does not support those queries - ->filter(static fn (QueryStatement $queryStatement) => ! ($dialect === DatabaseDialect::SQLITE && $queryStatement instanceof BelongsToStatement)) - ->map(static fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) - ->filter(static fn (ImmutableString $str) => $str->isNotEmpty()) + ->filter(fn (QueryStatement $queryStatement) => ! ($dialect === DatabaseDialect::SQLITE && $queryStatement instanceof BelongsToStatement)) + ->map(fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) + ->filter(fn (ImmutableString $str) => $str->isNotEmpty()) ->implode(', ' . PHP_EOL . ' ') ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), diff --git a/rector.php b/rector.php index 5f13cad10..b511c8c6c 100644 --- a/rector.php +++ b/rector.php @@ -29,7 +29,6 @@ __DIR__ . '/src', __DIR__ . '/tests', ]) - ->withSkipPath(__DIR__ . '/tests/PHPStan/QueryFunctionDynamicReturnTypeExtension.php') ->withConfiguredRule(AddSensitiveParameterAttributeRector::class, [ 'sensitive_parameters' => [ 'password', diff --git a/tests/Integration/Database/Builder/IsDatabaseModelTest.php b/tests/Integration/Database/Builder/IsDatabaseModelTest.php index f3a60efe7..1a312bad0 100644 --- a/tests/Integration/Database/Builder/IsDatabaseModelTest.php +++ b/tests/Integration/Database/Builder/IsDatabaseModelTest.php @@ -771,7 +771,6 @@ public function test_on_database_does_not_mutate_original(): void // Original still works against default database $foo->update(bar: 'updated'); - $refreshed = Foo::get($foo->id); $this->assertSame('updated', $refreshed->bar); From a019dfde661ca698a2ec8827a878515d8a4692d7 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:39:04 +0100 Subject: [PATCH 09/14] Revert "Run mago" This reverts commit 4792f58487bdc90708f9575678dc636d3ecb5ea7. # Conflicts: # packages/validation/tests/Rules/ValidateWithTest.php --- .../PolicyBasedAccessControl.php | 6 +- .../src/AccessControl/PolicyDiscovery.php | 1 + .../auth/src/Installer/OAuthInstaller.php | 8 +- .../Installer/oauth/OAuthControllerStub.php | 2 +- .../src/OAuth/Config/DiscordOAuthConfig.php | 1 - .../src/OAuth/Config/FacebookOAuthConfig.php | 1 - .../src/OAuth/Config/GenericOAuthConfig.php | 2 - .../src/OAuth/Config/GitHubOAuthConfig.php | 1 - .../src/OAuth/Config/GoogleOAuthConfig.php | 1 - .../src/OAuth/Config/InstagramOAuthConfig.php | 1 - .../src/OAuth/Config/LinkedInOAuthConfig.php | 1 - .../src/OAuth/Config/MicrosoftOAuthConfig.php | 1 - .../src/OAuth/Config/SlackOAuthConfig.php | 1 - .../src/OAuth/Config/TwitchOAuthConfig.php | 1 - .../auth/src/OAuth/GenericOAuthClient.php | 2 +- packages/auth/src/OAuth/OAuthClient.php | 2 +- packages/auth/src/OAuth/OAuthProvider.php | 2 +- .../src/OAuth/Testing/TestingOAuthClient.php | 6 +- packages/auth/tests/OAuthTest.php | 2 +- .../cache/src/Commands/CacheClearCommand.php | 4 +- packages/cache/src/GenericCache.php | 2 +- .../FileCommandRepository.php | 2 +- .../command-bus/src/MonitorAsyncCommands.php | 48 +++++------ packages/command-bus/src/functions.php | 1 + .../src/Actions/RenderConsoleCommand.php | 2 +- .../src/Actions/ResolveConsoleCommand.php | 2 +- .../console/src/Commands/AboutCommand.php | 4 +- .../src/Commands/MakeCommandCommand.php | 2 +- .../Commands/MakeGeneratorCommandCommand.php | 2 +- .../src/Commands/MakeMiddlewareCommand.php | 2 +- .../src/Completion/CompletionEngine.php | 6 +- .../Components/Concerns/RendersControls.php | 2 +- .../Interactive/ProgressBarComponent.php | 2 +- .../Components/Interactive/TaskComponent.php | 10 +-- .../InteractiveComponentRenderer.php | 6 +- .../src/Components/OptionCollection.php | 12 +-- .../Renderers/InstructionsRenderer.php | 2 +- .../Components/Renderers/KeyValueRenderer.php | 6 +- .../Components/Renderers/MessageRenderer.php | 2 +- .../src/Components/Renderers/TaskRenderer.php | 2 +- .../Renderers/TextInputRenderer.php | 4 +- .../Static/StaticMultipleChoiceComponent.php | 8 +- .../Static/StaticProgressBarComponent.php | 2 +- .../Static/StaticSingleChoiceComponent.php | 2 +- .../Components/Static/StaticTaskComponent.php | 2 +- packages/console/src/ConsoleInputBuilder.php | 2 +- .../Exceptions/ConsoleExceptionHandler.php | 4 +- .../Exceptions/InvalidCommandException.php | 2 +- .../src/Exceptions/InvalidEnumArgument.php | 2 +- .../Exceptions/UnknownArgumentsException.php | 2 +- .../Injections/DynamicInjection.php | 2 +- .../Injections/FileInjection.php | 2 +- .../Injections/LinkInjection.php | 2 +- .../src/Highlight/TempestTerminalTheme.php | 2 +- .../ConsoleApplicationInitializer.php | 2 +- .../console/src/Input/ConsoleArgumentBag.php | 36 ++++---- .../console/src/Input/MemoryInputBuffer.php | 2 +- .../src/Installers/ConsoleInstaller.php | 2 +- .../console/src/Middleware/HelpMiddleware.php | 6 +- .../src/Middleware/OverviewMiddleware.php | 6 +- .../Middleware/ResolveOrRescueMiddleware.php | 6 +- .../ValidateNamedArgumentsMiddleware.php | 10 +-- .../console/src/Output/MemoryOutputBuffer.php | 2 +- packages/console/src/Output/TailReader.php | 2 +- .../src/Scheduler/GenericScheduler.php | 2 +- .../src/Stubs/GeneratorCommandStub.php | 2 +- packages/console/src/Terminal/Terminal.php | 4 +- .../console/src/Testing/ConsoleTester.php | 4 +- .../console/tests/CompletionHelperPhpTest.php | 2 +- .../console/tests/OptionCollectionTest.php | 6 +- .../src/Commands/MakeInitializerCommand.php | 2 +- .../CircularDependencyEncountered.php | 2 +- .../DependencyCouldNotBeAutowired.php | 2 +- .../TaggedDependencyCouldNotBeResolved.php | 2 +- packages/container/src/functions.php | 1 + packages/container/tests/ContainerTest.php | 50 +++++------ .../tests/Fixtures/SlowDependency.php | 2 +- packages/core/src/Commands/InstallCommand.php | 4 +- packages/core/src/Composer.php | 20 ++--- .../core/src/EnvironmentValueWasInvalid.php | 2 +- .../EnvironmentVariableValidationFailed.php | 2 +- .../core/src/Exceptions/ExceptionTester.php | 2 +- packages/core/src/FrameworkKernel.php | 6 +- .../core/src/InsightsProviderDiscovery.php | 1 + packages/core/src/IsComponentInstaller.php | 2 +- packages/core/src/Kernel/LoadConfig.php | 4 +- .../core/src/Kernel/LoadDiscoveryClasses.php | 6 +- packages/core/src/Middleware.php | 6 +- packages/core/src/PublishesFiles.php | 10 +-- packages/core/src/functions.php | 1 + packages/cryptography/tests/TimelockTest.php | 10 +-- .../database/src/Builder/ModelInspector.php | 8 +- .../QueryBuilders/CountQueryBuilder.php | 2 +- .../HasConvenientWhereMethods.php | 6 +- .../src/Commands/MakeMigrationCommand.php | 2 +- packages/database/src/DatabaseInitializer.php | 2 +- .../Exceptions/InsertColumnsMismatched.php | 4 +- packages/database/src/IsDatabaseModel.php | 14 +-- .../src/Mappers/SelectModelMapper.php | 2 +- .../src/Migrations/MigrationManager.php | 4 +- .../src/Migrations/RunnableMigrations.php | 12 +-- .../QueryStatements/AlterTableStatement.php | 4 +- .../src/QueryStatements/CompoundStatement.php | 2 +- .../src/QueryStatements/CountStatement.php | 4 +- .../CreateEnumTypeStatement.php | 6 +- .../QueryStatements/CreateTableStatement.php | 4 +- .../src/QueryStatements/DeleteStatement.php | 4 +- .../src/QueryStatements/EnumStatement.php | 6 +- .../src/QueryStatements/FieldStatement.php | 4 +- .../src/QueryStatements/InsertStatement.php | 6 +- .../src/QueryStatements/SelectStatement.php | 14 +-- .../src/QueryStatements/UpdateStatement.php | 6 +- .../QueryStatements/WhereGroupStatement.php | 4 +- .../DataTransferObjectSerializer.php | 2 +- packages/database/src/functions.php | 4 +- .../tests/Config/DatabaseConfigTest.php | 2 +- .../database/tests/GenericDatabaseTest.php | 4 +- packages/datetime/src/SecondsStyle.php | 2 +- packages/datetime/src/functions.php | 8 ++ packages/datetime/tests/DateTimeTest.php | 38 ++++---- packages/datetime/tests/DurationTest.php | 58 ++++++------- packages/datetime/tests/SecondsStyleTest.php | 2 +- packages/datetime/tests/TimestampTest.php | 52 +++++------ packages/datetime/tests/TimezoneTest.php | 14 +-- packages/debug/src/Debug.php | 2 +- packages/debug/src/Stacktrace/Frame.php | 2 +- packages/debug/src/Stacktrace/Stacktrace.php | 6 +- packages/debug/tests/StacktraceTest.php | 6 +- .../src/Commands/MakeDiscoveryCommand.php | 2 +- packages/discovery/src/DiscoveryItems.php | 2 +- .../event-bus/src/Testing/EventBusTester.php | 2 +- packages/event-bus/src/functions.php | 2 + packages/event-bus/tests/EventBusTest.php | 12 +-- .../src/Php/ManipulatesPhpClasses.php | 6 +- .../src/Php/SimplifiesClassNames.php | 10 +-- .../generation/src/Php/StubFileGenerator.php | 7 +- .../src/TypeScript/TypeResolverDiscovery.php | 4 +- .../TypeScript/Writers/DirectoryWriter.php | 38 ++++---- .../tests/Php/ClassManipulatorTest.php | 4 +- packages/http/src/Input/StdinInputStream.php | 2 +- packages/http/src/IsResponse.php | 2 +- .../PsrRequestToGenericRequestMapper.php | 4 +- .../src/Mappers/RequestToObjectMapper.php | 4 +- packages/http/src/RequestHeaders.php | 4 +- .../Session/SessionIdResolverInitializer.php | 1 + .../PsrRequestToGenericRequestMapperTest.php | 4 +- .../tests/IdempotencyMiddlewareTest.php | 24 +++--- .../tests/IdempotentCommandMiddlewareTest.php | 18 ++-- packages/intl/src/GenericTranslator.php | 2 + packages/intl/src/IntlConfig.php | 1 + .../Formatter/MessageFormatter.php | 16 ++-- .../Parser/MessageFormatParser.php | 2 +- .../src/PluralRules/PluralRulesMatcher.php | 26 +++--- packages/intl/src/TranslationFailure.php | 2 + .../intl/src/TranslationMessageDiscovery.php | 3 +- packages/intl/src/TranslationMiss.php | 2 + packages/intl/src/Translator.php | 2 + packages/intl/src/TranslatorInitializer.php | 1 + packages/intl/src/functions.php | 2 + packages/intl/tests/FunctionsTest.php | 82 +++++++++--------- packages/intl/tests/LocaleTest.php | 24 ++---- .../kv-store/src/Redis/Config/RedisConfig.php | 1 - .../kv-store/src/Redis/PhpRedisClient.php | 2 +- packages/kv-store/src/Redis/PredisClient.php | 2 +- packages/log/src/TailLogsCommand.php | 9 +- packages/mail/src/Attachment.php | 4 +- .../mail/src/EmailToSymfonyEmailMapper.php | 2 +- packages/mail/src/MailerInitializer.php | 1 + packages/mail/src/Testing/MailTester.php | 28 +++--- .../src/Transports/RoundRobinMailerConfig.php | 2 +- .../src/Transports/Ses/SesMailerConfig.php | 1 - .../Transports/Ses/SesSmtpMailerConfig.php | 1 - .../src/Transports/Smtp/SmtpMailerConfig.php | 1 - .../src/Mappers/ObjectToArrayMapper.php | 6 +- packages/mapper/src/functions.php | 1 + packages/process/src/InvokedProcessPool.php | 12 +-- packages/process/src/InvokedSystemProcess.php | 2 +- packages/process/src/ProcessPoolResults.php | 12 +-- .../src/Testing/InvokedProcessDescription.php | 2 +- .../src/Testing/InvokedTestingProcess.php | 12 +-- .../process/src/Testing/ProcessTester.php | 12 +-- .../tests/GenericProcessExecutorTest.php | 2 +- packages/reflection/src/ClassReflector.php | 8 +- packages/reflection/src/EnumReflector.php | 2 +- packages/reflection/src/FunctionReflector.php | 2 +- packages/reflection/src/MethodReflector.php | 2 +- packages/reflection/src/TypeReflector.php | 2 +- packages/reflection/src/functions.php | 2 + .../tests/Fixtures/NoReturnType.php | 1 + .../tests/FunctionReflectorTest.php | 2 +- .../src/Commands/MakeControllerCommand.php | 2 +- .../src/Exceptions/HtmlExceptionRenderer.php | 6 +- .../src/Exceptions/JsonExceptionRenderer.php | 2 +- packages/router/src/GenericRouter.php | 2 +- .../src/HandleRouteSpecificMiddleware.php | 2 +- packages/router/src/MatchRouteMiddleware.php | 15 ++-- .../router/src/RouteBindingInitializer.php | 10 +-- .../RouteMatchingRegexBuilder.php | 2 +- .../router/src/Static/StaticCleanCommand.php | 6 +- packages/router/src/functions.php | 1 + .../storage/src/Config/FTPStorageConfig.php | 1 - .../storage/src/Config/S3StorageConfig.php | 1 - .../storage/src/Config/SFTPStorageConfig.php | 1 - packages/support/src/Arr/ManipulatesArray.php | 2 +- packages/support/src/Arr/functions.php | 26 +++--- packages/support/src/IsEnumHelper.php | 2 +- .../src/JavaScript/DependencyInstaller.php | 2 +- .../support/src/JavaScript/PackageManager.php | 2 +- .../Json/Exception/JsonCouldNotBeDecoded.php | 1 + .../Json/Exception/JsonCouldNotBeEncoded.php | 1 + packages/support/src/Math/constants.php | 30 +++---- packages/support/src/Math/functions.php | 24 ++---- packages/support/src/Uri/Uri.php | 10 +-- packages/support/src/Uri/functions.php | 2 +- .../tests/Arr/ManipulatesArrayTest.php | 86 +++++++++---------- .../tests/Conditions/HasConditionsTest.php | 10 +-- packages/support/tests/Math/MathsTest.php | 86 +++++++++---------- .../tests/Paginator/PaginatedDataTest.php | 2 +- .../support/tests/Paginator/PaginatorTest.php | 2 +- packages/support/tests/Path/PathTest.php | 2 +- .../support/tests/Regex/FunctionsTest.php | 6 +- packages/support/tests/Str/FunctionsTest.php | 2 +- .../tests/Str/ManipulatesStringTest.php | 4 +- packages/validation/src/Validator.php | 4 +- .../tests/Rules/IsJsonStringTest.php | 2 +- .../validation/tests/Rules/IsPasswordTest.php | 4 +- .../tests/Rules/ValidateWithTest.php | 7 ++ packages/validation/tests/ValidatorTest.php | 12 +-- packages/view/src/Elements/ElementFactory.php | 2 +- packages/view/src/Elements/GenericElement.php | 1 - packages/view/src/Elements/IsElement.php | 8 +- packages/view/src/Elements/PhpElement.php | 1 - packages/view/src/Elements/RawElement.php | 1 - packages/view/src/Elements/RootElement.php | 6 +- packages/view/src/Elements/SlotElement.php | 1 - .../view/src/Elements/TemplateElement.php | 1 - packages/view/src/Elements/TextElement.php | 4 +- .../src/Elements/ViewComponentElement.php | 43 +++++----- .../view/src/Export/ViewObjectExporter.php | 4 +- .../src/Initializers/ViewCacheInitializer.php | 4 +- packages/view/src/Parser/TempestViewAst.php | 4 +- .../view/src/Parser/TempestViewCompiler.php | 4 +- .../view/src/Parser/TempestViewParser.php | 2 +- packages/view/src/Parser/Token.php | 8 +- packages/view/src/Parser/TokenCollection.php | 4 +- packages/view/src/Slot.php | 2 +- packages/view/src/ViewCachePool.php | 2 +- packages/view/src/functions.php | 3 + packages/view/tests/ViewCachePoolTest.php | 2 +- packages/vite/src/Installer/ViteInstaller.php | 2 +- packages/vite/src/Manifest/Manifest.php | 4 +- .../TagsResolver/DevelopmentTagsResolver.php | 4 +- .../src/TagsResolver/ManifestTagsResolver.php | 8 +- packages/vite/src/ViteDiscovery.php | 1 + packages/vite/src/functions.php | 2 + .../Framework/Commands/ConfigShowCommand.php | 4 +- .../Commands/MetaViewComponentCommand.php | 16 ++-- .../Installers/FrameworkInstaller.php | 2 +- .../Installers/ViewComponentsInstaller.php | 2 +- .../Testing/Http/HttpRouterTester.php | 2 +- .../Testing/Http/TestResponseHelper.php | 6 +- .../Framework/Testing/IntegrationTest.php | 10 +-- src/Tempest/Framework/Testing/ViteTester.php | 4 +- tests/Benchmark/Container/ContainerBench.php | 10 +-- .../Benchmark/Extension/MarkdownExtension.php | 2 +- .../Benchmark/Extension/MarkdownRenderer.php | 6 +- tests/Benchmark/Http/GenericRouterBench.php | 12 +-- .../Fixtures/Controllers/DeferController.php | 2 +- .../Auth/AccessControl/HasPolicyTests.php | 6 +- .../Auth/OAuth/TestingOAuthClientTest.php | 2 +- tests/Integration/Cache/CacheTest.php | 16 ++-- tests/Integration/Cache/LockTest.php | 6 +- .../CommandBus/AsyncCommandTest.php | 6 +- .../Actions/ExecuteConsoleCommandTest.php | 2 +- .../Commands/MakeMiddlewareCommandTest.php | 4 +- .../Components/ProgressBarComponentTest.php | 6 +- .../Components/SearchComponentTest.php | 2 +- .../Static/StaticConfirmComponentTest.php | 10 +-- .../StaticMultipleChoiceComponentTest.php | 12 +-- .../Static/StaticProgressBarComponentTest.php | 4 +- .../Static/StaticSearchComponentTest.php | 2 +- .../StaticSingleChoiceComponentTest.php | 16 ++-- .../Static/StaticTextBoxComponentTest.php | 6 +- .../Console/Components/TaskComponentTest.php | 4 +- .../Console/ConsoleArgumentBagTest.php | 6 +- .../Console/Fixtures/InteractiveCommand.php | 8 +- .../Input/ConsoleInputArgumentTest.php | 8 +- .../ResolveOrRescueMiddlewareTest.php | 4 +- .../Console/Testing/ConsoleTesterTest.php | 12 +-- tests/Integration/Core/DeferredTasksTest.php | 4 +- .../Core/LoadDiscoveryClassesTest.php | 2 +- .../Core/ViewComponentsInstallerTest.php | 4 +- .../Integration/Cryptography/TimelockTest.php | 2 +- .../Builder/ConvenientWhereMethodsTest.php | 8 +- .../Builder/CountQueryBuilderTest.php | 8 +- .../Builder/DeleteQueryBuilderTest.php | 6 +- .../Builder/InsertQueryBuilderTest.php | 4 +- .../Database/Builder/NestedWhereTest.php | 18 ++-- .../Builder/SelectQueryBuilderTest.php | 16 ++-- .../Builder/TransformsQueryBuilderTest.php | 12 +-- .../Builder/UpdateQueryBuilderTest.php | 6 +- .../Database/Builder/WhereOperatorTest.php | 4 +- .../ConvenientDateWhereMethodsTest.php | 6 +- ...ustomPrimaryKeyRelationshipLoadingTest.php | 2 +- .../Database/EncryptedAttributeTest.php | 2 - .../Database/GenericDatabaseTest.php | 8 +- .../Database/GroupedWhereMethodsTest.php | 34 ++++---- .../Database/HashedAttributeTest.php | 2 - .../Database/MultiDatabaseTest.php | 4 +- tests/Integration/Database/ToRawSqlTest.php | 2 +- tests/Integration/Debug/DebugTest.php | 2 +- .../EventBus/EventBusTesterTest.php | 18 ++-- .../FrameworkIntegrationTestCase.php | 4 +- .../Http/Exceptions/ExceptionRendererTest.php | 14 +-- .../Exceptions/HttpExceptionHandlerTest.php | 4 +- .../Http/GenericResponseSenderTest.php | 10 +-- .../Http/HeaderSessionIdResolverTest.php | 4 +- .../Http/TrackPreviousUrlMiddlewareTest.php | 12 +-- tests/Integration/Icon/IconTest.php | 2 +- tests/Integration/Intl/TranslatorTest.php | 4 +- tests/Integration/Log/GenericLoggerTest.php | 6 +- tests/Integration/Mailer/AttachmentTest.php | 2 +- tests/Integration/Mailer/MailerTesterTest.php | 8 +- tests/Integration/Mailer/SentEmailTest.php | 8 +- .../Mapper/Fixtures/SerializableObject.php | 4 + .../Integration/Mapper/ObjectFactoryTest.php | 2 +- .../Process/ProcessExecutorTest.php | 2 +- .../Process/ProcessTesterAssertNotRanTest.php | 6 +- .../Process/ProcessTesterAssertRanTest.php | 14 +-- .../Integration/Process/ProcessTesterTest.php | 6 +- tests/Integration/Route/ClientTest.php | 2 +- .../Route/RequestToObjectMapperTest.php | 4 +- .../Integration/Storage/StorageTesterTest.php | 4 +- .../Integration/Validator/ExistsRuleTest.php | 6 +- .../View/Components/IconComponentTest.php | 26 +++--- tests/Integration/View/ElementFactoryTest.php | 2 +- tests/Integration/View/ViewCacheTest.php | 8 +- .../View/ViewComponentDiscoveryTest.php | 2 +- tests/Integration/View/ViewComponentTest.php | 6 +- tests/Integration/Vite/ViteTesterTest.php | 6 +- 340 files changed, 1126 insertions(+), 1163 deletions(-) diff --git a/packages/auth/src/AccessControl/PolicyBasedAccessControl.php b/packages/auth/src/AccessControl/PolicyBasedAccessControl.php index cfb7e2c88..3751de141 100644 --- a/packages/auth/src/AccessControl/PolicyBasedAccessControl.php +++ b/packages/auth/src/AccessControl/PolicyBasedAccessControl.php @@ -85,7 +85,7 @@ private function findPoliciesForResourceAction(object|string $resource, UnitEnum $actionBeingEvaluated = Str\parse($action); return new ImmutableArray($this->authConfig->policies[$resource] ?? []) - ->filter(static fn ($_, string $action) => $action === $actionBeingEvaluated) + ->filter(fn ($_, string $action) => $action === $actionBeingEvaluated) ->flatten(); } @@ -96,13 +96,13 @@ private function evaluatePolicy(MethodReflector $policy, ?object $resource, ?obj $this->ensureParameterAcceptsInput( reflector: $policy->getParameter(key: 0), input: $resource, - throw: static fn (string $expected) => throw PolicyMethodWasInvalid::resourceParameterIsInvalid($policyName, $expected), + throw: fn (string $expected) => throw PolicyMethodWasInvalid::resourceParameterIsInvalid($policyName, $expected), ); $this->ensureParameterAcceptsInput( reflector: $policy->getParameter(key: 1), input: $subject, - throw: static fn (string $expected) => throw PolicyMethodWasInvalid::subjectParameterIsInvalid($policyName, $expected), + throw: fn (string $expected) => throw PolicyMethodWasInvalid::subjectParameterIsInvalid($policyName, $expected), ); $decision = $policy->invokeArgs( diff --git a/packages/auth/src/AccessControl/PolicyDiscovery.php b/packages/auth/src/AccessControl/PolicyDiscovery.php index 85319bdff..92f28c4aa 100644 --- a/packages/auth/src/AccessControl/PolicyDiscovery.php +++ b/packages/auth/src/AccessControl/PolicyDiscovery.php @@ -2,6 +2,7 @@ namespace Tempest\Auth\AccessControl; +use Tempest\Auth\AccessControl\Policy; use Tempest\Auth\AuthConfig; use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; diff --git a/packages/auth/src/Installer/OAuthInstaller.php b/packages/auth/src/Installer/OAuthInstaller.php index 2cf5c3ab4..8915b44d3 100644 --- a/packages/auth/src/Installer/OAuthInstaller.php +++ b/packages/auth/src/Installer/OAuthInstaller.php @@ -53,7 +53,7 @@ public function install(): void '3. Review and customize the published files if needed', '', 'Published files', - ...arr($this->publishedFiles)->map(static fn (string $file) => '→ ' . $file), + ...arr($this->publishedFiles)->map(fn (string $file) => '→ ' . $file), ]); } @@ -108,7 +108,7 @@ private function publishController(SupportedOAuthProvider $provider): void $this->update( path: $destination, - callback: static fn (ImmutableString $contents) => $contents->replace( + callback: fn (ImmutableString $contents) => $contents->replace( search: [ "'tag_name'", 'redirect-route', @@ -132,7 +132,7 @@ private function publishController(SupportedOAuthProvider $provider): void private function installComposerDependencies(SupportedOAuthProvider ...$providers): void { $packages = arr($providers) - ->map(static fn (SupportedOAuthProvider $provider) => $provider->composerPackage()) + ->map(fn (SupportedOAuthProvider $provider) => $provider->composerPackage()) ->filter(); if ($packages->isNotEmpty()) { @@ -167,7 +167,7 @@ private function extractSettings(SupportedOAuthProvider $provider): array try { return str(read_file($configPath)) ->matchAll("/env\('(OAUTH_[^']*)'/", matches: 1) - ->map(static fn (array $matches) => $matches[1] ?? null) + ->map(fn (array $matches) => $matches[1] ?? null) ->filter() ->toArray(); } catch (PathWasNotFound|PathWasNotReadable) { diff --git a/packages/auth/src/Installer/oauth/OAuthControllerStub.php b/packages/auth/src/Installer/oauth/OAuthControllerStub.php index cd7be2d0e..293ab874f 100644 --- a/packages/auth/src/Installer/oauth/OAuthControllerStub.php +++ b/packages/auth/src/Installer/oauth/OAuthControllerStub.php @@ -36,7 +36,7 @@ public function callback(Request $request): Redirect $this->oauth->authenticate( request: $request, - map: static fn (OAuthUser $user): Authenticatable => query('user-model-fqcn')->updateOrCreate([ + map: fn (OAuthUser $user): Authenticatable => query('user-model-fqcn')->updateOrCreate([ 'provider_db_column' => $user->id, ], [ 'provider_db_column' => $user->id, diff --git a/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php b/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php index e0b4e6137..b1adf3e75 100644 --- a/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/DiscordOAuthConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * The client secret for the Discord OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php b/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php index 27ce451e9..376e19b86 100644 --- a/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/FacebookOAuthConfig.php @@ -26,7 +26,6 @@ public function __construct( /** * The client secret for the Facebook OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/GenericOAuthConfig.php b/packages/auth/src/OAuth/Config/GenericOAuthConfig.php index 2b9e3973d..9f296e5f4 100644 --- a/packages/auth/src/OAuth/Config/GenericOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/GenericOAuthConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * The client secret for the OAuth provider. */ - #[\SensitiveParameter] public string $clientSecret, /** @@ -41,7 +40,6 @@ public function __construct( /** * The access token URL for the OAuth provider. */ - #[\SensitiveParameter] public string $urlAccessToken, /** diff --git a/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php b/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php index 092b7fc39..cd0d3e82c 100644 --- a/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/GitHubOAuthConfig.php @@ -26,7 +26,6 @@ public function __construct( /** * The client secret for the GitHub OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php b/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php index 88bfa1a60..c1a0d8f5c 100644 --- a/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/GoogleOAuthConfig.php @@ -26,7 +26,6 @@ public function __construct( /** * The client secret for the Google OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php b/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php index e06d5565f..42a39e4b7 100644 --- a/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/InstagramOAuthConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * The client secret for the Instagram OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php b/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php index 68a7bb661..839b24dd2 100644 --- a/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/LinkedInOAuthConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * The client secret for the LinkedIn OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php b/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php index d2967d007..943c82090 100644 --- a/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/MicrosoftOAuthConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * The client secret for the Microsoft OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/SlackOAuthConfig.php b/packages/auth/src/OAuth/Config/SlackOAuthConfig.php index 513091bae..212f40a4e 100644 --- a/packages/auth/src/OAuth/Config/SlackOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/SlackOAuthConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * The client secret for the Slack OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php b/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php index 8b2bf25b8..e48e268f9 100644 --- a/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php +++ b/packages/auth/src/OAuth/Config/TwitchOAuthConfig.php @@ -26,7 +26,6 @@ public function __construct( /** * The client secret for the Twitch OAuth application. */ - #[\SensitiveParameter] public string $clientSecret, /** diff --git a/packages/auth/src/OAuth/GenericOAuthClient.php b/packages/auth/src/OAuth/GenericOAuthClient.php index 41286a336..9b591f26e 100644 --- a/packages/auth/src/OAuth/GenericOAuthClient.php +++ b/packages/auth/src/OAuth/GenericOAuthClient.php @@ -101,7 +101,7 @@ public function requestAccessToken(string $code): AccessToken } } - public function fetchUser(#[\SensitiveParameter] AccessToken $token): OAuthUser + public function fetchUser(AccessToken $token): OAuthUser { try { return $this->config->mapUser( diff --git a/packages/auth/src/OAuth/OAuthClient.php b/packages/auth/src/OAuth/OAuthClient.php index bceef9c51..63eb5566f 100644 --- a/packages/auth/src/OAuth/OAuthClient.php +++ b/packages/auth/src/OAuth/OAuthClient.php @@ -38,7 +38,7 @@ public function requestAccessToken(string $code): AccessToken; /** * Gets user information from an OAuth provider using an access token. */ - public function fetchUser(#[\SensitiveParameter] AccessToken $token): OAuthUser; + public function fetchUser(AccessToken $token): OAuthUser; /** * Authenticates a user based on the given OAuth callback request. diff --git a/packages/auth/src/OAuth/OAuthProvider.php b/packages/auth/src/OAuth/OAuthProvider.php index 4339dad98..5bb8dcaba 100644 --- a/packages/auth/src/OAuth/OAuthProvider.php +++ b/packages/auth/src/OAuth/OAuthProvider.php @@ -27,5 +27,5 @@ public function getAccessToken(string $code): AccessToken; /** * Gets the resource owner information using an access token. */ - public function getResourceOwner(#[\SensitiveParameter] AccessToken $token): ResourceOwnerInterface; + public function getResourceOwner(AccessToken $token): ResourceOwnerInterface; } diff --git a/packages/auth/src/OAuth/Testing/TestingOAuthClient.php b/packages/auth/src/OAuth/Testing/TestingOAuthClient.php index 20892876b..470cf0ccd 100644 --- a/packages/auth/src/OAuth/Testing/TestingOAuthClient.php +++ b/packages/auth/src/OAuth/Testing/TestingOAuthClient.php @@ -107,7 +107,7 @@ public function requestAccessToken(string $code): AccessToken return $token; } - public function fetchUser(#[\SensitiveParameter] AccessToken $token): OAuthUser + public function fetchUser(AccessToken $token): OAuthUser { $this->users[] = [ 'token' => $token, @@ -217,7 +217,7 @@ public function assertAuthorizationUrlGenerated(?array $scopes = null, ?array $o public function assertUserFetched(string $code): void { Assert::assertNotEmpty( - actual: array_filter($this->users, static fn (array $user) => $user['code'] === $code), + actual: array_filter($this->users, fn (array $user) => $user['code'] === $code), message: sprintf('User with code "%s" was not handled.', $code), ); } @@ -231,7 +231,7 @@ public function assertAccessTokenRetrieved(?string $code = null): void if ($code !== null) { Assert::assertNotEmpty( - actual: array_filter($this->accessTokens, static fn (#[\SensitiveParameter] array $token) => $token['code'] === $code), + actual: array_filter($this->accessTokens, fn (array $token) => $token['code'] === $code), message: sprintf('No access token was retrieved for code "%s".', $code), ); } diff --git a/packages/auth/tests/OAuthTest.php b/packages/auth/tests/OAuthTest.php index 503f16643..8f9271d55 100644 --- a/packages/auth/tests/OAuthTest.php +++ b/packages/auth/tests/OAuthTest.php @@ -185,7 +185,7 @@ public function oauth_user_creation(): void avatar: 'https://example.com/avatar.jpg', provider: 'github', raw: [ - 'id' => 123_456, + 'id' => 123456, 'login' => 'frieren', 'name' => 'Frieren the Mage', 'email' => 'frieren@elven-mage.magic', diff --git a/packages/cache/src/Commands/CacheClearCommand.php b/packages/cache/src/Commands/CacheClearCommand.php index 61ba781ae..fb1c7b13c 100644 --- a/packages/cache/src/Commands/CacheClearCommand.php +++ b/packages/cache/src/Commands/CacheClearCommand.php @@ -93,8 +93,8 @@ private function clearUserCaches(?string $tag = null, bool $all = false): void /** @var GenericContainer $container */ $container = $this->container; $cacheTags = arr($container->getSingletons(CacheConfig::class)) - ->map(static fn ($_, string $key) => $key === CacheConfig::class ? self::DEFAULT_CACHE : Str\after_last($key, '#')) - ->filter(static fn (string $value) => $tag === null || $value === $tag) + ->map(fn ($_, string $key) => $key === CacheConfig::class ? self::DEFAULT_CACHE : Str\after_last($key, '#')) + ->filter(fn (string $value) => $tag === null || $value === $tag) ->values(); if ($all === false && count($cacheTags) > 1) { diff --git a/packages/cache/src/GenericCache.php b/packages/cache/src/GenericCache.php index 1576223a7..2023dd58b 100644 --- a/packages/cache/src/GenericCache.php +++ b/packages/cache/src/GenericCache.php @@ -133,7 +133,7 @@ public function getMany(iterable $key): array if (! $this->enabled) { return Arr\map_with_keys( array: $key, - map: static fn (string|Stringable $key) => yield (string) $key => null, + map: fn (string|Stringable $key) => yield (string) $key => null, ); } diff --git a/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php b/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php index cfa7c47f3..b7759e982 100644 --- a/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php +++ b/packages/command-bus/src/AsyncCommandRepositories/FileCommandRepository.php @@ -52,7 +52,7 @@ public function markAsFailed(string $uuid): void public function getPendingCommands(): array { return arr(glob(__DIR__ . '/../stored-commands/*.pending.txt')) - ->mapWithKeys(static function (string $path) { + ->mapWithKeys(function (string $path) { if (! Filesystem\is_file($path)) { return; } diff --git a/packages/command-bus/src/MonitorAsyncCommands.php b/packages/command-bus/src/MonitorAsyncCommands.php index f28ed0033..03187e00b 100644 --- a/packages/command-bus/src/MonitorAsyncCommands.php +++ b/packages/command-bus/src/MonitorAsyncCommands.php @@ -35,35 +35,33 @@ public function __invoke(): void while (true) { // @phpstan-ignore-line foreach ($processes as $uuid => $process) { - if (! $process->isTerminated()) { - continue; + if ($process->isTerminated()) { + if ($process->isSuccessful()) { + $this->console->keyValue( + key: "{$uuid}", + value: "SUCCESS", + ); + } else { + $this->console->keyValue( + key: "{$uuid}", + value: "FAILED", + ); + } + + if ($output = trim($process->getOutput())) { + $this->writeln($output); + } + + if ($errorOutput = trim($process->getErrorOutput())) { + $this->writeln($errorOutput); + } + + unset($processes[$uuid]); } - - if ($process->isSuccessful()) { - $this->console->keyValue( - key: "{$uuid}", - value: "SUCCESS", - ); - } else { - $this->console->keyValue( - key: "{$uuid}", - value: "FAILED", - ); - } - - if ($output = trim($process->getOutput())) { - $this->writeln($output); - } - - if ($errorOutput = trim($process->getErrorOutput())) { - $this->writeln($errorOutput); - } - - unset($processes[$uuid]); } $availableCommands = arr($this->repository->getPendingCommands()) - ->filter(static fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes)); + ->filter(fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes)); if (count($processes) === 5) { $this->sleep(0.5); diff --git a/packages/command-bus/src/functions.php b/packages/command-bus/src/functions.php index 3333d44a5..e9dfbceda 100644 --- a/packages/command-bus/src/functions.php +++ b/packages/command-bus/src/functions.php @@ -4,6 +4,7 @@ namespace Tempest\CommandBus; +use Tempest\CommandBus\CommandBus; use Tempest\Container; /** diff --git a/packages/console/src/Actions/RenderConsoleCommand.php b/packages/console/src/Actions/RenderConsoleCommand.php index 72d6778c8..8015f7293 100644 --- a/packages/console/src/Actions/RenderConsoleCommand.php +++ b/packages/console/src/Actions/RenderConsoleCommand.php @@ -77,7 +77,7 @@ private function renderArgument(ConsoleArgumentDefinition $argument): string private function renderEnumArgument(ConsoleArgumentDefinition $argument): string { $parts = array_map( - callback: static fn (BackedEnum $case) => $case->value, + callback: fn (BackedEnum $case) => $case->value, array: $argument->type::cases(), ); diff --git a/packages/console/src/Actions/ResolveConsoleCommand.php b/packages/console/src/Actions/ResolveConsoleCommand.php index 1fc5795a8..6ff6da1f7 100644 --- a/packages/console/src/Actions/ResolveConsoleCommand.php +++ b/packages/console/src/Actions/ResolveConsoleCommand.php @@ -27,7 +27,7 @@ public function __invoke(array|string $command): ConsoleCommand if (is_array($command)) { $command = array_find( array: $this->consoleConfig->commands, - callback: static fn (ConsoleCommand $consoleCommand) => ( + callback: fn (ConsoleCommand $consoleCommand) => ( $consoleCommand->handler->getDeclaringClass()->getName() === $command[0] && $consoleCommand->handler->getName() === $command[1] ), diff --git a/packages/console/src/Commands/AboutCommand.php b/packages/console/src/Commands/AboutCommand.php index 13957bf6d..c5ca55399 100644 --- a/packages/console/src/Commands/AboutCommand.php +++ b/packages/console/src/Commands/AboutCommand.php @@ -76,7 +76,7 @@ private function formatInsight(Stringable|Insight|array|string $value): string { return arr($value) ->filter() - ->map(static function (Stringable|Insight|string $value) { + ->map(function (Stringable|Insight|string $value) { if ($value instanceof Insight) { return $value->formattedValue; } @@ -91,7 +91,7 @@ private function rawInsight(Stringable|Insight|array|string $value): array { return arr($value) ->filter() - ->map(static function (Stringable|Insight|string $value) { + ->map(function (Stringable|Insight|string $value) { if ($value instanceof Insight) { return $value->value; } diff --git a/packages/console/src/Commands/MakeCommandCommand.php b/packages/console/src/Commands/MakeCommandCommand.php index 34b177d59..ff03458bf 100644 --- a/packages/console/src/Commands/MakeCommandCommand.php +++ b/packages/console/src/Commands/MakeCommandCommand.php @@ -39,7 +39,7 @@ public function __invoke( 'dummy-command-slug' => str($className)->kebab()->toString(), ], manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Commands/MakeGeneratorCommandCommand.php b/packages/console/src/Commands/MakeGeneratorCommandCommand.php index 5c3e70e12..b3ef45c23 100644 --- a/packages/console/src/Commands/MakeGeneratorCommandCommand.php +++ b/packages/console/src/Commands/MakeGeneratorCommandCommand.php @@ -39,7 +39,7 @@ public function __invoke( 'dummy-command-slug' => str($className)->kebab()->toString(), ], manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Commands/MakeMiddlewareCommand.php b/packages/console/src/Commands/MakeMiddlewareCommand.php index 070bc1bb4..9a041f721 100644 --- a/packages/console/src/Commands/MakeMiddlewareCommand.php +++ b/packages/console/src/Commands/MakeMiddlewareCommand.php @@ -42,7 +42,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Completion/CompletionEngine.php b/packages/console/src/Completion/CompletionEngine.php index 9c8ab469c..ecc53dc37 100644 --- a/packages/console/src/Completion/CompletionEngine.php +++ b/packages/console/src/Completion/CompletionEngine.php @@ -131,11 +131,9 @@ private function selectCompletionValue(CompletionFlag $flag, string $current): ? $candidates[] = $flag->flag; foreach ($flag->aliases as $alias) { - if (! str_starts_with($alias, '--')) { - continue; + if (str_starts_with($alias, '--')) { + $candidates[] = $alias; } - - $candidates[] = $alias; } } elseif (str_starts_with($current, '-')) { foreach ($flag->aliases as $alias) { diff --git a/packages/console/src/Components/Concerns/RendersControls.php b/packages/console/src/Components/Concerns/RendersControls.php index 6dbf6b006..5e42d13d9 100644 --- a/packages/console/src/Components/Concerns/RendersControls.php +++ b/packages/console/src/Components/Concerns/RendersControls.php @@ -43,7 +43,7 @@ private function renderControls(array $controls, int $maxWidth): string $separator = ' · '; $marginLeft = ' '; $render = arr($controls) - ->map(static fn (string $label, string $shortcut) => "{$shortcut} {$label}") + ->map(fn (string $label, string $shortcut) => "{$shortcut} {$label}") ->implode($separator) ->prepend($marginLeft); diff --git a/packages/console/src/Components/Interactive/ProgressBarComponent.php b/packages/console/src/Components/Interactive/ProgressBarComponent.php index 897fefe5e..c6bc4a07c 100644 --- a/packages/console/src/Components/Interactive/ProgressBarComponent.php +++ b/packages/console/src/Components/Interactive/ProgressBarComponent.php @@ -43,7 +43,7 @@ public function render(Terminal $terminal): Generator $count = iterator_count($this->data); $step = 1; - $format = $this->format ?? static function (int $step, int $count): string { + $format = $this->format ?? function (int $step, int $count): string { $width = 30; $progress = (int) round(($step / $count) * $width); diff --git a/packages/console/src/Components/Interactive/TaskComponent.php b/packages/console/src/Components/Interactive/TaskComponent.php index e75b288b8..4ccb73ede 100644 --- a/packages/console/src/Components/Interactive/TaskComponent.php +++ b/packages/console/src/Components/Interactive/TaskComponent.php @@ -139,11 +139,9 @@ private function renderTask(Terminal $terminal, ?string $line = null): string private function cleanupSockets(): void { foreach ($this->sockets as $socket) { - if (! is_resource($socket)) { - continue; + if (is_resource($socket)) { + @fclose($socket); } - - @fclose($socket); } $this->sockets = []; @@ -153,7 +151,7 @@ private function executeHandler(): never { $log = function (string ...$lines): void { arr($lines) - ->flatMap(static fn (string $line) => explode("\n", $line)) + ->flatMap(fn (string $line) => explode("\n", $line)) ->each(function (string $line): void { fwrite($this->sockets[0], $line); }); @@ -174,7 +172,7 @@ private function resolveHandler(null|Process|Closure $handler): ?Closure if ($handler instanceof Process) { return static function (Closure $log) use ($handler): bool { - return $handler->run(static function (string $type, string $buffer) use ($log): void { + return $handler->run(function (string $type, string $buffer) use ($log): void { if ($type === Process::ERR) { return; } diff --git a/packages/console/src/Components/InteractiveComponentRenderer.php b/packages/console/src/Components/InteractiveComponentRenderer.php index 3c7806863..63bb076d2 100644 --- a/packages/console/src/Components/InteractiveComponentRenderer.php +++ b/packages/console/src/Components/InteractiveComponentRenderer.php @@ -108,14 +108,14 @@ private function applyKey(InteractiveConsoleComponent $component, Console $conso // If we have multiple handlers, we put the ones that return nothing // first because the ones that return something will be overridden otherwise. - usort($handlersForKey, static fn (MethodReflector $a, MethodReflector $b) => $b->getReturnType()->equals('void') <=> $a->getReturnType()->equals('void')); + usort($handlersForKey, fn (MethodReflector $a, MethodReflector $b) => $b->getReturnType()->equals('void') <=> $a->getReturnType()->equals('void')); // CTRL+C and CTRL+D means we exit the CLI, but only if there is no custom // handler. When we exit, we want one last render to display pretty // styles, so we will throw the exception in the next loop. if ($handlersForKey === [] && ($key === Key::CTRL_C->value || $key === Key::CTRL_D->value)) { $component->setState(ComponentState::CANCELLED); - $this->afterRenderCallbacks[] = static fn () => throw new InterruptException(); + $this->afterRenderCallbacks[] = fn () => throw new InterruptException(); $this->shouldRerender = true; Fiber::suspend(); @@ -242,7 +242,7 @@ private function validate(mixed $value, array $validation): ?string public function isComponentSupported(Console $console, InteractiveConsoleComponent $component): bool { - if (! arr($component->extensions ?? [])->every(static fn (string $ext) => extension_loaded($ext))) { + if (! arr($component->extensions ?? [])->every(fn (string $ext) => extension_loaded($ext))) { return false; } diff --git a/packages/console/src/Components/OptionCollection.php b/packages/console/src/Components/OptionCollection.php index 4d76724d4..16243f1be 100644 --- a/packages/console/src/Components/OptionCollection.php +++ b/packages/console/src/Components/OptionCollection.php @@ -38,7 +38,7 @@ public function setCollection(iterable $options): void $this->preserveKeys = $options->isAssociative(); $this->options = $options - ->map(static fn (mixed $value, string|int $key) => new Option($key, $value)) + ->map(fn (mixed $value, string|int $key) => new Option($key, $value)) ->toArray(); $this->filter(null); @@ -50,11 +50,11 @@ public function filter(?string $query): void $previouslySelectedOptions = $this->selectedOptions; $this->filteredOptions = arr($this->options) - ->filter(static fn (Option $option) => ! $query || str_contains(mb_strtolower((string) $option->value), mb_strtolower(trim($query)))) + ->filter(fn (Option $option) => ! $query || str_contains(mb_strtolower((string) $option->value), mb_strtolower(trim($query)))) ->values() ->toArray(); - $this->selectedOptions = array_filter($this->filteredOptions, static fn (Option $option) => in_array($option, $previouslySelectedOptions, strict: true)); + $this->selectedOptions = array_filter($this->filteredOptions, fn (Option $option) => in_array($option, $previouslySelectedOptions, strict: true)); $this->activeOption = array_search($previouslyActiveOption ?? $this->filteredOptions[0] ?? '', $this->filteredOptions, strict: true) ?: 0; } @@ -90,7 +90,7 @@ public function toggleCurrent(): void if (! $this->isSelected($active)) { $this->selectedOptions[] = $active; } else { - $this->selectedOptions = array_filter($this->selectedOptions, static fn (Option $option) => ! $active->equals($option)); + $this->selectedOptions = array_filter($this->selectedOptions, fn (Option $option) => ! $active->equals($option)); } } @@ -160,7 +160,7 @@ public function getCurrentIndex(): int public function isSelected(Option $option): bool { - return (bool) arr($this->selectedOptions)->first(static fn (Option $other) => $option->equals($other)); + return (bool) arr($this->selectedOptions)->first(fn (Option $other) => $option->equals($other)); } public function isActive(Option $option): bool @@ -186,7 +186,7 @@ public function setActive(null|Stringable|UnitEnum|string $value): void }; $this->activeOption = array_search( - array_find($this->filteredOptions, static fn (Option $option) => $option->key === $value || $option->value === $value), + array_find($this->filteredOptions, fn (Option $option) => $option->key === $value || $option->value === $value), $this->filteredOptions, strict: true, ) ?: 0; diff --git a/packages/console/src/Components/Renderers/InstructionsRenderer.php b/packages/console/src/Components/Renderers/InstructionsRenderer.php index 165211594..d2d8b57e9 100644 --- a/packages/console/src/Components/Renderers/InstructionsRenderer.php +++ b/packages/console/src/Components/Renderers/InstructionsRenderer.php @@ -15,7 +15,7 @@ public function render(string|array $lines): string { $lines = arr($lines) ->filter() - ->flatMap(static fn (string $string) => str($string)->chunk(self::MAX_WIDTH)->toArray()) + ->flatMap(fn (string $string) => str($string)->chunk(self::MAX_WIDTH)->toArray()) ->toArray(); $text = str(PHP_EOL); diff --git a/packages/console/src/Components/Renderers/KeyValueRenderer.php b/packages/console/src/Components/Renderers/KeyValueRenderer.php index 1720411d7..98a96f1f2 100644 --- a/packages/console/src/Components/Renderers/KeyValueRenderer.php +++ b/packages/console/src/Components/Renderers/KeyValueRenderer.php @@ -20,8 +20,8 @@ public function render(Stringable|string $key, null|Stringable|string $value = n { $key = $this->cleanText($key)->append(' '); $value = $this->cleanText($value)->when( - condition: static fn ($s) => $s->stripTags()->length() !== 0, - callback: static fn ($s) => $s->prepend(' '), + condition: fn ($s) => $s->stripTags()->length() !== 0, + callback: fn ($s) => $s->prepend(' '), ); $maximumWidth = $useAvailableWidth @@ -58,7 +58,7 @@ private function cleanText(null|Stringable|string $text): ImmutableString return $text ->replaceRegex('/\[([^]]+)]/', '[$1]') - ->when(static fn ($s) => $s->endsWith(['.', '?', '!', ':']), static fn ($s) => $s->replaceAt(-1, 1, '')) + ->when(fn ($s) => $s->endsWith(['.', '?', '!', ':']), fn ($s) => $s->replaceAt(-1, 1, '')) ->erase(root_path()) ->trim(); } diff --git a/packages/console/src/Components/Renderers/MessageRenderer.php b/packages/console/src/Components/Renderers/MessageRenderer.php index 2941e8ec1..398725c4f 100644 --- a/packages/console/src/Components/Renderers/MessageRenderer.php +++ b/packages/console/src/Components/Renderers/MessageRenderer.php @@ -19,7 +19,7 @@ public function render(string $contents, ?string $title = null): string { $title = str($title ?? $this->label)->toString(); $lines = ImmutableArray::explode($contents, "\n") - ->map(static fn ($s, $i) => str_repeat(' ', $i === 0 ? 1 : strlen($title) + 4) . $s) + ->map(fn ($s, $i) => str_repeat(' ', $i === 0 ? 1 : strlen($title) + 4) . $s) ->implode("\n"); return str() diff --git a/packages/console/src/Components/Renderers/TaskRenderer.php b/packages/console/src/Components/Renderers/TaskRenderer.php index 2e0535aef..0e73f87a9 100644 --- a/packages/console/src/Components/Renderers/TaskRenderer.php +++ b/packages/console/src/Components/Renderers/TaskRenderer.php @@ -23,7 +23,7 @@ public function render(Terminal $terminal, ComponentState $state, float $started $this->prepareRender($terminal, $state); $this->label($this->label); - $runtime = static fn (float $finishedAt) => $finishedAt + $runtime = fn (float $finishedAt) => $finishedAt ? number_format(($finishedAt - $startedAt) / 1_000_000, decimals: 0) : null; diff --git a/packages/console/src/Components/Renderers/TextInputRenderer.php b/packages/console/src/Components/Renderers/TextInputRenderer.php index 028e18c21..5d6006811 100644 --- a/packages/console/src/Components/Renderers/TextInputRenderer.php +++ b/packages/console/src/Components/Renderers/TextInputRenderer.php @@ -53,8 +53,8 @@ public function render( // if there is nothing to display after the component is done, show "no input" // TODO(innocenzi): clean up - if ($this->state->isFinished() && $lines->filter(static fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) { - $displayLines = $displayLines->filter(static fn (ImmutableString $line) => $line->trim()->isNotEmpty()); + if ($this->state->isFinished() && $lines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty())->isEmpty()) { + $displayLines = $displayLines->filter(fn (ImmutableString $line) => $line->trim()->isNotEmpty()); $this->line($this->style('italic dim', 'No input.'))->newLine(); } diff --git a/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php b/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php index 1679e60e4..76e3a8a0d 100644 --- a/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php @@ -35,7 +35,7 @@ public function render(Console $console): array $answers = $this->askQuestion($console); $answerAsString = arr($answers) - ->map(static fn (Option $option) => $option->displayValue) + ->map(fn (Option $option) => $option->displayValue) ->join(', ', ' and ') ->trim() ->toString() ?: 'no option'; @@ -52,7 +52,7 @@ public function render(Console $console): array return $this->default; } - return array_map(static fn (Option $option) => $option->value, $answers); + return array_map(fn (Option $option) => $option->value, $answers); } private function askQuestion(Console $console): array @@ -66,7 +66,7 @@ private function askQuestion(Console $console): array fn (Option $option, int $index) => str($index) ->when( condition: in_array($option->value, $this->default, strict: true), - callback: static fn ($s) => $s->wrap('', ''), + callback: fn ($s) => $s->wrap('', ''), ) ->wrap('[', ']') ->prepend('- ') @@ -105,7 +105,7 @@ private function askQuestion(Console $console): array }); }) ->filter() - ->unique(static fn (Option $option) => $option->value) + ->unique(fn (Option $option) => $option->value) ->toArray(); } } diff --git a/packages/console/src/Components/Static/StaticProgressBarComponent.php b/packages/console/src/Components/Static/StaticProgressBarComponent.php index 426899e4a..0cdeaf8ce 100644 --- a/packages/console/src/Components/Static/StaticProgressBarComponent.php +++ b/packages/console/src/Components/Static/StaticProgressBarComponent.php @@ -24,7 +24,7 @@ public function render(Console $console): array $count = iterator_count($this->data); $step = 1; - $format = $this->format ?? static function (int $step, int $count): string { + $format = $this->format ?? function (int $step, int $count): string { $width = 30; $progress = (int) round(($step / $count) * $width); diff --git a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php index 0da8f6d0a..8010ad1cd 100644 --- a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php @@ -38,7 +38,7 @@ public function render(Console $console): null|int|UnitEnum|string fn (Option $option, int $index) => str($index) ->when( condition: $option->key === $this->default || $option->value === $this->default, - callback: static fn ($s) => $s->wrap('', ''), + callback: fn ($s) => $s->wrap('', ''), ) ->wrap('[', ']') ->prepend('- ') diff --git a/packages/console/src/Components/Static/StaticTaskComponent.php b/packages/console/src/Components/Static/StaticTaskComponent.php index 7d9313855..ff92978aa 100644 --- a/packages/console/src/Components/Static/StaticTaskComponent.php +++ b/packages/console/src/Components/Static/StaticTaskComponent.php @@ -39,7 +39,7 @@ public function render(Console $console): bool private function executeClosureHandler(Closure $handler): bool { try { - return $handler(static fn () => null) !== false; + return $handler(fn () => null) !== false; } catch (Throwable) { return false; } diff --git a/packages/console/src/ConsoleInputBuilder.php b/packages/console/src/ConsoleInputBuilder.php index 6b3df2093..2b8f0aad9 100644 --- a/packages/console/src/ConsoleInputBuilder.php +++ b/packages/console/src/ConsoleInputBuilder.php @@ -59,7 +59,7 @@ public function build(): array } return array_map( - callback: static fn (ConsoleInputArgument $argument) => $argument->value, + callback: fn (ConsoleInputArgument $argument) => $argument->value, array: $validArguments, ); } diff --git a/packages/console/src/Exceptions/ConsoleExceptionHandler.php b/packages/console/src/Exceptions/ConsoleExceptionHandler.php index 0a178e54a..3c9d20f9f 100644 --- a/packages/console/src/Exceptions/ConsoleExceptionHandler.php +++ b/packages/console/src/Exceptions/ConsoleExceptionHandler.php @@ -41,7 +41,7 @@ public function handle(Throwable $throwable): void ->error($throwable::class) ->when( condition: $throwable->getMessage(), - callback: static fn (Console $console) => $console->error($throwable->getMessage()), + callback: fn (Console $console) => $console->error($throwable->getMessage()), ) ->writeln() ->writeln('In ' . $this->formatFileWithLine($throwable->getFile() . ':' . $throwable->getLine())) @@ -81,7 +81,7 @@ private function getSnippet(string $file, int $lineNumber): string $lines = explode(PHP_EOL, $code); $lines[$lineNumber - 1] = str($lines[$lineNumber - 1]) - ->replaceRegex('/^\d+/', static fn (array $match) => "{$match[0]}") + ->replaceRegex('/^\d+/', fn (array $match) => "{$match[0]}") ->append(' <<<') ->toString(); diff --git a/packages/console/src/Exceptions/InvalidCommandException.php b/packages/console/src/Exceptions/InvalidCommandException.php index 709ea01f2..cff1141f9 100644 --- a/packages/console/src/Exceptions/InvalidCommandException.php +++ b/packages/console/src/Exceptions/InvalidCommandException.php @@ -20,7 +20,7 @@ public function __construct( public function render(Console $console): void { $missingArguments = implode(', ', array_map( - static fn (ConsoleArgumentDefinition $argumentDefinition) => $argumentDefinition->name, + fn (ConsoleArgumentDefinition $argumentDefinition) => $argumentDefinition->name, $this->invalidArguments, )); diff --git a/packages/console/src/Exceptions/InvalidEnumArgument.php b/packages/console/src/Exceptions/InvalidEnumArgument.php index 8b998e8a5..7c6a04f87 100644 --- a/packages/console/src/Exceptions/InvalidEnumArgument.php +++ b/packages/console/src/Exceptions/InvalidEnumArgument.php @@ -32,7 +32,7 @@ public function render(Console $console): void } $cases = array_map( - callback: static fn (BackedEnum $case) => $case->value, + callback: fn (BackedEnum $case) => $case->value, array: $this->argumentType::cases(), ); diff --git a/packages/console/src/Exceptions/UnknownArgumentsException.php b/packages/console/src/Exceptions/UnknownArgumentsException.php index 03f0a710a..1d2beb269 100644 --- a/packages/console/src/Exceptions/UnknownArgumentsException.php +++ b/packages/console/src/Exceptions/UnknownArgumentsException.php @@ -20,7 +20,7 @@ public function render(Console $console): void $console->error(sprintf( 'Unknown arguments: %s', $this->invalidArguments - ->map(static fn (ConsoleInputArgument $argument) => sprintf( + ->map(fn (ConsoleInputArgument $argument) => sprintf( '%s', $argument->name, )) diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php index 07706f574..cbaae269b 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php @@ -21,7 +21,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio $content = preg_replace_callback( subject: $content, pattern: $pattern, - callback: static function ($matches) use ($highlighter) { + callback: function ($matches) use ($highlighter) { $theme = $highlighter->getTheme(); $quote = $matches['quote']; $match = $matches['match']; diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php index 4a84427af..b455eb5d3 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php @@ -20,7 +20,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio return new ParsedInjection(preg_replace_callback( subject: $content, pattern: '/(?\[\"\'])(?.+)\k\s*\/?>)/', - callback: static function (array $matches) { + callback: function (array $matches) { $href = $matches['file']; $exists = Filesystem\normalize_path($href) !== null; $file = $exists diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php index f62b597f5..cc5d3a47f 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php @@ -17,7 +17,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio return new ParsedInjection(preg_replace_callback( subject: $content, pattern: '/(?\[\"\'])(?.+)\k\>(?:(?!\)/', - callback: static function (array $matches) { + callback: function (array $matches) { $quote = $matches['quote']; $match = $matches['match']; $href = $matches['href']; diff --git a/packages/console/src/Highlight/TempestTerminalTheme.php b/packages/console/src/Highlight/TempestTerminalTheme.php index a4ae82577..1d8c4666e 100644 --- a/packages/console/src/Highlight/TempestTerminalTheme.php +++ b/packages/console/src/Highlight/TempestTerminalTheme.php @@ -55,7 +55,7 @@ private function style(TerminalStyle ...$styles): string return implode( '', array_map( - static fn (TerminalStyle $style) => TerminalStyle::ESC->value . $style->value, + fn (TerminalStyle $style) => TerminalStyle::ESC->value . $style->value, $styles, ), ); diff --git a/packages/console/src/Initializers/ConsoleApplicationInitializer.php b/packages/console/src/Initializers/ConsoleApplicationInitializer.php index caa6367e8..6fd620ee5 100644 --- a/packages/console/src/Initializers/ConsoleApplicationInitializer.php +++ b/packages/console/src/Initializers/ConsoleApplicationInitializer.php @@ -21,7 +21,7 @@ public function initialize(Container $container): ConsoleApplication argumentBag: $container->get(ConsoleArgumentBag::class), ); - $container->singleton(Application::class, static fn () => $application); + $container->singleton(Application::class, fn () => $application); return $application; } diff --git a/packages/console/src/Input/ConsoleArgumentBag.php b/packages/console/src/Input/ConsoleArgumentBag.php index b8d396b53..6cb10bbca 100644 --- a/packages/console/src/Input/ConsoleArgumentBag.php +++ b/packages/console/src/Input/ConsoleArgumentBag.php @@ -117,11 +117,9 @@ public function findArrayFor(ConsoleArgumentDefinition $argumentDefinition): Con $values = []; foreach ($this->arguments as $argument) { - if (! $argumentDefinition->matchesArgument($argument)) { - continue; + if ($argumentDefinition->matchesArgument($argument)) { + $values[] = $argument->value; } - - $values[] = $argument->value; } return new ConsoleInputArgument( @@ -139,15 +137,13 @@ public function findForVariadicArgument(ConsoleArgumentDefinition $argumentDefin $arguments = []; foreach ($this->arguments as $argument) { - if ($argument->position < $argumentDefinition->position) { - continue; + if ($argument->position >= $argumentDefinition->position) { + $arguments[] = new ConsoleInputArgument( + name: $argumentDefinition->name, + position: $argument->position, + value: $this->resolveArgumentValue($argumentDefinition, $argument)->value, + ); } - - $arguments[] = new ConsoleInputArgument( - name: $argumentDefinition->name, - position: $argument->position, - value: $this->resolveArgumentValue($argumentDefinition, $argument)->value, - ); } return $arguments; @@ -177,18 +173,16 @@ public function addMany(array $arguments): self // Otherwise, $arguments is an array of flags or positional argument. foreach ($arguments as $key => $argument) { - if (! (str_starts_with($argument, '-') && ! str_starts_with($argument, '--'))) { - continue; - } + if (str_starts_with($argument, '-') && ! str_starts_with($argument, '--')) { + $flags = str_split($argument); + unset($flags[0]); - $flags = str_split($argument); - unset($flags[0]); + foreach ($flags as $flag) { + $arguments[] = "-{$flag}"; + } - foreach ($flags as $flag) { - $arguments[] = "-{$flag}"; + unset($arguments[$key]); } - - unset($arguments[$key]); } $position = count($this->arguments); diff --git a/packages/console/src/Input/MemoryInputBuffer.php b/packages/console/src/Input/MemoryInputBuffer.php index 01e6162a5..63676ce4e 100644 --- a/packages/console/src/Input/MemoryInputBuffer.php +++ b/packages/console/src/Input/MemoryInputBuffer.php @@ -34,7 +34,7 @@ public function add(int|string|Key ...$input): void implode( separator: ', ', array: array_map( - callback: static fn (int|string|Key $i) => is_string($i) + callback: fn (int|string|Key $i) => is_string($i) ? rtrim($i) : $i->value, array: $input, diff --git a/packages/console/src/Installers/ConsoleInstaller.php b/packages/console/src/Installers/ConsoleInstaller.php index 1adee4a7b..99c17608e 100644 --- a/packages/console/src/Installers/ConsoleInstaller.php +++ b/packages/console/src/Installers/ConsoleInstaller.php @@ -22,7 +22,7 @@ public function install(): void $this->publish( source: __DIR__ . '/tempest', destination: root_path('tempest'), - callback: static function (string $_, string $destination): void { + callback: function (string $_, string $destination): void { if (PHP_OS_FAMILY !== 'Windows') { /** @phpstan-ignore-next-line */ exec("chmod +x {$destination}"); diff --git a/packages/console/src/Middleware/HelpMiddleware.php b/packages/console/src/Middleware/HelpMiddleware.php index 884b3b760..fdc1731ea 100644 --- a/packages/console/src/Middleware/HelpMiddleware.php +++ b/packages/console/src/Middleware/HelpMiddleware.php @@ -55,9 +55,9 @@ private function renderHelp(ConsoleCommand $consoleCommand): void $this->console ->writeln() ->write("{$argumentDefinition->name}") - ->when($argumentDefinition->aliases !== [], static fn (Console $console) => $console->write(' (' . implode(', ', $argumentDefinition->aliases) . ')')) - ->when($argumentDefinition->description, static fn (Console $console) => $console->writeln()->writeln($argumentDefinition->description)) - ->when($argumentDefinition->help, static fn (Console $console) => $console->writeln()->writeln('' . $argumentDefinition->help . '')); + ->when($argumentDefinition->aliases !== [], fn (Console $console) => $console->write(' (' . implode(', ', $argumentDefinition->aliases) . ')')) + ->when($argumentDefinition->description, fn (Console $console) => $console->writeln()->writeln($argumentDefinition->description)) + ->when($argumentDefinition->help, fn (Console $console) => $console->writeln()->writeln('' . $argumentDefinition->help . '')); } $this->console->writeln(); diff --git a/packages/console/src/Middleware/OverviewMiddleware.php b/packages/console/src/Middleware/OverviewMiddleware.php index 7b9eb94c7..f68ce8227 100644 --- a/packages/console/src/Middleware/OverviewMiddleware.php +++ b/packages/console/src/Middleware/OverviewMiddleware.php @@ -73,8 +73,8 @@ private function renderOverview(bool $showHidden = false): void $longestCommandName = max( arr($commands) - ->flatMap(static fn (array $group) => $group) - ->map(static fn (ConsoleCommand $command) => mb_strlen($command->getName())) + ->flatMap(fn (array $group) => $group) + ->map(fn (ConsoleCommand $command) => mb_strlen($command->getName())) ->toArray(), ) + 4; @@ -96,7 +96,7 @@ private function renderOverview(bool $showHidden = false): void $this->console ->unless( condition: $this->discoveryCache->valid, - callback: static fn (Console $console) => $console->writeln()->error('Discovery cache invalid. Run discovery:generate to enable discovery caching.'), + callback: fn (Console $console) => $console->writeln()->error('Discovery cache invalid. Run discovery:generate to enable discovery caching.'), ); } } diff --git a/packages/console/src/Middleware/ResolveOrRescueMiddleware.php b/packages/console/src/Middleware/ResolveOrRescueMiddleware.php index d87d997fc..1f252fc2e 100644 --- a/packages/console/src/Middleware/ResolveOrRescueMiddleware.php +++ b/packages/console/src/Middleware/ResolveOrRescueMiddleware.php @@ -93,7 +93,7 @@ private function getSimilarCommands(ImmutableString $search): ImmutableArray // `dis:st` will match `discovery:status` if ($searchParts->count() === $currentParts->count()) { - if ($searchParts->every(static fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) { + if ($searchParts->every(fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) { $suggestions[$currentName->toString()] = $currentName; continue; @@ -151,8 +151,8 @@ private function getSimilarCommands(ImmutableString $search): ImmutableArray } return $sorted - ->sortByCallback(static fn (array $a, array $b) => $a['levenshtein'] <=> $b['levenshtein']) - ->map(static fn (array $item) => $item['suggestion']); + ->sortByCallback(fn (array $a, array $b) => $a['levenshtein'] <=> $b['levenshtein']) + ->map(fn (array $item) => $item['suggestion']); } private function runIntendedCommand(Stringable $commandName): ExitCode|int diff --git a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php index e56f5d531..c7b4cd143 100644 --- a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php +++ b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php @@ -24,17 +24,17 @@ public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next } $allowedParameterNames = arr($invocation->consoleCommand->getArgumentDefinitions()) - ->flatMap(static function (ConsoleArgumentDefinition $definition) { + ->flatMap(function (ConsoleArgumentDefinition $definition) { return [$definition->name, ...$definition->aliases]; }) - ->map(static function (string $name) { + ->map(function (string $name) { return ltrim($name, '-'); }); $invalidInput = arr($invocation->argumentBag->arguments) - ->filter(static fn (ConsoleInputArgument $argument) => $argument->name !== null) - ->filter(static fn (ConsoleInputArgument $argument) => ! $allowedParameterNames->hasValue(ltrim($argument->name, '-'))) - ->filter(static fn (ConsoleInputArgument $argument) => ! in_array($argument->name, GlobalFlags::values(), strict: true)); + ->filter(fn (ConsoleInputArgument $argument) => $argument->name !== null) + ->filter(fn (ConsoleInputArgument $argument) => ! $allowedParameterNames->hasValue(ltrim($argument->name, '-'))) + ->filter(fn (ConsoleInputArgument $argument) => ! in_array($argument->name, GlobalFlags::values(), strict: true)); if ($invalidInput->isNotEmpty()) { throw new UnknownArgumentsException( diff --git a/packages/console/src/Output/MemoryOutputBuffer.php b/packages/console/src/Output/MemoryOutputBuffer.php index a92a97767..d7d182497 100644 --- a/packages/console/src/Output/MemoryOutputBuffer.php +++ b/packages/console/src/Output/MemoryOutputBuffer.php @@ -25,7 +25,7 @@ public function getBufferWithFormatting(): array public function getBufferWithoutFormatting(): array { return array_map( - static fn (string $line) => preg_replace('/\x1b\[[0-9;]*m/', '', $line), + fn (string $line) => preg_replace('/\x1b\[[0-9;]*m/', '', $line), $this->buffer, ); } diff --git a/packages/console/src/Output/TailReader.php b/packages/console/src/Output/TailReader.php index 591fa0b32..4191a8128 100644 --- a/packages/console/src/Output/TailReader.php +++ b/packages/console/src/Output/TailReader.php @@ -11,7 +11,7 @@ { public function tail(string $path, ?Closure $format = null): void { - $format ??= static fn (string $text) => $text; + $format ??= fn (string $text) => $text; $handle = fopen($path, 'r'); diff --git a/packages/console/src/Scheduler/GenericScheduler.php b/packages/console/src/Scheduler/GenericScheduler.php index fea67c26b..b98c1bec8 100644 --- a/packages/console/src/Scheduler/GenericScheduler.php +++ b/packages/console/src/Scheduler/GenericScheduler.php @@ -66,7 +66,7 @@ private function getInvocationsToRun(DateTime $date): array $eligibleToRun = array_filter( $this->config->scheduledInvocations, - static fn (ScheduledInvocation $invocation) => $invocation->canRunAt( + fn (ScheduledInvocation $invocation) => $invocation->canRunAt( date: $date, lastRunTimestamp: $previousRuns[$invocation->handler->getName()] ?? null, ), diff --git a/packages/console/src/Stubs/GeneratorCommandStub.php b/packages/console/src/Stubs/GeneratorCommandStub.php index a608f82ee..246fff407 100644 --- a/packages/console/src/Stubs/GeneratorCommandStub.php +++ b/packages/console/src/Stubs/GeneratorCommandStub.php @@ -30,7 +30,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/console/src/Terminal/Terminal.php b/packages/console/src/Terminal/Terminal.php index 54627408a..186b862fd 100644 --- a/packages/console/src/Terminal/Terminal.php +++ b/packages/console/src/Terminal/Terminal.php @@ -96,7 +96,7 @@ public function render(InteractiveConsoleComponent $component, array $validation ->render($this); if (! $rendered instanceof Generator) { - $rendered = (static function (string $content): Generator { + $rendered = (function (string $content): Generator { yield $content; return null; @@ -108,7 +108,7 @@ public function render(InteractiveConsoleComponent $component, array $validation if (! $component->getState()->isFinished() && $validationErrors) { $content .= PHP_EOL . arr($validationErrors) - ->map(static fn (string $error) => " {$error}") + ->map(fn (string $error) => " {$error}") ->implode(PHP_EOL) ->append(PHP_EOL) ->toString(); diff --git a/packages/console/src/Testing/ConsoleTester.php b/packages/console/src/Testing/ConsoleTester.php index aeaed7781..088f695c5 100644 --- a/packages/console/src/Testing/ConsoleTester.php +++ b/packages/console/src/Testing/ConsoleTester.php @@ -78,7 +78,7 @@ public function call(string|Closure|array $command, string|array $arguments = [] $clone->input = $memoryInputBuffer; if ($command instanceof Closure) { - $fiber = new Fiber(static function () use ($clone, $command, $console): void { + $fiber = new Fiber(function () use ($clone, $command, $console): void { $clone->exitCode = $command($console) ?? ExitCode::SUCCESS; }); } else { @@ -107,7 +107,7 @@ public function complete(?string $command = null): self $input = explode(' ', $command); $inputString = implode(' ', array_map( - static fn (string $item) => "--input=\"{$item}\"", + fn (string $item) => "--input=\"{$item}\"", $input, )); } else { diff --git a/packages/console/tests/CompletionHelperPhpTest.php b/packages/console/tests/CompletionHelperPhpTest.php index 1e5965834..4940f6095 100644 --- a/packages/console/tests/CompletionHelperPhpTest.php +++ b/packages/console/tests/CompletionHelperPhpTest.php @@ -228,7 +228,7 @@ private function parseMetadata(array $metadata): CompletionMetadata private function mapCompletions(array $completions): array { return array_map( - static fn (CompletionCandidate $completion): array => [ + fn (CompletionCandidate $completion): array => [ 'value' => $completion->value, 'display' => $completion->display, ], diff --git a/packages/console/tests/OptionCollectionTest.php b/packages/console/tests/OptionCollectionTest.php index fe15cf3c0..2a4f86da8 100644 --- a/packages/console/tests/OptionCollectionTest.php +++ b/packages/console/tests/OptionCollectionTest.php @@ -31,7 +31,7 @@ public function test_filter(): void $options->filter('ergljherkigjerg'); $this->assertCount(0, $options->getOptions()); - $this->assertNull($options->getActive()); + $this->assertSame(null, $options->getActive()); } public function test_keeps_active_on_filter(): void @@ -50,7 +50,7 @@ public function test_keeps_active_on_filter(): void $this->assertSame('baz', $options->getActive()->value); $options->filter('bazz'); - $this->assertNull($options->getActive()); + $this->assertSame(null, $options->getActive()); } public function test_navigate(): void @@ -168,6 +168,6 @@ public function test_set_active_enum(): void private function toValues(array $options): array { - return array_map(static fn (Option $option) => $option->value, array_values($options)); + return array_map(fn (Option $option) => $option->value, array_values($options)); } } diff --git a/packages/container/src/Commands/MakeInitializerCommand.php b/packages/container/src/Commands/MakeInitializerCommand.php index e43ad69dc..dff9019d0 100644 --- a/packages/container/src/Commands/MakeInitializerCommand.php +++ b/packages/container/src/Commands/MakeInitializerCommand.php @@ -38,7 +38,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - static function (ClassManipulator $stubClass) use ($isSingleton) { + function (ClassManipulator $stubClass) use ($isSingleton) { $stubClass->removeClassAttribute(SkipDiscovery::class); if ($isSingleton) { diff --git a/packages/container/src/Exceptions/CircularDependencyEncountered.php b/packages/container/src/Exceptions/CircularDependencyEncountered.php index 6cf5c901f..d4ed8de8b 100644 --- a/packages/container/src/Exceptions/CircularDependencyEncountered.php +++ b/packages/container/src/Exceptions/CircularDependencyEncountered.php @@ -35,7 +35,7 @@ public function __construct(DependencyChain $chain, Dependency $circularDependen $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $circularDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: static function ($matches) { + callback: function ($matches) { return '└' . str_repeat('─', strlen($matches['prefix']) + 3) . str_repeat('▒', strlen($matches['selection'])); }, subject: $chain->last()->getShortName(), diff --git a/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php b/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php index 8ac0cefa7..8a6e33be7 100644 --- a/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php +++ b/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php @@ -34,7 +34,7 @@ public function __construct(DependencyChain $chain, Dependency $brokenDependency $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $brokenDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: static function ($matches) { + callback: function ($matches) { return str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])); }, subject: $chain->last()->getShortName(), diff --git a/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php b/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php index 142eec4de..f9541f850 100644 --- a/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php +++ b/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php @@ -47,7 +47,7 @@ public function __construct(DependencyChain $chain, Dependency $brokenDependency $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $brokenDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: static function ($matches) { + callback: function ($matches) { return str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])); }, subject: $chain->last()->getShortName(), diff --git a/packages/container/src/functions.php b/packages/container/src/functions.php index a58062e56..32eee772b 100644 --- a/packages/container/src/functions.php +++ b/packages/container/src/functions.php @@ -4,6 +4,7 @@ namespace Tempest\Container; +use Tempest\Container\GenericContainer; use Tempest\Reflection\FunctionReflector; use Tempest\Reflection\MethodReflector; diff --git a/packages/container/tests/ContainerTest.php b/packages/container/tests/ContainerTest.php index 9edc51d92..1431f0f2a 100644 --- a/packages/container/tests/ContainerTest.php +++ b/packages/container/tests/ContainerTest.php @@ -89,7 +89,7 @@ public function test_get_with_definition(): void $container->register( ContainerObjectC::class, - static fn () => new ContainerObjectC(prop: 'test'), + fn () => new ContainerObjectC(prop: 'test'), ); $c = $container->get(ContainerObjectC::class); @@ -112,7 +112,7 @@ public function test_singleton(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, fn () => new SingletonClass()); $instance = $container->get(SingletonClass::class); @@ -349,18 +349,18 @@ public function test_singleton_on_class(): void public function test_invoke_callable(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, fn () => new SingletonClass()); $this->assertEquals('foo', $container->invoke(InvokableClass::class)); $this->assertEquals('foobar', $container->invoke([new InvokableClass(), 'execute'])); $this->assertEquals('bar', $container->invoke(InvokableClassWithParameters::class, param: 'bar')); - $this->assertInstanceOf(ReflectionClass::class, $container->invoke(static fn (SingletonClass $class) => new ReflectionClass($class))); + $this->assertInstanceOf(ReflectionClass::class, $container->invoke(fn (SingletonClass $class) => new ReflectionClass($class))); } public function test_invoke_invokable_class(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, fn () => new SingletonClass()); $result = $container->invoke(new ClassReflector(InvokableClassWithDependencies::class), param: 'bar'); @@ -370,10 +370,10 @@ public function test_invoke_invokable_class(): void public function test_call_function_with_parameters(): void { $container = new GenericContainer(); - $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, fn () => new SingletonClass()); $result = $container->invoke( - method: static fn (SingletonClass $class, string $prefix) => $prefix . $class::class, + method: fn (SingletonClass $class, string $prefix) => $prefix . $class::class, prefix: 'My resolved class is ', ); @@ -384,7 +384,7 @@ public function test_call_function_with_dependencies_and_parameters(): void { $container = new GenericContainer(); - $result = $container->invoke(static fn (string $param) => $param, param: 'foo'); + $result = $container->invoke(fn (string $param) => $param, param: 'foo'); $this->assertEquals('foo', $result); } @@ -395,7 +395,7 @@ public function test_call_function_with_unresolvable_parameters(): void $this->expectExceptionMessageMatches('/because string cannot be resolved/'); $container = new GenericContainer(); - $container->invoke(static fn (string $param) => $param); + $container->invoke(fn (string $param) => $param); } public function test_call_invalid_closure(): void @@ -410,9 +410,9 @@ public function test_call_invalid_closure(): void public function test_invoke_closure_with_function(): void { GenericContainer::setInstance($container = new GenericContainer()); - $container->singleton(SingletonClass::class, static fn () => new SingletonClass()); + $container->singleton(SingletonClass::class, fn () => new SingletonClass()); - $result = Container\invoke(static fn (SingletonClass $class) => $class::class); + $result = Container\invoke(fn (SingletonClass $class) => $class::class); $this->assertEquals(SingletonClass::class, $result); } @@ -448,7 +448,7 @@ public function test_unregister(): void { $container = new GenericContainer(); - $container->register(InterfaceA::class, static fn () => new ImplementsInterfaceA()); + $container->register(InterfaceA::class, fn () => new ImplementsInterfaceA()); $this->assertInstanceOf(ImplementsInterfaceA::class, $container->get(InterfaceA::class)); @@ -500,7 +500,7 @@ public function test_has(): void $this->assertFalse($container->has(InterfaceA::class)); - $container->register(InterfaceA::class, static fn () => new ImplementsInterfaceA()); + $container->register(InterfaceA::class, fn () => new ImplementsInterfaceA()); $this->assertTrue($container->has(InterfaceA::class)); } @@ -570,23 +570,23 @@ public function test_lazy_dependency(): void $delay = 0.01; $counter = 1; - $container->register(SlowDependency::class, static function () use ($delay, &$counter) { + $container->register(SlowDependency::class, function () use ($delay, &$counter) { return new SlowDependency($delay, $counter++); }); // Normal example, this is slow during initialization, fast during use - $instance1 = $this->assertSlowerThan(static fn () => $container->get(ClassWithSlowDependency::class), $delay); + $instance1 = $this->assertSlowerThan(fn () => $container->get(ClassWithSlowDependency::class), $delay); $this->assertInstanceOf(ClassWithSlowDependency::class, $instance1); $this->assertInstanceOf(SlowDependency::class, $instance1->dependency); - $this->assertSame('value1', $this->assertFasterThan(static fn () => $instance1->dependency->value, $delay)); + $this->assertSame('value1', $this->assertFasterThan(fn () => $instance1->dependency->value, $delay)); // Lazy example, this is fast during initialization, slow during (first) use - $instance2 = $this->assertFasterThan(static fn () => $container->get(ClassWithLazySlowDependency::class), $delay); + $instance2 = $this->assertFasterThan(fn () => $container->get(ClassWithLazySlowDependency::class), $delay); $this->assertInstanceOf(ClassWithLazySlowDependency::class, $instance2); $this->assertInstanceOf(SlowDependency::class, $instance2->dependency); - $this->assertSame('value2', $this->assertSlowerThan(static fn () => $instance2->dependency->value, $delay)); + $this->assertSame('value2', $this->assertSlowerThan(fn () => $instance2->dependency->value, $delay)); } public function test_lazy_property_dependency(): void @@ -600,14 +600,14 @@ public function test_lazy_property_dependency(): void $delay = 0.01; $counter = 1; - $container->register(SlowDependency::class, static function () use ($delay, &$counter) { + $container->register(SlowDependency::class, function () use ($delay, &$counter) { return new SlowDependency($delay, $counter++); }); - $instance = $this->assertFasterThan(static fn () => $container->get(ClassWithLazySlowPropertyDependency::class), $delay); + $instance = $this->assertFasterThan(fn () => $container->get(ClassWithLazySlowPropertyDependency::class), $delay); $this->assertInstanceOf(SlowDependency::class, $instance->dependency); - $this->assertSame('value1', $this->assertSlowerThan(static fn () => $instance->dependency->value, $delay)); + $this->assertSame('value1', $this->assertSlowerThan(fn () => $instance->dependency->value, $delay)); } public function test_has_tags_support(): void @@ -646,7 +646,7 @@ public function test_tag_attribute_with_enum(): void public function test_returns_decorated_instance(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); $container->addDecorator(DecoratorClass::class, DecoratedInterface::class); $instance = $container->get(DecoratedInterface::class); @@ -658,7 +658,7 @@ public function test_returns_decorated_instance(): void public function test_returns_multiple_decorated_instance(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); $container->addDecorator(DecoratorClass::class, DecoratedInterface::class); $container->addDecorator(DecoratorSecondClass::class, DecoratedInterface::class); @@ -672,7 +672,7 @@ public function test_returns_multiple_decorated_instance(): void public function test_throws_on_decorator_not_implementing_interface(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); $container->addDecorator(DecoratorInvalid::class, DecoratedInterface::class); $this->expectException(DecoratorDidNotImplementInterface::class); @@ -683,7 +683,7 @@ public function test_throws_on_decorator_not_implementing_interface(): void public function test_returns_decorator_without_constructor(): void { $container = new GenericContainer(); - $container->register(DecoratedInterface::class, static fn () => new DecoratedClass()); + $container->register(DecoratedInterface::class, fn () => new DecoratedClass()); $container->addDecorator(DecoratorWithoutConstructor::class, DecoratedInterface::class); $instance = $container->get(DecoratedInterface::class); diff --git a/packages/container/tests/Fixtures/SlowDependency.php b/packages/container/tests/Fixtures/SlowDependency.php index 868ab2700..087c27502 100644 --- a/packages/container/tests/Fixtures/SlowDependency.php +++ b/packages/container/tests/Fixtures/SlowDependency.php @@ -12,7 +12,7 @@ public function __construct(float $delay = 0.1, int $counter = 0) // usleep apparently is buggy on windows... $start = microtime(true); while ((microtime(true) - $start) < $delay) { - usleep(intval($delay * 1_000_000)); + usleep(intval($delay * 1000000)); } $this->value = 'value' . $counter; diff --git a/packages/core/src/Commands/InstallCommand.php b/packages/core/src/Commands/InstallCommand.php index f54bd28d3..1b49eea04 100644 --- a/packages/core/src/Commands/InstallCommand.php +++ b/packages/core/src/Commands/InstallCommand.php @@ -59,11 +59,11 @@ private function resolveInstaller(?string $search): ?Installer if (! $search) { $search = $this->ask( question: 'Please choose an installer', - options: $installers->mapWithKeys(static fn (Installer $installer) => yield $installer::class => $installer->name)->toArray(), + options: $installers->mapWithKeys(fn (Installer $installer) => yield $installer::class => $installer->name)->toArray(), ); } - return $installers->first(static fn (Installer $installer) => $installer::class === $search || $installer->name === $search); + return $installers->first(fn (Installer $installer) => $installer::class === $search || $installer->name === $search); } } } diff --git a/packages/core/src/Composer.php b/packages/core/src/Composer.php index 4346ee4c9..e3c6917b9 100644 --- a/packages/core/src/Composer.php +++ b/packages/core/src/Composer.php @@ -38,19 +38,17 @@ public function load(): self $this->composer = $this->loadComposerFile($this->composerPath); $this->namespaces = arr($this->composer) ->get('autoload.psr-4', default: arr()) - ->map(static fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) - ->sortByCallback(static fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) + ->map(fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) + ->sortByCallback(fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) ->values() ->toArray(); foreach ($this->namespaces as $namespace) { - if (! Str\starts_with(Str\ensure_ends_with($namespace->path, '/'), ['app/', 'src/', 'source/', 'lib/'])) { - continue; - } - - $this->mainNamespace = $namespace; + if (Str\starts_with(Str\ensure_ends_with($namespace->path, '/'), ['app/', 'src/', 'source/', 'lib/'])) { + $this->mainNamespace = $namespace; - break; + break; + } } if (! isset($this->mainNamespace) && count($this->namespaces)) { @@ -62,13 +60,13 @@ public function load(): self ...$this->namespaces, ]) ->filter() - ->unique(static fn (Psr4Namespace $ns) => $ns->namespace) + ->unique(fn (Psr4Namespace $ns) => $ns->namespace) ->toArray(); $this->devNamespaces = arr($this->composer) ->get('autoload-dev.psr-4', default: arr()) - ->map(static fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) - ->sortByCallback(static fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) + ->map(fn (string $path, string $namespace) => new Psr4Namespace($namespace, $path)) + ->sortByCallback(fn (Psr4Namespace $ns1, Psr4Namespace $ns2) => strlen($ns1->path) <=> strlen($ns2->path)) ->values() ->toArray(); diff --git a/packages/core/src/EnvironmentValueWasInvalid.php b/packages/core/src/EnvironmentValueWasInvalid.php index fd12a4a0f..77fd56a13 100644 --- a/packages/core/src/EnvironmentValueWasInvalid.php +++ b/packages/core/src/EnvironmentValueWasInvalid.php @@ -13,7 +13,7 @@ final class EnvironmentValueWasInvalid extends Exception public function __construct(string $value) { $possibleValues = arr(Environment::cases()) - ->map(static fn (Environment $environment) => $environment->value) + ->map(fn (Environment $environment) => $environment->value) ->join(); parent::__construct("Invalid environment [{$value}]. Possible values are {$possibleValues}."); diff --git a/packages/core/src/EnvironmentVariableValidationFailed.php b/packages/core/src/EnvironmentVariableValidationFailed.php index 634b96e78..696278f1b 100644 --- a/packages/core/src/EnvironmentVariableValidationFailed.php +++ b/packages/core/src/EnvironmentVariableValidationFailed.php @@ -22,7 +22,7 @@ public function __construct( parent::__construct(vsprintf("Environment variable [%s] is not valid:\n- %s", [ $name, arr($failingRules) - ->map(static fn (FailingRule $failingRule) => $validator->getErrorMessage($failingRule, $name)) + ->map(fn (FailingRule $failingRule) => $validator->getErrorMessage($failingRule, $name)) ->implode("\n- ") ->toString(), ])); diff --git a/packages/core/src/Exceptions/ExceptionTester.php b/packages/core/src/Exceptions/ExceptionTester.php index caff59a4d..0290234cd 100644 --- a/packages/core/src/Exceptions/ExceptionTester.php +++ b/packages/core/src/Exceptions/ExceptionTester.php @@ -87,7 +87,7 @@ public function assertNothingProcessed(): self private function findRecordedProcessings(string|object $exception): array { - return array_filter($this->processor->processed, static function (string|object $reported) use ($exception) { + return array_filter($this->processor->processed, function (string|object $reported) use ($exception) { if ($reported === $exception) { return true; } diff --git a/packages/core/src/FrameworkKernel.php b/packages/core/src/FrameworkKernel.php index 8d1b87d43..9fb47ddfe 100644 --- a/packages/core/src/FrameworkKernel.php +++ b/packages/core/src/FrameworkKernel.php @@ -99,7 +99,7 @@ public function createContainer(): Container GenericContainer::setInstance($container); - $container->singleton(Container::class, static fn () => $container); + $container->singleton(Container::class, fn () => $container); return $container; } @@ -143,7 +143,7 @@ public function registerShutdownFunction(): self // Fix for classes that don't have a proper PSR-4 namespace, // they break discovery with an unrecoverable error, // but you don't know why because PHP simply says "duplicate classname" instead of something reasonable. - register_shutdown_function(static function (): void { + register_shutdown_function(function (): void { $error = error_get_last(); $message = $error['message'] ?? ''; @@ -247,7 +247,7 @@ public function registerExceptionHandler(): self ini_set('display_errors', 'Off'); // @mago-expect lint:no-ini-set set_exception_handler($handler->handle(...)); - set_error_handler(static function (int $code, string $message, string $filename, int $line) use ($handler): bool { + set_error_handler(function (int $code, string $message, string $filename, int $line) use ($handler): bool { $handler->handle(new ErrorException( message: $message, code: $code, diff --git a/packages/core/src/InsightsProviderDiscovery.php b/packages/core/src/InsightsProviderDiscovery.php index bad000651..f456bf22b 100644 --- a/packages/core/src/InsightsProviderDiscovery.php +++ b/packages/core/src/InsightsProviderDiscovery.php @@ -4,6 +4,7 @@ namespace Tempest\Core; +use Tempest\Core\AppConfig; use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; diff --git a/packages/core/src/IsComponentInstaller.php b/packages/core/src/IsComponentInstaller.php index 313509a82..98883f28a 100644 --- a/packages/core/src/IsComponentInstaller.php +++ b/packages/core/src/IsComponentInstaller.php @@ -31,7 +31,7 @@ private function installMainNamespace(): void ->replaceStart(root_path(), '') ->trim('/') ->explode('/') - ->map(static fn (string $part) => ucfirst($part)) + ->map(fn (string $part) => ucfirst($part)) ->implode('\\') ->append('\\') ->toString(); diff --git a/packages/core/src/Kernel/LoadConfig.php b/packages/core/src/Kernel/LoadConfig.php index 5af8d201a..6c916f166 100644 --- a/packages/core/src/Kernel/LoadConfig.php +++ b/packages/core/src/Kernel/LoadConfig.php @@ -60,8 +60,8 @@ public function find(): array $this->environment->isStaging() => ! Str\contains($path, [...$suffixes['testing'], ...$suffixes['development'], ...$suffixes['production']]), default => true, }) - ->sortByCallback(static function (string $path1, string $path2) use ($suffixes): int { - $getPriority = static fn (string $path): int => match (true) { + ->sortByCallback(function (string $path1, string $path2) use ($suffixes): int { + $getPriority = fn (string $path): int => match (true) { Str\contains($path, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR) => 0, ! Str\contains($path, root_path()) => 0, Str\contains($path, $suffixes['testing']) => 6, diff --git a/packages/core/src/Kernel/LoadDiscoveryClasses.php b/packages/core/src/Kernel/LoadDiscoveryClasses.php index 178b72382..f6ae0b8cf 100644 --- a/packages/core/src/Kernel/LoadDiscoveryClasses.php +++ b/packages/core/src/Kernel/LoadDiscoveryClasses.php @@ -256,11 +256,9 @@ private function discoverPath(string $input, DiscoveryLocation $location, array } foreach ($discoveries as $discovery) { - if (! $discovery instanceof DiscoversPath) { - continue; + if ($discovery instanceof DiscoversPath) { + $discovery->discoverPath($location, $input); } - - $discovery->discoverPath($location, $input); } } diff --git a/packages/core/src/Middleware.php b/packages/core/src/Middleware.php index 5e0b3445c..1ff506df6 100644 --- a/packages/core/src/Middleware.php +++ b/packages/core/src/Middleware.php @@ -64,7 +64,7 @@ public function unwrap(): Generator /** @return self */ private function sort(): self { - uasort($this->middlewareClasses, static function (ClassReflector $a, ClassReflector $b): int { + uasort($this->middlewareClasses, function (ClassReflector $a, ClassReflector $b): int { $priorityA = $a->getAttribute(Priority::class)->priority ?? Priority::NORMAL; $priorityB = $b->getAttribute(Priority::class)->priority ?? Priority::NORMAL; @@ -78,7 +78,7 @@ public function __serialize(): array { return [ 'middlewareClasses' => arr($this->middlewareClasses) - ->map(static fn (ClassReflector $class) => $class->getName()) + ->map(fn (ClassReflector $class) => $class->getName()) ->toArray(), ]; } @@ -86,7 +86,7 @@ public function __serialize(): array public function __unserialize(array $data): void { $this->middlewareClasses = arr($data['middlewareClasses']) - ->map(static fn (string $className) => new ClassReflector($className)) + ->map(fn (string $className) => new ClassReflector($className)) ->toArray(); } } diff --git a/packages/core/src/PublishesFiles.php b/packages/core/src/PublishesFiles.php index 716ece1ff..410d5d156 100644 --- a/packages/core/src/PublishesFiles.php +++ b/packages/core/src/PublishesFiles.php @@ -83,7 +83,7 @@ public function publish(string $source, string $destination, ?Closure $callback targetPath: $destination, shouldOverride: true, manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); @@ -248,16 +248,14 @@ function (string $content) use ($callback) { // PHP will output empty arrays for empty dependencies, // which is invalid and will make package managers crash. foreach (['dependencies', 'devDependencies', 'peerDependencies'] as $key) { - if (! (isset($json[$key]) && ! $json[$key])) { - continue; + if (isset($json[$key]) && ! $json[$key]) { + unset($json[$key]); } - - unset($json[$key]); } $content = preg_replace_callback( '/^ +/m', - static fn ($m) => str_repeat($indent, strlen($m[0]) / 4), + fn ($m) => str_repeat($indent, strlen($m[0]) / 4), Json\encode($json, pretty: true), ); diff --git a/packages/core/src/functions.php b/packages/core/src/functions.php index 4d64ccfd4..3e93e0267 100644 --- a/packages/core/src/functions.php +++ b/packages/core/src/functions.php @@ -6,6 +6,7 @@ use Closure; use Stringable; +use Tempest\Container; use Tempest\Core\Composer; use Tempest\Core\DeferredTasks; use Tempest\Core\EnvironmentVariableValidationFailed; diff --git a/packages/cryptography/tests/TimelockTest.php b/packages/cryptography/tests/TimelockTest.php index aa3ebe7c4..08c073905 100644 --- a/packages/cryptography/tests/TimelockTest.php +++ b/packages/cryptography/tests/TimelockTest.php @@ -15,7 +15,7 @@ final class TimelockTest extends TestCase public function test_callback_is_executed(): void { $clock = new GenericClock(); - $result = new Timelock($clock)->invoke(static fn () => 'hello', Duration::zero()); + $result = new Timelock($clock)->invoke(fn () => 'hello', Duration::zero()); $this->assertSame('hello', $result); } @@ -26,7 +26,7 @@ public function test_locks_for_duration(): void $start = microtime(true); $timelock = new Timelock($clock); - $timelock->invoke(static fn () => null, Duration::milliseconds(100)); + $timelock->invoke(fn () => null, Duration::milliseconds(100)); $elapsed = microtime(true) - $start; @@ -40,7 +40,7 @@ public function test_return_early(): void $start = microtime(true); $timelock->invoke( - callback: static fn (Timelock $lock) => $lock->canReturnEarly = true, + callback: fn (Timelock $lock) => $lock->canReturnEarly = true, duration: Duration::milliseconds(100), ); $elapsed = microtime(true) - $start; @@ -57,7 +57,7 @@ public function test_throws_exception_after_delay(): void try { $timelock->invoke( - callback: static fn () => throw new \RuntimeException('This is an error.'), + callback: fn () => throw new \RuntimeException('This is an error.'), duration: Duration::milliseconds(100), ); } catch (\RuntimeException) { @@ -74,7 +74,7 @@ public function test_uses_clock_to_sleep(): void $ms = $clock->timestamp()->getMilliseconds(); $timelock->invoke( - callback: static fn () => null, + callback: fn () => null, duration: Duration::milliseconds(300), ); diff --git a/packages/database/src/Builder/ModelInspector.php b/packages/database/src/Builder/ModelInspector.php index 9284c2b60..d39dab76d 100644 --- a/packages/database/src/Builder/ModelInspector.php +++ b/packages/database/src/Builder/ModelInspector.php @@ -311,11 +311,9 @@ public function getRelations(): ImmutableArray $relationFields = arr(); foreach ($this->reflector->getPublicProperties() as $property) { - if (! ($relation = $this->getRelation($property->getName()))) { - continue; + if ($relation = $this->getRelation($property->getName())) { + $relationFields[] = $relation; } - - $relationFields[] = $relation; } return $relationFields; @@ -572,7 +570,7 @@ public function getPrimaryKeyProperty(): ?PropertyReflector } $primaryKeys = arr($this->reflector->getProperties()) - ->filter(static fn (PropertyReflector $property) => $property->getType()->matches(PrimaryKey::class)); + ->filter(fn (PropertyReflector $property) => $property->getType()->matches(PrimaryKey::class)); return match ($primaryKeys->count()) { 0 => null, diff --git a/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php index 7b85dc893..d665ec45e 100644 --- a/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php @@ -144,7 +144,7 @@ public function build(mixed ...$bindings): Query { if ($this->joins !== []) { $this->count->joins = arr($this->joins) - ->map(static fn (JoinStatement|string $join) => $join instanceof JoinStatement ? $join : new JoinStatement($join)); + ->map(fn (JoinStatement|string $join) => $join instanceof JoinStatement ? $join : new JoinStatement($join)); } return new Query($this->count, [...$this->bindings, ...$bindings])->onDatabase($this->onDatabase); diff --git a/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php b/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php index 50834df42..30f94d730 100644 --- a/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php +++ b/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php @@ -45,7 +45,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat throw new \InvalidArgumentException("{$operator->value} operator requires an array of values"); } - $value = array_map(static fn (mixed $value) => match (true) { + $value = array_map(fn (mixed $value) => match (true) { $value instanceof BackedEnum => $value->value, $value instanceof UnitEnum => $value->name, $value instanceof ArrayAccess => (array) $value, @@ -65,7 +65,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat $sql .= " {$operator->value} ? AND ?"; $bindings = array_map( - static fn (DateTimeInterface|string|float|int|Countable $value) => match (true) { + fn (DateTimeInterface|string|float|int|Countable $value) => match (true) { $value instanceof Countable => count($value), default => $value, }, @@ -99,7 +99,7 @@ private function looksLikeWhereRawStatement(string $statement, array $bindings): return false; } - if (! Str\contains($statement, [' ', ...array_map(static fn (WhereOperator $op) => $op->value, WhereOperator::cases())])) { + if (! Str\contains($statement, [' ', ...array_map(fn (WhereOperator $op) => $op->value, WhereOperator::cases())])) { return false; } diff --git a/packages/database/src/Commands/MakeMigrationCommand.php b/packages/database/src/Commands/MakeMigrationCommand.php index eb3d211d0..7e6c09507 100644 --- a/packages/database/src/Commands/MakeMigrationCommand.php +++ b/packages/database/src/Commands/MakeMigrationCommand.php @@ -176,7 +176,7 @@ private function generateClassFile(string $name, StubFile $stub, string $classNa $classFileName = str($className) ->when( condition: str($name)->contains(['\\', '/']), - callback: static fn ($path) => $path->prepend(str($name)->beforeLast(['\\', '/'])->toString(), '/'), + callback: fn ($path) => $path->prepend(str($name)->beforeLast(['\\', '/'])->toString(), '/'), ) ->toString(); diff --git a/packages/database/src/DatabaseInitializer.php b/packages/database/src/DatabaseInitializer.php index ddf1c1b17..c7a7fd187 100644 --- a/packages/database/src/DatabaseInitializer.php +++ b/packages/database/src/DatabaseInitializer.php @@ -27,7 +27,7 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con { $container->singleton( className: Connection::class, - definition: static function () use ($tag, $container) { + definition: function () use ($tag, $container) { $config = $container->get(DatabaseConfig::class, $tag); $connection = new PDOConnection($config); diff --git a/packages/database/src/Exceptions/InsertColumnsMismatched.php b/packages/database/src/Exceptions/InsertColumnsMismatched.php index 4f5f00dfb..121c463f9 100644 --- a/packages/database/src/Exceptions/InsertColumnsMismatched.php +++ b/packages/database/src/Exceptions/InsertColumnsMismatched.php @@ -11,8 +11,8 @@ public function __construct( ImmutableArray $expected, ImmutableArray $actual, ) { - $expected = $expected->map(static fn ($column) => "`{$column}`")->join(); - $actual = $actual->map(static fn ($column) => "`{$column}`")->join(); + $expected = $expected->map(fn ($column) => "`{$column}`")->join(); + $actual = $actual->map(fn ($column) => "`{$column}`")->join(); parent::__construct("Expected columns {$expected}; but got {$actual}"); } diff --git a/packages/database/src/IsDatabaseModel.php b/packages/database/src/IsDatabaseModel.php index 643227fdf..ebb837d6a 100644 --- a/packages/database/src/IsDatabaseModel.php +++ b/packages/database/src/IsDatabaseModel.php @@ -52,7 +52,9 @@ public function onDatabase(null|string|UnitEnum $databaseTag): self protected static function queryBuilder(): QueryBuilder { /** @var QueryBuilder $query */ - return query(self::class); + $query = query(self::class); + + return $query; } /** @@ -62,7 +64,9 @@ protected static function queryBuilder(): QueryBuilder */ public static function select(): SelectQueryBuilder { - return self::queryBuilder()->select(); + $query = self::queryBuilder()->select(); + + return $query; } /** @@ -205,7 +209,7 @@ public function refresh(): self $loadedRelations = $model ->getRelations() - ->filter(static fn (Relation $relation) => $model->isRelationLoaded($relation)); + ->filter(fn (Relation $relation) => $model->isRelationLoaded($relation)); $primaryKeyProperty = $model->getPrimaryKeyProperty(); $primaryKeyValue = $primaryKeyProperty->getValue($this); @@ -213,7 +217,7 @@ public function refresh(): self $new = self::queryBuilder() ->onDatabase($this->onDatabase) ->select() - ->with(...$loadedRelations->map(static fn (Relation $relation) => $relation->name)) + ->with(...$loadedRelations->map(fn (Relation $relation) => $relation->name)) ->get($primaryKeyValue); foreach ($loadedRelations as $relation) { @@ -248,7 +252,7 @@ public function load(string ...$relations): self ->get($primaryKeyValue, $relations); $fieldsToUpdate = arr($relations) - ->map(static fn (string $relation) => str($relation)->before('.')->toString()) + ->map(fn (string $relation) => str($relation)->before('.')->toString()) ->unique(); foreach ($fieldsToUpdate as $fieldToUpdate) { diff --git a/packages/database/src/Mappers/SelectModelMapper.php b/packages/database/src/Mappers/SelectModelMapper.php index adc47cdf3..12d8477d9 100644 --- a/packages/database/src/Mappers/SelectModelMapper.php +++ b/packages/database/src/Mappers/SelectModelMapper.php @@ -34,7 +34,7 @@ public function map(mixed $from, mixed $to): array $idField = $model->getQualifiedPrimaryKey(); $parsed = arr($from) - ->groupBy(static fn (array $data, int|string $i) => $idField !== null ? $data[$idField] ?? $i : $i) + ->groupBy(fn (array $data, int|string $i) => $idField !== null ? $data[$idField] ?? $i : $i) ->map(fn (array $rows) => $this->normalizeFields($model, $rows)) ->values(); diff --git a/packages/database/src/Migrations/MigrationManager.php b/packages/database/src/Migrations/MigrationManager.php index 308e59e62..bfcabca2a 100644 --- a/packages/database/src/Migrations/MigrationManager.php +++ b/packages/database/src/Migrations/MigrationManager.php @@ -326,6 +326,8 @@ private function getMinifiedSqlFromStatement(?QueryStatement $statement): string $sql = preg_replace('/\/\*[\s\S]*?\*\//', '', $sql); // Remove block comments // Remove blank lines and excessive spaces - return preg_replace('/\s+/', ' ', trim($sql)); + $sql = preg_replace('/\s+/', ' ', trim($sql)); + + return $sql; } } diff --git a/packages/database/src/Migrations/RunnableMigrations.php b/packages/database/src/Migrations/RunnableMigrations.php index 1fabaa706..c90a8de19 100644 --- a/packages/database/src/Migrations/RunnableMigrations.php +++ b/packages/database/src/Migrations/RunnableMigrations.php @@ -36,11 +36,9 @@ public function getIterator(): Traversable public function up(): Traversable { foreach ($this->getIterator() as $migration) { - if (! $migration instanceof MigratesUp) { - continue; + if ($migration instanceof MigratesUp) { + yield $migration; } - - yield $migration; } } @@ -50,11 +48,9 @@ public function up(): Traversable public function down(): Traversable { foreach ($this->getIterator() as $migration) { - if (! $migration instanceof MigratesDown) { - continue; + if ($migration instanceof MigratesDown) { + yield $migration; } - - yield $migration; } } } diff --git a/packages/database/src/QueryStatements/AlterTableStatement.php b/packages/database/src/QueryStatements/AlterTableStatement.php index bf9139aa8..1ba8b7421 100644 --- a/packages/database/src/QueryStatements/AlterTableStatement.php +++ b/packages/database/src/QueryStatements/AlterTableStatement.php @@ -94,8 +94,8 @@ public function compile(DatabaseDialect $dialect): string 'ALTER TABLE %s %s;', new TableDefinition($this->tableName), arr($this->statements) - ->map(static fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) - ->filter(static fn (ImmutableString $line) => $line->isNotEmpty()) + ->map(fn (QueryStatement $queryStatement) => str($queryStatement->compile($dialect))->trim()->replace(' ', ' ')) + ->filter(fn (ImmutableString $line) => $line->isNotEmpty()) ->implode(', ' . PHP_EOL . ' ') ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), diff --git a/packages/database/src/QueryStatements/CompoundStatement.php b/packages/database/src/QueryStatements/CompoundStatement.php index df088afab..afb75d04f 100644 --- a/packages/database/src/QueryStatements/CompoundStatement.php +++ b/packages/database/src/QueryStatements/CompoundStatement.php @@ -22,7 +22,7 @@ public function __construct(QueryStatement ...$statements) public function compile(DatabaseDialect $dialect): string { return arr($this->statements) - ->map(static fn (QueryStatement $statement) => $statement->compile($dialect)) + ->map(fn (QueryStatement $statement) => $statement->compile($dialect)) ->implode(';' . PHP_EOL) ->append(';') ->toString(); diff --git a/packages/database/src/QueryStatements/CountStatement.php b/packages/database/src/QueryStatements/CountStatement.php index aa170b3a4..353d1f354 100644 --- a/packages/database/src/QueryStatements/CountStatement.php +++ b/packages/database/src/QueryStatements/CountStatement.php @@ -44,8 +44,8 @@ public function compile(DatabaseDialect $dialect): string if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(static fn (QueryStatement $where) => $where->compile($dialect)) - ->filter(static fn (string $compiled) => $compiled !== '') + ->map(fn (QueryStatement $where) => $where->compile($dialect)) + ->filter(fn (string $compiled) => $compiled !== '') ->implode(' '); } diff --git a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php index 4f6f38a89..bf359c437 100644 --- a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php @@ -22,9 +22,9 @@ public function __construct( public function compile(DatabaseDialect $dialect): string { $cases = arr($this->enumClass::cases()) - ->map(static fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) - ->map(static fn (string $value) => str_replace('\\', '\\\\', $value)) - ->map(static fn (string $value) => "'{$value}'"); + ->map(fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) + ->map(fn (string $value) => str_replace('\\', '\\\\', $value)) + ->map(fn (string $value) => "'{$value}'"); return match ($dialect) { DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', diff --git a/packages/database/src/QueryStatements/CreateTableStatement.php b/packages/database/src/QueryStatements/CreateTableStatement.php index 28e9b2d6e..3e759a985 100644 --- a/packages/database/src/QueryStatements/CreateTableStatement.php +++ b/packages/database/src/QueryStatements/CreateTableStatement.php @@ -395,7 +395,7 @@ public function raw(string $statement): self public function compile(DatabaseDialect $dialect): string { - return sprintf( + $createTable = sprintf( 'CREATE TABLE %s (%s);', new TableDefinition($this->tableName), arr($this->statements) @@ -407,5 +407,7 @@ public function compile(DatabaseDialect $dialect): string ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), ); + + return $createTable; } } diff --git a/packages/database/src/QueryStatements/DeleteStatement.php b/packages/database/src/QueryStatements/DeleteStatement.php index b93e7c321..a8a880a5d 100644 --- a/packages/database/src/QueryStatements/DeleteStatement.php +++ b/packages/database/src/QueryStatements/DeleteStatement.php @@ -30,8 +30,8 @@ public function compile(DatabaseDialect $dialect): string if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(static fn (QueryStatement $where) => $where->compile($dialect)) - ->filter(static fn (string $compiled) => $compiled !== '') + ->map(fn (QueryStatement $where) => $where->compile($dialect)) + ->filter(fn (string $compiled) => $compiled !== '') ->implode(' '); } diff --git a/packages/database/src/QueryStatements/EnumStatement.php b/packages/database/src/QueryStatements/EnumStatement.php index 109310f7b..29d05bcd8 100644 --- a/packages/database/src/QueryStatements/EnumStatement.php +++ b/packages/database/src/QueryStatements/EnumStatement.php @@ -25,9 +25,9 @@ public function __construct( public function compile(DatabaseDialect $dialect): string { $cases = arr($this->enumClass::cases()) - ->map(static fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) - ->map(static fn (string $value) => str_replace('\\', '\\\\', $value)) - ->map(static fn (string $value) => "'{$value}'"); + ->map(fn (UnitEnum|BackedEnum $case) => $case instanceof BackedEnum ? $case->value : $case->name) + ->map(fn (string $value) => str_replace('\\', '\\\\', $value)) + ->map(fn (string $value) => "'{$value}'"); if ($this->default !== null) { $defaultValue = $this->default instanceof BackedEnum ? $this->default->value : $this->default->name; diff --git a/packages/database/src/QueryStatements/FieldStatement.php b/packages/database/src/QueryStatements/FieldStatement.php index 5dbc066e2..9492b1397 100644 --- a/packages/database/src/QueryStatements/FieldStatement.php +++ b/packages/database/src/QueryStatements/FieldStatement.php @@ -45,9 +45,9 @@ public function compile(DatabaseDialect $dialect): string } $field = arr(explode('.', $field)) - ->map(static fn (string $part) => trim($part, '` ')) + ->map(fn (string $part) => trim($part, '` ')) ->map( - static function (string $part) use ($dialect) { + function (string $part) use ($dialect) { // Function calls are never wrapped in backticks. if (str_contains($part, '(')) { return $part; diff --git a/packages/database/src/QueryStatements/InsertStatement.php b/packages/database/src/QueryStatements/InsertStatement.php index cabdb1a48..8b95d0c6f 100644 --- a/packages/database/src/QueryStatements/InsertStatement.php +++ b/packages/database/src/QueryStatements/InsertStatement.php @@ -30,7 +30,7 @@ public function compile(DatabaseDialect $dialect): string $columns = arr($this->entries->first())->keys(); $entryPlaceholders = $this->entries - ->map(static function (array|ImmutableArray $row) use ($columns) { + ->map(function (array|ImmutableArray $row) use ($columns) { $row = arr($row); $rowColumns = $row->keys(); @@ -41,7 +41,7 @@ public function compile(DatabaseDialect $dialect): string return sprintf( '(%s)', - $row->map(static fn () => '?')->implode(', '), + $row->map(fn () => '?')->implode(', '), ); }) ->implode(', '); @@ -55,7 +55,7 @@ public function compile(DatabaseDialect $dialect): string $sql = sprintf( 'INSERT INTO %s (%s) VALUES %s', $this->table, - $columns->map(static fn (string $column) => "`{$column}`")->implode(', '), + $columns->map(fn (string $column) => "`{$column}`")->implode(', '), $entryPlaceholders, ); } diff --git a/packages/database/src/QueryStatements/SelectStatement.php b/packages/database/src/QueryStatements/SelectStatement.php index 6c294cc98..926b5afc5 100644 --- a/packages/database/src/QueryStatements/SelectStatement.php +++ b/packages/database/src/QueryStatements/SelectStatement.php @@ -71,32 +71,32 @@ public function compile(DatabaseDialect $dialect): string if ($this->join->isNotEmpty()) { $query[] = $this->join - ->map(static fn (JoinStatement $join) => $join->compile($dialect)) + ->map(fn (JoinStatement $join) => $join->compile($dialect)) ->implode(' '); } if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(static fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) - ->filter(static fn (string $compiled) => $compiled !== '') + ->map(fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) + ->filter(fn (string $compiled) => $compiled !== '') ->implode(' '); } if ($this->groupBy->isNotEmpty()) { $query[] = 'GROUP BY ' . $this->groupBy - ->map(static fn (GroupByStatement $groupBy) => $groupBy->compile($dialect)) + ->map(fn (GroupByStatement $groupBy) => $groupBy->compile($dialect)) ->implode(', '); } if ($this->having->isNotEmpty()) { $query[] = 'HAVING ' . $this->having - ->map(static fn (HavingStatement $having) => $having->compile($dialect)) + ->map(fn (HavingStatement $having) => $having->compile($dialect)) ->implode(' '); } if ($this->orderBy->isNotEmpty()) { $query[] = 'ORDER BY ' . $this->orderBy - ->map(static fn (OrderByStatement $orderBy) => $orderBy->compile($dialect)) + ->map(fn (OrderByStatement $orderBy) => $orderBy->compile($dialect)) ->implode(', '); } @@ -110,7 +110,7 @@ public function compile(DatabaseDialect $dialect): string if ($this->raw->isNotEmpty()) { $query[] = $this->raw - ->map(static fn (RawStatement $raw) => $raw->compile($dialect)) + ->map(fn (RawStatement $raw) => $raw->compile($dialect)) ->implode(' ') ->toString(); } diff --git a/packages/database/src/QueryStatements/UpdateStatement.php b/packages/database/src/QueryStatements/UpdateStatement.php index 4811473e2..0a46b886d 100644 --- a/packages/database/src/QueryStatements/UpdateStatement.php +++ b/packages/database/src/QueryStatements/UpdateStatement.php @@ -35,13 +35,13 @@ public function compile(DatabaseDialect $dialect): string } $query[] = 'SET ' . $this->values - ->map(static fn (mixed $_, mixed $key) => "`{$key}` = ?") + ->map(fn (mixed $_, mixed $key) => "`{$key}` = ?") ->implode(', '); if ($this->where->isNotEmpty()) { $query[] = 'WHERE ' . $this->where - ->map(static fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) - ->filter(static fn (string $compiled) => $compiled !== '') + ->map(fn (WhereStatement|WhereGroupStatement $where) => $where->compile($dialect)) + ->filter(fn (string $compiled) => $compiled !== '') ->implode(' '); } diff --git a/packages/database/src/QueryStatements/WhereGroupStatement.php b/packages/database/src/QueryStatements/WhereGroupStatement.php index 3f1a2e5d5..2bdc2d95c 100644 --- a/packages/database/src/QueryStatements/WhereGroupStatement.php +++ b/packages/database/src/QueryStatements/WhereGroupStatement.php @@ -22,8 +22,8 @@ public function compile(DatabaseDialect $dialect): string } $compiled = $this->conditions - ->map(static fn (QueryStatement $condition) => $condition->compile($dialect)) - ->filter(static fn (string $condition) => $condition !== ''); + ->map(fn (QueryStatement $condition) => $condition->compile($dialect)) + ->filter(fn (string $condition) => $condition !== ''); if ($compiled->isEmpty()) { return ''; diff --git a/packages/database/src/Serializers/DataTransferObjectSerializer.php b/packages/database/src/Serializers/DataTransferObjectSerializer.php index 2a02e846b..a9aacf5f0 100644 --- a/packages/database/src/Serializers/DataTransferObjectSerializer.php +++ b/packages/database/src/Serializers/DataTransferObjectSerializer.php @@ -99,7 +99,7 @@ private function extractObjectData(object $input): array return Arr\map_with_keys( array: new ClassReflector($input)->getPublicProperties(), - map: static fn (PropertyReflector $property) => yield $property->getName() => $property->getValue($input), + map: fn (PropertyReflector $property) => yield $property->getName() => $property->getValue($input), ); } } diff --git a/packages/database/src/functions.php b/packages/database/src/functions.php index 44e466b43..73c135a17 100644 --- a/packages/database/src/functions.php +++ b/packages/database/src/functions.php @@ -15,7 +15,9 @@ function query(string|object $model): QueryBuilder { /** @var QueryBuilder $query */ - return new QueryBuilder($model); + $query = new QueryBuilder($model); + + return $query; } /** diff --git a/packages/database/tests/Config/DatabaseConfigTest.php b/packages/database/tests/Config/DatabaseConfigTest.php index 08d72ae66..02df0a722 100644 --- a/packages/database/tests/Config/DatabaseConfigTest.php +++ b/packages/database/tests/Config/DatabaseConfigTest.php @@ -22,7 +22,7 @@ final class DatabaseConfigTest extends TestCase { #[DataProvider('provide_database_drivers')] #[Test] - public function driver_has_the_correct_dsn(DatabaseConfig $driver, string $dsn, ?string $username, #[\SensitiveParameter] ?string $password): void + public function driver_has_the_correct_dsn(DatabaseConfig $driver, string $dsn, ?string $username, ?string $password): void { $this->assertSame($dsn, $driver->dsn); $this->assertSame($username, $driver->username); diff --git a/packages/database/tests/GenericDatabaseTest.php b/packages/database/tests/GenericDatabaseTest.php index b7f898394..ead08fdd6 100644 --- a/packages/database/tests/GenericDatabaseTest.php +++ b/packages/database/tests/GenericDatabaseTest.php @@ -37,7 +37,7 @@ public function test_it_executes_transactions(): void new SerializerFactory(new GenericContainer()), ); - $result = $database->withinTransaction(static function () { + $result = $database->withinTransaction(function () { return true; }); @@ -64,7 +64,7 @@ public function test_it_rolls_back_transactions_on_failure(): void new SerializerFactory(new GenericContainer()), ); - $result = $database->withinTransaction(static function (): never { + $result = $database->withinTransaction(function (): never { throw new Exception(); }); diff --git a/packages/datetime/src/SecondsStyle.php b/packages/datetime/src/SecondsStyle.php index 5b2b82540..ed6bb914a 100644 --- a/packages/datetime/src/SecondsStyle.php +++ b/packages/datetime/src/SecondsStyle.php @@ -38,7 +38,7 @@ public static function fromTimestamp(Timestamp $timestamp): SecondsStyle return match (true) { $nanoseconds === 0 => static::Seconds, - ($nanoseconds % 1_000_000) === 0 => static::Milliseconds, + ($nanoseconds % 1000000) === 0 => static::Milliseconds, ($nanoseconds % 1000) === 0 => static::Microseconds, default => static::Nanoseconds, }; diff --git a/packages/datetime/src/functions.php b/packages/datetime/src/functions.php index b60d23a84..63233bcf7 100644 --- a/packages/datetime/src/functions.php +++ b/packages/datetime/src/functions.php @@ -6,8 +6,14 @@ use IntlDateFormatter; use IntlTimeZone; use RuntimeException; +use Tempest\DateTime\DateStyle; use Tempest\DateTime\Exception\OverflowException; use Tempest\DateTime\Exception\ParserException; +use Tempest\DateTime\FormatPattern; +use Tempest\DateTime\SecondsStyle; +use Tempest\DateTime\Timestamp; +use Tempest\DateTime\TimeStyle; +use Tempest\DateTime\Timezone; use Tempest\Intl\Locale; use ValueError; @@ -15,6 +21,8 @@ use function microtime; use function Tempest\Intl\current_locale; +use const Tempest\DateTime\NANOSECONDS_PER_SECOND; + /** * Get the current date and time as a {@see \Tempest\DateTime\DateTime} object. */ diff --git a/packages/datetime/tests/DateTimeTest.php b/packages/datetime/tests/DateTimeTest.php index 26f1342e5..ba7428573 100644 --- a/packages/datetime/tests/DateTimeTest.php +++ b/packages/datetime/tests/DateTimeTest.php @@ -242,13 +242,13 @@ public function test_parse_icu(): void $parsed = DateTime::fromPattern('2025-01-01 10:00', pattern: 'yyyy-MM-dd HH:mm'); $this->assertEquals('2025-01-01 10:00', $parsed->format(pattern: 'yyyy-MM-dd HH:mm')); - $this->assertEquals(1_735_725_600, $parsed->getTimestamp()->getSeconds()); + $this->assertEquals(1735725600, $parsed->getTimestamp()->getSeconds()); } public function test_parse_timestamp(): void { - $expected = DateTime::fromTimestamp(1_747_670_452_940); - $parsed = DateTime::parse(1_747_670_452_940); + $expected = DateTime::fromTimestamp(1747670452940); + $parsed = DateTime::parse(1747670452940); $this->assertEquals($expected->getTimestamp(), $parsed->getTimestamp()); $this->assertSame($expected->getTimezone(), $parsed->getTimezone()); @@ -629,7 +629,7 @@ public function test_end_of_day(): void $this->assertSame(23, $new->getHours()); $this->assertSame(59, $new->getMinutes()); $this->assertSame(59, $new->getSeconds()); - $this->assertSame(999_999_999, $new->getNanoseconds()); + $this->assertSame(999999999, $new->getNanoseconds()); } public function test_start_of_week(): void @@ -696,7 +696,7 @@ public function test_convert_time_zone(): void public function test_is_same_year(): void { $date1 = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 12, 0, 0, 0); - $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); + $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999999999); $date3 = DateTime::fromParts(Timezone::default(), 2025, Month::JANUARY, 1, 0, 0, 0, 0); $this->assertTrue($date1->isSameYear($date2)); @@ -707,7 +707,7 @@ public function test_is_same_year(): void public function test_is_same_month(): void { $date1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 1, 12, 0, 0, 0); - $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 29, 23, 59, 59, 999_999_999); + $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 29, 23, 59, 59, 999999999); $date3 = DateTime::fromParts(Timezone::default(), 2024, Month::MARCH, 1, 0, 0, 0, 0); $date4 = DateTime::fromParts(Timezone::default(), 2025, Month::FEBRUARY, 15, 12, 0, 0, 0); @@ -733,7 +733,7 @@ public function test_is_same_week(): void public function test_is_same_day(): void { $morning = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 8, 30, 0, 0); - $evening = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 20, 45, 30, 123_456_789); + $evening = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 20, 45, 30, 123456789); $nextDay = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 8, 30, 0, 0); $this->assertTrue($morning->isSameDay($evening)); @@ -744,7 +744,7 @@ public function test_is_same_day(): void public function test_is_same_hour(): void { $time1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 15, 30, 0); - $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 45, 59, 999_999_999); + $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 45, 59, 999999999); $time3 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 15, 15, 30, 0); $differentDay = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 14, 15, 30, 0); @@ -757,7 +757,7 @@ public function test_is_same_hour(): void public function test_is_same_minute(): void { $time1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 15, 0); - $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 45, 999_999_999); + $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 45, 999999999); $time3 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 31, 15, 0); $differentHour = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 15, 30, 15, 0); @@ -770,7 +770,7 @@ public function test_is_same_minute(): void public function test_is_next_day(): void { $today = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $tomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 15, 30, 45, 123_456_789); + $tomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 15, 30, 45, 123456789); $dayAfterTomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 7, 8, 0, 0, 0); $this->assertTrue($tomorrow->isNextDay($today)); @@ -782,7 +782,7 @@ public function test_is_next_day(): void public function test_is_previous_day(): void { $today = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $yesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 4, 8, 15, 30, 987_654_321); + $yesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 4, 8, 15, 30, 987654321); $dayBeforeYesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 3, 20, 0, 0, 0); $this->assertTrue($yesterday->isPreviousDay($today)); @@ -846,9 +846,9 @@ public function test_is_last_day_of_month(): void public function test_is_first_day_of_year(): void { $newYearsDay = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 0, 0, 0, 0); - $newYearsDayDifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 23, 59, 59, 999_999_999); + $newYearsDayDifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 23, 59, 59, 999999999); $secondDay = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 2, 0, 0, 0, 0); - $december31 = DateTime::fromParts(Timezone::default(), 2023, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); + $december31 = DateTime::fromParts(Timezone::default(), 2023, Month::DECEMBER, 31, 23, 59, 59, 999999999); $this->assertTrue($newYearsDay->isFirstDayOfYear()); $this->assertTrue($newYearsDayDifferentTime->isFirstDayOfYear()); @@ -859,8 +859,8 @@ public function test_is_first_day_of_year(): void public function test_is_last_day_of_year(): void { $december31 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 0, 0, 0, 0); - $december31DifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); - $december30 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 30, 23, 59, 59, 999_999_999); + $december31DifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999999999); + $december30 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 30, 23, 59, 59, 999999999); $january1 = DateTime::fromParts(Timezone::default(), 2025, Month::JANUARY, 1, 0, 0, 0, 0); $this->assertTrue($december31->isLastDayOfYear()); @@ -917,13 +917,13 @@ public function test_time_of_day_methods(): void public function test_time_edge_cases(): void { - $boundary5_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 5, 59, 59, 999_999_999); + $boundary5_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 5, 59, 59, 999999999); $boundary6_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 6, 0, 0, 0); - $boundary11_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 11, 59, 59, 999_999_999); + $boundary11_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 11, 59, 59, 999999999); $boundary12_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $boundary17_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 17, 59, 59, 999_999_999); + $boundary17_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 17, 59, 59, 999999999); $boundary18_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 18, 0, 0, 0); - $boundary21_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 21, 59, 59, 999_999_999); + $boundary21_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 21, 59, 59, 999999999); $boundary22_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 22, 0, 0, 0); $this->assertTrue($boundary5_59->isNight()); diff --git a/packages/datetime/tests/DurationTest.php b/packages/datetime/tests/DurationTest.php index 348b6a2bc..7d58f9929 100644 --- a/packages/datetime/tests/DurationTest.php +++ b/packages/datetime/tests/DurationTest.php @@ -48,13 +48,13 @@ public function test_named_constructors(): void } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 2.777_777_777_777_778E-13])] + #[TestWith([0, 0, 0, 1, 2.777777777777778E-13])] #[TestWith([1, 0, 0, 0, 1.0])] #[TestWith([1, 30, 0, 0, 1.5])] - #[TestWith([2, 15, 30, 0, 2.258_333_333_333_333_3])] + #[TestWith([2, 15, 30, 0, 2.2583333333333333])] #[TestWith([-1, 0, 0, 0, -1.0])] #[TestWith([-1, -30, 0, 0, -1.5])] - #[TestWith([-2, -15, -30, 0, -2.258_333_333_333_333_3])] + #[TestWith([-2, -15, -30, 0, -2.2583333333333333])] public function test_get_total_hours( int $hours, int $minutes, @@ -67,7 +67,7 @@ public function test_get_total_hours( } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 1.666_666_666_666_666_7E-11])] + #[TestWith([0, 0, 0, 1, 1.6666666666666667E-11])] #[TestWith([1, 0, 0, 0, 60.0])] #[TestWith([1, 30, 0, 0, 90.0])] #[TestWith([2, 15, 30, 0, 135.5])] @@ -81,7 +81,7 @@ public function test_get_total_minutes(int $hours, int $minutes, int $seconds, i } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 0.000_000_001])] + #[TestWith([0, 0, 0, 1, 0.000000001])] #[TestWith([1, 0, 0, 0, 3600.0])] #[TestWith([1, 30, 0, 0, 5400.0])] #[TestWith([2, 15, 30, 0, 8130.0])] @@ -95,13 +95,13 @@ public function test_get_total_seconds(int $hours, int $minutes, int $seconds, i } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 0.000_001])] - #[TestWith([1, 0, 0, 0, 3_600_000.0])] - #[TestWith([1, 30, 0, 0, 5_400_000.0])] - #[TestWith([2, 15, 30, 0, 8_130_000.0])] - #[TestWith([-1, 0, 0, 0, -3_600_000.0])] - #[TestWith([-1, -30, 0, 0, -5_400_000.0])] - #[TestWith([-2, -15, -30, 0, -8_130_000.0])] + #[TestWith([0, 0, 0, 1, 0.000001])] + #[TestWith([1, 0, 0, 0, 3600000.0])] + #[TestWith([1, 30, 0, 0, 5400000.0])] + #[TestWith([2, 15, 30, 0, 8130000.0])] + #[TestWith([-1, 0, 0, 0, -3600000.0])] + #[TestWith([-1, -30, 0, 0, -5400000.0])] + #[TestWith([-2, -15, -30, 0, -8130000.0])] public function test_get_total_milliseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMilliseconds): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); @@ -110,12 +110,12 @@ public function test_get_total_milliseconds(int $hours, int $minutes, int $secon #[TestWith([0, 0, 0, 0, 0.0])] #[TestWith([0, 0, 0, 1, 0.001])] - #[TestWith([1, 0, 0, 0, 3_600_000_000.0])] - #[TestWith([1, 30, 0, 0, 5_400_000_000.0])] - #[TestWith([2, 15, 30, 0, 8_130_000_000.0])] - #[TestWith([-1, 0, 0, 0, -3_600_000_000.0])] - #[TestWith([-1, -30, 0, 0, -5_400_000_000.0])] - #[TestWith([-2, -15, -30, 0, -8_130_000_000.0])] + #[TestWith([1, 0, 0, 0, 3600000000.0])] + #[TestWith([1, 30, 0, 0, 5400000000.0])] + #[TestWith([2, 15, 30, 0, 8130000000.0])] + #[TestWith([-1, 0, 0, 0, -3600000000.0])] + #[TestWith([-1, -30, 0, 0, -5400000000.0])] + #[TestWith([-2, -15, -30, 0, -8130000000.0])] public function test_get_total_microseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMicroseconds): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); @@ -144,10 +144,10 @@ public function test_fractions_of_second(): void [0, 0, 1, 42], DateTime\Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts(), ); - $this->assertSame([0, 0, 0, 42_000], DateTime\Duration::microseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42_000], DateTime\Duration::microseconds(1_000_042)->getParts()); - $this->assertSame([0, 0, 0, 42_000_000], DateTime\Duration::milliseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42_000_000], DateTime\Duration::milliseconds(1042)->getParts()); + $this->assertSame([0, 0, 0, 42000], DateTime\Duration::microseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42000], DateTime\Duration::microseconds(1000042)->getParts()); + $this->assertSame([0, 0, 0, 42000000], DateTime\Duration::milliseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42000000], DateTime\Duration::milliseconds(1042)->getParts()); } #[TestWith([0, 0, 0, 0])] @@ -271,15 +271,15 @@ public function test_operations(): void #[TestWith([0, 0, 0, 0, '0 second(s)'])] #[TestWith([0, 0, 0, 42, '0 second(s)'])] #[TestWith([0, 0, 1, 42, '1 second(s)'])] - #[TestWith([0, 0, 1, 20_000_000, '1.02 second(s)'])] + #[TestWith([0, 0, 1, 20000000, '1.02 second(s)'])] #[TestWith([1, 2, 0, 0, '1 hour(s), 2 minute(s)'])] #[TestWith([1, 0, 3, 0, '1 hour(s), 0 minute(s), 3 second(s)'])] #[TestWith([0, 2, 3, 0, '2 minute(s), 3 second(s)'])] #[TestWith([1, 2, 3, 0, '1 hour(s), 2 minute(s), 3 second(s)'])] - #[TestWith([1, 0, 0, 42_000_000, '1 hour(s), 0 minute(s), 0.042 second(s)'])] + #[TestWith([1, 0, 0, 42000000, '1 hour(s), 0 minute(s), 0.042 second(s)'])] #[TestWith([-42, 0, -42, 0, '-42 hour(s), 0 minute(s), -42 second(s)'])] - #[TestWith([-42, 0, -42, -420_000_000, '-42 hour(s), 0 minute(s), -42.42 second(s)'])] - #[TestWith([0, 0, 0, -420_000_000, '-0.42 second(s)'])] + #[TestWith([-42, 0, -42, -420000000, '-42 hour(s), 0 minute(s), -42.42 second(s)'])] + #[TestWith([0, 0, 0, -420000000, '-0.42 second(s)'])] public function test_to_string(int $h, int $m, int $s, int $ns, string $expected): void { $this->assertSame($expected, DateTime\Duration::fromParts($h, $m, $s, $ns)->toString()); @@ -287,7 +287,7 @@ public function test_to_string(int $h, int $m, int $s, int $ns, string $expected public function test_serialization(): void { - $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500_000_000); + $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500000000); $serialized = serialize($timeInterval); $deserialized = unserialize($serialized); @@ -296,10 +296,10 @@ public function test_serialization(): void public function test_json_encoding(): void { - $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500_000_000); + $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500000000); $jsonEncoded = Json\encode($timeInterval); $jsonDecoded = Json\decode($jsonEncoded, associative: true); - $this->assertSame(['hours' => 1, 'minutes' => 30, 'seconds' => 45, 'nanoseconds' => 500_000_000], $jsonDecoded); + $this->assertSame(['hours' => 1, 'minutes' => 30, 'seconds' => 45, 'nanoseconds' => 500000000], $jsonDecoded); } } diff --git a/packages/datetime/tests/SecondsStyleTest.php b/packages/datetime/tests/SecondsStyleTest.php index b2c092dbb..a0efa3c9f 100644 --- a/packages/datetime/tests/SecondsStyleTest.php +++ b/packages/datetime/tests/SecondsStyleTest.php @@ -23,7 +23,7 @@ public static function provide_from_timestamp_data(): array { return [ [SecondsStyle::Seconds, Timestamp::fromParts(0)], - [SecondsStyle::Milliseconds, Timestamp::fromParts(0, 1_000_000)], + [SecondsStyle::Milliseconds, Timestamp::fromParts(0, 1000000)], [SecondsStyle::Microseconds, Timestamp::fromParts(0, 1000)], [SecondsStyle::Nanoseconds, Timestamp::fromParts(0, 1)], ]; diff --git a/packages/datetime/tests/TimestampTest.php b/packages/datetime/tests/TimestampTest.php index 42ba40ed5..297abff2a 100644 --- a/packages/datetime/tests/TimestampTest.php +++ b/packages/datetime/tests/TimestampTest.php @@ -144,50 +144,50 @@ public function test_parse_fails(): void public static function provide_format_parsing_data(): iterable { yield [ - 1_711_917_897, + 1711917897, FormatPattern::FULL_DATE_TIME, Timezone::UTC, Locale::ENGLISH, 'Sunday, March 31, 2024 20:44:57', ]; yield [ - 1_711_917_897, + 1711917897, FormatPattern::FULL_DATE_TIME, Timezone::ASIA_SHANGHAI, Locale::CHINESE_TRADITIONAL, '星期一, 4月 01, 2024 04:44:57', ]; yield [ - 1_711_917_897, + 1711917897, FormatPattern::COOKIE, Timezone::AMERICA_NEW_YORK, Locale::ENGLISH_UNITED_STATES, 'Sunday, 31-Mar-2024 16:44:57 EDT', ]; yield [ - 1_711_917_897, + 1711917897, FormatPattern::HTTP, Timezone::EUROPE_VIENNA, Locale::GERMAN_AUSTRIA, 'So., 31 März 2024 22:44:57 MESZ', ]; yield [ - 1_711_917_897, + 1711917897, FormatPattern::EMAIL, Timezone::EUROPE_MADRID, Locale::SPANISH_SPAIN, 'dom, 31 mar 2024 22:44:57 GMT+02:00', ]; yield [ - 1_711_917_897, + 1711917897, FormatPattern::SQL_DATE_TIME, Timezone::AFRICA_TUNIS, Locale::ARABIC_TUNISIA, '2024-03-31 21:44:57', ]; - yield [1_711_832_400, FormatPattern::ISO_ORDINAL_DATE, Timezone::EUROPE_MOSCOW, Locale::RUSSIAN_RUSSIA, '2024-091']; + yield [1711832400, FormatPattern::ISO_ORDINAL_DATE, Timezone::EUROPE_MOSCOW, Locale::RUSSIAN_RUSSIA, '2024-091']; yield [ - 1_711_917_897, + 1711917897, FormatPattern::ISO8601, Timezone::EUROPE_LONDON, Locale::ENGLISH_UNITED_KINGDOM, @@ -444,15 +444,15 @@ public function test_convert_to_timezone(): void public function test_json_serialization(): void { - $serialized = Timestamp::fromParts(1_711_917_232, 12)->jsonSerialize(); + $serialized = Timestamp::fromParts(1711917232, 12)->jsonSerialize(); - $this->assertSame(1_711_917_232, $serialized['seconds']); + $this->assertSame(1711917232, $serialized['seconds']); $this->assertSame(12, $serialized['nanoseconds']); } public function test_to_rfc3999(): void { - $timestamp = Timestamp::fromParts(1_711_917_232, 12); + $timestamp = Timestamp::fromParts(1711917232, 12); $this->assertSame('2024-03-31T20:33:52.12+00:00', $timestamp->toRfc3339()); $this->assertSame('2024-03-31T20:33:52+00:00', $timestamp->toRfc3339(secondsStyle: SecondsStyle::Seconds)); @@ -494,9 +494,9 @@ public function test_temporal_convenience_methods(): void public function test_at_the_same_time_edge_cases(): void { - $timestamp1 = Timestamp::fromParts(1_234_567_890, 123_456_789); - $timestamp2 = Timestamp::fromParts(1_234_567_890, 123_456_789); - $timestamp3 = Timestamp::fromParts(1_234_567_890, 123_456_790); + $timestamp1 = Timestamp::fromParts(1234567890, 123456789); + $timestamp2 = Timestamp::fromParts(1234567890, 123456789); + $timestamp3 = Timestamp::fromParts(1234567890, 123456790); $this->assertTrue($timestamp1->atTheSameTime($timestamp2)); $this->assertFalse($timestamp1->atTheSameTime($timestamp3)); @@ -547,9 +547,9 @@ public function test_between_time_reversed_parameters(): void public function test_nano_precision_temporal_comparisons(): void { - $base = Timestamp::fromParts(1_234_567_890, 0); - $plusOneNano = Timestamp::fromParts(1_234_567_890, 1); - $minusOneNano = Timestamp::fromParts(1_234_567_889, 999_999_999); + $base = Timestamp::fromParts(1234567890, 0); + $plusOneNano = Timestamp::fromParts(1234567890, 1); + $minusOneNano = Timestamp::fromParts(1234567889, 999999999); $this->assertTrue($base->isAfter($minusOneNano)); $this->assertTrue($base->isBefore($plusOneNano)); @@ -592,20 +592,20 @@ public function test_future_past_comprehensive(): void public function test_since_and_between_duration_methods(): void { - $start = Timestamp::fromParts(1000, 500_000_000); - $end = Timestamp::fromParts(1005, 750_000_000); + $start = Timestamp::fromParts(1000, 500000000); + $end = Timestamp::fromParts(1005, 750000000); $duration = $end->since($start); $this->assertSame(5, $duration->getSeconds()); - $this->assertSame(250_000_000, $duration->getNanoseconds()); + $this->assertSame(250000000, $duration->getNanoseconds()); $reverseDuration = $start->since($end); $this->assertSame(-5, $reverseDuration->getSeconds()); - $this->assertSame(-250_000_000, $reverseDuration->getNanoseconds()); + $this->assertSame(-250000000, $reverseDuration->getNanoseconds()); $betweenDuration = $start->between($end); $this->assertSame(-5, $betweenDuration->getSeconds()); - $this->assertSame(-250_000_000, $betweenDuration->getNanoseconds()); + $this->assertSame(-250000000, $betweenDuration->getNanoseconds()); $sameDuration = $start->since($start); $this->assertSame(0, $sameDuration->getSeconds()); @@ -614,8 +614,8 @@ public function test_since_and_between_duration_methods(): void public function test_temporal_comparison_with_large_values(): void { - $large1 = Timestamp::fromParts(9_223_372_036, 999_999_999); - $large2 = Timestamp::fromParts(9_223_372_036, 999_999_998); + $large1 = Timestamp::fromParts(9223372036, 999999999); + $large2 = Timestamp::fromParts(9223372036, 999999998); $this->assertTrue($large1->isAfter($large2)); $this->assertFalse($large1->isBefore($large2)); @@ -626,8 +626,8 @@ public function test_temporal_comparison_with_large_values(): void public function test_temporal_comparison_edge_case_overflow_boundary(): void { - $maxSeconds = Timestamp::fromParts(9_223_372_036_854_775_806, 0); - $nearMax = Timestamp::fromParts(9_223_372_036_854_775_805, 999_999_999); + $maxSeconds = Timestamp::fromParts(9223372036854775806, 0); + $nearMax = Timestamp::fromParts(9223372036854775805, 999999999); $this->assertTrue($maxSeconds->isAfter($nearMax)); $this->assertFalse($maxSeconds->isBefore($nearMax)); diff --git a/packages/datetime/tests/TimezoneTest.php b/packages/datetime/tests/TimezoneTest.php index 73d8ebca1..526e83a48 100644 --- a/packages/datetime/tests/TimezoneTest.php +++ b/packages/datetime/tests/TimezoneTest.php @@ -24,13 +24,13 @@ public function test_default(): void public function test_get_offset(): void { - $temporal = Timestamp::fromParts(seconds: 1_716_956_903); + $temporal = Timestamp::fromParts(seconds: 1716956903); $this->assertSame(3600., Timezone::EUROPE_LONDON->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(-14_400., Timezone::AMERICA_NEW_YORK->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(28_800., Timezone::ASIA_SHANGHAI->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(12_600., Timezone::PLUS_0330->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(-12_600., Timezone::MINUS_0330->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(-14400., Timezone::AMERICA_NEW_YORK->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(28800., Timezone::ASIA_SHANGHAI->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(12600., Timezone::PLUS_0330->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(-12600., Timezone::MINUS_0330->getOffset($temporal)->getTotalSeconds()); $this->assertSame(3600., Timezone::PLUS_0100->getOffset($temporal)->getTotalSeconds()); $this->assertSame(-3600., Timezone::MINUS_0100->getOffset($temporal)->getTotalSeconds()); @@ -45,8 +45,8 @@ public function test_get_offset(): void } #[TestWith([Timezone::EUROPE_LONDON, 0])] - #[TestWith([Timezone::AMERICA_NEW_YORK, -18_000])] - #[TestWith([Timezone::ASIA_SHANGHAI, 28_800])] + #[TestWith([Timezone::AMERICA_NEW_YORK, -18000])] + #[TestWith([Timezone::ASIA_SHANGHAI, 28800])] public function test_raw_offset(Timezone $timezone, int $expected): void { $this->assertSame($expected, (int) $timezone->getRawOffset()->getTotalSeconds()); diff --git a/packages/debug/src/Debug.php b/packages/debug/src/Debug.php index d08f34da2..4899fb2f0 100644 --- a/packages/debug/src/Debug.php +++ b/packages/debug/src/Debug.php @@ -125,7 +125,7 @@ private function createCliDump(mixed $input): string $cloner = new VarCloner(); $output = ''; - $dumper = new CliDumper(static function ($line, $depth) use (&$output): void { + $dumper = new CliDumper(function ($line, $depth) use (&$output): void { if ($depth < 0) { return; } diff --git a/packages/debug/src/Stacktrace/Frame.php b/packages/debug/src/Stacktrace/Frame.php index 381e34e17..95592f450 100644 --- a/packages/debug/src/Stacktrace/Frame.php +++ b/packages/debug/src/Stacktrace/Frame.php @@ -71,7 +71,7 @@ public static function extractArguments(array $frame): array : new ReflectionFunction(function: $frame['function']); $parameterNames = array_map( - callback: static fn (ReflectionParameter $param) => $param->getName(), + callback: fn (ReflectionParameter $param) => $param->getName(), array: $reflection->getParameters(), ); } catch (\Throwable) { diff --git a/packages/debug/src/Stacktrace/Stacktrace.php b/packages/debug/src/Stacktrace/Stacktrace.php index f00e51369..16ad4cd00 100644 --- a/packages/debug/src/Stacktrace/Stacktrace.php +++ b/packages/debug/src/Stacktrace/Stacktrace.php @@ -14,7 +14,7 @@ final class Stacktrace public array $applicationFrames { get => array_values(array_filter( array: $this->frames, - callback: static fn (Frame $frame) => ! $frame->isVendor, + callback: fn (Frame $frame) => ! $frame->isVendor, )); } @@ -22,7 +22,7 @@ final class Stacktrace public array $vendorFrames { get => array_values(array_filter( array: $this->frames, - callback: static fn (Frame $frame) => $frame->isVendor, + callback: fn (Frame $frame) => $frame->isVendor, )); } @@ -103,7 +103,7 @@ function: $frame->function, index: 1, ), // and shift the frame index by one for each frame - ...array_map(static fn (Frame $frame) => new Frame( + ...array_map(fn (Frame $frame) => new Frame( line: $frame->line, class: $frame->class, function: $frame->function, diff --git a/packages/debug/tests/StacktraceTest.php b/packages/debug/tests/StacktraceTest.php index 5e78c6afd..6edf46f7b 100644 --- a/packages/debug/tests/StacktraceTest.php +++ b/packages/debug/tests/StacktraceTest.php @@ -213,11 +213,9 @@ public function stacktrace_uses_root_path_for_vendor_detection(): void $this->assertNotEmpty($frames); foreach ($frames as $frame) { - if (! str_starts_with($frame->absoluteFile, $rootPath)) { - continue; + if (str_starts_with($frame->absoluteFile, $rootPath)) { + $this->assertFalse($frame->isVendor); } - - $this->assertFalse($frame->isVendor); } } diff --git a/packages/discovery/src/Commands/MakeDiscoveryCommand.php b/packages/discovery/src/Commands/MakeDiscoveryCommand.php index e1b5d3944..ddbb81295 100644 --- a/packages/discovery/src/Commands/MakeDiscoveryCommand.php +++ b/packages/discovery/src/Commands/MakeDiscoveryCommand.php @@ -35,7 +35,7 @@ public function __invoke( targetPath: $targetPath, shouldOverride: $shouldOverride, manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/discovery/src/DiscoveryItems.php b/packages/discovery/src/DiscoveryItems.php index 4de868ec0..8b5e1b30c 100644 --- a/packages/discovery/src/DiscoveryItems.php +++ b/packages/discovery/src/DiscoveryItems.php @@ -59,7 +59,7 @@ public function onlyVendor(): self { return new self( arr($this->items) - ->filter(static fn (array $_, string $path) => str_contains($path, '/vendor/') || str_contains($path, '\\vendor\\')) + ->filter(fn (array $_, string $path) => str_contains($path, '/vendor/') || str_contains($path, '\\vendor\\')) ->toArray(), ); } diff --git a/packages/event-bus/src/Testing/EventBusTester.php b/packages/event-bus/src/Testing/EventBusTester.php index 17c9e5dd7..668e4651b 100644 --- a/packages/event-bus/src/Testing/EventBusTester.php +++ b/packages/event-bus/src/Testing/EventBusTester.php @@ -106,7 +106,7 @@ public function assertListeningTo(string $event, ?int $count = null): self private function findDispatches(string|object $event): array { - return array_filter($this->fakeEventBus->dispatched, static function (string|object $dispatched) use ($event) { + return array_filter($this->fakeEventBus->dispatched, function (string|object $dispatched) use ($event) { if ($dispatched === $event) { return true; } diff --git a/packages/event-bus/src/functions.php b/packages/event-bus/src/functions.php index 01a7064ad..3869d85c1 100644 --- a/packages/event-bus/src/functions.php +++ b/packages/event-bus/src/functions.php @@ -6,6 +6,8 @@ use Closure; use Tempest\Container; +use Tempest\EventBus\EventBus; +use Tempest\EventBus\EventBusConfig; /** * Dispatches the given `$event`, triggering all associated event listeners. diff --git a/packages/event-bus/tests/EventBusTest.php b/packages/event-bus/tests/EventBusTest.php index 0918b2fa2..f667779a9 100644 --- a/packages/event-bus/tests/EventBusTest.php +++ b/packages/event-bus/tests/EventBusTest.php @@ -91,14 +91,14 @@ public function test_middleware_is_only_triggered_once_per_event_dispatch(): voi public function test_closure_based_handlers(): void { $container = new GenericContainer(); - $container->singleton(MyService::class, static fn () => new MyService('bar')); + $container->singleton(MyService::class, fn () => new MyService('bar')); $called = null; $config = new EventBusConfig( handlers: [ ItHappened::class => [ - new CallableEventHandler(ItHappened::class, static function (ItHappened $event, MyService $service) use (&$called): void { + new CallableEventHandler(ItHappened::class, function (ItHappened $event, MyService $service) use (&$called): void { $called = $service->value; }), ], @@ -125,7 +125,7 @@ public function test_closure_based_handlers_using_listen_method(): void $eventBus = new GenericEventBus($container, $config); $hasHappened = false; - $eventBus->listen(static function (string $event) use (&$hasHappened): void { + $eventBus->listen(function (string $event) use (&$hasHappened): void { $hasHappened = true; }, event: 'my-event'); @@ -141,7 +141,7 @@ public function test_closure_based_handlers_using_listen_method_and_first_parame $eventBus = new GenericEventBus($container, $config); $hasHappened = false; - $eventBus->listen(static function (ItHappened $event) use (&$hasHappened): void { + $eventBus->listen(function (ItHappened $event) use (&$hasHappened): void { $hasHappened = true; }); @@ -159,7 +159,7 @@ public function test_closure_based_handlers_using_function(): void $hasHappened = false; - listen(static function (string $event) use (&$hasHappened): void { + listen(function (string $event) use (&$hasHappened): void { $hasHappened = true; }, event: 'my-event'); @@ -199,7 +199,7 @@ public function test_closure_based_handlers_using_listen_method_and_enums(): voi $eventBus = new GenericEventBus($container, $config); $hasHappened = false; - $eventBus->listen(static function () use (&$hasHappened): void { + $eventBus->listen(function () use (&$hasHappened): void { $hasHappened = true; }, EventEnum::TWO); diff --git a/packages/generation/src/Php/ManipulatesPhpClasses.php b/packages/generation/src/Php/ManipulatesPhpClasses.php index fb9e1221f..c4eeea3e8 100644 --- a/packages/generation/src/Php/ManipulatesPhpClasses.php +++ b/packages/generation/src/Php/ManipulatesPhpClasses.php @@ -89,11 +89,9 @@ public function removeClassAttribute(string $attributeName): self $attributes = $this->classType->getAttributes(); foreach ($attributes as $key => $attribute) { - if ($attribute->getName() !== $attributeName) { - continue; + if ($attribute->getName() === $attributeName) { + unset($attributes[$key]); } - - unset($attributes[$key]); } $this->classType->setAttributes($attributes); diff --git a/packages/generation/src/Php/SimplifiesClassNames.php b/packages/generation/src/Php/SimplifiesClassNames.php index bc7a53756..20aff5779 100644 --- a/packages/generation/src/Php/SimplifiesClassNames.php +++ b/packages/generation/src/Php/SimplifiesClassNames.php @@ -118,7 +118,7 @@ private function simplifyClassNames(PhpFile $file): PhpFile } array_map( - static function ($param) use (&$types): void { + function ($param) use (&$types): void { $types[] = $param->getType(true); }, $class->getProperties(), @@ -136,11 +136,9 @@ static function ($param) use (&$types): void { } foreach ($type->getTypes() as $subtype) { - if (! ($subtype->isClass() && ! $subtype->isClassKeyword())) { - continue; + if ($subtype->isClass() && ! $subtype->isClassKeyword()) { + $namespace->addUse((string) $subtype); } - - $namespace->addUse((string) $subtype); } } } @@ -154,7 +152,7 @@ private function extractFqcnFromBody(string $body): array preg_match_all('/(?:\\\\?[A-Za-z_][\w\d_]*\\\\)+[A-Za-z_][\w\d_]*/', $body, $matches); return array_filter(array_unique( - array_map(static fn (string $fqcn) => rtrim(ltrim($fqcn, '\\'), ':'), $matches[0]), + array_map(fn (string $fqcn) => rtrim(ltrim($fqcn, '\\'), ':'), $matches[0]), )); } } diff --git a/packages/generation/src/Php/StubFileGenerator.php b/packages/generation/src/Php/StubFileGenerator.php index 991753cf3..61a7e0fee 100644 --- a/packages/generation/src/Php/StubFileGenerator.php +++ b/packages/generation/src/Php/StubFileGenerator.php @@ -8,6 +8,7 @@ use Tempest\Generation\Php\DataObjects\StubFile; use Tempest\Generation\Php\Exceptions\FileGenerationFailedException; use Tempest\Generation\Php\Exceptions\FileGenerationWasAborted; +use Tempest\Generation\Php\StubFileType; use Tempest\Support\Filesystem; use Tempest\Support\Str\ImmutableString; use Throwable; @@ -65,13 +66,13 @@ public function generateClassFile( continue; } - $classManipulator->manipulate(static fn (ImmutableString $code) => $code->replace($placeholder, $replacement)); + $classManipulator->manipulate(fn (ImmutableString $code) => $code->replace($placeholder, $replacement)); } // Run all manipulations $classManipulator = array_reduce( array: $manipulations, - callback: static fn (ClassManipulator $manipulator, Closure $manipulation) => $manipulation($manipulator), + callback: fn (ClassManipulator $manipulator, Closure $manipulation) => $manipulation($manipulator), initial: $classManipulator, ); @@ -129,7 +130,7 @@ public function generateRawFile( $fileContent = array_reduce( array: $manipulations, initial: $fileContent, - callback: static fn (ImmutableString $content, Closure $manipulation) => $manipulation($content), + callback: fn (ImmutableString $content, Closure $manipulation) => $manipulation($content), ); if (Filesystem\is_file($targetPath) && $shouldOverride) { diff --git a/packages/generation/src/TypeScript/TypeResolverDiscovery.php b/packages/generation/src/TypeScript/TypeResolverDiscovery.php index eba7c518a..1761028c4 100644 --- a/packages/generation/src/TypeScript/TypeResolverDiscovery.php +++ b/packages/generation/src/TypeScript/TypeResolverDiscovery.php @@ -33,8 +33,8 @@ public function discover(DiscoveryLocation $location, ClassReflector $class): vo public function apply(): void { $this->config->resolvers = arr([...$this->discoveryItems]) - ->sortByCallback(static fn (array $a, array $b) => $a[1] <=> $b[1]) - ->map(static fn (array $item) => $item[0]) + ->sortByCallback(fn (array $a, array $b) => $a[1] <=> $b[1]) + ->map(fn (array $item) => $item[0]) ->toArray(); } } diff --git a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php index a9bf98614..647d0cbf8 100644 --- a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php +++ b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php @@ -88,26 +88,24 @@ private function collectImports(array $namespaces, TypeScriptOutput $output): ar foreach ($namespaces as $namespace => $definitions) { foreach ($definitions as $definition) { - if (! $definition instanceof InterfaceDefinition) { - continue; - } - - foreach ($definition->properties as $property) { - if ($property->fqcn === null) { - continue; - } + if ($definition instanceof InterfaceDefinition) { + foreach ($definition->properties as $property) { + if ($property->fqcn === null) { + continue; + } - $targetNamespace = Str\before_last($property->fqcn, '\\'); + $targetNamespace = Str\before_last($property->fqcn, '\\'); - if (in_array($targetNamespace, $currentNamespaces, strict: true)) { - continue; - } + if (in_array($targetNamespace, $currentNamespaces, strict: true)) { + continue; + } - $typeName = Str\after_last($property->fqcn, '\\'); - $importPath = $this->computeImportPath($namespace, $targetNamespace); - $importKey = "{$importPath}::{$typeName}"; + $typeName = Str\after_last($property->fqcn, '\\'); + $importPath = $this->computeImportPath($namespace, $targetNamespace); + $importKey = "{$importPath}::{$typeName}"; - $imports[$importKey] ??= "import type { {$typeName} } from '{$importPath}';"; + $imports[$importKey] ??= "import type { {$typeName} } from '{$importPath}';"; + } } } } @@ -155,7 +153,7 @@ private function resolveTypeReference(PropertyDefinition $property): string private function namespaceToFilePath(string $namespace): string { $parts = explode('\\', $namespace); - $kebabParts = Arr\map($parts, static fn (string $part) => Str\to_kebab_case($part)); + $kebabParts = Arr\map($parts, fn (string $part) => Str\to_kebab_case($part)); $path = (string) Arr\implode($kebabParts, glue: '/'); return $this->config->directory . '/' . $path . '/index.ts'; @@ -179,7 +177,7 @@ private function computeImportPath(string $sourceNamespace, string $targetNamesp $upLevels = count($sourceParts) - $commonLength; $targetDiff = array_slice($targetParts, $commonLength); - $targetKebab = Arr\map($targetDiff, static fn (string $part) => Str\to_kebab_case($part)); + $targetKebab = Arr\map($targetDiff, fn (string $part) => Str\to_kebab_case($part)); if ($upLevels === 0 && count($targetKebab) === 0) { return './'; @@ -188,6 +186,8 @@ private function computeImportPath(string $sourceNamespace, string $targetNamesp $upPath = $upLevels > 0 ? str_repeat('../', $upLevels) : './'; $downPath = count($targetKebab) > 0 ? (string) Arr\implode($targetKebab, glue: '/') : ''; - return rtrim($upPath . $downPath, '/'); + $fullPath = rtrim($upPath . $downPath, '/'); + + return $fullPath; } } diff --git a/packages/generation/tests/Php/ClassManipulatorTest.php b/packages/generation/tests/Php/ClassManipulatorTest.php index 042d05cce..3c918215a 100644 --- a/packages/generation/tests/Php/ClassManipulatorTest.php +++ b/packages/generation/tests/Php/ClassManipulatorTest.php @@ -165,7 +165,7 @@ public function manipulates_classes(): void $class = new ClassManipulator(WelcomeController::class); $class->setNamespace('App\\Controllers'); $class->setClassName('WelcomeController'); - $class->manipulate(static fn (ImmutableString $string) => $string->replace('welcome', 'home')); + $class->manipulate(fn (ImmutableString $string) => $string->replace('welcome', 'home')); $this->assertMatchesSnapshot($class->print()); } @@ -190,7 +190,7 @@ public function simplifies_method_parameter_attributes(): void public function make_replacements_before_converting_fqcn(): void { $class = new ClassManipulator(ClassWithDummyStringToBeReplacedByFqcn::class); - $class->manipulate(static fn (ImmutableString $string) => $string->replace("'fqcn-to-be-replaced'", sprintf('%s::class', DummyFqcn::class))); + $class->manipulate(fn (ImmutableString $string) => $string->replace("'fqcn-to-be-replaced'", sprintf('%s::class', DummyFqcn::class))); $this->assertMatchesSnapshot($class->print()); } diff --git a/packages/http/src/Input/StdinInputStream.php b/packages/http/src/Input/StdinInputStream.php index 64a0b1585..5a5a2871f 100644 --- a/packages/http/src/Input/StdinInputStream.php +++ b/packages/http/src/Input/StdinInputStream.php @@ -20,7 +20,7 @@ public function parse(): array $inputStreamData = str($input) ->explode('&') - ->mapWithKeys(static function (string $item) { + ->mapWithKeys(function (string $item) { $parts = explode('=', $item, 2); $key = urldecode($parts[0]); diff --git a/packages/http/src/IsResponse.php b/packages/http/src/IsResponse.php index 3c7c82108..0eda90fb7 100644 --- a/packages/http/src/IsResponse.php +++ b/packages/http/src/IsResponse.php @@ -38,7 +38,7 @@ public function getHeader(string $name): ?Header { return array_find( array: $this->headers, - callback: static fn (Header $header) => strcasecmp($header->name, $name) === 0, + callback: fn (Header $header) => strcasecmp($header->name, $name) === 0, ); } diff --git a/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php b/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php index 42d004189..0dd427855 100644 --- a/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php +++ b/packages/http/src/Mappers/PsrRequestToGenericRequestMapper.php @@ -43,14 +43,14 @@ public function map(mixed $from, mixed $to): GenericRequest } $headersAsString = array_map( - static fn (array $items) => implode(',', $items), + fn (array $items) => implode(',', $items), $from->getHeaders(), ); parse_str($from->getUri()->getQuery(), $query); $uploads = array_map( - static fn (UploadedFileInterface $uploadedFile) => new Upload($uploadedFile), + fn (UploadedFileInterface $uploadedFile) => new Upload($uploadedFile), $from->getUploadedFiles(), ); diff --git a/packages/http/src/Mappers/RequestToObjectMapper.php b/packages/http/src/Mappers/RequestToObjectMapper.php index ddd6c9712..e79e482bb 100644 --- a/packages/http/src/Mappers/RequestToObjectMapper.php +++ b/packages/http/src/Mappers/RequestToObjectMapper.php @@ -33,8 +33,8 @@ public function map(mixed $from, mixed $to): array|object if (is_a($to, Request::class, true)) { $invalidReservedProperties = arr(new ClassReflector(Request::class)->getProperties()) - ->map(static fn (PropertyReflector $property) => $property->getName()) - ->filter(static fn (string $property) => array_key_exists($property, $data)); + ->map(fn (PropertyReflector $property) => $property->getName()) + ->filter(fn (string $property) => array_key_exists($property, $data)); if ($invalidReservedProperties->isNotEmpty()) { throw new RequestParametersIncludedReservedNames($to, $invalidReservedProperties); diff --git a/packages/http/src/RequestHeaders.php b/packages/http/src/RequestHeaders.php index a0ee7da05..9221155fb 100644 --- a/packages/http/src/RequestHeaders.php +++ b/packages/http/src/RequestHeaders.php @@ -20,7 +20,7 @@ public static function normalizeFromArray(array $headers): self { return new self(array_combine( array_map(strtolower(...), array_keys($headers)), - array_values(array_map(static fn (mixed $value) => Str\parse($value), $headers)), + array_values(array_map(fn (mixed $value) => Str\parse($value), $headers)), )); } @@ -45,7 +45,7 @@ public function get(string $name, ?string $default = null): ?string { $header = array_find( array: $this->headers, - callback: static fn (mixed $_, string $header) => strcasecmp($header, $name) === 0, + callback: fn (mixed $_, string $header) => strcasecmp($header, $name) === 0, ); return $header ?? $default; diff --git a/packages/http/src/Session/SessionIdResolverInitializer.php b/packages/http/src/Session/SessionIdResolverInitializer.php index 72c9cc2de..1fb27a9b2 100644 --- a/packages/http/src/Session/SessionIdResolverInitializer.php +++ b/packages/http/src/Session/SessionIdResolverInitializer.php @@ -11,6 +11,7 @@ use Tempest\Http\Cookie\CookieManager; use Tempest\Http\Request; use Tempest\Http\Session\Resolvers\CookieSessionIdResolver; +use Tempest\Http\Session\SessionConfig; final readonly class SessionIdResolverInitializer implements Initializer { diff --git a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php index 2b9bcb890..0d94bb81e 100644 --- a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php +++ b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php @@ -145,6 +145,8 @@ private function createServerRequest(string $method, array $body = []): ServerRe } $stream = new Stream('php://temp', 'r+'); - return $request->withBody($stream); + $request = $request->withBody($stream); + + return $request; } } diff --git a/packages/idempotency/tests/IdempotencyMiddlewareTest.php b/packages/idempotency/tests/IdempotencyMiddlewareTest.php index 89ab200a0..1abdaf995 100644 --- a/packages/idempotency/tests/IdempotencyMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotencyMiddlewareTest.php @@ -69,7 +69,7 @@ public function requires_an_idempotency_key_by_default(): void $response = $middleware( new GenericRequest(Method::POST, '/orders', body: ['amount' => 100]), - new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['ok' => true]); @@ -93,7 +93,7 @@ public function replays_the_original_response_for_the_same_key_and_payload(): vo headers: ['Idempotency-Key' => 'order-100'], ); - $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -115,7 +115,7 @@ public function rejects_the_same_key_when_the_payload_changes(): void $middleware = $this->createMiddleware('create'); $calls = 0; - $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -176,7 +176,7 @@ public function scopes_idempotency_keys_per_route_when_a_handler_has_multiple_ro ); $calls = 0; - $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-' . $calls]); @@ -238,7 +238,7 @@ public function isolates_idempotency_keys_per_scope_resolver_identity(): void ); $calls = 0; - $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-' . $calls]); @@ -269,7 +269,7 @@ public function can_skip_key_requirement_for_specific_routes(): void $response = $middleware( new GenericRequest(Method::POST, '/drafts', body: ['draft' => true]), - new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['ok' => true]); @@ -375,7 +375,7 @@ public function replays_a_non_serializable_body_as_fallback_text_instead_of_null headers: ['Idempotency-Key' => 'non-serializable-body'], ); - $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse( @@ -408,7 +408,7 @@ public function replays_a_json_serializable_body(): void headers: ['Idempotency-Key' => 'json-serializable-body'], ); - $next = new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + $next = new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, new SerializableBody('order-1')); @@ -454,14 +454,14 @@ public function takes_over_a_pending_record_owned_by_a_dead_process(): void key: 'stale-order', fingerprint: new RequestFingerprintGenerator()->generate($request), ttlInSeconds: 120, - pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99_999_999, 'stale-owner'), + pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99999999, 'stale-owner'), pendingHeartbeatAt: time(), ); $calls = 0; $response = $middleware( $request, - new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -510,7 +510,7 @@ public function takes_over_a_pending_record_owned_by_another_host_when_the_heart $calls = 0; $response = $middleware( $request, - new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); @@ -559,7 +559,7 @@ public function does_not_take_over_a_pending_record_owned_by_another_host_when_t $calls = 0; $response = $middleware( $request, - new HttpMiddlewareCallable(static function (Request $_) use (&$calls): Response { + new HttpMiddlewareCallable(function (Request $_) use (&$calls): Response { $calls++; return new GenericResponse(Status::CREATED, ['id' => 'order-1']); diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index 1eadacc79..e0bf1d171 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -42,7 +42,7 @@ public function ignores_commands_without_idempotent_attribute(): void $calls = 0; $command = new CreateDraftCommand('A'); - $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }); @@ -67,7 +67,7 @@ public function supports_idempotent_attribute_on_handler_method(): void $calls = 0; $command = new SyncInventoryCommand(warehouse: 'east', sku: 'WIDGET-1'); - $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }); @@ -84,7 +84,7 @@ public function executes_an_idempotent_command_only_once_for_equal_payloads(): v $calls = 0; $command = new ImportInvoicesCommand(tenant: 'acme', month: '2026-01'); - $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }); @@ -100,7 +100,7 @@ public function throws_when_the_same_explicit_key_is_used_for_different_payloads $middleware = $this->createMiddleware(); $calls = 0; - $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }); @@ -118,7 +118,7 @@ public function allows_replay_for_same_explicit_key_and_same_payload(): void $calls = 0; $command = new CreatePayoutCommand('payout-1', 100); - $next = new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + $next = new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }); @@ -181,14 +181,14 @@ public function takes_over_a_pending_record_owned_by_a_dead_process(): void key: $fingerprint, fingerprint: $fingerprint, ttlInSeconds: 120, - pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99_999_999, 'stale-owner'), + pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99999999, 'stale-owner'), pendingHeartbeatAt: time(), ); $calls = 0; $middleware( $command, - new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }), ); @@ -229,7 +229,7 @@ public function takes_over_a_pending_record_owned_by_another_host_when_the_heart $calls = 0; $middleware( $command, - new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }), ); @@ -270,7 +270,7 @@ public function does_not_take_over_a_pending_record_owned_by_another_host_when_t $calls = 0; $middleware( $command, - new CommandBusMiddlewareCallable(static function (object $_) use (&$calls): void { + new CommandBusMiddlewareCallable(function (object $_) use (&$calls): void { $calls++; }), ); diff --git a/packages/intl/src/GenericTranslator.php b/packages/intl/src/GenericTranslator.php index 76a8f25c5..338f5eb85 100644 --- a/packages/intl/src/GenericTranslator.php +++ b/packages/intl/src/GenericTranslator.php @@ -4,6 +4,8 @@ use Tempest\EventBus\EventBus; use Tempest\Intl\Catalog\Catalog; +use Tempest\Intl\IntlConfig; +use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; final readonly class GenericTranslator implements Translator diff --git a/packages/intl/src/IntlConfig.php b/packages/intl/src/IntlConfig.php index d7e4ad2e9..2d141be77 100644 --- a/packages/intl/src/IntlConfig.php +++ b/packages/intl/src/IntlConfig.php @@ -2,6 +2,7 @@ namespace Tempest\Intl; +use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\FormattingFunction; use Tempest\Intl\MessageFormat\MarkupFormatter; use Tempest\Intl\MessageFormat\SelectorFunction; diff --git a/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php b/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php index f42f2abc0..c0acb0f83 100644 --- a/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php +++ b/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php @@ -375,8 +375,8 @@ private function getMarkupFormatter(?string $tag): ?MarkupFormatter } return arr($this->markupFormatters) - ->filter(static fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof MarkupFormatter) - ->first(static fn (MarkupFormatter $fn) => $fn->supportsTag($tag)); + ->filter(fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof MarkupFormatter) + ->first(fn (MarkupFormatter $fn) => $fn->supportsTag($tag)); } private function getStandaloneMarkupFormatter(?string $tag): ?StandaloneMarkupFormatter @@ -386,8 +386,8 @@ private function getStandaloneMarkupFormatter(?string $tag): ?StandaloneMarkupFo } return arr($this->markupFormatters) - ->filter(static fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof StandaloneMarkupFormatter) - ->first(static fn (StandaloneMarkupFormatter $fn) => $fn->supportsTag($tag)); + ->filter(fn (MarkupFormatter|StandaloneMarkupFormatter $fn) => $fn instanceof StandaloneMarkupFormatter) + ->first(fn (StandaloneMarkupFormatter $fn) => $fn->supportsTag($tag)); } private function getSelectorFunction(?string $name): ?SelectorFunction @@ -397,8 +397,8 @@ private function getSelectorFunction(?string $name): ?SelectorFunction } return arr($this->functions) - ->filter(static fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof SelectorFunction) - ->first(static fn (SelectorFunction $fn) => $fn->name === $name); + ->filter(fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof SelectorFunction) + ->first(fn (SelectorFunction $fn) => $fn->name === $name); } private function getFormattingFunction(?string $name): ?FormattingFunction @@ -408,7 +408,7 @@ private function getFormattingFunction(?string $name): ?FormattingFunction } return arr($this->functions) - ->filter(static fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof FormattingFunction) - ->first(static fn (FormattingFunction $fn) => $fn->name === $name); + ->filter(fn (FormattingFunction|SelectorFunction $fn) => $fn instanceof FormattingFunction) + ->first(fn (FormattingFunction $fn) => $fn->name === $name); } } diff --git a/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php b/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php index 6f6ee0ef9..95f288065 100644 --- a/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php +++ b/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php @@ -129,7 +129,7 @@ private function parseInputDeclaration(): InputDeclaration $optional = (bool) array_find( array: $expression->function->options ?? [], - callback: static fn (Option $option) => $option->identifier->name === 'default', + callback: fn (Option $option) => $option->identifier->name === 'default', ); return new InputDeclaration($expression, $optional); diff --git a/packages/intl/src/PluralRules/PluralRulesMatcher.php b/packages/intl/src/PluralRules/PluralRulesMatcher.php index 3ed30faa4..eb89ced57 100644 --- a/packages/intl/src/PluralRules/PluralRulesMatcher.php +++ b/packages/intl/src/PluralRules/PluralRulesMatcher.php @@ -57,7 +57,7 @@ private static function getCompactExponent(float|int $n): int $abs = abs($n); - if ($abs >= 1_000_000) { + if ($abs >= 1000000) { return 6; } @@ -518,7 +518,7 @@ private static function getPluralCategoryBr(float|int $n): string return 'few'; } - if (! self::isEqual($n, 0) && self::isEqual($n % 1_000_000, 0)) { + if (! self::isEqual($n, 0) && self::isEqual($n % 1000000, 0)) { return 'many'; } @@ -580,7 +580,7 @@ private static function getPluralCategoryCa(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -980,7 +980,7 @@ private static function getPluralCategoryEs(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -1132,7 +1132,7 @@ private static function getPluralCategoryFr(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -1639,7 +1639,7 @@ private static function getPluralCategoryIt(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -2098,8 +2098,8 @@ private static function getPluralCategoryKw(float|int $n): string || self::isEqual($n % 100, 62) || self::isEqual($n % 100, 82) || self::isEqual($n % 1000, 0) - && (self::inRange($n % 100_000, 1000, 20_000) || self::isEqual($n % 100_000, 40_000) || self::isEqual($n % 100_000, 60_000) || self::isEqual($n % 100_000, 80_000)) - || self::isEqual($n % 1_000_000, 100_000) + && (self::inRange($n % 100000, 1000, 20000) || self::isEqual($n % 100000, 40000) || self::isEqual($n % 100000, 60000) || self::isEqual($n % 100000, 80000)) + || self::isEqual($n % 1000000, 100000) ) { return 'two'; } @@ -2238,7 +2238,7 @@ private static function getPluralCategoryLld(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -2998,7 +2998,7 @@ private static function getPluralCategoryPt(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -3020,7 +3020,7 @@ private static function getPluralCategoryPt_PT(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -3216,7 +3216,7 @@ private static function getPluralCategoryScn(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -4150,7 +4150,7 @@ private static function getPluralCategoryVec(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } diff --git a/packages/intl/src/TranslationFailure.php b/packages/intl/src/TranslationFailure.php index b7b8b570f..810e7a8cc 100644 --- a/packages/intl/src/TranslationFailure.php +++ b/packages/intl/src/TranslationFailure.php @@ -2,6 +2,8 @@ namespace Tempest\Intl; +use Tempest\Intl\Locale; + final readonly class TranslationFailure { public function __construct( diff --git a/packages/intl/src/TranslationMessageDiscovery.php b/packages/intl/src/TranslationMessageDiscovery.php index e3ef0af76..9f3a88466 100644 --- a/packages/intl/src/TranslationMessageDiscovery.php +++ b/packages/intl/src/TranslationMessageDiscovery.php @@ -8,6 +8,7 @@ use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; +use Tempest\Intl\Locale; use Tempest\Reflection\ClassReflector; use function Tempest\Support\arr; @@ -54,7 +55,7 @@ public function apply(): void private function isLocale(string $candidate): bool { $locale = arr(Locale::cases()) - ->first(static function (Locale $locale) use ($candidate) { + ->first(function (Locale $locale) use ($candidate) { if (strtolower($locale->value) === strtolower($candidate)) { return true; } diff --git a/packages/intl/src/TranslationMiss.php b/packages/intl/src/TranslationMiss.php index fe86fead2..394a1647d 100644 --- a/packages/intl/src/TranslationMiss.php +++ b/packages/intl/src/TranslationMiss.php @@ -2,6 +2,8 @@ namespace Tempest\Intl; +use Tempest\Intl\Locale; + final readonly class TranslationMiss { public function __construct( diff --git a/packages/intl/src/Translator.php b/packages/intl/src/Translator.php index e4e25c316..def5ead83 100644 --- a/packages/intl/src/Translator.php +++ b/packages/intl/src/Translator.php @@ -2,6 +2,8 @@ namespace Tempest\Intl; +use Tempest\Intl\Locale; + interface Translator { /** diff --git a/packages/intl/src/TranslatorInitializer.php b/packages/intl/src/TranslatorInitializer.php index 4f1a1cbbe..477b7a77d 100644 --- a/packages/intl/src/TranslatorInitializer.php +++ b/packages/intl/src/TranslatorInitializer.php @@ -7,6 +7,7 @@ use Tempest\Container\Singleton; use Tempest\EventBus\EventBus; use Tempest\Intl\Catalog\Catalog; +use Tempest\Intl\IntlConfig; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; final class TranslatorInitializer implements Initializer diff --git a/packages/intl/src/functions.php b/packages/intl/src/functions.php index ac45bd815..768d7ce0d 100644 --- a/packages/intl/src/functions.php +++ b/packages/intl/src/functions.php @@ -5,7 +5,9 @@ use Countable; use Stringable; use Tempest\Container\GenericContainer; +use Tempest\Intl\Locale; use Tempest\Intl\Pluralizer\Pluralizer; +use Tempest\Intl\Translator; use function Tempest\Container\get; diff --git a/packages/intl/tests/FunctionsTest.php b/packages/intl/tests/FunctionsTest.php index 1bce00620..3d3c1914d 100644 --- a/packages/intl/tests/FunctionsTest.php +++ b/packages/intl/tests/FunctionsTest.php @@ -21,12 +21,12 @@ public function test_format_number(): void $this->assertSame('10', Number\format(10)); $this->assertSame('25', Number\format(25)); $this->assertSame('100', Number\format(100)); - $this->assertSame('100,000', Number\format(100_000)); - $this->assertSame('100,000.00', Number\format(100_000, precision: 2)); - $this->assertSame('100,000.12', Number\format(100_000.123, precision: 2)); - $this->assertSame('100,000.123', Number\format(100_000.123_4, maxPrecision: 3)); - $this->assertSame('100,000.124', Number\format(100_000.123_6, maxPrecision: 3)); - $this->assertSame('123,456,789', Number\format(123_456_789)); + $this->assertSame('100,000', Number\format(100000)); + $this->assertSame('100,000.00', Number\format(100000, precision: 2)); + $this->assertSame('100,000.12', Number\format(100000.123, precision: 2)); + $this->assertSame('100,000.123', Number\format(100000.1234, maxPrecision: 3)); + $this->assertSame('100,000.124', Number\format(100000.1236, maxPrecision: 3)); + $this->assertSame('123,456,789', Number\format(123456789)); $this->assertSame('-1', Number\format(-1)); $this->assertSame('-10', Number\format(-10)); @@ -77,8 +77,8 @@ public function test_spellout_with_threshold(): void $this->assertSame('10', Number\spell_out(10, until: 10)); $this->assertSame('11', Number\spell_out(11, until: 10)); - $this->assertSame('ten thousand', Number\spell_out(10_000, until: 50_000)); - $this->assertSame('100,000', Number\spell_out(100_000, until: 50_000)); + $this->assertSame('ten thousand', Number\spell_out(10000, until: 50000)); + $this->assertSame('100,000', Number\spell_out(100000, until: 50000)); } #[RequiresPhpExtension('intl')] @@ -114,10 +114,10 @@ public function test_to_percent(): void $this->assertSame('2%', Number\to_percentage(1.75)); $this->assertSame('1.75%', Number\to_percentage(1.75, precision: 2)); $this->assertSame('1.750%', Number\to_percentage(1.75, precision: 3)); - $this->assertSame('0%', Number\to_percentage(0.123_45)); + $this->assertSame('0%', Number\to_percentage(0.12345)); $this->assertSame('0.00%', Number\to_percentage(0, precision: 2)); - $this->assertSame('0.12%', Number\to_percentage(0.123_45, precision: 2)); - $this->assertSame('0.1235%', Number\to_percentage(0.123_45, precision: 4)); + $this->assertSame('0.12%', Number\to_percentage(0.12345, precision: 2)); + $this->assertSame('0.1235%', Number\to_percentage(0.12345, precision: 4)); } #[RequiresPhpExtension('intl')] @@ -147,8 +147,8 @@ public function test_to_currency_with_different_locale(): void $this->assertSame('1,00 $', Number\currency(1, Currency::USD, Locale::GERMAN)); $this->assertSame('1,00 £', Number\currency(1, Currency::GBP, Locale::GERMAN)); - $this->assertSame('123.456.789,12 $', Number\currency(123_456_789.123_45, Currency::USD, Locale::GERMAN)); - $this->assertSame('123.456.789,12 €', Number\currency(123_456_789.123_45, Currency::EUR, Locale::GERMAN)); + $this->assertSame('123.456.789,12 $', Number\currency(123456789.12345, Currency::USD, Locale::GERMAN)); + $this->assertSame('123.456.789,12 €', Number\currency(123456789.12345, Currency::EUR, Locale::GERMAN)); $this->assertSame('1 234,56 $US', Number\currency(1234.56, Currency::USD, Locale::FRENCH)); } @@ -180,7 +180,7 @@ public function test_bytes_to_human(): void $this->assertSame('2 KiB', Number\to_file_size(2048, useBinaryPrefix: true)); $this->assertSame('2.00 KiB', Number\to_file_size(2048, precision: 2, useBinaryPrefix: true)); $this->assertSame('1.23 KiB', Number\to_file_size(1264, precision: 2, useBinaryPrefix: true)); - $this->assertSame('1.234 KiB', Number\to_file_size(1_264.123_45, maxPrecision: 3, useBinaryPrefix: true)); + $this->assertSame('1.234 KiB', Number\to_file_size(1264.12345, maxPrecision: 3, useBinaryPrefix: true)); $this->assertSame('1.234 KiB', Number\to_file_size(1264, 3, useBinaryPrefix: true)); $this->assertSame('5 GiB', Number\to_file_size(1024 * 1024 * 1024 * 5, useBinaryPrefix: true)); $this->assertSame('10 TiB', Number\to_file_size((1024 ** 4) * 10, useBinaryPrefix: true)); @@ -204,31 +204,31 @@ public function test_summarize(): void $this->assertSame('1K', Number\to_human_readable(1000, maxPrecision: 2)); $this->assertSame('1K', Number\to_human_readable(1230)); $this->assertSame('1.2K', Number\to_human_readable(1230, maxPrecision: 1)); - $this->assertSame('1M', Number\to_human_readable(1_000_000)); - $this->assertSame('1B', Number\to_human_readable(1_000_000_000)); - $this->assertSame('1T', Number\to_human_readable(1_000_000_000_000)); - $this->assertSame('1Q', Number\to_human_readable(1_000_000_000_000_000)); - $this->assertSame('1KQ', Number\to_human_readable(1_000_000_000_000_000_000)); + $this->assertSame('1M', Number\to_human_readable(1000000)); + $this->assertSame('1B', Number\to_human_readable(1000000000)); + $this->assertSame('1T', Number\to_human_readable(1000000000000)); + $this->assertSame('1Q', Number\to_human_readable(1000000000000000)); + $this->assertSame('1KQ', Number\to_human_readable(1000000000000000000)); $this->assertSame('123', Number\to_human_readable(123)); $this->assertSame('1K', Number\to_human_readable(1234)); $this->assertSame('1.23K', Number\to_human_readable(1234, precision: 2)); - $this->assertSame('12K', Number\to_human_readable(12_345)); - $this->assertSame('1M', Number\to_human_readable(1_234_567)); - $this->assertSame('1B', Number\to_human_readable(1_234_567_890)); - $this->assertSame('1T', Number\to_human_readable(1_234_567_890_123)); - $this->assertSame('1.23T', Number\to_human_readable(1_234_567_890_123, precision: 2)); - $this->assertSame('1Q', Number\to_human_readable(1_234_567_890_123_456)); - $this->assertSame('1.23KQ', Number\to_human_readable(1_234_567_890_123_456_789, precision: 2)); - $this->assertSame('490K', Number\to_human_readable(489_939)); - $this->assertSame('489.9390K', Number\to_human_readable(489_939, precision: 4)); - $this->assertSame('500.00000M', Number\to_human_readable(500_000_000, precision: 5)); - - $this->assertSame('1MQ', Number\to_human_readable(1_000_000_000_000_000_000_000)); - $this->assertSame('1BQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000)); - $this->assertSame('1TQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000)); - $this->assertSame('1QQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000_000)); - $this->assertSame('1KQQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000_000_000)); + $this->assertSame('12K', Number\to_human_readable(12345)); + $this->assertSame('1M', Number\to_human_readable(1234567)); + $this->assertSame('1B', Number\to_human_readable(1234567890)); + $this->assertSame('1T', Number\to_human_readable(1234567890123)); + $this->assertSame('1.23T', Number\to_human_readable(1234567890123, precision: 2)); + $this->assertSame('1Q', Number\to_human_readable(1234567890123456)); + $this->assertSame('1.23KQ', Number\to_human_readable(1234567890123456789, precision: 2)); + $this->assertSame('490K', Number\to_human_readable(489939)); + $this->assertSame('489.9390K', Number\to_human_readable(489939, precision: 4)); + $this->assertSame('500.00000M', Number\to_human_readable(500000000, precision: 5)); + + $this->assertSame('1MQ', Number\to_human_readable(1000000000000000000000)); + $this->assertSame('1BQ', Number\to_human_readable(1000000000000000000000000)); + $this->assertSame('1TQ', Number\to_human_readable(1000000000000000000000000000)); + $this->assertSame('1QQ', Number\to_human_readable(1000000000000000000000000000000)); + $this->assertSame('1KQQ', Number\to_human_readable(1000000000000000000000000000000000)); $this->assertSame('0', Number\to_human_readable(0)); $this->assertSame('0', Number\to_human_readable(0.0)); @@ -241,12 +241,12 @@ public function test_summarize(): void $this->assertSame('-1K', Number\to_human_readable(-1000)); $this->assertSame('-1.23K', Number\to_human_readable(-1234, precision: 2)); $this->assertSame('-1.2K', Number\to_human_readable(-1234, maxPrecision: 1)); - $this->assertSame('-1M', Number\to_human_readable(-1_000_000)); - $this->assertSame('-1B', Number\to_human_readable(-1_000_000_000)); - $this->assertSame('-1T', Number\to_human_readable(-1_000_000_000_000)); - $this->assertSame('-1.1T', Number\to_human_readable(-1_100_000_000_000, maxPrecision: 1)); - $this->assertSame('-1Q', Number\to_human_readable(-1_000_000_000_000_000)); - $this->assertSame('-1KQ', Number\to_human_readable(-1_000_000_000_000_000_000)); + $this->assertSame('-1M', Number\to_human_readable(-1000000)); + $this->assertSame('-1B', Number\to_human_readable(-1000000000)); + $this->assertSame('-1T', Number\to_human_readable(-1000000000000)); + $this->assertSame('-1.1T', Number\to_human_readable(-1100000000000, maxPrecision: 1)); + $this->assertSame('-1Q', Number\to_human_readable(-1000000000000000)); + $this->assertSame('-1KQ', Number\to_human_readable(-1000000000000000000)); } public function test_parse_int(): void diff --git a/packages/intl/tests/LocaleTest.php b/packages/intl/tests/LocaleTest.php index cc9ae82d8..e914d8632 100644 --- a/packages/intl/tests/LocaleTest.php +++ b/packages/intl/tests/LocaleTest.php @@ -174,11 +174,9 @@ public function test_it_returns_the_language_and_human_readable_name(Locale $loc public static function getLocalesWithScript(): Generator { foreach (Locale::cases() as $locale) { - if (! $locale->hasScript()) { - continue; + if ($locale->hasScript()) { + yield $locale->value => [$locale]; } - - yield $locale->value => [$locale]; } return null; @@ -197,11 +195,9 @@ public function test_it_returns_the_script(Locale $locale): void public static function getLocalesWithoutScript(): Generator { foreach (Locale::cases() as $locale) { - if ($locale->hasScript()) { - continue; + if (! $locale->hasScript()) { + yield $locale->value => [$locale]; } - - yield $locale->value => [$locale]; } return null; @@ -220,11 +216,9 @@ public function test_it_does_not_returns_the_script(Locale $locale): void public static function getLocalesWithRegion(): Generator { foreach (Locale::cases() as $locale) { - if (! $locale->hasRegion()) { - continue; + if ($locale->hasRegion()) { + yield $locale->value => [$locale]; } - - yield $locale->value => [$locale]; } return null; @@ -244,11 +238,9 @@ public function test_it_returns_the_region(Locale $locale): void public static function getLocalesWithoutRegion(): Generator { foreach (Locale::cases() as $locale) { - if ($locale->hasRegion()) { - continue; + if (! $locale->hasRegion()) { + yield $locale->value => [$locale]; } - - yield $locale->value => [$locale]; } return null; diff --git a/packages/kv-store/src/Redis/Config/RedisConfig.php b/packages/kv-store/src/Redis/Config/RedisConfig.php index 8558ef4af..5356b67fe 100644 --- a/packages/kv-store/src/Redis/Config/RedisConfig.php +++ b/packages/kv-store/src/Redis/Config/RedisConfig.php @@ -18,7 +18,6 @@ public function __construct( /** * Password to the Redis instance. */ - #[\SensitiveParameter] public ?string $password = null, /** diff --git a/packages/kv-store/src/Redis/PhpRedisClient.php b/packages/kv-store/src/Redis/PhpRedisClient.php index f65fa2512..8002e1486 100644 --- a/packages/kv-store/src/Redis/PhpRedisClient.php +++ b/packages/kv-store/src/Redis/PhpRedisClient.php @@ -82,7 +82,7 @@ public function command(Stringable|string $command, Stringable|string ...$argume } $command = (string) $command; - $arguments = array_map(static fn (Stringable|string $argument) => (string) $argument, $arguments); + $arguments = array_map(fn (Stringable|string $argument) => (string) $argument, $arguments); $startedAt = DateTime::now(); $result = $this->client->rawcommand($command, ...$arguments); diff --git a/packages/kv-store/src/Redis/PredisClient.php b/packages/kv-store/src/Redis/PredisClient.php index 3b36b3064..d2f01d377 100644 --- a/packages/kv-store/src/Redis/PredisClient.php +++ b/packages/kv-store/src/Redis/PredisClient.php @@ -45,7 +45,7 @@ public function flush(): void public function command(Stringable|string $command, Stringable|string ...$arguments): mixed { $command = (string) $command; - $arguments = array_map(static fn (Stringable|string $argument) => (string) $argument, $arguments); + $arguments = array_map(fn (Stringable|string $argument) => (string) $argument, $arguments); $startedAt = DateTime::now(); $result = $this->client->executeRaw(array_merge([$command], $arguments)); diff --git a/packages/log/src/TailLogsCommand.php b/packages/log/src/TailLogsCommand.php index f0a6dea27..b4cd35543 100644 --- a/packages/log/src/TailLogsCommand.php +++ b/packages/log/src/TailLogsCommand.php @@ -11,6 +11,7 @@ use Tempest\Container\Tag; use Tempest\Highlight\Highlighter; use Tempest\Log\Channels\AppendLogChannel; +use Tempest\Log\LogConfig; use Tempest\Support\Filesystem; final readonly class TailLogsCommand @@ -28,12 +29,10 @@ public function __invoke(): void $appendLogChannel = null; foreach ($this->config->logChannels as $channel) { - if (! $channel instanceof AppendLogChannel) { - continue; + if ($channel instanceof AppendLogChannel) { + $appendLogChannel = $channel; + break; } - - $appendLogChannel = $channel; - break; } if ($appendLogChannel === null) { diff --git a/packages/mail/src/Attachment.php b/packages/mail/src/Attachment.php index 85a3c8389..b0a88f980 100644 --- a/packages/mail/src/Attachment.php +++ b/packages/mail/src/Attachment.php @@ -47,7 +47,7 @@ public static function fromStorage(Storage $storage, string $path, ?string $name $path = Path\normalize($path); return new self( - resolve: static fn () => $storage->readStream($path), + resolve: fn () => $storage->readStream($path), name: $name ?? basename($path), contentType: $contentType ?? $storage->mimeType($path), ); @@ -65,7 +65,7 @@ public static function fromFilesystem(string $path, ?string $name = null, ?strin } return new self( - resolve: static fn () => Filesystem\read_file($path), + resolve: fn () => Filesystem\read_file($path), name: $name ?? basename($path), contentType: $contentType ?? finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path), ); diff --git a/packages/mail/src/EmailToSymfonyEmailMapper.php b/packages/mail/src/EmailToSymfonyEmailMapper.php index 7bd89a3e1..d6f862b62 100644 --- a/packages/mail/src/EmailToSymfonyEmailMapper.php +++ b/packages/mail/src/EmailToSymfonyEmailMapper.php @@ -119,7 +119,7 @@ public function map(mixed $from, mixed $to): SymfonyEmail private function convertAddresses(null|string|array|EmailAddress $addresses): array { return arr($addresses) - ->map(static fn (string|EmailAddress|SymfonyAddress $address) => match (true) { + ->map(fn (string|EmailAddress|SymfonyAddress $address) => match (true) { $address instanceof SymfonyAddress => $address, $address instanceof EmailAddress => new SymfonyAddress($address->email, $address->name ?? ''), default => SymfonyAddress::create($address), diff --git a/packages/mail/src/MailerInitializer.php b/packages/mail/src/MailerInitializer.php index 3869579ac..3a5da65eb 100644 --- a/packages/mail/src/MailerInitializer.php +++ b/packages/mail/src/MailerInitializer.php @@ -6,6 +6,7 @@ use Tempest\Container\Initializer; use Tempest\Container\Singleton; use Tempest\EventBus\EventBus; +use Tempest\Mail\MailerConfig; final class MailerInitializer implements Initializer { diff --git a/packages/mail/src/Testing/MailTester.php b/packages/mail/src/Testing/MailTester.php index ab786b670..1d19951bc 100644 --- a/packages/mail/src/Testing/MailTester.php +++ b/packages/mail/src/Testing/MailTester.php @@ -45,7 +45,7 @@ public function assertSent(string $email, ?Closure $callback = null): self { $this->assertClassStringIsEmail($email); - $sentEmail = Arr\first($this->mailer->sent, filter: static fn (Email $sent) => $sent instanceof $email); + $sentEmail = Arr\first($this->mailer->sent, filter: fn (Email $sent) => $sent instanceof $email); Assert::assertTrue( condition: (bool) $sentEmail, @@ -78,7 +78,7 @@ public function assertNotSent(string $email): self $this->assertClassStringIsEmail($email); Assert::assertFalse( - condition: (bool) Arr\first($this->mailer->sent, filter: static fn (Email $sent) => $sent instanceof $email), + condition: (bool) Arr\first($this->mailer->sent, filter: fn (Email $sent) => $sent instanceof $email), message: sprintf('Email `%s` was unexpectedly sent.', $email), ); @@ -92,22 +92,22 @@ public function assertNotSent(string $email): self public array $from { get => Arr\map( array: $this->sentSymfonyEmail->getFrom(), - map: static fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), + map: fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), ); } public array $to { get => Arr\map( array: $this->sentSymfonyEmail->getTo(), - map: static fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), + map: fn (SymfonyAddress $address) => new EmailAddress($address->getAddress(), $address->getName()), ); } public array $attachments { get => Arr\map( array: $this->sentSymfonyEmail->getAttachments(), - map: static fn (DataPart $attachment) => new Attachment( - resolve: static fn () => $attachment->getBody(), + map: fn (DataPart $attachment) => new Attachment( + resolve: fn () => $attachment->getBody(), name: $attachment->getFilename(), contentType: $attachment->getMediaType() . '/' . $attachment->getMediaSubtype(), ), @@ -369,21 +369,19 @@ public function assertAttached(string $filename, ?Closure $callback = null): sel ); foreach ($attachments as $attachment) { - if ($attachment->getFilename() !== $filename) { - continue; - } + if ($attachment->getFilename() === $filename) { + if ($callback && $callback(new AttachmentTester($attachment)) === false) { + Assert::fail(sprintf('The assertion callback returned `false` for attachment `%s`.', $filename)); + } - if ($callback && $callback(new AttachmentTester($attachment)) === false) { - Assert::fail(sprintf('The assertion callback returned `false` for attachment `%s`.', $filename)); + return $this; } - - return $this; } Assert::fail(sprintf( 'Failed asserting that the email has an attachment named `%s`. Existing attachments: %s.', $filename, - Arr\join(Arr\map($attachments, static fn (DataPart $attachment) => $attachment->getName())), + Arr\join(Arr\map($attachments, fn (DataPart $attachment) => $attachment->getName())), )); } @@ -446,7 +444,7 @@ private function assertAddressListDoesNotContain(null|string|array|EmailAddress private function convertAddresses(null|string|array|EmailAddress $addresses): array { return arr($addresses) - ->map(static function (string|EmailAddress|SymfonyAddress $address) { + ->map(function (string|EmailAddress|SymfonyAddress $address) { return match (true) { $address instanceof SymfonyAddress => $address->getAddress(), $address instanceof EmailAddress => $address->email, diff --git a/packages/mail/src/Transports/RoundRobinMailerConfig.php b/packages/mail/src/Transports/RoundRobinMailerConfig.php index 5b41abfaa..59f4b78f4 100644 --- a/packages/mail/src/Transports/RoundRobinMailerConfig.php +++ b/packages/mail/src/Transports/RoundRobinMailerConfig.php @@ -42,6 +42,6 @@ public function createTransport(): TransportInterface /** @return TransportInterface[] */ private function buildTransports(): array { - return Arr\map($this->transports, static fn (MailerConfig $config) => $config->createTransport()); + return Arr\map($this->transports, fn (MailerConfig $config) => $config->createTransport()); } } diff --git a/packages/mail/src/Transports/Ses/SesMailerConfig.php b/packages/mail/src/Transports/Ses/SesMailerConfig.php index 879e790f2..f2f46a13f 100644 --- a/packages/mail/src/Transports/Ses/SesMailerConfig.php +++ b/packages/mail/src/Transports/Ses/SesMailerConfig.php @@ -47,7 +47,6 @@ public function __construct( /** * An optional Amazon SES session token. */ - #[\SensitiveParameter] public ?string $sessionToken = null, /** diff --git a/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php b/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php index 12b116b65..59352766b 100644 --- a/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php +++ b/packages/mail/src/Transports/Ses/SesSmtpMailerConfig.php @@ -25,7 +25,6 @@ public function __construct( /** * Secret key used for authenticating to the SES API. */ - #[\SensitiveParameter] public string $password, /** diff --git a/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php b/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php index 52b22cbcf..5ee46e98e 100644 --- a/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php +++ b/packages/mail/src/Transports/Smtp/SmtpMailerConfig.php @@ -41,7 +41,6 @@ public function __construct( /** * Password used for connecting to the SMTP server. */ - #[\SensitiveParameter] public ?string $password, /** diff --git a/packages/mapper/src/Mappers/ObjectToArrayMapper.php b/packages/mapper/src/Mappers/ObjectToArrayMapper.php index c195e15a2..f72f411d2 100644 --- a/packages/mapper/src/Mappers/ObjectToArrayMapper.php +++ b/packages/mapper/src/Mappers/ObjectToArrayMapper.php @@ -64,11 +64,9 @@ private function resolvePropertyValue(PropertyReflector $property, object $objec if ($property->getIterableType()?->isClass()) { foreach ($propertyValue as $key => $value) { - if (! is_object($value)) { - continue; + if (is_object($value)) { + $propertyValue[$key] = map($value)->toArray(); } - - $propertyValue[$key] = map($value)->toArray(); } return $propertyValue; diff --git a/packages/mapper/src/functions.php b/packages/mapper/src/functions.php index 1329d2398..59aeb2f29 100644 --- a/packages/mapper/src/functions.php +++ b/packages/mapper/src/functions.php @@ -5,6 +5,7 @@ namespace Tempest\Mapper; use Tempest\Container; +use Tempest\Mapper\ObjectFactory; /** * Creates a factory which allows instantiating `$objectOrClass` with the data specified by the {@see \Tempest\Mapper\ObjectFactory::from()} method. diff --git a/packages/process/src/InvokedProcessPool.php b/packages/process/src/InvokedProcessPool.php index 10322764b..1e8598bb1 100644 --- a/packages/process/src/InvokedProcessPool.php +++ b/packages/process/src/InvokedProcessPool.php @@ -16,7 +16,7 @@ final class InvokedProcessPool implements Countable public ImmutableArray $running { get => $this->processes ->toImmutableArray() - ->filter(static fn (InvokedProcess $process) => $process->running); + ->filter(fn (InvokedProcess $process) => $process->running); } /** @@ -38,7 +38,7 @@ public function __construct( */ public function signal(int $signal): ImmutableArray { - return $this->running->each(static fn (InvokedProcess $process) => $process->signal($signal)); + return $this->running->each(fn (InvokedProcess $process) => $process->signal($signal)); } /** @@ -46,7 +46,7 @@ public function signal(int $signal): ImmutableArray */ public function stop(float|int|Duration $timeout = 10, ?int $signal = null): ImmutableArray { - return $this->running->each(static fn (InvokedProcess $process) => $process->stop($timeout, $signal)); + return $this->running->each(fn (InvokedProcess $process) => $process->stop($timeout, $signal)); } /** @@ -55,7 +55,7 @@ public function stop(float|int|Duration $timeout = 10, ?int $signal = null): Imm public function wait(): ProcessPoolResults { return new ProcessPoolResults( - $this->all->map(static fn (InvokedProcess $process) => $process->wait()), + $this->all->map(fn (InvokedProcess $process) => $process->wait()), ); } @@ -66,7 +66,7 @@ public function wait(): ProcessPoolResults */ public function forEachRunning(\Closure $callback): self { - $this->running->each(static fn (InvokedProcess $process) => $callback($process)); + $this->running->each(fn (InvokedProcess $process) => $callback($process)); return $this; } @@ -78,7 +78,7 @@ public function forEachRunning(\Closure $callback): self */ public function forEach(\Closure $callback): self { - $this->processes->each(static fn (InvokedProcess $process) => $callback($process)); + $this->processes->each(fn (InvokedProcess $process) => $callback($process)); return $this; } diff --git a/packages/process/src/InvokedSystemProcess.php b/packages/process/src/InvokedSystemProcess.php index 0f42edf5f..dada1c23a 100644 --- a/packages/process/src/InvokedSystemProcess.php +++ b/packages/process/src/InvokedSystemProcess.php @@ -66,7 +66,7 @@ public function wait(?callable $output = null): ProcessResult { try { $callback = $output - ? static fn (string $type, mixed $data) => $output(OutputChannel::fromSymfonyOutputType($type), $data) + ? fn (string $type, mixed $data) => $output(OutputChannel::fromSymfonyOutputType($type), $data) : null; $this->process->wait($callback); diff --git a/packages/process/src/ProcessPoolResults.php b/packages/process/src/ProcessPoolResults.php index 021b0d5a1..5bf7a55fa 100644 --- a/packages/process/src/ProcessPoolResults.php +++ b/packages/process/src/ProcessPoolResults.php @@ -19,7 +19,7 @@ public function __construct( */ public function allSuccessful(): bool { - return $this->results->every(static fn (ProcessResult $result) => $result->successful()); + return $this->results->every(fn (ProcessResult $result) => $result->successful()); } /** @@ -27,7 +27,7 @@ public function allSuccessful(): bool */ public function allFailed(): bool { - return $this->results->every(static fn (ProcessResult $result) => $result->failed()); + return $this->results->every(fn (ProcessResult $result) => $result->failed()); } /** @@ -35,7 +35,7 @@ public function allFailed(): bool */ public function someSuccessful(): bool { - return $this->results->filter(static fn (ProcessResult $result) => $result->successful())->count() > 0; + return $this->results->filter(fn (ProcessResult $result) => $result->successful())->count() > 0; } /** @@ -43,7 +43,7 @@ public function someSuccessful(): bool */ public function someFailed(): bool { - return $this->results->filter(static fn (ProcessResult $result) => $result->failed())->count() > 0; + return $this->results->filter(fn (ProcessResult $result) => $result->failed())->count() > 0; } /** @@ -51,7 +51,7 @@ public function someFailed(): bool */ public function successful(): ImmutableArray { - return $this->results->filter(static fn (ProcessResult $result) => $result->successful()); + return $this->results->filter(fn (ProcessResult $result) => $result->successful()); } /** @@ -59,7 +59,7 @@ public function successful(): ImmutableArray */ public function failed(): ImmutableArray { - return $this->results->filter(static fn (ProcessResult $result) => ! $result->successful()); + return $this->results->filter(fn (ProcessResult $result) => ! $result->successful()); } public function toImmutableArray(): ImmutableArray diff --git a/packages/process/src/Testing/InvokedProcessDescription.php b/packages/process/src/Testing/InvokedProcessDescription.php index 80d62e707..fa0a942d7 100644 --- a/packages/process/src/Testing/InvokedProcessDescription.php +++ b/packages/process/src/Testing/InvokedProcessDescription.php @@ -113,7 +113,7 @@ public function resolveOutput(bool $error = false): string ->filter(static fn (array $output) => $output['type'] === $expectedType) ->map(static fn (array $output) => rtrim($output['buffer'], "\n")) ->implode("\n") - ->when(static fn ($s) => $s->isNotEmpty(), static fn ($s) => $s->finish("\n")) + ->when(fn ($s) => $s->isNotEmpty(), fn ($s) => $s->finish("\n")) ->toString(); } } diff --git a/packages/process/src/Testing/InvokedTestingProcess.php b/packages/process/src/Testing/InvokedTestingProcess.php index c0614c40f..9a1938302 100644 --- a/packages/process/src/Testing/InvokedTestingProcess.php +++ b/packages/process/src/Testing/InvokedTestingProcess.php @@ -42,11 +42,9 @@ final class InvokedTestingProcess implements InvokedProcess $output = []; for ($i = 0; $i < $this->nextOutputIndex; $i++) { - if ($this->description->output[$i]['type'] !== OutputChannel::OUTPUT) { - continue; + if ($this->description->output[$i]['type'] === OutputChannel::OUTPUT) { + $output[] = $this->description->output[$i]['buffer']; } - - $output[] = $this->description->output[$i]['buffer']; } return rtrim(implode('', $output), "\n") . "\n"; @@ -60,11 +58,9 @@ final class InvokedTestingProcess implements InvokedProcess $output = []; for ($i = 0; $i < $this->nextErrorOutputIndex; $i++) { - if ($this->description->output[$i]['type'] !== OutputChannel::ERROR) { - continue; + if ($this->description->output[$i]['type'] === OutputChannel::ERROR) { + $output[] = $this->description->output[$i]['buffer']; } - - $output[] = $this->description->output[$i]['buffer']; } return rtrim(implode('', $output), "\n") . "\n"; diff --git a/packages/process/src/Testing/ProcessTester.php b/packages/process/src/Testing/ProcessTester.php index eaa22aa5e..ba75c8d33 100644 --- a/packages/process/src/Testing/ProcessTester.php +++ b/packages/process/src/Testing/ProcessTester.php @@ -246,11 +246,9 @@ public function assertRanTimes(string|\Closure $command, int $times): self $count = 0; foreach ($this->executor->executions as $executions) { foreach ($executions as [$process, $result]) { - if ($command($process, $result) !== true) { - continue; + if ($command($process, $result) === true) { + $count++; } - - $count++; } } } else { // @mago-expects linter:no-else-clause @@ -276,11 +274,9 @@ private function findExecutionsByPattern(string $pattern): array $executions = []; foreach ($this->executor->executions as $command => $commandExecutions) { - if (! $this->executor->commandMatchesPattern($command, $pattern)) { - continue; + if ($this->executor->commandMatchesPattern($command, $pattern)) { + $executions[] = $commandExecutions; } - - $executions[] = $commandExecutions; } return Arr\flatten($executions, depth: 1); diff --git a/packages/process/tests/GenericProcessExecutorTest.php b/packages/process/tests/GenericProcessExecutorTest.php index 32a59237a..cc73cf7b4 100644 --- a/packages/process/tests/GenericProcessExecutorTest.php +++ b/packages/process/tests/GenericProcessExecutorTest.php @@ -64,7 +64,7 @@ public function test_wait_callback(): void $process = $executor->start('echo hello'); $output = []; - $process->wait(static function (OutputChannel $channel, string $data) use (&$output) { + $process->wait(function (OutputChannel $channel, string $data) use (&$output) { $output[$channel->value] ??= []; $output[$channel->value][] = $data; }); diff --git a/packages/reflection/src/ClassReflector.php b/packages/reflection/src/ClassReflector.php index 2cf530860..3a388beef 100644 --- a/packages/reflection/src/ClassReflector.php +++ b/packages/reflection/src/ClassReflector.php @@ -56,7 +56,7 @@ public function getParent(): ?ClassReflector public function getInterfaces(): array { return array_map( - static fn (PHPReflectionClass $interface) => new TypeReflector($interface), + fn (PHPReflectionClass $interface) => new TypeReflector($interface), $this->reflectionClass->getInterfaces(), ); } @@ -65,7 +65,7 @@ public function getInterfaces(): array public function getPublicProperties(): array { return array_map( - static fn (PHPReflectionProperty $property) => new PropertyReflector($property), + fn (PHPReflectionProperty $property) => new PropertyReflector($property), $this->reflectionClass->getProperties(PHPReflectionProperty::IS_PUBLIC), ); } @@ -74,7 +74,7 @@ public function getPublicProperties(): array public function getProperties(): array { return array_map( - static fn (PHPReflectionProperty $property) => new PropertyReflector($property), + fn (PHPReflectionProperty $property) => new PropertyReflector($property), $this->reflectionClass->getProperties(), ); } @@ -85,7 +85,7 @@ public function getPublicMethods(): array return $this->memoize( 'public_methods', fn () => array_map( - static fn (PHPReflectionMethod $method) => new MethodReflector($method), + fn (PHPReflectionMethod $method) => new MethodReflector($method), $this->reflectionClass->getMethods(PHPReflectionMethod::IS_PUBLIC), ), ); diff --git a/packages/reflection/src/EnumReflector.php b/packages/reflection/src/EnumReflector.php index 4dade5c18..f1d204b56 100644 --- a/packages/reflection/src/EnumReflector.php +++ b/packages/reflection/src/EnumReflector.php @@ -88,7 +88,7 @@ public function getCases(): array return $this->memoize( key: 'cases', closure: fn () => array_map( - callback: static fn (ReflectionEnumUnitCase $case) => $case->getValue(), + callback: fn (ReflectionEnumUnitCase $case) => $case->getValue(), array: $this->getReflectionCases(), ), ); diff --git a/packages/reflection/src/FunctionReflector.php b/packages/reflection/src/FunctionReflector.php index ac1b39d1a..c7cb027b0 100644 --- a/packages/reflection/src/FunctionReflector.php +++ b/packages/reflection/src/FunctionReflector.php @@ -37,7 +37,7 @@ public function getParameter(int|string $key): ?ParameterReflector { $parameter = array_find( array: $this->reflectionFunction->getParameters(), - callback: static fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, + callback: fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, ); if ($parameter === null) { diff --git a/packages/reflection/src/MethodReflector.php b/packages/reflection/src/MethodReflector.php index 6dfc9f2fc..6667e8cb0 100644 --- a/packages/reflection/src/MethodReflector.php +++ b/packages/reflection/src/MethodReflector.php @@ -38,7 +38,7 @@ public function getParameter(int|string $key): ?ParameterReflector { $parameter = array_find( array: $this->reflectionMethod->getParameters(), - callback: static fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, + callback: fn (ReflectionParameter $parameter) => $parameter->getName() === $key || $parameter->getPosition() === $key, ); if ($parameter === null) { diff --git a/packages/reflection/src/TypeReflector.php b/packages/reflection/src/TypeReflector.php index 5cac70624..739cfd4e5 100644 --- a/packages/reflection/src/TypeReflector.php +++ b/packages/reflection/src/TypeReflector.php @@ -236,7 +236,7 @@ public function isIntersection(): bool public function split(): array { return array_map( - static fn (string $part) => new self($part), + fn (string $part) => new self($part), preg_split('/[&|]/', $this->definition), ); } diff --git a/packages/reflection/src/functions.php b/packages/reflection/src/functions.php index ee66d5e29..20f07a96e 100644 --- a/packages/reflection/src/functions.php +++ b/packages/reflection/src/functions.php @@ -6,6 +6,8 @@ use ReflectionClass as PHPReflectionClass; use ReflectionProperty as PHPReflectionProperty; +use Tempest\Reflection\ClassReflector; +use Tempest\Reflection\PropertyReflector; /** * Creates a new {@see Reflector} instance based on the given `$classOrProperty`. diff --git a/packages/reflection/tests/Fixtures/NoReturnType.php b/packages/reflection/tests/Fixtures/NoReturnType.php index 9d686184c..bf5dbbb1d 100644 --- a/packages/reflection/tests/Fixtures/NoReturnType.php +++ b/packages/reflection/tests/Fixtures/NoReturnType.php @@ -6,6 +6,7 @@ final class NoReturnType { + // @mago-expect lint:return-type public function noReturnType() { return 2137; diff --git a/packages/reflection/tests/FunctionReflectorTest.php b/packages/reflection/tests/FunctionReflectorTest.php index 86aeb94e7..d9a40d637 100644 --- a/packages/reflection/tests/FunctionReflectorTest.php +++ b/packages/reflection/tests/FunctionReflectorTest.php @@ -9,7 +9,7 @@ final class FunctionReflectorTest extends TestCase { public function test_get_parameter(): void { - $reflector = new FunctionReflector(static fn (string $_test) => null); + $reflector = new FunctionReflector(fn (string $_test) => null); $this->assertSame('_test', $reflector->getParameter(key: '_test')->getName()); $this->assertSame('_test', $reflector->getParameter(key: 0)->getName()); diff --git a/packages/router/src/Commands/MakeControllerCommand.php b/packages/router/src/Commands/MakeControllerCommand.php index 73f5e246a..5052d4aed 100644 --- a/packages/router/src/Commands/MakeControllerCommand.php +++ b/packages/router/src/Commands/MakeControllerCommand.php @@ -43,7 +43,7 @@ public function __invoke( 'dummy-view' => $controllerView, ], manipulations: [ - static fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), + fn (ClassManipulator $class) => $class->removeClassAttribute(SkipDiscovery::class), ], ); diff --git a/packages/router/src/Exceptions/HtmlExceptionRenderer.php b/packages/router/src/Exceptions/HtmlExceptionRenderer.php index 68e01594b..e4bf13fbc 100644 --- a/packages/router/src/Exceptions/HtmlExceptionRenderer.php +++ b/packages/router/src/Exceptions/HtmlExceptionRenderer.php @@ -163,11 +163,9 @@ private function filterSensitiveFields(Request $request, ?string $targetClass): $reflector = new ClassReflector($targetClass); foreach ($reflector->getPublicProperties() as $property) { - if (! $property->hasAttribute(SensitiveField::class)) { - continue; + if ($property->hasAttribute(SensitiveField::class)) { + unset($body[$property->getName()]); } - - unset($body[$property->getName()]); } return $body; diff --git a/packages/router/src/Exceptions/JsonExceptionRenderer.php b/packages/router/src/Exceptions/JsonExceptionRenderer.php index 735398ad8..9a3c247be 100644 --- a/packages/router/src/Exceptions/JsonExceptionRenderer.php +++ b/packages/router/src/Exceptions/JsonExceptionRenderer.php @@ -96,7 +96,7 @@ private function renderErrorResponse(Status $status, ?string $message = null, ?T 'line' => $throwable->getLine(), 'trace' => Arr\map( array: $throwable->getTrace(), - map: static fn (array $trace) => Arr\remove_keys($trace, 'args'), + map: fn (array $trace) => Arr\remove_keys($trace, 'args'), ), ]); } diff --git a/packages/router/src/GenericRouter.php b/packages/router/src/GenericRouter.php index 69ad507cc..6bedfe0e0 100644 --- a/packages/router/src/GenericRouter.php +++ b/packages/router/src/GenericRouter.php @@ -29,7 +29,7 @@ public function dispatch(Request|PsrRequest $request): Response $request = map($request)->with(PsrRequestToGenericRequestMapper::class)->do(); } - $this->container->singleton(Request::class, static fn () => $request); + $this->container->singleton(Request::class, fn () => $request); $callable = $this->getCallable(); diff --git a/packages/router/src/HandleRouteSpecificMiddleware.php b/packages/router/src/HandleRouteSpecificMiddleware.php index 145495031..9e27c96da 100644 --- a/packages/router/src/HandleRouteSpecificMiddleware.php +++ b/packages/router/src/HandleRouteSpecificMiddleware.php @@ -20,7 +20,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon { $middlewareStack = new Middleware(...$this->matchedRoute->route->middleware); - $callable = new HttpMiddlewareCallable(static fn (Request $request) => $next($request)); + $callable = new HttpMiddlewareCallable(fn (Request $request) => $next($request)); foreach ($middlewareStack->unwrap() as $middlewareClass) { $callable = new HttpMiddlewareCallable(function (Request $request) use ($middlewareClass, $callable) { diff --git a/packages/router/src/MatchRouteMiddleware.php b/packages/router/src/MatchRouteMiddleware.php index 33ecc45d8..ab8a44a32 100644 --- a/packages/router/src/MatchRouteMiddleware.php +++ b/packages/router/src/MatchRouteMiddleware.php @@ -35,7 +35,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon } // We register the matched route in the container, some internal framework components will need it - $this->container->singleton(MatchedRoute::class, static fn () => $matchedRoute); + $this->container->singleton(MatchedRoute::class, fn () => $matchedRoute); // Convert the request to a specific request implementation, if needed $request = $this->resolveRequest($request, $matchedRoute); @@ -43,7 +43,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon // We register this newly created request object in the container // This makes it so that RequestInitializer is bypassed entirely when the controller action needs the request class // Making it so that we don't need to set any $_SERVER variables and stuff like that - $this->container->singleton($request::class, static fn () => $request); + $this->container->singleton($request::class, fn () => $request); return $next($request); } @@ -56,13 +56,12 @@ private function resolveRequest(Request $request, MatchedRoute $matchedRoute): R // We'll loop over all the handler's parameters foreach ($matchedRoute->route->handler->getParameters() as $parameter) { // If the parameter's type is an instance of Request… - if (! $parameter->getType()->matches(Request::class)) { - continue; - } - - $requestClass = $parameter->getType()->getName(); + if ($parameter->getType()->matches(Request::class)) { + // We'll use that specific request class + $requestClass = $parameter->getType()->getName(); - break; + break; + } } if ($requestClass !== Request::class && $requestClass !== GenericRequest::class) { diff --git a/packages/router/src/RouteBindingInitializer.php b/packages/router/src/RouteBindingInitializer.php index 027e83d49..b9f3b00fc 100644 --- a/packages/router/src/RouteBindingInitializer.php +++ b/packages/router/src/RouteBindingInitializer.php @@ -24,13 +24,11 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con $parameter = null; foreach ($matchedRoute->route->handler->getParameters() as $searchParameter) { - if (! $searchParameter->getType()->equals($class->getType())) { - continue; - } - - $parameter = $searchParameter; + if ($searchParameter->getType()->equals($class->getType())) { + $parameter = $searchParameter; - break; + break; + } } if ($parameter === null) { diff --git a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php index 7a50389ad..7a71c6c7e 100644 --- a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php +++ b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php @@ -9,7 +9,7 @@ final readonly class RouteMatchingRegexBuilder { // This limit is guesstimated using a small script with an ever in pattern feed into preg_match - private const int PREG_REGEX_SIZE_LIMIT = 32_768; + private const int PREG_REGEX_SIZE_LIMIT = 32768; private const int REGEX_SIZE_MARGIN = 256; diff --git a/packages/router/src/Static/StaticCleanCommand.php b/packages/router/src/Static/StaticCleanCommand.php index 057fd0f75..a85a569a4 100644 --- a/packages/router/src/Static/StaticCleanCommand.php +++ b/packages/router/src/Static/StaticCleanCommand.php @@ -56,11 +56,9 @@ private function removeFiles(RecursiveDirectoryIterator $directoryIterator): voi /** @var SplFileInfo $file */ foreach (new RecursiveIteratorIterator($directoryIterator) as $file) { - if ($file->getExtension() !== 'html') { - continue; + if ($file->getExtension() === 'html') { + $files[] = $file; } - - $files[] = $file; } foreach ($files as $file) { diff --git a/packages/router/src/functions.php b/packages/router/src/functions.php index fa96034e9..083c5f837 100644 --- a/packages/router/src/functions.php +++ b/packages/router/src/functions.php @@ -7,6 +7,7 @@ use Tempest\DateTime\DateTime; use Tempest\DateTime\Duration; use Tempest\Reflection\MethodReflector; +use Tempest\Router\UriGenerator; use function Tempest\Container\get; diff --git a/packages/storage/src/Config/FTPStorageConfig.php b/packages/storage/src/Config/FTPStorageConfig.php index 02fc9571a..9bc200661 100644 --- a/packages/storage/src/Config/FTPStorageConfig.php +++ b/packages/storage/src/Config/FTPStorageConfig.php @@ -19,7 +19,6 @@ public function __construct( public string $host, public string $root, public string $username, - #[\SensitiveParameter] public string $password, public int $port = 21, public bool $ssl = false, diff --git a/packages/storage/src/Config/S3StorageConfig.php b/packages/storage/src/Config/S3StorageConfig.php index 120797d0a..f1f17f70f 100644 --- a/packages/storage/src/Config/S3StorageConfig.php +++ b/packages/storage/src/Config/S3StorageConfig.php @@ -35,7 +35,6 @@ public function __construct( /** * AWS session token (typically used with temporary credentials). If null, the SDK will attempt to use the default credential provider chain. */ - #[\SensitiveParameter] public ?string $sessionToken = null, /** diff --git a/packages/storage/src/Config/SFTPStorageConfig.php b/packages/storage/src/Config/SFTPStorageConfig.php index 28b4978ab..c2bfaae16 100644 --- a/packages/storage/src/Config/SFTPStorageConfig.php +++ b/packages/storage/src/Config/SFTPStorageConfig.php @@ -15,7 +15,6 @@ public function __construct( public string $host, public string $root, public string $username, - #[\SensitiveParameter] public string $password, public ?string $privateKey = null, public ?string $passphrase = null, diff --git a/packages/support/src/Arr/ManipulatesArray.php b/packages/support/src/Arr/ManipulatesArray.php index b9aa7cfd8..e038d9f17 100644 --- a/packages/support/src/Arr/ManipulatesArray.php +++ b/packages/support/src/Arr/ManipulatesArray.php @@ -90,7 +90,7 @@ public function findKey(mixed $value, bool $strict = false): int|string|null */ public function chunk(int $size, bool $preserveKeys = true): self { - return $this->createOrModify(array_map(static fn (array $array) => new static($array), namespace\chunk($this->value, $size, $preserveKeys))); + return $this->createOrModify(array_map(fn (array $array) => new static($array), namespace\chunk($this->value, $size, $preserveKeys))); } /** diff --git a/packages/support/src/Arr/functions.php b/packages/support/src/Arr/functions.php index 12dcd732b..96c97c720 100644 --- a/packages/support/src/Arr/functions.php +++ b/packages/support/src/Arr/functions.php @@ -202,11 +202,9 @@ function forget_values(array &$array, mixed $values): array $values = is_array($values) ? $values : [$values]; foreach ($values as $value) { - if (is_null($key = array_find_key($array, fn (mixed $match) => $value === $match))) { - continue; + if (! is_null($key = array_find_key($array, fn (mixed $match) => $value === $match))) { + unset($array[$key]); } - - unset($array[$key]); } return $array; @@ -759,7 +757,9 @@ function implode(iterable $array, string $glue): ImmutableString function keys(iterable $array): array { /** @var list $result */ - return array_keys(to_array($array)); + $result = array_keys(to_array($array)); + + return $result; } /** @@ -775,7 +775,9 @@ function keys(iterable $array): array function values(iterable $array): array { /** @var list $result */ - return array_values(to_array($array)); + $result = array_values(to_array($array)); + + return $result; } /** @@ -796,11 +798,9 @@ function filter(iterable $array, ?Closure $filter = null): array $filter ??= static fn (mixed $value, mixed $_) => ! in_array($value, [false, null], strict: true); foreach (to_array($array) as $key => $value) { - if (! $filter($value, $key)) { - continue; + if ($filter($value, $key)) { + $result[$key] = $value; } - - $result[$key] = $value; } return $result; @@ -1534,11 +1534,9 @@ function to_array(mixed $input): array $result = []; for ($i = 0; $i < $count; $i++) { - if (! isset($input[$i])) { - continue; + if (isset($input[$i])) { + $result[$i] = $input[$i]; } - - $result[$i] = $input[$i]; } return $result; diff --git a/packages/support/src/IsEnumHelper.php b/packages/support/src/IsEnumHelper.php index 24fcbb3fc..a8fe25859 100644 --- a/packages/support/src/IsEnumHelper.php +++ b/packages/support/src/IsEnumHelper.php @@ -39,7 +39,7 @@ public static function tryFromName(string $name): ?static { $cases = array_filter( static::cases(), - static fn (UnitEnum $case) => $case->name === $name, + fn (UnitEnum $case) => $case->name === $name, ); return array_shift($cases); diff --git a/packages/support/src/JavaScript/DependencyInstaller.php b/packages/support/src/JavaScript/DependencyInstaller.php index 8621ea2e5..762c68755 100644 --- a/packages/support/src/JavaScript/DependencyInstaller.php +++ b/packages/support/src/JavaScript/DependencyInstaller.php @@ -75,7 +75,7 @@ private function getInstallProcess(PackageManager $packageManager, string $cwd, $dev ? '-D' : null, ...$dependencies, ], - static fn (?string $arg): bool => $arg !== null, + fn (?string $arg): bool => $arg !== null, )); return new Process( diff --git a/packages/support/src/JavaScript/PackageManager.php b/packages/support/src/JavaScript/PackageManager.php index 1eb0b23d2..b2649ff8a 100644 --- a/packages/support/src/JavaScript/PackageManager.php +++ b/packages/support/src/JavaScript/PackageManager.php @@ -62,7 +62,7 @@ public static function detect(string $cwd): ?self { return array_find( array: PackageManager::cases(), - callback: static fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), static fn (string $lockFile): bool => Filesystem\is_file( + callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file( $cwd . '/' . $lockFile, )), ); diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php index 73d53c7af..54e0cb013 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php @@ -5,5 +5,6 @@ namespace Tempest\Support\Json\Exception; use InvalidArgumentException; +use Tempest\Support\Json\Exception\JsonException; final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php index 9148a3c7b..643d92ddd 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php @@ -5,5 +5,6 @@ namespace Tempest\Support\Json\Exception; use InvalidArgumentException; +use Tempest\Support\Json\Exception\JsonException; final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Math/constants.php b/packages/support/src/Math/constants.php index 3c6f7b403..8d296b290 100644 --- a/packages/support/src/Math/constants.php +++ b/packages/support/src/Math/constants.php @@ -26,21 +26,21 @@ * * @var float */ -const E = 2.718_281_828_459_045_235_360_287_5; +const E = 2.7182818284590452353602875; /** * The ratio of the circumference of a circle to its diameter, or approximately 3.141592653589793238462643. * * @var float */ -const PI = 3.141_592_653_589_793_238_462_643; +const PI = 3.141592653589793238462643; /** * The maximum integer value representable in a 64-bit binary-coded decimal. * * @var int */ -const INT64_MAX = 9_223_372_036_854_775_807; +const INT64_MAX = 9223372036854775807; /** * The minimum integer value representable in a 64-bit binary-coded decimal. @@ -54,42 +54,42 @@ * * @var int */ -const INT53_MAX = 9_007_199_254_740_992; +const INT53_MAX = 9007199254740992; /** * The minimum integer value representable in a 53-bit binary-coded decimal. * * @var int */ -const INT53_MIN = -9_007_199_254_740_993; +const INT53_MIN = -9007199254740993; /** * The maximum integer value representable in a 32-bit binary-coded decimal. * * @var int */ -const INT32_MAX = 2_147_483_647; +const INT32_MAX = 2147483647; /** * The minimum integer value representable in a 32-bit binary-coded decimal. * * @var int */ -const INT32_MIN = -2_147_483_648; +const INT32_MIN = -2147483648; /** * The maximum integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const INT16_MAX = 32_767; +const INT16_MAX = 32767; /** * The minimum integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const INT16_MIN = -32_768; +const INT16_MIN = -32768; /** * The maximum integer value representable in a 8-bit binary-coded decimal. @@ -110,14 +110,14 @@ * * @var int */ -const UINT32_MAX = 4_294_967_295; +const UINT32_MAX = 4294967295; /** * The maximum unsigned integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const UINT16_MAX = 65_535; +const UINT16_MAX = 65535; /** * The maximum unsigned integer value representable in a 8-bit binary-coded decimal. @@ -131,25 +131,25 @@ * * @var float */ -const FLOAT32_MAX = 3.402_823_47E+38; +const FLOAT32_MAX = 3.40282347E+38; /** * The minimum floating point value representable in a 32-bit binary-coded decimal. * * @var float */ -const FLOAT32_MIN = -3.402_823_47E+38; +const FLOAT32_MIN = -3.40282347E+38; /** * The maximum floating point value representable in a 64-bit binary-coded decimal. * * @var float */ -const FLOAT64_MAX = 1.797_693_134_862_315_7E+308; +const FLOAT64_MAX = 1.7976931348623157E+308; /** * The minimum floating point value representable in a 64-bit binary-coded decimal. * * @var float */ -const FLOAT64_MIN = -1.797_693_134_862_315_7E+308; +const FLOAT64_MIN = -1.7976931348623157E+308; diff --git a/packages/support/src/Math/functions.php b/packages/support/src/Math/functions.php index d24925656..9fbc60373 100644 --- a/packages/support/src/Math/functions.php +++ b/packages/support/src/Math/functions.php @@ -356,11 +356,9 @@ function max(array $numbers): null|int|float $max = null; foreach ($numbers as $number) { - if (! (null === $max || $number > $max)) { - continue; + if (null === $max || $number > $max) { + $max = $number; } - - $max = $number; } return $max; @@ -382,11 +380,9 @@ function maxva(int|float $first, int|float $second, int|float ...$rest): int|flo $max = \max($first, $second); foreach ($rest as $number) { - if ($number <= $max) { - continue; + if ($number > $max) { + $max = $number; } - - $max = $number; } return $max; @@ -492,11 +488,9 @@ function min(array $numbers): null|float|int $min = null; foreach ($numbers as $number) { - if (! (null === $min || $number < $min)) { - continue; + if (null === $min || $number < $min) { + $min = $number; } - - $min = $number; } return $min; @@ -518,11 +512,9 @@ function minva(int|float $first, int|float $second, int|float ...$rest): int|flo $min = \min($first, $second); foreach ($rest as $number) { - if ($number >= $min) { - continue; + if ($number < $min) { + $min = $number; } - - $min = $number; } return $min; diff --git a/packages/support/src/Uri/Uri.php b/packages/support/src/Uri/Uri.php index 15df9336f..aedf22f6d 100644 --- a/packages/support/src/Uri/Uri.php +++ b/packages/support/src/Uri/Uri.php @@ -21,7 +21,7 @@ final class Uri return []; } - return array_values(array_filter(explode('/', $this->path), static fn (string $segment) => $segment !== '')); + return array_values(array_filter(explode('/', $this->path), fn (string $segment) => $segment !== '')); } } @@ -53,7 +53,6 @@ final class Uri public function __construct( public readonly ?string $scheme = null, public readonly ?string $user = null, - #[\SensitiveParameter] public readonly ?string $password = null, public readonly ?string $host = null, public readonly ?int $port = null, @@ -104,7 +103,7 @@ public function withUser(string $user): self /** * Returns a new Uri with the provided password. */ - public function withPassword(#[\SensitiveParameter] string $password): self + public function withPassword(string $password): self { return $this->with( user: $this->user ?? '', @@ -216,7 +215,6 @@ public function withFragment(string $fragment): self private function with( ?string $scheme = null, ?string $user = null, - #[\SensitiveParameter] ?string $password = null, ?string $host = null, ?int $port = null, @@ -265,7 +263,9 @@ private function buildQueryString(array $query): ?string } $queryString = http_build_query($processedQuery, arg_separator: '&', encoding_type: PHP_QUERY_RFC3986); - return preg_replace('/([^=&]+)=(?=&|$)/', replacement: '$1', subject: $queryString); + $queryString = preg_replace('/([^=&]+)=(?=&|$)/', replacement: '$1', subject: $queryString); + + return $queryString; } /** diff --git a/packages/support/src/Uri/functions.php b/packages/support/src/Uri/functions.php index deef4b786..325c5308a 100644 --- a/packages/support/src/Uri/functions.php +++ b/packages/support/src/Uri/functions.php @@ -123,7 +123,7 @@ function get_user(string $uri): ?string /** * Updates the given URI to use the provided password. */ -function set_password(string $uri, #[\SensitiveParameter] string $password): string +function set_password(string $uri, string $password): string { return Uri::from($uri)->withPassword($password)->toString(); } diff --git a/packages/support/tests/Arr/ManipulatesArrayTest.php b/packages/support/tests/Arr/ManipulatesArrayTest.php index a7cb4dc13..46744bc84 100644 --- a/packages/support/tests/Arr/ManipulatesArrayTest.php +++ b/packages/support/tests/Arr/ManipulatesArrayTest.php @@ -203,7 +203,7 @@ public function test_unshift(): void public function test_last(): void { - $this->assertNull(arr()->last()); + $this->assertSame(null, arr()->last()); $this->assertSame('c', arr(['a', 'b', 'c'])->last()); $this->assertSame('foo', arr()->last(default: 'foo')); @@ -213,7 +213,7 @@ public function test_last(): void public function test_first(): void { $this->assertSame('a', arr(['a', 'b', 'c'])->first()); - $this->assertNull(arr()->first()); + $this->assertSame(null, arr()->first()); $this->assertSame('foo', arr()->first(default: 'foo')); $this->assertSame(1, arr([1, 2])->first(default: 'foo')); @@ -229,13 +229,13 @@ public function test_map(): void { $this->assertTrue( arr(['a', 'b']) - ->map(static fn (string $value) => $value . 'x') + ->map(fn (string $value) => $value . 'x') ->equals(['ax', 'bx']), ); $this->assertTrue( arr(['a', 'b']) - ->map(static fn (string $value, mixed $key) => $value . $key) + ->map(fn (string $value, mixed $key) => $value . $key) ->equals(['a0', 'b1']), ); } @@ -244,13 +244,13 @@ public function test_map_with_keys(): void { $this->assertTrue( arr(['a', 'b']) - ->mapWithKeys(static fn (mixed $value, mixed $_) => yield $value => $value) + ->mapWithKeys(fn (mixed $value, mixed $_) => yield $value => $value) ->equals(['a' => 'a', 'b' => 'b']), ); $this->assertTrue( arr(['a' => 'a', 'b' => 'b']) - ->mapWithKeys(static fn (mixed $value, mixed $_) => yield $value) + ->mapWithKeys(fn (mixed $value, mixed $_) => yield $value) ->equals(['b']), ); } @@ -260,7 +260,7 @@ public function test_map_with_keys_without_generator(): void $this->expectException(MapWithKeysDidNotUseAGenerator::class); arr(['a', 'b']) - ->mapWithKeys(static fn (mixed $value, mixed $_) => $value); + ->mapWithKeys(fn (mixed $value, mixed $_) => $value); } public function test_values(): void @@ -284,14 +284,14 @@ public function test_filter(): void $this->assertTrue( arr(['a', 'b', 'c']) - ->filter(static fn (mixed $value) => $value === 'b') + ->filter(fn (mixed $value) => $value === 'b') ->values() ->equals(['b']), ); $this->assertTrue( arr(['a', 'b', 'c']) - ->filter(static fn (mixed $_, mixed $key) => $key === 1) + ->filter(fn (mixed $_, mixed $key) => $key === 1) ->values() ->equals(['b']), ); @@ -311,7 +311,7 @@ public function test_each(): void $string = ''; arr(['a', 'b', 'c']) - ->each(static function (mixed $value) use (&$string): void { + ->each(function (mixed $value) use (&$string): void { $string .= $value; }); @@ -320,7 +320,7 @@ public function test_each(): void $string = ''; arr(['a', 'b', 'c']) - ->each(static function (mixed $_, mixed $key) use (&$string): void { + ->each(function (mixed $_, mixed $key) use (&$string): void { $string .= $key; }); @@ -338,14 +338,14 @@ public function test_contains(): void $this->assertTrue(arr(['a', 'b', 'c'])->hasValue('b')); $this->assertFalse(arr(['a', 'b', 'c'])->hasValue('d')); - $this->assertTrue(arr(['a', 'b', 'c'])->contains(static fn (string $v) => $v === 'b')); - $this->assertFalse(arr(['a', 'b', 'c'])->contains(static fn (string $v) => $v === 'd')); + $this->assertTrue(arr(['a', 'b', 'c'])->contains(fn (string $v) => $v === 'b')); + $this->assertFalse(arr(['a', 'b', 'c'])->contains(fn (string $v) => $v === 'd')); - $this->assertTrue(arr(['a', 'b', 'c'])->hasValue(static fn (string $v) => $v === 'b')); - $this->assertFalse(arr(['a', 'b', 'c'])->hasValue(static fn (string $v) => $v === 'd')); + $this->assertTrue(arr(['a', 'b', 'c'])->hasValue(fn (string $v) => $v === 'b')); + $this->assertFalse(arr(['a', 'b', 'c'])->hasValue(fn (string $v) => $v === 'd')); - $this->assertTrue(arr(['a', 'b', 'c'])->includes(static fn (string $v) => $v === 'b')); - $this->assertFalse(arr(['a', 'b', 'c'])->includes(static fn (string $v) => $v === 'd')); + $this->assertTrue(arr(['a', 'b', 'c'])->includes(fn (string $v) => $v === 'b')); + $this->assertFalse(arr(['a', 'b', 'c'])->includes(fn (string $v) => $v === 'd')); } public function test_explode(): void @@ -609,7 +609,7 @@ public function test_unique_callback(): void ]); $current = $collection - ->unique(static fn (string $item) => $item[0]) + ->unique(fn (string $item) => $item[0]) ->values() ->toArray(); @@ -1353,18 +1353,18 @@ public function test_sort_by_callback(): void // Test auto-detects key preservation $this->assertSame( ['a', 'b', 'c'], - arr(['c', 'a', 'b'])->sortByCallback(static fn ($a, $b) => $a <=> $b)->toArray(), + arr(['c', 'a', 'b'])->sortByCallback(fn ($a, $b) => $a <=> $b)->toArray(), ); $this->assertSame( [2 => 'a', 3 => 'b', 1 => 'c'], - $array->sortByCallback(static fn ($a, $b) => $a <=> $b)->toArray(), + $array->sortByCallback(fn ($a, $b) => $a <=> $b)->toArray(), ); $this->assertSame( expected: ['a', 'b', 'c'], actual: $array ->sortByCallback( - callback: static fn ($a, $b) => $a <=> $b, + callback: fn ($a, $b) => $a <=> $b, preserveKeys: false, ) ->toArray(), @@ -1373,7 +1373,7 @@ public function test_sort_by_callback(): void expected: [2 => 'a', 3 => 'b', 1 => 'c'], actual: $array ->sortByCallback( - callback: static fn ($a, $b) => $a <=> $b, + callback: fn ($a, $b) => $a <=> $b, preserveKeys: true, ) ->toArray(), @@ -1400,7 +1400,7 @@ public function test_sort_keys_by_callback(): void $this->assertSame( [1 => 'c', 2 => 'a', 3 => 'b'], - $array->sortKeysByCallback(static fn ($a, $b) => $a <=> $b)->toArray(), + $array->sortKeysByCallback(fn ($a, $b) => $a <=> $b)->toArray(), ); } @@ -1425,7 +1425,7 @@ public function test_flatmap(): void ['name' => 'Makise', 'hobbies' => ['Science', 'Programming']], ['name' => 'Okabe', 'hobbies' => ['Science', 'Anime']], ]) - ->flatMap(static fn (array $person) => $person['hobbies']) + ->flatMap(fn (array $person) => $person['hobbies']) ->equals(['Science', 'Programming', 'Science', 'Anime']), ); @@ -1449,7 +1449,7 @@ public function test_flatmap(): void $this->assertTrue( $likes - ->flatMap(static fn (array $person) => $person['likes'], depth: 1) + ->flatMap(fn (array $person) => $person['likes'], depth: 1) ->equals([ ['Tower of God', 'The Beginning After The End'], ['PHP', 'TypeScript'], @@ -1460,7 +1460,7 @@ public function test_flatmap(): void $this->assertTrue( $likes - ->flatMap(static fn (array $person) => $person['likes'], depth: INF) + ->flatMap(fn (array $person) => $person['likes'], depth: INF) ->equals([ 'Tower of God', 'The Beginning After The End', @@ -1482,7 +1482,7 @@ public function test_basic_reduce(): void ]); $this->assertSame( - $collection->reduce(static fn ($carry, $value) => $carry . ' ' . $value, 'Hello'), + $collection->reduce(fn ($carry, $value) => $carry . ' ' . $value, 'Hello'), 'Hello John Doe 42', ); } @@ -1504,7 +1504,7 @@ public function test_reduce_with_existing_function(): void public function test_empty_array_reduce(): void { $this->assertSame( - arr()->reduce(static fn ($carry, $value) => $carry . ' ' . $value, 'default'), + arr()->reduce(fn ($carry, $value) => $carry . ' ' . $value, 'default'), 'default', ); } @@ -1516,7 +1516,7 @@ public function test_chunk(): void $this->assertSame( $collection ->chunk(2, preserveKeys: false) - ->map(static fn ($chunk) => $chunk->toArray()) + ->map(fn ($chunk) => $chunk->toArray()) ->toArray(), [ [1, 2], @@ -1530,7 +1530,7 @@ public function test_chunk(): void $this->assertSame( $collection ->chunk(3, preserveKeys: false) - ->map(static fn ($chunk) => $chunk->toArray()) + ->map(fn ($chunk) => $chunk->toArray()) ->toArray(), [ [1, 2, 3], @@ -1548,7 +1548,7 @@ public function test_chunk_preserve_keys(): void $this->assertSame( $collection ->chunk(2) - ->map(static fn ($chunk) => $chunk->toArray()) + ->map(fn ($chunk) => $chunk->toArray()) ->toArray(), [ [0 => 1, 1 => 2], @@ -1562,7 +1562,7 @@ public function test_chunk_preserve_keys(): void $this->assertSame( $collection ->chunk(3) - ->map(static fn ($chunk) => $chunk->toArray()) + ->map(fn ($chunk) => $chunk->toArray()) ->toArray(), [ [0 => 1, 1 => 2, 2 => 3], @@ -1601,13 +1601,13 @@ public function test_find_key_with_closure(): void ['id' => 3, 'name' => 'Bob'], ]); - $result = $collection->findKey(static fn ($item) => $item['name'] === 'Jane'); + $result = $collection->findKey(fn ($item) => $item['name'] === 'Jane'); $this->assertSame(1, $result); - $result = $collection->findKey(static fn ($_, $key) => $key === 2); + $result = $collection->findKey(fn ($_, $key) => $key === 2); $this->assertSame(2, $result); - $result = $collection->findKey(static fn ($item) => $item['name'] === 'Alice'); + $result = $collection->findKey(fn ($item) => $item['name'] === 'Alice'); $this->assertNull($result); } @@ -1639,7 +1639,7 @@ public function test_find_key_with_complex_closure(): void ['age' => 35, 'active' => true], ]); - $result = $collection->findKey(static function ($item) { + $result = $collection->findKey(function ($item) { return $item['age'] > 28 && $item['active'] === true; }); @@ -1651,7 +1651,7 @@ public function test_find_key_with_empty_array(): void $collection = arr([]); $this->assertNull($collection->findKey('anything')); - $this->assertNull($collection->findKey(static fn () => true)); + $this->assertNull($collection->findKey(fn () => true)); } public function test_slice(): void @@ -1686,9 +1686,9 @@ public function test_slice(): void public function test_every(): void { - $this->assertTrue(arr([])->every(static fn (int $value) => ($value % 2) === 0)); - $this->assertTrue(arr([2, 4, 6])->every(static fn (int $value) => ($value % 2) === 0)); - $this->assertFalse(arr([1, 2, 4, 6])->every(static fn (int $value) => ($value % 2) === 0)); + $this->assertTrue(arr([])->every(fn (int $value) => ($value % 2) === 0)); + $this->assertTrue(arr([2, 4, 6])->every(fn (int $value) => ($value % 2) === 0)); + $this->assertFalse(arr([1, 2, 4, 6])->every(fn (int $value) => ($value % 2) === 0)); $this->assertTrue(arr([0, 1, true, false, ''])->every()); $this->assertFalse(arr([0, 1, true, false, '', null])->every()); } @@ -1738,7 +1738,7 @@ public function test_tap(): void $collection = arr(['foo']); $log = []; - $result = $collection->tap(static function (ImmutableArray $array) use (&$log): void { + $result = $collection->tap(function (ImmutableArray $array) use (&$log): void { $log[] = $array->first(); }); @@ -1786,7 +1786,7 @@ public function test_group_by(): void ['brand' => 'brand2', 'model' => 'model4'], ], ]) - ->equals($array->groupBy(static fn ($item) => $item['brand'])), + ->equals($array->groupBy(fn ($item) => $item['brand'])), ); } @@ -1809,7 +1809,7 @@ public function test_at(array $input, int $index, mixed $expected, mixed $defaul public function test_partition(): void { - $this->assertSame([[true, true], [false]], arr([true, true, false])->partition(static fn (bool $value) => $value === true)->toArray()); + $this->assertSame([[true, true], [false]], arr([true, true, false])->partition(fn (bool $value) => $value === true)->toArray()); } public function test_json_encode(): void diff --git a/packages/support/tests/Conditions/HasConditionsTest.php b/packages/support/tests/Conditions/HasConditionsTest.php index f76687938..ee994570e 100644 --- a/packages/support/tests/Conditions/HasConditionsTest.php +++ b/packages/support/tests/Conditions/HasConditionsTest.php @@ -20,7 +20,7 @@ public function test_when(): void public bool $value = false; }; - $class->when(true, static fn ($c) => $c->value = true); + $class->when(true, fn ($c) => $c->value = true); $this->assertTrue($class->value); } @@ -33,7 +33,7 @@ public function test_when_with_callback(): void public bool $value = false; }; - $class->when(static fn () => true, static fn ($c) => $c->value = true); + $class->when(fn () => true, fn ($c) => $c->value = true); $this->assertTrue($class->value); } @@ -46,7 +46,7 @@ public function test_unless(): void public bool $value = false; }; - $class->unless(true, static fn ($c) => $c->value = true); + $class->unless(true, fn ($c) => $c->value = true); $this->assertFalse($class->value); } @@ -59,7 +59,7 @@ public function test_unless_with_callback(): void public bool $value = false; }; - $class->unless(static fn () => true, static fn ($c) => $c->value = true); + $class->unless(fn () => true, fn ($c) => $c->value = true); $this->assertFalse($class->value); } @@ -80,7 +80,7 @@ public function append(string $string): self } }; - $class->when(true, static function ($c): void { + $class->when(true, function ($c): void { $c->append('bar'); }); diff --git a/packages/support/tests/Math/MathsTest.php b/packages/support/tests/Math/MathsTest.php index 994bbcf43..937195336 100644 --- a/packages/support/tests/Math/MathsTest.php +++ b/packages/support/tests/Math/MathsTest.php @@ -23,37 +23,37 @@ public function test_abs(int|float $expected, int|float $number): void } #[TestWith([0.0, 1.0])] - #[TestWith([1.266_103_672_779_499_2, 0.3])] - #[TestWith([1.047_197_551_196_597_9, 0.5])] + #[TestWith([1.2661036727794992, 0.3])] + #[TestWith([1.0471975511965979, 0.5])] public function test_acos(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\acos($number)); } - #[TestWith([0.523_598_775_598_298_9, 0.5])] - #[TestWith([0.927_295_218_001_612_3, 0.8])] + #[TestWith([0.5235987755982989, 0.5])] + #[TestWith([0.9272952180016123, 0.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.411_516_846_067_488_06, 0.4])] + #[TestWith([0.41151684606748806, 0.4])] public function test_asin(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\asin($number)); } - #[TestWith([0.785_398_163_397_448_3, 1.0, 1.0])] - #[TestWith([0.896_055_384_571_343_9, 1.0, 0.8])] + #[TestWith([0.7853981633974483, 1.0, 1.0])] + #[TestWith([0.8960553845713439, 1.0, 0.8])] #[TestWith([0.0, 0.0, 0.0])] - #[TestWith([0.785_398_163_397_448_3, 0.4, 0.4])] - #[TestWith([-2.260_001_062_633_476, -0.5, -0.412])] + #[TestWith([0.7853981633974483, 0.4, 0.4])] + #[TestWith([-2.260001062633476, -0.5, -0.412])] public function test_atan2(float $expected, float $y, float $x): void { $this->assertFloatEquals($expected, Math\atan2($y, $x)); } - #[TestWith([0.785_398_163_397_448_3, 1.0])] - #[TestWith([0.674_740_942_223_552_7, 0.8])] + #[TestWith([0.7853981633974483, 1.0])] + #[TestWith([0.6747409422235527, 0.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.380_506_377_112_364_9, 0.4])] - #[TestWith([-0.463_647_609_000_806_1, -0.5])] + #[TestWith([0.3805063771123649, 0.4])] + #[TestWith([-0.4636476090008061, -0.5])] public function test_atan(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\atan($number)); @@ -102,11 +102,11 @@ public function test_clamp_invalid_min_max(): void Math\clamp(10, 20, 10); } - #[TestWith([0.540_302_305_868_139_8, 1.0])] + #[TestWith([0.5403023058681398, 1.0])] #[TestWith([1.0, 0.0])] - #[TestWith([0.102_910_956_606_956_12, 45.45])] - #[TestWith([0.283_662_185_463_226_25, -5])] - #[TestWith([-0.998_320_600_058_992_4, -15.65])] + #[TestWith([0.10291095660695612, 45.45])] + #[TestWith([0.28366218546322625, -5])] + #[TestWith([-0.9983206000589924, -15.65])] public function test_cos(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\cos($number)); @@ -137,9 +137,9 @@ public function test_div_int64_min_by_minus_one(): void Math\div(Math\INT64_MIN, -1); } - #[TestWith([162_754.791_419_003_92, 12.0])] - #[TestWith([298.867_400_967_060_3, 5.7])] - #[TestWith([Math\INFINITY, 1_000_000])] + #[TestWith([162754.79141900392, 12.0])] + #[TestWith([298.8674009670603, 5.7])] + #[TestWith([Math\INFINITY, 1000000])] public function test_exp(float $expected, float $number): void { $this->assertSame($expected, Math\exp($number)); @@ -156,7 +156,7 @@ public function test_floor(float $expected, float $number): void } #[TestWith([5497, '1010101111001', 2])] - #[TestWith([2_014_587_925_987, 'pphlmw9v', 36])] + #[TestWith([2014587925987, 'pphlmw9v', 36])] #[TestWith([Math\INT32_MAX, 'zik0zj', 36])] #[TestWith([15, 'F', 16])] public function test_from_base(int $expected, string $value, int $from_base): void @@ -190,9 +190,9 @@ public function test_throws_for_overflow(): void Math\from_base($number, 32); } - #[TestWith([1.686_398_953_570_228_8, 5.4, null])] - #[TestWith([0.657_478_460_018_880_8, 5.4, 13])] - #[TestWith([1.732_393_759_822_968_6, 54.0, 10])] + #[TestWith([1.6863989535702288, 5.4, null])] + #[TestWith([0.6574784600188808, 5.4, 13])] + #[TestWith([1.7323937598229686, 54.0, 10])] #[TestWith([0, 1, null])] public function test_log(float $expected, float $number, ?float $base = null): void { @@ -293,8 +293,8 @@ public static function provide_mean_cases(): array { return [ [5.0, [10, 5, 0, 2, 4, 6, 8]], - [7.357_142_857_142_858, [18, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]], - [26.785_714_285_714_285, [19, 15, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 52, 64]], + [7.357142857142858, [18, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]], + [26.785714285714285, [19, 15, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 52, 64]], [100.0, array_fill(0, 100, 100)], [null, []], ]; @@ -384,33 +384,33 @@ public static function provide_min_va_cases(): array ]; } - #[TestWith([5.46, 5.456_63, 2])] + #[TestWith([5.46, 5.45663, 2])] #[TestWith([4.8, 4.811, 1])] #[TestWith([5.0, 5.42, 0])] #[TestWith([5.0, 4.8, 0])] #[TestWith([0.0, 0.4242, 0])] #[TestWith([0.5, 0.4634, 1])] - #[TestWith([-6.577_78, -6.577_777_777_7, 5])] + #[TestWith([-6.57778, -6.5777777777, 5])] public function test_round(float $expected, float $number, int $precision = 0): void { $this->assertSame($expected, Math\round($number, $precision)); } - #[TestWith([-0.958_924_274_663_138_5, 5.0])] - #[TestWith([-0.996_164_608_835_840_7, 4.8])] + #[TestWith([-0.9589242746631385, 5.0])] + #[TestWith([-0.9961646088358407, 4.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.389_418_342_308_650_5, 0.4])] - #[TestWith([-0.215_119_988_087_815_52, -6.5])] + #[TestWith([0.3894183423086505, 0.4])] + #[TestWith([-0.21511998808781552, -6.5])] public function test_sin(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\sin($number)); } - #[TestWith([2.236_067_977_499_79, 5.0])] - #[TestWith([2.190_890_230_020_664_3, 4.8])] - #[TestWith([0.632_455_532_033_675_9, 0.4])] - #[TestWith([2.549_509_756_796_392_2, 6.5])] - #[TestWith([1.414_213_562_373_095_1, 2])] + #[TestWith([2.23606797749979, 5.0])] + #[TestWith([2.1908902300206643, 4.8])] + #[TestWith([0.6324555320336759, 0.4])] + #[TestWith([2.5495097567963922, 6.5])] + #[TestWith([1.4142135623730951, 2])] #[TestWith([1, 1])] public function test_sqrt(float $expected, float $number): void { @@ -426,7 +426,7 @@ public function test_sum_floats(float $expected, array $numbers): void public static function provide_sum_floats_data(): array { return [ - [116.700_000_000_000_05, [10.9, 5, ...range(0, 9.8798, 0.48)]], + [116.70000000000005, [10.9, 5, ...range(0, 9.8798, 0.48)]], [103.0, [18, 15, ...range(0, 10), 15]], [323.54, [19.5, 15.8, ...range(0.5, 45, 5.98), 52.8, 64]], ]; @@ -447,18 +447,18 @@ public static function provide_sum_data(): array ]; } - #[TestWith([-3.380_515_006_246_586, 5.0, 0.000_000_000_000_01])] - #[TestWith([-11.384_870_654_242_922, 4.8])] + #[TestWith([-3.380515006246586, 5.0, 0.00000000000001])] + #[TestWith([-11.384870654242922, 4.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.422_793_218_738_161_8, 0.4])] - #[TestWith([-0.220_277_200_345_896_82, -6.5])] + #[TestWith([0.4227932187381618, 0.4])] + #[TestWith([-0.22027720034589682, -6.5])] public function test_tan(float $expected, float $number, float $epsilon = PHP_FLOAT_EPSILON): void { $this->assertFloatEquals($expected, Math\tan($number), $epsilon); } #[TestWith(['1010101111001', 5497, 2])] - #[TestWith(['pphlmw9v', 2_014_587_925_987, 36])] + #[TestWith(['pphlmw9v', 2014587925987, 36])] #[TestWith(['zik0zj', Math\INT32_MAX, 36])] #[TestWith(['f', 15, 16])] public function test_to_base(string $expected, int $value, int $to_base): void diff --git a/packages/support/tests/Paginator/PaginatedDataTest.php b/packages/support/tests/Paginator/PaginatedDataTest.php index af99fb09e..48a1c7ea1 100644 --- a/packages/support/tests/Paginator/PaginatedDataTest.php +++ b/packages/support/tests/Paginator/PaginatedDataTest.php @@ -65,7 +65,7 @@ public function it_checks_empty_status(): void public function it_maps_data_while_preserving_pagination(): void { $original = $this->createSamplePaginatedData([1, 2, 3]); - $mapped = $original->map(static fn ($x) => $x * 2); + $mapped = $original->map(fn ($x) => $x * 2); $this->assertSame([2, 4, 6], $mapped->data); $this->assertSame($original->currentPage, $mapped->currentPage); diff --git a/packages/support/tests/Paginator/PaginatorTest.php b/packages/support/tests/Paginator/PaginatorTest.php index bba3dca08..c93a7b3fd 100644 --- a/packages/support/tests/Paginator/PaginatorTest.php +++ b/packages/support/tests/Paginator/PaginatorTest.php @@ -140,7 +140,7 @@ public function test_it_creates_paginated_data_with_callback(): void { $paginator = $this->createPaginator(totalItems: 100, itemsPerPage: 10, currentPage: 3); - $dataFetcher = static function (int $_limit, int $offset): array { + $dataFetcher = function (int $_limit, int $offset): array { return ["item_{$offset}_1", "item_{$offset}_2"]; }; diff --git a/packages/support/tests/Path/PathTest.php b/packages/support/tests/Path/PathTest.php index 6a4fec6d1..16fd78264 100644 --- a/packages/support/tests/Path/PathTest.php +++ b/packages/support/tests/Path/PathTest.php @@ -15,7 +15,7 @@ public function test_glob(array $expected, string $input, string $glob): void $expected, new Path($input) ->glob($glob) - ->map(static fn (string $path) => basename($path)) + ->map(fn (string $path) => basename($path)) ->toArray(), ); } diff --git a/packages/support/tests/Regex/FunctionsTest.php b/packages/support/tests/Regex/FunctionsTest.php index 50c471a30..47e4b2033 100644 --- a/packages/support/tests/Regex/FunctionsTest.php +++ b/packages/support/tests/Regex/FunctionsTest.php @@ -53,8 +53,8 @@ public function test_replace(string $expected, string $subject, string $pattern, public function test_replace_with_callback(): void { - $this->assertSame('Hello, Jon!', replace('Hello, World!', '/World/', static fn () => 'Jon')); - $this->assertSame('Count: 2', replace('Count: 1', '/\d/', static fn (array $matches) => $matches[0] + 1)); + $this->assertSame('Hello, Jon!', replace('Hello, World!', '/World/', fn () => 'Jon')); + $this->assertSame('Count: 2', replace('Count: 1', '/\d/', fn (array $matches) => $matches[0] + 1)); } public function test_replace_with_invalid_pattern(): void @@ -87,7 +87,7 @@ public function test_get_match(): void $this->assertSame('10', get_match('10-abc', '/(\d+)-.*/', match: 1)); $this->assertSame([0 => '10-abc', 1 => '10'], get_match('10-abc', '/(\d+)-.*/')); $this->assertSame('10-abc', get_match('10-abc', '/\d+-.*/', match: 0)); - $this->assertNull(get_match('10-abc', '/\d+-.*/', match: 1)); + $this->assertSame(null, get_match('10-abc', '/\d+-.*/', match: 1)); $this->assertSame( expected: [ diff --git a/packages/support/tests/Str/FunctionsTest.php b/packages/support/tests/Str/FunctionsTest.php index ee16f2315..0f8278043 100644 --- a/packages/support/tests/Str/FunctionsTest.php +++ b/packages/support/tests/Str/FunctionsTest.php @@ -16,7 +16,7 @@ public function test_parse(): void $this->assertSame('1', Str\parse('1')); $this->assertSame('1', Str\parse(1)); $this->assertSame('', Str\parse(new stdClass())); - $this->assertNull(Str\parse(new stdClass(), default: null)); + $this->assertSame(null, Str\parse(new stdClass(), default: null)); $this->assertSame('', Str\parse(new stdClass(), default: '')); $this->assertSame('foo', Str\parse(new stdClass(), default: 'foo')); $this->assertSame('foo', Str\parse(new MutableString('foo'))); diff --git a/packages/support/tests/Str/ManipulatesStringTest.php b/packages/support/tests/Str/ManipulatesStringTest.php index 82627fff6..64778ab8a 100644 --- a/packages/support/tests/Str/ManipulatesStringTest.php +++ b/packages/support/tests/Str/ManipulatesStringTest.php @@ -322,7 +322,7 @@ public function test_matches(): void public function test_replace_regex(): void { $this->assertTrue(str('10-abc')->replaceRegex('/(?\d+-)/', '')->equals('abc')); - $this->assertTrue(str('10-abc')->replaceRegex('/(?\d+-)/', static fn () => '')->equals('abc')); + $this->assertTrue(str('10-abc')->replaceRegex('/(?\d+-)/', fn () => '')->equals('abc')); $this->assertTrue(str('10-abc')->replaceRegex(['/\d/', '/\w/'], ['#', 'X'])->equals('##-XXX')); } @@ -594,7 +594,7 @@ public function test_tap(): void $string = str('foo'); $log = ''; - $result = $string->tap(static function (ImmutableString $string) use (&$log): void { + $result = $string->tap(function (ImmutableString $string) use (&$log): void { $log .= $string->toString(); }); diff --git a/packages/validation/src/Validator.php b/packages/validation/src/Validator.php index a4dd9c2b0..7c692884f 100644 --- a/packages/validation/src/Validator.php +++ b/packages/validation/src/Validator.php @@ -157,7 +157,7 @@ public function validateValueForProperty(PropertyReflector $property, mixed $val return Arr\map( array: $this->validateValue($value, $rules), - map: static fn (FailingRule $rule) => $rule->withKey($key), + map: fn (FailingRule $rule) => $rule->withKey($key), ); } @@ -264,7 +264,7 @@ private function getTranslationKey(Rule|FailingRule $rule): string 'i_pv4' => 'ipv4', 'reg_ex' => 'regex', ]) - ->when($key !== '', static fn ($s) => $s->append('.', $key)) + ->when($key !== '', fn ($s) => $s->append('.', $key)) ->toString(); } diff --git a/packages/validation/tests/Rules/IsJsonStringTest.php b/packages/validation/tests/Rules/IsJsonStringTest.php index dc94da5f0..0003c143f 100644 --- a/packages/validation/tests/Rules/IsJsonStringTest.php +++ b/packages/validation/tests/Rules/IsJsonStringTest.php @@ -37,7 +37,7 @@ public function test_it_allows_to_specify_flags(): void { // Not sure if there is a better way of asserting that a php function was called with a given argument $this->expectException(ValueError::class); - $rule = new IsJsonString(flags: 232_312_312); // we intentionally send something that is not valid + $rule = new IsJsonString(flags: 232312312); // we intentionally send something that is not valid $rule->isValid('{"test": "test"}'); } } diff --git a/packages/validation/tests/Rules/IsPasswordTest.php b/packages/validation/tests/Rules/IsPasswordTest.php index 964d5d84a..09b306e65 100644 --- a/packages/validation/tests/Rules/IsPasswordTest.php +++ b/packages/validation/tests/Rules/IsPasswordTest.php @@ -23,8 +23,8 @@ public function test_defaults(): void public function test_invalid_input(): void { $rule = new IsPassword(); - $this->assertFalse($rule->isValid(123_456_789_012)); - $this->assertFalse($rule->isValid([123_456_789_012])); + $this->assertFalse($rule->isValid(123456789012)); + $this->assertFalse($rule->isValid([123456789012])); } public function test_minimum(): void diff --git a/packages/validation/tests/Rules/ValidateWithTest.php b/packages/validation/tests/Rules/ValidateWithTest.php index 82ea0a373..1a63700b6 100644 --- a/packages/validation/tests/Rules/ValidateWithTest.php +++ b/packages/validation/tests/Rules/ValidateWithTest.php @@ -49,4 +49,11 @@ public function test_non_string_value_fails(): void $this->assertFalse($rule->isValid(null)); $this->assertFalse($rule->isValid(false)); } + + public function test_static_closure_required(): void + { + $this->expectException(\InvalidArgumentException::class); + + new ValidateWith(fn (mixed $value): bool => str_contains((string) $value, '@')); + } } diff --git a/packages/validation/tests/ValidatorTest.php b/packages/validation/tests/ValidatorTest.php index fbd48a5fb..6631364a9 100644 --- a/packages/validation/tests/ValidatorTest.php +++ b/packages/validation/tests/ValidatorTest.php @@ -51,7 +51,7 @@ public function test_validate_value(): void public function test_closure_fails_with_false_response(): void { - $failingRules = $this->validator->validateValue('a', static function (mixed $_) { + $failingRules = $this->validator->validateValue('a', function (mixed $_) { return false; }); @@ -60,7 +60,7 @@ public function test_closure_fails_with_false_response(): void public function test_closure_fails_with_string_response(): void { - $failingRules = $this->validator->validateValue('a', static function (mixed $_) { + $failingRules = $this->validator->validateValue('a', function (mixed $_) { return 'I expected b'; }); @@ -74,7 +74,7 @@ public function test_closure_fails_with_string_response(): void public function test_closure_passes_with_null_response(): void { $validator = $this->validator; - $validator->validateValue('a', static function (mixed $_) { + $validator->validateValue('a', function (mixed $_) { return null; }); @@ -84,7 +84,7 @@ public function test_closure_passes_with_null_response(): void public function test_closure_passes_with_true_response(): void { $validator = $this->validator; - $validator->validateValue('a', static function (mixed $_) { + $validator->validateValue('a', function (mixed $_) { return true; }); @@ -95,11 +95,11 @@ public function test_closure_passes(): void { $validator = $this->validator; - $validator->validateValue('a', static function (mixed $value) { + $validator->validateValue('a', function (mixed $value) { return $value === 'a'; }); - $validator->validateValue('a', static function (mixed $value) { + $validator->validateValue('a', function (mixed $value) { if ($value === 'a') { return true; } diff --git a/packages/view/src/Elements/ElementFactory.php b/packages/view/src/Elements/ElementFactory.php index dc0ad9b19..2ee353519 100644 --- a/packages/view/src/Elements/ElementFactory.php +++ b/packages/view/src/Elements/ElementFactory.php @@ -42,7 +42,7 @@ public function withIsHtml(bool $isHtml): self return $clone; } - public function make(#[\SensitiveParameter] Token $token, Element $parent): ?Element + public function make(Token $token, Element $parent): ?Element { if ( $token->type === TokenType::OPEN_TAG_END diff --git a/packages/view/src/Elements/GenericElement.php b/packages/view/src/Elements/GenericElement.php index ff2e25f6e..b0266a9b7 100644 --- a/packages/view/src/Elements/GenericElement.php +++ b/packages/view/src/Elements/GenericElement.php @@ -15,7 +15,6 @@ final class GenericElement implements Element, WithToken use IsElement; public function __construct( - #[\SensitiveParameter] public readonly Token $token, private readonly string $tag, private readonly bool $isHtml, diff --git a/packages/view/src/Elements/IsElement.php b/packages/view/src/Elements/IsElement.php index e41eeeb84..415566d21 100644 --- a/packages/view/src/Elements/IsElement.php +++ b/packages/view/src/Elements/IsElement.php @@ -37,12 +37,10 @@ public function getAttributes(): array $tailingAttributes = []; foreach ($attributes as $name => $value) { - if (! ($name === ':foreach' || $name === ':if')) { - continue; + if ($name === ':foreach' || $name === ':if') { + unset($attributes[$name]); + $tailingAttributes[$name] = $value; } - - unset($attributes[$name]); - $tailingAttributes[$name] = $value; } // Tailing attributes are reversed because they need to be applied in reverse order diff --git a/packages/view/src/Elements/PhpElement.php b/packages/view/src/Elements/PhpElement.php index db5f2c1a2..a75cb3577 100644 --- a/packages/view/src/Elements/PhpElement.php +++ b/packages/view/src/Elements/PhpElement.php @@ -13,7 +13,6 @@ final class PhpElement implements Element, WithToken use IsElement; public function __construct( - #[\SensitiveParameter] public readonly Token $token, private readonly string $content, ) {} diff --git a/packages/view/src/Elements/RawElement.php b/packages/view/src/Elements/RawElement.php index 08ee565de..cb071cea8 100644 --- a/packages/view/src/Elements/RawElement.php +++ b/packages/view/src/Elements/RawElement.php @@ -15,7 +15,6 @@ final class RawElement implements Element, WithToken use IsElement; public function __construct( - #[\SensitiveParameter] public readonly Token $token, private readonly ?string $tag, private readonly string $content, diff --git a/packages/view/src/Elements/RootElement.php b/packages/view/src/Elements/RootElement.php index 088d6a875..ec54f92a3 100644 --- a/packages/view/src/Elements/RootElement.php +++ b/packages/view/src/Elements/RootElement.php @@ -29,11 +29,9 @@ public function getImports(): array $this->mergeImports($imports, $this->inheritedImports); foreach ($this->children as $child) { - if (! $child instanceof PhpElement) { - continue; + if ($child instanceof PhpElement) { + $this->mergeImports($imports, $child->getImports()); } - - $this->mergeImports($imports, $child->getImports()); } return array_values($imports); diff --git a/packages/view/src/Elements/SlotElement.php b/packages/view/src/Elements/SlotElement.php index ab751db8c..c40a65e81 100644 --- a/packages/view/src/Elements/SlotElement.php +++ b/packages/view/src/Elements/SlotElement.php @@ -13,7 +13,6 @@ final class SlotElement implements Element, WithToken use IsElement; public function __construct( - #[\SensitiveParameter] public readonly Token $token, public readonly string $name, array $attributes = [], diff --git a/packages/view/src/Elements/TemplateElement.php b/packages/view/src/Elements/TemplateElement.php index 596792c1c..ed14d8357 100644 --- a/packages/view/src/Elements/TemplateElement.php +++ b/packages/view/src/Elements/TemplateElement.php @@ -13,7 +13,6 @@ final class TemplateElement implements Element, WithToken use IsElement; public function __construct( - #[\SensitiveParameter] public readonly Token $token, array $attributes = [], ) { diff --git a/packages/view/src/Elements/TextElement.php b/packages/view/src/Elements/TextElement.php index 56d38ad18..41db6c590 100644 --- a/packages/view/src/Elements/TextElement.php +++ b/packages/view/src/Elements/TextElement.php @@ -22,14 +22,14 @@ public function compile(): string // Render {{ ->replaceRegex( regex: '/{{(?.*?)}}/', - replace: static function (array $matches): string { + replace: function (array $matches): string { return sprintf('escape(%s); ?>', $matches['match']); }, ) // Render {!! ->replaceRegex( regex: '/{!!(?.*?)!!}/', - replace: static function (array $matches): string { + replace: function (array $matches): string { return sprintf('', $matches['match']); }, ) diff --git a/packages/view/src/Elements/ViewComponentElement.php b/packages/view/src/Elements/ViewComponentElement.php index 02292a935..4f42d0627 100644 --- a/packages/view/src/Elements/ViewComponentElement.php +++ b/packages/view/src/Elements/ViewComponentElement.php @@ -34,7 +34,6 @@ final class ViewComponentElement implements Element, WithToken private ImmutableArray $viewComponentAttributes; public function __construct( - #[\SensitiveParameter] public readonly Token $token, private readonly Environment $environment, private readonly TempestViewCompiler $compiler, @@ -45,16 +44,16 @@ public function __construct( $this->attributes = $attributes; $this->viewComponentAttributes = arr($attributes) - ->mapWithKeys(static fn (string $value, string $key) => yield str($key)->ltrim(':')->toString() => $value); + ->mapWithKeys(fn (string $value, string $key) => yield str($key)->ltrim(':')->toString() => $value); $this->dataAttributes = arr($attributes) - ->filter(static fn (string $_, string $key) => ! str_starts_with($key, ':')) - ->mapWithKeys(static fn (string $value, string $key) => yield str($key)->camel()->toString() => $value); + ->filter(fn (string $_, string $key) => ! str_starts_with($key, ':')) + ->mapWithKeys(fn (string $value, string $key) => yield str($key)->camel()->toString() => $value); $this->expressionAttributes = arr($attributes) - ->filter(static fn (string $_, string $key) => str_starts_with($key, ':')) - ->filter(static fn (string $_, string $key) => ! in_array($key, [':if', ':else', ':elseif', ':foreach', ':forelse'], strict: true)) - ->mapWithKeys(static fn (string $value, string $key) => yield str($key)->camel()->ltrim(':')->toString() => $value ?: 'true'); + ->filter(fn (string $_, string $key) => str_starts_with($key, ':')) + ->filter(fn (string $_, string $key) => ! in_array($key, [':if', ':else', ':elseif', ':foreach', ':forelse'], strict: true)) + ->mapWithKeys(fn (string $value, string $key) => yield str($key)->camel()->ltrim(':')->toString() => $value ?: 'true'); $this->scopedVariables = arr(); } @@ -107,9 +106,9 @@ public function compile(): string ->prepend( sprintf( '', - $this->dataAttributes->isNotEmpty() ? ', ' . $this->dataAttributes->map(static fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', - $this->expressionAttributes->isNotEmpty() ? ', ' . $this->expressionAttributes->map(static fn (string $_value, string $key) => "\${$key}")->implode(', ') : '', - $this->scopedVariables->isNotEmpty() ? ', ' . $this->scopedVariables->map(static 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('viewCache->getCachedViewPath( $cacheKey, - static fn () => $compiledView->content, + fn () => $compiledView->content, ); $this->viewCache->saveSourceMap($cachePath, $compiledView->sourcePath, $compiledView->lineMap); @@ -172,16 +171,16 @@ public function compile(): string $this->exportAttributesArray(), ViewObjectExporter::export($slots), $this->scopedVariables->isNotEmpty() - ? $this->scopedVariables->map(static fn (string $name) => "'{$name}' => \${$name}")->implode(', ') + ? $this->scopedVariables->map(fn (string $name) => "'{$name}' => \${$name}")->implode(', ') : '', $this->dataAttributes->isNotEmpty() - ? ', ' . $this->dataAttributes->map(static 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(static fn (mixed $value, string $key) => "{$key}: " . $value)->implode(', ') + ? ', ' . $this->expressionAttributes->map(fn (mixed $value, string $key) => "{$key}: " . $value)->implode(', ') : '', $this->scopedVariables->isNotEmpty() - ? ', ' . $this->scopedVariables->map(static fn (string $name) => "{$name}: \${$name}")->implode(', ') + ? ', ' . $this->scopedVariables->map(fn (string $name) => "{$name}: \${$name}")->implode(', ') : '', ); } @@ -216,18 +215,18 @@ private function applyFallthroughAttributes(ImmutableString $compiled): Immutabl $token = TempestViewParser::ast($matches[0])[0]; $attributes = arr($token->htmlAttributes) - ->map(static fn (string $value) => new MutableString($value)); + ->map(fn (string $value) => new MutableString($value)); foreach (['class', 'style', 'id'] as $name) { $attributes = $this->applyFallthroughAttribute($attributes, $name); } $attributeString = $attributes - ->map(static fn (MutableString $value, string $key) => sprintf('%s="%s"', $key, $value->trim())) + ->map(fn (MutableString $value, string $key) => sprintf('%s="%s"', $key, $value->trim())) ->implode(' ') ->when( - static fn (ImmutableString $s) => $s->isNotEmpty(), - static fn (ImmutableString $s) => $s->prepend(' '), + fn (ImmutableString $s) => $s->isNotEmpty(), + fn (ImmutableString $s) => $s->prepend(' '), ); return sprintf('<%s%s>', $matches['tag'], $attributeString); @@ -289,11 +288,9 @@ public function getImports(): array } foreach ($this->getChildren() as $child) { - if (! $child instanceof PhpElement) { - continue; + if ($child instanceof PhpElement) { + $imports = [...$imports, ...$child->getImports()]; } - - $imports = [...$imports, ...$child->getImports()]; } return $imports; diff --git a/packages/view/src/Export/ViewObjectExporter.php b/packages/view/src/Export/ViewObjectExporter.php index 6b4c588d0..9d736e3f7 100644 --- a/packages/view/src/Export/ViewObjectExporter.php +++ b/packages/view/src/Export/ViewObjectExporter.php @@ -17,7 +17,7 @@ public static function export(ExportableViewObject|ImmutableArray $object): stri $object::class, $object ->exportData - ->map(static function (mixed $value, string $key) { + ->map(function (mixed $value, string $key) { $value = self::exportValue($value); return "{$key} : {$value}"; @@ -33,7 +33,7 @@ public static function exportValue(mixed $value): string $value instanceof ImmutableArray => sprintf( 'new \%s([%s])', ImmutableArray::class, - $value->map(static function (mixed $value, string|int $key) { + $value->map(function (mixed $value, string|int $key) { $key = is_int($key) ? $key : "'{$key}'"; return $key . ' => ' . rtrim(self::exportValue($value), ';'); diff --git a/packages/view/src/Initializers/ViewCacheInitializer.php b/packages/view/src/Initializers/ViewCacheInitializer.php index f1e3c888c..14befdca9 100644 --- a/packages/view/src/Initializers/ViewCacheInitializer.php +++ b/packages/view/src/Initializers/ViewCacheInitializer.php @@ -15,9 +15,11 @@ final class ViewCacheInitializer implements Initializer #[Singleton] public function initialize(Container $container): ViewCache { - return new ViewCache( + $viewCache = new ViewCache( enabled: $this->shouldCacheBeEnabled(), ); + + return $viewCache; } private function shouldCacheBeEnabled(): bool diff --git a/packages/view/src/Parser/TempestViewAst.php b/packages/view/src/Parser/TempestViewAst.php index 5921e892a..379e9564c 100644 --- a/packages/view/src/Parser/TempestViewAst.php +++ b/packages/view/src/Parser/TempestViewAst.php @@ -14,7 +14,7 @@ public function __construct( private(set) bool $isHtml = true; - public function add(#[\SensitiveParameter] Token $token): self + public function add(Token $token): self { if ($token->type === TokenType::XML) { $this->isHtml = false; @@ -28,7 +28,7 @@ public function add(#[\SensitiveParameter] Token $token): self public function compile(): string { return implode('', array_map( - static fn (#[\SensitiveParameter] Token $token) => $token->compile(), + fn (Token $token) => $token->compile(), iterator_to_array($this->tokens), )); } diff --git a/packages/view/src/Parser/TempestViewCompiler.php b/packages/view/src/Parser/TempestViewCompiler.php index 65bb9e5d6..0a7b21d70 100644 --- a/packages/view/src/Parser/TempestViewCompiler.php +++ b/packages/view/src/Parser/TempestViewCompiler.php @@ -118,7 +118,7 @@ private function retrieveTemplate(string|View $view): array $searchPathOptions = [ ...$searchPathOptions, ...arr($this->discoveryLocations) - ->map(static fn (DiscoveryLocation $discoveryLocation) => path($discoveryLocation->path, $path)->toString()) + ->map(fn (DiscoveryLocation $discoveryLocation) => path($discoveryLocation->path, $path)->toString()) ->toArray(), ]; @@ -273,7 +273,7 @@ private function cleanupCompiled(string $compiled, ?string $sourcePath, array $i $imports[$import] = $import; } - $compiled = $compiled->replaceRegex("/^\s*use (function )?.*;/m", static function (array $matches) use (&$imports) { + $compiled = $compiled->replaceRegex("/^\s*use (function )?.*;/m", function (array $matches) use (&$imports) { // The import contains escaped slashes, meaning it's a var_exported string; we can ignore those if (str_contains($matches[0], '\\\\')) { return $matches[0]; diff --git a/packages/view/src/Parser/TempestViewParser.php b/packages/view/src/Parser/TempestViewParser.php index 85455a22b..77309107b 100644 --- a/packages/view/src/Parser/TempestViewParser.php +++ b/packages/view/src/Parser/TempestViewParser.php @@ -66,7 +66,7 @@ public function parse(): TempestViewAst return $ast; } - private function openScope(#[\SensitiveParameter] Token $token): void + private function openScope(Token $token): void { $this->scope[] = $token; } diff --git a/packages/view/src/Parser/Token.php b/packages/view/src/Parser/Token.php index 3ae394733..007196160 100644 --- a/packages/view/src/Parser/Token.php +++ b/packages/view/src/Parser/Token.php @@ -60,7 +60,7 @@ public function getAttribute(string $name): null|string|bool return $this->htmlAttributes[$name] ?? null; } - public function addAttribute(#[\SensitiveParameter] Token $token): void + public function addAttribute(Token $token): void { $this->rawAttributes[] = $token; @@ -71,18 +71,18 @@ public function addAttribute(#[\SensitiveParameter] Token $token): void } } - public function setAttributeValue(string $name, #[\SensitiveParameter] Token $token): void + public function setAttributeValue(string $name, Token $token): void { $this->rawAttributes[] = $token; $this->htmlAttributes[$this->attributeName($name)] = $this->attributeValue($token->content); } - public function setEndingToken(#[\SensitiveParameter] Token $endingToken): void + public function setEndingToken(Token $endingToken): void { $this->endingToken = $endingToken; } - public function setClosingToken(#[\SensitiveParameter] Token $closingToken): void + public function setClosingToken(Token $closingToken): void { if ($closingToken->tag && $this->tag !== $closingToken->tag) { throw new ClosingTagWasInvalid($this->tag, $closingToken->tag); diff --git a/packages/view/src/Parser/TokenCollection.php b/packages/view/src/Parser/TokenCollection.php index 4044d4088..b2f63a95a 100644 --- a/packages/view/src/Parser/TokenCollection.php +++ b/packages/view/src/Parser/TokenCollection.php @@ -16,7 +16,7 @@ public function __construct( private array $tokens = [], ) {} - public function add(#[\SensitiveParameter] Token $token): self + public function add(Token $token): self { $this->tokens[] = $token; @@ -33,7 +33,7 @@ public function __debugInfo(): array return [ implode( ', ' . PHP_EOL, - array_map(static fn (#[\SensitiveParameter] Token $token) => $token->__debugInfo()[0], $this->tokens), + array_map(fn (Token $token) => $token->__debugInfo()[0], $this->tokens), ), ]; } diff --git a/packages/view/src/Slot.php b/packages/view/src/Slot.php index 28108e485..6d65f56f8 100644 --- a/packages/view/src/Slot.php +++ b/packages/view/src/Slot.php @@ -49,7 +49,7 @@ public function __get(string $name): mixed return $this->attributes[$name] ?? null; } - public static function named(#[\SensitiveParameter] Token $token): self + public static function named(Token $token): self { $name = $token->getAttribute('name'); $attributes = $token->htmlAttributes; diff --git a/packages/view/src/ViewCachePool.php b/packages/view/src/ViewCachePool.php index c0063ace6..81e68393d 100644 --- a/packages/view/src/ViewCachePool.php +++ b/packages/view/src/ViewCachePool.php @@ -58,7 +58,7 @@ public function clear(): bool $path = path($this->directory); if ($path->isDirectory()) { - $path->glob('/*.php')->each(static fn (string $file) => unlink($file)); + $path->glob('/*.php')->each(fn (string $file) => unlink($file)); Filesystem\delete_directory($this->directory); } diff --git a/packages/view/src/functions.php b/packages/view/src/functions.php index ce34bc3fd..49c43d5f0 100644 --- a/packages/view/src/functions.php +++ b/packages/view/src/functions.php @@ -4,6 +4,9 @@ namespace Tempest\View; +use Tempest\View\GenericView; +use Tempest\View\View; + /** * Returns a {@see View} instance for the specified `$path`. */ diff --git a/packages/view/tests/ViewCachePoolTest.php b/packages/view/tests/ViewCachePoolTest.php index 5e9029ede..bb87c8c71 100644 --- a/packages/view/tests/ViewCachePoolTest.php +++ b/packages/view/tests/ViewCachePoolTest.php @@ -33,7 +33,7 @@ protected function tearDown(): void $directory = path(self::DIRECTORY); if ($directory->isDirectory()) { - $directory->glob('/*.php')->each(static fn (string $file) => unlink($file)); + $directory->glob('/*.php')->each(fn (string $file) => unlink($file)); rmdir(self::DIRECTORY); } diff --git a/packages/vite/src/Installer/ViteInstaller.php b/packages/vite/src/Installer/ViteInstaller.php index 8110132ca..4c428a5cd 100644 --- a/packages/vite/src/Installer/ViteInstaller.php +++ b/packages/vite/src/Installer/ViteInstaller.php @@ -69,7 +69,7 @@ public function install(): void } // Installs package.json scripts - $this->updateJson(root_path('package.json'), static function (array $json) { + $this->updateJson(root_path('package.json'), function (array $json) { $json['type'] = 'module'; $json['scripts'] ??= []; $json['scripts'] = [ diff --git a/packages/vite/src/Manifest/Manifest.php b/packages/vite/src/Manifest/Manifest.php index 98026bd2b..1f82888e3 100644 --- a/packages/vite/src/Manifest/Manifest.php +++ b/packages/vite/src/Manifest/Manifest.php @@ -25,11 +25,11 @@ private function __construct( public static function fromArray(array $chunks): self { - $chunks = arr($chunks)->map(static fn (array $value) => Chunk::fromArray($value)); + $chunks = arr($chunks)->map(fn (array $value) => Chunk::fromArray($value)); return new self( chunks: $chunks, - entrypoints: $chunks->filter(static fn (Chunk $entry) => $entry->isEntry), + entrypoints: $chunks->filter(fn (Chunk $entry) => $entry->isEntry), ); } } diff --git a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php index 8ce64d27f..ab8b83a1c 100644 --- a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php +++ b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php @@ -59,8 +59,8 @@ private function fileToAssetPath(string $file): string { return str($file) ->when( - condition: static fn ($file) => $file->startsWith('./'), - callback: static fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), + condition: fn ($file) => $file->startsWith('./'), + callback: fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), ) ->replace('\\', '/') // `realpath` makes slashes backwards, so replacements below wouldn't work ->replaceStart(root_path('public'), '') diff --git a/packages/vite/src/TagsResolver/ManifestTagsResolver.php b/packages/vite/src/TagsResolver/ManifestTagsResolver.php index 42ee96247..f5f526307 100644 --- a/packages/vite/src/TagsResolver/ManifestTagsResolver.php +++ b/packages/vite/src/TagsResolver/ManifestTagsResolver.php @@ -91,7 +91,7 @@ private function getStyleTags(Chunk $chunk): array return array_merge( $styleChunks, - array_map(static fn (string $path) => ['file' => $path], $chunk->css), + array_map(fn (string $path) => ['file' => $path], $chunk->css), ); }; @@ -179,7 +179,7 @@ private function resolvePrefetchingScript(Chunk $chunk): ?string }; $assets = array_values(array_map( - callback: static fn (array $asset) => array_map('strval', $asset), + callback: fn (array $asset) => array_map('strval', $asset), array: array_unique($findPrefetchableAssets($chunk), flags: SORT_REGULAR), )); @@ -253,8 +253,8 @@ private function fileToAssetPath(string $file): string { return str($file) ->when( - condition: static fn ($file) => $file->startsWith('./'), - callback: static fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), + condition: fn ($file) => $file->startsWith('./'), + callback: fn ($file) => str(Filesystem\normalize_path(root_path($file->toString()))), ) ->replaceStart(root_path('public'), '') ->replaceStart(root_path(), '') diff --git a/packages/vite/src/ViteDiscovery.php b/packages/vite/src/ViteDiscovery.php index 4ab4d0ed2..ffbde22b3 100644 --- a/packages/vite/src/ViteDiscovery.php +++ b/packages/vite/src/ViteDiscovery.php @@ -9,6 +9,7 @@ use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; use Tempest\Reflection\ClassReflector; +use Tempest\Vite\ViteConfig; use function Tempest\Support\str; diff --git a/packages/vite/src/functions.php b/packages/vite/src/functions.php index 217fb0e4d..b217c0504 100644 --- a/packages/vite/src/functions.php +++ b/packages/vite/src/functions.php @@ -4,6 +4,8 @@ namespace Tempest\Vite; +use Tempest\Vite\Vite; + use function Tempest\Container\get; /** diff --git a/src/Tempest/Framework/Commands/ConfigShowCommand.php b/src/Tempest/Framework/Commands/ConfigShowCommand.php index 90427dab7..aba4447db 100644 --- a/src/Tempest/Framework/Commands/ConfigShowCommand.php +++ b/src/Tempest/Framework/Commands/ConfigShowCommand.php @@ -103,14 +103,14 @@ private function searchConfigFile(array $configs): string $return = $this->console->search( label: 'Which configuration file would you like to view?', - search: static function (string $query) use ($data): array { + search: function (string $query) use ($data): array { if ($query === '') { return $data; } return array_filter( array: $data, - callback: static fn (string $path) => str_contains($path, $query), + callback: fn (string $path) => str_contains($path, $query), ); }, default: $data[0], diff --git a/src/Tempest/Framework/Commands/MetaViewComponentCommand.php b/src/Tempest/Framework/Commands/MetaViewComponentCommand.php index 5f47752cd..1ce98f187 100644 --- a/src/Tempest/Framework/Commands/MetaViewComponentCommand.php +++ b/src/Tempest/Framework/Commands/MetaViewComponentCommand.php @@ -62,7 +62,7 @@ private function resolveViewComponent(string $viewComponent): ?ViewComponent if (is_file($viewComponent)) { return array_find( array: $this->viewConfig->viewComponents, - callback: static fn ($registeredViewComponent) => $registeredViewComponent->file === $viewComponent, + callback: fn ($registeredViewComponent) => $registeredViewComponent->file === $viewComponent, ); } @@ -74,7 +74,7 @@ private function resolveSlots(ViewComponent $viewComponent): ImmutableArray preg_match_all('/[\w-]+)")?((\s*\/>)|>(?(.|\n)*?)<\/x-slot>)/', $viewComponent->contents, $matches); return arr($matches['name']) - ->mapWithKeys(static fn (string $name) => yield $name => $name === '' ? Slot::DEFAULT : $name) + ->mapWithKeys(fn (string $name) => yield $name => $name === '' ? Slot::DEFAULT : $name) ->values(); } @@ -82,19 +82,19 @@ private function resolveVariables(ViewComponent $viewComponent): ImmutableArray { return str($viewComponent->contents) ->matchAll('/^\s*\*\s*@var.*$/m') - ->map(static fn (array $matches) => str($matches[0])) - ->map(static fn (ImmutableString $line) => $line->replaceRegex('/^\s*\*\s*@var\s*/', '')) - ->map(static fn (ImmutableString $line) => $line->trim()) - ->map(static fn (ImmutableString $line) => $line->explode(limit: 3)) + ->map(fn (array $matches) => str($matches[0])) + ->map(fn (ImmutableString $line) => $line->replaceRegex('/^\s*\*\s*@var\s*/', '')) + ->map(fn (ImmutableString $line) => $line->trim()) + ->map(fn (ImmutableString $line) => $line->explode(limit: 3)) ->mapWithKeys( - static fn (ImmutableArray $parts) => yield $parts[1] => [ + fn (ImmutableArray $parts) => yield $parts[1] => [ 'type' => $parts[0], 'name' => $parts[1], 'attributeName' => str($parts[1])->kebab()->ltrim('$'), 'description' => $parts[2] ?? null, ], ) - ->filter(static fn (array $parts) => ! in_array($parts['name'], ['$this', '$attributes', '$slots'], strict: true)) + ->filter(fn (array $parts) => ! in_array($parts['name'], ['$this', '$attributes', '$slots'], strict: true)) ->values(); } } diff --git a/src/Tempest/Framework/Installers/FrameworkInstaller.php b/src/Tempest/Framework/Installers/FrameworkInstaller.php index 966531470..b6174f248 100644 --- a/src/Tempest/Framework/Installers/FrameworkInstaller.php +++ b/src/Tempest/Framework/Installers/FrameworkInstaller.php @@ -37,7 +37,7 @@ public function install(): void $this->publish( source: __DIR__ . '/tempest', destination: root_path('tempest'), - callback: static function (string $_, string $destination): void { + callback: function (string $_, string $destination): void { if (PHP_OS_FAMILY !== 'Windows') { /** @phpstan-ignore-next-line */ exec("chmod +x {$destination}"); diff --git a/src/Tempest/Framework/Installers/ViewComponentsInstaller.php b/src/Tempest/Framework/Installers/ViewComponentsInstaller.php index 7313c371f..630036b32 100644 --- a/src/Tempest/Framework/Installers/ViewComponentsInstaller.php +++ b/src/Tempest/Framework/Installers/ViewComponentsInstaller.php @@ -25,7 +25,7 @@ public function __construct( public function install(): void { $searchOptions = arr($this->viewConfig->viewComponents) - ->filter(static fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent); + ->filter(fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent); if ($searchOptions->isEmpty()) { $this->error('No installable view vendor components found.'); diff --git a/src/Tempest/Framework/Testing/Http/HttpRouterTester.php b/src/Tempest/Framework/Testing/Http/HttpRouterTester.php index 10a377bff..f5bf6cddf 100644 --- a/src/Tempest/Framework/Testing/Http/HttpRouterTester.php +++ b/src/Tempest/Framework/Testing/Http/HttpRouterTester.php @@ -275,7 +275,7 @@ private function createHeaders(array $headers = []): array { $key = array_find_key( array: $headers, - callback: static fn (mixed $_, string $headerKey): bool => strcasecmp($headerKey, 'accept') === 0, + callback: fn (mixed $_, string $headerKey): bool => strcasecmp($headerKey, 'accept') === 0, ); if ($this->contentType !== null) { diff --git a/src/Tempest/Framework/Testing/Http/TestResponseHelper.php b/src/Tempest/Framework/Testing/Http/TestResponseHelper.php index 11e2533b7..497669ed0 100644 --- a/src/Tempest/Framework/Testing/Http/TestResponseHelper.php +++ b/src/Tempest/Framework/Testing/Http/TestResponseHelper.php @@ -214,7 +214,7 @@ public function assertHasCookie(string $key, null|string|Closure $value = null): /** @var array */ $cookies = Arr\map_with_keys( array: $this->response->getHeader('set-cookie')->values, - map: static function (string $cookie) { + map: function (string $cookie) { $cookie = Cookie::createFromString($cookie); yield $cookie->key => $cookie; }, @@ -247,7 +247,7 @@ public function assertDoesNotHaveCookie(string $key, null|string|Closure $value /** @var array */ $cookies = Arr\map_with_keys( array: $this->response->getHeader('set-cookie')->values ?? [], - map: static function (string $cookie) { + map: function (string $cookie) { $cookie = Cookie::createFromString($cookie); yield $cookie->key => $cookie; }, @@ -367,7 +367,7 @@ public function assertHasNoValidationsErrors(): self Assert::assertEmpty( actual: $validationErrors, message: arr($validationErrors) - ->map(static fn (array $failingRules, string $key) => $key . ': ' . arr($failingRules)->map(static fn (Rule $rule) => $rule::class)->implode(', ')) + ->map(fn (array $failingRules, string $key) => $key . ': ' . arr($failingRules)->map(fn (Rule $rule) => $rule::class)->implode(', ')) ->implode(', ') ->prepend('There should be no validation errors, but there were: ') ->toString(), diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index 58f7347e4..ef3d79d1d 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -168,8 +168,8 @@ protected function setupKernel(): self protected function setupConsole(): self { $this->console = new ConsoleTester($this->container); - $this->container->singleton(OutputBuffer::class, static fn () => new MemoryOutputBuffer()); - $this->container->singleton(StdoutOutputBuffer::class, static fn () => new MemoryOutputBuffer()); + $this->container->singleton(OutputBuffer::class, fn () => new MemoryOutputBuffer()); + $this->container->singleton(StdoutOutputBuffer::class, fn () => new MemoryOutputBuffer()); return $this; } @@ -203,8 +203,8 @@ protected function setupTesters(): self protected function setupBaseRequest(): self { $request = new GenericRequest(Method::GET, '/', []); - $this->container->singleton(Request::class, static fn () => $request); - $this->container->singleton(GenericRequest::class, static fn () => $request); + $this->container->singleton(Request::class, fn () => $request); + $this->container->singleton(GenericRequest::class, fn () => $request); return $this; } @@ -213,7 +213,7 @@ protected function clock(DateTimeInterface|string $now = 'now'): MockClock { $clock = new MockClock($now); - $this->container->singleton(Clock::class, static fn () => $clock); + $this->container->singleton(Clock::class, fn () => $clock); return $clock; } diff --git a/src/Tempest/Framework/Testing/ViteTester.php b/src/Tempest/Framework/Testing/ViteTester.php index 0d5868d87..cb9b5341c 100644 --- a/src/Tempest/Framework/Testing/ViteTester.php +++ b/src/Tempest/Framework/Testing/ViteTester.php @@ -54,7 +54,7 @@ public function clearCaches(): self */ public function preventTagResolution(): self { - $this->container->register(TagsResolver::class, static fn () => new NullTagsResolver()); + $this->container->register(TagsResolver::class, fn () => new NullTagsResolver()); return $this; } @@ -150,7 +150,7 @@ public function call(callable $callback, array $files, bool $manifest = false, ? $this->container->config($actualViteConfig); if ($tagsResolver) { - $this->container->register(TagsResolver::class, static fn () => $tagsResolver); + $this->container->register(TagsResolver::class, fn () => $tagsResolver); } delete_directory($temporaryRootDirectory); diff --git a/tests/Benchmark/Container/ContainerBench.php b/tests/Benchmark/Container/ContainerBench.php index 203c7f9bc..8dedc0ae4 100644 --- a/tests/Benchmark/Container/ContainerBench.php +++ b/tests/Benchmark/Container/ContainerBench.php @@ -88,7 +88,7 @@ public function benchRegisterDefinition(): void { $container = new GenericContainer(); - $container->register(ContainerObjectA::class, static fn () => new ContainerObjectA()); + $container->register(ContainerObjectA::class, fn () => new ContainerObjectA()); } #[BeforeMethods('setUpInitializer')] @@ -145,7 +145,7 @@ public function benchRegisterClosureSingleton(): void { $container = new GenericContainer(); - $container->singleton(ContainerObjectA::class, static fn () => new ContainerObjectA()); + $container->singleton(ContainerObjectA::class, fn () => new ContainerObjectA()); } #[BeforeMethods('setUp')] @@ -154,7 +154,7 @@ public function benchRegisterClosureSingleton(): void #[Warmup(10)] public function benchInvokeClosure(): void { - $this->container->invoke(static fn (ContainerObjectA $a) => $a); + $this->container->invoke(fn (ContainerObjectA $a) => $a); } public function setUpSingletonInstance(): void @@ -166,7 +166,7 @@ public function setUpSingletonInstance(): void public function setUpDefinition(): void { $this->setUp(); - $this->container->register(ContainerObjectA::class, static fn () => new ContainerObjectA()); + $this->container->register(ContainerObjectA::class, fn () => new ContainerObjectA()); } public function setUpInitializer(): void @@ -184,6 +184,6 @@ public function setUpDynamicInitializer(): void public function setUpClosureSingleton(): void { $this->setUp(); - $this->container->singleton(ContainerObjectA::class, static fn () => new ContainerObjectA()); + $this->container->singleton(ContainerObjectA::class, fn () => new ContainerObjectA()); } } diff --git a/tests/Benchmark/Extension/MarkdownExtension.php b/tests/Benchmark/Extension/MarkdownExtension.php index 07ed61a88..bcb2472b7 100644 --- a/tests/Benchmark/Extension/MarkdownExtension.php +++ b/tests/Benchmark/Extension/MarkdownExtension.php @@ -19,7 +19,7 @@ public function load(Container $container): void { $container->register( MarkdownRenderer::class, - static function (Container $container) { + function (Container $container) { return new MarkdownRenderer( $container->get(ConsoleExtension::SERVICE_OUTPUT_STD), $container->get(ExpressionExtension::SERVICE_PLAIN_PRINTER), diff --git a/tests/Benchmark/Extension/MarkdownRenderer.php b/tests/Benchmark/Extension/MarkdownRenderer.php index 6d045065d..565c59c2a 100644 --- a/tests/Benchmark/Extension/MarkdownRenderer.php +++ b/tests/Benchmark/Extension/MarkdownRenderer.php @@ -110,7 +110,7 @@ private function renderRow(array $cells): string private function renderSeparatorRow(array $columns): string { return $this->renderRow(array_map( - static fn (string $column): string => str_repeat('-', max(3, mb_strlen($column))), + fn (string $column): string => str_repeat('-', max(3, mb_strlen($column))), $columns, )); } @@ -128,7 +128,7 @@ private function compactAggregateReportTable(array $columns, array $rows): array return [$columns, $rows, false]; } - $rows = array_map(static function (array $row) use ($columnIndexes): array { + $rows = array_map(function (array $row) use ($columnIndexes): array { $set = trim((string) $row[$columnIndexes['set']]); return [ @@ -189,7 +189,7 @@ private function resolveCompactSourceColumnIndexes(array $columns): ?array { $columnIndexes = array_flip($columns); - if (array_any(self::COMPACT_SOURCE_COLUMNS, static fn ($column) => ! array_key_exists($column, $columnIndexes))) { + if (array_any(self::COMPACT_SOURCE_COLUMNS, fn ($column) => ! array_key_exists($column, $columnIndexes))) { return null; } diff --git a/tests/Benchmark/Http/GenericRouterBench.php b/tests/Benchmark/Http/GenericRouterBench.php index 44bcb60ce..d99bcb26d 100644 --- a/tests/Benchmark/Http/GenericRouterBench.php +++ b/tests/Benchmark/Http/GenericRouterBench.php @@ -47,9 +47,9 @@ public function setUp(): void $matcher = new GenericRouteMatcher($routeConfig); - $container->singleton(Container::class, static fn () => $container); - $container->singleton(RouteMatcher::class, static fn () => $matcher); - $container->singleton(RouteConfig::class, static fn () => $routeConfig); + $container->singleton(Container::class, fn () => $container); + $container->singleton(RouteMatcher::class, fn () => $matcher); + $container->singleton(RouteConfig::class, fn () => $routeConfig); $this->router = new GenericRouter($container, $routeConfig); @@ -61,9 +61,9 @@ public function setUp(): void $containerWithoutExceptionMiddleware = new GenericContainer(); $matcherWithoutExceptionMiddleware = new GenericRouteMatcher($routeConfigWithoutExceptionMiddleware); - $containerWithoutExceptionMiddleware->singleton(Container::class, static fn () => $containerWithoutExceptionMiddleware); - $containerWithoutExceptionMiddleware->singleton(RouteMatcher::class, static fn () => $matcherWithoutExceptionMiddleware); - $containerWithoutExceptionMiddleware->singleton(RouteConfig::class, static fn () => $routeConfigWithoutExceptionMiddleware); + $containerWithoutExceptionMiddleware->singleton(Container::class, fn () => $containerWithoutExceptionMiddleware); + $containerWithoutExceptionMiddleware->singleton(RouteMatcher::class, fn () => $matcherWithoutExceptionMiddleware); + $containerWithoutExceptionMiddleware->singleton(RouteConfig::class, fn () => $routeConfigWithoutExceptionMiddleware); $this->routerWithoutExceptionMiddleware = new GenericRouter($containerWithoutExceptionMiddleware, $routeConfigWithoutExceptionMiddleware); } diff --git a/tests/Fixtures/Controllers/DeferController.php b/tests/Fixtures/Controllers/DeferController.php index a486357b9..8a0b6bb27 100644 --- a/tests/Fixtures/Controllers/DeferController.php +++ b/tests/Fixtures/Controllers/DeferController.php @@ -17,7 +17,7 @@ final class DeferController #[Get('/defer')] public function __invoke(): Response { - defer(static function (): void { + defer(function (): void { // ll('defer start'); // sleep(2); // ll('defer done'); diff --git a/tests/Integration/Auth/AccessControl/HasPolicyTests.php b/tests/Integration/Auth/AccessControl/HasPolicyTests.php index 493e3a20f..e0dfdae9c 100644 --- a/tests/Integration/Auth/AccessControl/HasPolicyTests.php +++ b/tests/Integration/Auth/AccessControl/HasPolicyTests.php @@ -16,11 +16,9 @@ public function registerPoliciesFrom(string|object $class): self $config = $this->container->get(AuthConfig::class); foreach (new ClassReflector($class)->getPublicMethods() as $method) { - if (! ($policy = $method->getAttribute(Policy::class))) { - continue; + if ($policy = $method->getAttribute(Policy::class)) { + $config->registerPolicy($method, $policy); } - - $config->registerPolicy($method, $policy); } return $this; diff --git a/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php b/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php index a48c45181..87279d839 100644 --- a/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php +++ b/tests/Integration/Auth/OAuth/TestingOAuthClientTest.php @@ -246,7 +246,7 @@ public function abstracted_flow(): void method: Method::GET, uri: Uri\set_query('/oauth/callback', code: 'authorization-code-from-github', state: $client->getState()), ), - map: static fn (OAuthUser $user): User => query(User::class)->updateOrCreate([ + map: fn (OAuthUser $user): User => query(User::class)->updateOrCreate([ 'github_id' => $user->id, ], [ 'email' => $user->email, diff --git a/tests/Integration/Cache/CacheTest.php b/tests/Integration/Cache/CacheTest.php index 3486a68e6..3d11de9e6 100644 --- a/tests/Integration/Cache/CacheTest.php +++ b/tests/Integration/Cache/CacheTest.php @@ -38,7 +38,7 @@ public function test_put(): void $item = $pool->getItem('a'); $this->assertFalse($item->isHit()); - $this->assertNull($item->get()); + $this->assertSame(null, $item->get()); $item = $pool->getItem('b'); $this->assertTrue($item->isHit()); @@ -152,7 +152,7 @@ public function test_get(): void $clock->plus($interval); - $this->assertNull($cache->get('a')); + $this->assertSame(null, $cache->get('a')); $this->assertSame('b', $cache->get('b')); } @@ -171,7 +171,7 @@ public function test_get_many(): void $values = $cache->getMany(['foo2', 'foo3']); $this->assertSame('bar2', $values['foo2']); - $this->assertNull($values['foo3']); + $this->assertSame(null, $values['foo3']); } public function test_resolve(): void @@ -180,18 +180,18 @@ public function test_resolve(): void $clock = $this->clock(); $cache = new GenericCache(new ArrayAdapter(clock: $clock->toPsrClock())); - $a = $cache->resolve('a', static fn () => 'a', $clock->now()->plus($interval)); + $a = $cache->resolve('a', fn () => 'a', $clock->now()->plus($interval)); $this->assertSame('a', $a); - $b = $cache->resolve('b', static fn () => 'b'); + $b = $cache->resolve('b', fn () => 'b'); $this->assertSame('b', $b); $clock->plus($interval); - $this->assertNull($cache->get('a')); + $this->assertSame(null, $cache->get('a')); $this->assertSame('b', $cache->get('b')); - $b = $cache->resolve('b', static fn () => 'b'); + $b = $cache->resolve('b', fn () => 'b'); $this->assertSame('b', $b); } @@ -227,7 +227,7 @@ public function test_stale_while_revalidate(): void ); // Cache value can be stale for 1min, but will be refreshed in the background - $retrieve = static fn (string $value) => $cache->resolve('test', static fn () => $value, expiration: Duration::minute(), stale: Duration::minute()); + $retrieve = fn (string $value) => $cache->resolve('test', fn () => $value, expiration: Duration::minute(), stale: Duration::minute()); // We fetch the value within the allowed duration, there is no deferring $this->assertSame('update1', $retrieve('update1')); diff --git a/tests/Integration/Cache/LockTest.php b/tests/Integration/Cache/LockTest.php index 38f6f210c..63db4ce91 100644 --- a/tests/Integration/Cache/LockTest.php +++ b/tests/Integration/Cache/LockTest.php @@ -82,7 +82,7 @@ public function test_lock_execution_without_timeout(): void $lock = $cache->lock('processing'); - $this->assertTrue($lock->execute(static fn () => true)); // @phpstan-ignore method.alreadyNarrowedType + $this->assertTrue($lock->execute(fn () => true)); // @phpstan-ignore method.alreadyNarrowedType $this->assertFalse($lock->release()); } @@ -97,7 +97,7 @@ public function test_lock_execution_when_already_locked_by_another_owner(): void $externalLock->acquire(); // Try executing a callback, should timeout instantly - $cache->lock('processing')->execute(static fn () => true); + $cache->lock('processing')->execute(fn () => true); } public function test_lock_execution_when_already_locked_by_another_owner_with_timeout(): void @@ -114,7 +114,7 @@ public function test_lock_execution_when_already_locked_by_another_owner_with_ti // Try executing a callback for the specified duration /** @phpstan-ignore-next-line */ - $this->assertTrue($cache->lock('processing')->execute(static fn () => true, wait: Duration::hours(1))); + $this->assertTrue($cache->lock('processing')->execute(fn () => true, wait: Duration::hours(1))); } public function test_lock_can_be_reacquired_after_expiration(): void diff --git a/tests/Integration/CommandBus/AsyncCommandTest.php b/tests/Integration/CommandBus/AsyncCommandTest.php index 0cc58baa5..2899542c3 100644 --- a/tests/Integration/CommandBus/AsyncCommandTest.php +++ b/tests/Integration/CommandBus/AsyncCommandTest.php @@ -26,7 +26,7 @@ public function test_async_commands_are_stored_and_handled_afterwards(): void $this->container->singleton( CommandRepository::class, - static fn () => $repository, + fn () => $repository, ); MyAsyncCommandHandler::$isHandled = false; @@ -75,7 +75,7 @@ public function test_async_failed_command_monitor(): void $process->stop(); arr(glob(__DIR__ . '/../../../packages/command-bus/src/stored-commands/*.failed.txt')) - ->each(static function (string $filename): void { + ->each(function (string $filename): void { unlink($filename); }); } @@ -83,7 +83,7 @@ public function test_async_failed_command_monitor(): void private function getOutput(Process $process): string { $pattern = array_map( - static fn (TerminalStyle $consoleStyle) => TerminalStyle::ESC->value . $consoleStyle->value, + fn (TerminalStyle $consoleStyle) => TerminalStyle::ESC->value . $consoleStyle->value, TerminalStyle::cases(), ); diff --git a/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php b/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php index 9d1063c61..ed0d6ccbf 100644 --- a/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php +++ b/tests/Integration/Console/Actions/ExecuteConsoleCommandTest.php @@ -25,7 +25,7 @@ public function test_command_specific_middleware(): void public function test_command_specific_middleware_through_console(): void { $this->console - ->call(static fn (GenericConsole $console) => $console->call('with:middleware')) + ->call(fn (GenericConsole $console) => $console->call('with:middleware')) ->assertContains('from middleware') ->assertContains('from command'); } diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index eb919e0f2..2c84475c4 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -94,8 +94,8 @@ public static function middleware_type_provider(): array $cases = MiddlewareType::cases(); return array_combine( - keys: array_map(static fn (MiddlewareType $case) => $case->value, $cases), - values: array_map(static fn (MiddlewareType $case) => [ + keys: array_map(fn (MiddlewareType $case) => $case->value, $cases), + values: array_map(fn (MiddlewareType $case) => [ 'middlewareType' => $case, 'middlewareInterface' => $case->relatedInterface(), ], $cases), diff --git a/tests/Integration/Console/Components/ProgressBarComponentTest.php b/tests/Integration/Console/Components/ProgressBarComponentTest.php index 704e0f819..c28781e44 100644 --- a/tests/Integration/Console/Components/ProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/ProgressBarComponentTest.php @@ -22,7 +22,7 @@ public function test_progress_bar_component(): void $terminal = new Terminal($console); $component = new ProgressBarComponent( data: ['a', 'b', 'c', 'd'], - handler: static fn (string $input) => $input . $input, + handler: fn (string $input) => $input . $input, ); $generator = $component->render($terminal); @@ -55,8 +55,8 @@ public function test_progress_bar_with_format(): void $terminal = new Terminal($console); $component = new ProgressBarComponent( data: ['a', 'b', 'c', 'd'], - handler: static fn (string $input) => $input, - format: static fn (int $step) => str_repeat(':', $step), + handler: fn (string $input) => $input, + format: fn (int $step) => str_repeat(':', $step), ); $generator = $component->render($terminal); diff --git a/tests/Integration/Console/Components/SearchComponentTest.php b/tests/Integration/Console/Components/SearchComponentTest.php index b0024ef54..3fa3deb9b 100644 --- a/tests/Integration/Console/Components/SearchComponentTest.php +++ b/tests/Integration/Console/Components/SearchComponentTest.php @@ -173,7 +173,7 @@ public function search(string $query): array return array_filter( $data, - static fn (string $name) => str_contains(strtolower($name), strtolower($query)), + fn (string $name) => str_contains(strtolower($name), strtolower($query)), ); } } diff --git a/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php b/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php index 66d0ffd3f..36a0c8027 100644 --- a/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticConfirmComponentTest.php @@ -16,7 +16,7 @@ final class StaticConfirmComponentTest extends FrameworkIntegrationTestCase public function test_confirm(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { if ($console->confirm('continue')) { $console->writeln('continued'); } else { @@ -30,7 +30,7 @@ public function test_confirm(): void public function test_not_confirm(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { if ($console->confirm('continue')) { $console->writeln('continued'); } else { @@ -44,7 +44,7 @@ public function test_not_confirm(): void public function test_with_default(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { if ($console->confirm('continue', default: true)) { $console->writeln('continued'); } else { @@ -58,7 +58,7 @@ public function test_with_default(): void public function test_without_default(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { if ($console->confirm('continue')) { $console->writeln('continued'); } else { @@ -73,7 +73,7 @@ public function test_with_default_without_prompting(): void { $this->console ->withoutPrompting() - ->call(static function (Console $console): void { + ->call(function (Console $console): void { if ($console->confirm('continue', default: true)) { $console->writeln('continued'); } else { diff --git a/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php b/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php index e260e6298..a652862d3 100644 --- a/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticMultipleChoiceComponentTest.php @@ -16,7 +16,7 @@ final class StaticMultipleChoiceComponentTest extends FrameworkIntegrationTestCa public function test_ask(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $console->ask('test', ['a', 'b', 'c'], multiple: true); }) ->submit('0,1') @@ -26,7 +26,7 @@ public function test_ask(): void public function test_with_invalid_options(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $console->ask('test', ['a', 'b', 'c'], multiple: true); }) ->submit('0,4,c,2') @@ -36,7 +36,7 @@ public function test_with_invalid_options(): void public function test_confirm(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask('test', ['a', 'b', 'c'], multiple: true); $console->writeln(json_encode($answer)); @@ -54,7 +54,7 @@ public function test_confirm(): void public function test_supports_defaults(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask( question: 'test', options: ['foo', 'bar'], @@ -72,7 +72,7 @@ public function test_supports_defaults(): void public function test_supports_enum(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask( question: 'test', options: TestStringEnum::cases(), @@ -92,7 +92,7 @@ public function test_supports_enum(): void public function test_supports_enum_with_default(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask( question: 'test', options: TestStringEnum::cases(), diff --git a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php index 0953b879b..c5d6358b6 100644 --- a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php @@ -15,10 +15,10 @@ final class StaticProgressBarComponentTest extends FrameworkIntegrationTestCase public function test_progress_bar(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $output = $console->progressBar( ['a', 'b', 'c'], - static fn (string $input) => $input . $input, + fn (string $input) => $input . $input, ); $console->write(json_encode($output)); diff --git a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php index 49b996065..c1608c974 100644 --- a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php @@ -136,7 +136,7 @@ private function search(?string $query): array return array_filter( $data, - static fn (string $name) => str_contains(strtolower($name), strtolower($query)), + fn (string $name) => str_contains(strtolower($name), strtolower($query)), ); } } diff --git a/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php b/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php index c3bb1f892..3f0df9bca 100644 --- a/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSingleChoiceComponentTest.php @@ -17,7 +17,7 @@ final class StaticSingleChoiceComponentTest extends FrameworkIntegrationTestCase public function test_with_options(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask('test', ['a', 'b']); $console->writeln("picked {$answer}"); @@ -31,7 +31,7 @@ public function test_with_options(): void public function test_with_default_option(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask('test', ['a', 'b'], default: 'b'); $console->writeln("picked {$answer}"); @@ -44,7 +44,7 @@ public function test_with_default_option_without_prompting(): void { $this->console ->withoutPrompting() - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask('test', ['a', 'b'], default: 'b'); $console->writeln("picked {$answer}"); @@ -55,7 +55,7 @@ public function test_with_default_option_without_prompting(): void public function test_assoc_submit_key(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask('test', ['a' => 'A', 'b' => 'B']); $console->writeln("picked {$answer}"); @@ -67,7 +67,7 @@ public function test_assoc_submit_key(): void public function test_assoc_submit_value(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $answer = $console->ask('test', ['a' => 'A', 'b' => 'B']); $console->writeln("picked {$answer}"); @@ -79,7 +79,7 @@ public function test_assoc_submit_value(): void public function test_enum_submit_value(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { /** @var TestStringEnum $answer */ $answer = $console->ask('test', options: TestStringEnum::cases()); @@ -92,7 +92,7 @@ public function test_enum_submit_value(): void public function test_enum_submit_index(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { /** @var TestStringEnum $answer */ $answer = $console->ask('test', options: TestStringEnum::cases()); @@ -105,7 +105,7 @@ public function test_enum_submit_index(): void public function test_enum_default_value(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { /** @var TestStringEnum $answer */ $answer = $console->ask('test', options: TestStringEnum::cases(), default: TestStringEnum::B); diff --git a/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php b/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php index 54b0b0966..bb6fa62b4 100644 --- a/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticTextBoxComponentTest.php @@ -15,7 +15,7 @@ final class StaticTextBoxComponentTest extends FrameworkIntegrationTestCase public function test_text_box(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $name = $console->ask('test'); $console->writeln("Hello {$name}"); @@ -27,7 +27,7 @@ public function test_text_box(): void public function test_supports_default(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $name = $console->ask('test', default: 'Brent'); $console->writeln("Hello {$name}"); @@ -40,7 +40,7 @@ public function test_supports_default_without_prompting(): void { $this->console ->withoutPrompting() - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $name = $console->ask('test', default: 'Brent'); $console->writeln("Hello {$name}"); diff --git a/tests/Integration/Console/Components/TaskComponentTest.php b/tests/Integration/Console/Components/TaskComponentTest.php index f00b0a385..68428409e 100644 --- a/tests/Integration/Console/Components/TaskComponentTest.php +++ b/tests/Integration/Console/Components/TaskComponentTest.php @@ -76,7 +76,7 @@ public function test_successful_task(): void ->withoutPrompting() ->call(function (Console $console): void { $terminal = new Terminal($console); - $component = new TaskComponent('Task in progress', static function (): void {}); + $component = new TaskComponent('Task in progress', function (): void {}); $frames = iterator_to_array($component->render($terminal)); @@ -93,7 +93,7 @@ public function test_failing_task(): void ->withoutPrompting() ->call(function (Console $console): void { $terminal = new Terminal($console); - $component = new TaskComponent('Task in progress', static function (): never { + $component = new TaskComponent('Task in progress', function (): never { throw new Exception('Failure'); }); diff --git a/tests/Integration/Console/ConsoleArgumentBagTest.php b/tests/Integration/Console/ConsoleArgumentBagTest.php index 8423d1358..b9999ac95 100644 --- a/tests/Integration/Console/ConsoleArgumentBagTest.php +++ b/tests/Integration/Console/ConsoleArgumentBagTest.php @@ -36,13 +36,13 @@ public function test_argument_bag_works(): void $this->assertNull($firstArg->name); $forceFlag = $bag->all()[1]; - $this->assertTrue($forceFlag->value); - $this->assertNull($forceFlag->position); + $this->assertSame(true, $forceFlag->value); + $this->assertSame(null, $forceFlag->position); $this->assertSame('force', $forceFlag->name); $timesFlag = $bag->all()[2]; $this->assertSame('2', $timesFlag->value); - $this->assertNull($timesFlag->position); + $this->assertSame(null, $timesFlag->position); $this->assertSame('times', $timesFlag->name); $this->assertSame( diff --git a/tests/Integration/Console/Fixtures/InteractiveCommand.php b/tests/Integration/Console/Fixtures/InteractiveCommand.php index 8eb6712d7..afa941cbb 100644 --- a/tests/Integration/Console/Fixtures/InteractiveCommand.php +++ b/tests/Integration/Console/Fixtures/InteractiveCommand.php @@ -131,8 +131,8 @@ public function progress(): void { $result = $this->console->progressBar( data: array_fill(0, 10, 'a'), - handler: static function ($i) { - usleep(100_000); + handler: function ($i) { + usleep(100000); return $i . $i; }, @@ -148,14 +148,14 @@ public function searchCommand(): void $result = $this->console->search( 'Search', - static function (string $query) use ($data): array { + function (string $query) use ($data): array { if ($query === '') { return []; } return array_filter( $data, - static fn (string $name) => str_contains(strtolower($name), strtolower($query)), + fn (string $name) => str_contains(strtolower($name), strtolower($query)), ); }, ); diff --git a/tests/Integration/Console/Input/ConsoleInputArgumentTest.php b/tests/Integration/Console/Input/ConsoleInputArgumentTest.php index e708acc1c..6f53ef679 100644 --- a/tests/Integration/Console/Input/ConsoleInputArgumentTest.php +++ b/tests/Integration/Console/Input/ConsoleInputArgumentTest.php @@ -41,19 +41,19 @@ public function test_parse_named_arguments(): void $input = ConsoleInputArgument::fromString('--noFooBar'); $this->assertSame('foo-bar', $input->name); - $this->assertFalse($input->value); + $this->assertSame(false, $input->value); $input = ConsoleInputArgument::fromString('--no-interaction'); $this->assertSame('interaction', $input->name); - $this->assertFalse($input->value); + $this->assertSame(false, $input->value); $input = ConsoleInputArgument::fromString('--no-interaction=true'); $this->assertSame('interaction', $input->name); - $this->assertFalse($input->value); + $this->assertSame(false, $input->value); $input = ConsoleInputArgument::fromString('--no-interaction=false'); $this->assertSame('interaction', $input->name); - $this->assertTrue($input->value); + $this->assertSame(true, $input->value); $input = ConsoleInputArgument::fromString('--no-foo=baz'); $this->assertSame('no-foo', $input->name); diff --git a/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php b/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php index 8b07cb28b..09c4955b3 100644 --- a/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php +++ b/tests/Integration/Console/Middleware/ResolveOrRescueMiddlewareTest.php @@ -60,12 +60,12 @@ public function it_does_not_duplicate_completed_commands(): void $formatOutput = static fn (string $buffer) => str($buffer) ->trim() ->explode("\n") - ->map(static fn (string $line) => str($line)->afterLast(' ')->trim()->toString()) + ->map(fn (string $line) => str($line)->afterLast(' ')->trim()->toString()) ->toArray(); $output = $this->console ->call('discovery') - ->getBuffer(static fn (array $buffer) => $formatOutput(array_pop($buffer))); + ->getBuffer(fn (array $buffer) => $formatOutput(array_pop($buffer))); $this->assertContains('discovery:status', $output); $this->assertContains('discovery:clear', $output); diff --git a/tests/Integration/Console/Testing/ConsoleTesterTest.php b/tests/Integration/Console/Testing/ConsoleTesterTest.php index 614645d37..76803a3f8 100644 --- a/tests/Integration/Console/Testing/ConsoleTesterTest.php +++ b/tests/Integration/Console/Testing/ConsoleTesterTest.php @@ -26,7 +26,7 @@ public function test_call_with_invokable(): void public function test_call_with_closure(): void { $this->console - ->call(static function (Console $console): void { + ->call(function (Console $console): void { $console->writeln('hi'); }) ->assertContains('hi'); @@ -49,35 +49,35 @@ public function test_call_with_command(): void public function test_exit_code_success(): void { $this->console - ->call(static fn () => ExitCode::SUCCESS) + ->call(fn () => ExitCode::SUCCESS) ->assertSuccess(); } public function test_exit_code_invalid(): void { $this->console - ->call(static fn () => ExitCode::INVALID) + ->call(fn () => ExitCode::INVALID) ->assertInvalid(); } public function test_exit_code_error(): void { $this->console - ->call(static fn () => ExitCode::ERROR) + ->call(fn () => ExitCode::ERROR) ->assertError(); } public function test_exit_code_cancelled(): void { $this->console - ->call(static fn () => ExitCode::CANCELLED) + ->call(fn () => ExitCode::CANCELLED) ->assertCancelled(); } public function test_exit_code_success_default(): void { $this->console - ->call(static fn () => null) + ->call(fn () => null) ->assertSuccess(); } diff --git a/tests/Integration/Core/DeferredTasksTest.php b/tests/Integration/Core/DeferredTasksTest.php index 6c68f3ee6..129040906 100644 --- a/tests/Integration/Core/DeferredTasksTest.php +++ b/tests/Integration/Core/DeferredTasksTest.php @@ -36,8 +36,8 @@ public function test_deferred_tasks_are_executed_with_container_parameters(): vo { $executed = false; - defer(static function (Container $container) use (&$executed): void { - $container->invoke(static function () use (&$executed): void { + defer(function (Container $container) use (&$executed): void { + $container->invoke(function () use (&$executed): void { $executed = true; }); }); diff --git a/tests/Integration/Core/LoadDiscoveryClassesTest.php b/tests/Integration/Core/LoadDiscoveryClassesTest.php index 228af9925..29a21db43 100644 --- a/tests/Integration/Core/LoadDiscoveryClassesTest.php +++ b/tests/Integration/Core/LoadDiscoveryClassesTest.php @@ -28,7 +28,7 @@ public function do_not_discover(): void { $migrations = $this->container->get(RunnableMigrations::class); - $this->assertFalse(Arr\contains($migrations, static fn ($m) => $m instanceof HiddenDatabaseMigration)); + $this->assertFalse(Arr\contains($migrations, fn ($m) => $m instanceof HiddenDatabaseMigration)); } #[Test] diff --git a/tests/Integration/Core/ViewComponentsInstallerTest.php b/tests/Integration/Core/ViewComponentsInstallerTest.php index 88aedfdcc..7ebbb5bcb 100644 --- a/tests/Integration/Core/ViewComponentsInstallerTest.php +++ b/tests/Integration/Core/ViewComponentsInstallerTest.php @@ -39,8 +39,8 @@ protected function setUp(): void ); $this->searchOptionCount = arr($this->get(ViewConfig::class)->viewComponents) - ->filter(static fn (mixed $input) => $input instanceof ViewComponent) - ->filter(static fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent) + ->filter(fn (mixed $input) => $input instanceof ViewComponent) + ->filter(fn (ViewComponent $viewComponent) => $viewComponent->isVendorComponent) ->count(); } diff --git a/tests/Integration/Cryptography/TimelockTest.php b/tests/Integration/Cryptography/TimelockTest.php index f48669055..d514bab1a 100644 --- a/tests/Integration/Cryptography/TimelockTest.php +++ b/tests/Integration/Cryptography/TimelockTest.php @@ -15,7 +15,7 @@ public function test_uses_mocked_clock(): void $ms = $clock->timestamp()->getMilliseconds(); $timelock->invoke( - callback: static fn () => null, + callback: fn () => null, duration: Duration::milliseconds(10_000), ); $elapsed = $clock->timestamp()->getMilliseconds() - $ms; diff --git a/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php b/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php index 923de0cfc..85ee98dc1 100644 --- a/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php +++ b/tests/Integration/Database/Builder/ConvenientWhereMethodsTest.php @@ -218,12 +218,12 @@ public function test_convenient_methods_in_where_groups(): void $query = query('books') ->select() ->where('published', true) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereIn('category', ['fiction', 'mystery']) ->orWhereNull('featured_at'); }) - ->orWhereGroup(static function ($group): void { + ->orWhereGroup(function ($group): void { $group ->whereBetween('rating', 4.0, 5.0) ->whereNotLike('title', '%draft%'); @@ -241,10 +241,10 @@ public function test_nested_where_groups_with_convenient_methods(): void $query = query('books') ->select() ->whereIn('status', ['published', 'featured']) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereNotNull('published_at') - ->orWhereGroup(static function ($innerGroup): void { + ->orWhereGroup(function ($innerGroup): void { $innerGroup ->whereBetween('rating', 4.0, 5.0) ->whereNotIn('category', ['children']); diff --git a/tests/Integration/Database/Builder/CountQueryBuilderTest.php b/tests/Integration/Database/Builder/CountQueryBuilderTest.php index 162386e93..f580585ef 100644 --- a/tests/Integration/Database/Builder/CountQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/CountQueryBuilderTest.php @@ -113,14 +113,14 @@ public function test_count_query_with_conditions(): void ->count() ->when( true, - static fn (CountQueryBuilder $query) => $query + fn (CountQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Taxi') ->andWhereRaw('`index` <> ?', '1') ->orWhereRaw('`createdAt` > ?', '2025-01-01'), ) ->when( false, - static fn (CountQueryBuilder $query) => $query + fn (CountQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Uber') ->andWhereRaw('`index` <> ?', '2') ->orWhereRaw('`createdAt` > ?', '2025-01-02'), @@ -498,7 +498,7 @@ public function test_convenient_where_methods_in_groups(): void $query = query('books') ->count() ->whereIn('status', ['published', 'featured']) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereNotNull('published_at') ->orWhereBetween('rating', 4.0, 5.0); @@ -516,7 +516,7 @@ public function test_nested_where_with_count_query(): void $query = query('books') ->count() ->whereRaw('published = ?', true) - ->orWhereGroup(static function ($group): void { + ->orWhereGroup(function ($group): void { $group ->whereRaw('status = ?', 'featured') ->andWhereRaw('rating >= ?', 4.5); diff --git a/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php b/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php index 72a00c604..74fb24eb4 100644 --- a/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/DeleteQueryBuilderTest.php @@ -72,11 +72,11 @@ public function test_delete_on_plain_table_with_conditions(): void ->delete() ->when( true, - static fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'boo'), + fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'boo'), ) ->when( false, - static fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'foo'), + fn (DeleteQueryBuilder $query) => $query->whereRaw('`bar` = ?', 'foo'), ) ->build(); @@ -142,7 +142,7 @@ public function test_nested_where_with_delete_query(): void $query = query('books') ->delete() ->whereRaw('status = ?', 'draft') - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereRaw('created_at < ?', '2022-01-01') ->andWhereRaw('author_id IS NULL'); diff --git a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php index 3804db94a..c367d1d95 100644 --- a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php @@ -134,11 +134,11 @@ public function test_then_method(): void $id = query(Book::class) ->insert(title: 'Timeline Taxi') ->then( - static fn (PrimaryKey $id) => query(Chapter::class)->insert( + fn (PrimaryKey $id) => query(Chapter::class)->insert( ['title' => 'Chapter 01', 'book_id' => $id], ['title' => 'Chapter 02', 'book_id' => $id], ), - static fn (PrimaryKey $id) => query(Chapter::class)->insert( + fn (PrimaryKey $id) => query(Chapter::class)->insert( ['title' => 'Chapter 03', 'book_id' => $id], ), ) diff --git a/tests/Integration/Database/Builder/NestedWhereTest.php b/tests/Integration/Database/Builder/NestedWhereTest.php index 9b723052c..94be9fdda 100644 --- a/tests/Integration/Database/Builder/NestedWhereTest.php +++ b/tests/Integration/Database/Builder/NestedWhereTest.php @@ -15,7 +15,7 @@ public function test_nested_where_with_and_group(): void $query = query('books') ->select() ->whereRaw('title = ?', 'test') - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereRaw('author_id = ?', 1) ->orWhereRaw('author_id = ?', 2); @@ -33,7 +33,7 @@ public function test_nested_where_with_or_group(): void $query = query('books') ->select() ->whereRaw('status = ?', 'active') - ->orWhereGroup(static function ($group): void { + ->orWhereGroup(function ($group): void { $group ->whereRaw('priority = ?', 'high') ->andWhereRaw('urgent = ?', true); @@ -51,10 +51,10 @@ public function test_deeply_nested_where_groups(): void $query = query('books') ->select() ->whereRaw('published = ?', true) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereRaw('category = ?', 'fiction') - ->orWhereGroup(static function ($innerGroup): void { + ->orWhereGroup(function ($innerGroup): void { $innerGroup ->whereRaw('author_name = ?', 'Tolkien') ->andWhereRaw('rating > ?', 4.5); @@ -81,14 +81,14 @@ public function test_complex_nested_where_scenario(): void $query = query('books') ->select() ->whereRaw('status = ?', 'published') - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group - ->andWhereGroup(static function ($innerGroup): void { + ->andWhereGroup(function ($innerGroup): void { $innerGroup ->whereRaw('category = ?', 'fiction') ->andWhereRaw('rating > ?', 4.0); }) - ->orWhereGroup(static function ($innerGroup): void { + ->orWhereGroup(function ($innerGroup): void { $innerGroup ->whereRaw('category = ?', 'non-fiction') ->andWhereRaw('author_id IN (?, ?, ?)', 1, 2, 3); @@ -119,7 +119,7 @@ public function test_where_group_without_existing_conditions(): void { $query = query('books') ->select() - ->whereGroup(static function ($group): void { + ->whereGroup(function ($group): void { $group ->whereRaw('title LIKE ?', '%test%') ->orWhereRaw('description LIKE ?', '%test%'); @@ -137,7 +137,7 @@ public function test_nested_where_with_where(): void $query = query('books') ->select() ->where('published', true) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereRaw('category = ?', 'fiction') ->orWhereRaw('priority = ?', 'high'); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index 0c6eb4a7d..1c3c26212 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -310,7 +310,7 @@ public function test_chunk(): void Book::new(title: 'D')->save(); $results = []; - Book::select()->chunk(static function (array $chunk) use (&$results): void { + Book::select()->chunk(function (array $chunk) use (&$results): void { $results = [...$results, ...$chunk]; }, 2); $this->assertCount(4, $results); @@ -318,7 +318,7 @@ public function test_chunk(): void $results = []; Book::select() ->whereRaw("title <> 'A'") - ->chunk(static function (array $chunk) use (&$results): void { + ->chunk(function (array $chunk) use (&$results): void { $results = [...$results, ...$chunk]; }, 2); $this->assertCount(3, $results); @@ -341,7 +341,7 @@ public function test_chunk_with_relation(): void $results = []; Book::select() ->with('author') - ->chunk(static function (array $chunk) use (&$results): void { + ->chunk(function (array $chunk) use (&$results): void { $results = [...$results, ...$chunk]; }, 1); $this->assertCount(2, $results); @@ -370,14 +370,14 @@ public function test_select_query_with_conditions(): void ->select('title', 'index') ->when( true, - static fn (SelectQueryBuilder $query) => $query + fn (SelectQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Taxi') ->andWhereRaw('`index` <> ?', '1') ->orWhereRaw('`createdAt` > ?', '2025-01-01'), ) ->when( false, - static fn (SelectQueryBuilder $query) => $query + fn (SelectQueryBuilder $query) => $query ->whereRaw('`title` = ?', 'Timeline Uber') ->andWhereRaw('`index` <> ?', '2') ->orWhereRaw('`createdAt` > ?', '2025-01-02'), @@ -534,9 +534,9 @@ public function test_paginate(): void $this->assertSame(0, $page1->offset); $this->assertSame(2, $page1->limit); $this->assertSame(2, $page1->nextPage); - $this->assertNull($page1->previousPage); - $this->assertTrue($page1->hasNext); - $this->assertFalse($page1->hasPrevious); + $this->assertSame(null, $page1->previousPage); + $this->assertSame(true, $page1->hasNext); + $this->assertSame(false, $page1->hasPrevious); $this->assertSame('LOTR 1.1', $page1->data[0]->title); $this->assertSame('LOTR 1.2', $page1->data[1]->title); diff --git a/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php b/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php index 92246be2c..8ee939d87 100644 --- a/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/TransformsQueryBuilderTest.php @@ -18,7 +18,7 @@ public function test_select_query_builder_transform(): void { $query = query(Author::class) ->select() - ->transform(static fn ($builder) => $builder->where('name', 'Frieren')); + ->transform(fn ($builder) => $builder->where('name', 'Frieren')); $bindings = $query->build()->bindings; @@ -29,7 +29,7 @@ public function test_count_query_builder_transform(): void { $query = query(Author::class) ->count() - ->transform(static fn ($builder) => $builder->where('name', 'Himmel')); + ->transform(fn ($builder) => $builder->where('name', 'Himmel')); $bindings = $query->build()->bindings; @@ -40,7 +40,7 @@ public function test_update_query_builder_transform(): void { $query = query(Author::class) ->update(name: 'Heiter') - ->transform(static fn ($builder) => $builder->where('id', 1)); + ->transform(fn ($builder) => $builder->where('id', 1)); $bindings = $query->build()->bindings; @@ -51,7 +51,7 @@ public function test_delete_query_builder_transform(): void { $query = query(Author::class) ->delete() - ->transform(static fn ($builder) => $builder->where('name', 'Eisen')); + ->transform(fn ($builder) => $builder->where('name', 'Eisen')); $bindings = $query->build()->bindings; @@ -62,7 +62,7 @@ public function test_insert_query_builder_transform(): void { $query = query(Author::class) ->insert(['name' => 'Stark']) - ->transform(static fn ($builder) => $builder->then(static fn () => null)); + ->transform(fn ($builder) => $builder->then(fn () => null)); $bindings = $query->build()->bindings; @@ -73,7 +73,7 @@ public function test_transform_returns_new_instance(): void { $original = query(Author::class)->select(); - $transformed = $original->transform(static fn ($builder) => $builder); + $transformed = $original->transform(fn ($builder) => $builder); $this->assertNotSame($original, $transformed); } diff --git a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php index 312ffac01..a81f9a998 100644 --- a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php @@ -206,11 +206,11 @@ public function test_update_on_plain_table_with_conditions(): void ) ->when( true, - static fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 10), + fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 10), ) ->when( false, - static fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 20), + fn (UpdateQueryBuilder $query) => $query->whereRaw('`id` = ?', 20), ) ->build(); @@ -285,7 +285,7 @@ public function test_nested_where_with_update_query(): void $query = query('books') ->update(status: 'archived') ->whereRaw('published = ?', true) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereRaw('views < ?', 100) ->orWhereRaw('last_accessed < ?', '2023-01-01'); diff --git a/tests/Integration/Database/Builder/WhereOperatorTest.php b/tests/Integration/Database/Builder/WhereOperatorTest.php index 5c2b5ee39..3389effd9 100644 --- a/tests/Integration/Database/Builder/WhereOperatorTest.php +++ b/tests/Integration/Database/Builder/WhereOperatorTest.php @@ -189,7 +189,7 @@ public function test_nested_where_groups_with_new_api(): void $query = query('books') ->select() ->where('published', true) - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->where('category', 'fiction') ->orWhere('rating', 4.5, WhereOperator::GREATER_THAN); @@ -207,7 +207,7 @@ public function test_mixed_raw_and_typed_conditions_in_groups(): void $query = query('books') ->select() ->where('status', 'published') - ->andWhereGroup(static function ($group): void { + ->andWhereGroup(function ($group): void { $group ->whereField('category', ['fiction', 'mystery'], WhereOperator::IN) ->orWhereRaw('custom_field IS NOT NULL'); diff --git a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php index a3b798550..39ee9049a 100644 --- a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php +++ b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php @@ -226,11 +226,9 @@ public function test_where_this_year(): void $this->assertCount(10, $events); foreach ($events as $event) { - if ($event->name === 'Last year event') { - continue; + if ($event->name !== 'Last year event') { + $this->assertTrue($event->event_date->isCurrentYear()); } - - $this->assertTrue($event->event_date->isCurrentYear()); } } diff --git a/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php b/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php index a157aa435..4e9cc58cc 100644 --- a/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php +++ b/tests/Integration/Database/CustomPrimaryKeyRelationshipLoadingTest.php @@ -87,7 +87,7 @@ public function test_has_many_relationship_with_uuid_primary_keys(): void $this->assertCount(2, $loadedMage->spells); - $spellNames = array_map(static fn (SpellWithUuid $spell) => $spell->name, $loadedMage->spells); + $spellNames = array_map(fn (SpellWithUuid $spell) => $spell->name, $loadedMage->spells); $this->assertContains('Zoltraak', $spellNames); $this->assertContains('Volzandia', $spellNames); diff --git a/tests/Integration/Database/EncryptedAttributeTest.php b/tests/Integration/Database/EncryptedAttributeTest.php index a984e4642..68e17694d 100644 --- a/tests/Integration/Database/EncryptedAttributeTest.php +++ b/tests/Integration/Database/EncryptedAttributeTest.php @@ -108,7 +108,6 @@ final class UserWithEncryptedData public function __construct( public string $email, - #[\SensitiveParameter] #[Encrypted] public string $secret, ) {} @@ -123,7 +122,6 @@ final class UserWithNullableEncryptedData public function __construct( public string $email, - #[\SensitiveParameter] #[Encrypted] public ?string $secret, ) {} diff --git a/tests/Integration/Database/GenericDatabaseTest.php b/tests/Integration/Database/GenericDatabaseTest.php index 36f44a8e0..8ca68639f 100644 --- a/tests/Integration/Database/GenericDatabaseTest.php +++ b/tests/Integration/Database/GenericDatabaseTest.php @@ -28,7 +28,7 @@ public function test_transaction_manager_execute(): void $db = $this->container->get(Database::class); - $db->withinTransaction(static function (): void { + $db->withinTransaction(function (): void { query(Author::class) ->insert( name: 'Brent', @@ -45,7 +45,7 @@ public function test_transaction_manager_fails(): void $db = $this->container->get(Database::class); - $db->withinTransaction(static function (): never { + $db->withinTransaction(function (): never { query(Author::class) ->insert( name: 'Brent', @@ -75,14 +75,14 @@ public function test_query_with_semicolons(): void public function test_query_was_invalid_exception_is_thrown_on_fetch(): void { - $this->assertException(QueryWasInvalid::class, static function (): void { + $this->assertException(QueryWasInvalid::class, function (): void { query('books')->select()->orderByRaw('title DES')->first(); }); } public function test_query_was_invalid_exception_is_thrown_on_execute(): void { - $this->assertException(QueryWasInvalid::class, static function (): void { + $this->assertException(QueryWasInvalid::class, function (): void { query('books')->update(title: 'Timeline Taxi')->whereRaw('title = ?')->execute(); }); } diff --git a/tests/Integration/Database/GroupedWhereMethodsTest.php b/tests/Integration/Database/GroupedWhereMethodsTest.php index a865a662b..2814f08af 100644 --- a/tests/Integration/Database/GroupedWhereMethodsTest.php +++ b/tests/Integration/Database/GroupedWhereMethodsTest.php @@ -60,7 +60,7 @@ public function test_simple_where_group(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('category', 'electronics') ->where('in_stock', true); @@ -78,7 +78,7 @@ public function test_and_where_group(): void $products = query(Product::class) ->select() ->where('category', 'electronics') - ->andWhereGroup(static function ($query): void { + ->andWhereGroup(function ($query): void { $query ->whereField('price', 100.0, WhereOperator::GREATER_THAN) ->where('in_stock', true); @@ -97,7 +97,7 @@ public function test_or_where_group(): void $products = query(Product::class) ->select() ->where('category', 'furniture') - ->orWhereGroup(static function ($query): void { + ->orWhereGroup(function ($query): void { $query ->whereField('price', 500.0, WhereOperator::GREATER_THAN) ->where('brand', 'TechCorp'); @@ -125,10 +125,10 @@ public function test_nested_where_groups(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('category', 'electronics') - ->orWhereGroup(static function ($subQuery): void { + ->orWhereGroup(function ($subQuery): void { $subQuery ->where('category', 'furniture') ->whereField('price', 200.0, WhereOperator::LESS_THAN); @@ -149,12 +149,12 @@ public function test_complex_grouped_conditions(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('brand', 'TechCorp') ->orWhere('brand', 'ViewPro'); }) - ->andWhereGroup(static function ($query): void { + ->andWhereGroup(function ($query): void { $query ->where('rating', 4.0, WhereOperator::GREATER_THAN_OR_EQUAL) ->where('price', 300.0, WhereOperator::LESS_THAN); @@ -174,7 +174,7 @@ public function test_where_group_with_convenient_methods(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->whereIn('category', ['electronics', 'furniture']) ->whereBetween('price', 50.0, 250.0) @@ -194,7 +194,7 @@ public function test_where_group_with_raw_conditions(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->whereRaw('price > ?', 100.0) ->andWhereRaw('rating >= ?', 4.0); @@ -211,7 +211,7 @@ public function test_where_group_with_or_raw_conditions(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('brand', 'TechCorp') ->orWhereRaw('rating > ?', 4.5); @@ -238,7 +238,7 @@ public function test_empty_where_group_is_ignored(): void $products = query(Product::class) ->select() ->where('category', 'electronics') - ->whereGroup(static function (): void {}) + ->whereGroup(function (): void {}) ->all(); foreach ($products as $product) { @@ -250,12 +250,12 @@ public function test_multiple_where_groups(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('category', 'electronics') ->orWhere('category', 'furniture'); }) - ->andWhereGroup(static function ($query): void { + ->andWhereGroup(function ($query): void { $query ->where('in_stock', true) ->orWhere('rating', 4.5, WhereOperator::GREATER_THAN); @@ -272,7 +272,7 @@ public function test_where_group_with_all_logical_operators(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('brand', 'TechCorp') ->andWhere('category', 'electronics') @@ -301,13 +301,13 @@ public function test_deeply_nested_where_groups(): void { $products = query(Product::class) ->select() - ->whereGroup(static function ($query): void { + ->whereGroup(function ($query): void { $query ->where('category', 'electronics') - ->orWhereGroup(static function ($subQuery): void { + ->orWhereGroup(function ($subQuery): void { $subQuery ->where('category', 'furniture') - ->andWhereGroup(static function ($deepQuery): void { + ->andWhereGroup(function ($deepQuery): void { $deepQuery ->whereField('price', 150.0, WhereOperator::GREATER_THAN) ->orWhere('brand', 'LightUp'); diff --git a/tests/Integration/Database/HashedAttributeTest.php b/tests/Integration/Database/HashedAttributeTest.php index dfa1a061b..c0e76986d 100644 --- a/tests/Integration/Database/HashedAttributeTest.php +++ b/tests/Integration/Database/HashedAttributeTest.php @@ -103,7 +103,6 @@ final class UserWithHash public function __construct( public string $email, - #[\SensitiveParameter] #[Hashed] public string $password, ) {} @@ -117,7 +116,6 @@ final class UserWithNullablePassword public function __construct( public string $email, - #[\SensitiveParameter] #[Hashed] public ?string $password, ) {} diff --git a/tests/Integration/Database/MultiDatabaseTest.php b/tests/Integration/Database/MultiDatabaseTest.php index 02644ed12..4ae4a94b3 100644 --- a/tests/Integration/Database/MultiDatabaseTest.php +++ b/tests/Integration/Database/MultiDatabaseTest.php @@ -337,7 +337,7 @@ public function test_migrate_fresh_seed_on_selected_database(): void query(Book::class)->select()->onDatabase('main')->where('title', 'Timeline Taxi')->first()->title, ); - $this->assertException(QueryWasInvalid::class, static function (): void { + $this->assertException(QueryWasInvalid::class, function (): void { query(Book::class)->select()->onDatabase('backup')->first(); }); @@ -360,7 +360,7 @@ private function assertTableDoesNotExist(string $tableName, string $onDatabase): { $this->assertException( expectedExceptionClass: QueryWasInvalid::class, - handler: static fn () => query($tableName)->count()->onDatabase($onDatabase)->execute(), + handler: fn () => query($tableName)->count()->onDatabase($onDatabase)->execute(), message: "Table `{$tableName}` exists in database `{$onDatabase}`", ); } diff --git a/tests/Integration/Database/ToRawSqlTest.php b/tests/Integration/Database/ToRawSqlTest.php index e25d69ca2..b014d3b60 100644 --- a/tests/Integration/Database/ToRawSqlTest.php +++ b/tests/Integration/Database/ToRawSqlTest.php @@ -235,7 +235,7 @@ public function test_complex_select_query_with_groups_to_raw_sql(): void $rawSql = query('books') ->select() ->where('published', true) - ->whereGroup(static function ($group): void { + ->whereGroup(function ($group): void { $group ->where('category', 'fiction') ->orWhere('rating', 4.5, WhereOperator::GREATER_THAN_OR_EQUAL); diff --git a/tests/Integration/Debug/DebugTest.php b/tests/Integration/Debug/DebugTest.php index 048c2fa25..d366dc80b 100644 --- a/tests/Integration/Debug/DebugTest.php +++ b/tests/Integration/Debug/DebugTest.php @@ -34,7 +34,7 @@ public function recursive_debug_inside_event_listener_does_not_cause_infinite_lo $dispatchCount = 0; $eventBus = $this->container->get(EventBus::class); - $eventBus->listen(static function (ItemsDebugged $event) use (&$dispatchCount): void { + $eventBus->listen(function (ItemsDebugged $event) use (&$dispatchCount): void { $dispatchCount++; Debug::resolve()->log(['recursive call'], writeToLog: false, writeToOut: false); diff --git a/tests/Integration/EventBus/EventBusTesterTest.php b/tests/Integration/EventBus/EventBusTesterTest.php index ca9b6cd1b..1c4c41900 100644 --- a/tests/Integration/EventBus/EventBusTesterTest.php +++ b/tests/Integration/EventBus/EventBusTesterTest.php @@ -56,12 +56,12 @@ public function assert_dispatched_with_callback(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch('event-bus-fake-event'); - $this->eventBus->assertDispatched('event-bus-fake-event', static function (string $event) { + $this->eventBus->assertDispatched('event-bus-fake-event', function (string $event) { return $event === 'event-bus-fake-event'; }); $this->bus->dispatch(new FakeEvent('foo')); - $this->eventBus->assertDispatched(FakeEvent::class, static function (FakeEvent $event) { + $this->eventBus->assertDispatched(FakeEvent::class, function (FakeEvent $event) { return $event->value === 'foo'; }); } @@ -108,7 +108,7 @@ public function assert_dispatched_with_callback_failure(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch('event-bus-fake-event'); - $this->eventBus->assertDispatched('event-bus-fake-event', static function (string $event) { + $this->eventBus->assertDispatched('event-bus-fake-event', function (string $event) { return $event !== 'event-bus-fake-event'; }); } @@ -122,7 +122,7 @@ public function assert_dispatched_object_with_callback_failure(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch(new FakeEvent('foo')); - $this->eventBus->assertDispatched(FakeEvent::class, static function (FakeEvent $event) { + $this->eventBus->assertDispatched(FakeEvent::class, function (FakeEvent $event) { return $event->value === 'foobar'; }); } @@ -178,7 +178,7 @@ public function assert_listening_to(): void { $this->eventBus->preventEventHandling(); - $this->bus->listen(static function (FakeEvent $_): never { + $this->bus->listen(function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); @@ -191,13 +191,13 @@ public function assert_listening_to_count(): void { $this->eventBus->preventEventHandling(); - $this->bus->listen(static function (FakeEvent $_): never { + $this->bus->listen(function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); $this->eventBus->assertListeningTo(FakeEvent::class, count: 1); - $this->bus->listen(static function (FakeEvent $_): never { + $this->bus->listen(function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); @@ -223,7 +223,7 @@ public function assert_listening_to_count_failure(): void $this->eventBus->preventEventHandling(); - $this->bus->listen(static function (FakeEvent $_): never { + $this->bus->listen(function (FakeEvent $_): never { throw new LogicException('This should not be called'); }); @@ -235,7 +235,7 @@ public function allows_handling(): void $this->eventBus->recordEventDispatches(); $handled = false; - $this->bus->listen(static function (FakeEvent $_) use (&$handled): void { + $this->bus->listen(function (FakeEvent $_) use (&$handled): void { $handled = true; }); diff --git a/tests/Integration/FrameworkIntegrationTestCase.php b/tests/Integration/FrameworkIntegrationTestCase.php index f051ddb2a..87ce6e656 100644 --- a/tests/Integration/FrameworkIntegrationTestCase.php +++ b/tests/Integration/FrameworkIntegrationTestCase.php @@ -60,10 +60,10 @@ protected function assertSnippetsMatch(string $expected, string $actual): void protected function assertSameWithoutBackticks(Stringable|string $expected, Stringable|string $actual): void { - $clean = static function (string $string): string { + $clean = function (string $string): string { return str($string) ->replace('`', '') - ->replaceRegex('/AS \"(?.*?)\"/', static fn (array $matches) => "AS {$matches['alias']}") + ->replaceRegex('/AS \"(?.*?)\"/', fn (array $matches) => "AS {$matches['alias']}") ->toString(); }; diff --git a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php index d14f866d0..2b7cde3b9 100644 --- a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php +++ b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php @@ -35,7 +35,7 @@ final class ExceptionRendererTest extends FrameworkIntegrationTestCase #[PreCondition] protected function configure(): void { - $this->container->singleton(Kernel::class, static fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { + $this->container->singleton(Kernel::class, fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { public const string VERSION = '1.0.0-alpha.6'; public string $root; @@ -68,7 +68,7 @@ public function shutdown(int|string $status = ''): never } }); - $this->container->singleton(ResponseSender::class, static fn () => new class($this) implements ResponseSender { + $this->container->singleton(ResponseSender::class, fn () => new class($this) implements ResponseSender { public function __construct( private ExceptionRendererTest $case, ) {} @@ -90,7 +90,7 @@ public function custom_json_exception_renderer(): void $this->container->singleton( Request::class, - static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), + fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), ); $this->callExceptionHandler(function (): void { @@ -114,7 +114,7 @@ public function custom_html_exception_renderer(): void $this->container->singleton( Request::class, - static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), + fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), ); $this->callExceptionHandler(function (): void { @@ -135,7 +135,7 @@ public function falls_back_to_default_renderer_when_no_custom_match(): void $this->container->singleton( Request::class, - static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), + fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), ); $this->callExceptionHandler(function (): void { @@ -157,7 +157,7 @@ public function priority_ordering(): void $this->container->singleton( Request::class, - static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), + fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'application/json']), ); $this->callExceptionHandler(function (): void { @@ -179,7 +179,7 @@ public function custom_404_renderer(): void $this->container->singleton( Request::class, - static fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), + fn () => new GenericRequest(Method::GET, '/test', headers: ['Accept' => 'text/html']), ); $this->callExceptionHandler(function (): void { diff --git a/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php b/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php index f96d9e138..370c7d9e1 100644 --- a/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php +++ b/tests/Integration/Http/Exceptions/HttpExceptionHandlerTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->container->singleton( Kernel::class, - static fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { + fn () => new class($this->container->get(FrameworkKernel::class)) implements Kernel { public const string VERSION = '1.0.0-alpha.6'; public string $root; @@ -67,7 +67,7 @@ public function shutdown(int|string $status = ''): never $this->container->singleton( ResponseSender::class, - static fn () => new class($this) implements ResponseSender { + fn () => new class($this) implements ResponseSender { public function __construct( private HttpExceptionHandlerTest $case, ) {} diff --git a/tests/Integration/Http/GenericResponseSenderTest.php b/tests/Integration/Http/GenericResponseSenderTest.php index 3554b2c1a..7102f293e 100644 --- a/tests/Integration/Http/GenericResponseSenderTest.php +++ b/tests/Integration/Http/GenericResponseSenderTest.php @@ -158,7 +158,7 @@ public function test_view_body(): void public function test_stream(): void { ob_start(); - $response = new EventStream(static fn () => yield 'hello'); + $response = new EventStream(fn () => yield 'hello'); $responseSender = $this->container->get(GenericResponseSender::class); $responseSender->send($response); @@ -172,7 +172,7 @@ public function test_stream(): void public function test_stream_with_custom_event(): void { ob_start(); - $response = new EventStream(static function () { + $response = new EventStream(function () { yield new ServerSentMessage(data: 'hello', event: 'first'); yield new ServerSentMessage(data: 'goodbye', event: 'last'); }); @@ -191,7 +191,7 @@ public function test_stream_with_custom_event(): void public function test_stream_with_custom_id(): void { ob_start(); - $response = new EventStream(static function () { + $response = new EventStream(function () { yield new ServerSentMessage(data: 'hello', id: 123); yield new ServerSentMessage(data: 'goodbye', id: 456); }); @@ -210,7 +210,7 @@ public function test_stream_with_custom_id(): void public function test_stream_with_custom_retry(): void { ob_start(); - $response = new EventStream(static function () { + $response = new EventStream(function () { yield new ServerSentMessage(data: 'hello', retryAfter: 1000); yield new ServerSentMessage(data: 'goodbye', retryAfter: Duration::minute()); }); @@ -229,7 +229,7 @@ public function test_stream_with_custom_retry(): void public function test_stream_with_custom_implementation(): void { ob_start(); - $response = new EventStream(static function () { + $response = new EventStream(function () { yield new class implements ServerSentEvent { public ?int $id = 1; diff --git a/tests/Integration/Http/HeaderSessionIdResolverTest.php b/tests/Integration/Http/HeaderSessionIdResolverTest.php index 3ab488a6c..41ffec6d4 100644 --- a/tests/Integration/Http/HeaderSessionIdResolverTest.php +++ b/tests/Integration/Http/HeaderSessionIdResolverTest.php @@ -43,7 +43,7 @@ private function setSessionId(string $id): void { $request = new GenericRequest(Method::GET, '/', [], ['tempest_session_id' => $id]); - $this->container->singleton(Request::class, static fn () => $request); - $this->container->singleton(GenericRequest::class, static fn () => $request); + $this->container->singleton(Request::class, fn () => $request); + $this->container->singleton(GenericRequest::class, fn () => $request); } } diff --git a/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php b/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php index 3c7521c12..a51c48580 100644 --- a/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php +++ b/tests/Integration/Http/TrackPreviousUrlMiddlewareTest.php @@ -32,7 +32,7 @@ public function middleware_tracks_request_url(): void { $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/dashboard'), - next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), ); $this->assertEquals('/dashboard', $this->previousUrl->get()); @@ -45,7 +45,7 @@ public function middleware_calls_next_handler(): void $response = $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/test'), - next: new HttpMiddlewareCallable(static fn () => $expected), + next: new HttpMiddlewareCallable(fn () => $expected), ); $this->assertSame($expected, $response); @@ -56,7 +56,7 @@ public function middleware_does_not_track_post_requests(): void { $this->middleware->__invoke( request: new GenericRequest(method: Method::POST, uri: '/form-submit'), - next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), ); $this->assertEquals('/', $this->previousUrl->get()); @@ -65,7 +65,7 @@ public function middleware_does_not_track_post_requests(): void #[Test] public function middleware_tracks_multiple_requests_in_sequence(): void { - $next = new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)); + $next = new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)); $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/page1'), @@ -94,7 +94,7 @@ public function middleware_ignores_ajax_requests(): void { $this->middleware->__invoke( request: new GenericRequest(method: Method::GET, uri: '/dashboard'), - next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), ); $this->middleware->__invoke( @@ -103,7 +103,7 @@ public function middleware_ignores_ajax_requests(): void uri: '/api/data', headers: ['X-Requested-With' => 'XMLHttpRequest'], ), - next: new HttpMiddlewareCallable(static fn () => new GenericResponse(Status::OK)), + next: new HttpMiddlewareCallable(fn () => new GenericResponse(Status::OK)), ); $this->assertEquals('/dashboard', $this->previousUrl->get()); diff --git a/tests/Integration/Icon/IconTest.php b/tests/Integration/Icon/IconTest.php index c1fc76cbf..a5b040b79 100644 --- a/tests/Integration/Icon/IconTest.php +++ b/tests/Integration/Icon/IconTest.php @@ -134,7 +134,7 @@ private function registerMocks( ->with('https://api.iconify.test/mdi/tsunami.svg') ->willReturn($response ?? new GenericResponse(status: Status::OK, body: '')); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->container->singleton(Icon\IconCache::class, new Icon\IconCache( enabled: true, diff --git a/tests/Integration/Intl/TranslatorTest.php b/tests/Integration/Intl/TranslatorTest.php index 7eff90bf4..b364e022e 100644 --- a/tests/Integration/Intl/TranslatorTest.php +++ b/tests/Integration/Intl/TranslatorTest.php @@ -50,7 +50,7 @@ public function test_event_miss(): void $received = null; $eventbus = $this->container->get(EventBus::class); - $eventbus->listen(static function (TranslationMiss $event) use (&$received): void { + $eventbus->listen(function (TranslationMiss $event) use (&$received): void { $received = $event; }); @@ -68,7 +68,7 @@ public function test_event_fail(): void $received = null; $eventbus = $this->container->get(EventBus::class); - $eventbus->listen(static function (TranslationFailure $event) use (&$received): void { + $eventbus->listen(function (TranslationFailure $event) use (&$received): void { $received = $event; }); diff --git a/tests/Integration/Log/GenericLoggerTest.php b/tests/Integration/Log/GenericLoggerTest.php index 18d9763d1..05d392c27 100644 --- a/tests/Integration/Log/GenericLoggerTest.php +++ b/tests/Integration/Log/GenericLoggerTest.php @@ -179,12 +179,12 @@ public function different_log_levels(): void public static function tempestLevelProvider(): array { - return array_map(static fn (LogLevel $level) => [$level, strtoupper($level->value)], LogLevel::cases()); + return array_map(fn (LogLevel $level) => [$level, strtoupper($level->value)], LogLevel::cases()); } public static function monologLevelProvider(): array { - return array_map(static fn (Level $level) => [$level, strtoupper($level->name)], Level::cases()); + return array_map(fn (Level $level) => [$level, strtoupper($level->name)], Level::cases()); } public static function psrLogLevelProvider(): array @@ -192,6 +192,6 @@ public static function psrLogLevelProvider(): array $reflection = new ReflectionClass(PsrLogLevel::class); $levels = $reflection->getConstants(); - return array_map(static fn (string $level) => [$level, strtoupper($level)], array_values($levels)); + return array_map(fn (string $level) => [$level, strtoupper($level)], array_values($levels)); } } diff --git a/tests/Integration/Mailer/AttachmentTest.php b/tests/Integration/Mailer/AttachmentTest.php index 76c5564e0..0caa8cd6e 100644 --- a/tests/Integration/Mailer/AttachmentTest.php +++ b/tests/Integration/Mailer/AttachmentTest.php @@ -48,7 +48,7 @@ public function test_from_path_throws_when_file_does_not_exist(): void public function test_from_closure(): void { $attachment = Attachment::fromClosure( - static fn () => 'Hello, world!', + fn () => 'Hello, world!', 'greeting.txt', 'text/plain', ); diff --git a/tests/Integration/Mailer/MailerTesterTest.php b/tests/Integration/Mailer/MailerTesterTest.php index 7c1b9b205..f13b88f34 100644 --- a/tests/Integration/Mailer/MailerTesterTest.php +++ b/tests/Integration/Mailer/MailerTesterTest.php @@ -39,12 +39,12 @@ public function test_assert_sent_with_class_string_and_callback(): void $this->expectException(AssertionFailedError::class); $this->expectExceptionMessage("Email `Tests\Tempest\Integration\Mailer\Fixtures\TextEmail` was sent but failed the assertion."); - $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, static fn (Email $_email) => false); + $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, fn (Email $_email) => false); } public function test_assert_sent_with_class_string_and_truthy_callback(): void { - $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, static fn (Email $_email) => true); + $this->mailer->send(new TextEmail())->assertSent(TextEmail::class, fn (Email $_email) => true); } public function test_assert_not_sent_with_class_string(): void @@ -72,7 +72,7 @@ public function test_assertions(): void html: 'Hello Jon', from: 'no-reply@tempestphp.com', attachments: [ - Attachment::fromClosure(static fn () => 'hello!'), + Attachment::fromClosure(fn () => 'hello!'), ], )) ->assertSent(GenericEmail::class, function (GenericEmail $email): void { @@ -92,7 +92,7 @@ public function test_email_was_sent_event_was_dispatched(): void html: 'Hello Jon', from: 'no-reply@tempestphp.com', attachments: [ - Attachment::fromClosure(callable: static fn () => 'hello!'), + Attachment::fromClosure(callable: fn () => 'hello!'), ], )); diff --git a/tests/Integration/Mailer/SentEmailTest.php b/tests/Integration/Mailer/SentEmailTest.php index d2da25fb6..39d396cb9 100644 --- a/tests/Integration/Mailer/SentEmailTest.php +++ b/tests/Integration/Mailer/SentEmailTest.php @@ -123,9 +123,9 @@ public function test_assert_attachment_from_closure(): void $this->sendTestEmail( text: 'Hello', attachments: [ - Attachment::fromClosure(static fn () => 'hey', name: 'file.txt', contentType: 'text/plain'), + Attachment::fromClosure(fn () => 'hey', name: 'file.txt', contentType: 'text/plain'), ], - )->assertAttached('file.txt', static function (AttachmentTester $attachment): void { + )->assertAttached('file.txt', function (AttachmentTester $attachment): void { $attachment->assertNamed('file.txt'); $attachment->assertNotNamed('foo.txt'); $attachment->assertType('text'); @@ -140,7 +140,7 @@ public function test_assert_attachment_from_filesystem(): void attachments: [ Attachment::fromFilesystem(__FILE__), ], - )->assertAttached('SentEmailTest.php', static function (AttachmentTester $attachment): void { + )->assertAttached('SentEmailTest.php', function (AttachmentTester $attachment): void { $attachment->assertNamed('SentEmailTest.php'); $attachment->assertNotNamed('foo.txt'); $attachment->assertType('text'); @@ -160,7 +160,7 @@ public function test_assert_attachment_from_storage(): void attachments: [ Attachment::fromStorage($storage, 'file.txt'), ], - )->assertAttached('file.txt', static function (AttachmentTester $attachment): void { + )->assertAttached('file.txt', function (AttachmentTester $attachment): void { $attachment->assertNamed('file.txt'); $attachment->assertNotNamed('foo.txt'); $attachment->assertType('text'); diff --git a/tests/Integration/Mapper/Fixtures/SerializableObject.php b/tests/Integration/Mapper/Fixtures/SerializableObject.php index eb50d53f8..3c61c6a39 100644 --- a/tests/Integration/Mapper/Fixtures/SerializableObject.php +++ b/tests/Integration/Mapper/Fixtures/SerializableObject.php @@ -6,6 +6,10 @@ final class SerializableObject implements Serializable { + /* + * @mago-expect lint:return-type + * @phpstan-ignore return.unusedType + */ public function serialize() { return 'a'; diff --git a/tests/Integration/Mapper/ObjectFactoryTest.php b/tests/Integration/Mapper/ObjectFactoryTest.php index 341e09c91..05d8ef995 100644 --- a/tests/Integration/Mapper/ObjectFactoryTest.php +++ b/tests/Integration/Mapper/ObjectFactoryTest.php @@ -78,7 +78,7 @@ public function test_cannot_map_exception(): void public function test_map_with(): void { $result = map(['a' => 'a', 'b' => 'b'])->with( - static fn (ArrayToObjectMapper $mapper, mixed $from) => $mapper->map($from, ObjectA::class), + fn (ArrayToObjectMapper $mapper, mixed $from) => $mapper->map($from, ObjectA::class), ObjectToArrayMapper::class, ArrayToJsonMapper::class, )->do(); diff --git a/tests/Integration/Process/ProcessExecutorTest.php b/tests/Integration/Process/ProcessExecutorTest.php index 71c81809e..d25cd36fb 100644 --- a/tests/Integration/Process/ProcessExecutorTest.php +++ b/tests/Integration/Process/ProcessExecutorTest.php @@ -93,7 +93,7 @@ public function test_pool(): void while ($invocation->running->isNotEmpty()) { $output = $invocation ->all - ->map(static fn (InvokedProcess $process) => $process->output) + ->map(fn (InvokedProcess $process) => $process->output) ->toArray(); } diff --git a/tests/Integration/Process/ProcessTesterAssertNotRanTest.php b/tests/Integration/Process/ProcessTesterAssertNotRanTest.php index de326ad13..61e992a6a 100644 --- a/tests/Integration/Process/ProcessTesterAssertNotRanTest.php +++ b/tests/Integration/Process/ProcessTesterAssertNotRanTest.php @@ -22,7 +22,7 @@ public function test_succeeds_when_command_is_not_ran(): void public function test_succeeds_with_callback_when_no_command_ran(): void { $this->process->recordProcessExecutions(); - $this->process->assertCommandDidNotRun(static function (): void {}); + $this->process->assertCommandDidNotRun(function (): void {}); } public function test_succeeds_with_callback_when_other_commands_ran(): void @@ -30,7 +30,7 @@ public function test_succeeds_with_callback_when_other_commands_ran(): void $this->process->mockProcessResult('echo *', 'hello'); $this->executor->run('echo "hello"'); - $this->process->assertCommandDidNotRun(static function (PendingProcess $process) { + $this->process->assertCommandDidNotRun(function (PendingProcess $process) { // this returns false, so expectation succeeds return $process->command === 'echo "world"'; }); @@ -44,7 +44,7 @@ public function test_fails_with_callback_when_returning_false(): void $this->process->mockProcessResult('echo *', 'hello'); $this->executor->run('echo "hello"'); - $this->process->assertCommandDidNotRun(static function (PendingProcess $process) { + $this->process->assertCommandDidNotRun(function (PendingProcess $process) { // this returns true, so expectation fails return $process->command === 'echo "hello"'; }); diff --git a/tests/Integration/Process/ProcessTesterAssertRanTest.php b/tests/Integration/Process/ProcessTesterAssertRanTest.php index 7a38f4749..3e0472bec 100644 --- a/tests/Integration/Process/ProcessTesterAssertRanTest.php +++ b/tests/Integration/Process/ProcessTesterAssertRanTest.php @@ -29,7 +29,7 @@ public function test_expectation_succeeds_when_command_is_ran_and_callback_retur { $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', static function (ProcessResult $result) { + $this->process->assertCommandRan('echo *', function (ProcessResult $result) { return $result->output === "hello\n"; }); } @@ -51,7 +51,7 @@ public function test_expectation_fails_when_command_is_ran_and_callback_returns_ $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', static function (ProcessResult $result) { + $this->process->assertCommandRan('echo *', function (ProcessResult $result) { return $result->output !== "hello\n"; }); } @@ -60,7 +60,7 @@ public function test_expectation_succeeds_when_callback_returns_nothing(): void { $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', static function (): void {}); + $this->process->assertCommandRan('echo *', function (): void {}); } public function test_expectation_succeeds_when_callback_returns_true(): void @@ -68,7 +68,7 @@ public function test_expectation_succeeds_when_callback_returns_true(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(static function (PendingProcess $process): bool { + $this->process->assertRan(function (PendingProcess $process): bool { return $process->command === 'echo "hello"'; }); } @@ -81,7 +81,7 @@ public function test_returning_false_from_callback_fails_expectation(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(static function (PendingProcess $_process): bool { + $this->process->assertRan(function (PendingProcess $_process): bool { return false; }); } @@ -92,7 +92,7 @@ public function test_returning_true_from_callback_skips_other_iterations(): void $this->executor->run('echo "hello"'); $this->executor->run('echo "world"'); - $this->process->assertRan(static function (PendingProcess $process): bool { + $this->process->assertRan(function (PendingProcess $process): bool { if ($process->command === 'echo "hello"') { return true; } @@ -109,7 +109,7 @@ public function test_never_returning_fails_expectation(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(static function (PendingProcess $_process): void { + $this->process->assertRan(function (PendingProcess $_process): void { // This callback never returns. }); } diff --git a/tests/Integration/Process/ProcessTesterTest.php b/tests/Integration/Process/ProcessTesterTest.php index 6cb8d8192..4280a9969 100644 --- a/tests/Integration/Process/ProcessTesterTest.php +++ b/tests/Integration/Process/ProcessTesterTest.php @@ -94,7 +94,7 @@ public function test_assert_ran_times_with_callback(): void $this->executor->run('echo "hello"'); $this->executor->run('echo "hello"'); - $this->process->assertRanTimes(static fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 2); + $this->process->assertRanTimes(fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 2); } public function test_assert_ran_times_with_string_failure(): void @@ -118,7 +118,7 @@ public function test_assert_ran_times_with_callback_failure(): void $this->executor->run('echo "hello"'); $this->executor->run('echo "hello"'); - $this->process->assertRanTimes(static fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 1); + $this->process->assertRanTimes(fn (PendingProcess $process) => $process->command === 'echo "hello"', times: 1); } public function test_assert_ran_times_with_unrelated_callback(): void @@ -128,7 +128,7 @@ public function test_assert_ran_times_with_unrelated_callback(): void $this->executor->run('echo "hello"'); $this->process->assertRanTimes('echo *', times: 2); - $this->process->assertRanTimes(static fn (PendingProcess $process) => $process->command === 'echo "world"', times: 0); + $this->process->assertRanTimes(fn (PendingProcess $process) => $process->command === 'echo "world"', times: 0); } public function test_register_multiple_process_results(): void diff --git a/tests/Integration/Route/ClientTest.php b/tests/Integration/Route/ClientTest.php index f8ccf0357..e5e93dbf1 100644 --- a/tests/Integration/Route/ClientTest.php +++ b/tests/Integration/Route/ClientTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->server->start(); // Server needs to start - usleep(100_000); + usleep(100000); // We'll use the client interface directly because we want to write raw post data in this test $this->driver = $this->container->get(ClientInterface::class); diff --git a/tests/Integration/Route/RequestToObjectMapperTest.php b/tests/Integration/Route/RequestToObjectMapperTest.php index 12297cb41..176ccc11f 100644 --- a/tests/Integration/Route/RequestToObjectMapperTest.php +++ b/tests/Integration/Route/RequestToObjectMapperTest.php @@ -81,7 +81,7 @@ public function test_query_params_with_types(): void $this->assertSame(1, $request->intParam); $this->assertSame('a', $request->stringParam); - $this->assertTrue($request->boolParam); + $this->assertSame(true, $request->boolParam); $this->assertSame(0.1, $request->floatParam); } @@ -115,7 +115,7 @@ public function test_reserved_properties_cannot_be_mapped(): void { $this->assertException( expectedExceptionClass: RequestParametersIncludedReservedNames::class, - handler: static function (): void { + handler: function (): void { map(new GenericRequest( method: Method::GET, uri: '/books?uri=invalid', diff --git a/tests/Integration/Storage/StorageTesterTest.php b/tests/Integration/Storage/StorageTesterTest.php index 286a1857d..00599b7e1 100644 --- a/tests/Integration/Storage/StorageTesterTest.php +++ b/tests/Integration/Storage/StorageTesterTest.php @@ -133,7 +133,7 @@ public function test_public_url(): void { $storage = $this->storage->fake(); - $storage->createPublicUrlsUsing(static fn (string $path) => sprintf('https://localhost/%s', $path)); + $storage->createPublicUrlsUsing(fn (string $path) => sprintf('https://localhost/%s', $path)); $storage = $this->container->get(Storage::class); $storage->write('foo.txt', 'bar'); @@ -145,7 +145,7 @@ public function test_temporary_urls(): void { $storage = $this->storage->fake(); - $storage->createTemporaryUrlsUsing(static fn (string $path, DateTimeInterface $expiresAt) => sprintf( + $storage->createTemporaryUrlsUsing(fn (string $path, DateTimeInterface $expiresAt) => sprintf( 'https://localhost/%s?expires=%s', $path, $expiresAt->format(DateTimeInterface::RFC3339), diff --git a/tests/Integration/Validator/ExistsRuleTest.php b/tests/Integration/Validator/ExistsRuleTest.php index fe0d38849..c4f328521 100644 --- a/tests/Integration/Validator/ExistsRuleTest.php +++ b/tests/Integration/Validator/ExistsRuleTest.php @@ -45,8 +45,8 @@ public function non_existent_record_returns_false(): void { Book::create(title: 'Timeline Taxi'); - $this->assertFalse(new Exists(Book::class)->isValid(99_999)); - $this->assertFalse(new Exists(Book::class)->isValid(12_345)); + $this->assertFalse(new Exists(Book::class)->isValid(99999)); + $this->assertFalse(new Exists(Book::class)->isValid(12345)); $this->assertFalse(new Exists(Book::class, column: 'title')->isValid('Timeline Taxi 2')); } @@ -60,6 +60,6 @@ public function validates_multiple_existing_records(): void $this->assertTrue(new Exists(Book::class)->isValid($book1->id)); $this->assertTrue(new Exists(Book::class)->isValid($book2->id)); $this->assertTrue(new Exists(Book::class)->isValid($book3->id)); - $this->assertFalse(new Exists(Book::class)->isValid(99_999)); + $this->assertFalse(new Exists(Book::class)->isValid(99999)); } } diff --git a/tests/Integration/View/Components/IconComponentTest.php b/tests/Integration/View/Components/IconComponentTest.php index 2d99078ac..2221b9842 100644 --- a/tests/Integration/View/Components/IconComponentTest.php +++ b/tests/Integration/View/Components/IconComponentTest.php @@ -41,7 +41,7 @@ public function test_it_renders_an_icon(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->assertSame( '', @@ -61,11 +61,11 @@ public function test_it_downloads_the_icon_from_a_custom_api(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->container->singleton( IconConfig::class, - static fn () => new IconConfig(iconifyApiUrl: 'https://api.iconify.test', retryAfter: Duration::hours(12)), + fn () => new IconConfig(iconifyApiUrl: 'https://api.iconify.test', retryAfter: Duration::hours(12)), ); $this->assertSame( @@ -94,7 +94,7 @@ public function test_it_caches_icons_on_the_first_render(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->view->render(''); @@ -120,7 +120,7 @@ public function test_it_renders_an_icon_from_cache(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); // Trigger first render, which should cache the icon $this->view->render(''); @@ -140,7 +140,7 @@ public function test_it_renders_a_debug_comment_in_local_env_when_icon_does_not_ ->with('https://api.iconify.design/material-symbols/php.svg') ->willReturn(new GenericResponse(status: Status::NOT_FOUND, body: '')); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->container->singleton(Environment::class, Environment::LOCAL); $this->assertSame( @@ -158,7 +158,7 @@ public function test_it_renders_an_empty_string__in_non_local_env_when_icon_does ->with('https://api.iconify.design/material-symbols/php.svg') ->willReturn(new GenericResponse(status: Status::NOT_FOUND, body: '')); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->container->singleton(Environment::class, Environment::PRODUCTION); $this->assertSame( @@ -179,7 +179,7 @@ public function test_it_forwards_the_class_attribute(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->assertSame( '', @@ -201,7 +201,7 @@ public function test_it_forwards_the_style_attribute(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->assertSame( '', @@ -223,7 +223,7 @@ public function test_it_handles_width_and_height_together_props(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->assertSame( '', @@ -245,7 +245,7 @@ public function test_fallback_dimensions_when_none_defined_in_any_supported_meth body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $this->assertSame( '', @@ -267,7 +267,7 @@ public function test_with_dynamic_data(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $rendered = $this->view->render( '', @@ -294,7 +294,7 @@ public function test_icon_renders_inside_named_slot_in_a_layout(): void body: '', )); - $this->container->register(HttpClient::class, static fn () => $mockHttpClient); + $this->container->register(HttpClient::class, fn () => $mockHttpClient); $view = view(__DIR__ . '/../../../Fixtures/Views/view-with-icon-inside-named-slot.view.php'); $html = $this->view->render($view); diff --git a/tests/Integration/View/ElementFactoryTest.php b/tests/Integration/View/ElementFactoryTest.php index bab9f7b74..603fa9072 100644 --- a/tests/Integration/View/ElementFactoryTest.php +++ b/tests/Integration/View/ElementFactoryTest.php @@ -77,7 +77,7 @@ public function test_parental_relations(): void private function withoutWhitespace(array $elements): array { return arr($elements) - ->filter(static fn (Element $element) => ! $element instanceof WhitespaceElement) + ->filter(fn (Element $element) => ! $element instanceof WhitespaceElement) ->values() ->toArray(); } diff --git a/tests/Integration/View/ViewCacheTest.php b/tests/Integration/View/ViewCacheTest.php index 4a5cae0f2..0a805812f 100644 --- a/tests/Integration/View/ViewCacheTest.php +++ b/tests/Integration/View/ViewCacheTest.php @@ -37,7 +37,7 @@ protected function tearDown(): void $directory = path(self::DIRECTORY); if ($directory->isDirectory()) { - $directory->glob('/*.php')->each(static fn (string $file) => unlink($file)); + $directory->glob('/*.php')->each(fn (string $file) => unlink($file)); rmdir(self::DIRECTORY); } @@ -103,7 +103,7 @@ public function overriden_by_view_cache_locally(): void public function test_view_cache(): void { - $path = $this->viewCache->getCachedViewPath('path', static fn () => 'hi'); + $path = $this->viewCache->getCachedViewPath('path', fn () => 'hi'); $this->assertFileExists($path); $this->assertSame('hi', file_get_contents($path)); @@ -115,7 +115,7 @@ public function test_view_cache_when_disabled(): void $this->viewCache->enabled = false; - $compileFunction = static function () use (&$hit) { + $compileFunction = function () use (&$hit) { $hit += 1; return 'hi'; @@ -135,7 +135,7 @@ public function test_view_cache_when_enabled(): void $this->viewCache->enabled = true; - $compileFunction = static function () use (&$hit) { + $compileFunction = function () use (&$hit) { $hit += 1; return 'hi'; diff --git a/tests/Integration/View/ViewComponentDiscoveryTest.php b/tests/Integration/View/ViewComponentDiscoveryTest.php index 5a074ff43..117daef48 100644 --- a/tests/Integration/View/ViewComponentDiscoveryTest.php +++ b/tests/Integration/View/ViewComponentDiscoveryTest.php @@ -46,7 +46,7 @@ public function test_project_view_components_cannot_be_overwritten_by_other_proj $this->assertException( ViewComponentWasAlreadyRegistered::class, - static function () use ($viewConfig): void { + function () use ($viewConfig): void { $viewConfig->addViewComponent(new ViewComponent( name: 'x-form', contents: 'b', diff --git a/tests/Integration/View/ViewComponentTest.php b/tests/Integration/View/ViewComponentTest.php index 4e5ef900a..2ed4064ed 100644 --- a/tests/Integration/View/ViewComponentTest.php +++ b/tests/Integration/View/ViewComponentTest.php @@ -1107,7 +1107,7 @@ public function does_not_duplicate_view_compilation_frames_in_stacktrace(): void $this->assertException( ViewCompilationFailed::class, - static function () use ($viewRenderer): void { + function () use ($viewRenderer): void { $viewRenderer->render(view(__DIR__ . '/Fixtures/stacktrace-standalone-error.view.php')); }, function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { @@ -1121,7 +1121,7 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { $renderCompiledFrames = array_values(array_filter( $stacktrace['applicationFrames'], - static fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', + fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', )); $this->assertCount(1, $renderCompiledFrames); @@ -1160,7 +1160,7 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { $renderCompiledFrames = array_values(array_filter( $stacktrace['applicationFrames'], - static fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', + fn (array $frame): bool => ($frame['class'] ?? null) === TempestViewRenderer::class && ($frame['function'] ?? null) === 'renderCompiled', )); $this->assertCount(1, $renderCompiledFrames); diff --git a/tests/Integration/Vite/ViteTesterTest.php b/tests/Integration/Vite/ViteTesterTest.php index 5e6e53fd5..34a6dc9eb 100644 --- a/tests/Integration/Vite/ViteTesterTest.php +++ b/tests/Integration/Vite/ViteTesterTest.php @@ -73,17 +73,17 @@ public function test_call_requires_root(): void $this->expectException(InvalidArgumentException::class); $this->vite->call( - callback: static fn () => null, + callback: fn () => null, files: [], ); } public function test_retains_tags_resolver(): void { - $this->container->register(TagsResolver::class, static fn () => new NullTagsResolver()); + $this->container->register(TagsResolver::class, fn () => new NullTagsResolver()); $this->vite->call( - callback: static fn () => null, + callback: fn () => null, files: [], root: __DIR__ . '/Fixtures/tmp', ); From 2377d83af3bccb4f34efb8ffcbb1170c11a92392 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:39:20 +0100 Subject: [PATCH 10/14] Revert "Run mago" This reverts commit ef0fad18e8939764fbdc5a57af1ffc2986abaf91. --- .../src/Authentication/Authenticatable.php | 4 +- .../Exceptions/AuthenticationException.php | 4 +- .../src/Exceptions/OAuthStateWasInvalid.php | 4 +- packages/auth/src/OAuth/OAuthConfig.php | 16 +- packages/cache/src/Cache.php | 5 +- packages/cache/src/CacheCouldNotBeCleared.php | 4 +- packages/cache/src/CacheException.php | 4 +- packages/cache/src/Lock.php | 12 +- packages/command-bus/src/Async.php | 4 +- packages/console/src/CanOpenInEditor.php | 4 +- packages/console/src/Console.php | 4 +- packages/console/src/HasStaticComponent.php | 4 +- .../console/src/Scheduler/NullScheduler.php | 4 +- packages/console/tests/TextBufferTest.php | 40 +- packages/container/src/Autowire.php | 4 +- .../src/Exceptions/ContainerException.php | 4 +- packages/container/src/HasTag.php | 4 +- packages/container/src/Proxy.php | 4 +- packages/container/tests/ContainerTest.php | 6 +- .../CannotAutowireExceptionTest.php | 10 +- .../CircularDependencyExceptionTest.php | 22 +- .../tests/Fixtures/ContainerObjectA.php | 4 +- .../tests/Fixtures/DecoratedClass.php | 4 +- .../tests/Fixtures/DecoratedInterface.php | 4 +- .../Fixtures/DecoratorWithoutConstructor.php | 4 +- .../tests/Fixtures/ImplementsInterfaceA.php | 4 +- packages/container/tests/Fixtures/InjectB.php | 4 +- .../container/tests/Fixtures/InterfaceA.php | 4 +- .../tests/Fixtures/UnionImplementation.php | 4 +- .../tests/Fixtures/UnionInterfaceA.php | 4 +- .../tests/Fixtures/UnionInterfaceB.php | 4 +- .../src/ComposerJsonCouldNotBeLocated.php | 4 +- packages/core/src/InsightsProvider.php | 4 +- packages/core/src/Installer.php | 4 +- packages/core/src/Kernel.php | 30 +- .../cryptography/src/Encryption/Encrypter.php | 4 +- .../Exceptions/EncryptionException.php | 4 +- .../Exceptions/PasswordHashingException.php | 4 +- .../src/Password/PasswordHasher.php | 4 +- .../src/Password/PasswordHashingConfig.php | 8 +- .../Signing/Exceptions/SigningException.php | 4 +- packages/cryptography/src/Signing/Signer.php | 4 +- .../src/Builder/QueryBuilders/BuildsQuery.php | 12 +- .../Builder/QueryBuilders/QueryBuilder.php | 6 +- .../QueryBuilders/SelectQueryBuilder.php | 3 +- .../Builder/QueryBuilders/SupportsJoins.php | 4 +- .../QueryBuilders/SupportsRelations.php | 4 +- .../QueryBuilders/SupportsWhereStatements.php | 4 +- .../database/src/Config/DatabaseConfig.php | 32 +- packages/database/src/Database.php | 8 +- packages/database/src/Eager.php | 4 +- .../src/Exceptions/DatabaseException.php | 4 +- .../database/src/HasLeadingStatements.php | 4 +- .../database/src/HasTrailingStatements.php | 4 +- packages/database/src/Lazy.php | 4 +- packages/database/src/MigratesDown.php | 4 +- packages/database/src/MigratesUp.php | 4 +- .../src/Migrations/MigrationException.php | 4 +- .../CreateEnumTypeStatement.php | 4 +- .../QueryStatements/DropEnumTypeStatement.php | 4 +- .../QueryStatements/HasWhereStatements.php | 4 +- .../QueryStatements/ShowTablesStatement.php | 10 +- packages/database/src/Relation.php | 4 +- packages/database/src/Uuid.php | 4 +- packages/database/src/Virtual.php | 4 +- .../CreateTableStatementTest.php | 170 ++-- .../QueryBuilderGenericsTypeAssertions.php | 4 +- .../src/Exception/DateTimeException.php | 4 +- .../src/Exception/OverflowException.php | 4 +- .../src/Exception/ParserException.php | 4 +- .../src/Exception/RuntimeException.php | 4 +- .../src/Exception/UnderflowException.php | 4 +- packages/debug/src/Debug.php | 20 +- packages/event-bus/src/StopsPropagation.php | 4 +- .../tests/Fixtures/EventInterface.php | 4 +- .../Fixtures/EventInterfaceImplementation.php | 4 +- .../event-bus/tests/Fixtures/ItHappened.php | 4 +- .../Exceptions/FileGenerationException.php | 4 +- .../Exceptions/FileGenerationWasAborted.php | 4 +- packages/generation/src/TypeScript/AsType.php | 4 +- .../TypeScript/TypeScriptGenerationConfig.php | 14 +- .../tests/Php/ClassGeneratorTest.php | 32 +- .../tests/Php/Fixtures/ClassFromFile.php | 4 +- .../ClassWithMethodParameterAttributes.php | 3 +- .../Fixtures/SampleNamespace/DummyFqcn.php | 4 +- .../Fixtures/SampleNamespace/ExampleTrait.php | 4 +- .../SampleParameterAttribute.php | 4 +- .../tests/Php/Fixtures/TestAttribute.php | 4 +- packages/http/src/Request.php | 36 +- packages/http/src/Response.php | 12 +- packages/http/src/Responses/Download.php | 3 +- packages/http/src/Responses/File.php | 3 +- packages/http/src/SensitiveField.php | 4 +- packages/http/src/ServerSentEvent.php | 16 +- packages/http/src/Session/SessionConfig.php | 4 +- .../src/Exceptions/IdempotencyException.php | 4 +- .../tests/IdempotentCommandMiddlewareTest.php | 4 +- packages/intl/bin/plural-rules.php | 188 ++--- .../src/MessageFormat/FormattingFunction.php | 4 +- .../Parser/Node/Declaration/Declaration.php | 4 +- .../src/MessageFormat/Parser/Node/Key/Key.php | 4 +- .../Parser/Node/Key/WildcardKey.php | 4 +- .../Parser/Node/Literal/QuotedLiteral.php | 4 +- .../Parser/Node/Literal/UnquotedLiteral.php | 4 +- .../src/MessageFormat/Parser/Node/Node.php | 4 +- .../Parser/Node/Pattern/Placeholder.php | 4 +- .../Parser/Node/SimpleMessage.php | 4 +- .../src/MessageFormat/SelectorFunction.php | 4 +- packages/intl/tests/FormatterTest.php | 222 ++--- packages/intl/tests/GenericTranslatorTest.php | 12 +- packages/intl/tests/ParserTest.php | 22 +- .../kv-store/src/Redis/RedisException.php | 4 +- packages/log/src/LogConfig.php | 8 +- packages/log/src/Logger.php | 4 +- packages/mail/src/Email.php | 8 +- .../mail/src/Exceptions/MailerException.php | 4 +- packages/mail/src/HasAttachments.php | 4 +- packages/mail/src/HasTextContent.php | 4 +- packages/mail/src/MailerConfig.php | 4 +- .../src/Transports/ProvidesDefaultSender.php | 4 +- packages/mapper/src/Context.php | 4 +- packages/mapper/src/Hidden.php | 4 +- packages/mapper/src/ProvidesCaster.php | 4 +- packages/mapper/src/ProvidesSerializer.php | 4 +- packages/mapper/src/Strict.php | 4 +- packages/mapper/src/UnknownValue.php | 4 +- .../src/Exceptions/ProcessException.php | 4 +- packages/process/src/InvokedProcess.php | 16 +- packages/reflection/src/PropertyAttribute.php | 5 +- .../reflection/tests/EnumReflectorTest.php | 4 +- .../tests/Fixtures/AnnulledInvoice.php | 4 +- .../Fixtures/ChildWithRecursiveAttribute.php | 4 +- ...assWithInterfaceWithRecursiveAttribute.php | 4 +- .../InterfaceWithRecursiveAttribute.php | 4 +- .../tests/Fixtures/NullableClass.php | 4 +- .../Fixtures/ParentWithRecursiveAttribute.php | 4 +- .../tests/Fixtures/RecursiveAttribute.php | 4 +- .../tests/Fixtures/TestBackedEnum.php | 4 +- .../reflection/tests/Fixtures/TestEnum.php | 4 +- .../src/Exceptions/RouteBindingFailed.php | 4 +- .../router/src/Exceptions/RouterException.php | 4 +- packages/router/src/IsBindingValue.php | 4 +- packages/router/src/Route.php | 20 +- .../Static/Exceptions/StaticPageException.php | 4 +- packages/router/tests/FakeRouteBuilder.php | 4 +- .../FakeRouteBuilderWithOptionalParams.php | 16 +- packages/storage/src/Config/StorageConfig.php | 9 +- packages/storage/src/StorageException.php | 4 +- .../support/src/Arr/OffsetDidNotExist.php | 4 +- .../Exceptions/FilesystemException.php | 4 +- .../Exceptions/RuntimeException.php | 4 +- .../support/src/JavaScript/PackageManager.php | 6 +- .../Json/Exception/JsonCouldNotBeDecoded.php | 4 +- .../Json/Exception/JsonCouldNotBeEncoded.php | 4 +- .../src/Json/Exception/JsonException.php | 4 +- .../Math/Exception/ArithmeticException.php | 4 +- .../Exception/DivisionByZeroException.php | 4 +- .../Exception/InvalidArgumentException.php | 4 +- .../src/Math/Exception/MathException.php | 4 +- .../src/Math/Exception/OverflowException.php | 4 +- packages/support/src/Namespace/functions.php | 8 +- .../Exceptions/ArgumentWasInvalid.php | 4 +- .../Exceptions/PaginationException.php | 4 +- .../src/Regex/InvalidPatternException.php | 4 +- packages/support/src/Str/StringInterface.php | 4 +- .../src/VarExport/EmptyFileNameException.php | 4 +- .../VarExport/FileDoesNotExistException.php | 4 +- .../src/VarExport/VarExportPhpFile.php | 6 +- packages/support/tests/Json/JsonTest.php | 28 +- packages/validation/src/SkipValidation.php | 4 +- .../view/src/Components/x-component.view.php | 8 +- .../view/src/Export/ExportableViewObject.php | 4 +- packages/view/src/ShouldBeRemoved.php | 4 +- packages/view/src/View.php | 12 +- packages/view/src/WithToken.php | 4 +- .../view/tests/FallthroughAttributesTest.php | 10 +- .../view/tests/StandaloneViewRendererTest.php | 24 +- packages/view/tests/TempestViewLexerTest.php | 52 +- packages/view/tests/TempestViewParserTest.php | 40 +- .../EntrypointNotFoundException.php | 4 +- .../vite/src/Exceptions/ViteException.php | 4 +- .../TagsResolver/DevelopmentTagsResolver.php | 16 +- .../src/TagsResolver/ManifestTagsResolver.php | 66 +- .../Framework/Testing/IntegrationTest.php | 3 +- .../Benchmark/Extension/MarkdownExtension.php | 4 +- .../Extension/MarkdownRendererTest.php | 34 +- .../Commands/HelloWorldTestCommand.php | 4 +- tests/Fixtures/Commands/MyBrokenCommand.php | 4 +- tests/Fixtures/Commands/MyCommand.php | 4 +- .../Console/CommandWithDifferentArguments.php | 3 +- tests/Fixtures/Console/StylingCommand.php | 3 +- tests/Fixtures/Controllers/DocsController.php | 4 +- .../EventForListenerWithoutPropagation.php | 4 +- tests/Fixtures/Events/EventInterface.php | 4 +- .../Events/EventInterfaceImplementation.php | 4 +- .../Events/EventWithoutPropagation.php | 4 +- tests/Fixtures/Events/ItHappened.php | 4 +- tests/Fixtures/GlobalHiddenDiscovery.php | 4 +- tests/Fixtures/GlobalHiddenPathDiscovery.php | 4 +- tests/Fixtures/Handlers/MyCommandHandler.php | 4 +- tests/Fixtures/TestInstallerClass.php | 4 +- .../Static/StaticProgressBarComponentTest.php | 10 +- .../Static/StaticSearchComponentTest.php | 32 +- .../Fixtures/CommandWithNonCommandMethods.php | 12 +- .../Fixtures/CompletionTestCommand.php | 3 +- .../Console/Fixtures/MyConsole.php | 3 +- .../Integration/Console/Fixtures/Package.php | 7 +- .../Console/Fixtures/TestConsoleException.php | 4 +- .../Scheduler/GenericSchedulerTest.php | 8 +- .../Scheduler/HandlerInvocationTest.php | 4 +- .../Core/Config/LoadConfigTest.php | 12 +- .../Integration/Core/Fixtures/MiddlewareA.php | 4 +- .../Integration/Core/Fixtures/MiddlewareB.php | 4 +- .../Integration/Core/Fixtures/MiddlewareC.php | 4 +- .../Core/Fixtures/MiddlewareFramework.php | 4 +- .../Core/Fixtures/MiddlewareHigh.php | 4 +- .../Core/Fixtures/MiddlewareHighest.php | 4 +- .../Core/Fixtures/MiddlewareLow.php | 4 +- .../Core/Fixtures/MiddlewareLowest.php | 4 +- .../Core/Fixtures/MiddlewareNormal.php | 4 +- .../Builder/InsertQueryBuilderTest.php | 8 +- .../Builder/SelectQueryBuilderTest.php | 16 +- .../Builder/UpdateQueryBuilderTest.php | 8 +- .../Database/GenericDatabaseTest.php | 6 +- .../QueryStatements/CompoundStatementTest.php | 6 +- .../CreateEnumTypeStatementTest.php | 4 +- .../DropEnumTypeStatementTest.php | 4 +- .../Commands/MetaViewComponentCommandTest.php | 54 +- .../Http/Exceptions/ExceptionRendererTest.php | 4 +- tests/Integration/Mailer/SentEmailTest.php | 30 +- .../View/BladeViewRendererTest.php | 8 +- .../View/Components/MarkdownComponentTest.php | 8 +- tests/Integration/View/ElementFactoryTest.php | 20 +- ...estViewRendererCombinedExpressionsTest.php | 66 +- .../TempestViewRendererDataPassingTest.php | 152 ++-- .../View/TempestViewRendererTest.php | 440 +++++----- .../Integration/View/TwigViewRendererTest.php | 8 +- .../View/ViewComponentDiscoveryTest.php | 8 +- tests/Integration/View/ViewComponentTest.php | 796 +++++++++--------- tests/Integration/View/ViewTest.php | 4 +- .../Vite/ManifestTagsResolverTest.php | 4 +- .../Vite/ViteTagsComponentTest.php | 148 ++-- 242 files changed, 2186 insertions(+), 1717 deletions(-) diff --git a/packages/auth/src/Authentication/Authenticatable.php b/packages/auth/src/Authentication/Authenticatable.php index 6db39727e..6abf1008f 100644 --- a/packages/auth/src/Authentication/Authenticatable.php +++ b/packages/auth/src/Authentication/Authenticatable.php @@ -7,4 +7,6 @@ /** * Represents an entity that may be authenticated. */ -interface Authenticatable {} +interface Authenticatable +{ +} diff --git a/packages/auth/src/Exceptions/AuthenticationException.php b/packages/auth/src/Exceptions/AuthenticationException.php index acaea6737..c7c62e082 100644 --- a/packages/auth/src/Exceptions/AuthenticationException.php +++ b/packages/auth/src/Exceptions/AuthenticationException.php @@ -2,4 +2,6 @@ namespace Tempest\Auth\Exceptions; -interface AuthenticationException {} +interface AuthenticationException +{ +} diff --git a/packages/auth/src/Exceptions/OAuthStateWasInvalid.php b/packages/auth/src/Exceptions/OAuthStateWasInvalid.php index 06243d4c2..deecb77be 100644 --- a/packages/auth/src/Exceptions/OAuthStateWasInvalid.php +++ b/packages/auth/src/Exceptions/OAuthStateWasInvalid.php @@ -6,4 +6,6 @@ use Exception; -final class OAuthStateWasInvalid extends Exception implements AuthenticationException {} +final class OAuthStateWasInvalid extends Exception implements AuthenticationException +{ +} diff --git a/packages/auth/src/OAuth/OAuthConfig.php b/packages/auth/src/OAuth/OAuthConfig.php index 6722f7c42..250bd851a 100644 --- a/packages/auth/src/OAuth/OAuthConfig.php +++ b/packages/auth/src/OAuth/OAuthConfig.php @@ -14,24 +14,32 @@ interface OAuthConfig extends HasTag /** * The OAuth provider class name. */ - public string $provider { get; } + public string $provider { + get; + } /** * The authorization scopes for this OAuth provider. * * @return string[] */ - public array $scopes { get; } + public array $scopes { + get; + } /** * The client ID for the OAuth provider. */ - public string $clientId { get; } + public string $clientId { + get; + } /** * The controller action to redirect to after the user authorizes the application. */ - public string|array $redirectTo { get; } + public string|array $redirectTo { + get; + } /** * Creates the OAuth provider instance. diff --git a/packages/cache/src/Cache.php b/packages/cache/src/Cache.php index 19647a714..e46f189e9 100644 --- a/packages/cache/src/Cache.php +++ b/packages/cache/src/Cache.php @@ -15,7 +15,10 @@ interface Cache /** * Whether the cache is enabled. */ - public bool $enabled { get; set; } + public bool $enabled { + get; + set; + } /** * Returns a lock for the specified key. The lock is not acquired until `acquire()` is called. diff --git a/packages/cache/src/CacheCouldNotBeCleared.php b/packages/cache/src/CacheCouldNotBeCleared.php index c74d7dba1..f7e3c2214 100644 --- a/packages/cache/src/CacheCouldNotBeCleared.php +++ b/packages/cache/src/CacheCouldNotBeCleared.php @@ -6,4 +6,6 @@ use Exception; -final class CacheCouldNotBeCleared extends Exception implements CacheException {} +final class CacheCouldNotBeCleared extends Exception implements CacheException +{ +} diff --git a/packages/cache/src/CacheException.php b/packages/cache/src/CacheException.php index 3b72346ea..56297fdd4 100644 --- a/packages/cache/src/CacheException.php +++ b/packages/cache/src/CacheException.php @@ -2,4 +2,6 @@ namespace Tempest\Cache; -interface CacheException {} +interface CacheException +{ +} diff --git a/packages/cache/src/Lock.php b/packages/cache/src/Lock.php index e6ad9fc2e..908df168b 100644 --- a/packages/cache/src/Lock.php +++ b/packages/cache/src/Lock.php @@ -12,17 +12,23 @@ interface Lock /** * The key used to identify the lock. This should be unique across all locks. */ - public string $key { get; } + public string $key { + get; + } /** * The duration of the lock. If null, the lock will not expire. */ - public ?Duration $duration { get; } + public ?Duration $duration { + get; + } /** * The owner of the lock. This is used to verify that the lock is being released by the correct owner. */ - public string $owner { get; } + public string $owner { + get; + } /** * Attempts to acquire a lock. diff --git a/packages/command-bus/src/Async.php b/packages/command-bus/src/Async.php index b3b6b5852..eb1b35a49 100644 --- a/packages/command-bus/src/Async.php +++ b/packages/command-bus/src/Async.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute] -final readonly class Async {} +final readonly class Async +{ +} diff --git a/packages/console/src/CanOpenInEditor.php b/packages/console/src/CanOpenInEditor.php index f39561b98..3ff635bb0 100644 --- a/packages/console/src/CanOpenInEditor.php +++ b/packages/console/src/CanOpenInEditor.php @@ -4,4 +4,6 @@ namespace Tempest\Console; -interface CanOpenInEditor {} +interface CanOpenInEditor +{ +} diff --git a/packages/console/src/Console.php b/packages/console/src/Console.php index 57875c72d..056ce5584 100644 --- a/packages/console/src/Console.php +++ b/packages/console/src/Console.php @@ -161,5 +161,7 @@ public function disablePrompting(): self; /** * Whether the console is in forced mode (skipping confirmations). */ - public bool $isForced { get; } + public bool $isForced { + get; + } } diff --git a/packages/console/src/HasStaticComponent.php b/packages/console/src/HasStaticComponent.php index ef896911c..c23fa81ac 100644 --- a/packages/console/src/HasStaticComponent.php +++ b/packages/console/src/HasStaticComponent.php @@ -6,5 +6,7 @@ interface HasStaticComponent { - public StaticConsoleComponent $staticComponent { get; } + public StaticConsoleComponent $staticComponent { + get; + } } diff --git a/packages/console/src/Scheduler/NullScheduler.php b/packages/console/src/Scheduler/NullScheduler.php index 3ca9e1eb6..7cd1d58ad 100644 --- a/packages/console/src/Scheduler/NullScheduler.php +++ b/packages/console/src/Scheduler/NullScheduler.php @@ -9,5 +9,7 @@ final class NullScheduler implements Scheduler { - public function run(?DateTime $date = null): void {} + public function run(?DateTime $date = null): void + { + } } diff --git a/packages/console/tests/TextBufferTest.php b/packages/console/tests/TextBufferTest.php index 76b6a5267..af26f5b62 100644 --- a/packages/console/tests/TextBufferTest.php +++ b/packages/console/tests/TextBufferTest.php @@ -137,10 +137,10 @@ public function test_move_cursor_to_start(): void $this->assertSame(0, $buffer->cursor); $buffer = new TextBuffer(<<moveCursorX(100); $buffer->moveCursorToStart(); $this->assertSame(0, $buffer->cursor); @@ -155,10 +155,10 @@ public function test_move_cursor_to_end(): void $this->assertSame(13, $buffer->cursor); $buffer = new TextBuffer(<<setCursorIndex(0); $buffer->moveCursorToEnd(); $this->assertSame(48, $buffer->cursor); @@ -185,10 +185,10 @@ public function test_move_cursor_to_start_of_line(): void public function test_move_cursor_to_start_of_line_multiline(int $initial, int $expected): void { $buffer = new TextBuffer(<<setCursorIndex($initial); $buffer->moveCursorToStartOfLine(); @@ -217,10 +217,10 @@ public function test_move_cursor_to_end_of_line(): void public function test_move_cursor_to_end_of_line_multiline(int $initial, int $expected): void { $buffer = new TextBuffer(<<setCursorIndex($initial); $buffer->moveCursorToEndOfLine(); @@ -258,10 +258,10 @@ public function test_move_cursor_x(int $initialCursor, int $offsetX, int $expect public function move_cursor_y(int $initialCursor, int $offsetY, int $expectedPosition): void { $buffer = new TextBuffer(<<setCursorIndex($initialCursor); $buffer->moveCursorY($offsetY); diff --git a/packages/container/src/Autowire.php b/packages/container/src/Autowire.php index adc5f433e..8297e2d2e 100644 --- a/packages/container/src/Autowire.php +++ b/packages/container/src/Autowire.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS)] -final class Autowire {} +final class Autowire +{ +} diff --git a/packages/container/src/Exceptions/ContainerException.php b/packages/container/src/Exceptions/ContainerException.php index aac08af63..02809f491 100644 --- a/packages/container/src/Exceptions/ContainerException.php +++ b/packages/container/src/Exceptions/ContainerException.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Exceptions; -interface ContainerException {} +interface ContainerException +{ +} diff --git a/packages/container/src/HasTag.php b/packages/container/src/HasTag.php index 535bccf5a..0aa252f6a 100644 --- a/packages/container/src/HasTag.php +++ b/packages/container/src/HasTag.php @@ -6,5 +6,7 @@ interface HasTag { - public null|string|UnitEnum $tag { get; } + public null|string|UnitEnum $tag { + get; + } } diff --git a/packages/container/src/Proxy.php b/packages/container/src/Proxy.php index 7fa29f7c6..10cfee429 100644 --- a/packages/container/src/Proxy.php +++ b/packages/container/src/Proxy.php @@ -12,4 +12,6 @@ * The container may then decide to do lazy initialization */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] -final readonly class Proxy {} +final readonly class Proxy +{ +} diff --git a/packages/container/tests/ContainerTest.php b/packages/container/tests/ContainerTest.php index 1431f0f2a..effa97435 100644 --- a/packages/container/tests/ContainerTest.php +++ b/packages/container/tests/ContainerTest.php @@ -325,9 +325,9 @@ public function test_autowired_tagged_dependency_exception(): void } catch (TaggedDependencyCouldNotBeResolved $cannotResolveTaggedDependency) { $this->assertStringContainsStringIgnoringLineEndings( <<<'TXT' - ┌── DependencyWithTaggedDependency::__construct(TaggedDependency $dependency) - └── Tempest\Container\Tests\Fixtures\TaggedDependency - TXT, + ┌── DependencyWithTaggedDependency::__construct(TaggedDependency $dependency) + └── Tempest\Container\Tests\Fixtures\TaggedDependency + TXT, $cannotResolveTaggedDependency->getMessage(), ); } diff --git a/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php b/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php index 349fd2dd3..58e8f2cb0 100644 --- a/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php +++ b/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php @@ -26,11 +26,11 @@ public function test_autowire_without_exception(): void $this->assertStringContainsString('Cannot autowire ' . AutowireA::class . '::__construct because string cannot be resolved', $cannotAutowireException->getMessage()); $expected = <<<'TXT' - ┌── AutowireA::__construct(AutowireB $b) - ├── AutowireB::__construct(AutowireC $c) - └── AutowireC::__construct(ContainerObjectA $other, string $unknown) - ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + ┌── AutowireA::__construct(AutowireB $b) + ├── AutowireB::__construct(AutowireC $c) + └── AutowireC::__construct(ContainerObjectA $other, string $unknown) + ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $cannotAutowireException->getMessage()); $this->assertStringContainsString('CannotAutowireExceptionTest.php:24', $cannotAutowireException->getMessage()); diff --git a/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php b/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php index 147f28acc..6ec8887d5 100644 --- a/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php +++ b/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php @@ -30,11 +30,11 @@ public function test_circular_dependency_test(): void ); $expected = <<<'TXT' - ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) - │ CircularB::__construct(CircularC $c) - │ CircularC::__construct(ContainerObjectA $other, CircularA $a) - └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) + │ CircularB::__construct(CircularC $c) + │ CircularC::__construct(ContainerObjectA $other, CircularA $a) + └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $circularDependencyException->getMessage()); @@ -59,12 +59,12 @@ public function test_circular_dependency_as_a_child_test(): void ); $expected = <<<'TXT' - CircularZ::__construct(CircularA $a) - ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) - │ CircularB::__construct(CircularC $c) - │ CircularC::__construct(ContainerObjectA $other, CircularA $a) - └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + CircularZ::__construct(CircularA $a) + ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) + │ CircularB::__construct(CircularC $c) + │ CircularC::__construct(ContainerObjectA $other, CircularA $a) + └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $circularDependencyException->getMessage()); diff --git a/packages/container/tests/Fixtures/ContainerObjectA.php b/packages/container/tests/Fixtures/ContainerObjectA.php index 8f616a804..aceae4de0 100644 --- a/packages/container/tests/Fixtures/ContainerObjectA.php +++ b/packages/container/tests/Fixtures/ContainerObjectA.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -final class ContainerObjectA {} +final class ContainerObjectA +{ +} diff --git a/packages/container/tests/Fixtures/DecoratedClass.php b/packages/container/tests/Fixtures/DecoratedClass.php index 5e1cee022..da11df34a 100644 --- a/packages/container/tests/Fixtures/DecoratedClass.php +++ b/packages/container/tests/Fixtures/DecoratedClass.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -final class DecoratedClass implements DecoratedInterface {} +final class DecoratedClass implements DecoratedInterface +{ +} diff --git a/packages/container/tests/Fixtures/DecoratedInterface.php b/packages/container/tests/Fixtures/DecoratedInterface.php index 1a9d08396..ddae1db5a 100644 --- a/packages/container/tests/Fixtures/DecoratedInterface.php +++ b/packages/container/tests/Fixtures/DecoratedInterface.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -interface DecoratedInterface {} +interface DecoratedInterface +{ +} diff --git a/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php b/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php index de30c8b5e..6adabcc37 100644 --- a/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php +++ b/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php @@ -7,4 +7,6 @@ use Tempest\Container\Decorates; #[Decorates(DecoratedInterface::class)] -final class DecoratorWithoutConstructor implements DecoratedInterface {} +final class DecoratorWithoutConstructor implements DecoratedInterface +{ +} diff --git a/packages/container/tests/Fixtures/ImplementsInterfaceA.php b/packages/container/tests/Fixtures/ImplementsInterfaceA.php index 9b14c30f7..81404be60 100644 --- a/packages/container/tests/Fixtures/ImplementsInterfaceA.php +++ b/packages/container/tests/Fixtures/ImplementsInterfaceA.php @@ -6,5 +6,7 @@ final class ImplementsInterfaceA implements InterfaceA { - public function __invoke(): void {} + public function __invoke(): void + { + } } diff --git a/packages/container/tests/Fixtures/InjectB.php b/packages/container/tests/Fixtures/InjectB.php index f7564219b..81e0ddc78 100644 --- a/packages/container/tests/Fixtures/InjectB.php +++ b/packages/container/tests/Fixtures/InjectB.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -final readonly class InjectB {} +final readonly class InjectB +{ +} diff --git a/packages/container/tests/Fixtures/InterfaceA.php b/packages/container/tests/Fixtures/InterfaceA.php index 86e374a17..81206885f 100644 --- a/packages/container/tests/Fixtures/InterfaceA.php +++ b/packages/container/tests/Fixtures/InterfaceA.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -interface InterfaceA {} +interface InterfaceA +{ +} diff --git a/packages/container/tests/Fixtures/UnionImplementation.php b/packages/container/tests/Fixtures/UnionImplementation.php index e663b1906..ce931a18b 100644 --- a/packages/container/tests/Fixtures/UnionImplementation.php +++ b/packages/container/tests/Fixtures/UnionImplementation.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -final readonly class UnionImplementation implements UnionInterfaceA, UnionInterfaceB {} +final readonly class UnionImplementation implements UnionInterfaceA, UnionInterfaceB +{ +} diff --git a/packages/container/tests/Fixtures/UnionInterfaceA.php b/packages/container/tests/Fixtures/UnionInterfaceA.php index e64583989..6574213e8 100644 --- a/packages/container/tests/Fixtures/UnionInterfaceA.php +++ b/packages/container/tests/Fixtures/UnionInterfaceA.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -interface UnionInterfaceA {} +interface UnionInterfaceA +{ +} diff --git a/packages/container/tests/Fixtures/UnionInterfaceB.php b/packages/container/tests/Fixtures/UnionInterfaceB.php index 1cb98985b..061913934 100644 --- a/packages/container/tests/Fixtures/UnionInterfaceB.php +++ b/packages/container/tests/Fixtures/UnionInterfaceB.php @@ -4,4 +4,6 @@ namespace Tempest\Container\Tests\Fixtures; -interface UnionInterfaceB {} +interface UnionInterfaceB +{ +} diff --git a/packages/core/src/ComposerJsonCouldNotBeLocated.php b/packages/core/src/ComposerJsonCouldNotBeLocated.php index 4c3bcd1dc..10bf4b2c7 100644 --- a/packages/core/src/ComposerJsonCouldNotBeLocated.php +++ b/packages/core/src/ComposerJsonCouldNotBeLocated.php @@ -6,4 +6,6 @@ use Exception; -final class ComposerJsonCouldNotBeLocated extends Exception {} +final class ComposerJsonCouldNotBeLocated extends Exception +{ +} diff --git a/packages/core/src/InsightsProvider.php b/packages/core/src/InsightsProvider.php index 2c9fbed89..c361318ed 100644 --- a/packages/core/src/InsightsProvider.php +++ b/packages/core/src/InsightsProvider.php @@ -10,7 +10,9 @@ interface InsightsProvider /** * Display name of this provider. */ - public string $name { get; } + public string $name { + get; + } /** * Gets insights in the form of key/value pairs. diff --git a/packages/core/src/Installer.php b/packages/core/src/Installer.php index cb9698b2a..9f8cb3cf0 100644 --- a/packages/core/src/Installer.php +++ b/packages/core/src/Installer.php @@ -6,7 +6,9 @@ interface Installer { - public string $name { get; } + public string $name { + get; + } public function install(): void; } diff --git a/packages/core/src/Kernel.php b/packages/core/src/Kernel.php index 7a8b97cf9..65f45fb96 100644 --- a/packages/core/src/Kernel.php +++ b/packages/core/src/Kernel.php @@ -10,15 +10,27 @@ interface Kernel { public const string VERSION = '3.3.1'; - public string $root { get; } - - public string $internalStorage { get; } - - public array $discoveryLocations { get; set; } - - public array $discoveryClasses { get; set; } - - public Container $container { get; } + public string $root { + get; + } + + public string $internalStorage { + get; + } + + public array $discoveryLocations { + get; + set; + } + + public array $discoveryClasses { + get; + set; + } + + public Container $container { + get; + } public static function boot( string $root, diff --git a/packages/cryptography/src/Encryption/Encrypter.php b/packages/cryptography/src/Encryption/Encrypter.php index 84b78c34b..20f3087e5 100644 --- a/packages/cryptography/src/Encryption/Encrypter.php +++ b/packages/cryptography/src/Encryption/Encrypter.php @@ -4,7 +4,9 @@ interface Encrypter { - public EncryptionAlgorithm $algorithm { get; } + public EncryptionAlgorithm $algorithm { + get; + } /** * Encrypts the specified data. diff --git a/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php b/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php index bc252de37..b590b3c2b 100644 --- a/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php +++ b/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php @@ -2,4 +2,6 @@ namespace Tempest\Cryptography\Encryption\Exceptions; -interface EncryptionException {} +interface EncryptionException +{ +} diff --git a/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php b/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php index 0bc2a05c6..7a993a6d0 100644 --- a/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php +++ b/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php @@ -2,4 +2,6 @@ namespace Tempest\Cryptography\Password\Exceptions; -interface PasswordHashingException {} +interface PasswordHashingException +{ +} diff --git a/packages/cryptography/src/Password/PasswordHasher.php b/packages/cryptography/src/Password/PasswordHasher.php index bafe7fb9d..e2a256765 100644 --- a/packages/cryptography/src/Password/PasswordHasher.php +++ b/packages/cryptography/src/Password/PasswordHasher.php @@ -4,7 +4,9 @@ interface PasswordHasher { - public HashingAlgorithm $algorithm { get; } + public HashingAlgorithm $algorithm { + get; + } /** * Hashes the specified password. diff --git a/packages/cryptography/src/Password/PasswordHashingConfig.php b/packages/cryptography/src/Password/PasswordHashingConfig.php index 683dac6a4..a561ed49b 100644 --- a/packages/cryptography/src/Password/PasswordHashingConfig.php +++ b/packages/cryptography/src/Password/PasswordHashingConfig.php @@ -4,10 +4,14 @@ interface PasswordHashingConfig { - public HashingAlgorithm $algorithm { get; } + public HashingAlgorithm $algorithm { + get; + } /** * Options for PHP's `password_hash` and `password_verify` functions. */ - public array $options { get; } + public array $options { + get; + } } diff --git a/packages/cryptography/src/Signing/Exceptions/SigningException.php b/packages/cryptography/src/Signing/Exceptions/SigningException.php index 89dad5655..48e42aab5 100644 --- a/packages/cryptography/src/Signing/Exceptions/SigningException.php +++ b/packages/cryptography/src/Signing/Exceptions/SigningException.php @@ -2,4 +2,6 @@ namespace Tempest\Cryptography\Signing\Exceptions; -interface SigningException {} +interface SigningException +{ +} diff --git a/packages/cryptography/src/Signing/Signer.php b/packages/cryptography/src/Signing/Signer.php index 88002be90..6d40b6108 100644 --- a/packages/cryptography/src/Signing/Signer.php +++ b/packages/cryptography/src/Signing/Signer.php @@ -4,7 +4,9 @@ interface Signer { - public SigningAlgorithm $algorithm { get; } + public SigningAlgorithm $algorithm { + get; + } /** * Signs the given data. diff --git a/packages/database/src/Builder/QueryBuilders/BuildsQuery.php b/packages/database/src/Builder/QueryBuilders/BuildsQuery.php index 9ec20e885..712ac65b2 100644 --- a/packages/database/src/Builder/QueryBuilders/BuildsQuery.php +++ b/packages/database/src/Builder/QueryBuilders/BuildsQuery.php @@ -16,17 +16,23 @@ interface BuildsQuery * * @return array */ - public array $bindings { get; } + public array $bindings { + get; + } /** * The model inspector for this query builder. */ - public ModelInspector $model { get; } + public ModelInspector $model { + get; + } /** * The database tag for targeting a specific database connection. */ - public null|string|UnitEnum $onDatabase { get; } + public null|string|UnitEnum $onDatabase { + get; + } /** * Creates a {@see Query} instance with the specified optional bindings. diff --git a/packages/database/src/Builder/QueryBuilders/QueryBuilder.php b/packages/database/src/Builder/QueryBuilders/QueryBuilder.php index 9cb558dd1..d725161a4 100644 --- a/packages/database/src/Builder/QueryBuilders/QueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/QueryBuilder.php @@ -200,8 +200,7 @@ public function get(string|int|PrimaryKey $id, array $relations = []): ?object default => new PrimaryKey($id), }; - return $this - ->select() + return $this->select() ->with(...$relations) ->get($id); } @@ -213,8 +212,7 @@ public function get(string|int|PrimaryKey $id, array $relations = []): ?object */ public function all(array $relations = []): array { - return $this - ->select() + return $this->select() ->with(...$relations) ->all(); } diff --git a/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php index c194309f2..e05fc333e 100644 --- a/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php @@ -203,8 +203,7 @@ public function chunk(Closure $closure, int $amountPerChunk = 200): void $offset = 0; do { - $data = $this - ->clone() + $data = $this->clone() ->limit($amountPerChunk) ->offset($offset) ->all(); diff --git a/packages/database/src/Builder/QueryBuilders/SupportsJoins.php b/packages/database/src/Builder/QueryBuilders/SupportsJoins.php index 28ef8fe10..7e6dd4182 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsJoins.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsJoins.php @@ -14,5 +14,7 @@ interface SupportsJoins * * @return array */ - public array $joins { get; } + public array $joins { + get; + } } diff --git a/packages/database/src/Builder/QueryBuilders/SupportsRelations.php b/packages/database/src/Builder/QueryBuilders/SupportsRelations.php index 366aedd93..17bccd029 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsRelations.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsRelations.php @@ -14,7 +14,9 @@ interface SupportsRelations * * @return array */ - public array $relations { get; } + public array $relations { + get; + } /** * Gets all resolved relations with their join statements. diff --git a/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php b/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php index 90eb7158e..ce48e8dbe 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php @@ -17,7 +17,9 @@ interface SupportsWhereStatements * * @var ImmutableArray */ - public ImmutableArray $wheres { get; } + public ImmutableArray $wheres { + get; + } /** * Adds a WHERE condition to the query. diff --git a/packages/database/src/Config/DatabaseConfig.php b/packages/database/src/Config/DatabaseConfig.php index ced0c3d8c..581a5b878 100644 --- a/packages/database/src/Config/DatabaseConfig.php +++ b/packages/database/src/Config/DatabaseConfig.php @@ -13,40 +13,56 @@ interface DatabaseConfig extends HasTag /** * PDO data source name connection string. */ - public string $dsn { get; } + public string $dsn { + get; + } /** * The naming strategy for database tables and columns. */ - public NamingStrategy $namingStrategy { get; } + public NamingStrategy $namingStrategy { + get; + } /** * The naming strategy for migration file prefixes. */ - public MigrationNamingStrategy $migrationNamingStrategy { get; } + public MigrationNamingStrategy $migrationNamingStrategy { + get; + } /** * The database dialect (MySQL, PostgreSQL, SQLite). */ - public DatabaseDialect $dialect { get; } + public DatabaseDialect $dialect { + get; + } /** * The database username for authentication. */ - public ?string $username { get; } + public ?string $username { + get; + } /** * The database password for authentication. */ - public ?string $password { get; } + public ?string $password { + get; + } /** * Whether to use persistent database connections. */ - public bool $usePersistentConnection { get; } + public bool $usePersistentConnection { + get; + } /** * PDO connection options built from configuration properties. */ - public array $options { get; } + public array $options { + get; + } } diff --git a/packages/database/src/Database.php b/packages/database/src/Database.php index 966e492de..6f12cf132 100644 --- a/packages/database/src/Database.php +++ b/packages/database/src/Database.php @@ -17,12 +17,16 @@ interface Database /** * The dialect of this database. */ - public DatabaseDialect $dialect { get; } + public DatabaseDialect $dialect { + get; + } /** * The tag associated with this database, if any. */ - public null|string|UnitEnum $tag { get; } + public null|string|UnitEnum $tag { + get; + } /** * Executes the given query. diff --git a/packages/database/src/Eager.php b/packages/database/src/Eager.php index 9efd7e34e..cd3767dc6 100644 --- a/packages/database/src/Eager.php +++ b/packages/database/src/Eager.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Eager {} +final readonly class Eager +{ +} diff --git a/packages/database/src/Exceptions/DatabaseException.php b/packages/database/src/Exceptions/DatabaseException.php index c9e7b4a99..f7ae18e52 100644 --- a/packages/database/src/Exceptions/DatabaseException.php +++ b/packages/database/src/Exceptions/DatabaseException.php @@ -4,4 +4,6 @@ namespace Tempest\Database\Exceptions; -interface DatabaseException {} +interface DatabaseException +{ +} diff --git a/packages/database/src/HasLeadingStatements.php b/packages/database/src/HasLeadingStatements.php index 42946c0ae..d6f126fe1 100644 --- a/packages/database/src/HasLeadingStatements.php +++ b/packages/database/src/HasLeadingStatements.php @@ -4,5 +4,7 @@ interface HasLeadingStatements { - public array $leadingStatements { get; } + public array $leadingStatements { + get; + } } diff --git a/packages/database/src/HasTrailingStatements.php b/packages/database/src/HasTrailingStatements.php index b91b4ce66..081220705 100644 --- a/packages/database/src/HasTrailingStatements.php +++ b/packages/database/src/HasTrailingStatements.php @@ -4,5 +4,7 @@ interface HasTrailingStatements { - public array $trailingStatements { get; } + public array $trailingStatements { + get; + } } diff --git a/packages/database/src/Lazy.php b/packages/database/src/Lazy.php index a43fcc67f..b112d9e03 100644 --- a/packages/database/src/Lazy.php +++ b/packages/database/src/Lazy.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Lazy {} +final readonly class Lazy +{ +} diff --git a/packages/database/src/MigratesDown.php b/packages/database/src/MigratesDown.php index a3414f14d..a18004d87 100644 --- a/packages/database/src/MigratesDown.php +++ b/packages/database/src/MigratesDown.php @@ -6,7 +6,9 @@ interface MigratesDown { - public string $name { get; } + public string $name { + get; + } public function down(): QueryStatement; } diff --git a/packages/database/src/MigratesUp.php b/packages/database/src/MigratesUp.php index c25a08409..9a436fb8b 100644 --- a/packages/database/src/MigratesUp.php +++ b/packages/database/src/MigratesUp.php @@ -6,7 +6,9 @@ interface MigratesUp { - public string $name { get; } + public string $name { + get; + } public function up(): QueryStatement; } diff --git a/packages/database/src/Migrations/MigrationException.php b/packages/database/src/Migrations/MigrationException.php index 96d065eca..c9e7cb307 100644 --- a/packages/database/src/Migrations/MigrationException.php +++ b/packages/database/src/Migrations/MigrationException.php @@ -4,4 +4,6 @@ namespace Tempest\Database\Migrations; -interface MigrationException {} +interface MigrationException +{ +} diff --git a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php index bf359c437..9640b4e8e 100644 --- a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php @@ -30,8 +30,8 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', DatabaseDialect::POSTGRESQL => sprintf( <<<'PSQL' - CREATE TYPE "%s" AS ENUM (%s); - PSQL, + CREATE TYPE "%s" AS ENUM (%s); + PSQL, str($this->enumClass)->replace('\\\\', '_'), $cases->implode(', '), ), diff --git a/packages/database/src/QueryStatements/DropEnumTypeStatement.php b/packages/database/src/QueryStatements/DropEnumTypeStatement.php index 16396dcf7..35fddb0da 100644 --- a/packages/database/src/QueryStatements/DropEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/DropEnumTypeStatement.php @@ -24,8 +24,8 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', DatabaseDialect::POSTGRESQL => sprintf( <<<'PSQL' - DROP TYPE IF EXISTS "%s"; - PSQL, + DROP TYPE IF EXISTS "%s"; + PSQL, str($this->enumClass)->replace('\\\\', '_'), ), }; diff --git a/packages/database/src/QueryStatements/HasWhereStatements.php b/packages/database/src/QueryStatements/HasWhereStatements.php index def527731..91869b104 100644 --- a/packages/database/src/QueryStatements/HasWhereStatements.php +++ b/packages/database/src/QueryStatements/HasWhereStatements.php @@ -7,5 +7,7 @@ interface HasWhereStatements { /** @var ImmutableArray */ - public ImmutableArray $where { get; } + public ImmutableArray $where { + get; + } } diff --git a/packages/database/src/QueryStatements/ShowTablesStatement.php b/packages/database/src/QueryStatements/ShowTablesStatement.php index c29826f74..23d79dd54 100644 --- a/packages/database/src/QueryStatements/ShowTablesStatement.php +++ b/packages/database/src/QueryStatements/ShowTablesStatement.php @@ -23,11 +23,11 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL => "SHOW FULL TABLES WHERE table_type = 'BASE TABLE'", DatabaseDialect::SQLITE => "select type, name from sqlite_master where type = 'table' and name not like 'sqlite_%'", DatabaseDialect::POSTGRESQL => << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, <<', $queryBuilder); diff --git a/packages/datetime/src/Exception/DateTimeException.php b/packages/datetime/src/Exception/DateTimeException.php index 465fb7fad..f2a011621 100644 --- a/packages/datetime/src/Exception/DateTimeException.php +++ b/packages/datetime/src/Exception/DateTimeException.php @@ -4,4 +4,6 @@ namespace Tempest\DateTime\Exception; -interface DateTimeException {} +interface DateTimeException +{ +} diff --git a/packages/datetime/src/Exception/OverflowException.php b/packages/datetime/src/Exception/OverflowException.php index aac737522..889ff5d0c 100644 --- a/packages/datetime/src/Exception/OverflowException.php +++ b/packages/datetime/src/Exception/OverflowException.php @@ -6,4 +6,6 @@ use OverflowException as PhpOverflowException; -final class OverflowException extends PhpOverflowException implements DateTimeException {} +final class OverflowException extends PhpOverflowException implements DateTimeException +{ +} diff --git a/packages/datetime/src/Exception/ParserException.php b/packages/datetime/src/Exception/ParserException.php index 62edddb61..199391651 100644 --- a/packages/datetime/src/Exception/ParserException.php +++ b/packages/datetime/src/Exception/ParserException.php @@ -4,4 +4,6 @@ namespace Tempest\DateTime\Exception; -final class ParserException extends RuntimeException {} +final class ParserException extends RuntimeException +{ +} diff --git a/packages/datetime/src/Exception/RuntimeException.php b/packages/datetime/src/Exception/RuntimeException.php index 709ce27ed..a3228748a 100644 --- a/packages/datetime/src/Exception/RuntimeException.php +++ b/packages/datetime/src/Exception/RuntimeException.php @@ -7,4 +7,6 @@ use RuntimeException as PhpRuntimeException; // @phpstan-ignore-next-line -class RuntimeException extends PhpRuntimeException implements DateTimeException {} +class RuntimeException extends PhpRuntimeException implements DateTimeException +{ +} diff --git a/packages/datetime/src/Exception/UnderflowException.php b/packages/datetime/src/Exception/UnderflowException.php index 87b6c2936..a29986966 100644 --- a/packages/datetime/src/Exception/UnderflowException.php +++ b/packages/datetime/src/Exception/UnderflowException.php @@ -6,4 +6,6 @@ use UnderflowException as PhpUnderflowException; -final class UnderflowException extends PhpUnderflowException implements DateTimeException {} +final class UnderflowException extends PhpUnderflowException implements DateTimeException +{ +} diff --git a/packages/debug/src/Debug.php b/packages/debug/src/Debug.php index 4899fb2f0..cd17c4ef2 100644 --- a/packages/debug/src/Debug.php +++ b/packages/debug/src/Debug.php @@ -97,16 +97,16 @@ private function writeToOut(array $items, string $callPath): void echo vsprintf( <<%s (%s) - HTML, + %s (%s) + HTML, [ 'Source Code Pro, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace', $key, diff --git a/packages/event-bus/src/StopsPropagation.php b/packages/event-bus/src/StopsPropagation.php index a296547f9..ac3241e03 100644 --- a/packages/event-bus/src/StopsPropagation.php +++ b/packages/event-bus/src/StopsPropagation.php @@ -5,4 +5,6 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] -final readonly class StopsPropagation {} +final readonly class StopsPropagation +{ +} diff --git a/packages/event-bus/tests/Fixtures/EventInterface.php b/packages/event-bus/tests/Fixtures/EventInterface.php index 1be684456..0cfc74c27 100644 --- a/packages/event-bus/tests/Fixtures/EventInterface.php +++ b/packages/event-bus/tests/Fixtures/EventInterface.php @@ -4,4 +4,6 @@ namespace Tempest\EventBus\Tests\Fixtures; -interface EventInterface {} +interface EventInterface +{ +} diff --git a/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php b/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php index 8f56d225d..9b9fa7921 100644 --- a/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php +++ b/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php @@ -4,4 +4,6 @@ namespace Tempest\EventBus\Tests\Fixtures; -final readonly class EventInterfaceImplementation implements EventInterface {} +final readonly class EventInterfaceImplementation implements EventInterface +{ +} diff --git a/packages/event-bus/tests/Fixtures/ItHappened.php b/packages/event-bus/tests/Fixtures/ItHappened.php index 2dd32f315..37fcd827c 100644 --- a/packages/event-bus/tests/Fixtures/ItHappened.php +++ b/packages/event-bus/tests/Fixtures/ItHappened.php @@ -4,4 +4,6 @@ namespace Tempest\EventBus\Tests\Fixtures; -final readonly class ItHappened {} +final readonly class ItHappened +{ +} diff --git a/packages/generation/src/Php/Exceptions/FileGenerationException.php b/packages/generation/src/Php/Exceptions/FileGenerationException.php index 00d8bac3f..6c9e18f78 100644 --- a/packages/generation/src/Php/Exceptions/FileGenerationException.php +++ b/packages/generation/src/Php/Exceptions/FileGenerationException.php @@ -4,4 +4,6 @@ namespace Tempest\Generation\Php\Exceptions; -interface FileGenerationException {} +interface FileGenerationException +{ +} diff --git a/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php b/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php index 9a08bb47e..1e3004432 100644 --- a/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php +++ b/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php @@ -6,4 +6,6 @@ use Exception; -final class FileGenerationWasAborted extends Exception implements FileGenerationException {} +final class FileGenerationWasAborted extends Exception implements FileGenerationException +{ +} diff --git a/packages/generation/src/TypeScript/AsType.php b/packages/generation/src/TypeScript/AsType.php index b4b18db82..dd4fc72e4 100644 --- a/packages/generation/src/TypeScript/AsType.php +++ b/packages/generation/src/TypeScript/AsType.php @@ -8,4 +8,6 @@ * Marks this class as a source for TypeScript type generation. */ #[Attribute(Attribute::TARGET_CLASS)] -final class AsType {} +final class AsType +{ +} diff --git a/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php b/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php index 3294dcf56..fdcc7c892 100644 --- a/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php +++ b/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php @@ -11,19 +11,27 @@ interface TypeScriptGenerationConfig * * @var class-string */ - public string $writer { get; } + public string $writer { + get; + } /** * The list of source classes to generate types for. * * @var array */ - public array $sources { get; set; } + public array $sources { + get; + set; + } /** * The list of type resolvers for property-level type mapping. * * @var array> */ - public array $resolvers { get; set; } + public array $resolvers { + get; + set; + } } diff --git a/packages/generation/tests/Php/ClassGeneratorTest.php b/packages/generation/tests/Php/ClassGeneratorTest.php index b18bc5d65..2a3072e46 100644 --- a/packages/generation/tests/Php/ClassGeneratorTest.php +++ b/packages/generation/tests/Php/ClassGeneratorTest.php @@ -28,14 +28,14 @@ public function creates_class_from_scratch(): void $class->setReadOnly(); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $class->addMethod('getName', body: <<assertMatchesSnapshot($class->print()); } @@ -50,8 +50,8 @@ public function creates_methods_with_parameters(): void $class->setReadOnly(); $class->addMethod('findById', body: << 'int'], returnType: '?App\\Models\\User'); + // + PHP, parameters: ['id' => 'int'], returnType: '?App\\Models\\User'); $this->assertMatchesSnapshot($class->print()); } @@ -73,10 +73,10 @@ public function simplify_class_names_by_default(): void $class = new ClassGenerator('CreateUsersTable', namespace: 'App'); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $this->assertMatchesSnapshot($class->print()); } @@ -88,10 +88,10 @@ public function does_not_simplify_class_names(): void $class->simplifyClassNamesInMethodBodies(false); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $this->assertMatchesSnapshot($class->print()); } diff --git a/packages/generation/tests/Php/Fixtures/ClassFromFile.php b/packages/generation/tests/Php/Fixtures/ClassFromFile.php index 2ca7a96e4..724347072 100644 --- a/packages/generation/tests/Php/Fixtures/ClassFromFile.php +++ b/packages/generation/tests/Php/Fixtures/ClassFromFile.php @@ -4,4 +4,6 @@ namespace Tempest\Generation\Tests\Php\Fixtures; -final readonly class ClassFromFile {} +final readonly class ClassFromFile +{ +} diff --git a/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php b/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php index 5cdf78f0e..98ce82e66 100644 --- a/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php +++ b/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php @@ -11,5 +11,6 @@ final class ClassWithMethodParameterAttributes public function example( #[SampleParameterAttribute] string $parameter, - ): void {} + ): void { + } } diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php index 179cd4746..ae38bb730 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php @@ -4,4 +4,6 @@ namespace Tempest\Generation\Tests\Php\Fixtures\SampleNamespace; -final class DummyFqcn {} +final class DummyFqcn +{ +} diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php index 811dbc7d2..7205acca8 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php @@ -6,5 +6,7 @@ trait ExampleTrait { - public function traitMethod(): void {} + public function traitMethod(): void + { + } } diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php index 5ac1bc345..9d2bf3318 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_PARAMETER)] -final class SampleParameterAttribute {} +final class SampleParameterAttribute +{ +} diff --git a/packages/generation/tests/Php/Fixtures/TestAttribute.php b/packages/generation/tests/Php/Fixtures/TestAttribute.php index 4eace3257..91486e42b 100644 --- a/packages/generation/tests/Php/Fixtures/TestAttribute.php +++ b/packages/generation/tests/Php/Fixtures/TestAttribute.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS)] -final class TestAttribute {} +final class TestAttribute +{ +} diff --git a/packages/http/src/Request.php b/packages/http/src/Request.php index 7193d4f57..794d42c86 100644 --- a/packages/http/src/Request.php +++ b/packages/http/src/Request.php @@ -8,25 +8,43 @@ interface Request { - public Method $method { get; } + public Method $method { + get; + } - public string $uri { get; } + public string $uri { + get; + } - public ?string $raw { get; } + public ?string $raw { + get; + } - public array $body { get; } + public array $body { + get; + } - public RequestHeaders $headers { get; } + public RequestHeaders $headers { + get; + } - public string $path { get; } + public string $path { + get; + } - public array $query { get; } + public array $query { + get; + } /** @var \Tempest\Http\Upload[] $files */ - public array $files { get; } + public array $files { + get; + } /** @var Cookie[] $cookies */ - public array $cookies { get; } + public array $cookies { + get; + } public function has(string $key): bool; diff --git a/packages/http/src/Response.php b/packages/http/src/Response.php index 2c92b36b6..ea7bac8b3 100644 --- a/packages/http/src/Response.php +++ b/packages/http/src/Response.php @@ -15,19 +15,25 @@ interface Response /** * Gets the status code of the response. */ - public Status $status { get; } + public Status $status { + get; + } /** * Gets the headers of the response. * * @var \Tempest\Http\Header[] $headers */ - public array $headers { get; } + public array $headers { + get; + } /** * Gets the body of the response. */ - public View|string|array|Generator|JsonSerializable|null $body { get; } + public View|string|array|Generator|JsonSerializable|null $body { + get; + } /** * Gets a header by its name, case insensitive. diff --git a/packages/http/src/Responses/Download.php b/packages/http/src/Responses/Download.php index a5ee7f9e2..75b08fcd0 100644 --- a/packages/http/src/Responses/Download.php +++ b/packages/http/src/Responses/Download.php @@ -16,8 +16,7 @@ public function __construct(string $path, ?string $filename = null) { $filename ??= pathinfo($path, PATHINFO_BASENAME); - $this - ->addHeader('Content-Disposition', "attachment; filename=\"{$filename}\"") + $this->addHeader('Content-Disposition', "attachment; filename=\"{$filename}\"") ->setContentType(ContentType::fromPath($path)) ->removeHeader('Transfer-Encoding'); diff --git a/packages/http/src/Responses/File.php b/packages/http/src/Responses/File.php index c75213a39..f940def4d 100644 --- a/packages/http/src/Responses/File.php +++ b/packages/http/src/Responses/File.php @@ -16,8 +16,7 @@ public function __construct(string $path, ?string $filename = null) { $filename ??= pathinfo($path, PATHINFO_BASENAME); - $this - ->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"") + $this->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"") ->setContentType(ContentType::fromPath($path)) ->removeHeader('Transfer-Encoding'); diff --git a/packages/http/src/SensitiveField.php b/packages/http/src/SensitiveField.php index 2204b7f0d..0a01792cc 100644 --- a/packages/http/src/SensitiveField.php +++ b/packages/http/src/SensitiveField.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class SensitiveField {} +final class SensitiveField +{ +} diff --git a/packages/http/src/ServerSentEvent.php b/packages/http/src/ServerSentEvent.php index 847bb0aaa..8a8c8d5d2 100644 --- a/packages/http/src/ServerSentEvent.php +++ b/packages/http/src/ServerSentEvent.php @@ -11,12 +11,16 @@ interface ServerSentEvent /** * Defines the ID of this event, which sets the `Last-Event-ID` header in case of a reconnection. */ - public ?int $id { get; } + public ?int $id { + get; + } /** * Defines the event stream's reconnection time in case of a reconnection attempt. */ - public null|Duration|int $retryAfter { get; } + public null|Duration|int $retryAfter { + get; + } /** * The name of the event, which may be listened to by `EventSource#addEventListener`. @@ -29,10 +33,14 @@ interface ServerSentEvent * }) * ``` */ - public ?string $event { get; } + public ?string $event { + get; + } /** * Content of the event. */ - public JsonSerializable|Stringable|string|iterable $data { get; } + public JsonSerializable|Stringable|string|iterable $data { + get; + } } diff --git a/packages/http/src/Session/SessionConfig.php b/packages/http/src/Session/SessionConfig.php index 425d34025..6bbc9264c 100644 --- a/packages/http/src/Session/SessionConfig.php +++ b/packages/http/src/Session/SessionConfig.php @@ -10,7 +10,9 @@ interface SessionConfig /** * Time required for a session to expire. */ - public Duration $expiration { get; } + public Duration $expiration { + get; + } public function createManager(Container $container): SessionManager; } diff --git a/packages/idempotency/src/Exceptions/IdempotencyException.php b/packages/idempotency/src/Exceptions/IdempotencyException.php index 5f0eed9ce..989122683 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyException.php +++ b/packages/idempotency/src/Exceptions/IdempotencyException.php @@ -6,4 +6,6 @@ use Exception; -abstract class IdempotencyException extends Exception {} +abstract class IdempotencyException extends Exception +{ +} diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index e0bf1d171..52c9c11f4 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -338,5 +338,7 @@ final class SyncInventoryHandler { #[Idempotent] #[CommandHandler] - public function handle(SyncInventoryCommand $command): void {} + public function handle(SyncInventoryCommand $command): void + { + } } diff --git a/packages/intl/bin/plural-rules.php b/packages/intl/bin/plural-rules.php index 9d2957b84..0a79e7795 100755 --- a/packages/intl/bin/plural-rules.php +++ b/packages/intl/bin/plural-rules.php @@ -52,130 +52,130 @@ public function generate(): string private function generateHelperMethods(bool $includeMatchesValues): string { $helpers = <<<'PHP' - /** - * Extracts the integer part of a number. - */ - private static function getIntegerPart(float|int $n): int - { - return (int) abs($n); - } + /** + * Extracts the integer part of a number. + */ + private static function getIntegerPart(float|int $n): int + { + return (int) abs($n); + } - /** - * Counts visible fractional digits. - */ - private static function getVisibleFractionalDigits(float|int $n): int - { - $str = (string) $n; + /** + * Counts visible fractional digits. + */ + private static function getVisibleFractionalDigits(float|int $n): int + { + $str = (string) $n; - if (! str_contains($str, '.')) { - return 0; - } - - return strlen(rtrim(explode('.', $str)[1], '0')); + if (! str_contains($str, '.')) { + return 0; } - /** - * Gets fractional digits as integer. - */ - private static function getFractionalDigits(float|int $n): int - { - $str = (string) $n; + return strlen(rtrim(explode('.', $str)[1], '0')); + } - if (! str_contains($str, '.')) { - return 0; - } + /** + * Gets fractional digits as integer. + */ + private static function getFractionalDigits(float|int $n): int + { + $str = (string) $n; - return (int) rtrim(explode('.', $str)[1], '0') ?: 0; + if (! str_contains($str, '.')) { + return 0; } - /** - * Gets compact decimal exponent (magnitude). - */ - private static function getCompactExponent(float|int $n): int - { - if ($n === 0 || $n === 0.0) { - return 0; - } - - $abs = abs($n); - - if ($abs >= 1000000) { - return 6; - } - - if ($abs >= 1000) { - return 3; - } + return (int) rtrim(explode('.', $str)[1], '0') ?: 0; + } + /** + * Gets compact decimal exponent (magnitude). + */ + private static function getCompactExponent(float|int $n): int + { + if ($n === 0 || $n === 0.0) { return 0; } - /** - * Gets the exponent for scientific notation. - */ - private static function getExponent(float|int $n): int - { - if ($n === 0 || $n === 0.0) { - return 0; - } + $abs = abs($n); - return (int) floor(log10(abs($n))); + if ($abs >= 1000000) { + return 6; } - /** - * Checks if number is in range. - */ - private static function inRange(int|float $value, int|float $start, int|float $end): bool - { - return $value >= $start && $value <= $end; + if ($abs >= 1000) { + return 3; } - /** - * Checks whether two numeric values are equal. - */ - private static function isEqual(int|float $left, int|float $right): bool - { - return $left === $right; + return 0; + } + + /** + * Gets the exponent for scientific notation. + */ + private static function getExponent(float|int $n): int + { + if ($n === 0 || $n === 0.0) { + return 0; } - PHP; + return (int) floor(log10(abs($n))); + } + + /** + * Checks if number is in range. + */ + private static function inRange(int|float $value, int|float $start, int|float $end): bool + { + return $value >= $start && $value <= $end; + } + + /** + * Checks whether two numeric values are equal. + */ + private static function isEqual(int|float $left, int|float $right): bool + { + return $left === $right; + } + + PHP; if (! $includeMatchesValues) { return $helpers; } return $helpers . <<<'PHP' - /** - * Checks if number matches any value in comma-separated list. - */ - private static function matchesValues(int|float $value, string $values): bool - { - $parts = explode(',', $values); - - foreach ($parts as $part) { - $part = trim($part); - - if (str_contains($part, '~')) { - [$start, $end] = explode('~', $part); - - if (self::inRange($value, (float) trim($start), (float) trim($end))) { - return true; - } - } elseif (str_contains($part, '..')) { - [$start, $end] = explode('..', $part); - - if (self::inRange($value, (float) trim($start), (float) trim($end))) { - return true; - } - } elseif ((float) $part === (float) $value) { + /** + * Checks if number matches any value in comma-separated list. + */ + private static function matchesValues(int|float $value, string $values): bool + { + $parts = explode(',', $values); + + foreach ($parts as $part) { + $part = trim($part); + + if (str_contains($part, '~')) { + [$start, $end] = explode('~', $part); + + if (self::inRange($value, (float) trim($start), (float) trim($end))) { return true; } - } + } elseif (str_contains($part, '..')) { + [$start, $end] = explode('..', $part); - return false; + if (self::inRange($value, (float) trim($start), (float) trim($end))) { + return true; + } + } elseif ((float) $part === (float) $value) { + return true; + } } - PHP; + return false; + } + + PHP; } private function generateLanguageMethod(string $locale, array $rules): string diff --git a/packages/intl/src/MessageFormat/FormattingFunction.php b/packages/intl/src/MessageFormat/FormattingFunction.php index fc15e67d3..126884408 100644 --- a/packages/intl/src/MessageFormat/FormattingFunction.php +++ b/packages/intl/src/MessageFormat/FormattingFunction.php @@ -9,7 +9,9 @@ interface FormattingFunction /** * Identifier of the formatting function. */ - public string $name { get; } + public string $name { + get; + } /** * Formats the given value with the given parameters. diff --git a/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php b/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php index b5a039765..df661703f 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php @@ -4,4 +4,6 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Declaration extends Node {} +interface Declaration extends Node +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php b/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php index 815996002..5cb1a7378 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php @@ -4,4 +4,6 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Key extends Node {} +interface Key extends Node +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php b/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php index 4512d0147..81d144d04 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php @@ -2,4 +2,6 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Key; -final class WildcardKey implements Key {} +final class WildcardKey implements Key +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php b/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php index 109673762..a50fdfae6 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php @@ -2,4 +2,6 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Literal; -final class QuotedLiteral extends Literal {} +final class QuotedLiteral extends Literal +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php b/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php index 7b1109096..7fda533db 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php @@ -2,4 +2,6 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Literal; -final class UnquotedLiteral extends Literal {} +final class UnquotedLiteral extends Literal +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Node.php b/packages/intl/src/MessageFormat/Parser/Node/Node.php index 675f8bda3..bea306511 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Node.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Node.php @@ -2,4 +2,6 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -interface Node {} +interface Node +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php b/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php index 94fb62f9b..30b38dbd4 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php @@ -4,4 +4,6 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Placeholder extends Node {} +interface Placeholder extends Node +{ +} diff --git a/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php b/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php index b0fb3b404..dbc597e90 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php +++ b/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php @@ -2,4 +2,6 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -final class SimpleMessage extends MessageNode {} +final class SimpleMessage extends MessageNode +{ +} diff --git a/packages/intl/src/MessageFormat/SelectorFunction.php b/packages/intl/src/MessageFormat/SelectorFunction.php index e3020b3a9..0d2a31207 100644 --- a/packages/intl/src/MessageFormat/SelectorFunction.php +++ b/packages/intl/src/MessageFormat/SelectorFunction.php @@ -7,7 +7,9 @@ interface SelectorFunction /** * Identifier of the selector function. */ - public string $name { get; } + public string $name { + get; + } /** * Defines whether the matcher key matches with the given value. diff --git a/packages/intl/tests/FormatterTest.php b/packages/intl/tests/FormatterTest.php index 3bfc6da4e..e7428c305 100644 --- a/packages/intl/tests/FormatterTest.php +++ b/packages/intl/tests/FormatterTest.php @@ -44,8 +44,8 @@ public function test_placeholder_variable(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Hello, {$name}! - TXT, name: 'Jon'); + Hello, {$name}! + TXT, name: 'Jon'); $this->assertSame('Hello, Jon!', $value); } @@ -59,8 +59,8 @@ public function test_format_datetime_function_and_parameters(): void $formatter = new MessageFormatter([$this->createDateTimeFunction()]); $value = $formatter->format(<<<'TXT' - Today is {$today :datetime pattern=|yyyy/MM/dd|}. - TXT, today: '2024-01-01'); + Today is {$today :datetime pattern=|yyyy/MM/dd|}. + TXT, today: '2024-01-01'); $this->assertSame('Today is 2024/01/01.', $value); } @@ -70,8 +70,8 @@ public function test_format_number_function(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - The total was {31 :number style=percent}. - TXT); + The total was {31 :number style=percent}. + TXT); $this->assertSame('The total was 31%.', $value); } @@ -84,12 +84,12 @@ public function test_match_number(int $count, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$aircraft :number} - .match $aircraft - 0 {{pas d‘avion}} - 1 {{un avion}} - * {{{$aircraft} avions}} - TXT, aircraft: $count); + .input {$aircraft :number} + .match $aircraft + 0 {{pas d‘avion}} + 1 {{un avion}} + * {{{$aircraft} avions}} + TXT, aircraft: $count); $this->assertSame($expected, $value); } @@ -99,16 +99,16 @@ public function test_default_input(): void $formatter = new MessageFormatter([]); $value = $formatter->format(<<<'TXT' - .input {$field :string default=unknown} - field is {$field} - TXT); + .input {$field :string default=unknown} + field is {$field} + TXT); $this->assertSame('field is unknown', $value); $value = $formatter->format(<<<'TXT' - .input {$field :string default=unknown} - field is {$field} - TXT, field: 'here'); + .input {$field :string default=unknown} + field is {$field} + TXT, field: 'here'); $this->assertSame('field is here', $value); } @@ -117,8 +117,8 @@ public function test_unquoted_text(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Hello, {world}! - TXT); + Hello, {world}! + TXT); $this->assertSame('Hello, world!', $value); } @@ -127,8 +127,8 @@ public function test_quoted_text(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - My name is {|John Doe|}. - TXT); + My name is {|John Doe|}. + TXT); $this->assertSame('My name is John Doe.', $value); } @@ -137,11 +137,11 @@ public function test_number_matcher(): void { $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number} - .match $count - one {{You have {$count} notification.}} - * {{You have {$count} notifications.}} - TXT, count: 1); + .input {$count :number} + .match $count + one {{You have {$count} notification.}} + * {{You have {$count} notifications.}} + TXT, count: 1); $this->assertSame('You have 1 notification.', $value); } @@ -150,11 +150,11 @@ public function test_number_matcher_exact(): void { $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number select=exact} - .match $count - one {{You have {$count} notification.}} - * {{You have {$count} notifications.}} - TXT, count: 1); + .input {$count :number select=exact} + .match $count + one {{You have {$count} notification.}} + * {{You have {$count} notifications.}} + TXT, count: 1); $this->assertSame('You have 1 notifications.', $value); } @@ -163,12 +163,12 @@ public function test_local_declaration(): void { $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<<'TXT' - .local $val = {foo2 :string} - .match $val - foo {{Foo}} - bar {{Bar}} - * {{No match}} - TXT); + .local $val = {foo2 :string} + .match $val + foo {{Foo}} + bar {{Bar}} + * {{No match}} + TXT); $this->assertSame('No match', $value); } @@ -177,11 +177,11 @@ public function test_local_declarations_unquoted_literals(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .local $x = {42} - .local $y = {number42} - .local $z = {_number} - {{{$x} {$y} {$z}}} - TXT); + .local $x = {42} + .local $y = {number42} + .local $z = {_number} + {{{$x} {$y} {$z}}} + TXT); $this->assertSame('42 number42 _number', $value); } @@ -190,11 +190,11 @@ public function test_local_declarations_quoted_literals(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .local $x = {|@literal|} - .local $y = {|white space|} - .local $z = {|{{curly braces}}|} - {{{$x} {$y} {$z} {|and \\, a backslash|}}} - TXT); + .local $x = {|@literal|} + .local $y = {|white space|} + .local $z = {|{{curly braces}}|} + {{{$x} {$y} {$z} {|and \\, a backslash|}}} + TXT); $this->assertSame('@literal white space {{curly braces}} and \, a backslash', $value); } @@ -203,9 +203,9 @@ public function test_whitespace(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .input {$num :number} - {{ This is the {$num} pattern }} - TXT, num: 5); + .input {$num :number} + {{ This is the {$num} pattern }} + TXT, num: 5); $this->assertSame(' This is the 5 pattern ', $value); } @@ -214,8 +214,8 @@ public function test_escape(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Backslash: \\, left curly brace \{, right curly brace \} - TXT); + Backslash: \\, left curly brace \{, right curly brace \} + TXT); $this->assertSame('Backslash: \, left curly brace {, right curly brace }', $value); } @@ -224,12 +224,12 @@ public function test_matchers_escape(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .input {$char :string} - .match $char - | | {{You entered a space character.}} - |\|| {{You entered a pipe character.}} - * {{You entered something else.}} - TXT, char: '|'); + .input {$char :string} + .match $char + | | {{You entered a space character.}} + |\|| {{You entered a pipe character.}} + * {{You entered something else.}} + TXT, char: '|'); $this->assertSame('You entered a pipe character.', $value); } @@ -239,12 +239,12 @@ public function test_matchers_number_exact_match(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$numDays :number select=exact} - .match $numDays - 1 {{{$numDays} one}} - 2 {{{$numDays} two}} - 3 {{{$numDays} three}} - TXT, numDays: 2); + .input {$numDays :number select=exact} + .match $numDays + 1 {{{$numDays} one}} + 2 {{{$numDays} two}} + 3 {{{$numDays} three}} + TXT, numDays: 2); $this->assertSame('2 two', $value); } @@ -260,13 +260,13 @@ public function test_matchers_czech(int|float $days, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$days :number} - .match $days - one {{{$days} den}} - few {{{$days} dny}} - many {{{$days} dne}} - * {{{$days} dní}} - TXT, days: $days); + .input {$days :number} + .match $days + one {{{$days} den}} + few {{{$days} dny}} + many {{{$days} dne}} + * {{{$days} dní}} + TXT, days: $days); $this->assertSame($expected, $value); } @@ -279,12 +279,12 @@ public function test_string_function(): void ]); $value = $formatter->format(<<<'TXT' - .input {$operand :string} - .match $operand - 1 {{Number 1}} - one {{String "one"}} - * {{Something else}} - TXT, operand: 1); + .input {$operand :string} + .match $operand + 1 {{Number 1}} + one {{String "one"}} + * {{Something else}} + TXT, operand: 1); $this->assertSame('Number 1', $value); } @@ -298,8 +298,8 @@ public function test_string_formatting(mixed $input, string $expected): void $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<<'TXT' - {$value :string} - TXT, value: $input); + {$value :string} + TXT, value: $input); $this->assertSame($expected, $value); } @@ -316,8 +316,8 @@ public function test_string_formatting_options(mixed $input, string $expected, s $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<assertSame($expected, $value); } @@ -327,8 +327,8 @@ public function test_number_currency(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - You have {42 :number style=currency currency=$currency}. - TXT, currency: Currency::USD); + You have {42 :number style=currency currency=$currency}. + TXT, currency: Currency::USD); $this->assertSame('You have $42.00.', $value); } @@ -338,9 +338,9 @@ public function test_shadowing(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .local $count = {42} - {{The count is: {$count}}} - TXT, count: 32); + .local $count = {42} + {{The count is: {$count}}} + TXT, count: 32); $this->assertSame('The count is: 42', $value); } @@ -353,12 +353,12 @@ public function test_pluralization(int $count, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number} - .match $count - 0 {{No items.}} - one {{1 item.}} - * {{{$count} items.}} - TXT, count: $count); + .input {$count :number} + .match $count + 0 {{No items.}} + one {{1 item.}} + * {{{$count} items.}} + TXT, count: $count); $this->assertSame($expected, $value); } @@ -371,22 +371,22 @@ public function test_multiple_selectors(): void ]); $value = $formatter->format(<<<'TXT' - .input {$hostGender :string} - .input {$guestCount :number} - .match $hostGender $guestCount - female 0 {{{$hostName} does not give a party.}} - female 1 {{{$hostName} invites {$guestName} to her party.}} - female 2 {{{$hostName} invites {$guestName} and one other person to her party.}} - female * {{{$hostName} invites {$guestCount} people, including {$guestName}, to her party.}} - male 0 {{{$hostName} does not give a party.}} - male 1 {{{$hostName} invites {$guestName} to his party.}} - male 2 {{{$hostName} invites {$guestName} and one other person to his party.}} - male * {{{$hostName} invites {$guestCount} people, including {$guestName}, to his party.}} - * 0 {{{$hostName} does not give a party.}} - * 1 {{{$hostName} invites {$guestName} to their party.}} - * 2 {{{$hostName} invites {$guestName} and one other person to their party.}} - * * {{{$hostName} invites {$guestCount} people, including {$guestName}, to their party.}} - TXT, hostGender: 'female', hostName: 'Alice', guestCount: 2, guestName: 'Bob'); + .input {$hostGender :string} + .input {$guestCount :number} + .match $hostGender $guestCount + female 0 {{{$hostName} does not give a party.}} + female 1 {{{$hostName} invites {$guestName} to her party.}} + female 2 {{{$hostName} invites {$guestName} and one other person to her party.}} + female * {{{$hostName} invites {$guestCount} people, including {$guestName}, to her party.}} + male 0 {{{$hostName} does not give a party.}} + male 1 {{{$hostName} invites {$guestName} to his party.}} + male 2 {{{$hostName} invites {$guestName} and one other person to his party.}} + male * {{{$hostName} invites {$guestCount} people, including {$guestName}, to his party.}} + * 0 {{{$hostName} does not give a party.}} + * 1 {{{$hostName} invites {$guestName} to their party.}} + * 2 {{{$hostName} invites {$guestName} and one other person to their party.}} + * * {{{$hostName} invites {$guestCount} people, including {$guestName}, to their party.}} + TXT, hostGender: 'female', hostName: 'Alice', guestCount: 2, guestName: 'Bob'); $this->assertSame('Alice invites Bob and one other person to her party.', $value); } @@ -405,8 +405,8 @@ public function format(mixed $value, array $parameters): FormattedValue ]); $value = $formatter->format(<<<'TXT' - Check out {MessageFormat :uppercase}. - TXT); + Check out {MessageFormat :uppercase}. + TXT); $this->assertSame('Check out MESSAGEFORMAT.', $value); } diff --git a/packages/intl/tests/GenericTranslatorTest.php b/packages/intl/tests/GenericTranslatorTest.php index bbbb82e73..fcc76a9f8 100644 --- a/packages/intl/tests/GenericTranslatorTest.php +++ b/packages/intl/tests/GenericTranslatorTest.php @@ -66,12 +66,12 @@ public function test_complex_message(): void $this->config->currentLocale = Locale::FRENCH; $this->catalog->add(Locale::FRENCH, 'aircraft_count', <<<'MF2' - .input {$aircraft :number} - .match $aircraft - 0 {{pas d'avion}} - 1 {{un avion}} - * {{{$aircraft} avions}} - MF2); + .input {$aircraft :number} + .match $aircraft + 0 {{pas d'avion}} + 1 {{un avion}} + * {{{$aircraft} avions}} + MF2); $this->assertSame("pas d'avion", $this->translator->translate('aircraft_count', aircraft: 0)); $this->assertSame('un avion', $this->translator->translate('aircraft_count', aircraft: 1)); diff --git a/packages/intl/tests/ParserTest.php b/packages/intl/tests/ParserTest.php index 913803459..986091839 100644 --- a/packages/intl/tests/ParserTest.php +++ b/packages/intl/tests/ParserTest.php @@ -30,9 +30,9 @@ public function test_local_declaration(): void { /** @var ComplexMessage $ast */ $ast = new MessageFormatParser(<<<'MF2' - .local $time = {$launch_date :datetime style=|medium|} - Launch time: {$time} - MF2)->parse(); + .local $time = {$launch_date :datetime style=|medium|} + Launch time: {$time} + MF2)->parse(); $this->assertInstanceOf(ComplexMessage::class, $ast); $this->assertInstanceOf(Text::class, $ast->pattern->elements[0]); @@ -53,12 +53,12 @@ public function test_input_declaration(): void { /** @var ComplexMessage $ast */ $ast = new MessageFormatParser(<<<'MF2' - .input {$numDays :number select=exact} - .match $numDays - 1 {{{$numDays} one}} - 2 {{{$numDays} two}} - 3 {{{$numDays} three}} - MF2)->parse(); + .input {$numDays :number select=exact} + .match $numDays + 1 {{{$numDays} one}} + 2 {{{$numDays} two}} + 3 {{{$numDays} three}} + MF2)->parse(); $this->assertInstanceOf(ComplexMessage::class, $ast); $this->assertInstanceOf(InputDeclaration::class, $ast->declarations[0]); @@ -88,8 +88,8 @@ public function test_input_declaration(): void public function test_function_with_option_quoted_literal(): void { $ast = new MessageFormatParser(<<<'MF2' - Today is {$today :datetime pattern=|yyyy/MM/dd|}. - MF2)->parse(); + Today is {$today :datetime pattern=|yyyy/MM/dd|}. + MF2)->parse(); $this->assertInstanceOf(SimpleMessage::class, $ast); $this->assertInstanceOf(VariableExpression::class, $ast->pattern->elements[1]); diff --git a/packages/kv-store/src/Redis/RedisException.php b/packages/kv-store/src/Redis/RedisException.php index 4e1d824d8..ea92d27bd 100644 --- a/packages/kv-store/src/Redis/RedisException.php +++ b/packages/kv-store/src/Redis/RedisException.php @@ -4,4 +4,6 @@ use Throwable; -interface RedisException extends Throwable {} +interface RedisException extends Throwable +{ +} diff --git a/packages/log/src/LogConfig.php b/packages/log/src/LogConfig.php index f78d94106..4e3502073 100644 --- a/packages/log/src/LogConfig.php +++ b/packages/log/src/LogConfig.php @@ -11,12 +11,16 @@ interface LogConfig extends HasTag /** * An optional prefix displayed in all log messages. By default, the current environment is used. */ - public ?string $prefix { get; } + public ?string $prefix { + get; + } /** * The log channels to which log messages will be sent. * * @var LogChannel[] */ - public array $logChannels { get; } + public array $logChannels { + get; + } } diff --git a/packages/log/src/Logger.php b/packages/log/src/Logger.php index e8ba8017e..0ebe03df3 100644 --- a/packages/log/src/Logger.php +++ b/packages/log/src/Logger.php @@ -6,4 +6,6 @@ use Psr\Log\LoggerInterface; -interface Logger extends LoggerInterface {} +interface Logger extends LoggerInterface +{ +} diff --git a/packages/mail/src/Email.php b/packages/mail/src/Email.php index 74a856af4..d8221cfdb 100644 --- a/packages/mail/src/Email.php +++ b/packages/mail/src/Email.php @@ -12,10 +12,14 @@ interface Email /** * The envelope of the email. */ - public Envelope $envelope { get; } + public Envelope $envelope { + get; + } /** * The content of the email can be a path to a view file, raw HTML, or a View object */ - public string|View $html { get; } + public string|View $html { + get; + } } diff --git a/packages/mail/src/Exceptions/MailerException.php b/packages/mail/src/Exceptions/MailerException.php index 0a4747668..fc51bd89c 100644 --- a/packages/mail/src/Exceptions/MailerException.php +++ b/packages/mail/src/Exceptions/MailerException.php @@ -2,4 +2,6 @@ namespace Tempest\Mail\Exceptions; -interface MailerException {} +interface MailerException +{ +} diff --git a/packages/mail/src/HasAttachments.php b/packages/mail/src/HasAttachments.php index 6ef8742ff..70423315c 100644 --- a/packages/mail/src/HasAttachments.php +++ b/packages/mail/src/HasAttachments.php @@ -7,5 +7,7 @@ interface HasAttachments /** * @var \Tempest\Mail\Attachment[] $attachments */ - public array $attachments { get; } + public array $attachments { + get; + } } diff --git a/packages/mail/src/HasTextContent.php b/packages/mail/src/HasTextContent.php index d4b6a33c6..d1e5e6f95 100644 --- a/packages/mail/src/HasTextContent.php +++ b/packages/mail/src/HasTextContent.php @@ -6,5 +6,7 @@ interface HasTextContent { - public string|View|null $text { get; } + public string|View|null $text { + get; + } } diff --git a/packages/mail/src/MailerConfig.php b/packages/mail/src/MailerConfig.php index 28c1ac6f4..4cbfbb618 100644 --- a/packages/mail/src/MailerConfig.php +++ b/packages/mail/src/MailerConfig.php @@ -11,7 +11,9 @@ interface MailerConfig * * @var class-string */ - public string $transport { get; } + public string $transport { + get; + } /** * Creates the transport. diff --git a/packages/mail/src/Transports/ProvidesDefaultSender.php b/packages/mail/src/Transports/ProvidesDefaultSender.php index fceb3701a..20486a443 100644 --- a/packages/mail/src/Transports/ProvidesDefaultSender.php +++ b/packages/mail/src/Transports/ProvidesDefaultSender.php @@ -9,5 +9,7 @@ interface ProvidesDefaultSender /** * The default address from which emails will be sent. */ - public null|string|EmailAddress $defaultSender { get; } + public null|string|EmailAddress $defaultSender { + get; + } } diff --git a/packages/mapper/src/Context.php b/packages/mapper/src/Context.php index 444d8f179..917e1d8b7 100644 --- a/packages/mapper/src/Context.php +++ b/packages/mapper/src/Context.php @@ -10,5 +10,7 @@ interface Context /** * A unique name for this context. */ - public string $name { get; } + public string $name { + get; + } } diff --git a/packages/mapper/src/Hidden.php b/packages/mapper/src/Hidden.php index 964c4379c..9c9e94f05 100644 --- a/packages/mapper/src/Hidden.php +++ b/packages/mapper/src/Hidden.php @@ -10,4 +10,6 @@ * Hidden properties are excluded from SELECT queries and serialization. */ #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Hidden {} +final readonly class Hidden +{ +} diff --git a/packages/mapper/src/ProvidesCaster.php b/packages/mapper/src/ProvidesCaster.php index 9d23e9aa5..921357c6a 100644 --- a/packages/mapper/src/ProvidesCaster.php +++ b/packages/mapper/src/ProvidesCaster.php @@ -8,5 +8,7 @@ interface ProvidesCaster { /** @var class-string */ - public string $caster { get; } + public string $caster { + get; + } } diff --git a/packages/mapper/src/ProvidesSerializer.php b/packages/mapper/src/ProvidesSerializer.php index 0f9cab41b..86efbfb38 100644 --- a/packages/mapper/src/ProvidesSerializer.php +++ b/packages/mapper/src/ProvidesSerializer.php @@ -8,5 +8,7 @@ interface ProvidesSerializer { /** @var class-string */ - public string $serializer { get; } + public string $serializer { + get; + } } diff --git a/packages/mapper/src/Strict.php b/packages/mapper/src/Strict.php index 5f2593655..35a389a17 100644 --- a/packages/mapper/src/Strict.php +++ b/packages/mapper/src/Strict.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] -final readonly class Strict {} +final readonly class Strict +{ +} diff --git a/packages/mapper/src/UnknownValue.php b/packages/mapper/src/UnknownValue.php index e7b599665..170a5c712 100644 --- a/packages/mapper/src/UnknownValue.php +++ b/packages/mapper/src/UnknownValue.php @@ -4,4 +4,6 @@ namespace Tempest\Mapper; -final readonly class UnknownValue {} +final readonly class UnknownValue +{ +} diff --git a/packages/process/src/Exceptions/ProcessException.php b/packages/process/src/Exceptions/ProcessException.php index 7d00205de..00c0f6925 100644 --- a/packages/process/src/Exceptions/ProcessException.php +++ b/packages/process/src/Exceptions/ProcessException.php @@ -4,4 +4,6 @@ use Throwable; -interface ProcessException extends Throwable {} +interface ProcessException extends Throwable +{ +} diff --git a/packages/process/src/InvokedProcess.php b/packages/process/src/InvokedProcess.php index 216abf422..7465f258c 100644 --- a/packages/process/src/InvokedProcess.php +++ b/packages/process/src/InvokedProcess.php @@ -9,22 +9,30 @@ interface InvokedProcess /** * Gets the process identifier. */ - public ?int $pid { get; } + public ?int $pid { + get; + } /** * Whether the process is running. */ - public bool $running { get; } + public bool $running { + get; + } /** * Gets the output of the process. */ - public string $output { get; } + public string $output { + get; + } /** * Gets the error output of the process. */ - public string $errorOutput { get; } + public string $errorOutput { + get; + } /** * Sends a signal to the process. diff --git a/packages/reflection/src/PropertyAttribute.php b/packages/reflection/src/PropertyAttribute.php index 8b5683076..0e669c9ce 100644 --- a/packages/reflection/src/PropertyAttribute.php +++ b/packages/reflection/src/PropertyAttribute.php @@ -4,5 +4,8 @@ interface PropertyAttribute { - public PropertyReflector $property { set; get; } + public PropertyReflector $property { + set; + get; + } } diff --git a/packages/reflection/tests/EnumReflectorTest.php b/packages/reflection/tests/EnumReflectorTest.php index d316b271d..2af7df7d4 100644 --- a/packages/reflection/tests/EnumReflectorTest.php +++ b/packages/reflection/tests/EnumReflectorTest.php @@ -271,7 +271,9 @@ enum TestIntBackedEnum: int case SECOND = 2; } -interface TestInterface {} +interface TestInterface +{ +} enum TestEnumWithInterface: string implements TestInterface { diff --git a/packages/reflection/tests/Fixtures/AnnulledInvoice.php b/packages/reflection/tests/Fixtures/AnnulledInvoice.php index 76bb96e17..f5d5c7f8f 100644 --- a/packages/reflection/tests/Fixtures/AnnulledInvoice.php +++ b/packages/reflection/tests/Fixtures/AnnulledInvoice.php @@ -4,4 +4,6 @@ namespace Tempest\Reflection\Tests\Fixtures; -final readonly class AnnulledInvoice {} +final readonly class AnnulledInvoice +{ +} diff --git a/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php index 622d60770..1483015ae 100644 --- a/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php @@ -4,4 +4,6 @@ namespace Tempest\Reflection\Tests\Fixtures; -final class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute {} +final class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute +{ +} diff --git a/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php index 9558fb05f..39ecc50d5 100644 --- a/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php @@ -4,4 +4,6 @@ namespace Tempest\Reflection\Tests\Fixtures; -final class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute {} +final class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute +{ +} diff --git a/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php index d8f1f2c52..7282e5687 100644 --- a/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php @@ -5,4 +5,6 @@ namespace Tempest\Reflection\Tests\Fixtures; #[RecursiveAttribute] -interface InterfaceWithRecursiveAttribute {} +interface InterfaceWithRecursiveAttribute +{ +} diff --git a/packages/reflection/tests/Fixtures/NullableClass.php b/packages/reflection/tests/Fixtures/NullableClass.php index 6f745ad02..a2af1e599 100644 --- a/packages/reflection/tests/Fixtures/NullableClass.php +++ b/packages/reflection/tests/Fixtures/NullableClass.php @@ -4,4 +4,6 @@ namespace Tempest\Reflection\Tests\Fixtures; -final readonly class NullableClass {} +final readonly class NullableClass +{ +} diff --git a/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php index 76cd13221..9cf1cfe57 100644 --- a/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php @@ -5,4 +5,6 @@ namespace Tempest\Reflection\Tests\Fixtures; #[RecursiveAttribute] -abstract class ParentWithRecursiveAttribute {} +abstract class ParentWithRecursiveAttribute +{ +} diff --git a/packages/reflection/tests/Fixtures/RecursiveAttribute.php b/packages/reflection/tests/Fixtures/RecursiveAttribute.php index cd6814e67..32d3856c7 100644 --- a/packages/reflection/tests/Fixtures/RecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/RecursiveAttribute.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute] -final class RecursiveAttribute {} +final class RecursiveAttribute +{ +} diff --git a/packages/reflection/tests/Fixtures/TestBackedEnum.php b/packages/reflection/tests/Fixtures/TestBackedEnum.php index 6d300b899..e33bbd8d9 100644 --- a/packages/reflection/tests/Fixtures/TestBackedEnum.php +++ b/packages/reflection/tests/Fixtures/TestBackedEnum.php @@ -2,4 +2,6 @@ namespace Tempest\Reflection\Tests\Fixtures; -enum TestBackedEnum: string {} +enum TestBackedEnum: string +{ +} diff --git a/packages/reflection/tests/Fixtures/TestEnum.php b/packages/reflection/tests/Fixtures/TestEnum.php index 9d1c8b629..b9f6052b5 100644 --- a/packages/reflection/tests/Fixtures/TestEnum.php +++ b/packages/reflection/tests/Fixtures/TestEnum.php @@ -2,4 +2,6 @@ namespace Tempest\Reflection\Tests\Fixtures; -enum TestEnum {} +enum TestEnum +{ +} diff --git a/packages/router/src/Exceptions/RouteBindingFailed.php b/packages/router/src/Exceptions/RouteBindingFailed.php index 879ca6d9a..dbd261b54 100644 --- a/packages/router/src/Exceptions/RouteBindingFailed.php +++ b/packages/router/src/Exceptions/RouteBindingFailed.php @@ -6,4 +6,6 @@ use Exception; -final class RouteBindingFailed extends Exception implements RouterException {} +final class RouteBindingFailed extends Exception implements RouterException +{ +} diff --git a/packages/router/src/Exceptions/RouterException.php b/packages/router/src/Exceptions/RouterException.php index e4ecbde43..3f357efb2 100644 --- a/packages/router/src/Exceptions/RouterException.php +++ b/packages/router/src/Exceptions/RouterException.php @@ -2,4 +2,6 @@ namespace Tempest\Router\Exceptions; -interface RouterException {} +interface RouterException +{ +} diff --git a/packages/router/src/IsBindingValue.php b/packages/router/src/IsBindingValue.php index a345c6096..d2f633936 100644 --- a/packages/router/src/IsBindingValue.php +++ b/packages/router/src/IsBindingValue.php @@ -5,4 +5,6 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class IsBindingValue {} +final class IsBindingValue +{ +} diff --git a/packages/router/src/Route.php b/packages/router/src/Route.php index 082d0ed84..3387556c1 100644 --- a/packages/router/src/Route.php +++ b/packages/router/src/Route.php @@ -8,13 +8,25 @@ interface Route { - public Method $method { get; set; } + public Method $method { + get; + set; + } - public string $uri { get; set; } + public string $uri { + get; + set; + } /** @var class-string[] */ - public array $middleware { get; set; } + public array $middleware { + get; + set; + } /** @var class-string[] */ - public array $without { get; set; } + public array $without { + get; + set; + } } diff --git a/packages/router/src/Static/Exceptions/StaticPageException.php b/packages/router/src/Static/Exceptions/StaticPageException.php index 44810abb4..d6c563afc 100644 --- a/packages/router/src/Static/Exceptions/StaticPageException.php +++ b/packages/router/src/Static/Exceptions/StaticPageException.php @@ -4,5 +4,7 @@ interface StaticPageException { - public string $uri { get; } + public string $uri { + get; + } } diff --git a/packages/router/tests/FakeRouteBuilder.php b/packages/router/tests/FakeRouteBuilder.php index 08f523e8f..1d041c799 100644 --- a/packages/router/tests/FakeRouteBuilder.php +++ b/packages/router/tests/FakeRouteBuilder.php @@ -47,5 +47,7 @@ public function asDiscoveredRoute(): DiscoveredRoute return DiscoveredRoute::fromRoute($this, [], $this->handler); } - public function handler(): void {} + public function handler(): void + { + } } diff --git a/packages/router/tests/FakeRouteBuilderWithOptionalParams.php b/packages/router/tests/FakeRouteBuilderWithOptionalParams.php index 95e71f316..ed03e644e 100644 --- a/packages/router/tests/FakeRouteBuilderWithOptionalParams.php +++ b/packages/router/tests/FakeRouteBuilderWithOptionalParams.php @@ -53,11 +53,19 @@ public function asDiscoveredRoute(): DiscoveredRoute return DiscoveredRoute::fromRoute($this, [], $this->handler); } - public function handler(): void {} + public function handler(): void + { + } - public function handlerWithOptionalId(string $id = 'default-id'): void {} + public function handlerWithOptionalId(string $id = 'default-id'): void + { + } - public function handlerWithTwoOptionalParams(string $id = 'default-id', string $slug = 'default-slug'): void {} + public function handlerWithTwoOptionalParams(string $id = 'default-id', string $slug = 'default-slug'): void + { + } - public function handlerWithRequiredAndOptional(string $id, string $slug = 'default-slug'): void {} + public function handlerWithRequiredAndOptional(string $id, string $slug = 'default-slug'): void + { + } } diff --git a/packages/storage/src/Config/StorageConfig.php b/packages/storage/src/Config/StorageConfig.php index 33b8b33f9..1c0b4b921 100644 --- a/packages/storage/src/Config/StorageConfig.php +++ b/packages/storage/src/Config/StorageConfig.php @@ -10,12 +10,17 @@ interface StorageConfig extends HasTag /** * Whether the storage is read-only. */ - public bool $readonly { get; set; } + public bool $readonly { + get; + set; + } /** * The adapter class. */ - public string $adapter { get; } + public string $adapter { + get; + } /** * Creates the adapter. diff --git a/packages/storage/src/StorageException.php b/packages/storage/src/StorageException.php index f4a4bcb0c..9136ec1d7 100644 --- a/packages/storage/src/StorageException.php +++ b/packages/storage/src/StorageException.php @@ -2,4 +2,6 @@ namespace Tempest\Storage; -interface StorageException {} +interface StorageException +{ +} diff --git a/packages/support/src/Arr/OffsetDidNotExist.php b/packages/support/src/Arr/OffsetDidNotExist.php index 6099e582f..e99cd224e 100644 --- a/packages/support/src/Arr/OffsetDidNotExist.php +++ b/packages/support/src/Arr/OffsetDidNotExist.php @@ -6,4 +6,6 @@ use Exception; -final class OffsetDidNotExist extends Exception {} +final class OffsetDidNotExist extends Exception +{ +} diff --git a/packages/support/src/Filesystem/Exceptions/FilesystemException.php b/packages/support/src/Filesystem/Exceptions/FilesystemException.php index 574811e3c..4a0ffcf5d 100644 --- a/packages/support/src/Filesystem/Exceptions/FilesystemException.php +++ b/packages/support/src/Filesystem/Exceptions/FilesystemException.php @@ -2,4 +2,6 @@ namespace Tempest\Support\Filesystem\Exceptions; -interface FilesystemException {} +interface FilesystemException +{ +} diff --git a/packages/support/src/Filesystem/Exceptions/RuntimeException.php b/packages/support/src/Filesystem/Exceptions/RuntimeException.php index de5084684..145b290ee 100644 --- a/packages/support/src/Filesystem/Exceptions/RuntimeException.php +++ b/packages/support/src/Filesystem/Exceptions/RuntimeException.php @@ -6,4 +6,6 @@ use RuntimeException as PhpRuntimeException; -final class RuntimeException extends PhpRuntimeException implements FilesystemException {} +final class RuntimeException extends PhpRuntimeException implements FilesystemException +{ +} diff --git a/packages/support/src/JavaScript/PackageManager.php b/packages/support/src/JavaScript/PackageManager.php index b2649ff8a..f354f743f 100644 --- a/packages/support/src/JavaScript/PackageManager.php +++ b/packages/support/src/JavaScript/PackageManager.php @@ -62,9 +62,9 @@ public static function detect(string $cwd): ?self { return array_find( array: PackageManager::cases(), - callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file( - $cwd . '/' . $lockFile, - )), + callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file($cwd + . '/' + . $lockFile)), ); } } diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php index 54e0cb013..9b2c4ac99 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php @@ -7,4 +7,6 @@ use InvalidArgumentException; use Tempest\Support\Json\Exception\JsonException; -final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException {} +final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException +{ +} diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php index 643d92ddd..5548f1f33 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php @@ -7,4 +7,6 @@ use InvalidArgumentException; use Tempest\Support\Json\Exception\JsonException; -final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException {} +final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException +{ +} diff --git a/packages/support/src/Json/Exception/JsonException.php b/packages/support/src/Json/Exception/JsonException.php index 39462316d..43a580f29 100644 --- a/packages/support/src/Json/Exception/JsonException.php +++ b/packages/support/src/Json/Exception/JsonException.php @@ -4,4 +4,6 @@ namespace Tempest\Support\Json\Exception; -interface JsonException {} +interface JsonException +{ +} diff --git a/packages/support/src/Math/Exception/ArithmeticException.php b/packages/support/src/Math/Exception/ArithmeticException.php index 76c4f935e..8ea8a23a9 100644 --- a/packages/support/src/Math/Exception/ArithmeticException.php +++ b/packages/support/src/Math/Exception/ArithmeticException.php @@ -7,4 +7,6 @@ use InvalidArgumentException; // @phpstan-ignore-next-line -class ArithmeticException extends InvalidArgumentException implements MathException {} +class ArithmeticException extends InvalidArgumentException implements MathException +{ +} diff --git a/packages/support/src/Math/Exception/DivisionByZeroException.php b/packages/support/src/Math/Exception/DivisionByZeroException.php index 517aed1d7..24ad58821 100644 --- a/packages/support/src/Math/Exception/DivisionByZeroException.php +++ b/packages/support/src/Math/Exception/DivisionByZeroException.php @@ -4,4 +4,6 @@ namespace Tempest\Support\Math\Exception; -final class DivisionByZeroException extends ArithmeticException {} +final class DivisionByZeroException extends ArithmeticException +{ +} diff --git a/packages/support/src/Math/Exception/InvalidArgumentException.php b/packages/support/src/Math/Exception/InvalidArgumentException.php index 0279d738c..ade156b76 100644 --- a/packages/support/src/Math/Exception/InvalidArgumentException.php +++ b/packages/support/src/Math/Exception/InvalidArgumentException.php @@ -6,4 +6,6 @@ use InvalidArgumentException as PhpInvalidArgumentException; -final class InvalidArgumentException extends PhpInvalidArgumentException implements MathException {} +final class InvalidArgumentException extends PhpInvalidArgumentException implements MathException +{ +} diff --git a/packages/support/src/Math/Exception/MathException.php b/packages/support/src/Math/Exception/MathException.php index 7537b33a3..da1558aeb 100644 --- a/packages/support/src/Math/Exception/MathException.php +++ b/packages/support/src/Math/Exception/MathException.php @@ -4,4 +4,6 @@ namespace Tempest\Support\Math\Exception; -interface MathException {} +interface MathException +{ +} diff --git a/packages/support/src/Math/Exception/OverflowException.php b/packages/support/src/Math/Exception/OverflowException.php index 3415a9403..bfbd53e39 100644 --- a/packages/support/src/Math/Exception/OverflowException.php +++ b/packages/support/src/Math/Exception/OverflowException.php @@ -6,4 +6,6 @@ use OverflowException as PhpOverflowException; -final class OverflowException extends PhpOverflowException implements MathException {} +final class OverflowException extends PhpOverflowException implements MathException +{ +} diff --git a/packages/support/src/Namespace/functions.php b/packages/support/src/Namespace/functions.php index 22308bdb1..06bc5ba26 100644 --- a/packages/support/src/Namespace/functions.php +++ b/packages/support/src/Namespace/functions.php @@ -123,11 +123,9 @@ function prepare_namespace(Stringable|string $path, null|Stringable|string $root // If the path is a to a PHP file, we exclude the file name. Otherwise, // it's a path to a directory, which should be included in the namespace. if ($normalized->endsWith('.php')) { - return ( - $normalized->contains(['/', '\\']) - ? $normalized->beforeLast(['/', '\\']) - : new ImmutableString() - ); + return $normalized->contains(['/', '\\']) + ? $normalized->beforeLast(['/', '\\']) + : new ImmutableString(); } return $normalized; diff --git a/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php b/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php index e4462f07e..8d332b2bc 100644 --- a/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php +++ b/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php @@ -4,4 +4,6 @@ use InvalidArgumentException as PhpInvalidArgumentException; -final class ArgumentWasInvalid extends PhpInvalidArgumentException implements PaginationException {} +final class ArgumentWasInvalid extends PhpInvalidArgumentException implements PaginationException +{ +} diff --git a/packages/support/src/Paginator/Exceptions/PaginationException.php b/packages/support/src/Paginator/Exceptions/PaginationException.php index 1baf9d68a..261508265 100644 --- a/packages/support/src/Paginator/Exceptions/PaginationException.php +++ b/packages/support/src/Paginator/Exceptions/PaginationException.php @@ -2,4 +2,6 @@ namespace Tempest\Support\Paginator\Exceptions; -interface PaginationException {} +interface PaginationException +{ +} diff --git a/packages/support/src/Regex/InvalidPatternException.php b/packages/support/src/Regex/InvalidPatternException.php index 6814b90a1..c607821b7 100644 --- a/packages/support/src/Regex/InvalidPatternException.php +++ b/packages/support/src/Regex/InvalidPatternException.php @@ -6,4 +6,6 @@ use RuntimeException; -final class InvalidPatternException extends RuntimeException {} +final class InvalidPatternException extends RuntimeException +{ +} diff --git a/packages/support/src/Str/StringInterface.php b/packages/support/src/Str/StringInterface.php index c56f72700..1fc7f43f2 100644 --- a/packages/support/src/Str/StringInterface.php +++ b/packages/support/src/Str/StringInterface.php @@ -10,4 +10,6 @@ /** * @internal This interface is not meant to be used in userland. */ -interface StringInterface extends Stringable, JsonSerializable {} +interface StringInterface extends Stringable, JsonSerializable +{ +} diff --git a/packages/support/src/VarExport/EmptyFileNameException.php b/packages/support/src/VarExport/EmptyFileNameException.php index 971c27016..ea0c884e9 100644 --- a/packages/support/src/VarExport/EmptyFileNameException.php +++ b/packages/support/src/VarExport/EmptyFileNameException.php @@ -6,4 +6,6 @@ use RuntimeException; -final class EmptyFileNameException extends RuntimeException {} +final class EmptyFileNameException extends RuntimeException +{ +} diff --git a/packages/support/src/VarExport/FileDoesNotExistException.php b/packages/support/src/VarExport/FileDoesNotExistException.php index 42e029314..4b60ade07 100644 --- a/packages/support/src/VarExport/FileDoesNotExistException.php +++ b/packages/support/src/VarExport/FileDoesNotExistException.php @@ -6,4 +6,6 @@ use RuntimeException; -final class FileDoesNotExistException extends RuntimeException {} +final class FileDoesNotExistException extends RuntimeException +{ +} diff --git a/packages/support/src/VarExport/VarExportPhpFile.php b/packages/support/src/VarExport/VarExportPhpFile.php index fb17b7e3a..3cc625266 100644 --- a/packages/support/src/VarExport/VarExportPhpFile.php +++ b/packages/support/src/VarExport/VarExportPhpFile.php @@ -47,9 +47,9 @@ public function export(mixed $data): void $serializedData = VarExporter::export($data); $phpFileContent = <<filename, $phpFileContent, LOCK_EX); } diff --git a/packages/support/tests/Json/JsonTest.php b/packages/support/tests/Json/JsonTest.php index d50a98ca4..f8b746760 100644 --- a/packages/support/tests/Json/JsonTest.php +++ b/packages/support/tests/Json/JsonTest.php @@ -65,20 +65,20 @@ public function test_pretty_encode(): void ], true); $json = Str\replace(<<assertSame($json, $actual); } diff --git a/packages/validation/src/SkipValidation.php b/packages/validation/src/SkipValidation.php index 0ae0fa7b1..dddf690fc 100644 --- a/packages/validation/src/SkipValidation.php +++ b/packages/validation/src/SkipValidation.php @@ -7,4 +7,6 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class SkipValidation {} +final class SkipValidation +{ +} diff --git a/packages/view/src/Components/x-component.view.php b/packages/view/src/Components/x-component.view.php index 7847fd8c4..c35181f9d 100644 --- a/packages/view/src/Components/x-component.view.php +++ b/packages/view/src/Components/x-component.view.php @@ -17,10 +17,10 @@ $content = $slots[Slot::DEFAULT]->content ?? ''; $template = sprintf(<<<'HTML' - <%s %s> - %s - - HTML, $is, $attributeString, $content, $is); +<%s %s> +%s + +HTML, $is, $attributeString, $content, $is); $data = $scopedVariables ?? $_data ?? []; $data = is_array($data) ? $data : []; diff --git a/packages/view/src/Export/ExportableViewObject.php b/packages/view/src/Export/ExportableViewObject.php index 4be43a25a..c05f64774 100644 --- a/packages/view/src/Export/ExportableViewObject.php +++ b/packages/view/src/Export/ExportableViewObject.php @@ -6,7 +6,9 @@ interface ExportableViewObject { - public ImmutableArray $exportData { get; } + public ImmutableArray $exportData { + get; + } public static function restore(mixed ...$data): self; } diff --git a/packages/view/src/ShouldBeRemoved.php b/packages/view/src/ShouldBeRemoved.php index 318373f37..017adba67 100644 --- a/packages/view/src/ShouldBeRemoved.php +++ b/packages/view/src/ShouldBeRemoved.php @@ -2,4 +2,6 @@ namespace Tempest\View; -interface ShouldBeRemoved {} +interface ShouldBeRemoved +{ +} diff --git a/packages/view/src/View.php b/packages/view/src/View.php index 9a585116d..0f9695dc0 100644 --- a/packages/view/src/View.php +++ b/packages/view/src/View.php @@ -6,11 +6,17 @@ interface View { - public string $path { get; } + public string $path { + get; + } - public ?string $relativeRootPath { get; } + public ?string $relativeRootPath { + get; + } - public array $data { get; } + public array $data { + get; + } public function get(string $key): mixed; diff --git a/packages/view/src/WithToken.php b/packages/view/src/WithToken.php index 20922797e..23e4fe2ab 100644 --- a/packages/view/src/WithToken.php +++ b/packages/view/src/WithToken.php @@ -8,5 +8,7 @@ interface WithToken { - public Token $token { get; } + public Token $token { + get; + } } diff --git a/packages/view/tests/FallthroughAttributesTest.php b/packages/view/tests/FallthroughAttributesTest.php index d6670dec6..89a6f8475 100644 --- a/packages/view/tests/FallthroughAttributesTest.php +++ b/packages/view/tests/FallthroughAttributesTest.php @@ -29,10 +29,10 @@ public function render(): void ); $this->assertEquals(str_replace([' ', PHP_EOL], '', <<<'HTML' -
-
-
-
- HTML), str_replace([' ', PHP_EOL], '', $html)); +
+
+
+
+ HTML), str_replace([' ', PHP_EOL], '', $html)); } } diff --git a/packages/view/tests/StandaloneViewRendererTest.php b/packages/view/tests/StandaloneViewRendererTest.php index 6630e9d21..0a8ab7910 100644 --- a/packages/view/tests/StandaloneViewRendererTest.php +++ b/packages/view/tests/StandaloneViewRendererTest.php @@ -33,10 +33,10 @@ public function test_render(): void ); $this->assertSnippetsMatch(<<<'HTML' -
- Hi -
- HTML, $html); +
+ Hi +
+ HTML, $html); } public function test_invalid_view_component_paths(): void @@ -86,10 +86,10 @@ public function test_with_cache_enabled(): void ); $this->assertSnippetsMatch(<<<'HTML' - - Hi - - HTML, $html); + + Hi + + HTML, $html); } public function test_with_cache_disabled(): void @@ -103,10 +103,10 @@ public function test_with_cache_disabled(): void ); $this->assertSnippetsMatch(<<<'HTML' - - Hi - - HTML, $html); + + Hi + + HTML, $html); } public function test_xml_declaration_with_short_open_tag(): void diff --git a/packages/view/tests/TempestViewLexerTest.php b/packages/view/tests/TempestViewLexerTest.php index 53e27d922..0ba62e288 100644 --- a/packages/view/tests/TempestViewLexerTest.php +++ b/packages/view/tests/TempestViewLexerTest.php @@ -14,8 +14,8 @@ final class TempestViewLexerTest extends TestCase public function test_lexer(): void { $html = <<hello - HTML; + hello + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -144,15 +144,15 @@ public function test_closing_tag(string $tag): void public function test_multiline_attributes(): void { $html = <<<'HTML' -
+
-
- HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -183,8 +183,8 @@ class=', TokenType::ATTRIBUTE_NAME), public function test_whitespace(): void { $html = <<<'HTML' -

Test Test

- HTML; +

Test Test

+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -210,8 +210,8 @@ public function test_whitespace(): void public function test_lexer_with_falsy_values(): void { $html = <<<'HTML' - a0a - HTML; + a0a + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -245,8 +245,8 @@ public function test_lexer_attribute_values(): void public function test_php_within_tag(): void { $html = <<<'HTML' -
class="foo" >
- HTML; +
class="foo" >
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -267,8 +267,8 @@ public function test_php_within_tag(): void public function test_doctype(): void { $html = <<<'HTML' - - HTML; + + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -283,8 +283,8 @@ public function test_doctype(): void ); $html = <<<'HTML' - - HTML; + + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -343,8 +343,8 @@ public function test_unclosed_comment_tag(): void public function test_cdata(): void { $tokens = new TempestViewLexer(<<<'RSS' - <![CDATA[ {{ $post['title'] }} ]]> - RSS)->lex(); + <![CDATA[ {{ $post['title'] }} ]]> + RSS)->lex(); $this->assertTokens( expected: [ @@ -362,8 +362,8 @@ public function test_cdata(): void public function test_xml(): void { $tokens = new TempestViewLexer(<<<'XML' - - XML)->lex(); + + XML)->lex(); $this->assertTokens( expected: [ @@ -376,8 +376,8 @@ public function test_xml(): void public function test_single_quote_attributes(): void { $html = << - HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); diff --git a/packages/view/tests/TempestViewParserTest.php b/packages/view/tests/TempestViewParserTest.php index 0b1cff5e1..c38135f41 100644 --- a/packages/view/tests/TempestViewParserTest.php +++ b/packages/view/tests/TempestViewParserTest.php @@ -34,8 +34,8 @@ public function test_parser(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - hello - HTML, $parsed->compile()); + hello + HTML, $parsed->compile()); } public function test_parse_self_closing_tag_with_attributes(): void @@ -52,8 +52,8 @@ public function test_parse_self_closing_tag_with_attributes(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $parsed->compile()); + + HTML, $parsed->compile()); } public function test_self_closing_tags_with_attributes(): void @@ -63,8 +63,8 @@ public function test_self_closing_tags_with_attributes(): void $ast = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $ast->compile()); + + HTML, $ast->compile()); } public function test_invalid_closing_tag(): void @@ -79,19 +79,19 @@ public function test_invalid_closing_tag(): void public function test_invalid_closing_tag_ignores_commented_out_code(): void { $tokens = new TempestViewLexer(<< - - - HTML)->lex(); +

+ +

+ HTML)->lex(); $compiled = new TempestViewParser($tokens)->parse()->compile(); $this->assertSame(<< - - - HTML, $compiled); +

+ +

+ HTML, $compiled); } public function test_doctype(): void @@ -106,15 +106,15 @@ public function test_doctype(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $parsed->compile()); + + HTML, $parsed->compile()); } public function test_void_tags(): void { $html = <<<'HTML' -
- HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); diff --git a/packages/vite/src/Exceptions/EntrypointNotFoundException.php b/packages/vite/src/Exceptions/EntrypointNotFoundException.php index f81400d09..980fc9464 100644 --- a/packages/vite/src/Exceptions/EntrypointNotFoundException.php +++ b/packages/vite/src/Exceptions/EntrypointNotFoundException.php @@ -4,4 +4,6 @@ namespace Tempest\Vite\Exceptions; -interface EntrypointNotFoundException extends ViteException {} +interface EntrypointNotFoundException extends ViteException +{ +} diff --git a/packages/vite/src/Exceptions/ViteException.php b/packages/vite/src/Exceptions/ViteException.php index 4d176327d..e65746b26 100644 --- a/packages/vite/src/Exceptions/ViteException.php +++ b/packages/vite/src/Exceptions/ViteException.php @@ -4,4 +4,6 @@ namespace Tempest\Vite\Exceptions; -interface ViteException {} +interface ViteException +{ +} diff --git a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php index ab8b83a1c..9e86e52d1 100644 --- a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php +++ b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php @@ -71,13 +71,13 @@ private function fileToAssetPath(string $file): string private function createReactRefreshTag(): string { return << - import RefreshRuntime from '{$this->bridgeFile->url}/@react-refresh'; - RefreshRuntime.injectIntoGlobalHook(window); - window.\$RefreshReg$ = () => {}; - window.\$RefreshSig$ = () => (type) => type; - window.__vite_plugin_react_preamble_installed__ = true; - - HTML; + + HTML; } } diff --git a/packages/vite/src/TagsResolver/ManifestTagsResolver.php b/packages/vite/src/TagsResolver/ManifestTagsResolver.php index f5f526307..17da4e616 100644 --- a/packages/vite/src/TagsResolver/ManifestTagsResolver.php +++ b/packages/vite/src/TagsResolver/ManifestTagsResolver.php @@ -191,48 +191,48 @@ private function resolvePrefetchingScript(Chunk $chunk): ?string $script = match ($this->viteConfig->prefetching->strategy) { PrefetchStrategy::AGGRESSIVE => <<viteConfig->prefetching->prefetchEvent}', () => window.setTimeout(() => { - function makeLink(asset) { - const link = document.createElement('link') - Object.keys(asset).forEach((attribute) => link.setAttribute(attribute, asset[attribute])) - return link - } + window.addEventListener('{$this->viteConfig->prefetching->prefetchEvent}', () => window.setTimeout(() => { + function makeLink(asset) { + const link = document.createElement('link') + Object.keys(asset).forEach((attribute) => link.setAttribute(attribute, asset[attribute])) + return link + } - const fragment = new DocumentFragment(); - {$assets}.forEach((asset) => fragment.append(makeLink(asset))) - document.head.append(fragment) - })) - JS, + const fragment = new DocumentFragment(); + {$assets}.forEach((asset) => fragment.append(makeLink(asset))) + document.head.append(fragment) + })) + JS, PrefetchStrategy::WATERFALL => <<viteConfig->prefetching->prefetchEvent}', () => { - function makeLink(asset) { - const link = document.createElement('link') - Object.entries(asset).forEach(([key, value]) => link.setAttribute(key, value)) - return link - } + window.addEventListener('{$this->viteConfig->prefetching->prefetchEvent}', () => { + function makeLink(asset) { + const link = document.createElement('link') + Object.entries(asset).forEach(([key, value]) => link.setAttribute(key, value)) + return link + } - function loadNext(assets, count) { - if (!assets.length) return + function loadNext(assets, count) { + if (!assets.length) return - const fragment = new DocumentFragment() - const limit = Math.min(count, assets.length) + const fragment = new DocumentFragment() + const limit = Math.min(count, assets.length) - for (let i = 0; i < limit; i++) { - const link = makeLink(assets.shift()) - fragment.append(link) + for (let i = 0; i < limit; i++) { + const link = makeLink(assets.shift()) + fragment.append(link) - if (assets.length) { - link.onload = () => loadNext(assets, 1) - link.onerror = () => loadNext(assets, 1) - } + if (assets.length) { + link.onload = () => loadNext(assets, 1) + link.onerror = () => loadNext(assets, 1) } - - document.head.append(fragment) } - setTimeout(() => loadNext({$assets}, {$this->viteConfig->prefetching->concurrent})) - }) - JS, + document.head.append(fragment) + } + + setTimeout(() => loadNext({$assets}, {$this->viteConfig->prefetching->concurrent})) + }) + JS, PrefetchStrategy::NONE => '', }; diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index ef3d79d1d..7c600b78b 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -120,8 +120,7 @@ protected function setUp(): void { parent::setUp(); - $this - ->setupKernel() + $this->setupKernel() ->setupConsole() ->setupTesters() ->setupBaseRequest(); diff --git a/tests/Benchmark/Extension/MarkdownExtension.php b/tests/Benchmark/Extension/MarkdownExtension.php index bcb2472b7..e0108766e 100644 --- a/tests/Benchmark/Extension/MarkdownExtension.php +++ b/tests/Benchmark/Extension/MarkdownExtension.php @@ -13,7 +13,9 @@ final class MarkdownExtension implements ExtensionInterface { - public function configure(OptionsResolver $resolver): void {} + public function configure(OptionsResolver $resolver): void + { + } public function load(Container $container): void { diff --git a/tests/Benchmark/Extension/MarkdownRendererTest.php b/tests/Benchmark/Extension/MarkdownRendererTest.php index fc0efaee5..4faae9d60 100644 --- a/tests/Benchmark/Extension/MarkdownRendererTest.php +++ b/tests/Benchmark/Extension/MarkdownRendererTest.php @@ -40,14 +40,14 @@ public function it_renders_a_compact_aggregate_report_table(): void $renderer->render($reports, new Config('markdown', ['file' => null])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - | Benchmark | Set | Mem. Peak | Time | Variability | - | --------- | --- | --------- | ---- | ----------- | - | ContainerBench(benchAutowireSimple) | - | 3.952mb 0.00% | 4.187μs +0.17% | ±2.05% +108.06% | + | Benchmark | Set | Mem. Peak | Time | Variability | + | --------- | --- | --------- | ---- | ----------- | + | ContainerBench(benchAutowireSimple) | - | 3.952mb 0.00% | 4.187μs +0.17% | ±2.05% +108.06% | - MARKDOWN, + MARKDOWN, $output->fetch()); } @@ -70,12 +70,12 @@ public function it_keeps_non_aggregate_table_columns_unchanged(): void $renderer->render($reports, new Config('markdown', ['file' => null])); $this->assertSame(<<<'MARKDOWN' - | name | value | - | ---- | ----- | - | Example | 123 | + | name | value | + | ---- | ----- | + | Example | 123 | - MARKDOWN, $output->fetch()); + MARKDOWN, $output->fetch()); } #[Test] @@ -113,14 +113,14 @@ public function it_can_filter_compact_rows_by_minimum_time_difference(): void $renderer->render($reports, new Config('markdown', ['file' => null, 'outlier_min_diff' => 1.0])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - | Benchmark | Set | Mem. Peak | Time | Variability | - | --------- | --- | --------- | ---- | ----------- | - | ContainerBench(benchAutowireNested) | - | 3.952mb +0.10% | 14.791μs +1.55% | ±0.69% +0.50% | + | Benchmark | Set | Mem. Peak | Time | Variability | + | --------- | --- | --------- | ---- | ----------- | + | ContainerBench(benchAutowireNested) | - | 3.952mb +0.10% | 14.791μs +1.55% | ±0.69% +0.50% | - MARKDOWN, + MARKDOWN, $output->fetch()); } @@ -160,12 +160,12 @@ public function it_shows_an_informative_message_when_no_outliers_match(): void $renderer->render($reports, new Config('markdown', ['file' => null, 'outlier_min_diff' => 5.0])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - _No benchmark changes above ±5%._ + _No benchmark changes above ±5%._ - MARKDOWN, + MARKDOWN, $output->fetch()); } diff --git a/tests/Fixtures/Commands/HelloWorldTestCommand.php b/tests/Fixtures/Commands/HelloWorldTestCommand.php index 88a406a09..313d75eb9 100644 --- a/tests/Fixtures/Commands/HelloWorldTestCommand.php +++ b/tests/Fixtures/Commands/HelloWorldTestCommand.php @@ -9,5 +9,7 @@ final readonly class HelloWorldTestCommand { #[ConsoleCommand] - public function __invoke(): void {} + public function __invoke(): void + { + } } diff --git a/tests/Fixtures/Commands/MyBrokenCommand.php b/tests/Fixtures/Commands/MyBrokenCommand.php index 3bf5bb19e..29aad2368 100644 --- a/tests/Fixtures/Commands/MyBrokenCommand.php +++ b/tests/Fixtures/Commands/MyBrokenCommand.php @@ -4,4 +4,6 @@ namespace Tests\Tempest\Fixtures\Commands; -final class MyBrokenCommand {} +final class MyBrokenCommand +{ +} diff --git a/tests/Fixtures/Commands/MyCommand.php b/tests/Fixtures/Commands/MyCommand.php index 6bc340bee..24ea8316d 100644 --- a/tests/Fixtures/Commands/MyCommand.php +++ b/tests/Fixtures/Commands/MyCommand.php @@ -4,4 +4,6 @@ namespace Tests\Tempest\Fixtures\Commands; -final class MyCommand {} +final class MyCommand +{ +} diff --git a/tests/Fixtures/Console/CommandWithDifferentArguments.php b/tests/Fixtures/Console/CommandWithDifferentArguments.php index 3a488f0e0..3bcf7c6cb 100644 --- a/tests/Fixtures/Console/CommandWithDifferentArguments.php +++ b/tests/Fixtures/Console/CommandWithDifferentArguments.php @@ -21,5 +21,6 @@ public function __invoke( string $camelCaseStringWithDefault = 'foo', bool $camelCaseBoolWithTrueDefault = true, bool $camelCaseBoolWithFalseDefault = false, - ): void {} + ): void { + } } diff --git a/tests/Fixtures/Console/StylingCommand.php b/tests/Fixtures/Console/StylingCommand.php index 475490226..3d5f252cf 100644 --- a/tests/Fixtures/Console/StylingCommand.php +++ b/tests/Fixtures/Console/StylingCommand.php @@ -14,8 +14,7 @@ #[ConsoleCommand(name: 'test:style')] public function __invoke(): void { - $this - ->info('info') + $this->info('info') ->success('success') ->warning('warning') ->error('error'); diff --git a/tests/Fixtures/Controllers/DocsController.php b/tests/Fixtures/Controllers/DocsController.php index d8367974b..56d4ccda0 100644 --- a/tests/Fixtures/Controllers/DocsController.php +++ b/tests/Fixtures/Controllers/DocsController.php @@ -9,5 +9,7 @@ final readonly class DocsController { #[Get('/docs/{category}/{slug}')] - public function __invoke(string $category, string $slug): void {} + public function __invoke(string $category, string $slug): void + { + } } diff --git a/tests/Fixtures/Events/EventForListenerWithoutPropagation.php b/tests/Fixtures/Events/EventForListenerWithoutPropagation.php index ccf11b102..3dc5f4037 100644 --- a/tests/Fixtures/Events/EventForListenerWithoutPropagation.php +++ b/tests/Fixtures/Events/EventForListenerWithoutPropagation.php @@ -2,4 +2,6 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class EventForListenerWithoutPropagation {} +final readonly class EventForListenerWithoutPropagation +{ +} diff --git a/tests/Fixtures/Events/EventInterface.php b/tests/Fixtures/Events/EventInterface.php index 8af3a0201..55882c827 100644 --- a/tests/Fixtures/Events/EventInterface.php +++ b/tests/Fixtures/Events/EventInterface.php @@ -4,4 +4,6 @@ namespace Tests\Tempest\Fixtures\Events; -interface EventInterface {} +interface EventInterface +{ +} diff --git a/tests/Fixtures/Events/EventInterfaceImplementation.php b/tests/Fixtures/Events/EventInterfaceImplementation.php index d0d06f3a0..3f6002b47 100644 --- a/tests/Fixtures/Events/EventInterfaceImplementation.php +++ b/tests/Fixtures/Events/EventInterfaceImplementation.php @@ -4,4 +4,6 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class EventInterfaceImplementation implements EventInterface {} +final readonly class EventInterfaceImplementation implements EventInterface +{ +} diff --git a/tests/Fixtures/Events/EventWithoutPropagation.php b/tests/Fixtures/Events/EventWithoutPropagation.php index 63674a320..c18a33a2b 100644 --- a/tests/Fixtures/Events/EventWithoutPropagation.php +++ b/tests/Fixtures/Events/EventWithoutPropagation.php @@ -5,4 +5,6 @@ use Tempest\EventBus\StopsPropagation; #[StopsPropagation] -final readonly class EventWithoutPropagation {} +final readonly class EventWithoutPropagation +{ +} diff --git a/tests/Fixtures/Events/ItHappened.php b/tests/Fixtures/Events/ItHappened.php index 5b7a4df83..09dac2f71 100644 --- a/tests/Fixtures/Events/ItHappened.php +++ b/tests/Fixtures/Events/ItHappened.php @@ -4,4 +4,6 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class ItHappened {} +final readonly class ItHappened +{ +} diff --git a/tests/Fixtures/GlobalHiddenDiscovery.php b/tests/Fixtures/GlobalHiddenDiscovery.php index a784f8c7e..dc75910e7 100644 --- a/tests/Fixtures/GlobalHiddenDiscovery.php +++ b/tests/Fixtures/GlobalHiddenDiscovery.php @@ -13,7 +13,9 @@ final class GlobalHiddenDiscovery implements Discovery use IsDiscovery; - public function discover(DiscoveryLocation $location, ClassReflector $class): void {} + public function discover(DiscoveryLocation $location, ClassReflector $class): void + { + } public function apply(): void { diff --git a/tests/Fixtures/GlobalHiddenPathDiscovery.php b/tests/Fixtures/GlobalHiddenPathDiscovery.php index 7c12bcf71..737b4694c 100644 --- a/tests/Fixtures/GlobalHiddenPathDiscovery.php +++ b/tests/Fixtures/GlobalHiddenPathDiscovery.php @@ -13,7 +13,9 @@ final class GlobalHiddenPathDiscovery implements Discovery use IsDiscovery; - public function discover(DiscoveryLocation $location, ClassReflector $class): void {} + public function discover(DiscoveryLocation $location, ClassReflector $class): void + { + } public function apply(): void { diff --git a/tests/Fixtures/Handlers/MyCommandHandler.php b/tests/Fixtures/Handlers/MyCommandHandler.php index be53f3b94..4b6a9d1e3 100644 --- a/tests/Fixtures/Handlers/MyCommandHandler.php +++ b/tests/Fixtures/Handlers/MyCommandHandler.php @@ -10,5 +10,7 @@ final class MyCommandHandler { #[CommandHandler] - public function __invoke(MyCommand $command): void {} + public function __invoke(MyCommand $command): void + { + } } diff --git a/tests/Fixtures/TestInstallerClass.php b/tests/Fixtures/TestInstallerClass.php index e3a6abdbc..25e10c22c 100644 --- a/tests/Fixtures/TestInstallerClass.php +++ b/tests/Fixtures/TestInstallerClass.php @@ -7,4 +7,6 @@ use Tempest\Discovery\SkipDiscovery; #[SkipDiscovery] -final readonly class TestInstallerClass {} +final readonly class TestInstallerClass +{ +} diff --git a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php index c5d6358b6..e4cb3ac20 100644 --- a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php @@ -25,11 +25,11 @@ public function test_progress_bar(): void }) ->assertContains( << ] (1/3) - [====================> ] (2/3) - [===============================] (3/3) - ["aa","bb","cc"] - TXT, + [==========> ] (1/3) + [====================> ] (2/3) + [===============================] (3/3) + ["aa","bb","cc"] + TXT, true, ); } diff --git a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php index c1608c974..447de2dce 100644 --- a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php @@ -26,22 +26,22 @@ public function test_search_component(): void ->submit('a') ->assertContains( <<submit(1) ->submit('b') ->assertContains( <<submit(2) @@ -62,9 +62,9 @@ public function test_no_answer(): void ->submit() ->assertContains( text: <<submit(0) @@ -86,9 +86,9 @@ public function test_default_answer(): void ->submit() ->assertContains( text: <<submit(0) diff --git a/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php b/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php index ec9b88813..48118f0f0 100644 --- a/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php +++ b/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php @@ -8,10 +8,16 @@ final class CommandWithNonCommandMethods { - public function __invoke(): void {} + public function __invoke(): void + { + } #[ConsoleCommand('test:not-empty')] - public function do(): void {} + public function do(): void + { + } - public function empty(): void {} + public function empty(): void + { + } } diff --git a/tests/Integration/Console/Fixtures/CompletionTestCommand.php b/tests/Integration/Console/Fixtures/CompletionTestCommand.php index 9cc3c6c42..a41a36690 100644 --- a/tests/Integration/Console/Fixtures/CompletionTestCommand.php +++ b/tests/Integration/Console/Fixtures/CompletionTestCommand.php @@ -13,5 +13,6 @@ public function __invoke( string $value, bool $flag = false, array $items = [], - ): void {} + ): void { + } } diff --git a/tests/Integration/Console/Fixtures/MyConsole.php b/tests/Integration/Console/Fixtures/MyConsole.php index 453fd2454..d45b635e8 100644 --- a/tests/Integration/Console/Fixtures/MyConsole.php +++ b/tests/Integration/Console/Fixtures/MyConsole.php @@ -17,5 +17,6 @@ public function handle( int $times = 1, bool $force = false, ?string $optional = null, - ): void {} + ): void { + } } diff --git a/tests/Integration/Console/Fixtures/Package.php b/tests/Integration/Console/Fixtures/Package.php index 44239f29e..56dd3b7b5 100644 --- a/tests/Integration/Console/Fixtures/Package.php +++ b/tests/Integration/Console/Fixtures/Package.php @@ -10,7 +10,9 @@ final readonly class Package { #[ConsoleCommand] - public function list(): void {} + public function list(): void + { + } #[ConsoleCommand(help: 'help text')] public function info( @@ -21,5 +23,6 @@ public function info( aliases: ['n'], )] string $name, - ): void {} + ): void { + } } diff --git a/tests/Integration/Console/Fixtures/TestConsoleException.php b/tests/Integration/Console/Fixtures/TestConsoleException.php index e8f42d415..5ba91f6e1 100644 --- a/tests/Integration/Console/Fixtures/TestConsoleException.php +++ b/tests/Integration/Console/Fixtures/TestConsoleException.php @@ -9,5 +9,7 @@ final class TestConsoleException extends ConsoleException { - public function render(Console $console): void {} + public function render(Console $console): void + { + } } diff --git a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php index 552c26c26..341f23e52 100644 --- a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php +++ b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php @@ -117,8 +117,12 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v } // dummy handler for testing - public function handler(): void {} + public function handler(): void + { + } // dummy command for testing - public function command(): void {} + public function command(): void + { + } } diff --git a/tests/Integration/Console/Scheduler/HandlerInvocationTest.php b/tests/Integration/Console/Scheduler/HandlerInvocationTest.php index 54c058a4f..30e697d49 100644 --- a/tests/Integration/Console/Scheduler/HandlerInvocationTest.php +++ b/tests/Integration/Console/Scheduler/HandlerInvocationTest.php @@ -30,5 +30,7 @@ public function test_name_gets_constructed_properly(): void } // dummy handler method - public function handler(): void {} + public function handler(): void + { + } } diff --git a/tests/Integration/Core/Config/LoadConfigTest.php b/tests/Integration/Core/Config/LoadConfigTest.php index d3b51d6b3..365fff006 100644 --- a/tests/Integration/Core/Config/LoadConfigTest.php +++ b/tests/Integration/Core/Config/LoadConfigTest.php @@ -117,14 +117,14 @@ private function setupFixtures(array $configs): void $db = str_replace('.php', '.sqlite', $config); Filesystem\write_file(__DIR__ . '/Fixtures/' . $config, << <<<'SQL' - INSERT INTO authors (name) VALUES (?) RETURNING * - SQL, + INSERT INTO authors (name) VALUES (?) RETURNING * + SQL, default => <<<'SQL' - INSERT INTO `authors` (`name`) VALUES (?) - SQL, + INSERT INTO `authors` (`name`) VALUES (?) + SQL, }; $this->assertSame($expected, $query->compile()->toString()); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index 1c3c26212..c4d257591 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -316,11 +316,9 @@ public function test_chunk(): void $this->assertCount(4, $results); $results = []; - Book::select() - ->whereRaw("title <> 'A'") - ->chunk(function (array $chunk) use (&$results): void { - $results = [...$results, ...$chunk]; - }, 2); + Book::select()->whereRaw("title <> 'A'")->chunk(function (array $chunk) use (&$results): void { + $results = [...$results, ...$chunk]; + }, 2); $this->assertCount(3, $results); } @@ -339,11 +337,9 @@ public function test_chunk_with_relation(): void Book::new(title: 'B', author: $author)->save(); $results = []; - Book::select() - ->with('author') - ->chunk(function (array $chunk) use (&$results): void { - $results = [...$results, ...$chunk]; - }, 1); + Book::select()->with('author')->chunk(function (array $chunk) use (&$results): void { + $results = [...$results, ...$chunk]; + }, 1); $this->assertCount(2, $results); } diff --git a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php index a81f9a998..0fd8271db 100644 --- a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php @@ -310,11 +310,11 @@ public function test_update_mapping(): void $expected = match ($dialect) { DatabaseDialect::POSTGRESQL => <<<'SQL' - UPDATE authors SET name = ? WHERE authors.id = ? - SQL, + UPDATE authors SET name = ? WHERE authors.id = ? + SQL, default => <<<'SQL' - UPDATE `authors` SET `name` = ? WHERE `authors`.`id` = ? - SQL, + UPDATE `authors` SET `name` = ? WHERE `authors`.`id` = ? + SQL, }; $this->assertSame($expected, $query->compile()->toString()); diff --git a/tests/Integration/Database/GenericDatabaseTest.php b/tests/Integration/Database/GenericDatabaseTest.php index 8ca68639f..a8a257101 100644 --- a/tests/Integration/Database/GenericDatabaseTest.php +++ b/tests/Integration/Database/GenericDatabaseTest.php @@ -65,9 +65,9 @@ public function test_query_with_semicolons(): void $db = $this->container->get(Database::class); $db->execute( new Query(<<assertSame(1, query(Publisher::class)->count()->execute()); diff --git a/tests/Integration/Database/QueryStatements/CompoundStatementTest.php b/tests/Integration/Database/QueryStatements/CompoundStatementTest.php index 6090a01d4..ad98a5e17 100644 --- a/tests/Integration/Database/QueryStatements/CompoundStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CompoundStatementTest.php @@ -18,9 +18,9 @@ public function test_it_can_compile_create_enum_type_statement(): void $this->assertSame( <<compile(DatabaseDialect::SQLITE), ); } diff --git a/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php b/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php index f8dddf12f..3fa2f5928 100644 --- a/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php @@ -16,8 +16,8 @@ enumClass: CreateEnumTypeStatementTestEnumForCreateTable::class, $this->assertSame( <<compile(DatabaseDialect::POSTGRESQL), ); } diff --git a/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php b/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php index 191efae8a..83a0fccd0 100644 --- a/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php +++ b/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php @@ -16,8 +16,8 @@ enumClass: DropEnumTypeStatementTestEnumForCreateTable::class, $this->assertSame( <<compile(DatabaseDialect::POSTGRESQL), ); } diff --git a/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php b/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php index ad74ad792..7be91e7e8 100644 --- a/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php +++ b/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php @@ -29,33 +29,33 @@ public function test_show_meta_for_view_component(): void ->assertSee('x-view-component-with-named-slots.view.php') ->assertSee('"name": "x-view-component-with-named-slots",') ->assertSee(<<<'JSON' - "variables": [ - { - "type": "string", - "name": "$title", - "attributeName": "title", - "description": null - }, - { - "type": "\\Tests\\Tempest\\Fixtures\\Modules\\Books\\Models\\Book", - "name": "$book", - "attributeName": "book", - "description": "Any kind of book will work" - }, - { - "type": "string", - "name": "$dataFoo", - "attributeName": "data-foo", - "description": null - } - ] - JSON) + "variables": [ + { + "type": "string", + "name": "$title", + "attributeName": "title", + "description": null + }, + { + "type": "\\Tests\\Tempest\\Fixtures\\Modules\\Books\\Models\\Book", + "name": "$book", + "attributeName": "book", + "description": "Any kind of book will work" + }, + { + "type": "string", + "name": "$dataFoo", + "attributeName": "data-foo", + "description": null + } + ] + JSON) ->assertSee(<<<'JSON' - "slots": [ - "default", - "foo", - "bar" - ], - JSON); + "slots": [ + "default", + "foo", + "bar" + ], + JSON); } } diff --git a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php index 2b7cde3b9..653695a58 100644 --- a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php +++ b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php @@ -201,7 +201,9 @@ private function callExceptionHandler(Closure $callback): void } } -final class CustomValidationException extends Exception {} +final class CustomValidationException extends Exception +{ +} #[Priority(Priority::HIGH)] final readonly class CustomJsonValidationRenderer implements ExceptionRenderer diff --git a/tests/Integration/Mailer/SentEmailTest.php b/tests/Integration/Mailer/SentEmailTest.php index 39d396cb9..79e4b0168 100644 --- a/tests/Integration/Mailer/SentEmailTest.php +++ b/tests/Integration/Mailer/SentEmailTest.php @@ -68,11 +68,10 @@ public function test_with_default_sender(): void public function test_send_to_address_vo(): void { - $this - ->sendTestEmail( - to: [new EmailAddress('recipient1@example.com', 'Jon Doe'), 'recipient2@example.com'], - from: 'no-reply@tempestphp.com', - ) + $this->sendTestEmail( + to: [new EmailAddress('recipient1@example.com', 'Jon Doe'), 'recipient2@example.com'], + from: 'no-reply@tempestphp.com', + ) ->assertSentTo('recipient1@example.com') ->assertSentTo('recipient2@example.com'); } @@ -90,11 +89,10 @@ public function test_send_to_address_with_brackets(): void public function test_assert_sent_to(): void { - $this - ->sendTestEmail( - to: ['recipient1@example.com', 'recipient2@example.com'], - from: 'no-reply@tempestphp.com', - ) + $this->sendTestEmail( + to: ['recipient1@example.com', 'recipient2@example.com'], + from: 'no-reply@tempestphp.com', + ) ->assertSentTo('recipient1@example.com') ->assertSentTo('recipient2@example.com') ->assertSentTo(['recipient1@example.com', 'recipient2@example.com']) @@ -207,12 +205,12 @@ private function sendTestEmail( $content = match (true) { $html instanceof View => $html, $html !== null => << - -

{$html}

- - - HTML_WRAP, + + +

{$html}

+ + + HTML_WRAP, $text !== null => $text, default => 'Hello Jon in Text', }; diff --git a/tests/Integration/View/BladeViewRendererTest.php b/tests/Integration/View/BladeViewRendererTest.php index 9492407f9..3aec90c9c 100644 --- a/tests/Integration/View/BladeViewRendererTest.php +++ b/tests/Integration/View/BladeViewRendererTest.php @@ -33,10 +33,10 @@ public function test_blade(): void $html = $renderer->render(view('index')); $this->assertSame(<< - Hi - + + Hi + - HTML, $html); + HTML, $html); } } diff --git a/tests/Integration/View/Components/MarkdownComponentTest.php b/tests/Integration/View/Components/MarkdownComponentTest.php index 4bf287c90..77faeaaf1 100644 --- a/tests/Integration/View/Components/MarkdownComponentTest.php +++ b/tests/Integration/View/Components/MarkdownComponentTest.php @@ -9,8 +9,8 @@ final class MarkdownComponentTest extends FrameworkIntegrationTestCase public function test_render_markdown_as_content(): void { $html = $this->view->render(<<<'HTML' - # hi - HTML); + # hi + HTML); $this->assertSame('

hi

', $html); } @@ -18,8 +18,8 @@ public function test_render_markdown_as_content(): void public function test_render_markdown_as_variable(): void { $html = $this->view->render(<<<'HTML' - - HTML, text: '# hi'); + + HTML, text: '# hi'); $this->assertSame('

hi

', $html); } diff --git a/tests/Integration/View/ElementFactoryTest.php b/tests/Integration/View/ElementFactoryTest.php index 603fa9072..c9f1aa76a 100644 --- a/tests/Integration/View/ElementFactoryTest.php +++ b/tests/Integration/View/ElementFactoryTest.php @@ -24,16 +24,16 @@ public function test_parental_relations(): void { // See https://github.com/php/php-src/issues/16960 $contents = <<<'HTML' - - - - Hello - - - - - - HTML; + + + + Hello + + + + + + HTML; $ast = TempestViewParser::ast($contents); diff --git a/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php b/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php index 636856210..57389816a 100644 --- a/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php +++ b/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php @@ -24,44 +24,44 @@ protected function setUp(): void public function test_if_with_data_expression(): void { $view = <<<'HTML' - - {{ $label }} - - - {{ $label }} - -
Nothing
- HTML; + + {{ $label }} + + + {{ $label }} + +
Nothing
+ HTML; $html = $this->view->render(view($view, href: '#', label: 'Label')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - - Label - HTML, $html); + + Label + HTML, $html); $html = $this->view->render(view($view, label: 'Label')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - - Label - HTML, $html); + + Label + HTML, $html); $html = $this->view->render(view($view)); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
Nothing
- HTML, $html); +
Nothing
+ HTML, $html); } public function test_foreach_with_if_and_else_expression(): void { $view = <<<'HTML' -
- {{ $label }} {{ $item }} -
- - No label - - HTML; +
+ {{ $label }} {{ $item }} +
+ + No label + + HTML; $html = $this->view->render(view($view, items: ['a', 'b'], label: 'Label')); $this->assertStringContainsString('Label a', $html); @@ -76,16 +76,16 @@ public function test_foreach_with_if_and_else_expression(): void public function test_foreach_with_if_and_forelse_expression(): void { $view = <<<'HTML' -
- {{ $label }} {{ $item }} -
- - No items - - - No label - - HTML; +
+ {{ $label }} {{ $item }} +
+ + No items + + + No label + + HTML; $html = $this->view->render(view($view)); $this->assertStringNotContainsString('Label a', $html); diff --git a/tests/Integration/View/TempestViewRendererDataPassingTest.php b/tests/Integration/View/TempestViewRendererDataPassingTest.php index f9df80e92..1bd3d479b 100644 --- a/tests/Integration/View/TempestViewRendererDataPassingTest.php +++ b/tests/Integration/View/TempestViewRendererDataPassingTest.php @@ -63,8 +63,8 @@ public function test_normal_attribute_with_php_short_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://', ), ); @@ -77,8 +77,8 @@ public function test_normal_attribute_with_view_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://&', ), ); @@ -91,8 +91,8 @@ public function test_normal_attribute_with_raw_view_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://&', ), ); @@ -105,8 +105,8 @@ public function test_expression_attribute_with_view_echo_not_allowed(): void $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -117,8 +117,8 @@ public function test_expression_attribute_with_raw_view_echo_not_allowed(): void $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -129,8 +129,8 @@ public function test_expression_attribute_with_short_php_echo_not_allowed(): voi $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -141,8 +141,8 @@ public function test_expression_attribute_with_object_without_view_component_not $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() {}, ); } @@ -154,16 +154,16 @@ public function test_expression_attribute_with_object_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() { public string $url = 'https://'; }, @@ -178,16 +178,16 @@ public function test_expression_attribute_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://', ), ); @@ -200,16 +200,16 @@ public function test_normal_attribute_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ), ); } @@ -221,8 +221,8 @@ public function test_expression_attribute_with_same_name(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); /* There's a name collision here: @@ -237,8 +237,8 @@ public function test_expression_attribute_with_same_name(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() { public string $url = 'https://'; }, @@ -251,15 +251,15 @@ public function test_boolean_attributes(): void $this->assertSame( '', $this->view->render(<<<'HTML' - - HTML, value: 'value', selected: true, name: 'name'), + + HTML, value: 'value', selected: true, name: 'name'), ); $this->assertSame( '', $this->view->render(<<<'HTML' - - HTML, value: 'value', selected: false, name: 'name'), + + HTML, value: 'value', selected: false, name: 'name'), ); $this->assertSame( @@ -275,12 +275,12 @@ public function test_boolean_attributes(): void public function test_falsy_bool_attribute(mixed $value): void { $html = $this->view->render(<< - HTML, show: false); +
+ HTML, show: false); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } #[TestWith(['true'])] @@ -288,23 +288,23 @@ public function test_falsy_bool_attribute(mixed $value): void public function test_truthy_bool_attribute(mixed $value): void { $html = $this->view->render(<< - HTML, show: true); +
+ HTML, show: true); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_multiple_boolean_attribute(): void { $html = $this->view->render(<< - HTML); +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_expression_attribute_in_raw_element(): void @@ -312,20 +312,20 @@ public function test_expression_attribute_in_raw_element(): void $this->view->registerViewComponent( 'x-test', <<<'HTML' -
- HTML, +
+ HTML, ); $html = $this->view->render(<<<'HTML' - -
foo

bar

-
- HTML, language: 'php'); + +
foo

bar

+
+ HTML, language: 'php'); $this->assertSnippetsMatch( <<<'HTML' -
foo

bar

- HTML, +
foo

bar

+ HTML, $html, ); } @@ -335,31 +335,31 @@ public function test_echo_in_attributes(): void $this->assertSame( '
', $this->view->render(<< - HTML), +
+ HTML), ); $this->assertSame( '
', $this->view->render(<< - HTML), +
+ HTML), ); } public function test_boolean_attributes_in_view_component(): void { $this->view->registerViewComponent('x-test', << - -
- HTML); +
+ +
+ HTML); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertStringContainsString(' href="hi"', $html); } @@ -367,19 +367,19 @@ public function test_boolean_attributes_in_view_component(): void public function test_global_variables_are_kept(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
{{ $item }}
- HTML); +
{{ $item }}
+ HTML); $html = $this->view->render(<<<'HTML' - - - - HTML, item: 'foo'); + + + + HTML, item: 'foo'); $this->assertSnippetsMatch(<<<'HTML' -
foo
-
foo
-
foo
- HTML, $html); +
foo
+
foo
+
foo
+ HTML, $html); } } diff --git a/tests/Integration/View/TempestViewRendererTest.php b/tests/Integration/View/TempestViewRendererTest.php index cd516aa04..cbd9aaf58 100644 --- a/tests/Integration/View/TempestViewRendererTest.php +++ b/tests/Integration/View/TempestViewRendererTest.php @@ -270,9 +270,9 @@ public function test_foreach_attribute(): void { $this->assertStringEqualsStringIgnoringLineEndings( <<<'HTML' -
a
-
b
- HTML, +
a
+
b
+ HTML, $this->view->render(view('
{{ $foo }}
')->data(items: ['a', 'b'])), ); } @@ -281,39 +281,39 @@ public function test_foreach_consumes_attribute(): void { $html = $this->view->render( <<<'HTML' - - - - - -
{{ $item }}
-
- HTML, + + + + + +
{{ $item }}
+
+ HTML, items: ['a', 'b'], ); $this->assertSnippetsMatch( <<<'HTML' - - - Home - - - - - - - - - - - -
a
b
- - - - - HTML, + + + Home + + + + + + + + + + + +
a
b
+ + + + + HTML, $html, ); } @@ -322,15 +322,15 @@ public function test_forelse_attribute(): void { $this->assertSame( <<<'HTML' -
Empty
- HTML, +
Empty
+ HTML, $this->view->render(view('
{{ $foo }}
Empty
')->data(items: [])), ); $this->assertSame( <<<'HTML' -
a
- HTML, +
a
+ HTML, $this->view->render(view('
{{ $foo }}
Empty
')->data(items: ['a'])), ); } @@ -339,8 +339,8 @@ public function test_forelse_with_other_expression_attribute(): void { $this->assertSame( <<<'HTML' -
Empty
- HTML, +
Empty
+ HTML, $this->view->render('
{{ $foo }}
Empty
', items: [], data: 'test'), ); } @@ -349,14 +349,14 @@ public function test_default_slot(): void { $this->assertSnippetsMatch( <<<'HTML' -
Test
- HTML, +
Test
+ HTML, $this->view->render( <<<'HTML' - - Test - - HTML, + + Test + + HTML, ), ); } @@ -365,18 +365,18 @@ public function test_implicit_default_slot(): void { $this->assertSnippetsMatch( <<<'HTML' -
- - Test +
+ + Test -
- HTML, +
+ HTML, $this->view->render( <<<'HTML' - - Test - - HTML, + + Test + + HTML, ), ); } @@ -385,41 +385,41 @@ public function test_multiple_slots(): void { $this->assertSnippetsMatch( <<<'HTML' - injected scripts - + injected scripts + -
- - Test - - +
+ + Test + + - - Hi + + Hi -
+
- injected styles - HTML, + injected styles + HTML, $this->view->render( <<<'HTML' - - Test - - - injected scripts - - - - injected styles - - - Hi - - HTML, + + Test + + + injected scripts + + + + injected styles + + + Hi + + HTML, ), ); } @@ -428,18 +428,18 @@ public function test_pre(): void { $this->assertStringEqualsStringIgnoringLineEndings( <<<'HTML' +
a
+                    b
+                c
+            
+ HTML, + $this->view->render( + <<<'HTML'
a
                         b
                     c
                 
HTML, - $this->view->render( - <<<'HTML' -
a
-                            b
-                        c
-                    
- HTML, ), ); } @@ -456,10 +456,10 @@ public function test_raw_and_escaped(): void $html = $this->view->render(view(__DIR__ . '/../../Fixtures/Views/raw-escaped.view.php', var: '

hi

')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - <h1>hi</h1> - <H1>HI</H1> -

hi

- HTML, $html); + <h1>hi</h1> + <H1>HI</H1> +

hi

+ HTML, $html); } public function test_html_string(): void @@ -468,10 +468,10 @@ public function test_html_string(): void $this->assertStringEqualsStringIgnoringLineEndings( expected: <<<'HTML' -

hi

- <H1>HI</H1> -

hi

- HTML, +

hi

+ <H1>HI</H1> +

hi

+ HTML, actual: $html, ); } @@ -482,10 +482,10 @@ public function test_no_double_else_attributes(): void $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); } @@ -493,25 +493,25 @@ public function test_else_must_be_after_if_or_elseif(): void { $this->view->render( <<<'HTML' -
-
- HTML, +
+
+ HTML, ); $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -519,18 +519,18 @@ public function test_elseif_must_be_after_if_or_elseif(): void { $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -538,17 +538,17 @@ public function test_forelse_must_be_before_foreach(): void { $this->view->render( view(<<<'HTML' -
-
- HTML, foo: []), +
+
+ HTML, foo: []), ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -556,19 +556,19 @@ public function test_no_double_forelse_attributes(): void { $this->view->render( view(<<<'HTML' -
-
- HTML, foo: []), +
+
+ HTML, foo: []), ); $this->expectException(ElementWasInvalid::class); $this->view->render( view(<<<'HTML' -
-
-
- HTML, foo: []), +
+
+
+ HTML, foo: []), ); } @@ -576,8 +576,8 @@ public function test_render_element_with_attribute_with_dash(): void { $view = view( <<
- HTML, +
+ HTML, ); $html = $this->view->render($view); @@ -612,19 +612,19 @@ public function test_slot_with_comment(): void { $this->assertSnippetsMatch( <<<'HTML' -
+
- Test + Test -
- HTML, +
+ HTML, $this->view->render( <<<'HTML' - - - Test - - HTML, + + + Test + + HTML, ), ); } @@ -652,21 +652,21 @@ public function test_self_closing_component_tags_are_compiled(): void public function test_html_tags(): void { $view = <<<'HTML' - - - - - Tempest - - - - - - -

Tempest

- - - HTML; + + + + + Tempest + + + + + + +

Tempest

+ + + HTML; $html = $this->view->render($view); @@ -693,8 +693,8 @@ public function test_with_at_symbol_in_html_tag(): void $this->assertStringEqualsStringIgnoringLineEndings( <<test - HTML, + + HTML, $rendered, ); } @@ -707,8 +707,8 @@ public function test_with_colon_symbol_in_html_tag(): void $this->assertStringEqualsStringIgnoringLineEndings( <<test - HTML, + + HTML, $rendered, ); } @@ -718,10 +718,10 @@ public function test_loop_variable_can_be_used_within_the_looped_tag(): void $html = $this->view->render( view( <<<'HTML' - - {{ $item->title }} - - HTML, + + {{ $item->title }} + + HTML, ) ->data(items: [ new class { @@ -738,16 +738,16 @@ public function test_loop_variable_can_be_used_within_the_looped_tag(): void ); $this->assertSnippetsMatch(<<<'HTML' - Item 1Item 2 - HTML, $html); + Item 1Item 2 + HTML, $html); } public function test_if_and_foreach_precedence(): void { $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, items: [ (object) ['name' => 'A', 'show' => true], (object) ['name' => 'B', 'show' => false], @@ -759,8 +759,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: true, items: [ (object) ['name' => 'A', 'show' => true], @@ -773,8 +773,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: true, items: [ (object) ['name' => 'A', 'show' => true], @@ -787,8 +787,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: false, items: [ (object) ['name' => 'A', 'show' => true], @@ -801,8 +801,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: false, items: [ (object) ['name' => 'A', 'show' => true], @@ -815,8 +815,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, item: (object) ['show' => true], items: [ (object) ['name' => 'A', 'show' => true], @@ -829,8 +829,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, items: [ (object) ['name' => 'A', 'show' => true], (object) ['name' => 'B', 'show' => false], @@ -851,8 +851,8 @@ public function test_escape_expression_attribute(): void public function test_unclosed_php_tag(): void { $html = $this->view->render(<<<'HTML' - assertSame('hi', $html); } @@ -860,8 +860,8 @@ public function test_unclosed_php_tag(): void public function test_view_comments(): void { $html = $this->view->render(<<<'HTML' -

{{-- this is a comment --}}this is rendered text

{{-- this is a comment --}} - HTML); +

{{-- this is a comment --}}this is rendered text

{{-- this is a comment --}} + HTML); $this->assertSnippetsMatch('

this is rendered text

', $html); } @@ -869,19 +869,19 @@ public function test_view_comments(): void public function test_multiline_view_comments(): void { $html = $this->view->render(<<<'HTML' - {{-- this is a comment -
- - {{ Tempest\Intl\translate('test_2') }} - - -
- --}} -

This should be rendered

- HTML); + {{-- this is a comment +
+ + {{ Tempest\Intl\translate('test_2') }} + + +
+ --}} +

This should be rendered

+ HTML); $this->assertSnippetsMatch('

This should be rendered

', $html); } @@ -893,17 +893,17 @@ public function test_parse_rss_feed(): void } $rss = <<<'XML' - - - https://tempestphp.com/rss - - Tempest - - <![CDATA[ {!! $post['title'] !!} ]]> - - - - XML; + + + https://tempestphp.com/rss + + Tempest + + <![CDATA[ {!! $post['title'] !!} ]]> + + + + XML; $parsed = $this->view->render($rss, posts: [ ['title' => '

A

', 'url' => 'https://tempestphp.com/a'], @@ -911,27 +911,27 @@ public function test_parse_rss_feed(): void ]); $this->assertSnippetsMatch(<<<'RSS' - - - https://tempestphp.com/rss - - Tempest - - <![CDATA[ <h1>A</h1> ]]> - - - <![CDATA[ B ]]> - - - - RSS, $parsed); + + + https://tempestphp.com/rss + + Tempest + + <![CDATA[ <h1>A</h1> ]]> + + + <![CDATA[ B ]]> + + + + RSS, $parsed); } public function test_attributes_with_single_quotes(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch('
', $html); } @@ -939,8 +939,8 @@ public function test_attributes_with_single_quotes(): void public function test_zero_in_attribute(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch('
', $html); } diff --git a/tests/Integration/View/TwigViewRendererTest.php b/tests/Integration/View/TwigViewRendererTest.php index 0a009df02..68fbb9b2f 100644 --- a/tests/Integration/View/TwigViewRendererTest.php +++ b/tests/Integration/View/TwigViewRendererTest.php @@ -33,9 +33,9 @@ public function test_twig(): void $html = $renderer->render(view('index.twig', ...['foo' => 'bar'])); $this->assertStringEqualsStringIgnoringLineEndings(<< - bar - - HTML, $html); + + bar + + HTML, $html); } } diff --git a/tests/Integration/View/ViewComponentDiscoveryTest.php b/tests/Integration/View/ViewComponentDiscoveryTest.php index 117daef48..5953dff51 100644 --- a/tests/Integration/View/ViewComponentDiscoveryTest.php +++ b/tests/Integration/View/ViewComponentDiscoveryTest.php @@ -87,8 +87,8 @@ public function test_auto_registration(): void $discovery->apply(); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('Hello World', $html); } @@ -101,8 +101,8 @@ public function test_auto_registration_with_x_component(): void $discovery->apply(); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('Hello World', $html); } diff --git a/tests/Integration/View/ViewComponentTest.php b/tests/Integration/View/ViewComponentTest.php index 2ed4064ed..5b1a47103 100644 --- a/tests/Integration/View/ViewComponentTest.php +++ b/tests/Integration/View/ViewComponentTest.php @@ -59,8 +59,8 @@ public function test_view_component_with_php_code_in_attribute(): void expected: '
', actual: $this->view->render( <<<'HTML' - - HTML, + + HTML, input: 'hello', ), ); @@ -77,47 +77,47 @@ public function test_view_component_with_php_code_in_slot(): void public function test_view_can_access_dynamic_slots(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
-
{{ $slot->name }}
-
{{ $slot->attributes['language'] }}
-
{{ $slot->language }}
-
{!! $slot->content !!}
-
- HTML); +
+
{{ $slot->name }}
+
{{ $slot->attributes['language'] }}
+
{{ $slot->language }}
+
{!! $slot->content !!}
+
+ HTML); $html = $this->view->render(<<<'HTML_WRAP' - - PHP Body - HTML Body - - HTML_WRAP); + + PHP Body + HTML Body + + HTML_WRAP); $this->assertSnippetsMatch(<<<'HTML_WRAP' -
slot-php
PHP
PHP
PHP Body
-
slot-html
HTML
HTML
HTML Body
- HTML_WRAP, $html); +
slot-php
PHP
PHP
PHP Body
+
slot-html
HTML
HTML
HTML Body
+ HTML_WRAP, $html); } public function test_dynamic_slots_are_cleaned_up(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
-
{{ $slot->name }}
-
- - HTML); +
+
{{ $slot->name }}
+
+ + HTML); $html = $this->view->render(<<<'HTML' - - - -
internal slots still here
-
internal slots are cleared
-
+ + + +
internal slots still here
+
internal slots are cleared
+
-
slots still here
-
slots are cleared
- HTML); +
slots still here
+
slots are cleared
+ HTML); $this->assertStringContainsString('
internal slots still here
', $html); $this->assertStringContainsString('
slots are cleared
', $html); @@ -126,17 +126,17 @@ public function test_dynamic_slots_are_cleaned_up(): void public function test_dynamic_slots_include_the_default_slot(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
{{ $slots['default']->name }}
-
{{ $slots['default']->content }}
- HTML); +
{{ $slots['default']->name }}
+
{{ $slots['default']->content }}
+ HTML); $html = $this->view->render('Hello'); $this->assertSnippetsMatch( <<<'HTML' -
default
-
Hello
- HTML, +
default
+
Hello
+ HTML, $html, ); } @@ -144,29 +144,29 @@ public function test_dynamic_slots_include_the_default_slot(): void public function test_slots_with_nested_view_components(): void { $this->view->registerViewComponent('x-a', <<<'HTML' - -
-
A{{ $slot->name }}
-
- HTML); + +
+
A{{ $slot->name }}
+
+ HTML); $this->view->registerViewComponent('x-b', <<<'HTML' -
-
B{{ $slot->name }}
-
- HTML); +
+
B{{ $slot->name }}
+
+ HTML); $html = $this->view->render(<<<'HTML' - - - - - + + + + + - - - - HTML); + + + + HTML); $this->assertStringContainsString('
B1
', $html); $this->assertStringContainsString('
B2
', $html); @@ -185,9 +185,9 @@ public function test_slots_is_a_reserved_variable(): void public function test_scope_does_not_leak_data(): void { $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertStringContainsString('', $html); $this->assertStringContainsString('view->render(''); $this->assertSnippetsMatch(<<<'HTML' - hi + hi - -
- HTML, $html); + +
+ HTML, $html); } public function test_component_with_anther_component_included_with_slot(): void @@ -213,13 +213,13 @@ public function test_component_with_anther_component_included_with_slot(): void $html = $this->view->render('test'); $this->assertSnippetsMatch(<<<'HTML' - hi + hi - -
- test -
- HTML, $html); + +
+ test +
+ HTML, $html); } public function test_view_component_with_injected_view(): void @@ -238,8 +238,8 @@ public function test_view_component_with_injected_view(): void $html = $this->view->render(view( <<<'HTML' - - HTML, + + HTML, )); $validator = $this->container->get(Validator::class); @@ -265,8 +265,8 @@ public function test_component_with_if(): void public function test_component_with_foreach(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch( expected: '
a
b
', @@ -278,8 +278,8 @@ public function test_anonymous_view_component(): void { $this->assertSame( <<hi - HTML, +
hi
+ HTML, $this->view->render('hi'), ); } @@ -302,8 +302,8 @@ public function test_with_passed_variable(): void $this->assertSnippetsMatch( <<test - HTML, +
test
+ HTML, $rendered, ); } @@ -316,8 +316,8 @@ public function test_with_passed_data(): void $this->assertSnippetsMatch( <<test - HTML, +
test
+ HTML, $rendered, ); } @@ -326,14 +326,14 @@ public function test_with_passed_php_data(): void { $rendered = $this->view->render( view(<<
- HTML), + + HTML), ); $this->assertSnippetsMatch( <<TEST - HTML, +
TEST
+ HTML, $rendered, ); } @@ -360,8 +360,8 @@ public function test_with_passed_variable_within_loop(): void { $rendered = $this->view->render( <<<'HTML' - - HTML, + + HTML, variables: ['a', 'b', 'c'], ); @@ -386,8 +386,8 @@ public function test_view_component_attribute_variables_without_this(): void $html = $this->view->render(view(__DIR__ . '/../../Fixtures/Views/view-component-attribute-without-this-b.view.php')); $this->assertSame(<<view->render(view(__DIR__ . '/../../Fixtures/Views/view-component-with-non-self-closing-slot-b.view.php')); $this->assertSnippetsMatch(<<view->registerViewComponent('x-test', <<<'HTML' - {{ $metaType ?? 'nothing' }} - HTML); + {{ $metaType ?? 'nothing' }} + HTML); $this->assertSame('test', $this->view->render('')); $this->assertSame('test', $this->view->render('')); @@ -432,19 +432,19 @@ public function test_template_component(): void { $html = $this->view->render( <<<'HTML' - -
item {{ $item }}
-
boo
-
- HTML, + +
item {{ $item }}
+
boo
+
+ HTML, items: ['a', 'b', 'c'], ); $this->assertSnippetsMatch(<<<'HTML' -
item a
boo
-
item b
boo
-
item c
boo
- HTML, $html); +
item a
boo
+
item b
boo
+
item c
boo
+ HTML, $html); } public static function view_components(): Generator @@ -480,29 +480,29 @@ public static function view_components(): Generator public function test_full_html_document_as_component(): void { $this->view->registerViewComponent('x-layout', <<<'HTML' - - - Tempest View - - - - - - HTML); + + + Tempest View + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - Hello World - - HTML); + + Hello World + + HTML); $this->assertStringContainsString(<<<'HTML' - - - Tempest View - - - HTML, $html); + + + Tempest View + + + HTML, $html); $this->assertStringContainsString('Hello World', $html); $this->assertStringContainsString('', $html); $this->assertStringContainsString('', $html); @@ -513,23 +513,23 @@ public function test_empty_slots_are_commented_out(): void $this->container->singleton(Environment::class, Environment::LOCAL); $this->view->registerViewComponent('x-layout', <<<'HTML' - - - - - - - - HTML); + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_empty_slots_are_removed_in_production(): void @@ -537,131 +537,131 @@ public function test_empty_slots_are_removed_in_production(): void $this->container->singleton(Environment::class, Environment::PRODUCTION); $this->view->registerViewComponent('x-layout', <<<'HTML' - - - - - - - - HTML); + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_custom_components_in_head(): void { $this->view->registerViewComponent('x-custom-link', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - - HTML, $html); + + + HTML, $html); } public function test_head_injection(): void { $this->view->registerViewComponent('x-custom-link', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - - Foo - - - - - b - - HTML); + + + + Foo + + + + + b + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - Foo - b - - HTML, $html); + + Foo + b + + HTML, $html); } public function test_attributes_variable_in_view_component(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_fallthrough_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merged_fallthrough_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_fallthrough_attributes_with_other_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_file_name_component(): void @@ -674,79 +674,79 @@ public function test_file_name_component(): void public function test_array_attribute(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merge_class(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merge_class_from_template_to_component(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_does_not_duplicate_br(): void { $this->view->registerViewComponent('x-html-base', <<<'HTML' - - - - - - - - - HTML); + + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - -
-
-
- HTML); + +
+
+
+ HTML); $this->assertSnippetsMatch(<<<'HTML' - -

- HTML, $html); + +

+ HTML, $html); } public function test_renders_minified_html_with_void_elements(): void { $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_multiple_instances_of_custom_component_using_slots(): void @@ -754,48 +754,48 @@ public function test_multiple_instances_of_custom_component_using_slots(): void $this->view->registerViewComponent('x-foo-bar', 'FOO-BAR'); $this->view->registerViewComponent('x-test', <<<'HTML' -
- - -
- HTML); +
+ + +
+ HTML); $html = $this->view->render(<<<'HTML' - - - - - - HTML); + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
FOO-BAR - FOO-BAR -
- HTML, $html); +
FOO-BAR + FOO-BAR +
+ HTML, $html); } public function test_slots_with_hyphens(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- -
- HTML); +
+ +
+ HTML); $html = $this->view->render(<<<'HTML' - - - Hi - - - HTML); + + + Hi + + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- Hi -
- HTML, $html); +
+ Hi +
+ HTML, $html); } public function test_nested_table_components(): void @@ -807,34 +807,34 @@ public function test_nested_table_components(): void $this->view->registerViewComponent('x-my-table-th', ''); $html = $this->view->render(<<<'HTML' - - - - Header 1 - - - - - Row 1, Cell 1 - - -
- HTML); + + + + Header 1 + + + + + Row 1, Cell 1 + + +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' - - - - - - - - - - - -
Header1
Row 1, Cell 1
- HTML, $html); + + + + + + + + + + + +
Header1
Row 1, Cell 1
+ HTML, $html); } public function test_dynamic_view_component_with_string_name(): void @@ -842,8 +842,8 @@ public function test_dynamic_view_component_with_string_name(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('
test
', $html); } @@ -853,8 +853,8 @@ public function test_dynamic_view_component_with_expression_name(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML, name: 'x-test'); + + HTML, name: 'x-test'); $this->assertSame('
test
', $html); } @@ -864,8 +864,8 @@ public function test_dynamic_view_component_with_variable_attribute(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML, name: 'x-test', input: 'test'); + + HTML, name: 'x-test', input: 'test'); $this->assertSame('
test
', $html); } @@ -875,8 +875,8 @@ public function test_dynamic_view_component_with_slot(): void $this->view->registerViewComponent('x-test', '
'); $html = $this->view->render(<<<'HTML' - test - HTML, name: 'x-test'); + test + HTML, name: 'x-test'); $this->assertSnippetsMatch('
test
', $html); } @@ -888,8 +888,8 @@ public function dynamic_view_component_keeps_foreach_scope(): void $html = $this->view->render( <<<'HTML' - {{ $item }} - HTML, + {{ $item }} + HTML, name: 'x-test', items: ['a', 'b'], ); @@ -903,10 +903,10 @@ public function test_nested_slots(): void $this->view->registerViewComponent('x-b', ''); $html = $this->view->render(<<<'HTML' - - hi - - HTML); + + hi + + HTML); $this->assertSnippetsMatch('hi', $html); } @@ -915,18 +915,18 @@ public function test_nested_slots_with_escaping(): void { $this->view->registerViewComponent('x-a', ''); $this->view->registerViewComponent('x-b', <<<'HTML' - - {{ get(Environment::class)->value }} - HTML); + + {{ get(Environment::class)->value }} + HTML); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertSnippetsMatch('testing', $html); } @@ -936,10 +936,10 @@ public function test_repeated_local_var_across_view_components(): void $this->view->registerViewComponent('x-test', '
{{ $thing }}
'); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertSnippetsMatch('
a
@@ -960,17 +960,17 @@ public function test_escape_expression_attribute_in_view_components(): void public function test_default_slot_value(): void { $this->view->registerViewComponent('x-test', <<<'HTML' - Default - Default A - Default B - HTML); + Default + Default A + Default B + HTML); $this->assertSnippetsMatch( <<<'HTML' - Overwritten - Overwritten A - Overwritten B - HTML, + Overwritten + Overwritten A + Overwritten B + HTML, $this->view->render(' Overwritten Overwritten A @@ -980,10 +980,10 @@ public function test_default_slot_value(): void $this->assertSnippetsMatch( <<<'HTML' - Overwritten - Default A - Overwritten B - HTML, + Overwritten + Default A + Overwritten B + HTML, $this->view->render(' Overwritten Overwritten B @@ -991,10 +991,10 @@ public function test_default_slot_value(): void ); $this->assertSnippetsMatch(<<<'HTML' - Default - Default A - Default B - HTML, $this->view->render('')); + Default + Default A + Default B + HTML, $this->view->render('')); } public function test_view_variables_are_passed_into_the_component(): void @@ -1002,10 +1002,10 @@ public function test_view_variables_are_passed_into_the_component(): void $this->view->registerViewComponent('x-a', ''); $html = $this->view->render(<<<'HTML' - - {{ $title }} - - HTML, title: 'test'); + + {{ $title }} + + HTML, title: 'test'); $this->assertSnippetsMatch('test', $html); } @@ -1017,12 +1017,12 @@ public function test_capture_outer_scope_view_component_variables(): void $html = $this->view->render( <<<'HTML' - - - {{ $item }} - - - HTML, + + + {{ $item }} + + + HTML, items: ['a', 'b'], ); @@ -1042,13 +1042,13 @@ public function test_imports_in_slots_from_root_node(): void $this->view->registerViewComponent('x-test', '
'); $html = $this->view->render(<<<'HTML' - + - {{ uri(HomeController::class) }} - HTML); + {{ uri(HomeController::class) }} + HTML); $this->assertSame('
/
', $html); } @@ -1056,25 +1056,25 @@ public function test_imports_in_slots_from_root_node(): void public function test_combined_imports_from_root_node_and_view_component(): void { $this->view->registerViewComponent('x-parent', <<<'HTML' -
- HTML); +
+ HTML); $this->view->registerViewComponent('x-child', <<<'HTML' - -
- HTML); + +
+ HTML); $html = $this->view->render(<<<'HTML' - + - - {{ uri(HomeController::class) }} - - HTML); + + {{ uri(HomeController::class) }} + + HTML); $this->assertSnippetsMatch('
/
', $html); } @@ -1173,22 +1173,22 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { public function test_imports_with_nested_view_components(): void { $this->view->registerViewComponent('x-card', <<<'HTML' -
- HTML); +
+ HTML); $this->view->registerViewComponent('x-footer', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - {{ uri(HomeController::class) }} - - HTML); + + + {{ uri(HomeController::class) }} + + HTML); $this->assertSnippetsMatch('
/
', $html); } @@ -1199,18 +1199,18 @@ public function test_imports_in_nested_html_elements(): void $this->view->registerViewComponent('x-b', '
">'); $html = $this->view->render(<<<'HTML' - - -
- - {{ uri(HomeController::class) }} - -
-
- HTML); + + +
+ + {{ uri(HomeController::class) }} + +
+
+ HTML); $this->assertSnippetsMatch('
/
">
">', $html); } diff --git a/tests/Integration/View/ViewTest.php b/tests/Integration/View/ViewTest.php index 317043aa1..90a8c587d 100644 --- a/tests/Integration/View/ViewTest.php +++ b/tests/Integration/View/ViewTest.php @@ -41,8 +41,8 @@ public function test_render_with_view_model(): void $html = $this->view->render($view); $expected = <<assertEquals($expected, $html); } diff --git a/tests/Integration/Vite/ManifestTagsResolverTest.php b/tests/Integration/Vite/ManifestTagsResolverTest.php index ceb9e025b..e335ea58a 100644 --- a/tests/Integration/Vite/ManifestTagsResolverTest.php +++ b/tests/Integration/Vite/ManifestTagsResolverTest.php @@ -81,8 +81,8 @@ public function test_resolve_script_with_prefetching(PrefetchStrategy $strategy) $this->assertStringContainsString('nonce="123', $tags[3]); $this->assertStringContainsString( needle: <<view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -63,19 +63,19 @@ public function test_dev_entrypoints(): void )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -96,19 +96,19 @@ public function test_dev_entrypoints_from_config(): void )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -129,26 +129,26 @@ public function test_dev_entrypoints_from_config_and_react_refresh_from_bridgefi )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: << - Foo - - HTML, + + Foo + + HTML, actual: $html, ); }, @@ -173,17 +173,17 @@ public function test_production_entrypoint_from_config(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), @@ -201,17 +201,17 @@ public function test_production_entrypoint(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), @@ -229,17 +229,17 @@ public function test_production_entrypoints(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), From 5265fe412647094e7ea1b83e4c822c2298c8d409 Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 12 Mar 2026 10:41:18 +0100 Subject: [PATCH 11/14] rector --- rector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/rector.php b/rector.php index b511c8c6c..5f13cad10 100644 --- a/rector.php +++ b/rector.php @@ -29,6 +29,7 @@ __DIR__ . '/src', __DIR__ . '/tests', ]) + ->withSkipPath(__DIR__ . '/tests/PHPStan/QueryFunctionDynamicReturnTypeExtension.php') ->withConfiguredRule(AddSensitiveParameterAttributeRector::class, [ 'sensitive_parameters' => [ 'password', From 932a8f7965a046d77a39efcec66325fcc639d6fb Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 12 Mar 2026 17:01:28 +0100 Subject: [PATCH 12/14] wip rector --- .github/CODEOWNERS | 1 + composer.json | 3 +- rector.php | 52 +++--- utils/rector/src/ImportClassNamesRector.php | 173 ++++++++++++++++++++ 4 files changed, 201 insertions(+), 28 deletions(-) create mode 100644 utils/rector/src/ImportClassNamesRector.php diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f068a23b6..c4c01b5f0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -14,6 +14,7 @@ /.github/workflows/benchmark.yml @xHeaven /.github/workflows/benchmark-comment.yml @xHeaven /src/ @brendt +/utils/rector/ @xHeaven /docs/ @brendt @innocenzi /packages/auth/ @innocenzi /packages/cache/ @innocenzi diff --git a/composer.json b/composer.json index 72713f265..5703809bc 100644 --- a/composer.json +++ b/composer.json @@ -237,7 +237,8 @@ "Tempest\\Validation\\Tests\\": "packages/validation/tests", "Tempest\\View\\Tests\\": "packages/view/tests", "Tempest\\Vite\\Tests\\": "packages/vite/tests", - "Tests\\Tempest\\": "tests" + "Tests\\Tempest\\": "tests", + "Tempest\\Rector\\": "utils/rector/src" } }, "bin": [ diff --git a/rector.php b/rector.php index 5f13cad10..00becf98d 100644 --- a/rector.php +++ b/rector.php @@ -2,71 +2,69 @@ declare(strict_types=1); -use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector; use Rector\Caching\ValueObject\Storage\FileCacheStorage; +use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; +use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; use Rector\Config\RectorConfig; -use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector; +use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector; +use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector; -use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; -use Rector\Php82\Rector\Class_\ReadOnlyClassRector; use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector; use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector; -use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector; +use Rector\Php85\Rector\FuncCall\ArrayKeyExistsNullToEmptyStringRector; use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector; -use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; -use Rector\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; -use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector; +use Tempest\Rector\ImportClassNamesRector; return RectorConfig::configure() ->withCache('./.cache/rector', FileCacheStorage::class) ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', + __DIR__ . '/packages', ]) - ->withSkipPath(__DIR__ . '/tests/PHPStan/QueryFunctionDynamicReturnTypeExtension.php') ->withConfiguredRule(AddSensitiveParameterAttributeRector::class, [ 'sensitive_parameters' => [ 'password', 'secret', ], ]) - ->withRules([ - ExplicitNullableParamTypeRector::class, - ]) ->withSkip([ + '*.stub.php', + '*.input.php', + '*.expected.php', + '*/Fixtures/*', + __DIR__ . '/packages/intl/bin/plural-rules.php', AddOverrideAttributeToOverriddenMethodsRector::class, - ArgumentAdderRector::class, - ClosureToArrowFunctionRector::class, - EmptyOnNullableObjectToInstanceOfRector::class, ArrayToFirstClassCallableRector::class, NullToStrictStringFuncCallArgRector::class, - ReadOnlyClassRector::class, ReadOnlyPropertyRector::class, - RemoveNullPropertyInitializationRector::class, AddSensitiveParameterAttributeRector::class, RestoreDefaultNullToNullableTypePropertyRector::class, - ReturnNeverTypeRector::class, StaticCallOnNonStaticToInstanceCallRector::class, EncapsedStringsToSprintfRector::class, - AddArrowFunctionReturnTypeRector::class, PrivatizeFinalClassMethodRector::class, - NarrowObjectReturnTypeRector::class, + IssetOnPropertyObjectToPropertyExistsRector::class, + CatchExceptionNameMatchingTypeRector::class, + ArrayKeyExistsNullToEmptyStringRector::class, + StringClassNameToClassConstantRector::class, + ReturnBinaryOrToEarlyReturnRector::class, + ]) + ->withConfiguredRule(ImportClassNamesRector::class, [ + 'importShortClasses' => true, + 'excludedClasses' => [ + '\Redis', + ], ]) - ->withParallel(300, 10, 10) ->withPreparedSets( - codeQuality: false, + codeQuality: true, codingStyle: true, privatization: true, naming: false, earlyReturn: true, ) - ->withDeadCodeLevel(40) - ->withMemoryLimit('3G') - ->withPhpSets(php83: true) - ->withTypeCoverageLevel(37); + ->withPhpSets(php85: true); diff --git a/utils/rector/src/ImportClassNamesRector.php b/utils/rector/src/ImportClassNamesRector.php new file mode 100644 index 000000000..337338cd7 --- /dev/null +++ b/utils/rector/src/ImportClassNamesRector.php @@ -0,0 +1,173 @@ + */ + private array $excludedClasses = []; + + public function __construct( + private readonly NameImporter $nameImporter, + private readonly UseImportsResolver $useImportsResolver, + ) { + } + + /** + * @param array{importShortClasses?: bool, excludedClasses?: list} $configuration + */ + public function configure(array $configuration): void + { + SimpleParameterProvider::setParameter( + Option::IMPORT_SHORT_CLASSES, + $configuration['importShortClasses'] ?? true, + ); + + $this->excludedClasses = array_map( + static fn (string $class): string => ltrim($class, '\\'), + $configuration['excludedClasses'] ?? [], + ); + } + + public function getNodeTypes(): array + { + return [FullyQualified::class]; + } + + public function refactor(Node $node): ?Name + { + if (! $node instanceof FullyQualified) { + return null; + } + + if ($node->getAttribute(AttributeKey::IS_FUNCCALL_NAME) === true) { + return null; + } + + if ($node->getAttribute(AttributeKey::IS_CONSTFETCH_NAME) === true) { + return null; + } + + if ($this->isAlreadyShortInSource($node)) { + return null; + } + + if (in_array($node->toString(), $this->excludedClasses, true)) { + return null; + } + + $currentUses = $this->useImportsResolver->resolve(); + + $imported = $this->nameImporter->importName($node, $this->file, $currentUses); + + if ($imported instanceof Name) { + return $imported; + } + + return $this->shortenSameNamespaceName($node, $currentUses); + } + + /** + * @param array $currentUses + */ + private function shortenSameNamespaceName(FullyQualified $node, array $currentUses): ?Name + { + $namespaceName = $this->resolveCurrentNamespace(); + + if ($namespaceName === null) { + return null; + } + + $fqcn = $node->toString(); + $shortName = $node->getLast(); + $fqcnNamespace = substr($fqcn, 0, -(strlen($shortName) + 1)); + + if ($fqcnNamespace !== $namespaceName) { + return null; + } + + if ($this->hasConflictingUseStatement($shortName, $fqcn, $currentUses)) { + return null; + } + + return new Name($shortName); + } + + private function isAlreadyShortInSource(FullyQualified $node): bool + { + $startTokenPos = $node->getStartTokenPos(); + $oldTokens = $this->file->getOldTokens(); + if (! isset($oldTokens[$startTokenPos])) { + return false; + } + $originalText = $oldTokens[$startTokenPos]->text; + return ! str_contains($originalText, '\\'); + } + + private function resolveCurrentNamespace(): ?string + { + $filePath = $this->file->getFilePath(); + + if ($this->currentFilePath === $filePath) { + return $this->currentNamespace; + } + + $this->currentFilePath = $filePath; + $this->currentNamespace = null; + + $fileNode = $this->file->getFileNode(); + + if ($fileNode === null) { + return null; + } + + $namespace = $fileNode->getNamespace(); + + if ($namespace?->name !== null) { + $this->currentNamespace = $namespace->name->toString(); + } + + return $this->currentNamespace; + } + + /** + * @param array $currentUses + */ + private function hasConflictingUseStatement(string $shortName, string $fqcn, array $currentUses): bool + { + foreach ($currentUses as $use) { + foreach ($use->uses as $useUse) { + $importedName = $use instanceof GroupUse + ? $use->prefix . '\\' . $useUse->name->toString() + : $useUse->name->toString(); + + $alias = $useUse->alias?->toString() ?? $useUse->name->getLast(); + + if ($alias === $shortName && $importedName !== $fqcn) { + return true; + } + } + } + + return false; + } +} From 9c5ed85d187e3a6a7bfebb483cde013585b94f77 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 12 Mar 2026 17:30:47 +0100 Subject: [PATCH 13/14] rector + mago fmt applied --- .../PolicyBasedAccessControl.php | 11 +- .../src/Authentication/Authenticatable.php | 4 +- .../Authentication/SessionAuthenticator.php | 2 + .../Exceptions/AuthenticationException.php | 4 +- .../NoPolicyWereFoundForResource.php | 2 +- .../src/Exceptions/OAuthStateWasInvalid.php | 4 +- .../src/Installer/AuthenticationInstaller.php | 5 +- .../auth/src/Installer/OAuthInstaller.php | 2 +- packages/auth/src/OAuth/OAuthConfig.php | 16 +- .../AuthenticationAndOAuthSafetyTest.php | 3 +- packages/cache/src/Cache.php | 5 +- packages/cache/src/CacheCouldNotBeCleared.php | 4 +- packages/cache/src/CacheException.php | 4 +- packages/cache/src/CacheInitializer.php | 2 +- .../cache/src/Commands/CacheClearCommand.php | 2 +- packages/cache/src/GenericCache.php | 7 +- packages/cache/src/GenericLock.php | 2 +- packages/cache/src/Lock.php | 12 +- packages/cache/src/Testing/CacheTester.php | 3 +- packages/cache/src/Testing/TestingCache.php | 1 + packages/cache/src/Testing/TestingLock.php | 2 +- .../cache/src/UserCacheInsightsProvider.php | 2 +- packages/command-bus/src/Async.php | 4 +- .../command-bus/src/GenericCommandBus.php | 2 +- .../command-bus/src/HandleAsyncCommand.php | 2 +- .../command-bus/src/MonitorAsyncCommands.php | 10 +- .../src/Actions/RenderConsoleCommand.php | 6 +- packages/console/src/CanOpenInEditor.php | 4 +- .../console/src/Commands/AboutCommand.php | 6 +- .../src/Commands/CompletionInstallCommand.php | 2 +- .../src/Commands/CompletionShowCommand.php | 2 +- .../Commands/CompletionUninstallCommand.php | 2 +- .../src/Commands/MakeConfigCommand.php | 6 +- .../src/Completion/CompletionEngine.php | 6 +- .../Interactive/MultipleChoiceComponent.php | 6 +- .../Interactive/SearchComponent.php | 3 +- .../Interactive/SingleChoiceComponent.php | 6 +- .../Components/Interactive/TaskComponent.php | 22 +- .../InteractiveComponentRenderer.php | 8 +- .../src/Components/OptionCollection.php | 4 +- .../Components/Renderers/ChoiceRenderer.php | 6 +- .../Components/Renderers/ConfirmRenderer.php | 2 +- .../src/Components/Renderers/TaskRenderer.php | 2 +- .../Static/StaticMultipleChoiceComponent.php | 8 +- .../Static/StaticSearchComponent.php | 2 +- .../Static/StaticSingleChoiceComponent.php | 6 +- packages/console/src/Console.php | 4 +- packages/console/src/ConsoleInputBuilder.php | 2 +- .../Exceptions/InvalidCommandException.php | 2 +- packages/console/src/GenericConsole.php | 8 +- packages/console/src/HasStaticComponent.php | 4 +- .../console/src/Highlight/IsTagInjection.php | 2 +- .../Injections/DynamicInjection.php | 2 +- .../Injections/FileInjection.php | 2 +- .../Injections/LinkInjection.php | 2 +- .../src/Input/ConsoleArgumentDefinition.php | 4 +- .../console/src/Input/MemoryInputBuffer.php | 3 +- .../src/Middleware/ForceMiddleware.php | 9 +- .../src/Middleware/OverviewMiddleware.php | 2 +- .../Middleware/ResolveOrRescueMiddleware.php | 9 +- .../ValidateNamedArgumentsMiddleware.php | 8 +- packages/console/src/Output/TailReader.php | 2 +- .../console/src/Scheduler/NullScheduler.php | 4 +- .../console/src/Testing/ConsoleTester.php | 6 +- .../console/tests/CompletionHelperPhpTest.php | 2 + packages/console/tests/TextBufferTest.php | 40 +- packages/container/src/Autowire.php | 4 +- .../src/Commands/ContainerShowCommand.php | 6 +- .../src/Commands/MakeInitializerCommand.php | 2 +- packages/container/src/Dependency.php | 2 +- packages/container/src/DependencyChain.php | 4 +- .../CircularDependencyEncountered.php | 4 +- .../src/Exceptions/ContainerException.php | 4 +- .../DependencyCouldNotBeAutowired.php | 4 +- .../TaggedDependencyCouldNotBeResolved.php | 4 +- packages/container/src/GenericContainer.php | 20 +- packages/container/src/HasTag.php | 4 +- packages/container/src/Proxy.php | 4 +- packages/container/tests/ContainerTest.php | 6 +- .../CannotAutowireExceptionTest.php | 10 +- .../CircularDependencyExceptionTest.php | 22 +- .../tests/Fixtures/ContainerObjectA.php | 4 +- .../tests/Fixtures/DecoratedClass.php | 4 +- .../tests/Fixtures/DecoratedInterface.php | 4 +- .../Fixtures/DecoratorWithoutConstructor.php | 4 +- .../tests/Fixtures/ImplementsInterfaceA.php | 4 +- packages/container/tests/Fixtures/InjectB.php | 4 +- .../container/tests/Fixtures/InterfaceA.php | 4 +- .../tests/Fixtures/UnionImplementation.php | 4 +- .../tests/Fixtures/UnionInterfaceA.php | 4 +- .../tests/Fixtures/UnionInterfaceB.php | 4 +- .../src/Commands/DiscoveryClearCommand.php | 2 +- .../src/Commands/DiscoveryGenerateCommand.php | 2 +- .../src/Commands/DiscoveryStatusCommand.php | 2 +- packages/core/src/Commands/InstallCommand.php | 4 +- packages/core/src/Composer.php | 2 +- .../src/ComposerJsonCouldNotBeLocated.php | 4 +- packages/core/src/ConfigCache.php | 2 +- .../core/src/CouldNotStoreDiscoveryCache.php | 2 +- .../core/src/DiscoveryCacheInitializer.php | 4 +- .../core/src/Exceptions/ExceptionTester.php | 8 +- .../Exceptions/GenericExceptionProcessor.php | 6 +- .../Exceptions/LoggingExceptionReporter.php | 4 +- packages/core/src/FrameworkKernel.php | 2 +- packages/core/src/InsightsProvider.php | 4 +- packages/core/src/Installer.php | 4 +- packages/core/src/Kernel.php | 30 +- packages/core/src/Kernel/LoadConfig.php | 6 +- .../core/src/Kernel/LoadDiscoveryClasses.php | 27 +- packages/core/src/PublishesFiles.php | 7 +- .../cryptography/src/Encryption/Encrypter.php | 8 +- .../src/Encryption/EncryptionConfig.php | 4 +- .../Exceptions/EncryptionException.php | 4 +- .../src/Encryption/GenericEncrypter.php | 3 +- .../src/GenerateSigningKeyCommand.php | 2 +- .../Exceptions/PasswordHashingException.php | 4 +- .../src/Password/GenericPasswordHasher.php | 9 +- packages/cryptography/src/Password/Hash.php | 4 +- .../src/Password/PasswordHasher.php | 14 +- .../src/Password/PasswordHashingConfig.php | 8 +- .../Signing/Exceptions/SigningException.php | 4 +- packages/cryptography/src/Signing/Signer.php | 4 +- .../src/Signing/SigningConfig.php | 3 +- packages/cryptography/src/Timelock.php | 5 +- packages/cryptography/tests/TimelockTest.php | 5 +- packages/database/src/BelongsTo.php | 18 +- .../database/src/Builder/ModelInspector.php | 68 +- .../src/Builder/QueryBuilders/BuildsQuery.php | 12 +- .../QueryBuilders/DeleteQueryBuilder.php | 3 +- .../HasConvenientWhereMethods.php | 14 +- .../QueryBuilders/InsertQueryBuilder.php | 24 +- .../Builder/QueryBuilders/QueryBuilder.php | 9 +- .../QueryBuilders/SelectQueryBuilder.php | 5 +- .../Builder/QueryBuilders/SupportsJoins.php | 4 +- .../QueryBuilders/SupportsRelations.php | 4 +- .../QueryBuilders/SupportsWhereStatements.php | 4 +- .../QueryBuilders/UpdateQueryBuilder.php | 33 +- .../src/Casters/DataTransferObjectCaster.php | 10 +- .../src/Commands/MakeMigrationCommand.php | 5 +- .../database/src/Config/DatabaseConfig.php | 32 +- .../database/src/Connection/PDOConnection.php | 12 +- packages/database/src/Database.php | 8 +- .../database/src/DatabaseInsightsProvider.php | 7 +- packages/database/src/Eager.php | 4 +- .../src/Exceptions/DatabaseException.php | 4 +- .../ModelDidNotHavePrimaryColumn.php | 4 +- .../src/Exceptions/QueryWasInvalid.php | 10 +- packages/database/src/GenericDatabase.php | 4 +- .../database/src/HasLeadingStatements.php | 4 +- .../database/src/HasTrailingStatements.php | 4 +- packages/database/src/Lazy.php | 4 +- .../src/Mappers/SelectModelMapper.php | 2 +- packages/database/src/MigratesDown.php | 4 +- packages/database/src/MigratesUp.php | 4 +- packages/database/src/MigrationDiscovery.php | 6 +- .../src/Migrations/MigrationException.php | 4 +- .../src/Migrations/MigrationManager.php | 9 +- .../database/src/Migrations/TableGuesser.php | 4 +- .../QueryStatements/AlterTableStatement.php | 6 +- .../CreateEnumTypeStatement.php | 4 +- .../src/QueryStatements/DatetimeStatement.php | 2 +- .../QueryStatements/DropEnumTypeStatement.php | 4 +- .../src/QueryStatements/EnumStatement.php | 2 +- .../src/QueryStatements/FieldStatement.php | 1 + .../QueryStatements/HasWhereStatements.php | 4 +- .../src/QueryStatements/JoinStatement.php | 2 +- .../QueryStatements/ShowTablesStatement.php | 10 +- packages/database/src/RawSql.php | 6 +- packages/database/src/Relation.php | 4 +- .../DataTransferObjectSerializer.php | 10 +- .../src/Serializers/HashedSerializer.php | 3 +- .../database/src/Testing/DatabaseTester.php | 2 +- packages/database/src/Uuid.php | 4 +- packages/database/src/Virtual.php | 4 +- .../tests/Config/DatabaseConfigTest.php | 4 +- .../database/tests/GenericDatabaseTest.php | 4 +- .../Migrations/RunnableMigrationsTest.php | 2 +- .../AlterTableStatementTest.php | 30 +- .../CreateTableStatementTest.php | 170 ++-- .../QueryBuilderGenericsTypeAssertions.php | 4 +- packages/datetime/src/DateTime.php | 65 +- .../src/DateTimeConvenienceMethods.php | 11 +- packages/datetime/src/DateTimeInterface.php | 11 +- packages/datetime/src/Duration.php | 38 +- .../src/Exception/DateTimeException.php | 4 +- .../src/Exception/OverflowException.php | 4 +- .../src/Exception/ParserException.php | 4 +- .../src/Exception/RuntimeException.php | 4 +- .../src/Exception/UnderflowException.php | 4 +- .../src/TemporalConvenienceMethods.php | 19 +- packages/datetime/src/TemporalInterface.php | 7 +- packages/datetime/src/Timestamp.php | 15 +- packages/datetime/src/functions.php | 8 +- packages/datetime/tests/DurationTest.php | 107 +-- packages/debug/src/Debug.php | 20 +- packages/debug/src/DebugConfig.php | 4 +- packages/debug/src/Stacktrace/Frame.php | 3 +- packages/debug/src/TailDebugCommand.php | 2 +- packages/debug/src/functions.php | 2 +- .../src/Commands/MakeDiscoveryCommand.php | 2 +- packages/discovery/src/DiscoveryLocation.php | 4 +- packages/event-bus/src/StopsPropagation.php | 4 +- .../event-bus/src/Testing/EventBusTester.php | 8 +- .../tests/Fixtures/EventInterface.php | 4 +- .../Fixtures/EventInterfaceImplementation.php | 4 +- .../event-bus/tests/Fixtures/ItHappened.php | 4 +- .../Exceptions/FileGenerationException.php | 4 +- .../Exceptions/FileGenerationWasAborted.php | 4 +- .../generation/src/Php/StubFileGenerator.php | 6 +- packages/generation/src/TypeScript/AsType.php | 4 +- .../src/TypeScript/GenerateTypesCommand.php | 8 +- .../ClassStructureResolver.php | 8 +- .../EnumStructureResolver.php | 6 +- .../TypeResolvers/ScalarTypeResolver.php | 3 +- .../TypeScript/TypeScriptGenerationConfig.php | 14 +- .../src/TypeScript/TypeSourceDiscovery.php | 2 +- .../TypeScript/Writers/DirectoryWriter.php | 8 +- .../Writers/NamespacedFileWriter.php | 4 +- .../tests/Php/ClassGeneratorTest.php | 32 +- .../tests/Php/Fixtures/ClassFromFile.php | 4 +- .../ClassWithMethodParameterAttributes.php | 3 +- .../Fixtures/SampleNamespace/DummyFqcn.php | 4 +- .../Fixtures/SampleNamespace/ExampleTrait.php | 4 +- .../SampleParameterAttribute.php | 4 +- .../tests/Php/Fixtures/TestAttribute.php | 4 +- .../ClassStructureResolverTest.php | 2 + .../http-client/src/Testing/MockClient.php | 4 +- packages/http/src/Cookie/Cookie.php | 6 +- packages/http/src/HttpRequestFailed.php | 2 +- packages/http/src/Request.php | 36 +- packages/http/src/Response.php | 12 +- packages/http/src/Responses/Download.php | 3 +- packages/http/src/Responses/File.php | 3 +- packages/http/src/Responses/ServerError.php | 9 +- packages/http/src/SensitiveField.php | 4 +- packages/http/src/ServerSentEvent.php | 16 +- .../src/Session/Config/session.config.php | 2 +- packages/http/src/Session/FormSession.php | 1 + .../Installer/DatabaseSessionInstaller.php | 3 +- .../Managers/DatabaseSessionManager.php | 2 +- .../Session/Managers/FileSessionManager.php | 4 +- .../Session/Managers/RedisSessionManager.php | 4 +- packages/http/src/Session/PreviousUrl.php | 7 +- packages/http/src/Session/SessionConfig.php | 4 +- .../PsrRequestToGenericRequestMapperTest.php | 1 + packages/http/tests/StatusTest.php | 4 +- packages/icon/src/IconCache.php | 2 +- .../src/Exceptions/IdempotencyException.php | 4 +- .../src/Store/CacheIdempotencyStore.php | 2 +- .../tests/IdempotencyMiddlewareTest.php | 3 +- .../tests/IdempotentCommandMiddlewareTest.php | 4 +- .../intl/src/Catalog/CatalogInitializer.php | 3 +- packages/intl/src/GenericTranslator.php | 3 +- packages/intl/src/Locale.php | 4 +- .../Formatter/FormattingException.php | 3 +- .../Formatter/MessageFormatter.php | 17 +- .../src/MessageFormat/FormattingFunction.php | 4 +- .../Functions/DateTimeFunction.php | 3 +- .../Functions/NumberFunction.php | 6 +- .../Markup/IconMarkupFormatter.php | 3 +- .../Parser/MessageFormatParser.php | 7 +- .../Parser/Node/Declaration/Declaration.php | 4 +- .../MessageFormat/Parser/Node/Identifier.php | 4 +- .../src/MessageFormat/Parser/Node/Key/Key.php | 4 +- .../Parser/Node/Key/WildcardKey.php | 4 +- .../Parser/Node/Literal/QuotedLiteral.php | 4 +- .../Parser/Node/Literal/UnquotedLiteral.php | 4 +- .../src/MessageFormat/Parser/Node/Node.php | 4 +- .../Parser/Node/ParsingException.php | 4 +- .../Parser/Node/Pattern/Placeholder.php | 4 +- .../Parser/Node/SimpleMessage.php | 4 +- .../src/MessageFormat/SelectorFunction.php | 4 +- packages/intl/src/Number/functions.php | 17 +- packages/intl/src/TranslationFailure.php | 3 +- packages/intl/tests/FormatterTest.php | 222 ++--- packages/intl/tests/GenericTranslatorTest.php | 14 +- packages/intl/tests/LocaleTest.php | 5 +- packages/intl/tests/ParserTest.php | 22 +- .../kv-store/src/Redis/PhpRedisClient.php | 5 +- packages/kv-store/src/Redis/PredisClient.php | 2 +- packages/kv-store/src/Redis/Redis.php | 3 +- .../kv-store/src/Redis/RedisException.php | 4 +- .../src/Redis/RedisExtensionWasMissing.php | 3 +- .../kv-store/src/Redis/RedisInitializer.php | 9 +- .../src/Redis/RedisInsightsProvider.php | 8 +- packages/kv-store/tests/PredisClientTest.php | 7 +- packages/log/src/Channels/SlackLogChannel.php | 2 +- packages/log/src/LogConfig.php | 8 +- packages/log/src/Logger.php | 4 +- packages/log/src/TailLogsCommand.php | 10 +- packages/log/src/logging.config.php | 2 +- packages/mail/src/Email.php | 8 +- .../mail/src/Exceptions/MailerException.php | 4 +- packages/mail/src/HasAttachments.php | 4 +- packages/mail/src/HasTextContent.php | 4 +- packages/mail/src/MailerConfig.php | 4 +- packages/mail/src/Testing/MailTester.php | 12 +- .../src/Transports/ProvidesDefaultSender.php | 4 +- packages/mapper/src/CasterFactory.php | 10 +- .../Casters/ArrayToObjectCollectionCaster.php | 8 +- .../mapper/src/Casters/DateTimeCaster.php | 3 +- packages/mapper/src/Casters/EnumCaster.php | 3 +- packages/mapper/src/Context.php | 4 +- .../Exceptions/MappingValuesWereMissing.php | 6 +- packages/mapper/src/Hidden.php | 4 +- .../src/Mappers/ArrayToObjectMapper.php | 17 +- .../src/Mappers/ObjectToArrayMapper.php | 3 +- packages/mapper/src/MappingContext.php | 2 +- packages/mapper/src/ProvidesCaster.php | 4 +- packages/mapper/src/ProvidesSerializer.php | 4 +- .../mapper/src/SerializationMapDiscovery.php | 2 +- packages/mapper/src/SerializerFactory.php | 14 +- .../Serializers/ArrayOfObjectsSerializer.php | 2 +- packages/mapper/src/Strict.php | 4 +- packages/mapper/src/UnknownValue.php | 4 +- .../src/Exceptions/ProcessException.php | 4 +- .../process/src/GenericProcessExecutor.php | 3 +- packages/process/src/InvokedProcess.php | 16 +- packages/process/src/InvokedProcessPool.php | 4 +- packages/process/src/OutputChannel.php | 3 +- packages/process/src/ProcessPoolResults.php | 5 +- .../src/Testing/InvokedTestingProcess.php | 11 +- .../process/src/Testing/ProcessTester.php | 17 +- .../src/Testing/TestingProcessExecutor.php | 7 +- packages/reflection/src/ClassReflector.php | 9 +- packages/reflection/src/EnumReflector.php | 3 +- packages/reflection/src/HasAttributes.php | 2 +- packages/reflection/src/MethodReflector.php | 7 +- .../reflection/src/ParameterReflector.php | 4 +- packages/reflection/src/PropertyAttribute.php | 5 +- packages/reflection/src/PropertyReflector.php | 5 +- packages/reflection/src/TypeReflector.php | 14 +- .../reflection/tests/EnumReflectorTest.php | 19 +- .../tests/Fixtures/AnnulledInvoice.php | 4 +- .../Fixtures/ChildWithRecursiveAttribute.php | 4 +- ...assWithInterfaceWithRecursiveAttribute.php | 4 +- .../InterfaceWithRecursiveAttribute.php | 4 +- .../tests/Fixtures/NullableClass.php | 4 +- .../Fixtures/ParentWithRecursiveAttribute.php | 4 +- .../tests/Fixtures/RecursiveAttribute.php | 4 +- .../tests/Fixtures/TestBackedEnum.php | 4 +- .../reflection/tests/Fixtures/TestEnum.php | 4 +- .../src/Commands/MakeControllerCommand.php | 2 +- .../router/src/Commands/RoutesCommand.php | 2 +- packages/router/src/Commands/ServeCommand.php | 2 +- packages/router/src/Connect.php | 6 +- packages/router/src/Delete.php | 6 +- .../src/Exceptions/ConvertsToResponse.php | 3 +- .../src/Exceptions/DevelopmentException.php | 2 +- .../src/Exceptions/HtmlExceptionRenderer.php | 6 +- .../src/Exceptions/JsonExceptionRenderer.php | 4 +- .../src/Exceptions/RouteBindingFailed.php | 4 +- .../router/src/Exceptions/RouterException.php | 4 +- packages/router/src/GenericResponseSender.php | 4 +- packages/router/src/Get.php | 6 +- packages/router/src/Head.php | 6 +- packages/router/src/IsBindingValue.php | 4 +- packages/router/src/MatchRouteMiddleware.php | 6 +- packages/router/src/Options.php | 6 +- packages/router/src/Patch.php | 6 +- packages/router/src/Post.php | 6 +- .../PreventCrossSiteRequestsMiddleware.php | 12 +- packages/router/src/Put.php | 6 +- packages/router/src/Route.php | 20 +- .../Routing/Construction/DiscoveredRoute.php | 3 +- .../RouteMatchingRegexBuilder.php | 14 +- .../Routing/Construction/RouteTreeNode.php | 6 +- .../src/Routing/Construction/RoutingTree.php | 7 +- .../Routing/Matching/GenericRouteMatcher.php | 2 +- .../src/Routing/Matching/MatchingRegex.php | 2 +- .../Static/Exceptions/StaticPageException.php | 4 +- .../src/Static/StaticGenerateCommand.php | 10 +- packages/router/src/Trace.php | 6 +- packages/router/tests/FakeRouteBuilder.php | 4 +- .../FakeRouteBuilderWithOptionalParams.php | 16 +- .../storage/src/Config/R2StorageConfig.php | 2 +- packages/storage/src/Config/StorageConfig.php | 9 +- packages/storage/src/DirectoryListing.php | 6 +- packages/storage/src/StorageException.php | 4 +- .../storage/src/Testing/StorageTester.php | 3 +- .../storage/src/Testing/TestingStorage.php | 8 +- packages/support/src/Arr/ManipulatesArray.php | 3 +- .../support/src/Arr/OffsetDidNotExist.php | 4 +- packages/support/src/Arr/functions.php | 15 +- .../Exception/IncomparableException.php | 2 +- .../Exceptions/FilesystemException.php | 4 +- .../Exceptions/RuntimeException.php | 4 +- packages/support/src/Filesystem/functions.php | 86 +- packages/support/src/Html/HtmlString.php | 2 +- .../support/src/JavaScript/PackageManager.php | 6 +- .../Json/Exception/JsonCouldNotBeDecoded.php | 4 +- .../Json/Exception/JsonCouldNotBeEncoded.php | 4 +- .../src/Json/Exception/JsonException.php | 4 +- packages/support/src/Json/functions.php | 8 +- .../Math/Exception/ArithmeticException.php | 4 +- .../Exception/DivisionByZeroException.php | 4 +- .../Exception/InvalidArgumentException.php | 4 +- .../src/Math/Exception/MathException.php | 4 +- .../src/Math/Exception/OverflowException.php | 4 +- packages/support/src/Math/functions.php | 26 +- packages/support/src/Namespace/functions.php | 8 +- .../Exceptions/ArgumentWasInvalid.php | 4 +- .../Exceptions/PaginationException.php | 4 +- packages/support/src/Path/Path.php | 2 +- packages/support/src/Path/functions.php | 4 +- .../src/Regex/InvalidPatternException.php | 4 +- packages/support/src/Str/ImmutableString.php | 2 +- .../support/src/Str/ManipulatesString.php | 9 +- packages/support/src/Str/StringInterface.php | 4 +- packages/support/src/Str/functions.php | 14 +- packages/support/src/Uri/Uri.php | 11 +- packages/support/src/Uri/functions.php | 2 +- .../src/VarExport/EmptyFileNameException.php | 4 +- .../VarExport/FileDoesNotExistException.php | 4 +- .../src/VarExport/VarExportPhpFile.php | 6 +- .../support/tests/Arr/ImmutableArrayTest.php | 2 +- .../tests/Arr/ManipulatesArrayTest.php | 20 +- .../support/tests/Arr/MutableArrayTest.php | 2 +- .../tests/Comparison/ComparisonTest.php | 45 +- .../tests/Filesystem/UnixFunctionsTest.php | 8 +- packages/support/tests/Json/JsonTest.php | 42 +- packages/support/tests/Math/MathsTest.php | 30 +- .../support/tests/Namespace/FunctionsTest.php | 3 +- .../support/tests/Paginator/PaginatorTest.php | 4 +- .../upgrade/src/Set/TempestLevelSetList.php | 2 + packages/upgrade/src/Set/TempestSetList.php | 2 + .../upgrade/src/Tempest2/MigrationRector.php | 17 +- .../RemoveDatabaseMigrationImportRector.php | 5 +- .../src/Tempest2/RemoveIdImportRector.php | 5 +- .../src/Tempest2/UpdateUriImportsRector.php | 10 +- .../src/Tempest28/WriteableRouteRector.php | 8 +- .../Tempest3/UpdateArrMapFunctionRector.php | 16 +- .../UpdateBindableResolveReturnTypeRector.php | 11 +- .../UpdateCommandFunctionImportsRector.php | 16 +- .../UpdateContainerFunctionImportsRector.php | 20 +- .../UpdateEventFunctionImportsRector.php | 20 +- .../UpdateExceptionProcessorRector.php | 19 +- .../src/Tempest3/UpdateHasContextRector.php | 17 +- .../UpdateMapperFunctionImportsRector.php | 20 +- .../UpdateReflectionFunctionImportsRector.php | 16 +- .../UpdateViewFunctionImportsRector.php | 16 +- packages/upgrade/tests/RectorTester.php | 1 + .../tests/Tempest20/Tempest20RectorTest.php | 2 +- packages/validation/src/Rules/HasCount.php | 3 +- .../src/Rules/HasDateTimeFormat.php | 3 +- .../validation/src/Rules/IsBetweenDates.php | 1 + packages/validation/src/Rules/IsFloat.php | 2 +- packages/validation/src/Rules/IsInteger.php | 2 +- packages/validation/src/Rules/IsNumeric.php | 2 +- packages/validation/src/Rules/IsPassword.php | 6 +- packages/validation/src/Rules/IsTime.php | 4 +- .../validation/src/Rules/ValidateWith.php | 8 +- packages/validation/src/SkipValidation.php | 4 +- packages/validation/src/Validator.php | 4 +- .../validation/tests/Rules/IsTimeTest.php | 3 +- .../tests/Rules/MatchesRegExTest.php | 5 +- .../tests/Rules/ValidateWithTest.php | 3 +- packages/validation/tests/ValidatorTest.php | 28 +- .../src/Attributes/ExpressionAttribute.php | 2 +- .../src/Commands/ClearViewCacheCommand.php | 2 +- .../view/src/Commands/MakeViewCommand.php | 8 +- .../view/src/Components/x-component.view.php | 8 +- packages/view/src/Components/x-form.view.php | 2 +- packages/view/src/Components/x-icon.view.php | 4 +- packages/view/src/Elements/ElementFactory.php | 7 +- packages/view/src/Elements/GenericElement.php | 10 +- packages/view/src/Elements/IsElement.php | 6 +- .../view/src/Elements/PhpForeachElement.php | 6 +- packages/view/src/Elements/PhpIfElement.php | 4 +- packages/view/src/Elements/RawElement.php | 14 +- packages/view/src/Elements/RootElement.php | 2 +- packages/view/src/Elements/TextElement.php | 8 +- .../src/Elements/ViewComponentElement.php | 3 +- .../src/Exceptions/ViewCompilationFailed.php | 2 +- .../XmlDeclarationCouldNotBeParsed.php | 2 +- .../view/src/Export/ExportableViewObject.php | 4 +- .../view/src/Parser/TempestViewCompiler.php | 19 +- packages/view/src/Parser/TempestViewLexer.php | 4 +- .../view/src/Parser/TempestViewParser.php | 2 +- .../src/Renderers/TempestViewRenderer.php | 16 +- packages/view/src/ShouldBeRemoved.php | 4 +- packages/view/src/View.php | 12 +- packages/view/src/WithToken.php | 4 +- .../view/tests/FallthroughAttributesTest.php | 10 +- .../view/tests/StandaloneViewRendererTest.php | 24 +- packages/view/tests/TempestViewLexerTest.php | 54 +- packages/view/tests/TempestViewParserTest.php | 40 +- .../EntrypointNotFoundException.php | 4 +- .../vite/src/Exceptions/ViteException.php | 4 +- packages/vite/src/Installer/ViteInstaller.php | 3 +- packages/vite/src/Manifest/Chunk.php | 2 +- .../TagsResolver/DevelopmentTagsResolver.php | 16 +- .../src/TagsResolver/ManifestTagsResolver.php | 70 +- packages/vite/src/Vite.php | 22 +- .../Commands/DatabaseSeedCommand.php | 6 +- .../Commands/MetaViewComponentCommand.php | 6 +- .../Testing/Http/HttpRouterTester.php | 10 +- .../Testing/Http/TestResponseHelper.php | 12 +- .../Framework/Testing/IntegrationTest.php | 5 +- .../Benchmark/Extension/MarkdownExtension.php | 14 +- .../Extension/MarkdownRendererTest.php | 34 +- tests/Benchmark/Http/GenericRouterBench.php | 6 +- .../Matching/GenericRouteMatcherBench.php | 4 +- .../Commands/HelloWorldTestCommand.php | 4 +- tests/Fixtures/Commands/MyBrokenCommand.php | 4 +- tests/Fixtures/Commands/MyCommand.php | 4 +- .../Console/CommandWithDifferentArguments.php | 3 +- tests/Fixtures/Console/StylingCommand.php | 3 +- tests/Fixtures/Controllers/DocsController.php | 4 +- .../EventForListenerWithoutPropagation.php | 4 +- tests/Fixtures/Events/EventInterface.php | 4 +- .../Events/EventInterfaceImplementation.php | 4 +- .../Events/EventWithoutPropagation.php | 4 +- tests/Fixtures/Events/ItHappened.php | 4 +- tests/Fixtures/GlobalHiddenDiscovery.php | 4 +- tests/Fixtures/GlobalHiddenPathDiscovery.php | 4 +- tests/Fixtures/Handlers/MyCommandHandler.php | 4 +- tests/Fixtures/TestInstallerClass.php | 4 +- .../Auth/AccessControl/AccessControlTest.php | 6 +- .../PolicyBasedAccessControlTest.php | 10 +- .../SessionAuthenticatorTest.php | 2 +- tests/Integration/Cache/RedisCacheTest.php | 10 +- .../Static/StaticProgressBarComponentTest.php | 10 +- .../Static/StaticSearchComponentTest.php | 32 +- .../Console/Components/TaskComponentTest.php | 4 +- .../Fixtures/CommandWithNonCommandMethods.php | 12 +- .../Fixtures/CompletionTestCommand.php | 3 +- .../Console/Fixtures/MyConsole.php | 3 +- .../Integration/Console/Fixtures/Package.php | 7 +- .../Console/Fixtures/TestConsoleException.php | 4 +- .../Scheduler/GenericSchedulerTest.php | 8 +- .../Scheduler/HandlerInvocationTest.php | 4 +- .../Core/Config/LoadConfigTest.php | 12 +- .../LoggingExceptionReporterTest.php | 19 +- .../Integration/Core/Fixtures/MiddlewareA.php | 4 +- .../Integration/Core/Fixtures/MiddlewareB.php | 4 +- .../Integration/Core/Fixtures/MiddlewareC.php | 4 +- .../Core/Fixtures/MiddlewareFramework.php | 4 +- .../Core/Fixtures/MiddlewareHigh.php | 4 +- .../Core/Fixtures/MiddlewareHighest.php | 4 +- .../Core/Fixtures/MiddlewareLow.php | 4 +- .../Core/Fixtures/MiddlewareLowest.php | 4 +- .../Core/Fixtures/MiddlewareNormal.php | 4 +- .../Builder/InsertQueryBuilderTest.php | 8 +- .../Database/Builder/InsertRelationsTest.php | 4 +- .../Database/Builder/IsDatabaseModelTest.php | 1 + .../Builder/SelectQueryBuilderTest.php | 16 +- .../Builder/UpdateQueryBuilderTest.php | 8 +- .../Database/Builder/UpdateRelationsTest.php | 4 +- .../Database/ConvenientWhereMethodsTest.php | 7 +- .../Database/GenericDatabaseTest.php | 6 +- .../Database/ModelInspector/BelongsToTest.php | 4 +- .../QueryStatements/CompoundStatementTest.php | 6 +- .../CreateEnumTypeStatementTest.php | 4 +- .../DropEnumTypeStatementTest.php | 4 +- .../EventBus/EventBusTesterTest.php | 16 +- .../Commands/MetaViewComponentCommandTest.php | 54 +- .../FrameworkIntegrationTestCase.php | 10 +- .../Http/CleanupSessionsCommandTest.php | 2 +- .../Integration/Http/DatabaseSessionTest.php | 3 +- .../Http/Exceptions/ExceptionRendererTest.php | 4 +- tests/Integration/Http/FileSessionTest.php | 6 +- .../Http/SessionFromCookieTest.php | 4 +- tests/Integration/Icon/IconTest.php | 5 +- tests/Integration/Intl/FunctionsTest.php | 3 +- tests/Integration/KeyValue/RedisTest.php | 2 +- tests/Integration/Mailer/SentEmailTest.php | 30 +- .../Integration/Mapper/MapperContextTest.php | 14 +- .../Process/ProcessTesterAssertNotRanTest.php | 12 +- .../Process/ProcessTesterAssertRanTest.php | 16 +- .../Validator/TranslationKeyTest.php | 3 +- .../Validator/TranslationsTest.php | 225 +++-- .../View/BladeViewRendererTest.php | 8 +- .../View/Components/MarkdownComponentTest.php | 8 +- tests/Integration/View/ElementFactoryTest.php | 20 +- ...estViewRendererCombinedExpressionsTest.php | 66 +- .../TempestViewRendererDataPassingTest.php | 152 ++-- .../View/TempestViewRendererTest.php | 440 +++++----- .../Integration/View/TwigViewRendererTest.php | 8 +- .../View/ViewComponentDiscoveryTest.php | 8 +- tests/Integration/View/ViewComponentTest.php | 796 +++++++++--------- tests/Integration/View/ViewTest.php | 4 +- .../Vite/DevelopmentTagsResolverTest.php | 26 +- .../Vite/GenericTagCompilerTest.php | 6 +- .../Vite/ManifestTagsResolverTest.php | 6 +- .../Vite/ViteTagsComponentTest.php | 148 ++-- tests/Integration/Vite/ViteTest.php | 2 +- 587 files changed, 3098 insertions(+), 3480 deletions(-) diff --git a/packages/auth/src/AccessControl/PolicyBasedAccessControl.php b/packages/auth/src/AccessControl/PolicyBasedAccessControl.php index 3751de141..88cb780da 100644 --- a/packages/auth/src/AccessControl/PolicyBasedAccessControl.php +++ b/packages/auth/src/AccessControl/PolicyBasedAccessControl.php @@ -13,6 +13,7 @@ use Tempest\Reflection\ParameterReflector; use Tempest\Support\Arr\ImmutableArray; use Tempest\Support\Str; +use Throwable; use UnitEnum; /** @@ -45,7 +46,7 @@ public function isGranted(UnitEnum|string $action, object|string $resource, ?obj throw new NoPolicyWereFoundForResource($resource); } - $resource = ! is_object($resource) ? null : $resource; + $resource = is_object($resource) ? $resource : null; foreach ($policies as $policy) { $decision = $this->evaluatePolicy($policy, $resource, $subject); @@ -60,13 +61,13 @@ public function isGranted(UnitEnum|string $action, object|string $resource, ?obj private function resolveSubject(?object $subject): ?object { - if ($subject) { + if ($subject !== null) { return $subject; } try { return $this->container->get(Authenticator::class)->current(); - } catch (\Throwable) { + } catch (Throwable) { return null; } } @@ -113,9 +114,9 @@ private function evaluatePolicy(MethodReflector $policy, ?object $resource, ?obj return AccessDecision::from($decision); } - private function ensureParameterAcceptsInput(?ParameterReflector $reflector, mixed $input, \Closure $throw): void + private function ensureParameterAcceptsInput(?ParameterReflector $reflector, mixed $input, Closure $throw): void { - if ($reflector === null || $input === null) { + if (! $reflector instanceof ParameterReflector || $input === null) { return; } diff --git a/packages/auth/src/Authentication/Authenticatable.php b/packages/auth/src/Authentication/Authenticatable.php index 6abf1008f..6db39727e 100644 --- a/packages/auth/src/Authentication/Authenticatable.php +++ b/packages/auth/src/Authentication/Authenticatable.php @@ -7,6 +7,4 @@ /** * Represents an entity that may be authenticated. */ -interface Authenticatable -{ -} +interface Authenticatable {} diff --git a/packages/auth/src/Authentication/SessionAuthenticator.php b/packages/auth/src/Authentication/SessionAuthenticator.php index a7357f979..6d43b69c4 100644 --- a/packages/auth/src/Authentication/SessionAuthenticator.php +++ b/packages/auth/src/Authentication/SessionAuthenticator.php @@ -10,6 +10,7 @@ final readonly class SessionAuthenticator implements Authenticator { public const string AUTHENTICATABLE_KEY = '#authenticatable:id'; + public const string AUTHENTICATABLE_CLASS = '#authenticatable:class'; public function __construct( @@ -35,6 +36,7 @@ public function deauthenticate(): void { $this->session->remove(self::AUTHENTICATABLE_KEY); $this->session->remove(self::AUTHENTICATABLE_CLASS); + $this->sessionManager->save($this->session); } diff --git a/packages/auth/src/Exceptions/AuthenticationException.php b/packages/auth/src/Exceptions/AuthenticationException.php index c7c62e082..acaea6737 100644 --- a/packages/auth/src/Exceptions/AuthenticationException.php +++ b/packages/auth/src/Exceptions/AuthenticationException.php @@ -2,6 +2,4 @@ namespace Tempest\Auth\Exceptions; -interface AuthenticationException -{ -} +interface AuthenticationException {} diff --git a/packages/auth/src/Exceptions/NoPolicyWereFoundForResource.php b/packages/auth/src/Exceptions/NoPolicyWereFoundForResource.php index 97bef581e..7519211b9 100644 --- a/packages/auth/src/Exceptions/NoPolicyWereFoundForResource.php +++ b/packages/auth/src/Exceptions/NoPolicyWereFoundForResource.php @@ -9,6 +9,6 @@ final class NoPolicyWereFoundForResource extends Exception implements Authentica public function __construct( public readonly string|object $resource, ) { - parent::__construct(sprintf('No policies were found for resource `%s`.', is_object($resource) ? get_class($resource) : $resource)); + parent::__construct(sprintf('No policies were found for resource `%s`.', is_object($resource) ? $resource::class : $resource)); } } diff --git a/packages/auth/src/Exceptions/OAuthStateWasInvalid.php b/packages/auth/src/Exceptions/OAuthStateWasInvalid.php index deecb77be..06243d4c2 100644 --- a/packages/auth/src/Exceptions/OAuthStateWasInvalid.php +++ b/packages/auth/src/Exceptions/OAuthStateWasInvalid.php @@ -6,6 +6,4 @@ use Exception; -final class OAuthStateWasInvalid extends Exception implements AuthenticationException -{ -} +final class OAuthStateWasInvalid extends Exception implements AuthenticationException {} diff --git a/packages/auth/src/Installer/AuthenticationInstaller.php b/packages/auth/src/Installer/AuthenticationInstaller.php index 29ec896e0..2a068dee4 100644 --- a/packages/auth/src/Installer/AuthenticationInstaller.php +++ b/packages/auth/src/Installer/AuthenticationInstaller.php @@ -7,6 +7,7 @@ use Tempest\Console\Console; use Tempest\Console\ConsoleCommand; use Tempest\Console\Input\ConsoleArgumentBag; +use Tempest\Console\Input\ConsoleInputArgument; use Tempest\Container\Container; use Tempest\Core\Installer; use Tempest\Core\PublishesFiles; @@ -47,7 +48,7 @@ private function shouldMigrate(): bool { $argument = $this->consoleArgumentBag->get('migrate'); - if ($argument === null || ! is_bool($argument->value)) { + if (! $argument instanceof ConsoleInputArgument || ! is_bool($argument->value)) { return $this->console->confirm('Do you want to execute migrations?', default: false); } @@ -58,7 +59,7 @@ private function shouldInstallOAuth(): bool { $argument = $this->consoleArgumentBag->get('oauth'); - if ($argument === null || ! is_bool($argument->value)) { + if (! $argument instanceof ConsoleInputArgument || ! is_bool($argument->value)) { return $this->console->confirm('Do you want to install OAuth?', default: false); } diff --git a/packages/auth/src/Installer/OAuthInstaller.php b/packages/auth/src/Installer/OAuthInstaller.php index 8915b44d3..d5ec5f164 100644 --- a/packages/auth/src/Installer/OAuthInstaller.php +++ b/packages/auth/src/Installer/OAuthInstaller.php @@ -30,7 +30,7 @@ public function install(): void { $providers = $this->getProviders(); - if (count($providers) === 0) { + if ($providers === []) { return; } diff --git a/packages/auth/src/OAuth/OAuthConfig.php b/packages/auth/src/OAuth/OAuthConfig.php index 250bd851a..6722f7c42 100644 --- a/packages/auth/src/OAuth/OAuthConfig.php +++ b/packages/auth/src/OAuth/OAuthConfig.php @@ -14,32 +14,24 @@ interface OAuthConfig extends HasTag /** * The OAuth provider class name. */ - public string $provider { - get; - } + public string $provider { get; } /** * The authorization scopes for this OAuth provider. * * @return string[] */ - public array $scopes { - get; - } + public array $scopes { get; } /** * The client ID for the OAuth provider. */ - public string $clientId { - get; - } + public string $clientId { get; } /** * The controller action to redirect to after the user authorizes the application. */ - public string|array $redirectTo { - get; - } + public string|array $redirectTo { get; } /** * Creates the OAuth provider instance. diff --git a/packages/auth/tests/AuthenticationAndOAuthSafetyTest.php b/packages/auth/tests/AuthenticationAndOAuthSafetyTest.php index f3e8732d0..09ae269d8 100644 --- a/packages/auth/tests/AuthenticationAndOAuthSafetyTest.php +++ b/packages/auth/tests/AuthenticationAndOAuthSafetyTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionMethod; +use stdClass; use Tempest\Auth\Authentication\DatabaseAuthenticatableResolver; use Tempest\Auth\Exceptions\ModelWasNotAuthenticatable; use Tempest\Auth\OAuth\GenericOAuthClient; @@ -23,7 +24,7 @@ public function database_authenticatable_resolver_rejects_non_authenticatable_cl $this->expectException(ModelWasNotAuthenticatable::class); - $resolve->invoke($resolver, 1, \stdClass::class); + $resolve->invoke($resolver, 1, stdClass::class); } #[Test] diff --git a/packages/cache/src/Cache.php b/packages/cache/src/Cache.php index e46f189e9..19647a714 100644 --- a/packages/cache/src/Cache.php +++ b/packages/cache/src/Cache.php @@ -15,10 +15,7 @@ interface Cache /** * Whether the cache is enabled. */ - public bool $enabled { - get; - set; - } + public bool $enabled { get; set; } /** * Returns a lock for the specified key. The lock is not acquired until `acquire()` is called. diff --git a/packages/cache/src/CacheCouldNotBeCleared.php b/packages/cache/src/CacheCouldNotBeCleared.php index f7e3c2214..c74d7dba1 100644 --- a/packages/cache/src/CacheCouldNotBeCleared.php +++ b/packages/cache/src/CacheCouldNotBeCleared.php @@ -6,6 +6,4 @@ use Exception; -final class CacheCouldNotBeCleared extends Exception implements CacheException -{ -} +final class CacheCouldNotBeCleared extends Exception implements CacheException {} diff --git a/packages/cache/src/CacheException.php b/packages/cache/src/CacheException.php index 56297fdd4..3b72346ea 100644 --- a/packages/cache/src/CacheException.php +++ b/packages/cache/src/CacheException.php @@ -2,6 +2,4 @@ namespace Tempest\Cache; -interface CacheException -{ -} +interface CacheException {} diff --git a/packages/cache/src/CacheInitializer.php b/packages/cache/src/CacheInitializer.php index d6379daed..685c98c70 100644 --- a/packages/cache/src/CacheInitializer.php +++ b/packages/cache/src/CacheInitializer.php @@ -39,7 +39,7 @@ private function shouldCacheBeEnabled(null|string|UnitEnum $tag): bool { $globalCacheEnabled = (bool) env('CACHE_ENABLED', default: true); - if (! $tag) { + if ($tag === null) { return $globalCacheEnabled; } diff --git a/packages/cache/src/Commands/CacheClearCommand.php b/packages/cache/src/Commands/CacheClearCommand.php index fb1c7b13c..19d699bef 100644 --- a/packages/cache/src/Commands/CacheClearCommand.php +++ b/packages/cache/src/Commands/CacheClearCommand.php @@ -21,7 +21,7 @@ use function Tempest\Support\arr; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class CacheClearCommand { use HasConsole; diff --git a/packages/cache/src/GenericCache.php b/packages/cache/src/GenericCache.php index 2023dd58b..b22329bca 100644 --- a/packages/cache/src/GenericCache.php +++ b/packages/cache/src/GenericCache.php @@ -56,7 +56,7 @@ public function put(Stringable|string $key, mixed $value, null|Duration|DateTime $expiration = DateTime::now()->plus($expiration); } - if ($expiration !== null) { + if ($expiration instanceof DateTimeInterface) { $item = $item->expiresAt($expiration->toNativeDateTime()); } @@ -74,6 +74,7 @@ public function putMany(iterable $values, null|Duration|DateTimeInterface $expir foreach ($values as $key => $value) { $items[(string) $key] = $this->put($key, $value, $expiration); } + return $items; } @@ -149,7 +150,7 @@ public function resolve(Stringable|string $key, Closure $callback, null|Duration return $callback(); } - if ($stale) { + if ($stale instanceof Duration) { if ($expiration instanceof Duration) { $expiration = DateTime::now()->plus($expiration); } @@ -168,7 +169,7 @@ public function resolve(Stringable|string $key, Closure $callback, null|Duration private function resolveAllowingStale(Stringable|string $key, Closure $callback, DateTimeInterface $expiration, Duration $stale): mixed { - if (! $this->deferredTasks) { + if (! $this->deferredTasks instanceof DeferredTasks) { return $this->resolve($key, $callback, $expiration); } diff --git a/packages/cache/src/GenericLock.php b/packages/cache/src/GenericLock.php index 98b6963ae..c75284553 100644 --- a/packages/cache/src/GenericLock.php +++ b/packages/cache/src/GenericLock.php @@ -32,7 +32,7 @@ public function acquire(): bool return false; } - $expiration = $this->duration !== null + $expiration = $this->duration instanceof Duration ? DateTime::now()->plus($this->duration) : null; diff --git a/packages/cache/src/Lock.php b/packages/cache/src/Lock.php index 908df168b..e6ad9fc2e 100644 --- a/packages/cache/src/Lock.php +++ b/packages/cache/src/Lock.php @@ -12,23 +12,17 @@ interface Lock /** * The key used to identify the lock. This should be unique across all locks. */ - public string $key { - get; - } + public string $key { get; } /** * The duration of the lock. If null, the lock will not expire. */ - public ?Duration $duration { - get; - } + public ?Duration $duration { get; } /** * The owner of the lock. This is used to verify that the lock is being released by the correct owner. */ - public string $owner { - get; - } + public string $owner { get; } /** * Attempts to acquire a lock. diff --git a/packages/cache/src/Testing/CacheTester.php b/packages/cache/src/Testing/CacheTester.php index 84a04e748..c8023a706 100644 --- a/packages/cache/src/Testing/CacheTester.php +++ b/packages/cache/src/Testing/CacheTester.php @@ -2,6 +2,7 @@ namespace Tempest\Cache\Testing; +use RuntimeException; use Tempest\Cache\Cache; use Tempest\Cache\CacheInitializer; use Tempest\Clock\Clock; @@ -37,7 +38,7 @@ public function fake(null|string|UnitEnum $tag = null): TestingCache public function preventUsageWithoutFake(): void { if (! $this->container instanceof GenericContainer) { - throw new \RuntimeException('Container is not a GenericContainer, unable to prevent usage without fake.'); + throw new RuntimeException('Container is not a GenericContainer, unable to prevent usage without fake.'); } $this->container->unregister(Cache::class, tagged: true); diff --git a/packages/cache/src/Testing/TestingCache.php b/packages/cache/src/Testing/TestingCache.php index 3313a8352..72748ac15 100644 --- a/packages/cache/src/Testing/TestingCache.php +++ b/packages/cache/src/Testing/TestingCache.php @@ -28,6 +28,7 @@ final class TestingCache implements Cache } private Cache $cache; + private ArrayAdapter $adapter; public function __construct( diff --git a/packages/cache/src/Testing/TestingLock.php b/packages/cache/src/Testing/TestingLock.php index 1cccdb33a..73bb7f98b 100644 --- a/packages/cache/src/Testing/TestingLock.php +++ b/packages/cache/src/Testing/TestingLock.php @@ -61,7 +61,7 @@ public function assertLocked(null|Stringable|string $by = null, null|DateTimeInt : "Lock `{$this->key}` is not being held.", ); - if ($for) { + if ($for !== null) { if ($for instanceof DateTimeInterface) { $for = $for->since(DateTime::now()); } diff --git a/packages/cache/src/UserCacheInsightsProvider.php b/packages/cache/src/UserCacheInsightsProvider.php index 81d1ef18e..6fb6cbc88 100644 --- a/packages/cache/src/UserCacheInsightsProvider.php +++ b/packages/cache/src/UserCacheInsightsProvider.php @@ -45,7 +45,7 @@ public function getInsights(): array private function getInsight(Cache $cache): array { $type = $cache instanceof GenericCache - ? match (get_class($cache->adapter)) { + ? match ($cache->adapter::class) { FilesystemAdapter::class => new Insight('Filesystem'), PhpFilesAdapter::class => new Insight('PHP'), ArrayAdapter::class => new Insight('In-memory'), diff --git a/packages/command-bus/src/Async.php b/packages/command-bus/src/Async.php index eb1b35a49..b3b6b5852 100644 --- a/packages/command-bus/src/Async.php +++ b/packages/command-bus/src/Async.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute] -final readonly class Async -{ -} +final readonly class Async {} diff --git a/packages/command-bus/src/GenericCommandBus.php b/packages/command-bus/src/GenericCommandBus.php index 9c071545b..5ae0e156c 100644 --- a/packages/command-bus/src/GenericCommandBus.php +++ b/packages/command-bus/src/GenericCommandBus.php @@ -20,7 +20,7 @@ public function dispatch(object $command): void { $commandHandler = $this->getCommandHandler($command); - if ($commandHandler === null) { + if (! $commandHandler instanceof CommandHandler) { throw new CommandHandlerWasNotFound($command); } diff --git a/packages/command-bus/src/HandleAsyncCommand.php b/packages/command-bus/src/HandleAsyncCommand.php index 7947189fa..88fadf9c9 100644 --- a/packages/command-bus/src/HandleAsyncCommand.php +++ b/packages/command-bus/src/HandleAsyncCommand.php @@ -13,7 +13,7 @@ use function Tempest\Support\arr; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class HandleAsyncCommand { use HasConsole; diff --git a/packages/command-bus/src/MonitorAsyncCommands.php b/packages/command-bus/src/MonitorAsyncCommands.php index 03187e00b..2aaa2f36d 100644 --- a/packages/command-bus/src/MonitorAsyncCommands.php +++ b/packages/command-bus/src/MonitorAsyncCommands.php @@ -13,7 +13,7 @@ use function Tempest\Support\arr; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class MonitorAsyncCommands { use HasConsole; @@ -48,11 +48,15 @@ public function __invoke(): void ); } - if ($output = trim($process->getOutput())) { + $output = trim($process->getOutput()); + + if ($output !== '' && $output !== '0') { $this->writeln($output); } - if ($errorOutput = trim($process->getErrorOutput())) { + $errorOutput = trim($process->getErrorOutput()); + + if ($errorOutput !== '' && $errorOutput !== '0') { $this->writeln($errorOutput); } diff --git a/packages/console/src/Actions/RenderConsoleCommand.php b/packages/console/src/Actions/RenderConsoleCommand.php index 8015f7293..6ef462af5 100644 --- a/packages/console/src/Actions/RenderConsoleCommand.php +++ b/packages/console/src/Actions/RenderConsoleCommand.php @@ -30,10 +30,8 @@ public function __invoke(ConsoleCommand $consoleCommand): void } } - if ($this->renderDescription) { - if ($consoleCommand->description !== null && $consoleCommand->description !== '') { - $parts[] = "{$consoleCommand->description}"; - } + if ($this->renderDescription && ($consoleCommand->description !== null && $consoleCommand->description !== '')) { + $parts[] = "{$consoleCommand->description}"; } $this->console->writeln(implode(' ', $parts)); diff --git a/packages/console/src/CanOpenInEditor.php b/packages/console/src/CanOpenInEditor.php index 3ff635bb0..f39561b98 100644 --- a/packages/console/src/CanOpenInEditor.php +++ b/packages/console/src/CanOpenInEditor.php @@ -4,6 +4,4 @@ namespace Tempest\Console; -interface CanOpenInEditor -{ -} +interface CanOpenInEditor {} diff --git a/packages/console/src/Commands/AboutCommand.php b/packages/console/src/Commands/AboutCommand.php index c5ca55399..33a85b403 100644 --- a/packages/console/src/Commands/AboutCommand.php +++ b/packages/console/src/Commands/AboutCommand.php @@ -22,9 +22,9 @@ final readonly class AboutCommand { public function __construct( - private readonly Console $console, - private readonly Container $container, - private readonly AppConfig $appConfig, + private Console $console, + private Container $container, + private AppConfig $appConfig, ) {} #[ConsoleCommand(name: 'about', description: 'Shows insights about the application', aliases: ['insights'])] diff --git a/packages/console/src/Commands/CompletionInstallCommand.php b/packages/console/src/Commands/CompletionInstallCommand.php index 434591d51..a60477837 100644 --- a/packages/console/src/Commands/CompletionInstallCommand.php +++ b/packages/console/src/Commands/CompletionInstallCommand.php @@ -51,7 +51,7 @@ public function __invoke( $shell ??= ($this->resolveShell)('Which shell do you want to install completions for?'); - if ($shell === null) { + if (! $shell instanceof Shell) { $this->console->error('Could not detect shell. Please specify one using the --shell option. Possible values are: zsh, bash, fish.'); return ExitCode::ERROR; diff --git a/packages/console/src/Commands/CompletionShowCommand.php b/packages/console/src/Commands/CompletionShowCommand.php index e816b04b6..2bee1e135 100644 --- a/packages/console/src/Commands/CompletionShowCommand.php +++ b/packages/console/src/Commands/CompletionShowCommand.php @@ -43,7 +43,7 @@ public function __invoke( $shell ??= ($this->resolveShell)('Which shell completion script do you want to see?'); - if ($shell === null) { + if (! $shell instanceof Shell) { $this->console->error('Could not detect shell. Please specify one using the --shell option. Possible values are: zsh, bash, fish.'); return ExitCode::ERROR; diff --git a/packages/console/src/Commands/CompletionUninstallCommand.php b/packages/console/src/Commands/CompletionUninstallCommand.php index 21bc32f16..1ece3d629 100644 --- a/packages/console/src/Commands/CompletionUninstallCommand.php +++ b/packages/console/src/Commands/CompletionUninstallCommand.php @@ -42,7 +42,7 @@ public function __invoke( $shell ??= ($this->resolveShell)('Which shell completions do you want to uninstall?'); - if ($shell === null) { + if (! $shell instanceof Shell) { $this->console->error('Could not detect shell. Please specify one using the --shell option. Possible values are: zsh, bash, fish.'); return ExitCode::ERROR; diff --git a/packages/console/src/Commands/MakeConfigCommand.php b/packages/console/src/Commands/MakeConfigCommand.php index eee7a984c..73183f758 100644 --- a/packages/console/src/Commands/MakeConfigCommand.php +++ b/packages/console/src/Commands/MakeConfigCommand.php @@ -68,7 +68,11 @@ private function getStubFileFromConfigType(ConfigType $configType): StubFile default => throw new InvalidArgumentException(sprintf('The "%s" config type has no supported stub file.', $configType->value)), }; } catch (InvalidArgumentException $invalidArgumentException) { - throw new FileGenerationFailedException(sprintf('Cannot retrieve stub file: %s', $invalidArgumentException->getMessage())); + throw new FileGenerationFailedException( + sprintf('Cannot retrieve stub file: %s', $invalidArgumentException->getMessage()), + $invalidArgumentException->getCode(), + $invalidArgumentException, + ); } } } diff --git a/packages/console/src/Completion/CompletionEngine.php b/packages/console/src/Completion/CompletionEngine.php index ecc53dc37..52043027a 100644 --- a/packages/console/src/Completion/CompletionEngine.php +++ b/packages/console/src/Completion/CompletionEngine.php @@ -47,7 +47,11 @@ private function completeCommands(CompletionMetadata $metadata, string $current) $candidates = []; foreach ($metadata->commands as $name => $command) { - if (! is_string($name) || ! $command instanceof CompletionCommand) { + if (! is_string($name)) { + continue; + } + + if (! $command instanceof CompletionCommand) { continue; } diff --git a/packages/console/src/Components/Interactive/MultipleChoiceComponent.php b/packages/console/src/Components/Interactive/MultipleChoiceComponent.php index c9f52f263..3c6902462 100644 --- a/packages/console/src/Components/Interactive/MultipleChoiceComponent.php +++ b/packages/console/src/Components/Interactive/MultipleChoiceComponent.php @@ -109,12 +109,12 @@ public function input(string $key): void if (! $this->bufferEnabled && $key === '/') { $this->bufferEnabled = true; $this->updateQuery(); - return; - } elseif ($this->bufferEnabled && $key === '/') { + } + + if ($this->bufferEnabled && $key === '/') { $this->bufferEnabled = false; $this->updateQuery(); - return; } diff --git a/packages/console/src/Components/Interactive/SearchComponent.php b/packages/console/src/Components/Interactive/SearchComponent.php index a1665d6c9..055e4bdf1 100644 --- a/packages/console/src/Components/Interactive/SearchComponent.php +++ b/packages/console/src/Components/Interactive/SearchComponent.php @@ -9,6 +9,7 @@ use Tempest\Console\Components\Concerns\HasState; use Tempest\Console\Components\Concerns\HasTextBuffer; use Tempest\Console\Components\Concerns\RendersControls; +use Tempest\Console\Components\Option; use Tempest\Console\Components\OptionCollection; use Tempest\Console\Components\Renderers\ChoiceRenderer; use Tempest\Console\Components\Static\StaticSearchComponent; @@ -157,7 +158,7 @@ public function enter(): mixed return $this->options->getRawSelectedOptions() ?: $this->default; } - if (($active = $this->options->getActive()) !== null) { + if (($active = $this->options->getActive()) instanceof Option) { return $active->value; } diff --git a/packages/console/src/Components/Interactive/SingleChoiceComponent.php b/packages/console/src/Components/Interactive/SingleChoiceComponent.php index b0d9cc44e..75c4100f2 100644 --- a/packages/console/src/Components/Interactive/SingleChoiceComponent.php +++ b/packages/console/src/Components/Interactive/SingleChoiceComponent.php @@ -113,11 +113,11 @@ public function input(string $key): void { if (! $this->bufferEnabled && $key === '/') { $this->bufferEnabled = true; - return; - } elseif ($this->bufferEnabled && $key === '/') { - $this->bufferEnabled = false; + } + if ($this->bufferEnabled && $key === '/') { + $this->bufferEnabled = false; return; } diff --git a/packages/console/src/Components/Interactive/TaskComponent.php b/packages/console/src/Components/Interactive/TaskComponent.php index 4ccb73ede..08875a722 100644 --- a/packages/console/src/Components/Interactive/TaskComponent.php +++ b/packages/console/src/Components/Interactive/TaskComponent.php @@ -171,17 +171,17 @@ private function resolveHandler(null|Process|Closure $handler): ?Closure } if ($handler instanceof Process) { - return static function (Closure $log) use ($handler): bool { - return $handler->run(function (string $type, string $buffer) use ($log): void { - if ($type === Process::ERR) { - return; - } - - if ($line = trim($buffer)) { - $log($line); - } - }) === 0; - }; + return static fn (Closure $log): bool => $handler->run(function (string $type, string $buffer) use ($log): void { + if ($type === Process::ERR) { + return; + } + + $line = trim($buffer); + + if ($line !== '' && $line !== '0') { + $log($line); + } + }) === 0; } return $handler; diff --git a/packages/console/src/Components/InteractiveComponentRenderer.php b/packages/console/src/Components/InteractiveComponentRenderer.php index 63bb076d2..a77ccc571 100644 --- a/packages/console/src/Components/InteractiveComponentRenderer.php +++ b/packages/console/src/Components/InteractiveComponentRenderer.php @@ -66,7 +66,7 @@ private function renderComponent(Console $console, InteractiveConsoleComponent $ // If we're running within a fiber, we'll suspend here as well so that the parent can continue // This is needed for our testing helper - if (Fiber::getCurrent() !== null) { + if (Fiber::getCurrent() instanceof Fiber) { Fiber::suspend(); } } @@ -246,11 +246,7 @@ public function isComponentSupported(Console $console, InteractiveConsoleCompone return false; } - if (! Terminal::supportsTty()) { - return false; - } - - return true; + return Terminal::supportsTty(); } private function createTerminal(Console $console): Terminal diff --git a/packages/console/src/Components/OptionCollection.php b/packages/console/src/Components/OptionCollection.php index 16243f1be..12aeb37c4 100644 --- a/packages/console/src/Components/OptionCollection.php +++ b/packages/console/src/Components/OptionCollection.php @@ -83,7 +83,7 @@ public function next(): void public function toggleCurrent(): void { - if (($active = $this->getActive()) === null) { + if (! ($active = $this->getActive()) instanceof Option) { return; } @@ -133,7 +133,7 @@ public function getRawActiveOption(mixed $default = null): mixed { $option = $this->getActive(); - if ($option === null) { + if (! $option instanceof Option) { return $default; } diff --git a/packages/console/src/Components/Renderers/ChoiceRenderer.php b/packages/console/src/Components/Renderers/ChoiceRenderer.php index 463140131..bceb85f73 100644 --- a/packages/console/src/Components/Renderers/ChoiceRenderer.php +++ b/packages/console/src/Components/Renderers/ChoiceRenderer.php @@ -56,9 +56,9 @@ public function render( // Otherwise, display the filter line $this->line( $this->style($filtering ? 'fg-magenta' : 'fg-gray', '/ '), - ! $query->text - ? $this->style('fg-gray dim', $placeholder ?? ($this->multiple && ! $filtering ? count($options->getSelectedOptions()) . ' selected' : '')) - : $this->style($filtering ? 'fg-cyan' : 'fg-gray', $this->truncateLeft($query->text, maxLineOffset: 2)), + $query->text + ? $this->style($filtering ? 'fg-cyan' : 'fg-gray', $this->truncateLeft($query->text, maxLineOffset: 2)) + : $this->style('fg-gray dim', $placeholder ?? ($this->multiple && ! $filtering ? count($options->getSelectedOptions()) . ' selected' : '')), )->newLine(); // And the choices. diff --git a/packages/console/src/Components/Renderers/ConfirmRenderer.php b/packages/console/src/Components/Renderers/ConfirmRenderer.php index 95808b08c..ff6ad382c 100644 --- a/packages/console/src/Components/Renderers/ConfirmRenderer.php +++ b/packages/console/src/Components/Renderers/ConfirmRenderer.php @@ -36,7 +36,7 @@ public function render( }, "\n"), default => $this->line( $this->style( - $answer === true ? 'fg-green bold' : 'fg-gray dim', + $answer ? 'fg-green bold' : 'fg-gray dim', '→ ' . $this->yes, ), ' ', diff --git a/packages/console/src/Components/Renderers/TaskRenderer.php b/packages/console/src/Components/Renderers/TaskRenderer.php index 0e73f87a9..d4e1ffa7f 100644 --- a/packages/console/src/Components/Renderers/TaskRenderer.php +++ b/packages/console/src/Components/Renderers/TaskRenderer.php @@ -23,7 +23,7 @@ public function render(Terminal $terminal, ComponentState $state, float $started $this->prepareRender($terminal, $state); $this->label($this->label); - $runtime = fn (float $finishedAt) => $finishedAt + $runtime = fn (float $finishedAt) => $finishedAt !== 0.0 ? number_format(($finishedAt - $startedAt) / 1_000_000, decimals: 0) : null; diff --git a/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php b/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php index 76e3a8a0d..46c529b43 100644 --- a/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticMultipleChoiceComponent.php @@ -41,7 +41,7 @@ public function render(Console $console): array ->toString() ?: 'no option'; $continue = $console->confirm( - question: $answers + question: $answers !== [] ? "You picked {$answerAsString}; continue?" : "Continue with {$answerAsString}?", default: true, @@ -97,11 +97,7 @@ private function askQuestion(Console $console): array return true; } - if ($this->options->getOptions()->isList() && $answer === (string) $option->key) { - return true; - } - - return false; + return $this->options->getOptions()->isList() && $answer === (string) $option->key; }); }) ->filter() diff --git a/packages/console/src/Components/Static/StaticSearchComponent.php b/packages/console/src/Components/Static/StaticSearchComponent.php index 9630c65ce..ba62597aa 100644 --- a/packages/console/src/Components/Static/StaticSearchComponent.php +++ b/packages/console/src/Components/Static/StaticSearchComponent.php @@ -43,8 +43,8 @@ public function render(Console $console): null|array|string $answer = $console->ask( question: 'Please select a result', options: $options, - multiple: $this->multiple, default: $this->multiple ? [] : self::CANCEL, + multiple: $this->multiple, ); if ($answer === self::SEARCH_AGAIN) { diff --git a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php index 8010ad1cd..41853a12b 100644 --- a/packages/console/src/Components/Static/StaticSingleChoiceComponent.php +++ b/packages/console/src/Components/Static/StaticSingleChoiceComponent.php @@ -71,11 +71,7 @@ public function render(Console $console): null|int|UnitEnum|string return true; } - if ($this->options->getOptions()->isList() && $answer === (string) $option->key) { - return true; - } - - return false; + return $this->options->getOptions()->isList() && $answer === (string) $option->key; }); if ($selectedOption !== null) { diff --git a/packages/console/src/Console.php b/packages/console/src/Console.php index 056ce5584..57875c72d 100644 --- a/packages/console/src/Console.php +++ b/packages/console/src/Console.php @@ -161,7 +161,5 @@ public function disablePrompting(): self; /** * Whether the console is in forced mode (skipping confirmations). */ - public bool $isForced { - get; - } + public bool $isForced { get; } } diff --git a/packages/console/src/ConsoleInputBuilder.php b/packages/console/src/ConsoleInputBuilder.php index 2b8f0aad9..1a93db354 100644 --- a/packages/console/src/ConsoleInputBuilder.php +++ b/packages/console/src/ConsoleInputBuilder.php @@ -42,7 +42,7 @@ public function build(): array ? $this->argumentBag->findArrayFor($argumentDefinition) : $this->argumentBag->findFor($argumentDefinition); - if ($argument === null) { + if (! $argument instanceof ConsoleInputArgument) { $invalidArguments[] = $argumentDefinition; continue; diff --git a/packages/console/src/Exceptions/InvalidCommandException.php b/packages/console/src/Exceptions/InvalidCommandException.php index cff1141f9..3301854b3 100644 --- a/packages/console/src/Exceptions/InvalidCommandException.php +++ b/packages/console/src/Exceptions/InvalidCommandException.php @@ -24,7 +24,7 @@ public function render(Console $console): void $this->invalidArguments, )); - if ($missingArguments) { + if ($missingArguments !== '' && $missingArguments !== '0') { $console->writeln(); $console->error("Missing arguments: {$missingArguments}"); } else { diff --git a/packages/console/src/GenericConsole.php b/packages/console/src/GenericConsole.php index c22bc951f..06185f7b0 100644 --- a/packages/console/src/GenericConsole.php +++ b/packages/console/src/GenericConsole.php @@ -195,7 +195,7 @@ public function keyValue(string $key, ?string $value = null, bool $useAvailableW public function component(InteractiveConsoleComponent $component, array $validation = []): mixed { - if ($this->componentRenderer !== null && $this->supportsPrompting() && $this->componentRenderer->isComponentSupported($this, $component)) { + if ($this->componentRenderer instanceof InteractiveComponentRenderer && $this->supportsPrompting() && $this->componentRenderer->isComponentSupported($this, $component)) { return $this->componentRenderer->render($this, $component, $validation); } @@ -310,10 +310,6 @@ public function supportsPrompting(): bool return false; } - if ($this->argumentBag->get(GlobalFlags::INTERACTION->value)?->value === false) { - return false; - } - - return true; + return $this->argumentBag->get(GlobalFlags::INTERACTION->value)?->value !== false; } } diff --git a/packages/console/src/HasStaticComponent.php b/packages/console/src/HasStaticComponent.php index c23fa81ac..ef896911c 100644 --- a/packages/console/src/HasStaticComponent.php +++ b/packages/console/src/HasStaticComponent.php @@ -6,7 +6,5 @@ interface HasStaticComponent { - public StaticConsoleComponent $staticComponent { - get; - } + public StaticConsoleComponent $staticComponent { get; } } diff --git a/packages/console/src/Highlight/IsTagInjection.php b/packages/console/src/Highlight/IsTagInjection.php index 740263d00..bb519ea81 100644 --- a/packages/console/src/Highlight/IsTagInjection.php +++ b/packages/console/src/Highlight/IsTagInjection.php @@ -26,7 +26,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio callback: function ($matches) use ($highlighter) { $content = $matches['match'] ?? ''; - if (! $content) { + if ($content === '' || $content === '0') { return $matches[0]; } diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php index cbaae269b..66ed85f53 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/DynamicInjection.php @@ -19,7 +19,6 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio do { $content = preg_replace_callback( - subject: $content, pattern: $pattern, callback: function ($matches) use ($highlighter) { $theme = $highlighter->getTheme(); @@ -40,6 +39,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio ->replaceLast('', $after) ->toString(); }, + subject: $content, ); } while (preg_match($pattern, $content)); diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php index b455eb5d3..fc0868ddf 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/FileInjection.php @@ -18,7 +18,6 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjection { return new ParsedInjection(preg_replace_callback( - subject: $content, pattern: '/(?\[\"\'])(?.+)\k\s*\/?>)/', callback: function (array $matches) { $href = $matches['file']; @@ -29,6 +28,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio return TerminalStyle::UNDERLINE((string) $file); }, + subject: $content, )); } } diff --git a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php index cc5d3a47f..79b068e04 100644 --- a/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php +++ b/packages/console/src/Highlight/TempestConsoleLanguage/Injections/LinkInjection.php @@ -15,7 +15,6 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjection { return new ParsedInjection(preg_replace_callback( - subject: $content, pattern: '/(?\[\"\'])(?.+)\k\>(?:(?!\)/', callback: function (array $matches) { $quote = $matches['quote']; @@ -27,6 +26,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio ->replaceLast('', "\x1b]8;;\x1b\\") ->toString(); }, + subject: $content, )); } } diff --git a/packages/console/src/Input/ConsoleArgumentDefinition.php b/packages/console/src/Input/ConsoleArgumentDefinition.php index c636990d8..199109755 100644 --- a/packages/console/src/Input/ConsoleArgumentDefinition.php +++ b/packages/console/src/Input/ConsoleArgumentDefinition.php @@ -32,7 +32,7 @@ public static function fromParameter(ParameterReflector $parameter): ConsoleArgu $boolean = $type->getName() === 'bool' || is_bool($default); return new ConsoleArgumentDefinition( - name: static::normalizeName($attribute->name ?? $parameter->getName(), boolean: $boolean), + name: self::normalizeName($attribute->name ?? $parameter->getName(), boolean: $boolean), type: $type->getName(), default: $default, hasDefault: $parameter->isDefaultValueAvailable(), @@ -56,7 +56,7 @@ public function matchesArgument(ConsoleInputArgument $argument): bool return array_any( array: [$this->name, ...$this->aliases], - callback: fn ($match) => $argument->matches(static::normalizeName($match, $this->type === 'bool')), + callback: fn ($match) => $argument->matches(self::normalizeName($match, $this->type === 'bool')), ); } diff --git a/packages/console/src/Input/MemoryInputBuffer.php b/packages/console/src/Input/MemoryInputBuffer.php index 63676ce4e..0600eb26f 100644 --- a/packages/console/src/Input/MemoryInputBuffer.php +++ b/packages/console/src/Input/MemoryInputBuffer.php @@ -7,6 +7,7 @@ use Exception; use Fiber; use FiberError; +use RuntimeException; use Tempest\Console\InputBuffer; use Tempest\Console\Key; @@ -29,7 +30,7 @@ public function add(int|string|Key ...$input): void try { $this->fiber?->resume(); } catch (FiberError) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Tried to send [%s] to the console, but no input was expected.', implode( separator: ', ', diff --git a/packages/console/src/Middleware/ForceMiddleware.php b/packages/console/src/Middleware/ForceMiddleware.php index 65ae19620..8f15f4af0 100644 --- a/packages/console/src/Middleware/ForceMiddleware.php +++ b/packages/console/src/Middleware/ForceMiddleware.php @@ -22,10 +22,11 @@ public function __construct( public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int { - if ($invocation->argumentBag->get(GlobalFlags::FORCE_SHORTHAND->value) || $invocation->argumentBag->get(GlobalFlags::FORCE->value)) { - if ($this->console instanceof GenericConsole) { - $this->console->setForced(); - } + if ( + ($invocation->argumentBag->get(GlobalFlags::FORCE_SHORTHAND->value) || $invocation->argumentBag->get(GlobalFlags::FORCE->value)) + && $this->console instanceof GenericConsole + ) { + $this->console->setForced(); } return $next($invocation); diff --git a/packages/console/src/Middleware/OverviewMiddleware.php b/packages/console/src/Middleware/OverviewMiddleware.php index f68ce8227..0e51b8a8d 100644 --- a/packages/console/src/Middleware/OverviewMiddleware.php +++ b/packages/console/src/Middleware/OverviewMiddleware.php @@ -31,7 +31,7 @@ public function __construct( public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int { - if (! $invocation->argumentBag->getCommandName()) { + if ($invocation->argumentBag->getCommandName() === '' || $invocation->argumentBag->getCommandName() === '0') { $this->renderOverview(showHidden: $invocation->argumentBag->has('--all', '-a')); return ExitCode::SUCCESS; diff --git a/packages/console/src/Middleware/ResolveOrRescueMiddleware.php b/packages/console/src/Middleware/ResolveOrRescueMiddleware.php index 1f252fc2e..97771ee3f 100644 --- a/packages/console/src/Middleware/ResolveOrRescueMiddleware.php +++ b/packages/console/src/Middleware/ResolveOrRescueMiddleware.php @@ -92,12 +92,9 @@ private function getSimilarCommands(ImmutableString $search): ImmutableArray $searchParts = $search->explode(':'); // `dis:st` will match `discovery:status` - if ($searchParts->count() === $currentParts->count()) { - if ($searchParts->every(fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) { - $suggestions[$currentName->toString()] = $currentName; - - continue; - } + if ($searchParts->count() === $currentParts->count() && $searchParts->every(fn (string $part, int $index) => str_starts_with($currentParts[$index], $part))) { + $suggestions[$currentName->toString()] = $currentName; + continue; } // `generate` will match `discovery:generate` diff --git a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php index c7b4cd143..375102a9e 100644 --- a/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php +++ b/packages/console/src/Middleware/ValidateNamedArgumentsMiddleware.php @@ -24,12 +24,8 @@ public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next } $allowedParameterNames = arr($invocation->consoleCommand->getArgumentDefinitions()) - ->flatMap(function (ConsoleArgumentDefinition $definition) { - return [$definition->name, ...$definition->aliases]; - }) - ->map(function (string $name) { - return ltrim($name, '-'); - }); + ->flatMap(fn (ConsoleArgumentDefinition $definition) => [$definition->name, ...$definition->aliases]) + ->map(fn (string $name) => ltrim($name, '-')); $invalidInput = arr($invocation->argumentBag->arguments) ->filter(fn (ConsoleInputArgument $argument) => $argument->name !== null) diff --git a/packages/console/src/Output/TailReader.php b/packages/console/src/Output/TailReader.php index 4191a8128..b4024fa68 100644 --- a/packages/console/src/Output/TailReader.php +++ b/packages/console/src/Output/TailReader.php @@ -20,7 +20,7 @@ public function tail(string $path, ?Closure $format = null): void /** @phpstan-ignore-next-line */ while (true) { - if (Fiber::getCurrent() !== null) { + if (Fiber::getCurrent() instanceof Fiber) { Fiber::suspend(); } diff --git a/packages/console/src/Scheduler/NullScheduler.php b/packages/console/src/Scheduler/NullScheduler.php index 7cd1d58ad..3ca9e1eb6 100644 --- a/packages/console/src/Scheduler/NullScheduler.php +++ b/packages/console/src/Scheduler/NullScheduler.php @@ -9,7 +9,5 @@ final class NullScheduler implements Scheduler { - public function run(?DateTime $date = null): void - { - } + public function run(?DateTime $date = null): void {} } diff --git a/packages/console/src/Testing/ConsoleTester.php b/packages/console/src/Testing/ConsoleTester.php index 088f695c5..a33541c9d 100644 --- a/packages/console/src/Testing/ConsoleTester.php +++ b/packages/console/src/Testing/ConsoleTester.php @@ -68,7 +68,7 @@ public function call(string|Closure|array $command, string|array $arguments = [] $console->disablePrompting(); } - if ($this->componentRenderer !== null) { + if ($this->componentRenderer instanceof InteractiveComponentRenderer) { $console->setComponentRenderer($this->componentRenderer); } @@ -94,7 +94,7 @@ public function call(string|Closure|array $command, string|array $arguments = [] $fiber->start(); - if ($clone->componentRenderer !== null) { + if ($clone->componentRenderer instanceof InteractiveComponentRenderer) { $clone->input("\e[1;1R"); // Set cursor for interactive testing } @@ -162,7 +162,7 @@ public function printFormatted(): self public function getBuffer(?callable $callback = null): array { - $buffer = array_map('trim', $this->output->getBufferWithoutFormatting()); + $buffer = array_map(trim(...), $this->output->getBufferWithoutFormatting()); $this->output->clear(); diff --git a/packages/console/tests/CompletionHelperPhpTest.php b/packages/console/tests/CompletionHelperPhpTest.php index 4940f6095..518a4340d 100644 --- a/packages/console/tests/CompletionHelperPhpTest.php +++ b/packages/console/tests/CompletionHelperPhpTest.php @@ -16,7 +16,9 @@ final class CompletionHelperPhpTest extends TestCase { private CompletionEngine $engine; + private CompletionInputNormalizer $inputNormalizer; + private CompletionMetadataParser $metadataParser; protected function setUp(): void diff --git a/packages/console/tests/TextBufferTest.php b/packages/console/tests/TextBufferTest.php index af26f5b62..76b6a5267 100644 --- a/packages/console/tests/TextBufferTest.php +++ b/packages/console/tests/TextBufferTest.php @@ -137,10 +137,10 @@ public function test_move_cursor_to_start(): void $this->assertSame(0, $buffer->cursor); $buffer = new TextBuffer(<<moveCursorX(100); $buffer->moveCursorToStart(); $this->assertSame(0, $buffer->cursor); @@ -155,10 +155,10 @@ public function test_move_cursor_to_end(): void $this->assertSame(13, $buffer->cursor); $buffer = new TextBuffer(<<setCursorIndex(0); $buffer->moveCursorToEnd(); $this->assertSame(48, $buffer->cursor); @@ -185,10 +185,10 @@ public function test_move_cursor_to_start_of_line(): void public function test_move_cursor_to_start_of_line_multiline(int $initial, int $expected): void { $buffer = new TextBuffer(<<setCursorIndex($initial); $buffer->moveCursorToStartOfLine(); @@ -217,10 +217,10 @@ public function test_move_cursor_to_end_of_line(): void public function test_move_cursor_to_end_of_line_multiline(int $initial, int $expected): void { $buffer = new TextBuffer(<<setCursorIndex($initial); $buffer->moveCursorToEndOfLine(); @@ -258,10 +258,10 @@ public function test_move_cursor_x(int $initialCursor, int $offsetX, int $expect public function move_cursor_y(int $initialCursor, int $offsetY, int $expectedPosition): void { $buffer = new TextBuffer(<<setCursorIndex($initialCursor); $buffer->moveCursorY($offsetY); diff --git a/packages/container/src/Autowire.php b/packages/container/src/Autowire.php index 8297e2d2e..adc5f433e 100644 --- a/packages/container/src/Autowire.php +++ b/packages/container/src/Autowire.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS)] -final class Autowire -{ -} +final class Autowire {} diff --git a/packages/container/src/Commands/ContainerShowCommand.php b/packages/container/src/Commands/ContainerShowCommand.php index 0542e21c5..5c2cd62d3 100644 --- a/packages/container/src/Commands/ContainerShowCommand.php +++ b/packages/container/src/Commands/ContainerShowCommand.php @@ -18,7 +18,7 @@ use function Tempest\Support\Str\before_last; use function Tempest\Support\Str\contains; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class ContainerShowCommand { public function __construct( @@ -68,12 +68,12 @@ public function __invoke(): ExitCode private function listBindings(string $title, array $bindings, ?Closure $formatKey = null, ?Closure $formatValue = null, ?Closure $reject = null): void { - if (! $bindings) { + if ($bindings === []) { return; } $reject ??= static fn (): bool => false; - $formatKey ??= fn (int|string $key): string => $this->formatClassKey($key); + $formatKey ??= $this->formatClassKey(...); $formatValue ??= fn (int|string $key, mixed $value): string => $this->formatClassValue($value, $key); $this->console->header($title); diff --git a/packages/container/src/Commands/MakeInitializerCommand.php b/packages/container/src/Commands/MakeInitializerCommand.php index dff9019d0..bc86fd0d7 100644 --- a/packages/container/src/Commands/MakeInitializerCommand.php +++ b/packages/container/src/Commands/MakeInitializerCommand.php @@ -13,7 +13,7 @@ use Tempest\Generation\Php\ClassManipulator; use Tempest\Generation\Php\DataObjects\StubFile; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final class MakeInitializerCommand { use PublishesFiles; diff --git a/packages/container/src/Dependency.php b/packages/container/src/Dependency.php index 39b9a6aed..149d60f3d 100644 --- a/packages/container/src/Dependency.php +++ b/packages/container/src/Dependency.php @@ -40,7 +40,7 @@ public function getTypeName(): string if (is_string($dependency)) { $parts = explode('\\', $dependency); - return $parts[array_key_last($parts)]; + return array_last($parts); } return match ($dependency::class) { diff --git a/packages/container/src/DependencyChain.php b/packages/container/src/DependencyChain.php index 41af43699..210cfb4c4 100644 --- a/packages/container/src/DependencyChain.php +++ b/packages/container/src/DependencyChain.php @@ -34,12 +34,12 @@ public function add(Reflector|Closure|string $dependency): self public function first(): Dependency { - return $this->dependencies[array_key_first($this->dependencies)]; + return array_first($this->dependencies); } public function last(): Dependency { - return $this->dependencies[array_key_last($this->dependencies)]; + return array_last($this->dependencies); } /** @return \Tempest\Container\Dependency[] */ diff --git a/packages/container/src/Exceptions/CircularDependencyEncountered.php b/packages/container/src/Exceptions/CircularDependencyEncountered.php index d4ed8de8b..36c75e5dc 100644 --- a/packages/container/src/Exceptions/CircularDependencyEncountered.php +++ b/packages/container/src/Exceptions/CircularDependencyEncountered.php @@ -35,9 +35,7 @@ public function __construct(DependencyChain $chain, Dependency $circularDependen $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $circularDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: function ($matches) { - return '└' . str_repeat('─', strlen($matches['prefix']) + 3) . str_repeat('▒', strlen($matches['selection'])); - }, + callback: fn ($matches) => '└' . str_repeat('─', strlen($matches['prefix']) + 3) . str_repeat('▒', strlen($matches['selection'])), subject: $chain->last()->getShortName(), ); diff --git a/packages/container/src/Exceptions/ContainerException.php b/packages/container/src/Exceptions/ContainerException.php index 02809f491..aac08af63 100644 --- a/packages/container/src/Exceptions/ContainerException.php +++ b/packages/container/src/Exceptions/ContainerException.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Exceptions; -interface ContainerException -{ -} +interface ContainerException {} diff --git a/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php b/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php index 8a6e33be7..da50c7020 100644 --- a/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php +++ b/packages/container/src/Exceptions/DependencyCouldNotBeAutowired.php @@ -34,9 +34,7 @@ public function __construct(DependencyChain $chain, Dependency $brokenDependency $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $brokenDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: function ($matches) { - return str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])); - }, + callback: fn ($matches) => str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])), subject: $chain->last()->getShortName(), ); diff --git a/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php b/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php index f9541f850..62a6b336c 100644 --- a/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php +++ b/packages/container/src/Exceptions/TaggedDependencyCouldNotBeResolved.php @@ -47,9 +47,7 @@ public function __construct(DependencyChain $chain, Dependency $brokenDependency $selectionLine = preg_replace_callback( pattern: '/(?(.*))(?' . $brokenDependency->getTypeName() . '\s\$\w+)(.*)/', - callback: function ($matches) { - return str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])); - }, + callback: fn ($matches) => str_repeat(' ', strlen($matches['prefix']) + 4) . str_repeat('▒', strlen($matches['selection'])), subject: $chain->last()->getShortName(), ); diff --git a/packages/container/src/GenericContainer.php b/packages/container/src/GenericContainer.php index 2483f0640..b69d44ca8 100644 --- a/packages/container/src/GenericContainer.php +++ b/packages/container/src/GenericContainer.php @@ -326,7 +326,7 @@ private function resolve(string $className, null|string|UnitEnum $tag = null, mi $instance = $this->resolveDependency($className, $tag, ...$params); if ($this->decorators[$className] ?? null) { - $instance = $this->resolveDecorator($className, $instance, $tag, ...$params); + return $this->resolveDecorator($className, $instance, $tag, ...$params); } return $instance; @@ -378,7 +378,7 @@ private function resolveDependency(string $className, null|string|UnitEnum $tag } // If we're requesting a tagged dependency and haven't resolved it at this point, something's wrong - if ($tag) { + if ($tag !== null) { throw new TaggedDependencyCouldNotBeResolved($this->chain, new Dependency($className), $tag); } @@ -433,15 +433,15 @@ private function autowire(string $className, mixed ...$params): object throw new DependencyCouldNotBeInstantiated($classReflector, $this->chain); } - $instance = $constructor === null + $instance = $constructor instanceof MethodReflector // trying to build it. // If there isn't a constructor, don't waste time - ? $classReflector->newInstanceWithoutConstructor() + ? $classReflector->newInstanceArgs( + $this->autowireDependencies($constructor, $params), + ) // build up each parameter. // Otherwise, use our autowireDependencies helper to automagically - : $classReflector->newInstanceArgs( - $this->autowireDependencies($constructor, $params), - ); + : $classReflector->newInstanceWithoutConstructor(); if ( ! $classReflector->getType()->matches(Initializer::class) @@ -546,9 +546,7 @@ private function autowireObjectDependency(TypeReflector $type, null|string|UnitE return $type ->asClass() ->getReflection() - ->newLazyProxy(function () use ($type, $tag) { - return $this->resolve(className: $type->getName(), tag: $tag); - }); + ->newLazyProxy(fn () => $this->resolve(className: $type->getName(), tag: $tag)); } // If we can successfully retrieve an instance @@ -612,7 +610,7 @@ private function clone(): self private function resolveChain(): DependencyChain { - if ($this->chain === null) { + if (! $this->chain instanceof DependencyChain) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $this->chain = new DependencyChain($trace[1]['file'] . ':' . $trace[1]['line']); diff --git a/packages/container/src/HasTag.php b/packages/container/src/HasTag.php index 0aa252f6a..535bccf5a 100644 --- a/packages/container/src/HasTag.php +++ b/packages/container/src/HasTag.php @@ -6,7 +6,5 @@ interface HasTag { - public null|string|UnitEnum $tag { - get; - } + public null|string|UnitEnum $tag { get; } } diff --git a/packages/container/src/Proxy.php b/packages/container/src/Proxy.php index 10cfee429..7fa29f7c6 100644 --- a/packages/container/src/Proxy.php +++ b/packages/container/src/Proxy.php @@ -12,6 +12,4 @@ * The container may then decide to do lazy initialization */ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)] -final readonly class Proxy -{ -} +final readonly class Proxy {} diff --git a/packages/container/tests/ContainerTest.php b/packages/container/tests/ContainerTest.php index effa97435..1431f0f2a 100644 --- a/packages/container/tests/ContainerTest.php +++ b/packages/container/tests/ContainerTest.php @@ -325,9 +325,9 @@ public function test_autowired_tagged_dependency_exception(): void } catch (TaggedDependencyCouldNotBeResolved $cannotResolveTaggedDependency) { $this->assertStringContainsStringIgnoringLineEndings( <<<'TXT' - ┌── DependencyWithTaggedDependency::__construct(TaggedDependency $dependency) - └── Tempest\Container\Tests\Fixtures\TaggedDependency - TXT, + ┌── DependencyWithTaggedDependency::__construct(TaggedDependency $dependency) + └── Tempest\Container\Tests\Fixtures\TaggedDependency + TXT, $cannotResolveTaggedDependency->getMessage(), ); } diff --git a/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php b/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php index 58e8f2cb0..349fd2dd3 100644 --- a/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php +++ b/packages/container/tests/Exceptions/CannotAutowireExceptionTest.php @@ -26,11 +26,11 @@ public function test_autowire_without_exception(): void $this->assertStringContainsString('Cannot autowire ' . AutowireA::class . '::__construct because string cannot be resolved', $cannotAutowireException->getMessage()); $expected = <<<'TXT' - ┌── AutowireA::__construct(AutowireB $b) - ├── AutowireB::__construct(AutowireC $c) - └── AutowireC::__construct(ContainerObjectA $other, string $unknown) - ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + ┌── AutowireA::__construct(AutowireB $b) + ├── AutowireB::__construct(AutowireC $c) + └── AutowireC::__construct(ContainerObjectA $other, string $unknown) + ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $cannotAutowireException->getMessage()); $this->assertStringContainsString('CannotAutowireExceptionTest.php:24', $cannotAutowireException->getMessage()); diff --git a/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php b/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php index 6ec8887d5..147f28acc 100644 --- a/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php +++ b/packages/container/tests/Exceptions/CircularDependencyExceptionTest.php @@ -30,11 +30,11 @@ public function test_circular_dependency_test(): void ); $expected = <<<'TXT' - ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) - │ CircularB::__construct(CircularC $c) - │ CircularC::__construct(ContainerObjectA $other, CircularA $a) - └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) + │ CircularB::__construct(CircularC $c) + │ CircularC::__construct(ContainerObjectA $other, CircularA $a) + └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $circularDependencyException->getMessage()); @@ -59,12 +59,12 @@ public function test_circular_dependency_as_a_child_test(): void ); $expected = <<<'TXT' - CircularZ::__construct(CircularA $a) - ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) - │ CircularB::__construct(CircularC $c) - │ CircularC::__construct(ContainerObjectA $other, CircularA $a) - └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ - TXT; + CircularZ::__construct(CircularA $a) + ┌─► CircularA::__construct(ContainerObjectA $other, CircularB $b) + │ CircularB::__construct(CircularC $c) + │ CircularC::__construct(ContainerObjectA $other, CircularA $a) + └───────────────────────────────────────────────────▒▒▒▒▒▒▒▒▒▒▒▒ + TXT; $this->assertStringContainsStringIgnoringLineEndings($expected, $circularDependencyException->getMessage()); diff --git a/packages/container/tests/Fixtures/ContainerObjectA.php b/packages/container/tests/Fixtures/ContainerObjectA.php index aceae4de0..8f616a804 100644 --- a/packages/container/tests/Fixtures/ContainerObjectA.php +++ b/packages/container/tests/Fixtures/ContainerObjectA.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final class ContainerObjectA -{ -} +final class ContainerObjectA {} diff --git a/packages/container/tests/Fixtures/DecoratedClass.php b/packages/container/tests/Fixtures/DecoratedClass.php index da11df34a..5e1cee022 100644 --- a/packages/container/tests/Fixtures/DecoratedClass.php +++ b/packages/container/tests/Fixtures/DecoratedClass.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final class DecoratedClass implements DecoratedInterface -{ -} +final class DecoratedClass implements DecoratedInterface {} diff --git a/packages/container/tests/Fixtures/DecoratedInterface.php b/packages/container/tests/Fixtures/DecoratedInterface.php index ddae1db5a..1a9d08396 100644 --- a/packages/container/tests/Fixtures/DecoratedInterface.php +++ b/packages/container/tests/Fixtures/DecoratedInterface.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface DecoratedInterface -{ -} +interface DecoratedInterface {} diff --git a/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php b/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php index 6adabcc37..de30c8b5e 100644 --- a/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php +++ b/packages/container/tests/Fixtures/DecoratorWithoutConstructor.php @@ -7,6 +7,4 @@ use Tempest\Container\Decorates; #[Decorates(DecoratedInterface::class)] -final class DecoratorWithoutConstructor implements DecoratedInterface -{ -} +final class DecoratorWithoutConstructor implements DecoratedInterface {} diff --git a/packages/container/tests/Fixtures/ImplementsInterfaceA.php b/packages/container/tests/Fixtures/ImplementsInterfaceA.php index 81404be60..9b14c30f7 100644 --- a/packages/container/tests/Fixtures/ImplementsInterfaceA.php +++ b/packages/container/tests/Fixtures/ImplementsInterfaceA.php @@ -6,7 +6,5 @@ final class ImplementsInterfaceA implements InterfaceA { - public function __invoke(): void - { - } + public function __invoke(): void {} } diff --git a/packages/container/tests/Fixtures/InjectB.php b/packages/container/tests/Fixtures/InjectB.php index 81e0ddc78..f7564219b 100644 --- a/packages/container/tests/Fixtures/InjectB.php +++ b/packages/container/tests/Fixtures/InjectB.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final readonly class InjectB -{ -} +final readonly class InjectB {} diff --git a/packages/container/tests/Fixtures/InterfaceA.php b/packages/container/tests/Fixtures/InterfaceA.php index 81206885f..86e374a17 100644 --- a/packages/container/tests/Fixtures/InterfaceA.php +++ b/packages/container/tests/Fixtures/InterfaceA.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface InterfaceA -{ -} +interface InterfaceA {} diff --git a/packages/container/tests/Fixtures/UnionImplementation.php b/packages/container/tests/Fixtures/UnionImplementation.php index ce931a18b..e663b1906 100644 --- a/packages/container/tests/Fixtures/UnionImplementation.php +++ b/packages/container/tests/Fixtures/UnionImplementation.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -final readonly class UnionImplementation implements UnionInterfaceA, UnionInterfaceB -{ -} +final readonly class UnionImplementation implements UnionInterfaceA, UnionInterfaceB {} diff --git a/packages/container/tests/Fixtures/UnionInterfaceA.php b/packages/container/tests/Fixtures/UnionInterfaceA.php index 6574213e8..e64583989 100644 --- a/packages/container/tests/Fixtures/UnionInterfaceA.php +++ b/packages/container/tests/Fixtures/UnionInterfaceA.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface UnionInterfaceA -{ -} +interface UnionInterfaceA {} diff --git a/packages/container/tests/Fixtures/UnionInterfaceB.php b/packages/container/tests/Fixtures/UnionInterfaceB.php index 061913934..1cb98985b 100644 --- a/packages/container/tests/Fixtures/UnionInterfaceB.php +++ b/packages/container/tests/Fixtures/UnionInterfaceB.php @@ -4,6 +4,4 @@ namespace Tempest\Container\Tests\Fixtures; -interface UnionInterfaceB -{ -} +interface UnionInterfaceB {} diff --git a/packages/core/src/Commands/DiscoveryClearCommand.php b/packages/core/src/Commands/DiscoveryClearCommand.php index b31776e11..5bcba5189 100644 --- a/packages/core/src/Commands/DiscoveryClearCommand.php +++ b/packages/core/src/Commands/DiscoveryClearCommand.php @@ -8,7 +8,7 @@ use Tempest\Console\ConsoleCommand; use Tempest\Core\DiscoveryCache; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class DiscoveryClearCommand { public function __construct( diff --git a/packages/core/src/Commands/DiscoveryGenerateCommand.php b/packages/core/src/Commands/DiscoveryGenerateCommand.php index ca286ddfa..a3dafeff0 100644 --- a/packages/core/src/Commands/DiscoveryGenerateCommand.php +++ b/packages/core/src/Commands/DiscoveryGenerateCommand.php @@ -16,7 +16,7 @@ use Tempest\Core\Kernel; use Tempest\Core\Kernel\LoadDiscoveryClasses; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class DiscoveryGenerateCommand { use HasConsole; diff --git a/packages/core/src/Commands/DiscoveryStatusCommand.php b/packages/core/src/Commands/DiscoveryStatusCommand.php index 1f037ff11..91f3c9cfb 100644 --- a/packages/core/src/Commands/DiscoveryStatusCommand.php +++ b/packages/core/src/Commands/DiscoveryStatusCommand.php @@ -15,7 +15,7 @@ use function Tempest\root_path; use function Tempest\Support\str; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class DiscoveryStatusCommand { public function __construct( diff --git a/packages/core/src/Commands/InstallCommand.php b/packages/core/src/Commands/InstallCommand.php index 1b49eea04..1d3a19738 100644 --- a/packages/core/src/Commands/InstallCommand.php +++ b/packages/core/src/Commands/InstallCommand.php @@ -14,7 +14,7 @@ use function Tempest\Support\arr; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class InstallCommand { use HasConsole; @@ -35,7 +35,7 @@ public function __invoke(?string $installer = null, bool $_tailwind = false): vo { $installer = $this->resolveInstaller($installer); - if ($installer === null) { + if (! $installer instanceof Installer) { $this->error('Installer not found'); return; diff --git a/packages/core/src/Composer.php b/packages/core/src/Composer.php index e3c6917b9..a14ab5a5b 100644 --- a/packages/core/src/Composer.php +++ b/packages/core/src/Composer.php @@ -112,7 +112,7 @@ public function save(): self public function executeUpdate(): self { - if ($this->executor) { + if ($this->executor instanceof ProcessExecutor) { $this->executor->run('composer up'); } else { exec('composer update'); diff --git a/packages/core/src/ComposerJsonCouldNotBeLocated.php b/packages/core/src/ComposerJsonCouldNotBeLocated.php index 10bf4b2c7..4c3bcd1dc 100644 --- a/packages/core/src/ComposerJsonCouldNotBeLocated.php +++ b/packages/core/src/ComposerJsonCouldNotBeLocated.php @@ -6,6 +6,4 @@ use Exception; -final class ComposerJsonCouldNotBeLocated extends Exception -{ -} +final class ComposerJsonCouldNotBeLocated extends Exception {} diff --git a/packages/core/src/ConfigCache.php b/packages/core/src/ConfigCache.php index 5a156b5ce..bc3a5c491 100644 --- a/packages/core/src/ConfigCache.php +++ b/packages/core/src/ConfigCache.php @@ -38,7 +38,7 @@ public function put(string $key, mixed $value, null|Duration|DateTimeInterface $ $expiresAt = DateTime::now()->plus($expiresAt); } - if ($expiresAt !== null) { + if ($expiresAt instanceof DateTimeInterface) { $item = $item->expiresAt($expiresAt->toNativeDateTime()); } diff --git a/packages/core/src/CouldNotStoreDiscoveryCache.php b/packages/core/src/CouldNotStoreDiscoveryCache.php index 0fdd88245..1733e51e7 100644 --- a/packages/core/src/CouldNotStoreDiscoveryCache.php +++ b/packages/core/src/CouldNotStoreDiscoveryCache.php @@ -10,7 +10,7 @@ final class CouldNotStoreDiscoveryCache extends Exception public function __construct(DiscoveryLocation $location) { parent::__construct(sprintf( - 'Could not store discovery cache for %s. This is likely because you\'re trying to store unserializable data like reflection classes or closures in discovery items.', + "Could not store discovery cache for %s. This is likely because you're trying to store unserializable data like reflection classes or closures in discovery items.", $location->path, )); } diff --git a/packages/core/src/DiscoveryCacheInitializer.php b/packages/core/src/DiscoveryCacheInitializer.php index 0370519a6..378cb3743 100644 --- a/packages/core/src/DiscoveryCacheInitializer.php +++ b/packages/core/src/DiscoveryCacheInitializer.php @@ -51,7 +51,7 @@ private function isDiscoveryGenerateCommand(): bool $command = $_SERVER['argv'][1] ?? null; - return $command === 'dg' || $command === 'discovery:generate' || $command === 'd:g'; + return in_array($command, ['dg', 'discovery:generate', 'd:g'], true); } private function isDiscoveryClearCommand(): bool @@ -62,6 +62,6 @@ private function isDiscoveryClearCommand(): bool $command = $_SERVER['argv'][1] ?? null; - return $command === 'dc' || $command === 'discovery:clear' || $command === 'd:c'; + return in_array($command, ['dc', 'discovery:clear', 'd:c'], true); } } diff --git a/packages/core/src/Exceptions/ExceptionTester.php b/packages/core/src/Exceptions/ExceptionTester.php index 0290234cd..a8e72ad89 100644 --- a/packages/core/src/Exceptions/ExceptionTester.php +++ b/packages/core/src/Exceptions/ExceptionTester.php @@ -50,7 +50,7 @@ public function assertProcessed(string|object $exception, ?Closure $callback = n Assert::assertCount($count, $reports, sprintf('Expected %s report(s), got %s.', $count, count($reports))); } - if ($callback !== null) { + if ($callback instanceof Closure) { foreach ($reports as $dispatch) { Assert::assertNotFalse($callback($dispatch), 'The callback failed.'); } @@ -92,11 +92,7 @@ private function findRecordedProcessings(string|object $exception): array return true; } - if (class_exists($exception) && is_a($reported, $exception, allow_string: true)) { - return true; - } - - return false; + return class_exists($exception) && is_a($reported, $exception, allow_string: true); }); } diff --git a/packages/core/src/Exceptions/GenericExceptionProcessor.php b/packages/core/src/Exceptions/GenericExceptionProcessor.php index fa9e72334..b6d02f9b9 100644 --- a/packages/core/src/Exceptions/GenericExceptionProcessor.php +++ b/packages/core/src/Exceptions/GenericExceptionProcessor.php @@ -8,11 +8,11 @@ /** * Reports exceptions to registered exception processors. */ -final class GenericExceptionProcessor implements ExceptionProcessor +final readonly class GenericExceptionProcessor implements ExceptionProcessor { public function __construct( - private readonly ExceptionsConfig $config, - private readonly Container $container, + private ExceptionsConfig $config, + private Container $container, ) {} public function process(Throwable $throwable): void diff --git a/packages/core/src/Exceptions/LoggingExceptionReporter.php b/packages/core/src/Exceptions/LoggingExceptionReporter.php index 8454a4b47..bb56479bb 100644 --- a/packages/core/src/Exceptions/LoggingExceptionReporter.php +++ b/packages/core/src/Exceptions/LoggingExceptionReporter.php @@ -9,10 +9,10 @@ /** * An exception reporter that write exceptions through the {@see Logger}. */ -final class LoggingExceptionReporter implements ExceptionReporter +final readonly class LoggingExceptionReporter implements ExceptionReporter { public function __construct( - private readonly Logger $logger, + private Logger $logger, ) {} public function report(Throwable $throwable): void diff --git a/packages/core/src/FrameworkKernel.php b/packages/core/src/FrameworkKernel.php index 9fb47ddfe..42969f3ea 100644 --- a/packages/core/src/FrameworkKernel.php +++ b/packages/core/src/FrameworkKernel.php @@ -183,7 +183,7 @@ public function loadConfig(): self public function registerInternalStorage(): self { - $path = isset($this->internalStorage) ? $this->internalStorage : $this->root . '/.tempest'; + $path = $this->internalStorage ?? $this->root . '/.tempest'; if (! is_dir($path)) { if (file_exists($path)) { diff --git a/packages/core/src/InsightsProvider.php b/packages/core/src/InsightsProvider.php index c361318ed..2c9fbed89 100644 --- a/packages/core/src/InsightsProvider.php +++ b/packages/core/src/InsightsProvider.php @@ -10,9 +10,7 @@ interface InsightsProvider /** * Display name of this provider. */ - public string $name { - get; - } + public string $name { get; } /** * Gets insights in the form of key/value pairs. diff --git a/packages/core/src/Installer.php b/packages/core/src/Installer.php index 9f8cb3cf0..cb9698b2a 100644 --- a/packages/core/src/Installer.php +++ b/packages/core/src/Installer.php @@ -6,9 +6,7 @@ interface Installer { - public string $name { - get; - } + public string $name { get; } public function install(): void; } diff --git a/packages/core/src/Kernel.php b/packages/core/src/Kernel.php index 65f45fb96..7a8b97cf9 100644 --- a/packages/core/src/Kernel.php +++ b/packages/core/src/Kernel.php @@ -10,27 +10,15 @@ interface Kernel { public const string VERSION = '3.3.1'; - public string $root { - get; - } - - public string $internalStorage { - get; - } - - public array $discoveryLocations { - get; - set; - } - - public array $discoveryClasses { - get; - set; - } - - public Container $container { - get; - } + public string $root { get; } + + public string $internalStorage { get; } + + public array $discoveryLocations { get; set; } + + public array $discoveryClasses { get; set; } + + public Container $container { get; } public static function boot( string $root, diff --git a/packages/core/src/Kernel/LoadConfig.php b/packages/core/src/Kernel/LoadConfig.php index 6c916f166..1c22ee9d2 100644 --- a/packages/core/src/Kernel/LoadConfig.php +++ b/packages/core/src/Kernel/LoadConfig.php @@ -113,7 +113,11 @@ private function scan(string $path, MutableArray $configPaths): void foreach ($subPaths as $subPath) { // `.` and `..` are skipped - if ($subPath === '.' || $subPath === '..') { + if ($subPath === '.') { + continue; + } + + if ($subPath === '..') { continue; } diff --git a/packages/core/src/Kernel/LoadDiscoveryClasses.php b/packages/core/src/Kernel/LoadDiscoveryClasses.php index f6ae0b8cf..073e1674a 100644 --- a/packages/core/src/Kernel/LoadDiscoveryClasses.php +++ b/packages/core/src/Kernel/LoadDiscoveryClasses.php @@ -24,6 +24,7 @@ final class LoadDiscoveryClasses { private array $appliedDiscovery = []; + private array $shouldSkipForClass = []; public function __construct( @@ -72,7 +73,7 @@ public function build( // Resolve all other discoveries from the container, optionally loading their cache $discoveries = array_map( - fn (string $discoveryClass) => $this->resolveDiscovery($discoveryClass), + $this->resolveDiscovery(...), $kernel->discoveryClasses, ); @@ -80,17 +81,15 @@ public function build( $this->discover($discoveries, $discoveryLocations); return [$discoveryDiscovery, ...$discoveries]; - } else { - // Resolve all manually specified discoveries - $discoveries = array_map( - fn (string $discoveryClass) => $this->resolveDiscovery($discoveryClass), - $discoveryClasses, - ); - - $this->discover($discoveries, $discoveryLocations); - - return $discoveries; } + + // Resolve all manually specified discoveries + $discoveries = array_map( + $this->resolveDiscovery(...), + $discoveryClasses, + ); + $this->discover($discoveries, $discoveryLocations); + return $discoveries; } /** @@ -175,7 +174,11 @@ private function scan(DiscoveryLocation $location, array $discoveries, string $p foreach ($subPaths as $subPath) { // `.` and `..` are skipped - if ($subPath === '.' || $subPath === '..') { + if ($subPath === '.') { + continue; + } + + if ($subPath === '..') { continue; } diff --git a/packages/core/src/PublishesFiles.php b/packages/core/src/PublishesFiles.php index 410d5d156..0ebe8dbc3 100644 --- a/packages/core/src/PublishesFiles.php +++ b/packages/core/src/PublishesFiles.php @@ -103,7 +103,7 @@ public function publish(string $source, string $destination, ?Closure $callback $this->publishedFiles[] = $destination; - if ($callback !== null) { + if ($callback instanceof Closure) { $callback($source, $destination); } @@ -115,10 +115,7 @@ public function publish(string $source, string $destination, ?Closure $callback throw $throwable; } - throw new FileGenerationFailedException( - message: 'The file could not be published.', - previous: $throwable, - ); + throw new FileGenerationFailedException(message: 'The file could not be published.', code: $throwable->getCode(), previous: $throwable); } } diff --git a/packages/cryptography/src/Encryption/Encrypter.php b/packages/cryptography/src/Encryption/Encrypter.php index 20f3087e5..f26d4703b 100644 --- a/packages/cryptography/src/Encryption/Encrypter.php +++ b/packages/cryptography/src/Encryption/Encrypter.php @@ -2,16 +2,16 @@ namespace Tempest\Cryptography\Encryption; +use SensitiveParameter; + interface Encrypter { - public EncryptionAlgorithm $algorithm { - get; - } + public EncryptionAlgorithm $algorithm { get; } /** * Encrypts the specified data. */ - public function encrypt(#[\SensitiveParameter] string $data): EncryptedData; + public function encrypt(#[SensitiveParameter] string $data): EncryptedData; /** * Decrypts the specified data. diff --git a/packages/cryptography/src/Encryption/EncryptionConfig.php b/packages/cryptography/src/Encryption/EncryptionConfig.php index ffd2de0a2..1d70a404d 100644 --- a/packages/cryptography/src/Encryption/EncryptionConfig.php +++ b/packages/cryptography/src/Encryption/EncryptionConfig.php @@ -2,6 +2,8 @@ namespace Tempest\Cryptography\Encryption; +use SensitiveParameter; + final class EncryptionConfig { /** @@ -10,7 +12,7 @@ final class EncryptionConfig */ public function __construct( public EncryptionAlgorithm $algorithm, - #[\SensitiveParameter] + #[SensitiveParameter] public readonly ?string $key, ) {} } diff --git a/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php b/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php index b590b3c2b..bc252de37 100644 --- a/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php +++ b/packages/cryptography/src/Encryption/Exceptions/EncryptionException.php @@ -2,6 +2,4 @@ namespace Tempest\Cryptography\Encryption\Exceptions; -interface EncryptionException -{ -} +interface EncryptionException {} diff --git a/packages/cryptography/src/Encryption/GenericEncrypter.php b/packages/cryptography/src/Encryption/GenericEncrypter.php index 1b2e68c98..c23892149 100644 --- a/packages/cryptography/src/Encryption/GenericEncrypter.php +++ b/packages/cryptography/src/Encryption/GenericEncrypter.php @@ -2,6 +2,7 @@ namespace Tempest\Cryptography\Encryption; +use SensitiveParameter; use Tempest\Cryptography\Encryption\Exceptions\AlgorithmMismatched; use Tempest\Cryptography\Encryption\Exceptions\DecryptionFailed; use Tempest\Cryptography\Encryption\Exceptions\EncryptionFailed; @@ -23,7 +24,7 @@ public function __construct( private readonly EncryptionConfig $config, ) {} - public function encrypt(#[\SensitiveParameter] string $data): EncryptedData + public function encrypt(#[SensitiveParameter] string $data): EncryptedData { $iv = random_bytes($this->algorithm->getIvLength()); $tag = ''; diff --git a/packages/cryptography/src/GenerateSigningKeyCommand.php b/packages/cryptography/src/GenerateSigningKeyCommand.php index f65b1da33..e953230fd 100644 --- a/packages/cryptography/src/GenerateSigningKeyCommand.php +++ b/packages/cryptography/src/GenerateSigningKeyCommand.php @@ -13,7 +13,7 @@ use function Tempest\root_path; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class GenerateSigningKeyCommand { public function __construct( diff --git a/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php b/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php index 7a993a6d0..0bc2a05c6 100644 --- a/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php +++ b/packages/cryptography/src/Password/Exceptions/PasswordHashingException.php @@ -2,6 +2,4 @@ namespace Tempest\Cryptography\Password\Exceptions; -interface PasswordHashingException -{ -} +interface PasswordHashingException {} diff --git a/packages/cryptography/src/Password/GenericPasswordHasher.php b/packages/cryptography/src/Password/GenericPasswordHasher.php index 22c97ca60..ee7fd50eb 100644 --- a/packages/cryptography/src/Password/GenericPasswordHasher.php +++ b/packages/cryptography/src/Password/GenericPasswordHasher.php @@ -3,6 +3,7 @@ namespace Tempest\Cryptography\Password; use Error; +use SensitiveParameter; use Tempest\Cryptography\Password\Exceptions\HashingFailed; use ValueError; @@ -16,7 +17,7 @@ public function __construct( private readonly PasswordHashingConfig $config, ) {} - public function hash(#[\SensitiveParameter] string $password): string + public function hash(#[SensitiveParameter] string $password): string { if ($password === '') { throw HashingFailed::forEmptyPassword(); @@ -33,7 +34,7 @@ public function hash(#[\SensitiveParameter] string $password): string return $hash; } - public function verify(#[\SensitiveParameter] string $password, #[\SensitiveParameter] string $hash): bool + public function verify(#[SensitiveParameter] string $password, #[SensitiveParameter] string $hash): bool { if ($password === '' || $hash === '') { return false; @@ -42,7 +43,7 @@ public function verify(#[\SensitiveParameter] string $password, #[\SensitivePara return password_verify($password, $hash); } - public function needsRehash(#[\SensitiveParameter] string $hash): bool + public function needsRehash(#[SensitiveParameter] string $hash): bool { if ($hash === '') { return false; @@ -51,7 +52,7 @@ public function needsRehash(#[\SensitiveParameter] string $hash): bool return password_needs_rehash($hash, $this->algorithm->value, $this->config->options); } - public function analyze(#[\SensitiveParameter] string $hash): ?Hash + public function analyze(#[SensitiveParameter] string $hash): ?Hash { if ($hash === '') { return null; diff --git a/packages/cryptography/src/Password/Hash.php b/packages/cryptography/src/Password/Hash.php index d1242fb7e..6dd12cedd 100644 --- a/packages/cryptography/src/Password/Hash.php +++ b/packages/cryptography/src/Password/Hash.php @@ -2,10 +2,12 @@ namespace Tempest\Cryptography\Password; +use SensitiveParameter; + final readonly class Hash { public function __construct( - #[\SensitiveParameter] + #[SensitiveParameter] public string $hash, public HashingAlgorithm $algorithm, public PasswordHashingConfig $config, diff --git a/packages/cryptography/src/Password/PasswordHasher.php b/packages/cryptography/src/Password/PasswordHasher.php index e2a256765..46d224a9a 100644 --- a/packages/cryptography/src/Password/PasswordHasher.php +++ b/packages/cryptography/src/Password/PasswordHasher.php @@ -2,30 +2,30 @@ namespace Tempest\Cryptography\Password; +use SensitiveParameter; + interface PasswordHasher { - public HashingAlgorithm $algorithm { - get; - } + public HashingAlgorithm $algorithm { get; } /** * Hashes the specified password. */ - public function hash(#[\SensitiveParameter] string $password): string; + public function hash(#[SensitiveParameter] string $password): string; /** * Checks if the given plain-text password matches the given hash. */ - public function verify(#[\SensitiveParameter] string $password, string $hash): bool; + public function verify(#[SensitiveParameter] string $password, string $hash): bool; /** * Checks if the given hash needs to be rehashed, which happens * when the initial hash was created with different algorithm options. */ - public function needsRehash(#[\SensitiveParameter] string $hash): bool; + public function needsRehash(#[SensitiveParameter] string $hash): bool; /** * Returns information about the given hash, such as the algorithm used and its options. */ - public function analyze(#[\SensitiveParameter] string $hash): ?Hash; + public function analyze(#[SensitiveParameter] string $hash): ?Hash; } diff --git a/packages/cryptography/src/Password/PasswordHashingConfig.php b/packages/cryptography/src/Password/PasswordHashingConfig.php index a561ed49b..683dac6a4 100644 --- a/packages/cryptography/src/Password/PasswordHashingConfig.php +++ b/packages/cryptography/src/Password/PasswordHashingConfig.php @@ -4,14 +4,10 @@ interface PasswordHashingConfig { - public HashingAlgorithm $algorithm { - get; - } + public HashingAlgorithm $algorithm { get; } /** * Options for PHP's `password_hash` and `password_verify` functions. */ - public array $options { - get; - } + public array $options { get; } } diff --git a/packages/cryptography/src/Signing/Exceptions/SigningException.php b/packages/cryptography/src/Signing/Exceptions/SigningException.php index 48e42aab5..89dad5655 100644 --- a/packages/cryptography/src/Signing/Exceptions/SigningException.php +++ b/packages/cryptography/src/Signing/Exceptions/SigningException.php @@ -2,6 +2,4 @@ namespace Tempest\Cryptography\Signing\Exceptions; -interface SigningException -{ -} +interface SigningException {} diff --git a/packages/cryptography/src/Signing/Signer.php b/packages/cryptography/src/Signing/Signer.php index 6d40b6108..88002be90 100644 --- a/packages/cryptography/src/Signing/Signer.php +++ b/packages/cryptography/src/Signing/Signer.php @@ -4,9 +4,7 @@ interface Signer { - public SigningAlgorithm $algorithm { - get; - } + public SigningAlgorithm $algorithm { get; } /** * Signs the given data. diff --git a/packages/cryptography/src/Signing/SigningConfig.php b/packages/cryptography/src/Signing/SigningConfig.php index d2d26a5ba..785fb7da6 100644 --- a/packages/cryptography/src/Signing/SigningConfig.php +++ b/packages/cryptography/src/Signing/SigningConfig.php @@ -2,6 +2,7 @@ namespace Tempest\Cryptography\Signing; +use SensitiveParameter; use Tempest\DateTime\Duration; final class SigningConfig @@ -13,7 +14,7 @@ final class SigningConfig */ public function __construct( public SigningAlgorithm $algorithm, - #[\SensitiveParameter] + #[SensitiveParameter] public readonly ?string $key, public false|Duration $minimumExecutionDuration, ) {} diff --git a/packages/cryptography/src/Timelock.php b/packages/cryptography/src/Timelock.php index 99408c40e..30eb75786 100644 --- a/packages/cryptography/src/Timelock.php +++ b/packages/cryptography/src/Timelock.php @@ -4,6 +4,7 @@ use Tempest\Clock\Clock; use Tempest\DateTime\Duration; +use Throwable; final class Timelock { @@ -32,7 +33,7 @@ public function invoke(callable $callback, Duration $duration): mixed try { $result = $callback($this); - } catch (\Throwable $thrown) { + } catch (Throwable $thrown) { $exception = $thrown; } @@ -42,7 +43,7 @@ public function invoke(callable $callback, Duration $duration): mixed $this->clock->sleep(Duration::microseconds($remainderInMicroseconds)); } - if ($exception) { + if ($exception instanceof Throwable) { throw $exception; } diff --git a/packages/cryptography/tests/TimelockTest.php b/packages/cryptography/tests/TimelockTest.php index 08c073905..ef68a2b99 100644 --- a/packages/cryptography/tests/TimelockTest.php +++ b/packages/cryptography/tests/TimelockTest.php @@ -3,6 +3,7 @@ namespace Tempest\Cryptography\Tests; use PHPUnit\Framework\TestCase; +use RuntimeException; use Tempest\Clock\GenericClock; use Tempest\Clock\MockClock; use Tempest\Cryptography\Timelock; @@ -57,10 +58,10 @@ public function test_throws_exception_after_delay(): void try { $timelock->invoke( - callback: fn () => throw new \RuntimeException('This is an error.'), + callback: fn () => throw new RuntimeException('This is an error.'), duration: Duration::milliseconds(100), ); - } catch (\RuntimeException) { + } catch (RuntimeException) { $elapsed = microtime(true) - $start; $this->assertEqualsToMoreOrLess(0.1, $elapsed, margin: 0.015, windowsMargin: 0.025); } diff --git a/packages/database/src/BelongsTo.php b/packages/database/src/BelongsTo.php index 2478fdf32..8d5a56681 100644 --- a/packages/database/src/BelongsTo.php +++ b/packages/database/src/BelongsTo.php @@ -42,9 +42,9 @@ public function getOwnerFieldName(): string if ($this->ownerJoin) { if (str_contains($this->ownerJoin, '.')) { return explode('.', $this->ownerJoin)[1]; - } else { - return $this->ownerJoin; } + + return $this->ownerJoin; } $relationModel = inspect($this->property->getType()->asClass()); @@ -66,15 +66,13 @@ public function getSelectFields(): ImmutableArray return $relationModel ->getSelectFields() - ->map(function ($field) use ($tableReference) { - return new FieldStatement( - $tableReference . '.' . $field, + ->map(fn ($field) => new FieldStatement( + $tableReference . '.' . $field, + ) + ->withAlias( + sprintf('%s.%s', $this->property->getName(), $field), ) - ->withAlias( - sprintf('%s.%s', $this->property->getName(), $field), - ) - ->withAliasPrefix($this->parent); - }); + ->withAliasPrefix($this->parent)); } public function getJoinStatement(): JoinStatement diff --git a/packages/database/src/Builder/ModelInspector.php b/packages/database/src/Builder/ModelInspector.php index d39dab76d..89712b5ba 100644 --- a/packages/database/src/Builder/ModelInspector.php +++ b/packages/database/src/Builder/ModelInspector.php @@ -89,7 +89,7 @@ public function __construct( public function isObjectModel(): bool { - return $this->reflector !== null; + return $this->reflector instanceof ClassReflector; } public function getTableDefinition(): TableDefinition @@ -113,12 +113,10 @@ public function getTableDefinition(): TableDefinition public function getFieldDefinition(string $field): FieldDefinition { - return $this->memoize('getFieldDefinition' . $field, function () use ($field) { - return new FieldDefinition( - $this->getTableDefinition(), - $field, - ); - }); + return $this->memoize('getFieldDefinition' . $field, fn () => new FieldDefinition( + $this->getTableDefinition(), + $field, + )); } public function getTableName(): string @@ -152,7 +150,11 @@ public function getPropertyValues(): array continue; } - if ($this->getHasMany($property->getName()) || $this->getHasOne($property->getName())) { + if ($this->getHasMany($property->getName()) instanceof HasMany) { + continue; + } + + if ($this->getHasOne($property->getName()) instanceof HasOne) { continue; } @@ -186,7 +188,7 @@ public function getBelongsTo(string $name): ?BelongsTo $property = $this->reflector->getProperty($name); - if ($belongsTo = $property->getAttribute(BelongsTo::class)) { + if (($belongsTo = $property->getAttribute(BelongsTo::class)) instanceof BelongsTo) { return $belongsTo; } @@ -238,7 +240,7 @@ public function getHasOne(string $name): ?HasOne $property = $this->reflector->getProperty($name); - if ($hasOne = $property->getAttribute(HasOne::class)) { + if (($hasOne = $property->getAttribute(HasOne::class)) instanceof HasOne) { return $hasOne; } @@ -261,7 +263,7 @@ public function getHasMany(string $name): ?HasMany $property = $this->reflector->getProperty($name); - if ($hasMany = $property->getAttribute(HasMany::class)) { + if (($hasMany = $property->getAttribute(HasMany::class)) instanceof HasMany) { return $hasMany; } @@ -284,18 +286,17 @@ public function isRelation(string|PropertyReflector $name): bool { $name = $name instanceof PropertyReflector ? $name->getName() : $name; - return $this->memoize('isRelation' . $name, function () use ($name) { - return $this->getBelongsTo($name) !== null || $this->getHasOne($name) !== null || $this->getHasMany($name) !== null; - }); + return $this->memoize( + 'isRelation' . $name, + fn () => $this->getBelongsTo($name) instanceof BelongsTo || $this->getHasOne($name) instanceof HasOne || $this->getHasMany($name) instanceof HasMany, + ); } public function getRelation(string|PropertyReflector $name): ?Relation { $name = $name instanceof PropertyReflector ? $name->getName() : $name; - return $this->memoize('getRelation' . $name, function () use ($name) { - return $this->getBelongsTo($name) ?? $this->getHasOne($name) ?? $this->getHasMany($name); - }); + return $this->memoize('getRelation' . $name, fn () => $this->getBelongsTo($name) ?? $this->getHasOne($name) ?? $this->getHasMany($name)); } /** @@ -311,7 +312,7 @@ public function getRelations(): ImmutableArray $relationFields = arr(); foreach ($this->reflector->getPublicProperties() as $property) { - if ($relation = $this->getRelation($property->getName())) { + if (($relation = $this->getRelation($property->getName())) instanceof Relation) { $relationFields[] = $relation; } } @@ -360,7 +361,7 @@ public function isRelationLoaded(string|PropertyReflector|Relation $relation): b $relation = $this->getRelation($relation); } - if (! $relation) { + if (! $relation instanceof Relation) { return false; } @@ -368,11 +369,7 @@ public function isRelationLoaded(string|PropertyReflector|Relation $relation): b return false; } - if ($relation->property->getValue($this->instance) === null) { - return false; - } - - return true; + return $relation->property->getValue($this->instance) !== null; } public function getSelectFields(): ImmutableArray @@ -383,18 +380,25 @@ public function getSelectFields(): ImmutableArray $selectFields = arr(); - if ($primaryKey = $this->getPrimaryKeyProperty()) { + if (($primaryKey = $this->getPrimaryKeyProperty()) instanceof PropertyReflector) { $selectFields[] = $primaryKey->getName(); } foreach ($this->reflector->getPublicProperties() as $property) { $relation = $this->getRelation($property->getName()); + if ($relation instanceof HasMany) { + continue; + } - if ($relation instanceof HasMany || $relation instanceof HasOne) { + if ($relation instanceof HasOne) { continue; } - if ($property->isVirtual() || $property->hasAttribute(Virtual::class)) { + if ($property->isVirtual()) { + continue; + } + + if ($property->hasAttribute(Virtual::class)) { continue; } @@ -428,7 +432,7 @@ public function resolveRelations(string $relationString, string $parent = '', ar $currentRelation = $this->getRelation($currentRelationName); - if ($currentRelation === null) { + if (! $currentRelation instanceof Relation) { return []; } @@ -473,7 +477,7 @@ public function resolveEagerRelations(string $parent = '', array $visitedPaths = $currentRelationName = $property->getName(); $currentRelation = $this->getRelation($currentRelationName); - if (! $currentRelation) { + if (! $currentRelation instanceof Relation) { continue; } @@ -537,7 +541,7 @@ public function validate(mixed ...$data): void public function getName(): string { - if ($this->reflector) { + if ($this->reflector instanceof ClassReflector) { return $this->reflector->getName(); } @@ -560,7 +564,7 @@ public function getPrimaryKey(): ?string public function hasPrimaryKey(): bool { - return $this->getPrimaryKeyProperty() !== null; + return $this->getPrimaryKeyProperty() instanceof PropertyReflector; } public function getPrimaryKeyProperty(): ?PropertyReflector @@ -590,7 +594,7 @@ public function getPrimaryKeyValue(): ?PrimaryKey $primaryKeyProperty = $this->getPrimaryKeyProperty(); - if ($primaryKeyProperty === null) { + if (! $primaryKeyProperty instanceof PropertyReflector) { return null; } diff --git a/packages/database/src/Builder/QueryBuilders/BuildsQuery.php b/packages/database/src/Builder/QueryBuilders/BuildsQuery.php index 712ac65b2..9ec20e885 100644 --- a/packages/database/src/Builder/QueryBuilders/BuildsQuery.php +++ b/packages/database/src/Builder/QueryBuilders/BuildsQuery.php @@ -16,23 +16,17 @@ interface BuildsQuery * * @return array */ - public array $bindings { - get; - } + public array $bindings { get; } /** * The model inspector for this query builder. */ - public ModelInspector $model { - get; - } + public ModelInspector $model { get; } /** * The database tag for targeting a specific database connection. */ - public null|string|UnitEnum $onDatabase { - get; - } + public null|string|UnitEnum $onDatabase { get; } /** * Creates a {@see Query} instance with the specified optional bindings. diff --git a/packages/database/src/Builder/QueryBuilders/DeleteQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/DeleteQueryBuilder.php index ec415c455..49a29ee4a 100644 --- a/packages/database/src/Builder/QueryBuilders/DeleteQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/DeleteQueryBuilder.php @@ -4,6 +4,7 @@ use Tempest\Database\Builder\ModelInspector; use Tempest\Database\OnDatabase; +use Tempest\Database\PrimaryKey; use Tempest\Database\Query; use Tempest\Database\QueryStatements\DeleteStatement; use Tempest\Support\Arr\ImmutableArray; @@ -118,7 +119,7 @@ public function build(mixed ...$bindings): Query if ($this->model->isObjectModel() && is_object($this->model->instance) && $this->model->hasPrimaryKey()) { $primaryKeyValue = $this->model->getPrimaryKeyValue(); - if ($primaryKeyValue !== null) { + if ($primaryKeyValue instanceof PrimaryKey) { $this->where($this->model->getPrimaryKey(), $primaryKeyValue->value); } } diff --git a/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php b/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php index 30f94d730..a6927bef0 100644 --- a/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php +++ b/packages/database/src/Builder/QueryBuilders/HasConvenientWhereMethods.php @@ -5,6 +5,7 @@ use ArrayAccess; use BackedEnum; use Countable; +use InvalidArgumentException; use Tempest\Database\Builder\WhereOperator; use Tempest\DateTime\DateTime; use Tempest\DateTime\DateTimeInterface; @@ -42,7 +43,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat } if (! is_array($value)) { - throw new \InvalidArgumentException("{$operator->value} operator requires an array of values"); + throw new InvalidArgumentException("{$operator->value} operator requires an array of values"); } $value = array_map(fn (mixed $value) => match (true) { @@ -60,7 +61,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat case WhereOperator::BETWEEN: case WhereOperator::NOT_BETWEEN: if (! is_array($value) || count($value) !== 2) { - throw new \InvalidArgumentException("{$operator->value} operator requires an array with exactly 2 values"); + throw new InvalidArgumentException("{$operator->value} operator requires an array with exactly 2 values"); } $sql .= " {$operator->value} ? AND ?"; @@ -75,7 +76,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat default: if ($operator->requiresValue() && $value === null) { - throw new \InvalidArgumentException("{$operator->value} operator requires a value"); + throw new InvalidArgumentException("{$operator->value} operator requires a value"); } if ($operator->requiresValue()) { @@ -84,6 +85,7 @@ protected function buildCondition(string $fieldDefinition, WhereOperator $operat } else { $sql .= " {$operator->value}"; } + break; } @@ -99,11 +101,7 @@ private function looksLikeWhereRawStatement(string $statement, array $bindings): return false; } - if (! Str\contains($statement, [' ', ...array_map(fn (WhereOperator $op) => $op->value, WhereOperator::cases())])) { - return false; - } - - return true; + return Str\contains($statement, [' ', ...array_map(fn (WhereOperator $op) => $op->value, WhereOperator::cases())]); } /** diff --git a/packages/database/src/Builder/QueryBuilders/InsertQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/InsertQueryBuilder.php index cfd009c08..098da200b 100644 --- a/packages/database/src/Builder/QueryBuilders/InsertQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/InsertQueryBuilder.php @@ -3,12 +3,14 @@ namespace Tempest\Database\Builder\QueryBuilders; use Closure; +use Tempest\Database\BelongsTo; use Tempest\Database\Builder\ModelInspector; use Tempest\Database\Database; use Tempest\Database\DatabaseContext; use Tempest\Database\Exceptions\HasManyRelationCouldNotBeInsterted; use Tempest\Database\Exceptions\HasOneRelationCouldNotBeInserted; use Tempest\Database\Exceptions\ModelDidNotHavePrimaryColumn; +use Tempest\Database\HasMany; use Tempest\Database\HasOne; use Tempest\Database\OnDatabase; use Tempest\Database\PrimaryKey; @@ -34,7 +36,9 @@ */ final class InsertQueryBuilder implements BuildsQuery { - use HasConditions, OnDatabase, TransformsQueryBuilder; + use HasConditions; + use OnDatabase; + use TransformsQueryBuilder; private InsertStatement $insert; @@ -71,7 +75,7 @@ public function execute(mixed ...$bindings): ?PrimaryKey { $id = $this->build()->execute(...$bindings); - if ($id === null) { + if (! $id instanceof PrimaryKey) { return null; } @@ -209,7 +213,7 @@ private function addHasManyRelationCallback(string $relationName, array $relatio { $hasMany = $this->model->getHasMany($relationName); - if ($hasMany === null) { + if (! $hasMany instanceof HasMany) { return; } @@ -243,7 +247,7 @@ private function addHasOneRelationCallback(string $relationName, object|iterable { $hasOne = $this->model->getHasOne($relationName); - if ($hasOne === null) { + if (! $hasOne instanceof HasOne) { return; } @@ -346,7 +350,7 @@ private function handleHasManyRelation(string $key, mixed $relations): bool { $hasMany = $this->model->getHasMany($key); - if ($hasMany === null) { + if (! $hasMany instanceof HasMany) { return false; } @@ -363,7 +367,7 @@ private function handleHasOneRelation(string $key, mixed $relation): bool { $hasOne = $this->model->getHasOne($key); - if ($hasOne === null) { + if (! $hasOne instanceof HasOne) { return false; } @@ -380,7 +384,7 @@ private function handleBelongsToRelation(string $key, mixed $value, array &$entr { $belongsTo = $this->model->getBelongsTo($key); - if ($belongsTo === null || ! is_object($value) && ! is_array($value)) { + if (! $belongsTo instanceof BelongsTo || ! is_object($value) && ! is_array($value)) { return false; } @@ -424,7 +428,7 @@ private function resolveObjectData(object $model): array $value = $property->getValue($model); - if ($definition->getHasMany($propertyName)) { + if ($definition->getHasMany($propertyName) instanceof HasMany) { if (is_iterable($value)) { $this->addHasManyRelationCallback($propertyName, $value); } @@ -432,7 +436,7 @@ private function resolveObjectData(object $model): array continue; } - if ($definition->getHasOne($propertyName)) { + if ($definition->getHasOne($propertyName) instanceof HasOne) { if (is_object($value) || is_array($value)) { $this->addHasOneRelationCallback($propertyName, $value); } @@ -468,7 +472,7 @@ private function resolveRelationProperty(ModelInspector $definition, PropertyRef } $belongsTo = $definition->getBelongsTo($property->getName()); - $column = $belongsTo + $column = $belongsTo instanceof BelongsTo ? $belongsTo->getOwnerFieldName() : $property->getName() . '_' . $primaryKey; diff --git a/packages/database/src/Builder/QueryBuilders/QueryBuilder.php b/packages/database/src/Builder/QueryBuilders/QueryBuilder.php index d725161a4..8f99aa2bd 100644 --- a/packages/database/src/Builder/QueryBuilders/QueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/QueryBuilder.php @@ -6,6 +6,7 @@ use Tempest\Database\OnDatabase; use Tempest\Database\PrimaryKey; use Tempest\Mapper\SerializerFactory; +use Tempest\Reflection\PropertyReflector; use function Tempest\Container\get; use function Tempest\Database\inspect; @@ -200,7 +201,8 @@ public function get(string|int|PrimaryKey $id, array $relations = []): ?object default => new PrimaryKey($id), }; - return $this->select() + return $this + ->select() ->with(...$relations) ->get($id); } @@ -212,7 +214,8 @@ public function get(string|int|PrimaryKey $id, array $relations = []): ?object */ public function all(array $relations = []): array { - return $this->select() + return $this + ->select() ->with(...$relations) ->all(); } @@ -259,7 +262,7 @@ public function create(mixed ...$params): object $inspector = inspect($this->model); $primaryKeyProperty = $inspector->getPrimaryKeyProperty(); - if ($id !== null && $primaryKeyProperty !== null) { + if ($id instanceof PrimaryKey && $primaryKeyProperty instanceof PropertyReflector) { $primaryKeyName = $primaryKeyProperty->getName(); if (! $inspector->hasUuidPrimaryKey() || $model->{$primaryKeyName} === null) { diff --git a/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php index e05fc333e..bc7115014 100644 --- a/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php @@ -104,7 +104,7 @@ public function first(mixed ...$bindings): mixed return null; } - return $result[array_key_first($result)]; + return array_first($result); } /** @@ -203,7 +203,8 @@ public function chunk(Closure $closure, int $amountPerChunk = 200): void $offset = 0; do { - $data = $this->clone() + $data = $this + ->clone() ->limit($amountPerChunk) ->offset($offset) ->all(); diff --git a/packages/database/src/Builder/QueryBuilders/SupportsJoins.php b/packages/database/src/Builder/QueryBuilders/SupportsJoins.php index 7e6dd4182..28ef8fe10 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsJoins.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsJoins.php @@ -14,7 +14,5 @@ interface SupportsJoins * * @return array */ - public array $joins { - get; - } + public array $joins { get; } } diff --git a/packages/database/src/Builder/QueryBuilders/SupportsRelations.php b/packages/database/src/Builder/QueryBuilders/SupportsRelations.php index 17bccd029..366aedd93 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsRelations.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsRelations.php @@ -14,9 +14,7 @@ interface SupportsRelations * * @return array */ - public array $relations { - get; - } + public array $relations { get; } /** * Gets all resolved relations with their join statements. diff --git a/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php b/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php index ce48e8dbe..90eb7158e 100644 --- a/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php +++ b/packages/database/src/Builder/QueryBuilders/SupportsWhereStatements.php @@ -17,9 +17,7 @@ interface SupportsWhereStatements * * @var ImmutableArray */ - public ImmutableArray $wheres { - get; - } + public ImmutableArray $wheres { get; } /** * Adds a WHERE condition to the query. diff --git a/packages/database/src/Builder/QueryBuilders/UpdateQueryBuilder.php b/packages/database/src/Builder/QueryBuilders/UpdateQueryBuilder.php index ec4f2d8de..cc043ed21 100644 --- a/packages/database/src/Builder/QueryBuilders/UpdateQueryBuilder.php +++ b/packages/database/src/Builder/QueryBuilders/UpdateQueryBuilder.php @@ -2,6 +2,7 @@ namespace Tempest\Database\Builder\QueryBuilders; +use Tempest\Database\BelongsTo; use Tempest\Database\Builder\ModelInspector; use Tempest\Database\Builder\WhereOperator; use Tempest\Database\Database; @@ -10,6 +11,8 @@ use Tempest\Database\Exceptions\HasManyRelationCouldNotBeUpdated; use Tempest\Database\Exceptions\HasOneRelationCouldNotBeUpdated; use Tempest\Database\Exceptions\ModelDidNotHavePrimaryColumn; +use Tempest\Database\HasMany; +use Tempest\Database\HasOne; use Tempest\Database\OnDatabase; use Tempest\Database\PrimaryKey; use Tempest\Database\Query; @@ -17,6 +20,7 @@ use Tempest\Database\QueryStatements\WhereStatement; use Tempest\Database\Virtual; use Tempest\Intl; +use Tempest\Mapper\Serializer; use Tempest\Mapper\SerializerFactory; use Tempest\Reflection\ClassReflector; use Tempest\Reflection\PropertyReflector; @@ -112,7 +116,7 @@ public function execute(mixed ...$bindings): ?PrimaryKey } // Execute after callbacks for relation updates - if ($this->model->hasPrimaryKey() && $this->after !== [] && $this->primaryKeyForRelations !== null) { + if ($this->model->hasPrimaryKey() && $this->after !== [] && $this->primaryKeyForRelations instanceof PrimaryKey) { foreach ($this->after as $after) { $query = $after($this->primaryKeyForRelations); @@ -239,7 +243,7 @@ private function resolveRelationValue(PropertyReflector $property, string $colum { $belongsTo = $this->model->getBelongsTo($column); - if ($belongsTo) { + if ($belongsTo instanceof BelongsTo) { $column = $belongsTo->getOwnerFieldName(); $relationModel = inspect($property->getType()->asClass()); $this->ensureModelHasPrimaryKey($relationModel, 'BelongsTo'); @@ -271,7 +275,7 @@ private function serializeValue(PropertyReflector $property, mixed $value): mixe ->in($this->context) ->forProperty($property); - if ($value !== null && $serializer !== null) { + if ($value !== null && $serializer instanceof Serializer) { return $serializer->serialize($value); } @@ -289,7 +293,7 @@ private function handleHasManyRelation(string $key, mixed $relations): bool { $hasMany = $this->model->getHasMany($key); - if ($hasMany === null) { + if (! $hasMany instanceof HasMany) { return false; } @@ -306,7 +310,7 @@ private function handleHasOneRelation(string $key, mixed $relation): bool { $hasOne = $this->model->getHasOne($key); - if ($hasOne === null) { + if (! $hasOne instanceof HasOne) { return false; } @@ -323,7 +327,7 @@ private function addHasManyRelationCallback(string $relationName, iterable $rela { $hasMany = $this->model->getHasMany($relationName); - if ($hasMany === null) { + if (! $hasMany instanceof HasMany) { return; } @@ -357,7 +361,7 @@ private function addHasOneRelationCallback(string $relationName, object|array $r { $hasOne = $this->model->getHasOne($relationName); - if ($hasOne === null) { + if (! $hasOne instanceof HasOne) { return; } @@ -544,10 +548,13 @@ public function whereField(string $field, mixed $value, string|WhereOperator $op { $operator = WhereOperator::fromOperator($operator); - if ($this->model->hasPrimaryKey() && $field === $this->model->getPrimaryKey() && $this->hasRelationUpdates()) { - if ($operator === WhereOperator::EQUALS && (is_string($value) || is_int($value) || $value instanceof PrimaryKey)) { - $this->primaryKeyForRelations = new PrimaryKey($value); - } + if ( + $this->model->hasPrimaryKey() && $field === $this->model->getPrimaryKey() && $this->hasRelationUpdates() && ( + $operator === WhereOperator::EQUALS + && (is_string($value) || is_int($value) || $value instanceof PrimaryKey) + ) + ) { + $this->primaryKeyForRelations = new PrimaryKey($value); } $fieldDefinition = $this->model->getFieldDefinition($field); @@ -602,7 +609,7 @@ private function validateRelationUpdateConstraints(): void throw CouldNotUpdateRelation::requiresPrimaryKey($this->model); } - if ($this->primaryKeyForRelations === null) { + if (! $this->primaryKeyForRelations instanceof PrimaryKey) { throw CouldNotUpdateRelation::requiresSingleRecord($this->model); } } @@ -613,7 +620,7 @@ private function setWhereForObjectModel(): void return; } - if ($primaryKeyValue = $this->model->getPrimaryKeyValue()) { + if (($primaryKeyValue = $this->model->getPrimaryKeyValue()) instanceof PrimaryKey) { $this->whereField($this->model->getPrimaryKey(), $primaryKeyValue->value); } } diff --git a/packages/database/src/Casters/DataTransferObjectCaster.php b/packages/database/src/Casters/DataTransferObjectCaster.php index 4f9d6dfc5..a18bb67c9 100644 --- a/packages/database/src/Casters/DataTransferObjectCaster.php +++ b/packages/database/src/Casters/DataTransferObjectCaster.php @@ -34,13 +34,7 @@ public static function accepts(PropertyReflector|TypeReflector $type): bool : $type; if ($type->isUnion()) { - foreach ($type->split() as $memberType) { - if (static::accepts($memberType)) { - return true; - } - } - - return false; + return array_any($type->split(), fn ($memberType) => self::accepts($memberType)); } return $type->isClass() && $type->asClass()->getAttribute(SerializeAs::class) !== null; @@ -77,7 +71,7 @@ private function deserialize(mixed $input): mixed } if (is_array($input)) { - return array_map(fn (mixed $value) => $this->deserialize($value), $input); + return array_map($this->deserialize(...), $input); } return $input; diff --git a/packages/database/src/Commands/MakeMigrationCommand.php b/packages/database/src/Commands/MakeMigrationCommand.php index 7e6c09507..8a7cfa19d 100644 --- a/packages/database/src/Commands/MakeMigrationCommand.php +++ b/packages/database/src/Commands/MakeMigrationCommand.php @@ -9,6 +9,7 @@ use Tempest\Core\PublishesFiles; use Tempest\Database\Config\DatabaseConfig; use Tempest\Database\Enums\MigrationType; +use Tempest\Database\Migrations\TableGuess; use Tempest\Database\Migrations\TableGuesser; use Tempest\Database\Stubs\ObjectAlterMigrationStub; use Tempest\Database\Stubs\ObjectMigrationStub; @@ -81,10 +82,10 @@ public function __invoke( ); $alter ??= $yes - ? $guess !== null && ! $guess->isCreate + ? $guess instanceof TableGuess && ! $guess->isCreate : $this->confirm( question: 'Is this an alteration?', - default: $guess !== null && ! $guess->isCreate, + default: $guess instanceof TableGuess && ! $guess->isCreate, ); $table = $this->resolveTableName($table); diff --git a/packages/database/src/Config/DatabaseConfig.php b/packages/database/src/Config/DatabaseConfig.php index 581a5b878..ced0c3d8c 100644 --- a/packages/database/src/Config/DatabaseConfig.php +++ b/packages/database/src/Config/DatabaseConfig.php @@ -13,56 +13,40 @@ interface DatabaseConfig extends HasTag /** * PDO data source name connection string. */ - public string $dsn { - get; - } + public string $dsn { get; } /** * The naming strategy for database tables and columns. */ - public NamingStrategy $namingStrategy { - get; - } + public NamingStrategy $namingStrategy { get; } /** * The naming strategy for migration file prefixes. */ - public MigrationNamingStrategy $migrationNamingStrategy { - get; - } + public MigrationNamingStrategy $migrationNamingStrategy { get; } /** * The database dialect (MySQL, PostgreSQL, SQLite). */ - public DatabaseDialect $dialect { - get; - } + public DatabaseDialect $dialect { get; } /** * The database username for authentication. */ - public ?string $username { - get; - } + public ?string $username { get; } /** * The database password for authentication. */ - public ?string $password { - get; - } + public ?string $password { get; } /** * Whether to use persistent database connections. */ - public bool $usePersistentConnection { - get; - } + public bool $usePersistentConnection { get; } /** * PDO connection options built from configuration properties. */ - public array $options { - get; - } + public array $options { get; } } diff --git a/packages/database/src/Connection/PDOConnection.php b/packages/database/src/Connection/PDOConnection.php index 1b3e6ae98..16a5cd9e7 100644 --- a/packages/database/src/Connection/PDOConnection.php +++ b/packages/database/src/Connection/PDOConnection.php @@ -20,7 +20,7 @@ public function __construct( public function beginTransaction(): bool { - if ($this->pdo === null) { + if (! $this->pdo instanceof PDO) { throw new ConnectionClosed(); } @@ -29,7 +29,7 @@ public function beginTransaction(): bool public function commit(): bool { - if ($this->pdo === null) { + if (! $this->pdo instanceof PDO) { throw new ConnectionClosed(); } @@ -38,7 +38,7 @@ public function commit(): bool public function rollback(): bool { - if ($this->pdo === null) { + if (! $this->pdo instanceof PDO) { throw new ConnectionClosed(); } @@ -47,7 +47,7 @@ public function rollback(): bool public function lastInsertId(): false|string { - if ($this->pdo === null) { + if (! $this->pdo instanceof PDO) { throw new ConnectionClosed(); } @@ -56,7 +56,7 @@ public function lastInsertId(): false|string public function prepare(string $sql): PDOStatement { - if ($this->pdo === null) { + if (! $this->pdo instanceof PDO) { throw new ConnectionClosed(); } @@ -94,7 +94,7 @@ public function close(): void public function connect(): void { - if ($this->pdo !== null) { + if ($this->pdo instanceof PDO) { return; } diff --git a/packages/database/src/Database.php b/packages/database/src/Database.php index 6f12cf132..966e492de 100644 --- a/packages/database/src/Database.php +++ b/packages/database/src/Database.php @@ -17,16 +17,12 @@ interface Database /** * The dialect of this database. */ - public DatabaseDialect $dialect { - get; - } + public DatabaseDialect $dialect { get; } /** * The tag associated with this database, if any. */ - public null|string|UnitEnum $tag { - get; - } + public null|string|UnitEnum $tag { get; } /** * Executes the given query. diff --git a/packages/database/src/DatabaseInsightsProvider.php b/packages/database/src/DatabaseInsightsProvider.php index a3afaba7e..59d37b525 100644 --- a/packages/database/src/DatabaseInsightsProvider.php +++ b/packages/database/src/DatabaseInsightsProvider.php @@ -11,6 +11,7 @@ use Tempest\Database\Config\SQLiteConfig; use Tempest\Support\Arr; use Tempest\Support\Regex; +use Throwable; use function Tempest\Support\Path\normalize; use function Tempest\Support\Path\to_relative_path; @@ -35,7 +36,7 @@ public function getInsights(): array private function getDatabaseEngine(): string { - return match (get_class($this->databaseConfig)) { + return match ($this->databaseConfig::class) { SQLiteConfig::class => 'SQLite', PostgresConfig::class => 'PostgreSQL', MysqlConfig::class => 'MySQL', @@ -46,7 +47,7 @@ private function getDatabaseEngine(): string private function getDatabaseVersion(): Insight { // TODO: support displaying multiple databases, after cache PR - [$versionQuery, $regex] = match (get_class($this->databaseConfig)) { + [$versionQuery, $regex] = match ($this->databaseConfig::class) { SQLiteConfig::class => ['SELECT sqlite_version() AS version;', '/(?.*)/'], PostgresConfig::class => ['SELECT version() AS version;', "/PostgreSQL (?\S+)/"], MysqlConfig::class => ['SELECT version() AS version;', '/^(?\d+\.\d+\.\d+)(?:-\w+)?/'], @@ -63,7 +64,7 @@ private function getDatabaseVersion(): Insight pattern: $regex, match: 'version', )); - } catch (\Throwable $e) { + } catch (Throwable) { return new Insight('Unavailable', InsightType::ERROR); } } diff --git a/packages/database/src/Eager.php b/packages/database/src/Eager.php index cd3767dc6..9efd7e34e 100644 --- a/packages/database/src/Eager.php +++ b/packages/database/src/Eager.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Eager -{ -} +final readonly class Eager {} diff --git a/packages/database/src/Exceptions/DatabaseException.php b/packages/database/src/Exceptions/DatabaseException.php index f7ae18e52..c9e7b4a99 100644 --- a/packages/database/src/Exceptions/DatabaseException.php +++ b/packages/database/src/Exceptions/DatabaseException.php @@ -4,6 +4,4 @@ namespace Tempest\Database\Exceptions; -interface DatabaseException -{ -} +interface DatabaseException {} diff --git a/packages/database/src/Exceptions/ModelDidNotHavePrimaryColumn.php b/packages/database/src/Exceptions/ModelDidNotHavePrimaryColumn.php index e60b2890a..e311557f6 100644 --- a/packages/database/src/Exceptions/ModelDidNotHavePrimaryColumn.php +++ b/packages/database/src/Exceptions/ModelDidNotHavePrimaryColumn.php @@ -11,7 +11,7 @@ final class ModelDidNotHavePrimaryColumn extends Exception implements DatabaseEx public static function neededForMethod(string|object $model, string $method): self { if (is_object($model)) { - $model = get_class($model); + $model = $model::class; } return new self("`{$model}` does not have a primary column defined, which is required for the `{$method}` method."); @@ -20,7 +20,7 @@ public static function neededForMethod(string|object $model, string $method): se public static function neededForRelation(string|object $model, string $relationType): self { if (is_object($model)) { - $model = get_class($model); + $model = $model::class; } return new self("`{$model}` does not have a primary column defined, which is required for `{$relationType}` relationships."); diff --git a/packages/database/src/Exceptions/QueryWasInvalid.php b/packages/database/src/Exceptions/QueryWasInvalid.php index 5afe13807..3da5a1784 100644 --- a/packages/database/src/Exceptions/QueryWasInvalid.php +++ b/packages/database/src/Exceptions/QueryWasInvalid.php @@ -11,21 +11,17 @@ final class QueryWasInvalid extends Exception implements ProvidesContext { - public readonly PDOException $pdoException; - public function __construct( private(set) Query $query, private(set) array $bindings, - PDOException $previous, + public readonly PDOException $pdoException, ) { - $this->pdoException = $previous; - - $message = $previous->getMessage(); + $message = $this->pdoException->getMessage(); $message .= PHP_EOL . PHP_EOL . $query->toRawSql(); parent::__construct( message: $message, - previous: $previous, + previous: $this->pdoException, ); } diff --git a/packages/database/src/GenericDatabase.php b/packages/database/src/GenericDatabase.php index 06d018402..60390ec57 100644 --- a/packages/database/src/GenericDatabase.php +++ b/packages/database/src/GenericDatabase.php @@ -13,6 +13,7 @@ use Tempest\Database\Connection\PDOConnection; use Tempest\Database\Exceptions\QueryWasInvalid; use Tempest\Database\Transactions\TransactionManager; +use Tempest\Mapper\Serializer; use Tempest\Mapper\SerializerFactory; use Tempest\Support\Str\ImmutableString; use Throwable; @@ -23,6 +24,7 @@ final class GenericDatabase implements Database { private ?PDOStatement $lastStatement = null; + private ?Query $lastQuery = null; public DatabaseDialect $dialect { @@ -152,7 +154,7 @@ private function resolveBindings(Query $query): array $value = $value->execute(); } elseif (is_string($value) || is_numeric($value)) { // Keep value as is - } elseif ($serializer = $serializerFactory->forValue($value)) { + } elseif (($serializer = $serializerFactory->forValue($value)) instanceof Serializer) { $value = $serializer->serialize($value); } diff --git a/packages/database/src/HasLeadingStatements.php b/packages/database/src/HasLeadingStatements.php index d6f126fe1..42946c0ae 100644 --- a/packages/database/src/HasLeadingStatements.php +++ b/packages/database/src/HasLeadingStatements.php @@ -4,7 +4,5 @@ interface HasLeadingStatements { - public array $leadingStatements { - get; - } + public array $leadingStatements { get; } } diff --git a/packages/database/src/HasTrailingStatements.php b/packages/database/src/HasTrailingStatements.php index 081220705..b91b4ce66 100644 --- a/packages/database/src/HasTrailingStatements.php +++ b/packages/database/src/HasTrailingStatements.php @@ -4,7 +4,5 @@ interface HasTrailingStatements { - public array $trailingStatements { - get; - } + public array $trailingStatements { get; } } diff --git a/packages/database/src/Lazy.php b/packages/database/src/Lazy.php index b112d9e03..a43fcc67f 100644 --- a/packages/database/src/Lazy.php +++ b/packages/database/src/Lazy.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Lazy -{ -} +final readonly class Lazy {} diff --git a/packages/database/src/Mappers/SelectModelMapper.php b/packages/database/src/Mappers/SelectModelMapper.php index 12d8477d9..910a23d28 100644 --- a/packages/database/src/Mappers/SelectModelMapper.php +++ b/packages/database/src/Mappers/SelectModelMapper.php @@ -155,7 +155,7 @@ public function normalizeRow(ModelInspector $model, array $row, MutableArray $da $currentModel = inspect($relation); } - if ($key) { + if ($key !== '' && $key !== '0') { $data->set($key, $value); } } diff --git a/packages/database/src/MigratesDown.php b/packages/database/src/MigratesDown.php index a18004d87..a3414f14d 100644 --- a/packages/database/src/MigratesDown.php +++ b/packages/database/src/MigratesDown.php @@ -6,9 +6,7 @@ interface MigratesDown { - public string $name { - get; - } + public string $name { get; } public function down(): QueryStatement; } diff --git a/packages/database/src/MigratesUp.php b/packages/database/src/MigratesUp.php index 9a436fb8b..c25a08409 100644 --- a/packages/database/src/MigratesUp.php +++ b/packages/database/src/MigratesUp.php @@ -6,9 +6,7 @@ interface MigratesUp { - public string $name { - get; - } + public string $name { get; } public function up(): QueryStatement; } diff --git a/packages/database/src/MigrationDiscovery.php b/packages/database/src/MigrationDiscovery.php index 205a29fd2..c8af947bc 100644 --- a/packages/database/src/MigrationDiscovery.php +++ b/packages/database/src/MigrationDiscovery.php @@ -49,7 +49,11 @@ public function discoverPath(DiscoveryLocation $location, string $path): void $contents = explode(';', Filesystem\read_file($path)); foreach ($contents as $i => $content) { - if (! $content) { + if ($content === '') { + continue; + } + + if ($content === '0') { continue; } diff --git a/packages/database/src/Migrations/MigrationException.php b/packages/database/src/Migrations/MigrationException.php index c9e7cb307..96d065eca 100644 --- a/packages/database/src/Migrations/MigrationException.php +++ b/packages/database/src/Migrations/MigrationException.php @@ -4,6 +4,4 @@ namespace Tempest\Database\Migrations; -interface MigrationException -{ -} +interface MigrationException {} diff --git a/packages/database/src/Migrations/MigrationManager.php b/packages/database/src/Migrations/MigrationManager.php index bfcabca2a..3f8c31ec2 100644 --- a/packages/database/src/Migrations/MigrationManager.php +++ b/packages/database/src/Migrations/MigrationManager.php @@ -211,8 +211,11 @@ public function executeUp(MigratesUp $migration): void try { foreach ($statements as $statement) { $sql = $statement->compile($this->dialect); + if (trim($sql) === '') { + continue; + } - if (! trim($sql)) { + if (trim($sql) === '0') { continue; } @@ -292,7 +295,7 @@ private function getTableDefinitions(): array fn (array $item) => match ($this->dialect) { DatabaseDialect::SQLITE => new TableMigrationDefinition($item['name']), DatabaseDialect::POSTGRESQL => new TableMigrationDefinition($item['table_name']), - DatabaseDialect::MYSQL => new TableMigrationDefinition(array_values($item)[0]), + DatabaseDialect::MYSQL => new TableMigrationDefinition(array_first($item)), }, new ShowTablesStatement()->fetch($this->dialect), ); @@ -315,7 +318,7 @@ private function getMigrationHash(MigratesUp|MigratesDown $migration): string private function getMinifiedSqlFromStatement(?QueryStatement $statement): string { - if ($statement === null) { + if (! $statement instanceof QueryStatement) { return ''; } diff --git a/packages/database/src/Migrations/TableGuesser.php b/packages/database/src/Migrations/TableGuesser.php index 841366102..0a194a460 100644 --- a/packages/database/src/Migrations/TableGuesser.php +++ b/packages/database/src/Migrations/TableGuesser.php @@ -15,7 +15,7 @@ public static function guess(string $migration): ?TableGuess if (Str\starts_with($migration, 'create_')) { $table = Str\strip_end(Str\after_first($migration, 'create_'), '_table'); - return ! Str\is_empty($table) ? new TableGuess($table, isCreate: true) : null; + return Str\is_empty($table) ? null : new TableGuess($table, isCreate: true); } if (! Str\contains($migration, self::PREPOSITIONS)) { @@ -24,6 +24,6 @@ public static function guess(string $migration): ?TableGuess $table = Str\strip_end(Str\after_last($migration, self::PREPOSITIONS), '_table'); - return ! Str\is_empty($table) ? new TableGuess($table, isCreate: false) : null; + return Str\is_empty($table) ? null : new TableGuess($table, isCreate: false); } } diff --git a/packages/database/src/QueryStatements/AlterTableStatement.php b/packages/database/src/QueryStatements/AlterTableStatement.php index 1ba8b7421..d1d7530c0 100644 --- a/packages/database/src/QueryStatements/AlterTableStatement.php +++ b/packages/database/src/QueryStatements/AlterTableStatement.php @@ -90,7 +90,7 @@ public function modify(QueryStatement $column): self public function compile(DatabaseDialect $dialect): string { if ($this->statements !== []) { - $alterTable = sprintf( + return sprintf( 'ALTER TABLE %s %s;', new TableDefinition($this->tableName), arr($this->statements) @@ -100,10 +100,8 @@ public function compile(DatabaseDialect $dialect): string ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), ); - } else { - $alterTable = ''; } - return $alterTable; + return ''; } } diff --git a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php index 9640b4e8e..bf359c437 100644 --- a/packages/database/src/QueryStatements/CreateEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/CreateEnumTypeStatement.php @@ -30,8 +30,8 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', DatabaseDialect::POSTGRESQL => sprintf( <<<'PSQL' - CREATE TYPE "%s" AS ENUM (%s); - PSQL, + CREATE TYPE "%s" AS ENUM (%s); + PSQL, str($this->enumClass)->replace('\\\\', '_'), $cases->implode(', '), ), diff --git a/packages/database/src/QueryStatements/DatetimeStatement.php b/packages/database/src/QueryStatements/DatetimeStatement.php index 6b2dea5fa..c4aa33997 100644 --- a/packages/database/src/QueryStatements/DatetimeStatement.php +++ b/packages/database/src/QueryStatements/DatetimeStatement.php @@ -19,7 +19,7 @@ public function __construct( public function compile(DatabaseDialect $dialect): string { - if ($this->default !== null && $this->current === true) { + if ($this->default !== null && $this->current) { throw new InvalidArgumentException("Cannot set both `default` and `current` for datetime column `{$this->name}`."); } diff --git a/packages/database/src/QueryStatements/DropEnumTypeStatement.php b/packages/database/src/QueryStatements/DropEnumTypeStatement.php index 35fddb0da..16396dcf7 100644 --- a/packages/database/src/QueryStatements/DropEnumTypeStatement.php +++ b/packages/database/src/QueryStatements/DropEnumTypeStatement.php @@ -24,8 +24,8 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL, DatabaseDialect::SQLITE => '', DatabaseDialect::POSTGRESQL => sprintf( <<<'PSQL' - DROP TYPE IF EXISTS "%s"; - PSQL, + DROP TYPE IF EXISTS "%s"; + PSQL, str($this->enumClass)->replace('\\\\', '_'), ), }; diff --git a/packages/database/src/QueryStatements/EnumStatement.php b/packages/database/src/QueryStatements/EnumStatement.php index 29d05bcd8..26ba7f5eb 100644 --- a/packages/database/src/QueryStatements/EnumStatement.php +++ b/packages/database/src/QueryStatements/EnumStatement.php @@ -29,7 +29,7 @@ public function compile(DatabaseDialect $dialect): string ->map(fn (string $value) => str_replace('\\', '\\\\', $value)) ->map(fn (string $value) => "'{$value}'"); - if ($this->default !== null) { + if ($this->default instanceof UnitEnum) { $defaultValue = $this->default instanceof BackedEnum ? $this->default->value : $this->default->name; } else { $defaultValue = null; diff --git a/packages/database/src/QueryStatements/FieldStatement.php b/packages/database/src/QueryStatements/FieldStatement.php index 9492b1397..26dd22cfd 100644 --- a/packages/database/src/QueryStatements/FieldStatement.php +++ b/packages/database/src/QueryStatements/FieldStatement.php @@ -11,6 +11,7 @@ final class FieldStatement implements QueryStatement { private null|bool|string $alias = null; + private ?string $aliasPrefix = null; public function __construct( diff --git a/packages/database/src/QueryStatements/HasWhereStatements.php b/packages/database/src/QueryStatements/HasWhereStatements.php index 91869b104..def527731 100644 --- a/packages/database/src/QueryStatements/HasWhereStatements.php +++ b/packages/database/src/QueryStatements/HasWhereStatements.php @@ -7,7 +7,5 @@ interface HasWhereStatements { /** @var ImmutableArray */ - public ImmutableArray $where { - get; - } + public ImmutableArray $where { get; } } diff --git a/packages/database/src/QueryStatements/JoinStatement.php b/packages/database/src/QueryStatements/JoinStatement.php index 23ab04d0b..a05d9f7f9 100644 --- a/packages/database/src/QueryStatements/JoinStatement.php +++ b/packages/database/src/QueryStatements/JoinStatement.php @@ -18,7 +18,7 @@ public function compile(DatabaseDialect $dialect): string $statement = $this->statement; if (! str($statement)->lower()->startsWith(['join', 'inner join', 'left join', 'right join', 'full join', 'full outer join', 'self join'])) { - $statement = sprintf('INNER JOIN %s', $statement); + return sprintf('INNER JOIN %s', $statement); } return $statement; diff --git a/packages/database/src/QueryStatements/ShowTablesStatement.php b/packages/database/src/QueryStatements/ShowTablesStatement.php index 23d79dd54..c29826f74 100644 --- a/packages/database/src/QueryStatements/ShowTablesStatement.php +++ b/packages/database/src/QueryStatements/ShowTablesStatement.php @@ -23,11 +23,11 @@ public function compile(DatabaseDialect $dialect): string DatabaseDialect::MYSQL => "SHOW FULL TABLES WHERE table_type = 'BASE TABLE'", DatabaseDialect::SQLITE => "select type, name from sqlite_master where type = 'table' and name not like 'sqlite_%'", DatabaseDialect::POSTGRESQL => << $this->context ??= new RawSqlDatabaseContext($this->dialect); @@ -83,7 +85,7 @@ private function resolveBindingsForDisplay(): array continue; } - if ($serializer = $this->serializerFactory->in($this->context)->forValue($value)) { + if (($serializer = $this->serializerFactory->in($this->context)->forValue($value)) instanceof Serializer) { $bindings[$key] = $serializer->serialize($value); continue; } diff --git a/packages/database/src/Relation.php b/packages/database/src/Relation.php index c53139f0b..ea40f63a6 100644 --- a/packages/database/src/Relation.php +++ b/packages/database/src/Relation.php @@ -8,9 +8,7 @@ interface Relation extends PropertyAttribute { - public string $name { - get; - } + public string $name { get; } public function setParent(string $name): self; diff --git a/packages/database/src/Serializers/DataTransferObjectSerializer.php b/packages/database/src/Serializers/DataTransferObjectSerializer.php index a9aacf5f0..1b67d7756 100644 --- a/packages/database/src/Serializers/DataTransferObjectSerializer.php +++ b/packages/database/src/Serializers/DataTransferObjectSerializer.php @@ -34,13 +34,7 @@ public static function accepts(PropertyReflector|TypeReflector $type): bool : $type; if ($type->isUnion()) { - foreach ($type->split() as $memberType) { - if (static::accepts($memberType)) { - return true; - } - } - - return false; + return array_any($type->split(), fn ($memberType) => self::accepts($memberType)); } return $type->isClass() && $type->asClass()->getAttribute(SerializeAs::class) !== null; @@ -76,7 +70,7 @@ private function serializeWithType(mixed $input): mixed $data[$key] = $this->serializeWithType($value); } - $type = $this->mapperConfig->serializationMap[get_class($input)] ?? get_class($input); + $type = $this->mapperConfig->serializationMap[$input::class] ?? $input::class; return [ 'type' => $type, diff --git a/packages/database/src/Serializers/HashedSerializer.php b/packages/database/src/Serializers/HashedSerializer.php index b02ed9f07..7791a2902 100644 --- a/packages/database/src/Serializers/HashedSerializer.php +++ b/packages/database/src/Serializers/HashedSerializer.php @@ -2,6 +2,7 @@ namespace Tempest\Database\Serializers; +use Tempest\Cryptography\Password\Hash; use Tempest\Cryptography\Password\PasswordHasher; use Tempest\Mapper\Exceptions\ValueCouldNotBeSerialized; use Tempest\Mapper\Serializer; @@ -18,7 +19,7 @@ public function serialize(mixed $input): string throw new ValueCouldNotBeSerialized('string'); } - if (! $this->passwordHasher->analyze($input)) { + if (! $this->passwordHasher->analyze($input) instanceof Hash) { return $this->passwordHasher->hash($input); } diff --git a/packages/database/src/Testing/DatabaseTester.php b/packages/database/src/Testing/DatabaseTester.php index 93d80430f..4165258f7 100644 --- a/packages/database/src/Testing/DatabaseTester.php +++ b/packages/database/src/Testing/DatabaseTester.php @@ -46,7 +46,7 @@ public function migrate(string|object ...$migrationClasses): void { $migrationManager = $this->container->get(MigrationManager::class); - if (count($migrationClasses) === 0) { + if ($migrationClasses === []) { $migrationManager->up(); return; } diff --git a/packages/database/src/Uuid.php b/packages/database/src/Uuid.php index e93d7a923..2087295e0 100644 --- a/packages/database/src/Uuid.php +++ b/packages/database/src/Uuid.php @@ -24,6 +24,4 @@ * ``` */ #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Uuid -{ -} +final readonly class Uuid {} diff --git a/packages/database/src/Virtual.php b/packages/database/src/Virtual.php index 6d44eb7b6..1a314d41c 100644 --- a/packages/database/src/Virtual.php +++ b/packages/database/src/Virtual.php @@ -10,6 +10,4 @@ * Virtual properties are ignored by the database mapper. */ #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Virtual -{ -} +final readonly class Virtual {} diff --git a/packages/database/tests/Config/DatabaseConfigTest.php b/packages/database/tests/Config/DatabaseConfigTest.php index 02df0a722..ad7e54770 100644 --- a/packages/database/tests/Config/DatabaseConfigTest.php +++ b/packages/database/tests/Config/DatabaseConfigTest.php @@ -76,8 +76,8 @@ public static function provide_database_drivers_with_options(): Generator { yield 'mysql with SSL' => [ new MysqlConfig( - certificateAuthority: '/etc/ssl/certs/ca-certificates.crt', persistent: true, + certificateAuthority: '/etc/ssl/certs/ca-certificates.crt', ), [ PDO::ATTR_PERSISTENT => true, @@ -87,8 +87,8 @@ public static function provide_database_drivers_with_options(): Generator yield 'mysql with all SSL options' => [ new MysqlConfig( - certificateAuthority: '/etc/ssl/certs/ca-certificates.crt', verifyServerCertificate: false, + certificateAuthority: '/etc/ssl/certs/ca-certificates.crt', clientCertificate: '/path/to/cert.pem', clientKey: '/path/to/key.pem', ), diff --git a/packages/database/tests/GenericDatabaseTest.php b/packages/database/tests/GenericDatabaseTest.php index ead08fdd6..b22cfd63c 100644 --- a/packages/database/tests/GenericDatabaseTest.php +++ b/packages/database/tests/GenericDatabaseTest.php @@ -37,9 +37,7 @@ public function test_it_executes_transactions(): void new SerializerFactory(new GenericContainer()), ); - $result = $database->withinTransaction(function () { - return true; - }); + $result = $database->withinTransaction(fn () => true); $this->assertTrue($result); } diff --git a/packages/database/tests/Migrations/RunnableMigrationsTest.php b/packages/database/tests/Migrations/RunnableMigrationsTest.php index a15805d7f..f53ef5033 100644 --- a/packages/database/tests/Migrations/RunnableMigrationsTest.php +++ b/packages/database/tests/Migrations/RunnableMigrationsTest.php @@ -18,7 +18,7 @@ final class RunnableMigrationsTest extends TestCase #[Test] public function migration_ordering(array $migrationNames, array $expectedOrder): void { - $migrations = array_map(fn (string $name) => $this->createDatabaseMigration($name), $migrationNames); + $migrations = array_map($this->createDatabaseMigration(...), $migrationNames); $this->assertSame( expected: $expectedOrder, diff --git a/packages/database/tests/QueryStatements/AlterTableStatementTest.php b/packages/database/tests/QueryStatements/AlterTableStatementTest.php index 547877387..e06f14e6f 100644 --- a/packages/database/tests/QueryStatements/AlterTableStatementTest.php +++ b/packages/database/tests/QueryStatements/AlterTableStatementTest.php @@ -35,12 +35,12 @@ public function test_alter_for_only_indexes(DatabaseDialect $dialect): void #[TestWith([DatabaseDialect::SQLITE])] public function test_alter_add_column(DatabaseDialect $dialect): void { - $expected = 'ALTER TABLE `table` ADD `bar` VARCHAR(42) DEFAULT \'xx\' ;'; + $expected = "ALTER TABLE `table` ADD `bar` VARCHAR(42) DEFAULT 'xx' ;"; $statement = new AlterTableStatement('table') ->add(new VarcharStatement('bar', 42, true, 'xx')) ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -53,7 +53,7 @@ public function test_alter_add_belongs_to_mysql(DatabaseDialect $dialect): void ->add(new BelongsToStatement('table.foo', 'parent.bar')) ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -66,7 +66,7 @@ public function test_alter_add_belongs_to_postgresql(DatabaseDialect $dialect): ->add(new BelongsToStatement('table.foo', 'parent.bar')) ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -91,7 +91,7 @@ public function test_alter_table_drop_column(DatabaseDialect $dialect): void ->dropColumn('foo') ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -104,7 +104,7 @@ public function test_alter_table_drop_constraint(DatabaseDialect $dialect, strin ->dropConstraint('foo') ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -118,19 +118,19 @@ public function test_alter_table_drop_constraint_unsupported_dialects(DatabaseDi ->compile($dialect); } - #[TestWith([DatabaseDialect::MYSQL, 'ALTER TABLE `table` ADD `foo` VARCHAR(42) DEFAULT \'bar\' NOT NULL ;'])] + #[TestWith([DatabaseDialect::MYSQL, "ALTER TABLE `table` ADD `foo` VARCHAR(42) DEFAULT 'bar' NOT NULL ;"])] #[TestWith([ DatabaseDialect::POSTGRESQL, - 'ALTER TABLE `table` ADD `foo` VARCHAR(42) DEFAULT \'bar\' NOT NULL ;', + "ALTER TABLE `table` ADD `foo` VARCHAR(42) DEFAULT 'bar' NOT NULL ;", ])] - #[TestWith([DatabaseDialect::SQLITE, 'ALTER TABLE `table` ADD `foo` VARCHAR(42) DEFAULT \'bar\' NOT NULL ;'])] + #[TestWith([DatabaseDialect::SQLITE, "ALTER TABLE `table` ADD `foo` VARCHAR(42) DEFAULT 'bar' NOT NULL ;"])] public function test_alter_table_add_column(DatabaseDialect $dialect, string $expected): void { $statement = new AlterTableStatement('table') ->add(new VarcharStatement('foo', 42, false, 'bar')) ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -145,20 +145,20 @@ public function test_alter_table_rename_column(DatabaseDialect $dialect): void ->rename('foo', 'bar') ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } - #[TestWith([DatabaseDialect::MYSQL, 'ALTER TABLE `table` MODIFY COLUMN `foo` VARCHAR(42) DEFAULT \'bar\' NOT NULL ;'])] - #[TestWith([DatabaseDialect::POSTGRESQL, 'ALTER TABLE `table` ALTER COLUMN `foo` VARCHAR(42) DEFAULT \'bar\' NOT NULL ;'])] + #[TestWith([DatabaseDialect::MYSQL, "ALTER TABLE `table` MODIFY COLUMN `foo` VARCHAR(42) DEFAULT 'bar' NOT NULL ;"])] + #[TestWith([DatabaseDialect::POSTGRESQL, "ALTER TABLE `table` ALTER COLUMN `foo` VARCHAR(42) DEFAULT 'bar' NOT NULL ;"])] public function test_alter_table_modify_column(DatabaseDialect $dialect, string $expected): void { $statement = new AlterTableStatement('table') ->modify(new VarcharStatement('foo', 42, false, 'bar')) ->compile($dialect); - $normalized = self::removeDuplicateWhitespace($statement); + $normalized = $this->removeDuplicateWhitespace($statement); $this->assertEqualsIgnoringCase($expected, $normalized); } @@ -173,7 +173,7 @@ public function test_alter_table_modify_column_unsupported(DatabaseDialect $dial ->compile($dialect); } - private static function removeDuplicateWhitespace(string $string): string + private function removeDuplicateWhitespace(string $string): string { return trim(preg_replace('/(\n|\s)+/m', ' ', $string)); } diff --git a/packages/database/tests/QueryStatements/CreateTableStatementTest.php b/packages/database/tests/QueryStatements/CreateTableStatementTest.php index 9ae4eb9a8..1c93557d6 100644 --- a/packages/database/tests/QueryStatements/CreateTableStatementTest.php +++ b/packages/database/tests/QueryStatements/CreateTableStatementTest.php @@ -36,31 +36,31 @@ public static function provide_create_table_database_dialects(): iterable yield 'mysql' => [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, << [ DatabaseDialect::MYSQL, << [ DatabaseDialect::POSTGRESQL, << [ DatabaseDialect::SQLITE, <<', $queryBuilder); diff --git a/packages/datetime/src/DateTime.php b/packages/datetime/src/DateTime.php index 830da8487..bea06dfd0 100644 --- a/packages/datetime/src/DateTime.php +++ b/packages/datetime/src/DateTime.php @@ -5,7 +5,12 @@ namespace Tempest\DateTime; use DateTimeInterface as NativeDateTimeInterface; +use DateTimeZone; use IntlCalendar; +use Override; +use Tempest\DateTime\Exception\InvalidArgumentException; +use Tempest\DateTime\Exception\OverflowException; +use Tempest\DateTime\Exception\UnexpectedValueException; use Tempest\Intl\Locale; /** @@ -72,27 +77,27 @@ private function __construct( int $nanoseconds, ) { if ($nanoseconds < 0 || $nanoseconds >= NANOSECONDS_PER_SECOND) { - throw Exception\InvalidArgumentException::forNanoseconds($nanoseconds); + throw InvalidArgumentException::forNanoseconds($nanoseconds); } if ($seconds < 0 || $seconds >= 60) { - throw Exception\InvalidArgumentException::forSeconds($seconds); + throw InvalidArgumentException::forSeconds($seconds); } if ($minutes < 0 || $minutes >= 60) { - throw Exception\InvalidArgumentException::forMinutes($minutes); + throw InvalidArgumentException::forMinutes($minutes); } if ($hours < 0 || $hours >= 24) { - throw Exception\InvalidArgumentException::forHours($hours); + throw InvalidArgumentException::forHours($hours); } if ($month < 1 || $month > 12) { - throw Exception\InvalidArgumentException::forMonth($month); + throw InvalidArgumentException::forMonth($month); } if ($day < 1 || $day > 31 || $day > Month::from($month)->getDaysForYear($year)) { - throw Exception\InvalidArgumentException::forDay($day, $month, $year); + throw InvalidArgumentException::forDay($day, $month, $year); } $this->year = $year; @@ -179,34 +184,34 @@ public static function fromParts(Timezone $timezone, int $year, Month|int $month $calendarSeconds = $calendar->get(IntlCalendar::FIELD_SECOND); if ($calendarYear === false || $calendarMonth === false || $calendarDay === false || $calendarHours === false || $calendarMinutes === false || $calendarSeconds === false) { - throw new Exception\OverflowException(sprintf( + throw new OverflowException(sprintf( 'The year value "%d" exceeds the range supported by the calendar.', $year, )); } if ($seconds !== $calendarSeconds) { - throw Exception\UnexpectedValueException::forSeconds($seconds, $calendarSeconds); + throw UnexpectedValueException::forSeconds($seconds, $calendarSeconds); } if ($minutes !== $calendarMinutes) { - throw Exception\UnexpectedValueException::forMinutes($minutes, $calendarMinutes); + throw UnexpectedValueException::forMinutes($minutes, $calendarMinutes); } if ($hours !== $calendarHours) { - throw Exception\UnexpectedValueException::forHours($hours, $calendarHours); + throw UnexpectedValueException::forHours($hours, $calendarHours); } if ($day !== $calendarDay) { - throw Exception\UnexpectedValueException::forDay($day, $calendarDay); + throw UnexpectedValueException::forDay($day, $calendarDay); } if ($month !== ($calendarMonth + 1)) { - throw Exception\UnexpectedValueException::forMonth($month, $calendarMonth + 1); + throw UnexpectedValueException::forMonth($month, $calendarMonth + 1); } if ($year !== $calendarYear) { - throw Exception\UnexpectedValueException::forYear($year, $calendarYear); + throw UnexpectedValueException::forYear($year, $calendarYear); } $timestamp_in_seconds = (int) ($calendar->getTime() / (float) MILLISECONDS_PER_SECOND); @@ -223,7 +228,7 @@ public static function fromParts(Timezone $timezone, int $year, Month|int $month * * @see Timezone::default() */ - #[\Override] + #[Override] public static function fromTimestamp(int|Timestamp $timestamp, ?Timezone $timezone = null): static { $timezone ??= Timezone::default(); @@ -245,7 +250,7 @@ public static function fromTimestamp(int|Timestamp $timestamp, ?Timezone $timezo $second = $calendar->get(IntlCalendar::FIELD_SECOND); $nanoseconds = $timestamp->getNanoseconds(); - return new static($timezone, $timestamp, $year, $month, $day, $hour, $minute, $second, $nanoseconds); + return new self($timezone, $timestamp, $year, $month, $day, $hour, $minute, $second, $nanoseconds); } /** @@ -281,7 +286,7 @@ public static function parse(NativeDateTimeInterface|TemporalInterface|string|in return self::fromTimestamp( timestamp: Timestamp::fromParts($string->getTimestamp()), - timezone: $timezone ?? ($nativeTimezone instanceof \DateTimeZone ? Timezone::tryFrom($nativeTimezone->getName()) : null), + timezone: $timezone ?? ($nativeTimezone instanceof DateTimeZone ? Timezone::tryFrom($nativeTimezone->getName()) : null), ); } @@ -368,7 +373,7 @@ public static function fromString(string $rawString, ?DateStyle $dateStyle = nul /** * Returns the timestamp representation of this date time object. */ - #[\Override] + #[Override] public function getTimestamp(): Timestamp { return $this->timestamp; @@ -386,7 +391,7 @@ public function getTimestamp(): Timestamp * * @return int The year, formatted according to ISO-8601 standards, where 1 AD is 1, 1 BC is 0, 2 BC is -1, etc. */ - #[\Override] + #[Override] public function getYear(): int { return $this->year; @@ -397,7 +402,7 @@ public function getYear(): int * * @return int<1, 12> */ - #[\Override] + #[Override] public function getMonth(): int { return $this->month; @@ -408,7 +413,7 @@ public function getMonth(): int * * @return int<1, 31> */ - #[\Override] + #[Override] public function getDay(): int { return $this->day; @@ -419,7 +424,7 @@ public function getDay(): int * * @return int<0, 23> */ - #[\Override] + #[Override] public function getHours(): int { return $this->hours; @@ -430,7 +435,7 @@ public function getHours(): int * * @return int<0, 59> */ - #[\Override] + #[Override] public function getMinutes(): int { return $this->minutes; @@ -441,7 +446,7 @@ public function getMinutes(): int * * @return int<0, 59> */ - #[\Override] + #[Override] public function getSeconds(): int { return $this->seconds; @@ -452,7 +457,7 @@ public function getSeconds(): int * * @return int<0, 999999999> */ - #[\Override] + #[Override] public function getNanoseconds(): int { return $this->nanoseconds; @@ -461,7 +466,7 @@ public function getNanoseconds(): int /** * Gets the timezone associated with the date and time. */ - #[\Override] + #[Override] public function getTimezone(): Timezone { return $this->timezone; @@ -475,10 +480,10 @@ public function getTimezone(): Timezone * * @throws Exception\UnexpectedValueException If any of the provided date components do not align with calendar expectations. */ - #[\Override] + #[Override] public function withDate(int $year, Month|int $month, int $day): static { - return static::fromParts( + return self::fromParts( $this->timezone, $year, $month, @@ -500,10 +505,10 @@ public function withDate(int $year, Month|int $month, int $day): static * * @throws Exception\UnexpectedValueException If any of the provided time components do not align with calendar expectations. */ - #[\Override] + #[Override] public function withTime(int $hours, int $minutes, int $seconds = 0, int $nanoseconds = 0): static { - return static::fromParts( + return self::fromParts( $this->timezone, $this->year, $this->month, @@ -515,7 +520,7 @@ public function withTime(int $hours, int $minutes, int $seconds = 0, int $nanose ); } - #[\Override] + #[Override] public function jsonSerialize(): array { return [ diff --git a/packages/datetime/src/DateTimeConvenienceMethods.php b/packages/datetime/src/DateTimeConvenienceMethods.php index 24536f7ee..b1a50acbb 100644 --- a/packages/datetime/src/DateTimeConvenienceMethods.php +++ b/packages/datetime/src/DateTimeConvenienceMethods.php @@ -4,6 +4,7 @@ namespace Tempest\DateTime; +use Override; use Tempest\Intl\Locale; use Tempest\Support\Math; @@ -61,10 +62,10 @@ public function isDaylightSavingTime(): bool * * @param null|Timezone $timezone The timezone to convert to. */ - #[\Override] + #[Override] public function convertToTimezone(?Timezone $timezone): static { - if ($timezone === null) { + if (! $timezone instanceof Timezone) { return $this; } @@ -925,7 +926,7 @@ public function isEndOfWeek(): bool * @see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax * @see Locale::default() */ - #[\Override] + #[Override] public function format(null|FormatPattern|string $pattern = null, ?Timezone $timezone = null, ?Locale $locale = null): string { $timestamp = $this->getTimestamp(); @@ -964,7 +965,7 @@ public function format(null|FormatPattern|string $pattern = null, ?Timezone $tim * * @see https://datatracker.ietf.org/doc/html/rfc3339 */ - #[\Override] + #[Override] public function toRfc3339(?SecondsStyle $secondsStyle = null, bool $useZ = false): string { return namespace\format_rfc3339($this->getTimestamp(), $secondsStyle, $useZ, $this->getTimezone()); @@ -996,7 +997,7 @@ public function toRfc3339(?SecondsStyle $secondsStyle = null, bool $useZ = false * @see TimeStyle::default() * @see Locale::default() */ - #[\Override] + #[Override] public function toString( ?DateStyle $dateStyle = null, ?TimeStyle $timeStyle = null, diff --git a/packages/datetime/src/DateTimeInterface.php b/packages/datetime/src/DateTimeInterface.php index 069b9edce..837693c98 100644 --- a/packages/datetime/src/DateTimeInterface.php +++ b/packages/datetime/src/DateTimeInterface.php @@ -4,6 +4,7 @@ namespace Tempest\DateTime; +use Override; use Tempest\Intl\Locale; interface DateTimeInterface extends TemporalInterface @@ -633,7 +634,7 @@ public function isEndOfWeek(): bool; * @see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax * @see Locale::default() */ - #[\Override] + #[Override] public function format(null|FormatPattern|string $pattern = null, ?Timezone $timezone = null, ?Locale $locale = null): string; /** @@ -662,7 +663,7 @@ public function format(null|FormatPattern|string $pattern = null, ?Timezone $tim * @see TimeStyle::default() * @see Locale::default() */ - #[\Override] + #[Override] public function toString(?DateStyle $dateStyle = null, ?TimeStyle $timeStyle = null, ?Timezone $timezone = null, ?Locale $locale = null): string; /** @@ -690,7 +691,7 @@ public function toString(?DateStyle $dateStyle = null, ?TimeStyle $timeStyle = n * * @see https://datatracker.ietf.org/doc/html/rfc3339 */ - #[\Override] + #[Override] public function toRfc3339(?SecondsStyle $secondsStyle = null, bool $useZ = false): string; /** @@ -709,7 +710,7 @@ public function toRfc3339(?SecondsStyle $secondsStyle = null, bool $useZ = false * * @see TemporalInterface::toString() */ - #[\Override] + #[Override] public function __toString(): string; /** @@ -717,6 +718,6 @@ public function __toString(): string; * * @param null|Timezone $timezone The timezone to convert to. */ - #[\Override] + #[Override] public function convertToTimezone(?Timezone $timezone): static; } diff --git a/packages/datetime/src/Duration.php b/packages/datetime/src/Duration.php index 8badb32ae..21aba22c7 100644 --- a/packages/datetime/src/Duration.php +++ b/packages/datetime/src/Duration.php @@ -5,8 +5,12 @@ namespace Tempest\DateTime; use JsonSerializable; +use Override; use Stringable; use Tempest\Support\Comparison; +use Tempest\Support\Comparison\Comparable; +use Tempest\Support\Comparison\Equable; +use Tempest\Support\Comparison\Order; use Tempest\Support\Str; /** @@ -23,7 +27,7 @@ * @implements Comparison\Comparable * @implements Comparison\Equable */ -final readonly class Duration implements Comparison\Comparable, Comparison\Equable, JsonSerializable, Stringable +final readonly class Duration implements Comparable, Equable, JsonSerializable, Stringable { /** * Initializes a new instance of Duration with specified hours, minutes, seconds, and nanoseconds. @@ -405,22 +409,22 @@ public function withNanoseconds(int $nanoseconds): self * * @param Duration $other */ - #[\Override] - public function compare(mixed $other): Comparison\Order + #[Override] + public function compare(mixed $other): Order { if ($this->hours !== $other->hours) { - return Comparison\Order::from($this->hours <=> $other->hours); + return Order::from($this->hours <=> $other->hours); } if ($this->minutes !== $other->minutes) { - return Comparison\Order::from($this->minutes <=> $other->minutes); + return Order::from($this->minutes <=> $other->minutes); } if ($this->seconds !== $other->seconds) { - return Comparison\Order::from($this->seconds <=> $other->seconds); + return Order::from($this->seconds <=> $other->seconds); } - return Comparison\Order::from($this->nanoseconds <=> $other->nanoseconds); + return Order::from($this->nanoseconds <=> $other->nanoseconds); } /** @@ -428,10 +432,10 @@ public function compare(mixed $other): Comparison\Order * * @param Duration $other */ - #[\Override] + #[Override] public function equals(mixed $other): bool { - return $this->compare($other) === Comparison\Order::EQUAL; + return $this->compare($other) === Order::EQUAL; } /** @@ -439,7 +443,7 @@ public function equals(mixed $other): bool */ public function shorter(self $other): bool { - return $this->compare($other) === Comparison\Order::LESS; + return $this->compare($other) === Order::LESS; } /** @@ -447,7 +451,7 @@ public function shorter(self $other): bool */ public function shorterOrEqual(self $other): bool { - return $this->compare($other) !== Comparison\Order::GREATER; + return $this->compare($other) !== Order::GREATER; } /** @@ -455,7 +459,7 @@ public function shorterOrEqual(self $other): bool */ public function longer(self $other): bool { - return $this->compare($other) === Comparison\Order::GREATER; + return $this->compare($other) === Order::GREATER; } /** @@ -463,7 +467,7 @@ public function longer(self $other): bool */ public function longerOrEqual(self $other): bool { - return $this->compare($other) !== Comparison\Order::LESS; + return $this->compare($other) !== Order::LESS; } /** @@ -477,7 +481,7 @@ public function betweenInclusive(self $a, self $b): bool $ca = $this->compare($a); $cb = $this->compare($b); - return $ca === Comparison\Order::EQUAL || $ca !== $cb; + return $ca === Order::EQUAL || $ca !== $cb; } /** @@ -491,7 +495,7 @@ public function betweenExclusive(self $a, self $b): bool $ca = $this->compare($a); $cb = $this->compare($b); - return $ca !== Comparison\Order::EQUAL && $cb !== Comparison\Order::EQUAL && $ca !== $cb; + return $ca !== Order::EQUAL && $cb !== Order::EQUAL && $ca !== $cb; } /** @@ -613,7 +617,7 @@ public function toString(int $max_decimals = 3): string /** * Returns a string representation of the time duration. */ - #[\Override] + #[Override] public function __toString(): string { return $this->toString(); @@ -624,7 +628,7 @@ public function __toString(): string * * @return array{hours: int, minutes: int, seconds: int, nanoseconds: int} */ - #[\Override] + #[Override] public function jsonSerialize(): array { return [ diff --git a/packages/datetime/src/Exception/DateTimeException.php b/packages/datetime/src/Exception/DateTimeException.php index f2a011621..465fb7fad 100644 --- a/packages/datetime/src/Exception/DateTimeException.php +++ b/packages/datetime/src/Exception/DateTimeException.php @@ -4,6 +4,4 @@ namespace Tempest\DateTime\Exception; -interface DateTimeException -{ -} +interface DateTimeException {} diff --git a/packages/datetime/src/Exception/OverflowException.php b/packages/datetime/src/Exception/OverflowException.php index 889ff5d0c..aac737522 100644 --- a/packages/datetime/src/Exception/OverflowException.php +++ b/packages/datetime/src/Exception/OverflowException.php @@ -6,6 +6,4 @@ use OverflowException as PhpOverflowException; -final class OverflowException extends PhpOverflowException implements DateTimeException -{ -} +final class OverflowException extends PhpOverflowException implements DateTimeException {} diff --git a/packages/datetime/src/Exception/ParserException.php b/packages/datetime/src/Exception/ParserException.php index 199391651..62edddb61 100644 --- a/packages/datetime/src/Exception/ParserException.php +++ b/packages/datetime/src/Exception/ParserException.php @@ -4,6 +4,4 @@ namespace Tempest\DateTime\Exception; -final class ParserException extends RuntimeException -{ -} +final class ParserException extends RuntimeException {} diff --git a/packages/datetime/src/Exception/RuntimeException.php b/packages/datetime/src/Exception/RuntimeException.php index a3228748a..709ce27ed 100644 --- a/packages/datetime/src/Exception/RuntimeException.php +++ b/packages/datetime/src/Exception/RuntimeException.php @@ -7,6 +7,4 @@ use RuntimeException as PhpRuntimeException; // @phpstan-ignore-next-line -class RuntimeException extends PhpRuntimeException implements DateTimeException -{ -} +class RuntimeException extends PhpRuntimeException implements DateTimeException {} diff --git a/packages/datetime/src/Exception/UnderflowException.php b/packages/datetime/src/Exception/UnderflowException.php index a29986966..87b6c2936 100644 --- a/packages/datetime/src/Exception/UnderflowException.php +++ b/packages/datetime/src/Exception/UnderflowException.php @@ -6,6 +6,4 @@ use UnderflowException as PhpUnderflowException; -final class UnderflowException extends PhpUnderflowException implements DateTimeException -{ -} +final class UnderflowException extends PhpUnderflowException implements DateTimeException {} diff --git a/packages/datetime/src/TemporalConvenienceMethods.php b/packages/datetime/src/TemporalConvenienceMethods.php index e02480503..99eae1d9c 100644 --- a/packages/datetime/src/TemporalConvenienceMethods.php +++ b/packages/datetime/src/TemporalConvenienceMethods.php @@ -6,6 +6,7 @@ use DateTimeImmutable as NativeDateTimeImmutable; use DateTimeInterface as NativeDateTimeInterface; +use Override; use Tempest\Intl\Locale; use Tempest\Support\Comparison; use Tempest\Support\Comparison\Order; @@ -33,7 +34,7 @@ public function compare(mixed $other): Order $a = $this->getTimestamp()->toParts(); $b = $other->getTimestamp()->toParts(); - return Comparison\Order::from($a[0] !== $b[0] ? $a[0] <=> $b[0] : $a[1] <=> $b[1]); + return Order::from($a[0] !== $b[0] ? $a[0] <=> $b[0] : $a[1] <=> $b[1]); } /** @@ -59,7 +60,7 @@ public function atTheSameTime(TemporalInterface|string $other): bool $other = DateTime::parse($other); } - return $this->compare($other) === Comparison\Order::EQUAL; + return $this->compare($other) === Order::EQUAL; } /** @@ -67,7 +68,7 @@ public function atTheSameTime(TemporalInterface|string $other): bool */ public function before(TemporalInterface $other): bool { - return $this->compare($other) === Comparison\Order::LESS; + return $this->compare($other) === Order::LESS; } /** @@ -75,7 +76,7 @@ public function before(TemporalInterface $other): bool */ public function beforeOrAtTheSameTime(TemporalInterface $other): bool { - return $this->compare($other) !== Comparison\Order::GREATER; + return $this->compare($other) !== Order::GREATER; } /** @@ -83,7 +84,7 @@ public function beforeOrAtTheSameTime(TemporalInterface $other): bool */ public function after(TemporalInterface $other): bool { - return $this->compare($other) === Comparison\Order::GREATER; + return $this->compare($other) === Order::GREATER; } /** @@ -91,7 +92,7 @@ public function after(TemporalInterface $other): bool */ public function afterOrAtTheSameTime(TemporalInterface $other): bool { - return $this->compare($other) !== Comparison\Order::LESS; + return $this->compare($other) !== Order::LESS; } /** @@ -102,7 +103,7 @@ public function betweenTimeInclusive(TemporalInterface $a, TemporalInterface $b) $ca = $this->compare($a); $cb = $this->compare($b); - return $ca === Comparison\Order::EQUAL || $ca !== $cb; + return $ca === Order::EQUAL || $ca !== $cb; } /** @@ -113,7 +114,7 @@ public function betweenTimeExclusive(TemporalInterface $a, TemporalInterface $b) $ca = $this->compare($a); $cb = $this->compare($b); - return $ca !== Comparison\Order::EQUAL && $cb !== Comparison\Order::EQUAL && $ca !== $cb; + return $ca !== Order::EQUAL && $cb !== Order::EQUAL && $ca !== $cb; } /** @@ -549,7 +550,7 @@ public function toString(?DateStyle $dateStyle = null, ?TimeStyle $timeStyle = n * * @see TemporalInterface::toString() */ - #[\Override] + #[Override] public function __toString(): string { return $this->toString(); diff --git a/packages/datetime/src/TemporalInterface.php b/packages/datetime/src/TemporalInterface.php index 2e0c16d11..3b2c573d9 100644 --- a/packages/datetime/src/TemporalInterface.php +++ b/packages/datetime/src/TemporalInterface.php @@ -6,6 +6,7 @@ use DateTimeInterface as NativeDateTimeInterface; use JsonSerializable; +use Override; use Stringable; use Tempest\Intl\Locale; use Tempest\Support\Comparison\Comparable; @@ -35,7 +36,7 @@ public function getTimestamp(): Timestamp; * * @param TemporalInterface $other */ - #[\Override] + #[Override] public function compare(mixed $other): Order; /** @@ -45,7 +46,7 @@ public function compare(mixed $other): Order; * * @param TemporalInterface|string $other */ - #[\Override] + #[Override] public function equals(mixed $other): bool; /** @@ -419,7 +420,7 @@ public function toString(?DateStyle $dateStyle = null, ?TimeStyle $timeStyle = n * * @see TemporalInterface::toString() */ - #[\Override] + #[Override] public function __toString(): string; /** diff --git a/packages/datetime/src/Timestamp.php b/packages/datetime/src/Timestamp.php index a7ac0bb19..a49d7b2f4 100644 --- a/packages/datetime/src/Timestamp.php +++ b/packages/datetime/src/Timestamp.php @@ -4,8 +4,11 @@ namespace Tempest\DateTime; +use Override; use Tempest\Clock\Clock; use Tempest\Container\GenericContainer; +use Tempest\DateTime\Exception\OverflowException; +use Tempest\DateTime\Exception\UnderflowException; use Tempest\Intl\Locale; use Tempest\Support\Math; use Tempest\Support\Math\Exception\ArithmeticException; @@ -46,11 +49,11 @@ public static function fromParts(int $seconds, int $nanoseconds = 0): Timestamp { // Check for potential overflow or underflow before doing any operation if ($seconds === Math\INT64_MAX && $nanoseconds >= NANOSECONDS_PER_SECOND) { - throw new Exception\OverflowException('Adding nanoseconds would cause an overflow.'); + throw new OverflowException('Adding nanoseconds would cause an overflow.'); } if ($seconds === Math\INT64_MIN && $nanoseconds <= -NANOSECONDS_PER_SECOND) { - throw new Exception\UnderflowException('Subtracting nanoseconds would cause an underflow.'); + throw new UnderflowException('Subtracting nanoseconds would cause an underflow.'); } $seconds_adjustment = Math\div($nanoseconds, NANOSECONDS_PER_SECOND); @@ -170,7 +173,7 @@ public static function fromString(string $rawString, ?DateStyle $dateStyle = nul /** * Returns this Timestamp instance itself, as it already represents a timestamp. */ - #[\Override] + #[Override] public function getTimestamp(): self { return $this; @@ -224,7 +227,7 @@ public function getNanoseconds(): int * @throws Exception\UnderflowException If adding the duration results in an arithmetic underflow. * @throws Exception\OverflowException If adding the duration results in an arithmetic overflow. */ - #[\Override] + #[Override] public function plus(Duration $duration): static { [$h, $m, $s, $ns] = $duration->getParts(); @@ -242,7 +245,7 @@ public function plus(Duration $duration): static * @throws Exception\UnderflowException If subtracting the duration results in an arithmetic underflow. * @throws Exception\OverflowException If subtracting the duration results in an arithmetic overflow. */ - #[\Override] + #[Override] public function minus(Duration $duration): static { [$h, $m, $s, $ns] = $duration->getParts(); @@ -273,7 +276,7 @@ private static function resolveFromContainer(): ?Timestamp ->timestamp(); } - #[\Override] + #[Override] public function jsonSerialize(): array { return [ diff --git a/packages/datetime/src/functions.php b/packages/datetime/src/functions.php index 63233bcf7..2fb6d6c88 100644 --- a/packages/datetime/src/functions.php +++ b/packages/datetime/src/functions.php @@ -51,7 +51,7 @@ function format_rfc3339(Timestamp $timestamp, ?SecondsStyle $secondsStyle = null { $secondsStyle ??= SecondsStyle::fromTimestamp($timestamp); - if (null === $timezone) { + if (! $timezone instanceof Timezone) { $timezone = Timezone::UTC; } elseif ($useZ) { $useZ = Timezone::UTC === $timezone; @@ -159,7 +159,7 @@ function high_resolution_time(): array $offset = hrtime(); if ($offset === false) { // @phpstan-ignore-line identical.alwaysFalse - throw new \RuntimeException('The system does not provide a monotonic timer.'); + throw new RuntimeException('The system does not provide a monotonic timer.'); } $time = system_time(); @@ -252,7 +252,7 @@ function to_intl_timezone(Timezone $timezone): IntlTimeZone $tz = IntlTimeZone::createTimeZone($value); if ($tz === null) { // @phpstan-ignore-line identical.alwaysFalse - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to create intl timezone from timezone "%s" ("%s" / "%s").', $timezone->name, $timezone->value, @@ -261,7 +261,7 @@ function to_intl_timezone(Timezone $timezone): IntlTimeZone } if ($tz->getID() === 'Etc/Unknown' && $tz->getRawOffset() === 0) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to create a valid intl timezone, unknown timezone "%s" ("%s" / "%s") given.', $timezone->name, $timezone->value, diff --git a/packages/datetime/tests/DurationTest.php b/packages/datetime/tests/DurationTest.php index 7d58f9929..650e549e8 100644 --- a/packages/datetime/tests/DurationTest.php +++ b/packages/datetime/tests/DurationTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use Tempest\DateTime; +use Tempest\DateTime\Duration; use Tempest\Support\Comparison\Order; use Tempest\Support\Json; @@ -20,7 +21,7 @@ final class DurationTest extends TestCase public function test_getters(): void { - $t = DateTime\Duration::fromParts(1, 2, 3, 4); + $t = Duration::fromParts(1, 2, 3, 4); $this->assertSame(1, $t->getHours()); $this->assertSame(2, $t->getMinutes()); @@ -31,20 +32,20 @@ public function test_getters(): void public function test_named_constructors(): void { - $this->assertSame(168.0, DateTime\Duration::weeks(1)->getTotalHours()); - $this->assertSame(168.0, DateTime\Duration::week()->getTotalHours()); - $this->assertSame(24.0, DateTime\Duration::days(1)->getTotalHours()); - $this->assertSame(24.0, DateTime\Duration::day()->getTotalHours()); - $this->assertSame(1.0, DateTime\Duration::hours(1)->getTotalHours()); - $this->assertSame(1.0, DateTime\Duration::hour()->getTotalHours()); - $this->assertSame(1.0, DateTime\Duration::minutes(1)->getTotalMinutes()); - $this->assertSame(1.0, DateTime\Duration::minute()->getTotalMinutes()); - $this->assertSame(1.0, DateTime\Duration::seconds(1)->getTotalSeconds()); - $this->assertSame(1.0, DateTime\Duration::second()->getTotalSeconds()); - $this->assertSame(1.0, DateTime\Duration::milliseconds(1)->getTotalMilliseconds()); - $this->assertSame(1.0, DateTime\Duration::microseconds(1)->getTotalMicroseconds()); - $this->assertSame(1, DateTime\Duration::nanoseconds(1)->getNanoseconds()); - $this->assertSame(0.0, DateTime\Duration::zero()->getTotalSeconds()); + $this->assertSame(168.0, Duration::weeks(1)->getTotalHours()); + $this->assertSame(168.0, Duration::week()->getTotalHours()); + $this->assertSame(24.0, Duration::days(1)->getTotalHours()); + $this->assertSame(24.0, Duration::day()->getTotalHours()); + $this->assertSame(1.0, Duration::hours(1)->getTotalHours()); + $this->assertSame(1.0, Duration::hour()->getTotalHours()); + $this->assertSame(1.0, Duration::minutes(1)->getTotalMinutes()); + $this->assertSame(1.0, Duration::minute()->getTotalMinutes()); + $this->assertSame(1.0, Duration::seconds(1)->getTotalSeconds()); + $this->assertSame(1.0, Duration::second()->getTotalSeconds()); + $this->assertSame(1.0, Duration::milliseconds(1)->getTotalMilliseconds()); + $this->assertSame(1.0, Duration::microseconds(1)->getTotalMicroseconds()); + $this->assertSame(1, Duration::nanoseconds(1)->getNanoseconds()); + $this->assertSame(0.0, Duration::zero()->getTotalSeconds()); } #[TestWith([0, 0, 0, 0, 0.0])] @@ -62,7 +63,7 @@ public function test_get_total_hours( int $nanoseconds, float $expectedHours, ): void { - $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); + $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); $this->assertSame($expectedHours, $time->getTotalHours()); } @@ -76,7 +77,7 @@ public function test_get_total_hours( #[TestWith([-2, -15, -30, 0, -135.5])] public function test_get_total_minutes(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMinutes): void { - $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); + $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); $this->assertSame($expectedMinutes, $time->getTotalMinutes()); } @@ -90,7 +91,7 @@ public function test_get_total_minutes(int $hours, int $minutes, int $seconds, i #[TestWith([-2, -15, -30, 0, -8130.0])] public function test_get_total_seconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedSeconds): void { - $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); + $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); $this->assertSame($expectedSeconds, $time->getTotalSeconds()); } @@ -104,7 +105,7 @@ public function test_get_total_seconds(int $hours, int $minutes, int $seconds, i #[TestWith([-2, -15, -30, 0, -8130000.0])] public function test_get_total_milliseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMilliseconds): void { - $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); + $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); $this->assertSame($expectedMilliseconds, $time->getTotalMilliseconds()); } @@ -118,13 +119,13 @@ public function test_get_total_milliseconds(int $hours, int $minutes, int $secon #[TestWith([-2, -15, -30, 0, -8130000000.0])] public function test_get_total_microseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMicroseconds): void { - $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); + $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); $this->assertSame($expectedMicroseconds, $time->getTotalMicroseconds()); } public function test_setters(): void { - $t = DateTime\Duration::fromParts(1, 2, 3, 4); + $t = Duration::fromParts(1, 2, 3, 4); $this->assertSame([42, 2, 3, 4], $t->withHours(42)->getParts()); $this->assertSame([1, 42, 3, 4], $t->withMinutes(42)->getParts()); @@ -138,16 +139,16 @@ public function test_setters(): void public function test_fractions_of_second(): void { - $this->assertSame([0, 0, 0, 0], DateTime\Duration::zero()->getParts()); - $this->assertSame([0, 0, 0, 42], DateTime\Duration::nanoseconds(42)->getParts()); + $this->assertSame([0, 0, 0, 0], Duration::zero()->getParts()); + $this->assertSame([0, 0, 0, 42], Duration::nanoseconds(42)->getParts()); $this->assertSame( [0, 0, 1, 42], - DateTime\Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts(), + Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts(), ); - $this->assertSame([0, 0, 0, 42000], DateTime\Duration::microseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42000], DateTime\Duration::microseconds(1000042)->getParts()); - $this->assertSame([0, 0, 0, 42000000], DateTime\Duration::milliseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42000000], DateTime\Duration::milliseconds(1042)->getParts()); + $this->assertSame([0, 0, 0, 42000], Duration::microseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42000], Duration::microseconds(1000042)->getParts()); + $this->assertSame([0, 0, 0, 42000000], Duration::milliseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42000000], Duration::milliseconds(1042)->getParts()); } #[TestWith([0, 0, 0, 0])] @@ -164,22 +165,22 @@ public function test_normalized(int $input_s, int $input_ns, int $normalized_s, { $this->assertSame( [0, 0, $normalized_s, $normalized_ns], - DateTime\Duration::fromParts(0, 0, $input_s, $input_ns)->getParts(), + Duration::fromParts(0, 0, $input_s, $input_ns)->getParts(), ); } public function test_normalized_hms(): void { - $this->assertSame([3, 5, 4, 0], DateTime\Duration::fromParts(2, 63, 124)->getParts()); - $this->assertSame([0, 59, 4, 0], DateTime\Duration::fromParts(2, -63, 124)->getParts()); + $this->assertSame([3, 5, 4, 0], Duration::fromParts(2, 63, 124)->getParts()); + $this->assertSame([0, 59, 4, 0], Duration::fromParts(2, -63, 124)->getParts()); $this->assertSame( [-1, 0, -55, -(DateTime\NANOSECONDS_PER_SECOND - 42)], - DateTime\Duration::fromParts(0, -63, 124, 42)->getParts(), + Duration::fromParts(0, -63, 124, 42)->getParts(), ); - $this->assertSame([42, 0, 0, 0], DateTime\Duration::hours(42)->getParts()); - $this->assertSame([1, 3, 0, 0], DateTime\Duration::minutes(63)->getParts()); - $this->assertSame([0, -1, -3, 0], DateTime\Duration::seconds(-63)->getParts()); - $this->assertSame([0, 0, -1, 0], DateTime\Duration::nanoseconds(-DateTime\NANOSECONDS_PER_SECOND)->getParts()); + $this->assertSame([42, 0, 0, 0], Duration::hours(42)->getParts()); + $this->assertSame([1, 3, 0, 0], Duration::minutes(63)->getParts()); + $this->assertSame([0, -1, -3, 0], Duration::seconds(-63)->getParts()); + $this->assertSame([0, 0, -1, 0], Duration::nanoseconds(-DateTime\NANOSECONDS_PER_SECOND)->getParts()); } #[TestWith([0, 0, 0, 0, 0])] @@ -188,7 +189,7 @@ public function test_normalized_hms(): void #[TestWith([1, -63, 0, 0, -1])] public function test_positive_negative(int $h, int $m, int $s, int $ns, int $expected_sign): void { - $t = DateTime\Duration::fromParts($h, $m, $s, $ns); + $t = Duration::fromParts($h, $m, $s, $ns); $this->assertSame($expected_sign === 0, $t->isZero()); $this->assertSame($expected_sign === 1, $t->isPositive()); $this->assertSame($expected_sign === -1, $t->isNegative()); @@ -200,17 +201,17 @@ public function test_positive_negative(int $h, int $m, int $s, int $ns, int $exp public static function provide_compare_data(): array { return [ - [DateTime\Duration::seconds(20), DateTime\Duration::seconds(10), Order::GREATER], - [DateTime\Duration::seconds(10), DateTime\Duration::seconds(20), Order::LESS], - [DateTime\Duration::seconds(10), DateTime\Duration::seconds(10), Order::EQUAL], - [DateTime\Duration::hours(1), DateTime\Duration::minutes(42), Order::GREATER], - [DateTime\Duration::minutes(2), DateTime\Duration::seconds(120), Order::EQUAL], - [DateTime\Duration::zero(), DateTime\Duration::nanoseconds(1), Order::LESS], + [Duration::seconds(20), Duration::seconds(10), Order::GREATER], + [Duration::seconds(10), Duration::seconds(20), Order::LESS], + [Duration::seconds(10), Duration::seconds(10), Order::EQUAL], + [Duration::hours(1), Duration::minutes(42), Order::GREATER], + [Duration::minutes(2), Duration::seconds(120), Order::EQUAL], + [Duration::zero(), Duration::nanoseconds(1), Order::LESS], ]; } #[DataProvider('provide_compare_data')] - public function test_compare(DateTime\Duration $a, DateTime\Duration $b, Order $expected): void + public function test_compare(Duration $a, Duration $b, Order $expected): void { $opposite = Order::from(-$expected->value); @@ -233,9 +234,9 @@ public function test_compare(DateTime\Duration $a, DateTime\Duration $b, Order $ public function test_is_between(): void { - $a = DateTime\Duration::hours(1); - $b = DateTime\Duration::minutes(64); - $c = DateTime\Duration::fromParts(1, 30); + $a = Duration::hours(1); + $b = Duration::minutes(64); + $c = Duration::fromParts(1, 30); $this->assertTrue($b->betweenExclusive($a, $c)); $this->assertTrue($b->betweenExclusive($c, $a)); $this->assertTrue($b->betweenInclusive($a, $c)); @@ -248,9 +249,9 @@ public function test_is_between(): void public function test_operations(): void { - $z = DateTime\Duration::zero(); - $a = DateTime\Duration::fromParts(0, 2, 25); - $b = DateTime\Duration::fromParts(0, 0, -63, 42); + $z = Duration::zero(); + $a = Duration::fromParts(0, 2, 25); + $b = Duration::fromParts(0, 0, -63, 42); $this->assertSame([0, 0, 0, 0], $z->invert()->getParts()); $this->assertSame([0, -2, -25, 0], $a->invert()->getParts()); $this->assertSame([0, 1, 2, DateTime\NANOSECONDS_PER_SECOND - 42], $b->invert()->getParts()); @@ -282,12 +283,12 @@ public function test_operations(): void #[TestWith([0, 0, 0, -420000000, '-0.42 second(s)'])] public function test_to_string(int $h, int $m, int $s, int $ns, string $expected): void { - $this->assertSame($expected, DateTime\Duration::fromParts($h, $m, $s, $ns)->toString()); + $this->assertSame($expected, Duration::fromParts($h, $m, $s, $ns)->toString()); } public function test_serialization(): void { - $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500000000); + $timeInterval = Duration::fromParts(1, 30, 45, 500000000); $serialized = serialize($timeInterval); $deserialized = unserialize($serialized); @@ -296,7 +297,7 @@ public function test_serialization(): void public function test_json_encoding(): void { - $timeInterval = DateTime\Duration::fromParts(1, 30, 45, 500000000); + $timeInterval = Duration::fromParts(1, 30, 45, 500000000); $jsonEncoded = Json\encode($timeInterval); $jsonDecoded = Json\decode($jsonEncoded, associative: true); diff --git a/packages/debug/src/Debug.php b/packages/debug/src/Debug.php index cd17c4ef2..4899fb2f0 100644 --- a/packages/debug/src/Debug.php +++ b/packages/debug/src/Debug.php @@ -97,16 +97,16 @@ private function writeToOut(array $items, string $callPath): void echo vsprintf( <<%s (%s) - HTML, + %s (%s) + HTML, [ 'Source Code Pro, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace', $key, diff --git a/packages/debug/src/DebugConfig.php b/packages/debug/src/DebugConfig.php index 11cc9fad5..b7b47682f 100644 --- a/packages/debug/src/DebugConfig.php +++ b/packages/debug/src/DebugConfig.php @@ -2,12 +2,12 @@ namespace Tempest\Debug; -final class DebugConfig +final readonly class DebugConfig { /** * @param string $logPath The file path where debug logs will be written. */ public function __construct( - public readonly string $logPath, + public string $logPath, ) {} } diff --git a/packages/debug/src/Stacktrace/Frame.php b/packages/debug/src/Stacktrace/Frame.php index 95592f450..8d86f24a1 100644 --- a/packages/debug/src/Stacktrace/Frame.php +++ b/packages/debug/src/Stacktrace/Frame.php @@ -7,6 +7,7 @@ use ReflectionFunction; use ReflectionMethod; use ReflectionParameter; +use Throwable; use function Tempest\Support\Path\to_relative_path; @@ -74,7 +75,7 @@ public static function extractArguments(array $frame): array callback: fn (ReflectionParameter $param) => $param->getName(), array: $reflection->getParameters(), ); - } catch (\Throwable) { + } catch (Throwable) { // @mago-expect lint:no-empty-catch-clause } diff --git a/packages/debug/src/TailDebugCommand.php b/packages/debug/src/TailDebugCommand.php index 98397faa7..8c94fe550 100644 --- a/packages/debug/src/TailDebugCommand.php +++ b/packages/debug/src/TailDebugCommand.php @@ -21,7 +21,7 @@ public function __invoke(bool $clear = true): void { $debugLogPath = $this->debugConfig->logPath; - if (! $debugLogPath) { + if ($debugLogPath === '' || $debugLogPath === '0') { $this->console->error('No debug log configured in DebugConfig.'); return; diff --git a/packages/debug/src/functions.php b/packages/debug/src/functions.php index 3aa00a0cd..a9e75f1f6 100644 --- a/packages/debug/src/functions.php +++ b/packages/debug/src/functions.php @@ -45,7 +45,7 @@ function ll(mixed ...$input): void */ function le(mixed ...$input): void { - Debug::resolve()->log($input, writeToOut: false, writeToLog: false); + Debug::resolve()->log($input, writeToLog: false, writeToOut: false); } } diff --git a/packages/discovery/src/Commands/MakeDiscoveryCommand.php b/packages/discovery/src/Commands/MakeDiscoveryCommand.php index ddbb81295..48d536922 100644 --- a/packages/discovery/src/Commands/MakeDiscoveryCommand.php +++ b/packages/discovery/src/Commands/MakeDiscoveryCommand.php @@ -12,7 +12,7 @@ use Tempest\Generation\Php\ClassManipulator; use Tempest\Generation\Php\DataObjects\StubFile; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final class MakeDiscoveryCommand { use PublishesFiles; diff --git a/packages/discovery/src/DiscoveryLocation.php b/packages/discovery/src/DiscoveryLocation.php index 13dd3c8b3..84b33b494 100644 --- a/packages/discovery/src/DiscoveryLocation.php +++ b/packages/discovery/src/DiscoveryLocation.php @@ -9,7 +9,6 @@ final class DiscoveryLocation { - public readonly string $namespace; public readonly string $path; public string $key { @@ -17,10 +16,9 @@ final class DiscoveryLocation } public function __construct( - string $namespace, + public readonly string $namespace, string $path, ) { - $this->namespace = $namespace; $this->path = Filesystem\normalize_path(rtrim($path, '\\/')); } diff --git a/packages/event-bus/src/StopsPropagation.php b/packages/event-bus/src/StopsPropagation.php index ac3241e03..a296547f9 100644 --- a/packages/event-bus/src/StopsPropagation.php +++ b/packages/event-bus/src/StopsPropagation.php @@ -5,6 +5,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] -final readonly class StopsPropagation -{ -} +final readonly class StopsPropagation {} diff --git a/packages/event-bus/src/Testing/EventBusTester.php b/packages/event-bus/src/Testing/EventBusTester.php index 668e4651b..383a7af97 100644 --- a/packages/event-bus/src/Testing/EventBusTester.php +++ b/packages/event-bus/src/Testing/EventBusTester.php @@ -62,7 +62,7 @@ public function assertDispatched(string|object $event, ?Closure $callback = null Assert::assertCount($count, $dispatches, 'The number of dispatches does not match.'); } - if ($callback !== null) { + if ($callback instanceof Closure) { foreach ($dispatches as $dispatch) { Assert::assertNotFalse($callback($dispatch), 'The callback failed.'); } @@ -111,11 +111,7 @@ private function findDispatches(string|object $event): array return true; } - if (class_exists($event) && $dispatched instanceof $event) { - return true; - } - - return false; + return class_exists($event) && $dispatched instanceof $event; }); } diff --git a/packages/event-bus/tests/Fixtures/EventInterface.php b/packages/event-bus/tests/Fixtures/EventInterface.php index 0cfc74c27..1be684456 100644 --- a/packages/event-bus/tests/Fixtures/EventInterface.php +++ b/packages/event-bus/tests/Fixtures/EventInterface.php @@ -4,6 +4,4 @@ namespace Tempest\EventBus\Tests\Fixtures; -interface EventInterface -{ -} +interface EventInterface {} diff --git a/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php b/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php index 9b9fa7921..8f56d225d 100644 --- a/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php +++ b/packages/event-bus/tests/Fixtures/EventInterfaceImplementation.php @@ -4,6 +4,4 @@ namespace Tempest\EventBus\Tests\Fixtures; -final readonly class EventInterfaceImplementation implements EventInterface -{ -} +final readonly class EventInterfaceImplementation implements EventInterface {} diff --git a/packages/event-bus/tests/Fixtures/ItHappened.php b/packages/event-bus/tests/Fixtures/ItHappened.php index 37fcd827c..2dd32f315 100644 --- a/packages/event-bus/tests/Fixtures/ItHappened.php +++ b/packages/event-bus/tests/Fixtures/ItHappened.php @@ -4,6 +4,4 @@ namespace Tempest\EventBus\Tests\Fixtures; -final readonly class ItHappened -{ -} +final readonly class ItHappened {} diff --git a/packages/generation/src/Php/Exceptions/FileGenerationException.php b/packages/generation/src/Php/Exceptions/FileGenerationException.php index 6c9e18f78..00d8bac3f 100644 --- a/packages/generation/src/Php/Exceptions/FileGenerationException.php +++ b/packages/generation/src/Php/Exceptions/FileGenerationException.php @@ -4,6 +4,4 @@ namespace Tempest\Generation\Php\Exceptions; -interface FileGenerationException -{ -} +interface FileGenerationException {} diff --git a/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php b/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php index 1e3004432..9a08bb47e 100644 --- a/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php +++ b/packages/generation/src/Php/Exceptions/FileGenerationWasAborted.php @@ -6,6 +6,4 @@ use Exception; -final class FileGenerationWasAborted extends Exception implements FileGenerationException -{ -} +final class FileGenerationWasAborted extends Exception implements FileGenerationException {} diff --git a/packages/generation/src/Php/StubFileGenerator.php b/packages/generation/src/Php/StubFileGenerator.php index 61a7e0fee..5d636a602 100644 --- a/packages/generation/src/Php/StubFileGenerator.php +++ b/packages/generation/src/Php/StubFileGenerator.php @@ -82,7 +82,7 @@ public function generateClassFile( $classManipulator->save($targetPath); } catch (Throwable $throwable) { - throw new FileGenerationFailedException(sprintf('The file could not be written. %s', $throwable->getMessage())); + throw new FileGenerationFailedException(sprintf('The file could not be written. %s', $throwable->getMessage()), $throwable->getCode(), $throwable); } } @@ -129,8 +129,8 @@ public function generateRawFile( // Run all manipulations $fileContent = array_reduce( array: $manipulations, - initial: $fileContent, callback: fn (ImmutableString $content, Closure $manipulation) => $manipulation($content), + initial: $fileContent, ); if (Filesystem\is_file($targetPath) && $shouldOverride) { @@ -139,7 +139,7 @@ public function generateRawFile( Filesystem\write_file($targetPath, $fileContent); } catch (Throwable $throwable) { - throw new FileGenerationFailedException(sprintf('The file could not be written. %s', $throwable->getMessage())); + throw new FileGenerationFailedException(sprintf('The file could not be written. %s', $throwable->getMessage()), $throwable->getCode(), $throwable); } } diff --git a/packages/generation/src/TypeScript/AsType.php b/packages/generation/src/TypeScript/AsType.php index dd4fc72e4..b4b18db82 100644 --- a/packages/generation/src/TypeScript/AsType.php +++ b/packages/generation/src/TypeScript/AsType.php @@ -8,6 +8,4 @@ * Marks this class as a source for TypeScript type generation. */ #[Attribute(Attribute::TARGET_CLASS)] -final class AsType -{ -} +final class AsType {} diff --git a/packages/generation/src/TypeScript/GenerateTypesCommand.php b/packages/generation/src/TypeScript/GenerateTypesCommand.php index b4e83dc06..6685e3ef4 100644 --- a/packages/generation/src/TypeScript/GenerateTypesCommand.php +++ b/packages/generation/src/TypeScript/GenerateTypesCommand.php @@ -8,14 +8,14 @@ use Tempest\Console\HasConsole; use Tempest\Container\Container; -final class GenerateTypesCommand +final readonly class GenerateTypesCommand { use HasConsole; public function __construct( - private readonly TypeScriptGenerationConfig $config, - private readonly TypeScriptGenerator $generator, - private readonly Container $container, + private TypeScriptGenerationConfig $config, + private TypeScriptGenerator $generator, + private Container $container, ) {} #[ConsoleCommand( diff --git a/packages/generation/src/TypeScript/StructureResolvers/ClassStructureResolver.php b/packages/generation/src/TypeScript/StructureResolvers/ClassStructureResolver.php index 4dd9a85b2..9c8e5696b 100644 --- a/packages/generation/src/TypeScript/StructureResolvers/ClassStructureResolver.php +++ b/packages/generation/src/TypeScript/StructureResolvers/ClassStructureResolver.php @@ -17,11 +17,11 @@ /** * Resolves PHP classes into TypeScript interfaces. */ -final class ClassStructureResolver implements StructureResolver +final readonly class ClassStructureResolver implements StructureResolver { public function __construct( - private readonly TypeScriptGenerationConfig $config, - private readonly Container $container, + private TypeScriptGenerationConfig $config, + private Container $container, ) {} public function resolve(TypeReflector $type, TypeScriptGenerator $generator): InterfaceDefinition @@ -47,7 +47,7 @@ private function resolveProperty(PropertyReflector $property, TypeScriptGenerato if ($type->isIterable()) { $elementTypeReflector = $property->getIterableType(); - if ($elementTypeReflector !== null) { + if ($elementTypeReflector instanceof TypeReflector) { $result = $this->resolveType($elementTypeReflector, $generator); return new PropertyDefinition( diff --git a/packages/generation/src/TypeScript/StructureResolvers/EnumStructureResolver.php b/packages/generation/src/TypeScript/StructureResolvers/EnumStructureResolver.php index 7293fec25..a0151d97f 100644 --- a/packages/generation/src/TypeScript/StructureResolvers/EnumStructureResolver.php +++ b/packages/generation/src/TypeScript/StructureResolvers/EnumStructureResolver.php @@ -17,11 +17,11 @@ /** * Resolves PHP enums into TypeScript union types. */ -final class EnumStructureResolver implements StructureResolver +final readonly class EnumStructureResolver implements StructureResolver { public function __construct( - private readonly TypeScriptGenerationConfig $config, - private readonly Container $container, + private TypeScriptGenerationConfig $config, + private Container $container, ) {} public function resolve(TypeReflector $type, TypeScriptGenerator $generator): TypeDefinition diff --git a/packages/generation/src/TypeScript/TypeResolvers/ScalarTypeResolver.php b/packages/generation/src/TypeScript/TypeResolvers/ScalarTypeResolver.php index ae88f7df3..322434cde 100644 --- a/packages/generation/src/TypeScript/TypeResolvers/ScalarTypeResolver.php +++ b/packages/generation/src/TypeScript/TypeResolvers/ScalarTypeResolver.php @@ -4,6 +4,7 @@ namespace Tempest\Generation\TypeScript\TypeResolvers; +use LogicException; use Tempest\Core\Priority; use Tempest\Generation\TypeScript\ResolvedType; use Tempest\Generation\TypeScript\TypeResolver; @@ -27,7 +28,7 @@ public function canResolve(TypeReflector $type): bool public function resolve(TypeReflector $type, TypeScriptGenerator $generator): ResolvedType { - $type = self::SCALAR_TYPE_MAP[$type->getName()] ?? throw new \LogicException(sprintf('Unsupported scalar type "%s".', $type->getName())); + $type = self::SCALAR_TYPE_MAP[$type->getName()] ?? throw new LogicException(sprintf('Unsupported scalar type "%s".', $type->getName())); return new ResolvedType($type); } diff --git a/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php b/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php index fdcc7c892..3294dcf56 100644 --- a/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php +++ b/packages/generation/src/TypeScript/TypeScriptGenerationConfig.php @@ -11,27 +11,19 @@ interface TypeScriptGenerationConfig * * @var class-string */ - public string $writer { - get; - } + public string $writer { get; } /** * The list of source classes to generate types for. * * @var array */ - public array $sources { - get; - set; - } + public array $sources { get; set; } /** * The list of type resolvers for property-level type mapping. * * @var array> */ - public array $resolvers { - get; - set; - } + public array $resolvers { get; set; } } diff --git a/packages/generation/src/TypeScript/TypeSourceDiscovery.php b/packages/generation/src/TypeScript/TypeSourceDiscovery.php index 3d69a7fc0..92943518b 100644 --- a/packages/generation/src/TypeScript/TypeSourceDiscovery.php +++ b/packages/generation/src/TypeScript/TypeSourceDiscovery.php @@ -18,7 +18,7 @@ public function __construct( public function discover(DiscoveryLocation $location, ClassReflector $class): void { - if ($class->getAttribute(AsType::class)) { + if ($class->getAttribute(AsType::class) instanceof AsType) { $this->discoveryItems->add($location, [$class->getName()]); } diff --git a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php index 647d0cbf8..127381d59 100644 --- a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php +++ b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php @@ -16,10 +16,10 @@ /** * Writes TypeScript definitions to separate .ts files organized by namespace in a directory structure. */ -final class DirectoryWriter implements TypeScriptWriter +final readonly class DirectoryWriter implements TypeScriptWriter { public function __construct( - private readonly DirectoryTypeScriptGenerationConfig $config, + private DirectoryTypeScriptGenerationConfig $config, ) {} public function write(TypeScriptOutput $output): void @@ -179,12 +179,12 @@ private function computeImportPath(string $sourceNamespace, string $targetNamesp $targetDiff = array_slice($targetParts, $commonLength); $targetKebab = Arr\map($targetDiff, fn (string $part) => Str\to_kebab_case($part)); - if ($upLevels === 0 && count($targetKebab) === 0) { + if ($upLevels === 0 && $targetKebab === []) { return './'; } $upPath = $upLevels > 0 ? str_repeat('../', $upLevels) : './'; - $downPath = count($targetKebab) > 0 ? (string) Arr\implode($targetKebab, glue: '/') : ''; + $downPath = $targetKebab !== [] ? (string) Arr\implode($targetKebab, glue: '/') : ''; $fullPath = rtrim($upPath . $downPath, '/'); diff --git a/packages/generation/src/TypeScript/Writers/NamespacedFileWriter.php b/packages/generation/src/TypeScript/Writers/NamespacedFileWriter.php index c8c5a7a98..f593fc478 100644 --- a/packages/generation/src/TypeScript/Writers/NamespacedFileWriter.php +++ b/packages/generation/src/TypeScript/Writers/NamespacedFileWriter.php @@ -16,10 +16,10 @@ /** * Writes TypeScript definitions to a single .d.ts file using TypeScript namespaces. */ -final class NamespacedFileWriter implements TypeScriptWriter +final readonly class NamespacedFileWriter implements TypeScriptWriter { public function __construct( - private readonly NamespacedTypeScriptGenerationConfig $config, + private NamespacedTypeScriptGenerationConfig $config, ) {} public function write(TypeScriptOutput $output): void diff --git a/packages/generation/tests/Php/ClassGeneratorTest.php b/packages/generation/tests/Php/ClassGeneratorTest.php index 2a3072e46..b18bc5d65 100644 --- a/packages/generation/tests/Php/ClassGeneratorTest.php +++ b/packages/generation/tests/Php/ClassGeneratorTest.php @@ -28,14 +28,14 @@ public function creates_class_from_scratch(): void $class->setReadOnly(); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $class->addMethod('getName', body: <<assertMatchesSnapshot($class->print()); } @@ -50,8 +50,8 @@ public function creates_methods_with_parameters(): void $class->setReadOnly(); $class->addMethod('findById', body: << 'int'], returnType: '?App\\Models\\User'); + // + PHP, parameters: ['id' => 'int'], returnType: '?App\\Models\\User'); $this->assertMatchesSnapshot($class->print()); } @@ -73,10 +73,10 @@ public function simplify_class_names_by_default(): void $class = new ClassGenerator('CreateUsersTable', namespace: 'App'); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $this->assertMatchesSnapshot($class->print()); } @@ -88,10 +88,10 @@ public function does_not_simplify_class_names(): void $class->simplifyClassNamesInMethodBodies(false); $class->addMethod('up', body: <<primary() - ->text('name'); - PHP, returnType: FakeQueryStatement::class); + return (new \Tempest\Generation\Tests\Fixtures\Database\FakeCreateTableStatement(\Tempest\Generation\Tests\Fixtures\Database\MigrationModel::table())) + ->primary() + ->text('name'); + PHP, returnType: FakeQueryStatement::class); $this->assertMatchesSnapshot($class->print()); } diff --git a/packages/generation/tests/Php/Fixtures/ClassFromFile.php b/packages/generation/tests/Php/Fixtures/ClassFromFile.php index 724347072..2ca7a96e4 100644 --- a/packages/generation/tests/Php/Fixtures/ClassFromFile.php +++ b/packages/generation/tests/Php/Fixtures/ClassFromFile.php @@ -4,6 +4,4 @@ namespace Tempest\Generation\Tests\Php\Fixtures; -final readonly class ClassFromFile -{ -} +final readonly class ClassFromFile {} diff --git a/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php b/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php index 98ce82e66..5cdf78f0e 100644 --- a/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php +++ b/packages/generation/tests/Php/Fixtures/ClassWithMethodParameterAttributes.php @@ -11,6 +11,5 @@ final class ClassWithMethodParameterAttributes public function example( #[SampleParameterAttribute] string $parameter, - ): void { - } + ): void {} } diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php index ae38bb730..179cd4746 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/DummyFqcn.php @@ -4,6 +4,4 @@ namespace Tempest\Generation\Tests\Php\Fixtures\SampleNamespace; -final class DummyFqcn -{ -} +final class DummyFqcn {} diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php index 7205acca8..811dbc7d2 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/ExampleTrait.php @@ -6,7 +6,5 @@ trait ExampleTrait { - public function traitMethod(): void - { - } + public function traitMethod(): void {} } diff --git a/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php b/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php index 9d2bf3318..5ac1bc345 100644 --- a/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php +++ b/packages/generation/tests/Php/Fixtures/SampleNamespace/SampleParameterAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PARAMETER)] -final class SampleParameterAttribute -{ -} +final class SampleParameterAttribute {} diff --git a/packages/generation/tests/Php/Fixtures/TestAttribute.php b/packages/generation/tests/Php/Fixtures/TestAttribute.php index 91486e42b..4eace3257 100644 --- a/packages/generation/tests/Php/Fixtures/TestAttribute.php +++ b/packages/generation/tests/Php/Fixtures/TestAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS)] -final class TestAttribute -{ -} +final class TestAttribute {} diff --git a/packages/generation/tests/TypeScript/StructureResolvers/ClassStructureResolverTest.php b/packages/generation/tests/TypeScript/StructureResolvers/ClassStructureResolverTest.php index 578ca75fd..dbadca213 100644 --- a/packages/generation/tests/TypeScript/StructureResolvers/ClassStructureResolverTest.php +++ b/packages/generation/tests/TypeScript/StructureResolvers/ClassStructureResolverTest.php @@ -23,6 +23,7 @@ final class ClassStructureResolverTest extends TestCase { private ClassStructureResolver $resolver; + private GenericTypeScriptGenerator $generator; #[PreCondition] @@ -78,5 +79,6 @@ public function resolves_scalar_properties(): void final class Badge { public string $name; + public int $value; } diff --git a/packages/http-client/src/Testing/MockClient.php b/packages/http-client/src/Testing/MockClient.php index 75636d3c8..ae033c413 100644 --- a/packages/http-client/src/Testing/MockClient.php +++ b/packages/http-client/src/Testing/MockClient.php @@ -97,11 +97,11 @@ public function sendRequest(RequestInterface $request): ResponseInterface $this->lastRequest = $request; $this->requests[] = $request; - if ($response = $this->resolveFakeResponse($request)) { + if (($response = $this->resolveFakeResponse($request)) instanceof ResponseInterface) { return $response; } - if ($response = $this->resolveWildcardFakeResponse($request)) { + if (($response = $this->resolveWildcardFakeResponse($request)) instanceof ResponseInterface) { return $response; } diff --git a/packages/http/src/Cookie/Cookie.php b/packages/http/src/Cookie/Cookie.php index 36f235faa..9d5621943 100644 --- a/packages/http/src/Cookie/Cookie.php +++ b/packages/http/src/Cookie/Cookie.php @@ -60,15 +60,15 @@ public function __toString(): string $parts[] = 'Path=' . $this->path; } - if ($this->secure === true) { + if ($this->secure) { $parts[] = 'Secure'; } - if ($this->httpOnly === true) { + if ($this->httpOnly) { $parts[] = 'HttpOnly'; } - if ($this->sameSite !== null) { + if ($this->sameSite instanceof SameSite) { $parts[] = 'SameSite=' . $this->sameSite->value; } diff --git a/packages/http/src/HttpRequestFailed.php b/packages/http/src/HttpRequestFailed.php index ed3999c3d..b207921de 100644 --- a/packages/http/src/HttpRequestFailed.php +++ b/packages/http/src/HttpRequestFailed.php @@ -34,7 +34,7 @@ public function context(): array 'request_uri' => $this->request?->uri, 'request_method' => $this->request?->method->value, 'status_code' => $this->status->value, - 'original_response' => $this->cause ? $this->cause::class : null, + 'original_response' => $this->cause instanceof Response ? $this->cause::class : null, ]); } } diff --git a/packages/http/src/Request.php b/packages/http/src/Request.php index 794d42c86..7193d4f57 100644 --- a/packages/http/src/Request.php +++ b/packages/http/src/Request.php @@ -8,43 +8,25 @@ interface Request { - public Method $method { - get; - } + public Method $method { get; } - public string $uri { - get; - } + public string $uri { get; } - public ?string $raw { - get; - } + public ?string $raw { get; } - public array $body { - get; - } + public array $body { get; } - public RequestHeaders $headers { - get; - } + public RequestHeaders $headers { get; } - public string $path { - get; - } + public string $path { get; } - public array $query { - get; - } + public array $query { get; } /** @var \Tempest\Http\Upload[] $files */ - public array $files { - get; - } + public array $files { get; } /** @var Cookie[] $cookies */ - public array $cookies { - get; - } + public array $cookies { get; } public function has(string $key): bool; diff --git a/packages/http/src/Response.php b/packages/http/src/Response.php index ea7bac8b3..2c92b36b6 100644 --- a/packages/http/src/Response.php +++ b/packages/http/src/Response.php @@ -15,25 +15,19 @@ interface Response /** * Gets the status code of the response. */ - public Status $status { - get; - } + public Status $status { get; } /** * Gets the headers of the response. * * @var \Tempest\Http\Header[] $headers */ - public array $headers { - get; - } + public array $headers { get; } /** * Gets the body of the response. */ - public View|string|array|Generator|JsonSerializable|null $body { - get; - } + public View|string|array|Generator|JsonSerializable|null $body { get; } /** * Gets a header by its name, case insensitive. diff --git a/packages/http/src/Responses/Download.php b/packages/http/src/Responses/Download.php index 75b08fcd0..a5ee7f9e2 100644 --- a/packages/http/src/Responses/Download.php +++ b/packages/http/src/Responses/Download.php @@ -16,7 +16,8 @@ public function __construct(string $path, ?string $filename = null) { $filename ??= pathinfo($path, PATHINFO_BASENAME); - $this->addHeader('Content-Disposition', "attachment; filename=\"{$filename}\"") + $this + ->addHeader('Content-Disposition', "attachment; filename=\"{$filename}\"") ->setContentType(ContentType::fromPath($path)) ->removeHeader('Transfer-Encoding'); diff --git a/packages/http/src/Responses/File.php b/packages/http/src/Responses/File.php index f940def4d..c75213a39 100644 --- a/packages/http/src/Responses/File.php +++ b/packages/http/src/Responses/File.php @@ -16,7 +16,8 @@ public function __construct(string $path, ?string $filename = null) { $filename ??= pathinfo($path, PATHINFO_BASENAME); - $this->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"") + $this + ->addHeader('Content-Disposition', "inline; filename=\"{$filename}\"") ->setContentType(ContentType::fromPath($path)) ->removeHeader('Transfer-Encoding'); diff --git a/packages/http/src/Responses/ServerError.php b/packages/http/src/Responses/ServerError.php index 21ef41b98..024fb4ead 100644 --- a/packages/http/src/Responses/ServerError.php +++ b/packages/http/src/Responses/ServerError.php @@ -15,12 +15,11 @@ final class ServerError implements Response { use IsResponse; - private(set) ?Exception $exception = null; - - public function __construct(View|Generator|string|array|null $body = null, ?Exception $exception = null) - { + public function __construct( + View|Generator|string|array|null $body = null, + private(set) ?Exception $exception = null, + ) { $this->status = Status::INTERNAL_SERVER_ERROR; $this->body = $body; - $this->exception = $exception; } } diff --git a/packages/http/src/SensitiveField.php b/packages/http/src/SensitiveField.php index 0a01792cc..2204b7f0d 100644 --- a/packages/http/src/SensitiveField.php +++ b/packages/http/src/SensitiveField.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class SensitiveField -{ -} +final class SensitiveField {} diff --git a/packages/http/src/ServerSentEvent.php b/packages/http/src/ServerSentEvent.php index 8a8c8d5d2..847bb0aaa 100644 --- a/packages/http/src/ServerSentEvent.php +++ b/packages/http/src/ServerSentEvent.php @@ -11,16 +11,12 @@ interface ServerSentEvent /** * Defines the ID of this event, which sets the `Last-Event-ID` header in case of a reconnection. */ - public ?int $id { - get; - } + public ?int $id { get; } /** * Defines the event stream's reconnection time in case of a reconnection attempt. */ - public null|Duration|int $retryAfter { - get; - } + public null|Duration|int $retryAfter { get; } /** * The name of the event, which may be listened to by `EventSource#addEventListener`. @@ -33,14 +29,10 @@ interface ServerSentEvent * }) * ``` */ - public ?string $event { - get; - } + public ?string $event { get; } /** * Content of the event. */ - public JsonSerializable|Stringable|string|iterable $data { - get; - } + public JsonSerializable|Stringable|string|iterable $data { get; } } diff --git a/packages/http/src/Session/Config/session.config.php b/packages/http/src/Session/Config/session.config.php index 1c6cebdc3..8864f4abb 100644 --- a/packages/http/src/Session/Config/session.config.php +++ b/packages/http/src/Session/Config/session.config.php @@ -4,6 +4,6 @@ use Tempest\Http\Session\Config\FileSessionConfig; return new FileSessionConfig( - path: 'sessions', expiration: Duration::days(30), + path: 'sessions', ); diff --git a/packages/http/src/Session/FormSession.php b/packages/http/src/Session/FormSession.php index e349a12cf..a6cc7da40 100644 --- a/packages/http/src/Session/FormSession.php +++ b/packages/http/src/Session/FormSession.php @@ -14,6 +14,7 @@ final readonly class FormSession { private const string VALIDATION_ERRORS_KEY = '#validation_errors'; + private const string ORIGINAL_VALUES_KEY = '#original_values'; public function __construct( diff --git a/packages/http/src/Session/Installer/DatabaseSessionInstaller.php b/packages/http/src/Session/Installer/DatabaseSessionInstaller.php index 316131f88..6037c7d63 100644 --- a/packages/http/src/Session/Installer/DatabaseSessionInstaller.php +++ b/packages/http/src/Session/Installer/DatabaseSessionInstaller.php @@ -6,6 +6,7 @@ use Tempest\Console\Console; use Tempest\Console\Input\ConsoleArgumentBag; +use Tempest\Console\Input\ConsoleInputArgument; use Tempest\Core\Installer; use Tempest\Core\PublishesFiles; use Tempest\Database\Migrations\MigrationManager; @@ -47,7 +48,7 @@ private function shouldMigrate(): bool { $argument = $this->consoleArgumentBag->get('migrate'); - if ($argument === null || ! is_bool($argument->value)) { + if (! $argument instanceof ConsoleInputArgument || ! is_bool($argument->value)) { return $this->console->confirm('Do you want to execute migrations?'); } diff --git a/packages/http/src/Session/Managers/DatabaseSessionManager.php b/packages/http/src/Session/Managers/DatabaseSessionManager.php index 788eaf564..ad6f1cf96 100644 --- a/packages/http/src/Session/Managers/DatabaseSessionManager.php +++ b/packages/http/src/Session/Managers/DatabaseSessionManager.php @@ -28,7 +28,7 @@ public function getOrCreate(SessionId $id): Session $now = $this->clock->now(); $session = $this->load($id); - if ($session === null) { + if (! $session instanceof Session) { $session = new Session( id: $id, createdAt: $now, diff --git a/packages/http/src/Session/Managers/FileSessionManager.php b/packages/http/src/Session/Managers/FileSessionManager.php index 6cfe992ed..aebe39a59 100644 --- a/packages/http/src/Session/Managers/FileSessionManager.php +++ b/packages/http/src/Session/Managers/FileSessionManager.php @@ -29,7 +29,7 @@ public function getOrCreate(SessionId $id): Session $now = $this->clock->now(); $session = $this->load($id); - if ($session === null) { + if (! $session instanceof Session) { $session = new Session( id: $id, createdAt: $now, @@ -81,7 +81,7 @@ public function deleteExpiredSessions(): void $id = new SessionId(pathinfo($sessionFile, flags: PATHINFO_FILENAME)); $session = $this->load($id); - if ($session === null) { + if (! $session instanceof Session) { continue; } diff --git a/packages/http/src/Session/Managers/RedisSessionManager.php b/packages/http/src/Session/Managers/RedisSessionManager.php index a2450ff4c..6e19e9f4a 100644 --- a/packages/http/src/Session/Managers/RedisSessionManager.php +++ b/packages/http/src/Session/Managers/RedisSessionManager.php @@ -30,7 +30,7 @@ public function getOrCreate(SessionId $id): Session $now = $this->clock->now(); $session = $this->load($id); - if ($session === null) { + if (! $session instanceof Session) { $session = new Session( id: $id, createdAt: $now, @@ -80,7 +80,7 @@ public function deleteExpiredSessions(): void $sessionId = $this->getSessionIdFromKey($key); $session = $this->load($sessionId); - if ($session === null) { + if (! $session instanceof Session) { continue; } diff --git a/packages/http/src/Session/PreviousUrl.php b/packages/http/src/Session/PreviousUrl.php index f5b78c094..9fe22a66e 100644 --- a/packages/http/src/Session/PreviousUrl.php +++ b/packages/http/src/Session/PreviousUrl.php @@ -13,6 +13,7 @@ final readonly class PreviousUrl { private const string PREVIOUS_URL_SESSION_KEY = '#previous_url'; + private const string INTENDED_URL_SESSION_KEY = '#intended_url'; public function __construct( @@ -65,10 +66,6 @@ private function shouldNotTrack(Request $request): bool return true; } - if ($request->headers->get('purpose') === 'prefetch') { - return true; - } - - return false; + return $request->headers->get('purpose') === 'prefetch'; } } diff --git a/packages/http/src/Session/SessionConfig.php b/packages/http/src/Session/SessionConfig.php index 6bbc9264c..425d34025 100644 --- a/packages/http/src/Session/SessionConfig.php +++ b/packages/http/src/Session/SessionConfig.php @@ -10,9 +10,7 @@ interface SessionConfig /** * Time required for a session to expire. */ - public Duration $expiration { - get; - } + public Duration $expiration { get; } public function createManager(Container $container): SessionManager; } diff --git a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php index 0d94bb81e..bbc1d781c 100644 --- a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php +++ b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php @@ -27,6 +27,7 @@ final class PsrRequestToGenericRequestMapperTest extends TestCase { private PsrRequestToGenericRequestMapper $mapper; + private ReflectionMethod $requestMethod; protected function setUp(): void diff --git a/packages/http/tests/StatusTest.php b/packages/http/tests/StatusTest.php index e14d5fbd7..5b16f6a84 100644 --- a/packages/http/tests/StatusTest.php +++ b/packages/http/tests/StatusTest.php @@ -15,7 +15,7 @@ */ final class StatusTest extends TestCase { - private static function descriptionToStatus(string $description): Status + private function descriptionToStatus(string $description): Status { $description = strtoupper( str_replace("'", '', str_replace([' ', '-'], '_', $description)), @@ -30,7 +30,7 @@ public function test_status_code(int $code, string $description): void $status = Status::fromCode($code); $this->assertSame( - self::descriptionToStatus($description), + $this->descriptionToStatus($description), $status, ); diff --git a/packages/icon/src/IconCache.php b/packages/icon/src/IconCache.php index d63070799..d3f3b05f4 100644 --- a/packages/icon/src/IconCache.php +++ b/packages/icon/src/IconCache.php @@ -60,7 +60,7 @@ public function put(string $key, mixed $value, null|Duration|DateTimeInterface $ $expiresAt = DateTime::now()->plus($expiresAt); } - if ($expiresAt !== null) { + if ($expiresAt instanceof DateTimeInterface) { $item = $item->expiresAt($expiresAt->toNativeDateTime()); } diff --git a/packages/idempotency/src/Exceptions/IdempotencyException.php b/packages/idempotency/src/Exceptions/IdempotencyException.php index 989122683..5f0eed9ce 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyException.php +++ b/packages/idempotency/src/Exceptions/IdempotencyException.php @@ -6,6 +6,4 @@ use Exception; -abstract class IdempotencyException extends Exception -{ -} +abstract class IdempotencyException extends Exception {} diff --git a/packages/idempotency/src/Store/CacheIdempotencyStore.php b/packages/idempotency/src/Store/CacheIdempotencyStore.php index cbcad5b9d..1bce72c13 100644 --- a/packages/idempotency/src/Store/CacheIdempotencyStore.php +++ b/packages/idempotency/src/Store/CacheIdempotencyStore.php @@ -44,7 +44,7 @@ public function updateHeartbeat(string $scope, string $key, string $owner, int $ { $record = $this->find($scope, $key); - if ($record === null || $record->state !== IdempotencyState::PENDING || $record->pendingOwner !== $owner) { + if (! $record instanceof IdempotencyRecord || $record->state !== IdempotencyState::PENDING || $record->pendingOwner !== $owner) { return; } diff --git a/packages/idempotency/tests/IdempotencyMiddlewareTest.php b/packages/idempotency/tests/IdempotencyMiddlewareTest.php index 1abdaf995..e23fa37a4 100644 --- a/packages/idempotency/tests/IdempotencyMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotencyMiddlewareTest.php @@ -25,6 +25,7 @@ use Tempest\Idempotency\Fingerprint\RequestFingerprintGenerator; use Tempest\Idempotency\Middleware\IdempotencyMiddleware; use Tempest\Idempotency\Store\CacheIdempotencyStore; +use Tempest\Idempotency\Store\IdempotencyRecord; use Tempest\Idempotency\Store\IdempotencyState; use Tempest\Idempotency\Store\IdempotencyStore; use Tempest\Idempotency\Store\StoredResponse; @@ -694,7 +695,7 @@ public function __construct( private readonly IdempotencyStore $store, ) {} - public function find(string $scope, string $key): ?\Tempest\Idempotency\Store\IdempotencyRecord + public function find(string $scope, string $key): ?IdempotencyRecord { throw new RuntimeException('Simulated store read failure.'); } diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index 52c9c11f4..e0bf1d171 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -338,7 +338,5 @@ final class SyncInventoryHandler { #[Idempotent] #[CommandHandler] - public function handle(SyncInventoryCommand $command): void - { - } + public function handle(SyncInventoryCommand $command): void {} } diff --git a/packages/intl/src/Catalog/CatalogInitializer.php b/packages/intl/src/Catalog/CatalogInitializer.php index db4ac0117..1712c70f5 100644 --- a/packages/intl/src/Catalog/CatalogInitializer.php +++ b/packages/intl/src/Catalog/CatalogInitializer.php @@ -2,6 +2,7 @@ namespace Tempest\Intl\Catalog; +use RuntimeException; use Symfony\Component\Yaml\Yaml; use Tempest\Container\Container; use Tempest\Container\Initializer; @@ -30,7 +31,7 @@ public function initialize(Container $container): Catalog $messages = match (true) { Str\ends_with($path, '.json') => Json\decode($contents), Str\ends_with($path, ['.yaml', '.yml']) => Yaml::parse($contents), - default => throw new \RuntimeException("Unsupported translation file format: {$path}"), + default => throw new RuntimeException("Unsupported translation file format: {$path}"), }; foreach (Arr\dot($messages) as $key => $message) { diff --git a/packages/intl/src/GenericTranslator.php b/packages/intl/src/GenericTranslator.php index 338f5eb85..a8421b6df 100644 --- a/packages/intl/src/GenericTranslator.php +++ b/packages/intl/src/GenericTranslator.php @@ -7,6 +7,7 @@ use Tempest\Intl\IntlConfig; use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; +use Throwable; final readonly class GenericTranslator implements Translator { @@ -34,7 +35,7 @@ public function translateForLocale(Locale $locale, string $key, mixed ...$argume try { return $this->formatter->format(mb_trim($message), ...$arguments); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $this->eventBus?->dispatch(new TranslationFailure( locale: $locale, key: $key, diff --git a/packages/intl/src/Locale.php b/packages/intl/src/Locale.php index faa3bc407..1062777be 100644 --- a/packages/intl/src/Locale.php +++ b/packages/intl/src/Locale.php @@ -829,11 +829,11 @@ public static function default(): self $locale = to_lower_case($language); - if ($script) { + if ($script !== '' && $script !== '0') { $locale .= '_' . upper_first($script); } - if ($region) { + if ($region !== '' && $region !== '0') { $locale .= '_' . to_upper_case($region); } diff --git a/packages/intl/src/MessageFormat/Formatter/FormattingException.php b/packages/intl/src/MessageFormat/Formatter/FormattingException.php index abb0c1de0..26330a1de 100644 --- a/packages/intl/src/MessageFormat/Formatter/FormattingException.php +++ b/packages/intl/src/MessageFormat/Formatter/FormattingException.php @@ -2,9 +2,10 @@ namespace Tempest\Intl\MessageFormat\Formatter; +use Exception; use Tempest\Core\ProvidesContext; -final class FormattingException extends \Exception implements ProvidesContext +final class FormattingException extends Exception implements ProvidesContext { public function __construct( string $message, diff --git a/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php b/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php index c0acb0f83..fea3ed83b 100644 --- a/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php +++ b/packages/intl/src/MessageFormat/Formatter/MessageFormatter.php @@ -108,7 +108,7 @@ private function formatMessage(MessageNode $message): string } elseif ($declaration instanceof LocalDeclaration) { $variableName = $declaration->variable->name->name; - $functionName = $declaration->expression->function + $functionName = $declaration->expression->function instanceof FunctionCall ? (string) $declaration->expression->function->identifier : null; @@ -132,7 +132,7 @@ private function formatMessage(MessageNode $message): string } } - throw new FormattingException('Unknown message type: ' . get_class($message)); + throw new FormattingException('Unknown message type: ' . $message::class); } private function formatComplexBody(ComplexBody $body): string @@ -149,7 +149,7 @@ private function formatComplexBody(ComplexBody $body): string return $this->formatMatcher($body); } - throw new FormattingException('Unknown complex body type: ' . get_class($body)); + throw new FormattingException('Unknown complex body type: ' . $body::class); } private function formatMatcher(Matcher $matcher): string @@ -176,8 +176,9 @@ private function formatMatcher(Matcher $matcher): string $matches = true; $hasWildcard = false; + $counter = count($variant->keys); - for ($i = 0; $i < count($variant->keys); $i++) { + for ($i = 0; $i < $counter; $i++) { $keyNode = $variant->keys[$i]; $variable = $selectorVariables[$i]; @@ -194,7 +195,7 @@ private function formatMatcher(Matcher $matcher): string $variantKey = $keyNode->value; $isMatch = false; - if ($variable->selector) { + if ($variable->selector instanceof SelectorFunction) { $isMatch = $variable->selector->match($variantKey, $variable->value, $variable->parameters); } else { $isMatch = $variable->value === $variantKey; @@ -259,7 +260,7 @@ private function formatPlaceholder(Placeholder $placeholder): string return $this->formatPattern($placeholder->pattern); } - throw new FormattingException('Unknown placeholder type: ' . get_class($placeholder)); + throw new FormattingException('Unknown placeholder type: ' . $placeholder::class); } private function evaluateExpression(Expression $expression): FormattedValue @@ -284,7 +285,7 @@ private function evaluateExpression(Expression $expression): FormattedValue $value = null; // Function-only expressions start with null } - if ($expression->function !== null) { + if ($expression->function instanceof FunctionCall) { $functionName = (string) $expression->function->identifier; $parameters = $this->evaluateOptions($expression->function->options); @@ -293,7 +294,7 @@ private function evaluateExpression(Expression $expression): FormattedValue } } - if ($formattingFunction) { + if ($formattingFunction instanceof FormattingFunction) { return $formattingFunction->format($value, $parameters); } diff --git a/packages/intl/src/MessageFormat/FormattingFunction.php b/packages/intl/src/MessageFormat/FormattingFunction.php index 126884408..fc15e67d3 100644 --- a/packages/intl/src/MessageFormat/FormattingFunction.php +++ b/packages/intl/src/MessageFormat/FormattingFunction.php @@ -9,9 +9,7 @@ interface FormattingFunction /** * Identifier of the formatting function. */ - public string $name { - get; - } + public string $name { get; } /** * Formats the given value with the given parameters. diff --git a/packages/intl/src/MessageFormat/Functions/DateTimeFunction.php b/packages/intl/src/MessageFormat/Functions/DateTimeFunction.php index 9e005dc06..331ad2fb7 100644 --- a/packages/intl/src/MessageFormat/Functions/DateTimeFunction.php +++ b/packages/intl/src/MessageFormat/Functions/DateTimeFunction.php @@ -2,6 +2,7 @@ namespace Tempest\Intl\MessageFormat\Functions; +use RuntimeException; use Tempest\DateTime\DateStyle; use Tempest\DateTime\DateTime; use Tempest\DateTime\TimeStyle; @@ -16,7 +17,7 @@ final class DateTimeFunction implements FormattingFunction public function format(mixed $value, array $parameters): FormattedValue { if (! class_exists(DateTime::class)) { - throw new \RuntimeException('`tempest/datetime` is required to use the `datetime` function.'); + throw new RuntimeException('`tempest/datetime` is required to use the `datetime` function.'); } $datetime = DateTime::parse($value); diff --git a/packages/intl/src/MessageFormat/Functions/NumberFunction.php b/packages/intl/src/MessageFormat/Functions/NumberFunction.php index 13ffa552e..b728176d7 100644 --- a/packages/intl/src/MessageFormat/Functions/NumberFunction.php +++ b/packages/intl/src/MessageFormat/Functions/NumberFunction.php @@ -36,11 +36,7 @@ public function match(string $key, mixed $value, array $parameters): bool return true; } - if ($key === $this->pluralRules->getPluralCategory($this->intlConfig->currentLocale, $number)) { - return true; - } - - return false; + return $key === $this->pluralRules->getPluralCategory($this->intlConfig->currentLocale, $number); } private function matchExists(string $key, mixed $value): bool diff --git a/packages/intl/src/MessageFormat/Markup/IconMarkupFormatter.php b/packages/intl/src/MessageFormat/Markup/IconMarkupFormatter.php index 0aa8e008c..6bb0505f5 100644 --- a/packages/intl/src/MessageFormat/Markup/IconMarkupFormatter.php +++ b/packages/intl/src/MessageFormat/Markup/IconMarkupFormatter.php @@ -2,6 +2,7 @@ namespace Tempest\Intl\MessageFormat\Markup; +use RuntimeException; use Tempest\Container\Container; use Tempest\Icon\Icon; use Tempest\Intl\MessageFormat\StandaloneMarkupFormatter; @@ -21,7 +22,7 @@ public function supportsTag(string $tag): bool public function format(string $tag, array $options): string { if (! class_exists(Icon::class)) { - throw new \RuntimeException('The `tempest\icon` package is required to use the `icon` tag inside a translation string.'); + throw new RuntimeException('The `tempest\icon` package is required to use the `icon` tag inside a translation string.'); } $icon = Str\after_first($tag, 'icon-'); diff --git a/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php b/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php index 95f288065..60aa5974a 100644 --- a/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php +++ b/packages/intl/src/MessageFormat/Parser/MessageFormatParser.php @@ -35,7 +35,9 @@ final class MessageFormatParser { private string $input; + private int $pos = 0; + private int $len; /** @@ -213,6 +215,7 @@ private function parseVariant(): Variant } else { $keys[] = $this->parseLiteral(); } + $this->consumeOptionalWhitespace(); } while ($this->peek() !== '{'); @@ -331,7 +334,7 @@ private function parseExpressionBody(): Expression $this->consumeOptionalWhitespace(); - if ($function === null && $this->peek() === ':') { + if (! $function instanceof FunctionCall && $this->peek() === ':') { $function = $this->parseFunction(); } @@ -349,7 +352,7 @@ private function parseExpressionBody(): Expression return new LiteralExpression($subject, $function, $attributes); } - if ($function !== null) { + if ($function instanceof FunctionCall) { return new FunctionExpression($function, $attributes); } diff --git a/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php b/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php index df661703f..b5a039765 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Declaration/Declaration.php @@ -4,6 +4,4 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Declaration extends Node -{ -} +interface Declaration extends Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Identifier.php b/packages/intl/src/MessageFormat/Parser/Node/Identifier.php index fce8c0649..e6ca4f0bc 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Identifier.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Identifier.php @@ -2,7 +2,9 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -final readonly class Identifier implements Node +use Stringable; + +final readonly class Identifier implements Node, Stringable { public function __construct( public string $name, diff --git a/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php b/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php index 5cb1a7378..815996002 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Key/Key.php @@ -4,6 +4,4 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Key extends Node -{ -} +interface Key extends Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php b/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php index 81d144d04..4512d0147 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Key/WildcardKey.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Key; -final class WildcardKey implements Key -{ -} +final class WildcardKey implements Key {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php b/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php index a50fdfae6..109673762 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Literal/QuotedLiteral.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Literal; -final class QuotedLiteral extends Literal -{ -} +final class QuotedLiteral extends Literal {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php b/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php index 7fda533db..7b1109096 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Literal/UnquotedLiteral.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node\Literal; -final class UnquotedLiteral extends Literal -{ -} +final class UnquotedLiteral extends Literal {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/Node.php b/packages/intl/src/MessageFormat/Parser/Node/Node.php index bea306511..675f8bda3 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Node.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Node.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -interface Node -{ -} +interface Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/ParsingException.php b/packages/intl/src/MessageFormat/Parser/Node/ParsingException.php index c306762ba..14ea21cd9 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/ParsingException.php +++ b/packages/intl/src/MessageFormat/Parser/Node/ParsingException.php @@ -2,7 +2,9 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -final class ParsingException extends \Exception +use Exception; + +final class ParsingException extends Exception { public function __construct( string $message, diff --git a/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php b/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php index 30b38dbd4..94fb62f9b 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php +++ b/packages/intl/src/MessageFormat/Parser/Node/Pattern/Placeholder.php @@ -4,6 +4,4 @@ use Tempest\Intl\MessageFormat\Parser\Node\Node; -interface Placeholder extends Node -{ -} +interface Placeholder extends Node {} diff --git a/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php b/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php index dbc597e90..b0fb3b404 100644 --- a/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php +++ b/packages/intl/src/MessageFormat/Parser/Node/SimpleMessage.php @@ -2,6 +2,4 @@ namespace Tempest\Intl\MessageFormat\Parser\Node; -final class SimpleMessage extends MessageNode -{ -} +final class SimpleMessage extends MessageNode {} diff --git a/packages/intl/src/MessageFormat/SelectorFunction.php b/packages/intl/src/MessageFormat/SelectorFunction.php index 0d2a31207..e3020b3a9 100644 --- a/packages/intl/src/MessageFormat/SelectorFunction.php +++ b/packages/intl/src/MessageFormat/SelectorFunction.php @@ -7,9 +7,7 @@ interface SelectorFunction /** * Identifier of the selector function. */ - public string $name { - get; - } + public string $name { get; } /** * Defines whether the matcher key matches with the given value. diff --git a/packages/intl/src/Number/functions.php b/packages/intl/src/Number/functions.php index e67d01863..6f8b4ad57 100644 --- a/packages/intl/src/Number/functions.php +++ b/packages/intl/src/Number/functions.php @@ -163,13 +163,16 @@ function to_human_readable(int|float $number, int $precision = 0, ?int $maxPreci ]; } - switch (true) { - case floatval($number) === 0.0: - return $precision > 0 ? namespace\format(0, $precision, $maxPrecision) : '0'; - case $number < 0: - return sprintf('-%s', namespace\to_human_readable(Math\abs($number), $precision, $maxPrecision, $units)); - case $number >= 1e15: - return sprintf('%s' . end($units), namespace\to_human_readable($number / 1e15, $precision, $maxPrecision, $units)); + if (floatval($number) === 0.0) { + return $precision > 0 ? namespace\format(0, $precision, $maxPrecision) : '0'; + } + + if ($number < 0) { + return sprintf('-%s', namespace\to_human_readable(Math\abs($number), $precision, $maxPrecision, $units)); + } + + if ($number >= 1e15) { + return sprintf('%s' . end($units), namespace\to_human_readable($number / 1e15, $precision, $maxPrecision, $units)); } $numberExponent = (int) Math\floor(Math\log($number, base: 10)); diff --git a/packages/intl/src/TranslationFailure.php b/packages/intl/src/TranslationFailure.php index 810e7a8cc..726281858 100644 --- a/packages/intl/src/TranslationFailure.php +++ b/packages/intl/src/TranslationFailure.php @@ -3,12 +3,13 @@ namespace Tempest\Intl; use Tempest\Intl\Locale; +use Throwable; final readonly class TranslationFailure { public function __construct( public Locale $locale, public string $key, - public \Throwable $exception, + public Throwable $exception, ) {} } diff --git a/packages/intl/tests/FormatterTest.php b/packages/intl/tests/FormatterTest.php index e7428c305..3bfc6da4e 100644 --- a/packages/intl/tests/FormatterTest.php +++ b/packages/intl/tests/FormatterTest.php @@ -44,8 +44,8 @@ public function test_placeholder_variable(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Hello, {$name}! - TXT, name: 'Jon'); + Hello, {$name}! + TXT, name: 'Jon'); $this->assertSame('Hello, Jon!', $value); } @@ -59,8 +59,8 @@ public function test_format_datetime_function_and_parameters(): void $formatter = new MessageFormatter([$this->createDateTimeFunction()]); $value = $formatter->format(<<<'TXT' - Today is {$today :datetime pattern=|yyyy/MM/dd|}. - TXT, today: '2024-01-01'); + Today is {$today :datetime pattern=|yyyy/MM/dd|}. + TXT, today: '2024-01-01'); $this->assertSame('Today is 2024/01/01.', $value); } @@ -70,8 +70,8 @@ public function test_format_number_function(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - The total was {31 :number style=percent}. - TXT); + The total was {31 :number style=percent}. + TXT); $this->assertSame('The total was 31%.', $value); } @@ -84,12 +84,12 @@ public function test_match_number(int $count, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$aircraft :number} - .match $aircraft - 0 {{pas d‘avion}} - 1 {{un avion}} - * {{{$aircraft} avions}} - TXT, aircraft: $count); + .input {$aircraft :number} + .match $aircraft + 0 {{pas d‘avion}} + 1 {{un avion}} + * {{{$aircraft} avions}} + TXT, aircraft: $count); $this->assertSame($expected, $value); } @@ -99,16 +99,16 @@ public function test_default_input(): void $formatter = new MessageFormatter([]); $value = $formatter->format(<<<'TXT' - .input {$field :string default=unknown} - field is {$field} - TXT); + .input {$field :string default=unknown} + field is {$field} + TXT); $this->assertSame('field is unknown', $value); $value = $formatter->format(<<<'TXT' - .input {$field :string default=unknown} - field is {$field} - TXT, field: 'here'); + .input {$field :string default=unknown} + field is {$field} + TXT, field: 'here'); $this->assertSame('field is here', $value); } @@ -117,8 +117,8 @@ public function test_unquoted_text(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Hello, {world}! - TXT); + Hello, {world}! + TXT); $this->assertSame('Hello, world!', $value); } @@ -127,8 +127,8 @@ public function test_quoted_text(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - My name is {|John Doe|}. - TXT); + My name is {|John Doe|}. + TXT); $this->assertSame('My name is John Doe.', $value); } @@ -137,11 +137,11 @@ public function test_number_matcher(): void { $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number} - .match $count - one {{You have {$count} notification.}} - * {{You have {$count} notifications.}} - TXT, count: 1); + .input {$count :number} + .match $count + one {{You have {$count} notification.}} + * {{You have {$count} notifications.}} + TXT, count: 1); $this->assertSame('You have 1 notification.', $value); } @@ -150,11 +150,11 @@ public function test_number_matcher_exact(): void { $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number select=exact} - .match $count - one {{You have {$count} notification.}} - * {{You have {$count} notifications.}} - TXT, count: 1); + .input {$count :number select=exact} + .match $count + one {{You have {$count} notification.}} + * {{You have {$count} notifications.}} + TXT, count: 1); $this->assertSame('You have 1 notifications.', $value); } @@ -163,12 +163,12 @@ public function test_local_declaration(): void { $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<<'TXT' - .local $val = {foo2 :string} - .match $val - foo {{Foo}} - bar {{Bar}} - * {{No match}} - TXT); + .local $val = {foo2 :string} + .match $val + foo {{Foo}} + bar {{Bar}} + * {{No match}} + TXT); $this->assertSame('No match', $value); } @@ -177,11 +177,11 @@ public function test_local_declarations_unquoted_literals(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .local $x = {42} - .local $y = {number42} - .local $z = {_number} - {{{$x} {$y} {$z}}} - TXT); + .local $x = {42} + .local $y = {number42} + .local $z = {_number} + {{{$x} {$y} {$z}}} + TXT); $this->assertSame('42 number42 _number', $value); } @@ -190,11 +190,11 @@ public function test_local_declarations_quoted_literals(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .local $x = {|@literal|} - .local $y = {|white space|} - .local $z = {|{{curly braces}}|} - {{{$x} {$y} {$z} {|and \\, a backslash|}}} - TXT); + .local $x = {|@literal|} + .local $y = {|white space|} + .local $z = {|{{curly braces}}|} + {{{$x} {$y} {$z} {|and \\, a backslash|}}} + TXT); $this->assertSame('@literal white space {{curly braces}} and \, a backslash', $value); } @@ -203,9 +203,9 @@ public function test_whitespace(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .input {$num :number} - {{ This is the {$num} pattern }} - TXT, num: 5); + .input {$num :number} + {{ This is the {$num} pattern }} + TXT, num: 5); $this->assertSame(' This is the 5 pattern ', $value); } @@ -214,8 +214,8 @@ public function test_escape(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - Backslash: \\, left curly brace \{, right curly brace \} - TXT); + Backslash: \\, left curly brace \{, right curly brace \} + TXT); $this->assertSame('Backslash: \, left curly brace {, right curly brace }', $value); } @@ -224,12 +224,12 @@ public function test_matchers_escape(): void { $formatter = new MessageFormatter(); $value = $formatter->format(<<<'TXT' - .input {$char :string} - .match $char - | | {{You entered a space character.}} - |\|| {{You entered a pipe character.}} - * {{You entered something else.}} - TXT, char: '|'); + .input {$char :string} + .match $char + | | {{You entered a space character.}} + |\|| {{You entered a pipe character.}} + * {{You entered something else.}} + TXT, char: '|'); $this->assertSame('You entered a pipe character.', $value); } @@ -239,12 +239,12 @@ public function test_matchers_number_exact_match(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$numDays :number select=exact} - .match $numDays - 1 {{{$numDays} one}} - 2 {{{$numDays} two}} - 3 {{{$numDays} three}} - TXT, numDays: 2); + .input {$numDays :number select=exact} + .match $numDays + 1 {{{$numDays} one}} + 2 {{{$numDays} two}} + 3 {{{$numDays} three}} + TXT, numDays: 2); $this->assertSame('2 two', $value); } @@ -260,13 +260,13 @@ public function test_matchers_czech(int|float $days, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$days :number} - .match $days - one {{{$days} den}} - few {{{$days} dny}} - many {{{$days} dne}} - * {{{$days} dní}} - TXT, days: $days); + .input {$days :number} + .match $days + one {{{$days} den}} + few {{{$days} dny}} + many {{{$days} dne}} + * {{{$days} dní}} + TXT, days: $days); $this->assertSame($expected, $value); } @@ -279,12 +279,12 @@ public function test_string_function(): void ]); $value = $formatter->format(<<<'TXT' - .input {$operand :string} - .match $operand - 1 {{Number 1}} - one {{String "one"}} - * {{Something else}} - TXT, operand: 1); + .input {$operand :string} + .match $operand + 1 {{Number 1}} + one {{String "one"}} + * {{Something else}} + TXT, operand: 1); $this->assertSame('Number 1', $value); } @@ -298,8 +298,8 @@ public function test_string_formatting(mixed $input, string $expected): void $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<<'TXT' - {$value :string} - TXT, value: $input); + {$value :string} + TXT, value: $input); $this->assertSame($expected, $value); } @@ -316,8 +316,8 @@ public function test_string_formatting_options(mixed $input, string $expected, s $formatter = new MessageFormatter([new StringFunction()]); $value = $formatter->format(<<assertSame($expected, $value); } @@ -327,8 +327,8 @@ public function test_number_currency(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - You have {42 :number style=currency currency=$currency}. - TXT, currency: Currency::USD); + You have {42 :number style=currency currency=$currency}. + TXT, currency: Currency::USD); $this->assertSame('You have $42.00.', $value); } @@ -338,9 +338,9 @@ public function test_shadowing(): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .local $count = {42} - {{The count is: {$count}}} - TXT, count: 32); + .local $count = {42} + {{The count is: {$count}}} + TXT, count: 32); $this->assertSame('The count is: 42', $value); } @@ -353,12 +353,12 @@ public function test_pluralization(int $count, string $expected): void $formatter = new MessageFormatter([$this->createNumberFunction()]); $value = $formatter->format(<<<'TXT' - .input {$count :number} - .match $count - 0 {{No items.}} - one {{1 item.}} - * {{{$count} items.}} - TXT, count: $count); + .input {$count :number} + .match $count + 0 {{No items.}} + one {{1 item.}} + * {{{$count} items.}} + TXT, count: $count); $this->assertSame($expected, $value); } @@ -371,22 +371,22 @@ public function test_multiple_selectors(): void ]); $value = $formatter->format(<<<'TXT' - .input {$hostGender :string} - .input {$guestCount :number} - .match $hostGender $guestCount - female 0 {{{$hostName} does not give a party.}} - female 1 {{{$hostName} invites {$guestName} to her party.}} - female 2 {{{$hostName} invites {$guestName} and one other person to her party.}} - female * {{{$hostName} invites {$guestCount} people, including {$guestName}, to her party.}} - male 0 {{{$hostName} does not give a party.}} - male 1 {{{$hostName} invites {$guestName} to his party.}} - male 2 {{{$hostName} invites {$guestName} and one other person to his party.}} - male * {{{$hostName} invites {$guestCount} people, including {$guestName}, to his party.}} - * 0 {{{$hostName} does not give a party.}} - * 1 {{{$hostName} invites {$guestName} to their party.}} - * 2 {{{$hostName} invites {$guestName} and one other person to their party.}} - * * {{{$hostName} invites {$guestCount} people, including {$guestName}, to their party.}} - TXT, hostGender: 'female', hostName: 'Alice', guestCount: 2, guestName: 'Bob'); + .input {$hostGender :string} + .input {$guestCount :number} + .match $hostGender $guestCount + female 0 {{{$hostName} does not give a party.}} + female 1 {{{$hostName} invites {$guestName} to her party.}} + female 2 {{{$hostName} invites {$guestName} and one other person to her party.}} + female * {{{$hostName} invites {$guestCount} people, including {$guestName}, to her party.}} + male 0 {{{$hostName} does not give a party.}} + male 1 {{{$hostName} invites {$guestName} to his party.}} + male 2 {{{$hostName} invites {$guestName} and one other person to his party.}} + male * {{{$hostName} invites {$guestCount} people, including {$guestName}, to his party.}} + * 0 {{{$hostName} does not give a party.}} + * 1 {{{$hostName} invites {$guestName} to their party.}} + * 2 {{{$hostName} invites {$guestName} and one other person to their party.}} + * * {{{$hostName} invites {$guestCount} people, including {$guestName}, to their party.}} + TXT, hostGender: 'female', hostName: 'Alice', guestCount: 2, guestName: 'Bob'); $this->assertSame('Alice invites Bob and one other person to her party.', $value); } @@ -405,8 +405,8 @@ public function format(mixed $value, array $parameters): FormattedValue ]); $value = $formatter->format(<<<'TXT' - Check out {MessageFormat :uppercase}. - TXT); + Check out {MessageFormat :uppercase}. + TXT); $this->assertSame('Check out MESSAGEFORMAT.', $value); } diff --git a/packages/intl/tests/GenericTranslatorTest.php b/packages/intl/tests/GenericTranslatorTest.php index fcc76a9f8..7863c3a7b 100644 --- a/packages/intl/tests/GenericTranslatorTest.php +++ b/packages/intl/tests/GenericTranslatorTest.php @@ -17,7 +17,9 @@ final class GenericTranslatorTest extends TestCase { private Catalog $catalog; + private Translator $translator; + private IntlConfig $config; protected function setUp(): void @@ -66,12 +68,12 @@ public function test_complex_message(): void $this->config->currentLocale = Locale::FRENCH; $this->catalog->add(Locale::FRENCH, 'aircraft_count', <<<'MF2' - .input {$aircraft :number} - .match $aircraft - 0 {{pas d'avion}} - 1 {{un avion}} - * {{{$aircraft} avions}} - MF2); + .input {$aircraft :number} + .match $aircraft + 0 {{pas d'avion}} + 1 {{un avion}} + * {{{$aircraft} avions}} + MF2); $this->assertSame("pas d'avion", $this->translator->translate('aircraft_count', aircraft: 0)); $this->assertSame('un avion', $this->translator->translate('aircraft_count', aircraft: 1)); diff --git a/packages/intl/tests/LocaleTest.php b/packages/intl/tests/LocaleTest.php index e914d8632..2060115d6 100644 --- a/packages/intl/tests/LocaleTest.php +++ b/packages/intl/tests/LocaleTest.php @@ -5,6 +5,7 @@ namespace Tempest\Intl\Tests; use Generator; +use Override; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Tempest\Intl\Locale; @@ -18,13 +19,13 @@ final class LocaleTest extends TestCase { private ?string $defaultLocale = null; - #[\Override] + #[Override] protected function setUp(): void { $this->defaultLocale = locale_get_default(); } - #[\Override] + #[Override] protected function tearDown(): void { if (null !== $this->defaultLocale) { diff --git a/packages/intl/tests/ParserTest.php b/packages/intl/tests/ParserTest.php index 986091839..913803459 100644 --- a/packages/intl/tests/ParserTest.php +++ b/packages/intl/tests/ParserTest.php @@ -30,9 +30,9 @@ public function test_local_declaration(): void { /** @var ComplexMessage $ast */ $ast = new MessageFormatParser(<<<'MF2' - .local $time = {$launch_date :datetime style=|medium|} - Launch time: {$time} - MF2)->parse(); + .local $time = {$launch_date :datetime style=|medium|} + Launch time: {$time} + MF2)->parse(); $this->assertInstanceOf(ComplexMessage::class, $ast); $this->assertInstanceOf(Text::class, $ast->pattern->elements[0]); @@ -53,12 +53,12 @@ public function test_input_declaration(): void { /** @var ComplexMessage $ast */ $ast = new MessageFormatParser(<<<'MF2' - .input {$numDays :number select=exact} - .match $numDays - 1 {{{$numDays} one}} - 2 {{{$numDays} two}} - 3 {{{$numDays} three}} - MF2)->parse(); + .input {$numDays :number select=exact} + .match $numDays + 1 {{{$numDays} one}} + 2 {{{$numDays} two}} + 3 {{{$numDays} three}} + MF2)->parse(); $this->assertInstanceOf(ComplexMessage::class, $ast); $this->assertInstanceOf(InputDeclaration::class, $ast->declarations[0]); @@ -88,8 +88,8 @@ public function test_input_declaration(): void public function test_function_with_option_quoted_literal(): void { $ast = new MessageFormatParser(<<<'MF2' - Today is {$today :datetime pattern=|yyyy/MM/dd|}. - MF2)->parse(); + Today is {$today :datetime pattern=|yyyy/MM/dd|}. + MF2)->parse(); $this->assertInstanceOf(SimpleMessage::class, $ast); $this->assertInstanceOf(VariableExpression::class, $ast->pattern->elements[1]); diff --git a/packages/kv-store/src/Redis/PhpRedisClient.php b/packages/kv-store/src/Redis/PhpRedisClient.php index 8002e1486..9947924ba 100644 --- a/packages/kv-store/src/Redis/PhpRedisClient.php +++ b/packages/kv-store/src/Redis/PhpRedisClient.php @@ -2,6 +2,7 @@ namespace Tempest\KeyValue\Redis; +use InvalidArgumentException; use Stringable; use Tempest\DateTime\DateTime; use Tempest\DateTime\DateTimeInterface; @@ -57,7 +58,7 @@ public function connect(): void } if ($this->config->options && ! is_associative($this->config->options)) { - throw new \InvalidArgumentException('The `options` property of the Redis configuration must be an associative array.'); + throw new InvalidArgumentException('The `options` property of the Redis configuration must be an associative array.'); } foreach ($this->config->options as $key => $value) { @@ -109,7 +110,7 @@ public function set(Stringable|string $key, mixed $value, null|Duration|DateTime $this->command('SET', ...array_filter([ (string) $key, // key $this->serializeValue($value), // value - $expiration ? 'PX' : null, // ttl format + $expiration instanceof Duration ? 'PX' : null, // ttl format (int) $expiration?->getTotalMilliseconds(), // ttl ])); } diff --git a/packages/kv-store/src/Redis/PredisClient.php b/packages/kv-store/src/Redis/PredisClient.php index d2f01d377..d4a424a87 100644 --- a/packages/kv-store/src/Redis/PredisClient.php +++ b/packages/kv-store/src/Redis/PredisClient.php @@ -72,7 +72,7 @@ public function set(Stringable|string $key, mixed $value, null|Duration|DateTime $this->command('SET', ...array_filter([ (string) $key, // key $this->serializeValue($value), // value - $expiration ? 'PX' : null, // ttl format + $expiration instanceof Duration ? 'PX' : null, // ttl format (int) $expiration?->getTotalMilliseconds(), // ttl ])); } diff --git a/packages/kv-store/src/Redis/Redis.php b/packages/kv-store/src/Redis/Redis.php index 459272789..9793d9146 100644 --- a/packages/kv-store/src/Redis/Redis.php +++ b/packages/kv-store/src/Redis/Redis.php @@ -2,6 +2,7 @@ namespace Tempest\KeyValue\Redis; +use Predis\Client; use Stringable; use Tempest\DateTime\DateTimeInterface; use Tempest\DateTime\Duration; @@ -11,7 +12,7 @@ interface Redis /** * Get the underlying client. This breaks abstraction and should only be used if absolutely necessary. */ - public function getClient(): \Redis|\Predis\Client; + public function getClient(): \Redis|Client; /** * Flushes the Redis database. diff --git a/packages/kv-store/src/Redis/RedisException.php b/packages/kv-store/src/Redis/RedisException.php index ea92d27bd..4e1d824d8 100644 --- a/packages/kv-store/src/Redis/RedisException.php +++ b/packages/kv-store/src/Redis/RedisException.php @@ -4,6 +4,4 @@ use Throwable; -interface RedisException extends Throwable -{ -} +interface RedisException extends Throwable {} diff --git a/packages/kv-store/src/Redis/RedisExtensionWasMissing.php b/packages/kv-store/src/Redis/RedisExtensionWasMissing.php index 19a05154a..be65dae71 100644 --- a/packages/kv-store/src/Redis/RedisExtensionWasMissing.php +++ b/packages/kv-store/src/Redis/RedisExtensionWasMissing.php @@ -4,6 +4,7 @@ use Exception; use Predis; +use Predis\Client; final class RedisExtensionWasMissing extends Exception implements RedisException { @@ -12,7 +13,7 @@ public function __construct(string $fqcn) parent::__construct( 'Redis client not found.' . match ($fqcn) { \Redis::class => ' You may be missing the `redis` extension.', - Predis\Client::class => ' You may need to install the `predis/predis` package.', + Client::class => ' You may need to install the `predis/predis` package.', default => ' Install the `redis` extension or the `predis/predis` package.', }, ); diff --git a/packages/kv-store/src/Redis/RedisInitializer.php b/packages/kv-store/src/Redis/RedisInitializer.php index 9eeccfe57..68339f3dd 100644 --- a/packages/kv-store/src/Redis/RedisInitializer.php +++ b/packages/kv-store/src/Redis/RedisInitializer.php @@ -3,6 +3,7 @@ namespace Tempest\KeyValue\Redis; use Predis; +use Predis\Client; use Tempest\Container\Container; use Tempest\Container\Initializer; use Tempest\Container\Singleton; @@ -33,13 +34,13 @@ private function buildPhpRedisClient(): \Redis return new \Redis(); } - private function buildPredisClient(RedisConfig $config): Predis\Client + private function buildPredisClient(RedisConfig $config): Client { - if (! class_exists(Predis\Client::class)) { - throw new RedisExtensionWasMissing(Predis\Client::class); + if (! class_exists(Client::class)) { + throw new RedisExtensionWasMissing(Client::class); } - return new Predis\Client( + return new Client( parameters: array_filter([ 'scheme' => $config->scheme->value, 'host' => $config->host ?? '127.0.0.1', diff --git a/packages/kv-store/src/Redis/RedisInsightsProvider.php b/packages/kv-store/src/Redis/RedisInsightsProvider.php index 7ef93de84..fb1e803b5 100644 --- a/packages/kv-store/src/Redis/RedisInsightsProvider.php +++ b/packages/kv-store/src/Redis/RedisInsightsProvider.php @@ -3,11 +3,13 @@ namespace Tempest\KeyValue\Redis; use Predis; +use Predis\Client; use Tempest\Container\Container; use Tempest\Core\Insight; use Tempest\Core\InsightsProvider; use Tempest\Core\InsightType; use Tempest\Support\Regex; +use Throwable; final class RedisInsightsProvider implements InsightsProvider { @@ -26,14 +28,14 @@ public function getInsights(): array $version = Regex\get_match($redis->command('info', 'server'), '/redis_version:(?[0-9.]+)/', match: 'version'); return [ - 'Engine' => match (get_class($redis->getClient())) { + 'Engine' => match ($redis->getClient()::class) { \Redis::class => 'Redis extension', - Predis\Client::class => 'Predis', + Client::class => 'Predis', default => new Insight('None', InsightType::WARNING), }, 'Version' => $version ?: new Insight('Unknown', InsightType::WARNING), ]; - } catch (\Throwable) { + } catch (Throwable) { return [ 'Engine' => new Insight('Disconnected', InsightType::ERROR), ]; diff --git a/packages/kv-store/tests/PredisClientTest.php b/packages/kv-store/tests/PredisClientTest.php index 72ee2fa35..16d53ed70 100644 --- a/packages/kv-store/tests/PredisClientTest.php +++ b/packages/kv-store/tests/PredisClientTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\Attributes\PreCondition; use PHPUnit\Framework\TestCase; use Predis; +use Predis\Client; use Tempest\KeyValue\Redis\PredisClient; use Throwable; @@ -16,12 +17,12 @@ final class PredisClientTest extends TestCase #[PreCondition] protected function configure(): void { - if (! class_exists(Predis\Client::class)) { + if (! class_exists(Client::class)) { $this->markTestSkipped('The `predis/predis` package is not installed.'); } $this->redis = new PredisClient( - client: new Predis\Client( + client: new Client( parameters: [ 'scheme' => 'tcp', 'host' => '127.0.0.1', @@ -52,7 +53,7 @@ protected function cleanup(): void public function test_basic(): void { $this->assertSame('response', $this->redis->command('PING', 'response')); - $this->assertInstanceOf(Predis\Client::class, $this->redis->getClient()); + $this->assertInstanceOf(Client::class, $this->redis->getClient()); } public function test_set(): void diff --git a/packages/log/src/Channels/SlackLogChannel.php b/packages/log/src/Channels/SlackLogChannel.php index b080a0aa4..b572d703f 100644 --- a/packages/log/src/Channels/SlackLogChannel.php +++ b/packages/log/src/Channels/SlackLogChannel.php @@ -41,9 +41,9 @@ public function getHandlers(Level $level): array webhookUrl: $this->webhookUrl, channel: $this->channelId, username: $this->username, - level: $level, useAttachment: $this->mode === PresentationMode::BLOCKS || $this->mode === PresentationMode::BLOCKS_WITH_CONTEXT, includeContextAndExtra: $this->mode === PresentationMode::BLOCKS_WITH_CONTEXT, + level: $level, ), ]; } diff --git a/packages/log/src/LogConfig.php b/packages/log/src/LogConfig.php index 4e3502073..f78d94106 100644 --- a/packages/log/src/LogConfig.php +++ b/packages/log/src/LogConfig.php @@ -11,16 +11,12 @@ interface LogConfig extends HasTag /** * An optional prefix displayed in all log messages. By default, the current environment is used. */ - public ?string $prefix { - get; - } + public ?string $prefix { get; } /** * The log channels to which log messages will be sent. * * @var LogChannel[] */ - public array $logChannels { - get; - } + public array $logChannels { get; } } diff --git a/packages/log/src/Logger.php b/packages/log/src/Logger.php index 0ebe03df3..e8ba8017e 100644 --- a/packages/log/src/Logger.php +++ b/packages/log/src/Logger.php @@ -6,6 +6,4 @@ use Psr\Log\LoggerInterface; -interface Logger extends LoggerInterface -{ -} +interface Logger extends LoggerInterface {} diff --git a/packages/log/src/TailLogsCommand.php b/packages/log/src/TailLogsCommand.php index b4cd35543..434909129 100644 --- a/packages/log/src/TailLogsCommand.php +++ b/packages/log/src/TailLogsCommand.php @@ -26,15 +26,7 @@ public function __construct( #[ConsoleCommand('tail:logs', description: 'Tails the project logs', aliases: ['log:tail', 'logs:tail'])] public function __invoke(): void { - $appendLogChannel = null; - - foreach ($this->config->logChannels as $channel) { - if ($channel instanceof AppendLogChannel) { - $appendLogChannel = $channel; - break; - } - } - + $appendLogChannel = array_find($this->config->logChannels, fn ($channel) => $channel instanceof AppendLogChannel); if ($appendLogChannel === null) { $this->console->error('Tailing logs is only supported when a AppendLogChannel is configured.'); return; diff --git a/packages/log/src/logging.config.php b/packages/log/src/logging.config.php index 227806df9..696b2e2ea 100644 --- a/packages/log/src/logging.config.php +++ b/packages/log/src/logging.config.php @@ -9,6 +9,6 @@ return new DailyLogConfig( path: Tempest\internal_storage_path('logs', 'tempest.log'), - prefix: Tempest\env('ENVIRONMENT', default: 'tempest'), maxFiles: Tempest\env('LOG_MAX_FILES', default: 31), + prefix: Tempest\env('ENVIRONMENT', default: 'tempest'), ); diff --git a/packages/mail/src/Email.php b/packages/mail/src/Email.php index d8221cfdb..74a856af4 100644 --- a/packages/mail/src/Email.php +++ b/packages/mail/src/Email.php @@ -12,14 +12,10 @@ interface Email /** * The envelope of the email. */ - public Envelope $envelope { - get; - } + public Envelope $envelope { get; } /** * The content of the email can be a path to a view file, raw HTML, or a View object */ - public string|View $html { - get; - } + public string|View $html { get; } } diff --git a/packages/mail/src/Exceptions/MailerException.php b/packages/mail/src/Exceptions/MailerException.php index fc51bd89c..0a4747668 100644 --- a/packages/mail/src/Exceptions/MailerException.php +++ b/packages/mail/src/Exceptions/MailerException.php @@ -2,6 +2,4 @@ namespace Tempest\Mail\Exceptions; -interface MailerException -{ -} +interface MailerException {} diff --git a/packages/mail/src/HasAttachments.php b/packages/mail/src/HasAttachments.php index 70423315c..6ef8742ff 100644 --- a/packages/mail/src/HasAttachments.php +++ b/packages/mail/src/HasAttachments.php @@ -7,7 +7,5 @@ interface HasAttachments /** * @var \Tempest\Mail\Attachment[] $attachments */ - public array $attachments { - get; - } + public array $attachments { get; } } diff --git a/packages/mail/src/HasTextContent.php b/packages/mail/src/HasTextContent.php index d1e5e6f95..d4b6a33c6 100644 --- a/packages/mail/src/HasTextContent.php +++ b/packages/mail/src/HasTextContent.php @@ -6,7 +6,5 @@ interface HasTextContent { - public string|View|null $text { - get; - } + public string|View|null $text { get; } } diff --git a/packages/mail/src/MailerConfig.php b/packages/mail/src/MailerConfig.php index 4cbfbb618..28c1ac6f4 100644 --- a/packages/mail/src/MailerConfig.php +++ b/packages/mail/src/MailerConfig.php @@ -11,9 +11,7 @@ interface MailerConfig * * @var class-string */ - public string $transport { - get; - } + public string $transport { get; } /** * Creates the transport. diff --git a/packages/mail/src/Testing/MailTester.php b/packages/mail/src/Testing/MailTester.php index 1d19951bc..0dc014b71 100644 --- a/packages/mail/src/Testing/MailTester.php +++ b/packages/mail/src/Testing/MailTester.php @@ -52,7 +52,7 @@ public function assertSent(string $email, ?Closure $callback = null): self message: sprintf('Email `%s` was not sent.', $email), ); - if ($callback) { + if ($callback instanceof Closure) { try { if ($callback($sentEmail) === false) { throw new ExpectationFailedException('The assertion callback returned `false`.'); @@ -444,12 +444,10 @@ private function assertAddressListDoesNotContain(null|string|array|EmailAddress private function convertAddresses(null|string|array|EmailAddress $addresses): array { return arr($addresses) - ->map(function (string|EmailAddress|SymfonyAddress $address) { - return match (true) { - $address instanceof SymfonyAddress => $address->getAddress(), - $address instanceof EmailAddress => $address->email, - default => $address, - }; + ->map(fn (string|EmailAddress|SymfonyAddress $address) => match (true) { + $address instanceof SymfonyAddress => $address->getAddress(), + $address instanceof EmailAddress => $address->email, + default => $address, }) ->filter() ->toArray(); diff --git a/packages/mail/src/Transports/ProvidesDefaultSender.php b/packages/mail/src/Transports/ProvidesDefaultSender.php index 20486a443..fceb3701a 100644 --- a/packages/mail/src/Transports/ProvidesDefaultSender.php +++ b/packages/mail/src/Transports/ProvidesDefaultSender.php @@ -9,7 +9,5 @@ interface ProvidesDefaultSender /** * The default address from which emails will be sent. */ - public null|string|EmailAddress $defaultSender { - get; - } + public null|string|EmailAddress $defaultSender { get; } } diff --git a/packages/mapper/src/CasterFactory.php b/packages/mapper/src/CasterFactory.php index f9f488a27..43fcd6268 100644 --- a/packages/mapper/src/CasterFactory.php +++ b/packages/mapper/src/CasterFactory.php @@ -65,19 +65,17 @@ public function forProperty(PropertyReflector $property): ?Caster $castWith = $type->asClass()->getAttribute(CastWith::class, recursive: true); } - if ($castWith) { + if ($castWith instanceof CastWith) { return $this->container->get($castWith->className, context: $context); } - if ($casterAttribute = $property->getAttribute(ProvidesCaster::class)) { + if (($casterAttribute = $property->getAttribute(ProvidesCaster::class)) instanceof ProvidesCaster) { return $this->container->get($casterAttribute->caster, context: $context); } foreach ($this->resolveCasters() as [$casterClass]) { - if (is_a($casterClass, DynamicCaster::class, allow_string: true)) { - if (! $casterClass::accepts($property)) { - continue; - } + if (is_a($casterClass, DynamicCaster::class, allow_string: true) && ! $casterClass::accepts($property)) { + continue; } if (is_a($casterClass, ConfigurableCaster::class, allow_string: true)) { diff --git a/packages/mapper/src/Casters/ArrayToObjectCollectionCaster.php b/packages/mapper/src/Casters/ArrayToObjectCollectionCaster.php index 12e99b11f..67cdb2a75 100644 --- a/packages/mapper/src/Casters/ArrayToObjectCollectionCaster.php +++ b/packages/mapper/src/Casters/ArrayToObjectCollectionCaster.php @@ -26,7 +26,7 @@ public static function accepts(PropertyReflector|TypeReflector $input): bool return false; } - return $input->getIterableType() !== null; + return $input->getIterableType() instanceof TypeReflector; } public static function configure(PropertyReflector $property, Context $context): self @@ -53,11 +53,7 @@ public function cast(mixed $input): mixed $values = []; foreach ($input as $key => $item) { - if (is_object($item) && $iterableType->matches($item::class)) { - $values[$key] = $item; - } else { - $values[$key] = $caster->cast($item); - } + $values[$key] = is_object($item) && $iterableType->matches($item::class) ? $item : $caster->cast($item); } return $values; diff --git a/packages/mapper/src/Casters/DateTimeCaster.php b/packages/mapper/src/Casters/DateTimeCaster.php index f6b42f420..c3a11ae84 100644 --- a/packages/mapper/src/Casters/DateTimeCaster.php +++ b/packages/mapper/src/Casters/DateTimeCaster.php @@ -15,6 +15,7 @@ use Tempest\Reflection\PropertyReflector; use Tempest\Reflection\TypeReflector; use Tempest\Validation\Rules\HasDateTimeFormat; +use Throwable; #[Priority(Priority::HIGHEST)] final readonly class DateTimeCaster implements Caster, DynamicCaster, ConfigurableCaster @@ -55,7 +56,7 @@ public function cast(mixed $input): ?DateTimeInterface } return DateTime::parse($input); - } catch (\Throwable) { + } catch (Throwable) { return null; } } diff --git a/packages/mapper/src/Casters/EnumCaster.php b/packages/mapper/src/Casters/EnumCaster.php index c3fa26e67..7de8fba52 100644 --- a/packages/mapper/src/Casters/EnumCaster.php +++ b/packages/mapper/src/Casters/EnumCaster.php @@ -4,6 +4,7 @@ namespace Tempest\Mapper\Casters; +use BackedEnum; use Tempest\Core\Priority; use Tempest\Mapper\Caster; use Tempest\Mapper\ConfigurableCaster; @@ -51,7 +52,7 @@ public function cast(mixed $input): ?object return constant("{$this->enum}::{$input}"); } - if (! is_a($this->enum, \BackedEnum::class, allow_string: true)) { + if (! is_a($this->enum, BackedEnum::class, allow_string: true)) { return null; } diff --git a/packages/mapper/src/Context.php b/packages/mapper/src/Context.php index 917e1d8b7..444d8f179 100644 --- a/packages/mapper/src/Context.php +++ b/packages/mapper/src/Context.php @@ -10,7 +10,5 @@ interface Context /** * A unique name for this context. */ - public string $name { - get; - } + public string $name { get; } } diff --git a/packages/mapper/src/Exceptions/MappingValuesWereMissing.php b/packages/mapper/src/Exceptions/MappingValuesWereMissing.php index 64782e50c..d9bb0caaa 100644 --- a/packages/mapper/src/Exceptions/MappingValuesWereMissing.php +++ b/packages/mapper/src/Exceptions/MappingValuesWereMissing.php @@ -10,11 +10,7 @@ final class MappingValuesWereMissing extends Exception { public function __construct(object|string $objectOrClass, array $missingValues) { - if (is_string($objectOrClass)) { - $className = $objectOrClass; - } else { - $className = $objectOrClass::class; - } + $className = is_string($objectOrClass) ? $objectOrClass : $objectOrClass::class; $missingValues = implode(', ', $missingValues); diff --git a/packages/mapper/src/Hidden.php b/packages/mapper/src/Hidden.php index 9c9e94f05..964c4379c 100644 --- a/packages/mapper/src/Hidden.php +++ b/packages/mapper/src/Hidden.php @@ -10,6 +10,4 @@ * Hidden properties are excluded from SELECT queries and serialization. */ #[Attribute(Attribute::TARGET_PROPERTY)] -final readonly class Hidden -{ -} +final readonly class Hidden {} diff --git a/packages/mapper/src/Mappers/ArrayToObjectMapper.php b/packages/mapper/src/Mappers/ArrayToObjectMapper.php index 3d95d8645..8b4ff4bc7 100644 --- a/packages/mapper/src/Mappers/ArrayToObjectMapper.php +++ b/packages/mapper/src/Mappers/ArrayToObjectMapper.php @@ -12,6 +12,7 @@ use Tempest\Mapper\Strict; use Tempest\Reflection\ClassReflector; use Tempest\Reflection\PropertyReflector; +use Tempest\Reflection\TypeReflector; use Tempest\Support\Arr; use Tempest\Support\Memoization\HasMemoization; use Throwable; @@ -122,7 +123,11 @@ private function resolveObject(mixed $objectOrClass): object private function setParentRelations(object $parent, ClassReflector $parentClass): void { foreach ($parentClass->getPublicProperties() as $property) { - if (! $property->isInitialized($parent) || $property->isVirtual()) { + if (! $property->isInitialized($parent)) { + continue; + } + + if ($property->isVirtual()) { continue; } @@ -165,11 +170,9 @@ private function setChildParentRelation(object $parent, mixed $child, ClassRefle public function resolveValue(PropertyReflector $property, mixed $value): mixed { - $caster = $this->memoize((string) $property, function () use ($property) { - return $this->casterFactory - ->in($this->context) - ->forProperty($property); - }); + $caster = $this->memoize((string) $property, fn () => $this->casterFactory + ->in($this->context) + ->forProperty($property)); if ($property->isNullable() && $value === null) { return null; @@ -179,7 +182,7 @@ public function resolveValue(PropertyReflector $property, mixed $value): mixed return $value; } - if ($property->getIterableType() !== null) { + if ($property->getIterableType() instanceof TypeReflector) { return $caster->cast($value); } diff --git a/packages/mapper/src/Mappers/ObjectToArrayMapper.php b/packages/mapper/src/Mappers/ObjectToArrayMapper.php index f72f411d2..72083e0f7 100644 --- a/packages/mapper/src/Mappers/ObjectToArrayMapper.php +++ b/packages/mapper/src/Mappers/ObjectToArrayMapper.php @@ -9,6 +9,7 @@ use Tempest\Mapper\Hidden; use Tempest\Mapper\Mapper; use Tempest\Mapper\MapTo; +use Tempest\Mapper\Serializer; use Tempest\Mapper\SerializerFactory; use Tempest\Reflection\ClassReflector; use Tempest\Reflection\PropertyReflector; @@ -72,7 +73,7 @@ private function resolvePropertyValue(PropertyReflector $property, object $objec return $propertyValue; } - if ($propertyValue !== null && ($serializer = $this->serializerFactory->in($this->context)->forProperty($property)) !== null) { + if ($propertyValue !== null && ($serializer = $this->serializerFactory->in($this->context)->forProperty($property)) instanceof Serializer) { return $serializer->serialize($propertyValue); } diff --git a/packages/mapper/src/MappingContext.php b/packages/mapper/src/MappingContext.php index 1215c1f33..b75ee40d9 100644 --- a/packages/mapper/src/MappingContext.php +++ b/packages/mapper/src/MappingContext.php @@ -18,7 +18,7 @@ public static function default(): Context public static function from(Context|UnitEnum|string|null $context): Context { - if (! $context) { + if ($context === null) { return self::default(); } diff --git a/packages/mapper/src/ProvidesCaster.php b/packages/mapper/src/ProvidesCaster.php index 921357c6a..9d23e9aa5 100644 --- a/packages/mapper/src/ProvidesCaster.php +++ b/packages/mapper/src/ProvidesCaster.php @@ -8,7 +8,5 @@ interface ProvidesCaster { /** @var class-string */ - public string $caster { - get; - } + public string $caster { get; } } diff --git a/packages/mapper/src/ProvidesSerializer.php b/packages/mapper/src/ProvidesSerializer.php index 86efbfb38..0f9cab41b 100644 --- a/packages/mapper/src/ProvidesSerializer.php +++ b/packages/mapper/src/ProvidesSerializer.php @@ -8,7 +8,5 @@ interface ProvidesSerializer { /** @var class-string */ - public string $serializer { - get; - } + public string $serializer { get; } } diff --git a/packages/mapper/src/SerializationMapDiscovery.php b/packages/mapper/src/SerializationMapDiscovery.php index 72dc82d4b..0a526b274 100644 --- a/packages/mapper/src/SerializationMapDiscovery.php +++ b/packages/mapper/src/SerializationMapDiscovery.php @@ -17,7 +17,7 @@ public function __construct( public function discover(DiscoveryLocation $location, ClassReflector $class): void { - if ($attribute = $class->getAttribute(SerializeAs::class)) { + if (($attribute = $class->getAttribute(SerializeAs::class)) instanceof SerializeAs) { $this->discoveryItems->add($location, [$class->getName(), $attribute->name]); } } diff --git a/packages/mapper/src/SerializerFactory.php b/packages/mapper/src/SerializerFactory.php index 5917fd6d0..2bbe04b11 100644 --- a/packages/mapper/src/SerializerFactory.php +++ b/packages/mapper/src/SerializerFactory.php @@ -71,15 +71,13 @@ public function forProperty(PropertyReflector $property): ?Serializer return $this->container->get($serializeWith->className, context: $context); } - if ($serializerAttribute = $property->getAttribute(ProvidesSerializer::class)) { + if (($serializerAttribute = $property->getAttribute(ProvidesSerializer::class)) instanceof ProvidesSerializer) { return $this->container->get($serializerAttribute->serializer, context: $context); } foreach ($this->resolveSerializers() as [$serializerClass]) { - if (is_a($serializerClass, DynamicSerializer::class, allow_string: true)) { - if (! $serializerClass::accepts($property)) { - continue; - } + if (is_a($serializerClass, DynamicSerializer::class, allow_string: true) && ! $serializerClass::accepts($property)) { + continue; } return $this->resolveSerializer($serializerClass, $property); @@ -102,10 +100,8 @@ public function forValue(mixed $value): ?Serializer } foreach ($this->resolveSerializers() as [$serializerClass]) { - if (is_a($serializerClass, DynamicSerializer::class, allow_string: true)) { - if (! $serializerClass::accepts($input)) { - continue; - } + if (is_a($serializerClass, DynamicSerializer::class, allow_string: true) && ! $serializerClass::accepts($input)) { + continue; } return $this->resolveSerializer($serializerClass, $input); diff --git a/packages/mapper/src/Serializers/ArrayOfObjectsSerializer.php b/packages/mapper/src/Serializers/ArrayOfObjectsSerializer.php index 0d3a71c7c..0a8af6346 100644 --- a/packages/mapper/src/Serializers/ArrayOfObjectsSerializer.php +++ b/packages/mapper/src/Serializers/ArrayOfObjectsSerializer.php @@ -23,7 +23,7 @@ public static function accepts(PropertyReflector|TypeReflector $input): bool return false; } - return $input->getIterableType() !== null; + return $input->getIterableType() instanceof TypeReflector; } public function serialize(mixed $input): array diff --git a/packages/mapper/src/Strict.php b/packages/mapper/src/Strict.php index 35a389a17..5f2593655 100644 --- a/packages/mapper/src/Strict.php +++ b/packages/mapper/src/Strict.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] -final readonly class Strict -{ -} +final readonly class Strict {} diff --git a/packages/mapper/src/UnknownValue.php b/packages/mapper/src/UnknownValue.php index 170a5c712..e7b599665 100644 --- a/packages/mapper/src/UnknownValue.php +++ b/packages/mapper/src/UnknownValue.php @@ -4,6 +4,4 @@ namespace Tempest\Mapper; -final readonly class UnknownValue -{ -} +final readonly class UnknownValue {} diff --git a/packages/process/src/Exceptions/ProcessException.php b/packages/process/src/Exceptions/ProcessException.php index 00c0f6925..7d00205de 100644 --- a/packages/process/src/Exceptions/ProcessException.php +++ b/packages/process/src/Exceptions/ProcessException.php @@ -4,6 +4,4 @@ use Throwable; -interface ProcessException extends Throwable -{ -} +interface ProcessException extends Throwable {} diff --git a/packages/process/src/GenericProcessExecutor.php b/packages/process/src/GenericProcessExecutor.php index 0683b9b22..5cda6fc7a 100644 --- a/packages/process/src/GenericProcessExecutor.php +++ b/packages/process/src/GenericProcessExecutor.php @@ -3,6 +3,7 @@ namespace Tempest\Process; use Symfony\Component\Process\Process as SymfonyProcess; +use Tempest\DateTime\Duration; use Tempest\Support\Arr\ImmutableArray; final class GenericProcessExecutor implements ProcessExecutor @@ -52,7 +53,7 @@ private function createSymfonyProcess(PendingProcess $pending): SymfonyProcess $process->setWorkingDirectory((string) ($pending->path ?? getcwd())); $process->setTimeout($pending->timeout?->getTotalSeconds()); - if ($pending->idleTimeout) { + if ($pending->idleTimeout instanceof Duration) { $process->setIdleTimeout($pending->idleTimeout->getTotalSeconds()); } diff --git a/packages/process/src/InvokedProcess.php b/packages/process/src/InvokedProcess.php index 7465f258c..216abf422 100644 --- a/packages/process/src/InvokedProcess.php +++ b/packages/process/src/InvokedProcess.php @@ -9,30 +9,22 @@ interface InvokedProcess /** * Gets the process identifier. */ - public ?int $pid { - get; - } + public ?int $pid { get; } /** * Whether the process is running. */ - public bool $running { - get; - } + public bool $running { get; } /** * Gets the output of the process. */ - public string $output { - get; - } + public string $output { get; } /** * Gets the error output of the process. */ - public string $errorOutput { - get; - } + public string $errorOutput { get; } /** * Sends a signal to the process. diff --git a/packages/process/src/InvokedProcessPool.php b/packages/process/src/InvokedProcessPool.php index 1e8598bb1..949a6a139 100644 --- a/packages/process/src/InvokedProcessPool.php +++ b/packages/process/src/InvokedProcessPool.php @@ -64,7 +64,7 @@ public function wait(): ProcessPoolResults * * @param Closure(InvokedProcess): mixed $callback */ - public function forEachRunning(\Closure $callback): self + public function forEachRunning(Closure $callback): self { $this->running->each(fn (InvokedProcess $process) => $callback($process)); @@ -76,7 +76,7 @@ public function forEachRunning(\Closure $callback): self * * @param Closure(InvokedProcess): mixed $callback */ - public function forEach(\Closure $callback): self + public function forEach(Closure $callback): self { $this->processes->each(fn (InvokedProcess $process) => $callback($process)); diff --git a/packages/process/src/OutputChannel.php b/packages/process/src/OutputChannel.php index fa3f546c6..bdc1b8247 100644 --- a/packages/process/src/OutputChannel.php +++ b/packages/process/src/OutputChannel.php @@ -3,6 +3,7 @@ namespace Tempest\Process; use Symfony\Component\Process\Process; +use UnexpectedValueException; enum OutputChannel: string { @@ -14,7 +15,7 @@ public static function fromSymfonyOutputType(string $type): self return match ($type) { Process::OUT => self::OUTPUT, Process::ERR => self::ERROR, - default => throw new \UnexpectedValueException(sprintf('Unsupported output type "%s".', $type)), + default => throw new UnexpectedValueException(sprintf('Unsupported output type "%s".', $type)), }; } } diff --git a/packages/process/src/ProcessPoolResults.php b/packages/process/src/ProcessPoolResults.php index 5bf7a55fa..7379fab64 100644 --- a/packages/process/src/ProcessPoolResults.php +++ b/packages/process/src/ProcessPoolResults.php @@ -3,6 +3,7 @@ namespace Tempest\Process; use ArrayAccess; +use BadMethodCallException; use Countable; use Iterator; use Tempest\Support\Arr\ImmutableArray; @@ -109,12 +110,12 @@ public function offsetGet(mixed $offset): ProcessResult public function offsetSet(mixed $offset, mixed $value): void { - throw new \BadMethodCallException('ProcessPoolResults is immutable and cannot be modified.'); + throw new BadMethodCallException('ProcessPoolResults is immutable and cannot be modified.'); } public function offsetUnset(mixed $offset): void { - throw new \BadMethodCallException('ProcessPoolResults is immutable and cannot be modified.'); + throw new BadMethodCallException('ProcessPoolResults is immutable and cannot be modified.'); } public function count(): int diff --git a/packages/process/src/Testing/InvokedTestingProcess.php b/packages/process/src/Testing/InvokedTestingProcess.php index 9a1938302..a9180d4aa 100644 --- a/packages/process/src/Testing/InvokedTestingProcess.php +++ b/packages/process/src/Testing/InvokedTestingProcess.php @@ -2,6 +2,7 @@ namespace Tempest\Process\Testing; +use Closure; use Tempest\DateTime\Duration; use Tempest\Process\InvokedProcess; use Tempest\Process\OutputChannel; @@ -72,7 +73,7 @@ final class InvokedTestingProcess implements InvokedProcess * * @var null|\Closure(OutputChannel, string): void */ - private ?\Closure $outputHandler = null; + private ?Closure $outputHandler = null; /** * The number of times the process should indicate that it is "running". @@ -118,12 +119,12 @@ public function stop(float|int|Duration $timeout = 10, ?int $signal = null): sel public function wait(?callable $output = null): ProcessResult { if ($output !== null) { - $this->outputHandler = $output instanceof \Closure + $this->outputHandler = $output instanceof Closure ? $output - : \Closure::fromCallable($output); + : Closure::fromCallable($output); } - if (! $this->outputHandler) { + if (! $this->outputHandler instanceof Closure) { $this->remainingRunIterations = 0; return $this->getProcessResult(); @@ -185,7 +186,7 @@ public function latestErrorOutput(): string */ private function invokeOutputHandlerWithNextLineOfOutput(): bool { - if (! $this->outputHandler) { + if (! $this->outputHandler instanceof Closure) { return false; } diff --git a/packages/process/src/Testing/ProcessTester.php b/packages/process/src/Testing/ProcessTester.php index ba75c8d33..f08d5d3f1 100644 --- a/packages/process/src/Testing/ProcessTester.php +++ b/packages/process/src/Testing/ProcessTester.php @@ -5,6 +5,7 @@ use Closure; use PHPUnit\Framework\Assert; use PHPUnit\Framework\ExpectationFailedException; +use RuntimeException; use Tempest\Container\Container; use Tempest\Container\Singleton; use Tempest\Process\GenericProcessExecutor; @@ -73,7 +74,7 @@ public function allowRunningActualProcesses(): void { $this->allowRunningActualProcesses = true; - if ($this->executor) { + if ($this->executor instanceof TestingProcessExecutor) { $this->executor->allowRunningActualProcesses = true; } else { $this->recordProcessExecutions(); @@ -87,7 +88,7 @@ public function preventRunningActualProcesses(): void { $this->allowRunningActualProcesses = false; - if ($this->executor) { + if ($this->executor instanceof TestingProcessExecutor) { $this->executor->allowRunningActualProcesses = false; } else { $this->recordProcessExecutions(); @@ -109,7 +110,7 @@ public function debugExecutedProcesses(): never { $this->ensureTestingSetUp(); - throw new \RuntimeException(var_export($this->executor->executions, true)); + throw new RuntimeException(var_export($this->executor->executions, true)); } /** @@ -125,7 +126,7 @@ public function describe(): InvokedProcessDescription * * @param null|Closure(): mixed|Closure(ProcessResult): mixed|Closure(ProcessResult, PendingProcess): mixed $callback */ - public function assertCommandRan(string $command, ?\Closure $callback = null): self + public function assertCommandRan(string $command, ?Closure $callback = null): self { $this->ensureTestingSetUp(); @@ -160,7 +161,7 @@ public function assertCommandRan(string $command, ?\Closure $callback = null): s * * @param Closure(PendingProcess): mixed|Closure(PendingProcess, ProcessResult): mixed $callback */ - public function assertRan(\Closure $callback): self + public function assertRan(Closure $callback): self { $this->ensureTestingSetUp(); @@ -188,7 +189,7 @@ public function assertRan(\Closure $callback): self * * @param string|Closure(): mixed|Closure(PendingProcess): mixed|Closure(PendingProcess, ProcessResult): mixed $command */ - public function assertCommandDidNotRun(string|\Closure $command): self + public function assertCommandDidNotRun(string|Closure $command): self { $this->ensureTestingSetUp(); @@ -238,11 +239,11 @@ public function assertNothingRan(): self * * @param string|\Closure(PendingProcess,ProcessResult):bool $command */ - public function assertRanTimes(string|\Closure $command, int $times): self + public function assertRanTimes(string|Closure $command, int $times): self { $this->ensureTestingSetUp(); - if ($command instanceof \Closure) { + if ($command instanceof Closure) { $count = 0; foreach ($this->executor->executions as $executions) { foreach ($executions as [$process, $result]) { diff --git a/packages/process/src/Testing/TestingProcessExecutor.php b/packages/process/src/Testing/TestingProcessExecutor.php index 0b5381e18..c40f6d291 100644 --- a/packages/process/src/Testing/TestingProcessExecutor.php +++ b/packages/process/src/Testing/TestingProcessExecutor.php @@ -2,6 +2,7 @@ namespace Tempest\Process\Testing; +use RuntimeException; use Tempest\Process\GenericProcessExecutor; use Tempest\Process\InvokedProcess; use Tempest\Process\InvokedSystemProcess; @@ -29,7 +30,7 @@ public function __construct( public function run(string|PendingProcess $command): ProcessResult { - if ($result = $this->findMockedProcess($command)) { + if (($result = $this->findMockedProcess($command)) instanceof ProcessResult) { return $this->recordExecution($command, $result); } @@ -42,7 +43,7 @@ public function run(string|PendingProcess $command): ProcessResult public function start(string|PendingProcess $command): InvokedProcess { - if ($processResult = $this->findInvokedProcessDescription($command)) { + if (($processResult = $this->findInvokedProcessDescription($command)) instanceof InvokedProcessDescription) { $this->recordExecution($command, $process = new InvokedTestingProcess($processResult)); } else { if (! $this->allowRunningActualProcesses) { @@ -117,7 +118,7 @@ private function recordExecution(string|PendingProcess $command, InvokedProcess| $result instanceof ProcessResult => $result, $result instanceof InvokedTestingProcess => $result->getProcessResult(), $result instanceof InvokedSystemProcess => $result->wait(), // TODO: fix - default => throw new \RuntimeException('Unexpected result type.'), + default => throw new RuntimeException('Unexpected result type.'), }; $this->executions[$process->command] ??= []; diff --git a/packages/reflection/src/ClassReflector.php b/packages/reflection/src/ClassReflector.php index 3a388beef..5c0797719 100644 --- a/packages/reflection/src/ClassReflector.php +++ b/packages/reflection/src/ClassReflector.php @@ -19,6 +19,7 @@ final class ClassReflector implements Reflector private array $memoize = []; private readonly PHPReflectionClass $reflectionClass; + private string $name; /** @@ -157,19 +158,19 @@ public function newInstanceArgs(array $args = []): object public function callStatic(string $method, mixed ...$args): mixed { - $className = $this->getName(); + $className = $this->name; return $className::$method(...$args); } public function is(string $className): bool { - return is_a($this->getName(), $className, allow_string: true); + return is_a($this->name, $className, allow_string: true); } public function implements(string $interface): bool { - return $this->isInstantiable() && is_a($this->getName(), $interface, allow_string: true); + return $this->isInstantiable() && is_a($this->name, $interface, allow_string: true); } private function memoize(string $key, Closure $closure): mixed @@ -183,7 +184,7 @@ private function memoize(string $key, Closure $closure): mixed public function __serialize(): array { - return ['name' => $this->getName()]; + return ['name' => $this->name]; } public function __unserialize(array $data): void diff --git a/packages/reflection/src/EnumReflector.php b/packages/reflection/src/EnumReflector.php index f1d204b56..a60f04b9f 100644 --- a/packages/reflection/src/EnumReflector.php +++ b/packages/reflection/src/EnumReflector.php @@ -7,6 +7,7 @@ use Closure; use ReflectionEnum as PHPReflectionEnum; use ReflectionEnumUnitCase; +use ReflectionNamedType; use UnitEnum; /** @@ -73,7 +74,7 @@ public function getBackingType(): ?TypeReflector { $backingType = $this->reflectionEnum->getBackingType(); - if ($backingType === null) { + if (! $backingType instanceof ReflectionNamedType) { return null; } diff --git a/packages/reflection/src/HasAttributes.php b/packages/reflection/src/HasAttributes.php index 14ac25898..0a82ccbda 100644 --- a/packages/reflection/src/HasAttributes.php +++ b/packages/reflection/src/HasAttributes.php @@ -72,7 +72,7 @@ private function instantiate(?ReflectionAttribute $attribute): ?object { $object = $attribute?->newInstance(); - if (! $object) { + if ($object === null) { return null; } diff --git a/packages/reflection/src/MethodReflector.php b/packages/reflection/src/MethodReflector.php index 6667e8cb0..523287b13 100644 --- a/packages/reflection/src/MethodReflector.php +++ b/packages/reflection/src/MethodReflector.php @@ -7,13 +7,14 @@ use Generator; use ReflectionMethod as PHPReflectionMethod; use ReflectionParameter; +use ReflectionType; -final class MethodReflector implements Reflector +final readonly class MethodReflector implements Reflector { use HasAttributes; public function __construct( - private readonly PHPReflectionMethod $reflectionMethod, + private PHPReflectionMethod $reflectionMethod, ) {} public static function fromParts(string|object $class, string $name): self @@ -55,7 +56,7 @@ public function invokeArgs(?object $object, array $args = []): mixed public function getReturnType(): ?TypeReflector { - if ($this->reflectionMethod->getReturnType() === null) { + if (! $this->reflectionMethod->getReturnType() instanceof ReflectionType) { return null; } diff --git a/packages/reflection/src/ParameterReflector.php b/packages/reflection/src/ParameterReflector.php index 02d92188e..d9126d83a 100644 --- a/packages/reflection/src/ParameterReflector.php +++ b/packages/reflection/src/ParameterReflector.php @@ -6,12 +6,12 @@ use ReflectionParameter as PHPReflectionParameter; -final class ParameterReflector implements Reflector +final readonly class ParameterReflector implements Reflector { use HasAttributes; public function __construct( - private readonly PHPReflectionParameter $reflectionParameter, + private PHPReflectionParameter $reflectionParameter, ) {} public function getReflection(): PHPReflectionParameter diff --git a/packages/reflection/src/PropertyAttribute.php b/packages/reflection/src/PropertyAttribute.php index 0e669c9ce..8b5683076 100644 --- a/packages/reflection/src/PropertyAttribute.php +++ b/packages/reflection/src/PropertyAttribute.php @@ -4,8 +4,5 @@ interface PropertyAttribute { - public PropertyReflector $property { - set; - get; - } + public PropertyReflector $property { set; get; } } diff --git a/packages/reflection/src/PropertyReflector.php b/packages/reflection/src/PropertyReflector.php index 3eda1ce13..eafb3dae4 100644 --- a/packages/reflection/src/PropertyReflector.php +++ b/packages/reflection/src/PropertyReflector.php @@ -6,13 +6,14 @@ use Error; use ReflectionProperty as PHPReflectionProperty; +use Stringable; -final class PropertyReflector implements Reflector +final readonly class PropertyReflector implements Reflector, Stringable { use HasAttributes; public function __construct( - private readonly PHPReflectionProperty $reflectionProperty, + private PHPReflectionProperty $reflectionProperty, ) {} public static function fromParts(string|object $class, string $name): self diff --git a/packages/reflection/src/TypeReflector.php b/packages/reflection/src/TypeReflector.php index 739cfd4e5..a9b5bd2f1 100644 --- a/packages/reflection/src/TypeReflector.php +++ b/packages/reflection/src/TypeReflector.php @@ -7,7 +7,9 @@ use BackedEnum; use DateTimeInterface; use Generator; +use InvalidArgumentException; use Iterator; +use LogicException; use ReflectionClass as PHPReflectionClass; use ReflectionClassConstant as PHPReflectionClassConstant; use ReflectionEnumUnitCase as PHPReflectionEnumUnitCase; @@ -141,7 +143,7 @@ public function getShortName(): string { $parts = explode('\\', $this->definition); - return $parts[array_key_last($parts)]; + return array_last($parts); } public function isBuiltIn(): bool @@ -172,7 +174,7 @@ public function isEnumCase(): bool public function asEnumCase(): PHPReflectionEnumUnitCase { if (! $this->reflector instanceof PHPReflectionEnumUnitCase) { - throw new \LogicException(sprintf('Cannot get enum case from `%s`.', $this->definition)); + throw new LogicException(sprintf('Cannot get enum case from `%s`.', $this->definition)); } return $this->reflector; @@ -214,7 +216,7 @@ public function isStringable(): bool return true; } - return in_array($this->cleanDefinition, ['string'], strict: true); + return $this->cleanDefinition === 'string'; } public function isNullable(): bool @@ -271,19 +273,19 @@ private function resolveDefinition(PHPReflector|PHPReflectionType|string $reflec if ($reflector instanceof PHPReflectionUnionType) { return implode('|', array_map( - fn (PHPReflectionType $reflectionType) => $this->resolveDefinition($reflectionType), + $this->resolveDefinition(...), $reflector->getTypes(), )); } if ($reflector instanceof PHPReflectionIntersectionType) { return implode('&', array_map( - fn (PHPReflectionType $reflectionType) => $this->resolveDefinition($reflectionType), + $this->resolveDefinition(...), $reflector->getTypes(), )); } - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf('Could not resolve type for reflector of type: %s', get_debug_type($reflector)), ); } diff --git a/packages/reflection/tests/EnumReflectorTest.php b/packages/reflection/tests/EnumReflectorTest.php index 2af7df7d4..e2e562ea6 100644 --- a/packages/reflection/tests/EnumReflectorTest.php +++ b/packages/reflection/tests/EnumReflectorTest.php @@ -4,11 +4,16 @@ namespace Tempest\Reflection\Tests; +use Attribute; +use BackedEnum; +use JsonSerializable; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use ReflectionEnum; +use stdClass; use Tempest\Reflection\EnumReflector; use Tempest\Reflection\TypeReflector; +use UnitEnum; /** * @internal @@ -153,9 +158,9 @@ public function is_method(): void { $reflector = new EnumReflector(TestBackedEnum::class); - $this->assertTrue($reflector->is(\BackedEnum::class)); - $this->assertTrue($reflector->is(\UnitEnum::class)); - $this->assertFalse($reflector->is(\stdClass::class)); + $this->assertTrue($reflector->is(BackedEnum::class)); + $this->assertTrue($reflector->is(UnitEnum::class)); + $this->assertFalse($reflector->is(stdClass::class)); } #[Test] @@ -164,7 +169,7 @@ public function implements_method(): void $reflector = new EnumReflector(TestEnumWithInterface::class); $this->assertTrue($reflector->implements(TestInterface::class)); - $this->assertFalse($reflector->implements(\JsonSerializable::class)); + $this->assertFalse($reflector->implements(JsonSerializable::class)); } #[Test] @@ -271,16 +276,14 @@ enum TestIntBackedEnum: int case SECOND = 2; } -interface TestInterface -{ -} +interface TestInterface {} enum TestEnumWithInterface: string implements TestInterface { case VALUE = 'value'; } -#[\Attribute] +#[Attribute] final class TestAttribute { public function __construct( diff --git a/packages/reflection/tests/Fixtures/AnnulledInvoice.php b/packages/reflection/tests/Fixtures/AnnulledInvoice.php index f5d5c7f8f..76bb96e17 100644 --- a/packages/reflection/tests/Fixtures/AnnulledInvoice.php +++ b/packages/reflection/tests/Fixtures/AnnulledInvoice.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final readonly class AnnulledInvoice -{ -} +final readonly class AnnulledInvoice {} diff --git a/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php index 1483015ae..622d60770 100644 --- a/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ChildWithRecursiveAttribute.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute -{ -} +final class ChildWithRecursiveAttribute extends ParentWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php index 39ecc50d5..9558fb05f 100644 --- a/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ClassWithInterfaceWithRecursiveAttribute.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute -{ -} +final class ClassWithInterfaceWithRecursiveAttribute implements InterfaceWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php index 7282e5687..d8f1f2c52 100644 --- a/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/InterfaceWithRecursiveAttribute.php @@ -5,6 +5,4 @@ namespace Tempest\Reflection\Tests\Fixtures; #[RecursiveAttribute] -interface InterfaceWithRecursiveAttribute -{ -} +interface InterfaceWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/NullableClass.php b/packages/reflection/tests/Fixtures/NullableClass.php index a2af1e599..6f745ad02 100644 --- a/packages/reflection/tests/Fixtures/NullableClass.php +++ b/packages/reflection/tests/Fixtures/NullableClass.php @@ -4,6 +4,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -final readonly class NullableClass -{ -} +final readonly class NullableClass {} diff --git a/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php b/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php index 9cf1cfe57..76cd13221 100644 --- a/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/ParentWithRecursiveAttribute.php @@ -5,6 +5,4 @@ namespace Tempest\Reflection\Tests\Fixtures; #[RecursiveAttribute] -abstract class ParentWithRecursiveAttribute -{ -} +abstract class ParentWithRecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/RecursiveAttribute.php b/packages/reflection/tests/Fixtures/RecursiveAttribute.php index 32d3856c7..cd6814e67 100644 --- a/packages/reflection/tests/Fixtures/RecursiveAttribute.php +++ b/packages/reflection/tests/Fixtures/RecursiveAttribute.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute] -final class RecursiveAttribute -{ -} +final class RecursiveAttribute {} diff --git a/packages/reflection/tests/Fixtures/TestBackedEnum.php b/packages/reflection/tests/Fixtures/TestBackedEnum.php index e33bbd8d9..6d300b899 100644 --- a/packages/reflection/tests/Fixtures/TestBackedEnum.php +++ b/packages/reflection/tests/Fixtures/TestBackedEnum.php @@ -2,6 +2,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -enum TestBackedEnum: string -{ -} +enum TestBackedEnum: string {} diff --git a/packages/reflection/tests/Fixtures/TestEnum.php b/packages/reflection/tests/Fixtures/TestEnum.php index b9f6052b5..9d1c8b629 100644 --- a/packages/reflection/tests/Fixtures/TestEnum.php +++ b/packages/reflection/tests/Fixtures/TestEnum.php @@ -2,6 +2,4 @@ namespace Tempest\Reflection\Tests\Fixtures; -enum TestEnum -{ -} +enum TestEnum {} diff --git a/packages/router/src/Commands/MakeControllerCommand.php b/packages/router/src/Commands/MakeControllerCommand.php index 5052d4aed..5e0cd4c91 100644 --- a/packages/router/src/Commands/MakeControllerCommand.php +++ b/packages/router/src/Commands/MakeControllerCommand.php @@ -12,7 +12,7 @@ use Tempest\Generation\Php\DataObjects\StubFile; use Tempest\Router\Stubs\ControllerStub; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final class MakeControllerCommand { use PublishesFiles; diff --git a/packages/router/src/Commands/RoutesCommand.php b/packages/router/src/Commands/RoutesCommand.php index 73e6c0a42..2cf51e9e1 100644 --- a/packages/router/src/Commands/RoutesCommand.php +++ b/packages/router/src/Commands/RoutesCommand.php @@ -17,7 +17,7 @@ use function Tempest\Support\Str\after_last; use function Tempest\Support\Str\before_last; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class RoutesCommand { public function __construct( diff --git a/packages/router/src/Commands/ServeCommand.php b/packages/router/src/Commands/ServeCommand.php index 76bf4b01d..998559ad4 100644 --- a/packages/router/src/Commands/ServeCommand.php +++ b/packages/router/src/Commands/ServeCommand.php @@ -8,7 +8,7 @@ use Tempest\Intl\Number; use Tempest\Support\Str; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class ServeCommand { #[ConsoleCommand( diff --git a/packages/router/src/Connect.php b/packages/router/src/Connect.php index 280c5752e..dfce369a6 100644 --- a/packages/router/src/Connect.php +++ b/packages/router/src/Connect.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Connect implements Route { - public Method $method; + public Method $method = Method::CONNECT; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::CONNECT; - } + ) {} } diff --git a/packages/router/src/Delete.php b/packages/router/src/Delete.php index 40724d91c..7bb003c6d 100644 --- a/packages/router/src/Delete.php +++ b/packages/router/src/Delete.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Delete implements Route { - public Method $method; + public Method $method = Method::DELETE; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::DELETE; - } + ) {} } diff --git a/packages/router/src/Exceptions/ConvertsToResponse.php b/packages/router/src/Exceptions/ConvertsToResponse.php index f49d1258d..587ce2f0f 100644 --- a/packages/router/src/Exceptions/ConvertsToResponse.php +++ b/packages/router/src/Exceptions/ConvertsToResponse.php @@ -3,11 +3,12 @@ namespace Tempest\Router\Exceptions; use Tempest\Http\Response; +use Throwable; /** * Marks this exception class as one that can be converted to a response. */ -interface ConvertsToResponse extends \Throwable +interface ConvertsToResponse extends Throwable { /** * Gets a response to be sent to the client. diff --git a/packages/router/src/Exceptions/DevelopmentException.php b/packages/router/src/Exceptions/DevelopmentException.php index 9cb242712..659bf49d0 100644 --- a/packages/router/src/Exceptions/DevelopmentException.php +++ b/packages/router/src/Exceptions/DevelopmentException.php @@ -86,7 +86,7 @@ private function enhanceStacktraceForViewCompilation(ViewCompilationFailed $exce { $previous = $exception->getPrevious(); - if (! $previous) { + if (! $previous instanceof Throwable) { return $stacktrace; } diff --git a/packages/router/src/Exceptions/HtmlExceptionRenderer.php b/packages/router/src/Exceptions/HtmlExceptionRenderer.php index e4bf13fbc..fb1bf0345 100644 --- a/packages/router/src/Exceptions/HtmlExceptionRenderer.php +++ b/packages/router/src/Exceptions/HtmlExceptionRenderer.php @@ -113,11 +113,7 @@ private function shouldRenderDevelopmentException(Throwable $throwable): bool return true; } - if ($throwable->status === Status::NOT_FOUND) { - return false; - } - - return true; + return $throwable->status !== Status::NOT_FOUND; } private function renderValidationFailedResponse(ValidationFailed $exception): Response diff --git a/packages/router/src/Exceptions/JsonExceptionRenderer.php b/packages/router/src/Exceptions/JsonExceptionRenderer.php index 9a3c247be..f86ef7fbe 100644 --- a/packages/router/src/Exceptions/JsonExceptionRenderer.php +++ b/packages/router/src/Exceptions/JsonExceptionRenderer.php @@ -88,10 +88,10 @@ private function renderErrorResponse(Status $status, ?string $message = null, ?T 'message' => $message ?? $status->description(), ]; - if ($this->environment->isLocal() && $throwable !== null) { + if ($this->environment->isLocal() && $throwable instanceof Throwable) { $body['debug'] = array_filter([ 'message' => $throwable->getMessage(), - 'exception' => get_class($throwable), + 'exception' => $throwable::class, 'file' => $throwable->getFile(), 'line' => $throwable->getLine(), 'trace' => Arr\map( diff --git a/packages/router/src/Exceptions/RouteBindingFailed.php b/packages/router/src/Exceptions/RouteBindingFailed.php index dbd261b54..879ca6d9a 100644 --- a/packages/router/src/Exceptions/RouteBindingFailed.php +++ b/packages/router/src/Exceptions/RouteBindingFailed.php @@ -6,6 +6,4 @@ use Exception; -final class RouteBindingFailed extends Exception implements RouterException -{ -} +final class RouteBindingFailed extends Exception implements RouterException {} diff --git a/packages/router/src/Exceptions/RouterException.php b/packages/router/src/Exceptions/RouterException.php index 3f357efb2..e4ecbde43 100644 --- a/packages/router/src/Exceptions/RouterException.php +++ b/packages/router/src/Exceptions/RouterException.php @@ -2,6 +2,4 @@ namespace Tempest\Router\Exceptions; -interface RouterException -{ -} +interface RouterException {} diff --git a/packages/router/src/GenericResponseSender.php b/packages/router/src/GenericResponseSender.php index 45a8e3842..be9f1f4c8 100644 --- a/packages/router/src/GenericResponseSender.php +++ b/packages/router/src/GenericResponseSender.php @@ -130,7 +130,7 @@ private function sendEventStream(EventStream $response): void } foreach ($response->body as $message) { - if (connection_aborted()) { + if (connection_aborted() !== 0) { break; } @@ -142,7 +142,7 @@ private function sendEventStream(EventStream $response): void echo "id: {$message->id}\n"; } - if ($message->retryAfter) { + if ($message->retryAfter !== null) { $retry = match (true) { is_int($message->retryAfter) => $message->retryAfter, $message->retryAfter instanceof Duration => $message->retryAfter->getTotalMilliseconds(), diff --git a/packages/router/src/Get.php b/packages/router/src/Get.php index e73c04813..6d5f23bc3 100644 --- a/packages/router/src/Get.php +++ b/packages/router/src/Get.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Get implements Route { - public Method $method; + public Method $method = Method::GET; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::GET; - } + ) {} } diff --git a/packages/router/src/Head.php b/packages/router/src/Head.php index 74530c1c0..a21be9c53 100644 --- a/packages/router/src/Head.php +++ b/packages/router/src/Head.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Head implements Route { - public Method $method; + public Method $method = Method::HEAD; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::HEAD; - } + ) {} } diff --git a/packages/router/src/IsBindingValue.php b/packages/router/src/IsBindingValue.php index d2f633936..a345c6096 100644 --- a/packages/router/src/IsBindingValue.php +++ b/packages/router/src/IsBindingValue.php @@ -5,6 +5,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class IsBindingValue -{ -} +final class IsBindingValue {} diff --git a/packages/router/src/MatchRouteMiddleware.php b/packages/router/src/MatchRouteMiddleware.php index ab8a44a32..901f7b68f 100644 --- a/packages/router/src/MatchRouteMiddleware.php +++ b/packages/router/src/MatchRouteMiddleware.php @@ -26,11 +26,11 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon { $matchedRoute = $this->routeMatcher->match($request); - if ($matchedRoute === null && $request->method === Method::HEAD && $request instanceof GenericRequest) { + if (! $matchedRoute instanceof MatchedRoute && $request->method === Method::HEAD && $request instanceof GenericRequest) { $matchedRoute = $this->routeMatcher->match($request->withMethod(Method::GET)); } - if ($matchedRoute === null) { + if (! $matchedRoute instanceof MatchedRoute) { return new NotFound(); } @@ -65,7 +65,7 @@ private function resolveRequest(Request $request, MatchedRoute $matchedRoute): R } if ($requestClass !== Request::class && $requestClass !== GenericRequest::class) { - $request = map($request)->with(RequestToObjectMapper::class)->to($requestClass); + return map($request)->with(RequestToObjectMapper::class)->to($requestClass); } return $request; diff --git a/packages/router/src/Options.php b/packages/router/src/Options.php index 60d370ddf..e66634f1a 100644 --- a/packages/router/src/Options.php +++ b/packages/router/src/Options.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Options implements Route { - public Method $method; + public Method $method = Method::OPTIONS; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::OPTIONS; - } + ) {} } diff --git a/packages/router/src/Patch.php b/packages/router/src/Patch.php index c00c875c4..ffaed917c 100644 --- a/packages/router/src/Patch.php +++ b/packages/router/src/Patch.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Patch implements Route { - public Method $method; + public Method $method = Method::PATCH; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::PATCH; - } + ) {} } diff --git a/packages/router/src/Post.php b/packages/router/src/Post.php index 83711e1db..d9d1f953a 100644 --- a/packages/router/src/Post.php +++ b/packages/router/src/Post.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Post implements Route { - public Method $method; + public Method $method = Method::POST; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::POST; - } + ) {} } diff --git a/packages/router/src/PreventCrossSiteRequestsMiddleware.php b/packages/router/src/PreventCrossSiteRequestsMiddleware.php index b1bf73f4f..645a884aa 100644 --- a/packages/router/src/PreventCrossSiteRequestsMiddleware.php +++ b/packages/router/src/PreventCrossSiteRequestsMiddleware.php @@ -50,11 +50,7 @@ public function __invoke(Request $request, HttpMiddlewareCallable $next): Respon */ private function shouldValidate(Request $request): bool { - if (in_array($request->method, self::SAFE_METHODS, strict: true)) { - return false; - } - - return true; + return ! in_array($request->method, self::SAFE_METHODS, strict: true); } /** @@ -76,10 +72,6 @@ private function isValidRequest(Request $request): bool } // same origin, same site and user-originated requests are always allowed - if ($secFetchSite !== SecFetchSite::CROSS_SITE) { - return true; - } - - return false; + return $secFetchSite !== SecFetchSite::CROSS_SITE; } } diff --git a/packages/router/src/Put.php b/packages/router/src/Put.php index 4e990b83b..9995d4c2b 100644 --- a/packages/router/src/Put.php +++ b/packages/router/src/Put.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Put implements Route { - public Method $method; + public Method $method = Method::PUT; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::PUT; - } + ) {} } diff --git a/packages/router/src/Route.php b/packages/router/src/Route.php index 3387556c1..082d0ed84 100644 --- a/packages/router/src/Route.php +++ b/packages/router/src/Route.php @@ -8,25 +8,13 @@ interface Route { - public Method $method { - get; - set; - } + public Method $method { get; set; } - public string $uri { - get; - set; - } + public string $uri { get; set; } /** @var class-string[] */ - public array $middleware { - get; - set; - } + public array $middleware { get; set; } /** @var class-string[] */ - public array $without { - get; - set; - } + public array $without { get; set; } } diff --git a/packages/router/src/Routing/Construction/DiscoveredRoute.php b/packages/router/src/Routing/Construction/DiscoveredRoute.php index be603c882..a32e9e22a 100644 --- a/packages/router/src/Routing/Construction/DiscoveredRoute.php +++ b/packages/router/src/Routing/Construction/DiscoveredRoute.php @@ -6,6 +6,7 @@ use Tempest\Http\Method; use Tempest\Reflection\MethodReflector; +use Tempest\Reflection\ParameterReflector; use Tempest\Router\Route; final class DiscoveredRoute implements Route @@ -88,7 +89,7 @@ private static function parseUriAndParameters(string $uri, MethodReflector $meth $parameter = $methodReflector->getParameter($paramName); - if ($parameter === null) { + if (! $parameter instanceof ParameterReflector) { return $matches[0]; } diff --git a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php index 7a71c6c7e..aea61940a 100644 --- a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php +++ b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php @@ -59,14 +59,14 @@ public function toRegex(): MatchingRegex // Rebuild the regex match prefix based on the current visited parent nodes, known as 'the stack' foreach ($stack as $previousNode) { - $regex .= '|' . self::routeNodeSegmentRegex($previousNode); + $regex .= '|' . $this->routeNodeSegmentRegex($previousNode); $regex .= '(?'; } } // Add the node route segment to the current regex - $regex .= '|' . self::routeNodeSegmentRegex($node); - $targetRouteRegex = self::routeNodeTargetRegex($node); + $regex .= '|' . $this->routeNodeSegmentRegex($node); + $targetRouteRegex = $this->routeNodeTargetRegex($node); // Check if node has children to ensure we only use branches if the node has children if ($node->dynamicPaths !== [] || $node->staticPaths !== []) { @@ -77,7 +77,7 @@ public function toRegex(): MatchingRegex $stack[] = $node; // Add target route regex as an alteration group - if ($targetRouteRegex) { + if ($targetRouteRegex !== '' && $targetRouteRegex !== '0') { $regex .= '|' . $targetRouteRegex; } @@ -112,9 +112,9 @@ public function toRegex(): MatchingRegex * a key `"MARK"` with value `"x"`, it is used to track which route has been matched. * Returns an empty string for nodes without a target. */ - private static function routeNodeTargetRegex(RouteTreeNode $node): string + private function routeNodeTargetRegex(RouteTreeNode $node): string { - if ($node->targetRoute === null) { + if (! $node->targetRoute instanceof MarkedRoute) { return ''; } @@ -124,7 +124,7 @@ private static function routeNodeTargetRegex(RouteTreeNode $node): string /** * Creates the regex for a route node's segment */ - private static function routeNodeSegmentRegex(RouteTreeNode $node): string + private function routeNodeSegmentRegex(RouteTreeNode $node): string { return match ($node->type) { RouteTreeNodeType::Root => '^', diff --git a/packages/router/src/Routing/Construction/RouteTreeNode.php b/packages/router/src/Routing/Construction/RouteTreeNode.php index 7e4ed1640..566e16553 100644 --- a/packages/router/src/Routing/Construction/RouteTreeNode.php +++ b/packages/router/src/Routing/Construction/RouteTreeNode.php @@ -40,7 +40,7 @@ public static function createStaticRouteNode(string $name): self public function findOrCreateNodeForSegment(string $routeSegment): self { // Translates a path segment like {id} into it's matching regex. Static segments remain the same - $regexRouteSegment = self::convertDynamicSegmentToRegex($routeSegment); + $regexRouteSegment = $this->convertDynamicSegmentToRegex($routeSegment); // Returns a static or dynamic child node depending on the segment is dynamic or static if ($routeSegment === $regexRouteSegment) { @@ -52,14 +52,14 @@ public function findOrCreateNodeForSegment(string $routeSegment): self public function setTargetRoute(MarkedRoute $markedRoute): void { - if ($this->targetRoute !== null) { + if ($this->targetRoute instanceof MarkedRoute) { throw new DuplicateRouteException($markedRoute->route); } $this->targetRoute = $markedRoute; } - private static function convertDynamicSegmentToRegex(string $uriPart): string + private function convertDynamicSegmentToRegex(string $uriPart): string { $regex = '#\{' . DiscoveredRoute::ROUTE_PARAM_OPTIONAL_REGEX . DiscoveredRoute::ROUTE_PARAM_NAME_REGEX . DiscoveredRoute::ROUTE_PARAM_CUSTOM_REGEX . '\}#'; diff --git a/packages/router/src/Routing/Construction/RoutingTree.php b/packages/router/src/Routing/Construction/RoutingTree.php index e8f658ab3..6bac79e0e 100644 --- a/packages/router/src/Routing/Construction/RoutingTree.php +++ b/packages/router/src/Routing/Construction/RoutingTree.php @@ -12,12 +12,9 @@ final class RoutingTree { /** @var array */ - private array $roots; + private array $roots = []; - public function __construct() - { - $this->roots = []; - } + public function __construct() {} public function add(MarkedRoute $markedRoute): void { diff --git a/packages/router/src/Routing/Matching/GenericRouteMatcher.php b/packages/router/src/Routing/Matching/GenericRouteMatcher.php index e7298976b..ba5265859 100644 --- a/packages/router/src/Routing/Matching/GenericRouteMatcher.php +++ b/packages/router/src/Routing/Matching/GenericRouteMatcher.php @@ -19,7 +19,7 @@ public function __construct( public function match(Request $request): ?MatchedRoute { // Try to match routes without any parameters - if (($staticRoute = $this->matchStaticRoute($request)) !== null) { + if (($staticRoute = $this->matchStaticRoute($request)) instanceof MatchedRoute) { return $staticRoute; } diff --git a/packages/router/src/Routing/Matching/MatchingRegex.php b/packages/router/src/Routing/Matching/MatchingRegex.php index ec382c847..ffc4a95cc 100644 --- a/packages/router/src/Routing/Matching/MatchingRegex.php +++ b/packages/router/src/Routing/Matching/MatchingRegex.php @@ -25,7 +25,7 @@ public function match(string $uri): ?RouteMatch throw new RuntimeException('Failed to use matching regex. Got error ' . preg_last_error()); } - if (! $matchResult) { + if ($matchResult === 0) { continue; } diff --git a/packages/router/src/Static/Exceptions/StaticPageException.php b/packages/router/src/Static/Exceptions/StaticPageException.php index d6c563afc..44810abb4 100644 --- a/packages/router/src/Static/Exceptions/StaticPageException.php +++ b/packages/router/src/Static/Exceptions/StaticPageException.php @@ -4,7 +4,5 @@ interface StaticPageException { - public string $uri { - get; - } + public string $uri { get; } } diff --git a/packages/router/src/Static/StaticGenerateCommand.php b/packages/router/src/Static/StaticGenerateCommand.php index ecef517c6..440ee29f3 100644 --- a/packages/router/src/Static/StaticGenerateCommand.php +++ b/packages/router/src/Static/StaticGenerateCommand.php @@ -99,7 +99,7 @@ public function __invoke( "{$event->path}", "NO CONTENT", ), - $verbose === true => $this->error("Failed to generate static page: {$event->exception->getMessage()}"), + $verbose => $this->error("Failed to generate static page: {$event->exception->getMessage()}"), default => $this->keyValue("{$event->path}", "FAILED"), }; }); @@ -181,13 +181,13 @@ public function __invoke( } } - if ($failures) { + if ($failures !== 0) { $this->keyValue('Failures', "{$failures}"); } $this->keyValue('Static pages generated', "{$generated}"); - if ($deadlinks) { + if ($deadlinks !== []) { $this->console->header('Dead links'); foreach ($deadlinks as $uri => $deadLinks) { @@ -197,7 +197,7 @@ public function __invoke( } } - return $failures > 0 || count($deadlinks) > 0 + return $failures > 0 || $deadlinks !== [] ? ExitCode::ERROR : ExitCode::SUCCESS; } @@ -224,7 +224,7 @@ private function detectDeadLinks(string $uri, string $html, bool $checkExternal // Check anchors (#) if (Str\starts_with($link, '#')) { - if (! Regex\matches($html, "/id=\"" . preg_quote(Str\strip_start($link, '#'), '/') . "\"/")) { + if (! Regex\matches($html, '/id="' . preg_quote(Str\strip_start($link, '#'), '/') . '"/')) { $deadlinks[] = $link; } diff --git a/packages/router/src/Trace.php b/packages/router/src/Trace.php index 24b8857af..fa85c0dd1 100644 --- a/packages/router/src/Trace.php +++ b/packages/router/src/Trace.php @@ -10,7 +10,7 @@ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD)] final class Trace implements Route { - public Method $method; + public Method $method = Method::TRACE; /** * @param class-string[] $middleware Middleware specific to this route. @@ -20,7 +20,5 @@ public function __construct( public string $uri, public array $middleware = [], public array $without = [], - ) { - $this->method = Method::TRACE; - } + ) {} } diff --git a/packages/router/tests/FakeRouteBuilder.php b/packages/router/tests/FakeRouteBuilder.php index 1d041c799..08f523e8f 100644 --- a/packages/router/tests/FakeRouteBuilder.php +++ b/packages/router/tests/FakeRouteBuilder.php @@ -47,7 +47,5 @@ public function asDiscoveredRoute(): DiscoveredRoute return DiscoveredRoute::fromRoute($this, [], $this->handler); } - public function handler(): void - { - } + public function handler(): void {} } diff --git a/packages/router/tests/FakeRouteBuilderWithOptionalParams.php b/packages/router/tests/FakeRouteBuilderWithOptionalParams.php index ed03e644e..95e71f316 100644 --- a/packages/router/tests/FakeRouteBuilderWithOptionalParams.php +++ b/packages/router/tests/FakeRouteBuilderWithOptionalParams.php @@ -53,19 +53,11 @@ public function asDiscoveredRoute(): DiscoveredRoute return DiscoveredRoute::fromRoute($this, [], $this->handler); } - public function handler(): void - { - } + public function handler(): void {} - public function handlerWithOptionalId(string $id = 'default-id'): void - { - } + public function handlerWithOptionalId(string $id = 'default-id'): void {} - public function handlerWithTwoOptionalParams(string $id = 'default-id', string $slug = 'default-slug'): void - { - } + public function handlerWithTwoOptionalParams(string $id = 'default-id', string $slug = 'default-slug'): void {} - public function handlerWithRequiredAndOptional(string $id, string $slug = 'default-slug'): void - { - } + public function handlerWithRequiredAndOptional(string $id, string $slug = 'default-slug'): void {} } diff --git a/packages/storage/src/Config/R2StorageConfig.php b/packages/storage/src/Config/R2StorageConfig.php index 4acb8d1e7..6325d1d35 100644 --- a/packages/storage/src/Config/R2StorageConfig.php +++ b/packages/storage/src/Config/R2StorageConfig.php @@ -57,12 +57,12 @@ public function createAdapter(): FilesystemAdapter return new S3StorageConfig( bucket: $this->bucket, region: 'auto', - endpoint: $this->endpoint, accessKeyId: $this->accessKeyId, secretAccessKey: $this->secretAccessKey, sessionToken: null, prefix: $this->prefix, readonly: $this->readonly, + endpoint: $this->endpoint, usePathStyleEndpoint: true, options: $this->options, )->createAdapter(); diff --git a/packages/storage/src/Config/StorageConfig.php b/packages/storage/src/Config/StorageConfig.php index 1c0b4b921..33b8b33f9 100644 --- a/packages/storage/src/Config/StorageConfig.php +++ b/packages/storage/src/Config/StorageConfig.php @@ -10,17 +10,12 @@ interface StorageConfig extends HasTag /** * Whether the storage is read-only. */ - public bool $readonly { - get; - set; - } + public bool $readonly { get; set; } /** * The adapter class. */ - public string $adapter { - get; - } + public string $adapter { get; } /** * Creates the adapter. diff --git a/packages/storage/src/DirectoryListing.php b/packages/storage/src/DirectoryListing.php index af3705f66..44e95e750 100644 --- a/packages/storage/src/DirectoryListing.php +++ b/packages/storage/src/DirectoryListing.php @@ -26,7 +26,7 @@ public function __construct( */ public function filter(callable $filter): static { - return new static(parent::filter($filter)); + return new self(parent::filter($filter)); } /** @@ -38,7 +38,7 @@ public function filter(callable $filter): static */ public function map(callable $mapper): static { - return new static(parent::map($mapper)); + return new self(parent::map($mapper)); } /** @@ -46,7 +46,7 @@ public function map(callable $mapper): static */ public function sortByPath(): static { - return new static(parent::sortByPath()); + return new self(parent::sortByPath()); } /** diff --git a/packages/storage/src/StorageException.php b/packages/storage/src/StorageException.php index 9136ec1d7..f4a4bcb0c 100644 --- a/packages/storage/src/StorageException.php +++ b/packages/storage/src/StorageException.php @@ -2,6 +2,4 @@ namespace Tempest\Storage; -interface StorageException -{ -} +interface StorageException {} diff --git a/packages/storage/src/Testing/StorageTester.php b/packages/storage/src/Testing/StorageTester.php index 3ca86ead7..ab13946c2 100644 --- a/packages/storage/src/Testing/StorageTester.php +++ b/packages/storage/src/Testing/StorageTester.php @@ -2,6 +2,7 @@ namespace Tempest\Storage\Testing; +use RuntimeException; use Tempest\Container\Container; use Tempest\Container\GenericContainer; use Tempest\Storage\Storage; @@ -37,7 +38,7 @@ public function fake(null|string|UnitEnum $tag = null, bool $persist = false): T public function preventUsageWithoutFake(): void { if (! $this->container instanceof GenericContainer) { - throw new \RuntimeException('Container is not a GenericContainer, unable to prevent usage without fake.'); + throw new RuntimeException('Container is not a GenericContainer, unable to prevent usage without fake.'); } $this->container->unregister(Storage::class, tagged: true); diff --git a/packages/storage/src/Testing/TestingStorage.php b/packages/storage/src/Testing/TestingStorage.php index c841e7e51..7d2e9f0f0 100644 --- a/packages/storage/src/Testing/TestingStorage.php +++ b/packages/storage/src/Testing/TestingStorage.php @@ -189,9 +189,9 @@ private function createStorage(?string $path = null, ?TemporaryUrlGenerator $tem public function createTemporaryUrlsUsing(Closure $closure): void { - $generator = new class($closure) implements TemporaryUrlGenerator { + $generator = new readonly class($closure) implements TemporaryUrlGenerator { public function __construct( - private readonly Closure $closure, + private Closure $closure, ) {} public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config $config): string @@ -205,9 +205,9 @@ public function temporaryUrl(string $path, DateTimeInterface $expiresAt, Config public function createPublicUrlsUsing(Closure $closure): void { - $generator = new class($closure) implements PublicUrlGenerator { + $generator = new readonly class($closure) implements PublicUrlGenerator { public function __construct( - private readonly Closure $closure, + private Closure $closure, ) {} public function publicUrl(string $path, Config $config): string diff --git a/packages/support/src/Arr/ManipulatesArray.php b/packages/support/src/Arr/ManipulatesArray.php index e038d9f17..ee1f49cec 100644 --- a/packages/support/src/Arr/ManipulatesArray.php +++ b/packages/support/src/Arr/ManipulatesArray.php @@ -6,6 +6,7 @@ use Closure; use Stringable; +use Tempest\Debug\Debug; use Tempest\Mapper; use Tempest\Support\Str\ImmutableString; @@ -825,7 +826,7 @@ public function dd(mixed ...$dd): void private function debugLog(array $items, bool $terminate = false): void { - $debugClass = \Tempest\Debug\Debug::class; + $debugClass = Debug::class; if (class_exists($debugClass)) { $debugClass::resolve()->log($items); diff --git a/packages/support/src/Arr/OffsetDidNotExist.php b/packages/support/src/Arr/OffsetDidNotExist.php index e99cd224e..6099e582f 100644 --- a/packages/support/src/Arr/OffsetDidNotExist.php +++ b/packages/support/src/Arr/OffsetDidNotExist.php @@ -6,6 +6,4 @@ use Exception; -final class OffsetDidNotExist extends Exception -{ -} +final class OffsetDidNotExist extends Exception {} diff --git a/packages/support/src/Arr/functions.php b/packages/support/src/Arr/functions.php index 96c97c720..8c80d9cde 100644 --- a/packages/support/src/Arr/functions.php +++ b/packages/support/src/Arr/functions.php @@ -4,6 +4,7 @@ namespace Tempest\Support\Arr; +use ArrayAccess; use Closure; use Countable; use Generator; @@ -62,9 +63,7 @@ function chunk(iterable $array, int $size, bool $preserveKeys = true): array } $chunks = []; - foreach (array_chunk($array, $size, $preserveKeys) as $chunk) { - $chunks[] = $chunk; - } + $chunks = array_chunk($array, $size, $preserveKeys); return $chunks; } @@ -615,8 +614,8 @@ function first(iterable $array, ?Closure $filter = null, mixed $default = null): return $default; } - if ($filter === null) { - return $array[array_key_first($array)] ?? $default; + if (! $filter instanceof Closure) { + return array_first($array) ?? $default; } return array_find($array, static fn ($value, $key) => $filter($value, $key)) ?? $default; @@ -666,8 +665,8 @@ function last(iterable $array, ?Closure $filter = null, mixed $default = null): return $default; } - if ($filter === null) { - return $array[array_key_last($array)] ?? $default; + if (! $filter instanceof Closure) { + return array_last($array) ?? $default; } return array_find(namespace\reverse($array), static fn ($value, $key) => $filter($value, $key)) ?? $default; @@ -907,7 +906,7 @@ function get_by_key(iterable $array, int|string $key, mixed $default = null): mi : explode('.', $key); foreach ($keys as $key) { - if (! is_array($value) && ! $value instanceof \ArrayAccess) { + if (! is_array($value) && ! $value instanceof ArrayAccess) { return $default; } diff --git a/packages/support/src/Comparison/Exception/IncomparableException.php b/packages/support/src/Comparison/Exception/IncomparableException.php index 97ca67859..b49c928f7 100644 --- a/packages/support/src/Comparison/Exception/IncomparableException.php +++ b/packages/support/src/Comparison/Exception/IncomparableException.php @@ -16,7 +16,7 @@ public static function fromValues(mixed $a, mixed $b, string $additionalInfo = ' 'Unable to compare "%s" with "%s"%s', get_debug_type($a), get_debug_type($b), - $additionalInfo ? ': ' . $additionalInfo : '.', + $additionalInfo !== '' && $additionalInfo !== '0' ? ': ' . $additionalInfo : '.', )); } } diff --git a/packages/support/src/Filesystem/Exceptions/FilesystemException.php b/packages/support/src/Filesystem/Exceptions/FilesystemException.php index 4a0ffcf5d..574811e3c 100644 --- a/packages/support/src/Filesystem/Exceptions/FilesystemException.php +++ b/packages/support/src/Filesystem/Exceptions/FilesystemException.php @@ -2,6 +2,4 @@ namespace Tempest\Support\Filesystem\Exceptions; -interface FilesystemException -{ -} +interface FilesystemException {} diff --git a/packages/support/src/Filesystem/Exceptions/RuntimeException.php b/packages/support/src/Filesystem/Exceptions/RuntimeException.php index 145b290ee..de5084684 100644 --- a/packages/support/src/Filesystem/Exceptions/RuntimeException.php +++ b/packages/support/src/Filesystem/Exceptions/RuntimeException.php @@ -6,6 +6,4 @@ use RuntimeException as PhpRuntimeException; -final class RuntimeException extends PhpRuntimeException implements FilesystemException -{ -} +final class RuntimeException extends PhpRuntimeException implements FilesystemException {} diff --git a/packages/support/src/Filesystem/functions.php b/packages/support/src/Filesystem/functions.php index 6f8da6916..f69c05d41 100644 --- a/packages/support/src/Filesystem/functions.php +++ b/packages/support/src/Filesystem/functions.php @@ -5,6 +5,14 @@ namespace Tempest\Support\Filesystem; use FilesystemIterator; +use Phar; +use Tempest\Support\Filesystem\Exceptions\NameWasInvalid; +use Tempest\Support\Filesystem\Exceptions\PathWasNotADirectory; +use Tempest\Support\Filesystem\Exceptions\PathWasNotAFile; +use Tempest\Support\Filesystem\Exceptions\PathWasNotASymbolicLink; +use Tempest\Support\Filesystem\Exceptions\PathWasNotFound; +use Tempest\Support\Filesystem\Exceptions\PathWasNotReadable; +use Tempest\Support\Filesystem\Exceptions\RuntimeException; use Tempest\Support\Json; use Tempest\Support\Str; @@ -49,15 +57,15 @@ function copy_file(string $source, string $destination, bool $overwrite = false) } if (namespace\is_directory($source)) { - throw new Exceptions\PathWasNotAFile($source); + throw new PathWasNotAFile($source); } if (! namespace\is_file($source)) { - throw Exceptions\PathWasNotFound::forFile($source); + throw PathWasNotFound::forFile($source); } if (! namespace\is_readable($source)) { - throw Exceptions\PathWasNotReadable::forFile($source); + throw PathWasNotReadable::forFile($source); } namespace\create_directory_for_file($destination); @@ -65,7 +73,7 @@ function copy_file(string $source, string $destination, bool $overwrite = false) [$result, $errorMessage] = box(static fn (): bool => php_copy($source, $destination)); if ($result === false) { - throw new Exceptions\RuntimeException( + throw new RuntimeException( sprintf('Failed to copy source file "%s" to destination "%s": %s', $source, $destination, $errorMessage), ); } @@ -77,15 +85,15 @@ function copy_file(string $source, string $destination, bool $overwrite = false) function copy_directory(string $source, string $destination, bool $overwrite = false): void { if (! namespace\exists($source)) { - throw Exceptions\PathWasNotFound::forDirectory($source); + throw PathWasNotFound::forDirectory($source); } if (! namespace\is_directory($source)) { - throw new Exceptions\PathWasNotADirectory($source); + throw new PathWasNotADirectory($source); } if (! namespace\is_readable($source)) { - throw Exceptions\PathWasNotReadable::forDirectory($source); + throw PathWasNotReadable::forDirectory($source); } if (! $overwrite && namespace\is_directory($destination)) { @@ -138,7 +146,7 @@ function write_file(string $filename, mixed $content, int $flags = 0): void [$result, $errorMessage] = box(static fn (): int|false => file_put_contents($filename, $content, $flags)); if (false === $result) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to write to file "%s": %s.', $filename, $errorMessage ?? 'internal error', @@ -160,17 +168,17 @@ function read_json(string $filename, bool $associative = true): array function read_file(string $filename): string { if (! namespace\exists($filename)) { - throw Exceptions\PathWasNotFound::forFile($filename); + throw PathWasNotFound::forFile($filename); } if (! namespace\is_readable($filename)) { - throw Exceptions\PathWasNotReadable::forFile($filename); + throw PathWasNotReadable::forFile($filename); } [$result, $message] = box(static fn (): false|string => file_get_contents($filename)); if (false === $result) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to read file "%s": %s', $filename, $message ?? 'internal error', @@ -186,17 +194,17 @@ function read_file(string $filename): string function read_locked_file(string $filename, LockType $type = LockType::SHARED): string { if (! namespace\exists($filename)) { - throw Exceptions\PathWasNotFound::forFile($filename); + throw PathWasNotFound::forFile($filename); } if (! namespace\is_readable($filename)) { - throw Exceptions\PathWasNotReadable::forFile($filename); + throw PathWasNotReadable::forFile($filename); } [$handle, $openMessage] = box(static fn () => fopen($filename, 'rb')); if ($handle === false) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to open file "%s": %s', $filename, $openMessage ?? 'internal error', @@ -206,7 +214,7 @@ function read_locked_file(string $filename, LockType $type = LockType::SHARED): if (! flock($handle, $type->value)) { fclose($handle); - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to acquire lock on file "%s"', $filename, )); @@ -218,7 +226,7 @@ function read_locked_file(string $filename, LockType $type = LockType::SHARED): fclose($handle); if ($content === false) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to read file "%s": %s', $filename, $readMessage ?? 'internal error', @@ -250,7 +258,7 @@ function create_directory(string $directory, int $permissions = 0o777): void [$result, $errorMessage] = box(static fn (): bool => mkdir($directory, $permissions, recursive: true)); if ($result === false && ! namespace\is_directory($directory)) { // @phpstan-ignore booleanNot.alwaysTrue - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to create directory "%s": %s.', $directory, $errorMessage ?? 'internal error', @@ -306,7 +314,7 @@ function create_file(string $filename, ?int $time = null, ?int $accessTime = nul [$result, $errorMessage] = box($fun); if (false === $result && ! namespace\is_file($filename)) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to create file "%s": %s.', $filename, $errorMessage ?? 'internal error', @@ -347,7 +355,7 @@ function delete_file(string $file): void [$result, $errorMessage] = box(static fn (): bool => unlink($file)); if ($result === false && namespace\is_symbolic_link($file)) { // @phpstan-ignore booleanAnd.rightAlwaysTrue - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to delete symbolic link "%s": %s.', $file, $errorMessage ?? 'internal error', @@ -358,17 +366,17 @@ function delete_file(string $file): void } if (! namespace\exists($file)) { - throw Exceptions\PathWasNotFound::forFile($file); + throw PathWasNotFound::forFile($file); } if (! namespace\is_file($file)) { - throw new Exceptions\PathWasNotAFile($file); + throw new PathWasNotAFile($file); } [$result, $errorMessage] = box(static fn (): bool => unlink($file)); if ($result === false && namespace\is_file($file)) { // @phpstan-ignore booleanAnd.rightAlwaysTrue - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to delete file "%s": %s.', $file, $errorMessage ?? 'internal error', @@ -382,13 +390,13 @@ function delete_file(string $file): void function get_permissions(string $path): int { if (! namespace\exists($path)) { - throw Exceptions\PathWasNotFound::forPath($path); + throw PathWasNotFound::forPath($path); } [$result, $message] = box(static fn (): int|false => fileperms($path)); if (false === $result) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to retrieve permissions of file "%s": %s', $path, $message ?? 'internal error', @@ -404,7 +412,7 @@ function get_permissions(string $path): int function ensure_directory_empty(string $directory): void { if (namespace\exists($directory) && ! namespace\is_directory($directory)) { - throw new Exceptions\PathWasNotADirectory($directory); + throw new PathWasNotADirectory($directory); } if (! namespace\is_directory($directory)) { @@ -444,18 +452,18 @@ function delete_directory(string $directory, bool $recursive = true): void } } else { if (! namespace\exists($directory)) { - throw Exceptions\PathWasNotFound::forDirectory($directory); + throw PathWasNotFound::forDirectory($directory); } if (! namespace\is_directory($directory)) { - throw new Exceptions\PathWasNotADirectory($directory); + throw new PathWasNotADirectory($directory); } } [$result, $errorMessage] = box(static fn (): bool => rmdir($directory)); if (false === $result && namespace\is_directory($directory)) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to delete directory "%s": %s.', $directory, $errorMessage ?? 'internal error', @@ -469,7 +477,7 @@ function delete_directory(string $directory, bool $recursive = true): void function rename(string $source, string $name, bool $overwrite = false): void { if (Str\contains($name, ['/', '\\'])) { - throw Exceptions\NameWasInvalid::forName($name); + throw NameWasInvalid::forName($name); } namespace\move( @@ -485,11 +493,11 @@ function rename(string $source, string $name, bool $overwrite = false): void function move(string $source, string $destination, bool $overwrite = false): void { if (! namespace\exists($source)) { - throw Exceptions\PathWasNotFound::forPath($source); + throw PathWasNotFound::forPath($source); } if (! namespace\is_readable($source)) { - throw Exceptions\PathWasNotReadable::forFile($source); + throw PathWasNotReadable::forFile($source); } if (namespace\exists($destination) && $overwrite === false) { @@ -505,7 +513,7 @@ function move(string $source, string $destination, bool $overwrite = false): voi [$result, $errorMessage] = box(static fn (): bool => php_rename($source, $destination)); if ($result === false) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to move "%s" to "%s": %s', $source, $destination, @@ -571,15 +579,15 @@ function is_directory(string $path): bool function list_directory(string $directory): array { if (! namespace\exists($directory)) { - throw Exceptions\PathWasNotFound::forDirectory($directory); + throw PathWasNotFound::forDirectory($directory); } if (! namespace\is_directory($directory)) { - throw new Exceptions\PathWasNotADirectory($directory); + throw new PathWasNotADirectory($directory); } if (! namespace\is_readable($directory)) { - throw Exceptions\PathWasNotReadable::forDirectory($directory); + throw PathWasNotReadable::forDirectory($directory); } /** @var array */ @@ -595,17 +603,17 @@ function list_directory(string $directory): array function read_symbolic_link(string $path): string { if (! namespace\exists($path)) { - throw Exceptions\PathWasNotFound::forSymbolicLink($path); + throw PathWasNotFound::forSymbolicLink($path); } if (! namespace\is_symbolic_link($path)) { - throw new Exceptions\PathWasNotASymbolicLink($path); + throw new PathWasNotASymbolicLink($path); } [$result, $message] = box(static fn (): false|string => readlink($path)); if (false === $result) { - throw new Exceptions\RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Failed to retrieve the target of symbolic link "%s": %s', $path, $message ?? 'internal error', @@ -620,7 +628,7 @@ function read_symbolic_link(string $path): string */ function normalize_path(string $path): ?string { - if (str_starts_with($path, 'phar:') && class_exists(\Phar::class) && \Phar::running(false) !== '') { + if (str_starts_with($path, 'phar:') && class_exists(Phar::class) && Phar::running(false) !== '') { return $path; } diff --git a/packages/support/src/Html/HtmlString.php b/packages/support/src/Html/HtmlString.php index 8c5e1cf54..828cae81f 100644 --- a/packages/support/src/Html/HtmlString.php +++ b/packages/support/src/Html/HtmlString.php @@ -47,6 +47,6 @@ public function toMutableString(): MutableString */ protected function createOrModify(Stringable|string $string): self { - return new static($string); + return new self($string); } } diff --git a/packages/support/src/JavaScript/PackageManager.php b/packages/support/src/JavaScript/PackageManager.php index f354f743f..b2649ff8a 100644 --- a/packages/support/src/JavaScript/PackageManager.php +++ b/packages/support/src/JavaScript/PackageManager.php @@ -62,9 +62,9 @@ public static function detect(string $cwd): ?self { return array_find( array: PackageManager::cases(), - callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file($cwd - . '/' - . $lockFile)), + callback: fn (PackageManager $packageManager): bool => array_any($packageManager->getLockFiles(), fn (string $lockFile): bool => Filesystem\is_file( + $cwd . '/' . $lockFile, + )), ); } } diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php index 9b2c4ac99..54e0cb013 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php @@ -7,6 +7,4 @@ use InvalidArgumentException; use Tempest\Support\Json\Exception\JsonException; -final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException -{ -} +final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php index 5548f1f33..643d92ddd 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php @@ -7,6 +7,4 @@ use InvalidArgumentException; use Tempest\Support\Json\Exception\JsonException; -final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException -{ -} +final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonException.php b/packages/support/src/Json/Exception/JsonException.php index 43a580f29..39462316d 100644 --- a/packages/support/src/Json/Exception/JsonException.php +++ b/packages/support/src/Json/Exception/JsonException.php @@ -4,6 +4,4 @@ namespace Tempest\Support\Json\Exception; -interface JsonException -{ -} +interface JsonException {} diff --git a/packages/support/src/Json/functions.php b/packages/support/src/Json/functions.php index cc54c39ea..8d8129989 100644 --- a/packages/support/src/Json/functions.php +++ b/packages/support/src/Json/functions.php @@ -5,6 +5,8 @@ namespace Tempest\Support\Json; use JsonException; +use Tempest\Support\Json\Exception\JsonCouldNotBeDecoded; +use Tempest\Support\Json\Exception\JsonCouldNotBeEncoded; use function json_decode; use function json_encode; @@ -27,7 +29,7 @@ function decode(string $json, bool $associative = true, bool $base64 = false): m $json = base64_decode($json, strict: true); if ($json === false) { - throw new Exception\JsonCouldNotBeDecoded('The provided base64 string is not valid.'); + throw new JsonCouldNotBeDecoded('The provided base64 string is not valid.'); } } @@ -35,7 +37,7 @@ function decode(string $json, bool $associative = true, bool $base64 = false): m /** @var mixed $value */ $value = json_decode($json, $associative, 512, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR); } catch (JsonException $jsonException) { - throw new Exception\JsonCouldNotBeDecoded(sprintf('%s.', $jsonException->getMessage()), $jsonException->getCode(), $jsonException); + throw new JsonCouldNotBeDecoded(sprintf('%s.', $jsonException->getMessage()), $jsonException->getCode(), $jsonException); } return $value; @@ -60,7 +62,7 @@ function encode(mixed $value, bool $pretty = false, int $flags = 0, bool $base64 /** @var non-empty-string $json */ $json = json_encode($value, $flags); } catch (JsonException $jsonException) { - throw new Exception\JsonCouldNotBeEncoded(sprintf('%s.', $jsonException->getMessage()), $jsonException->getCode(), $jsonException); + throw new JsonCouldNotBeEncoded(sprintf('%s.', $jsonException->getMessage()), $jsonException->getCode(), $jsonException); } if ($base64) { diff --git a/packages/support/src/Math/Exception/ArithmeticException.php b/packages/support/src/Math/Exception/ArithmeticException.php index 8ea8a23a9..76c4f935e 100644 --- a/packages/support/src/Math/Exception/ArithmeticException.php +++ b/packages/support/src/Math/Exception/ArithmeticException.php @@ -7,6 +7,4 @@ use InvalidArgumentException; // @phpstan-ignore-next-line -class ArithmeticException extends InvalidArgumentException implements MathException -{ -} +class ArithmeticException extends InvalidArgumentException implements MathException {} diff --git a/packages/support/src/Math/Exception/DivisionByZeroException.php b/packages/support/src/Math/Exception/DivisionByZeroException.php index 24ad58821..517aed1d7 100644 --- a/packages/support/src/Math/Exception/DivisionByZeroException.php +++ b/packages/support/src/Math/Exception/DivisionByZeroException.php @@ -4,6 +4,4 @@ namespace Tempest\Support\Math\Exception; -final class DivisionByZeroException extends ArithmeticException -{ -} +final class DivisionByZeroException extends ArithmeticException {} diff --git a/packages/support/src/Math/Exception/InvalidArgumentException.php b/packages/support/src/Math/Exception/InvalidArgumentException.php index ade156b76..0279d738c 100644 --- a/packages/support/src/Math/Exception/InvalidArgumentException.php +++ b/packages/support/src/Math/Exception/InvalidArgumentException.php @@ -6,6 +6,4 @@ use InvalidArgumentException as PhpInvalidArgumentException; -final class InvalidArgumentException extends PhpInvalidArgumentException implements MathException -{ -} +final class InvalidArgumentException extends PhpInvalidArgumentException implements MathException {} diff --git a/packages/support/src/Math/Exception/MathException.php b/packages/support/src/Math/Exception/MathException.php index da1558aeb..7537b33a3 100644 --- a/packages/support/src/Math/Exception/MathException.php +++ b/packages/support/src/Math/Exception/MathException.php @@ -4,6 +4,4 @@ namespace Tempest\Support\Math\Exception; -interface MathException -{ -} +interface MathException {} diff --git a/packages/support/src/Math/Exception/OverflowException.php b/packages/support/src/Math/Exception/OverflowException.php index bfbd53e39..3415a9403 100644 --- a/packages/support/src/Math/Exception/OverflowException.php +++ b/packages/support/src/Math/Exception/OverflowException.php @@ -6,6 +6,4 @@ use OverflowException as PhpOverflowException; -final class OverflowException extends PhpOverflowException implements MathException -{ -} +final class OverflowException extends PhpOverflowException implements MathException {} diff --git a/packages/support/src/Math/functions.php b/packages/support/src/Math/functions.php index 9fbc60373..853d7163f 100644 --- a/packages/support/src/Math/functions.php +++ b/packages/support/src/Math/functions.php @@ -5,6 +5,10 @@ use ArithmeticError; use Closure; use DivisionByZeroError; +use Tempest\Support\Math\Exception\ArithmeticException; +use Tempest\Support\Math\Exception\DivisionByZeroException; +use Tempest\Support\Math\Exception\InvalidArgumentException; +use Tempest\Support\Math\Exception\OverflowException; use Tempest\Support\Str; use function acos as php_acos; @@ -38,7 +42,7 @@ function sqrt(float $number): float { if ($number < 0) { - throw new Exception\InvalidArgumentException('$number must be a non-negative number.'); + throw new InvalidArgumentException('$number must be a non-negative number.'); } return php_sqrt($number); @@ -115,7 +119,7 @@ function base_convert(string $value, int $fromBase, int $toBase): string $digitNumeric = stripos($fromAlphabet, $digit); if (false === $digitNumeric) { - throw new Exception\InvalidArgumentException(sprintf('Invalid digit %s in base %d', $digit, $fromBase)); + throw new InvalidArgumentException(sprintf('Invalid digit %s in base %d', $digit, $fromBase)); } $resultDecimal = bcadd($resultDecimal, bcmul((string) $digitNumeric, $placeValue)); @@ -161,7 +165,7 @@ function ceil(float $number): float function clamp(int|float $number, int|float $min, int|float $max): int|float { if ($max < $min) { - throw new Exception\InvalidArgumentException('Expected $min to be lower or equal to $max.'); + throw new InvalidArgumentException('Expected $min to be lower or equal to $max.'); } if ($number < $min) { @@ -194,9 +198,9 @@ function div(int $numerator, int $denominator): int try { return intdiv($numerator, $denominator); } catch (DivisionByZeroError $error) { - throw new Exception\DivisionByZeroException(sprintf('%s.', $error->getMessage()), $error->getCode(), $error); + throw new DivisionByZeroException(sprintf('%s.', $error->getMessage()), $error->getCode(), $error); } catch (ArithmeticError $error) { - throw new Exception\ArithmeticException( + throw new ArithmeticException( 'Division of Math\INT64_MIN by -1 is not an integer.', $error->getCode(), $error, @@ -236,7 +240,7 @@ function from_base(string $number, int $fromBase): int $result = 0; foreach (str_split($number) as $digit) { - $oval = ord($digit); + $oval = ord($digit[0]); // Branches sorted by guesstimated frequency of use. */ if (/* '0' - '9' */ $oval <= 57 && $oval >= 48) { @@ -250,13 +254,13 @@ function from_base(string $number, int $fromBase): int } if ($fromBase < $dval) { - throw new Exception\InvalidArgumentException(sprintf('Invalid digit %s in base %d', $digit, $fromBase)); + throw new InvalidArgumentException(sprintf('Invalid digit %s in base %d', $digit, $fromBase)); } $oldval = $result; $result = ($fromBase * $result) + $dval; if ($oldval > $limit || $oldval > $result) { - throw new Exception\OverflowException(sprintf('Unexpected integer overflow parsing %s from base %d', $number, $fromBase)); + throw new OverflowException(sprintf('Unexpected integer overflow parsing %s from base %d', $number, $fromBase)); } } @@ -293,7 +297,7 @@ function to_base(int $number, int $base): string function log(float $number, ?float $base = null): float { if ($number <= 0) { - throw new Exception\InvalidArgumentException('$number must be positive.'); + throw new InvalidArgumentException('$number must be positive.'); } if (null === $base) { @@ -301,11 +305,11 @@ function log(float $number, ?float $base = null): float } if ($base <= 0) { - throw new Exception\InvalidArgumentException('$base must be positive.'); + throw new InvalidArgumentException('$base must be positive.'); } if ($base === 1.0) { - throw new Exception\InvalidArgumentException('Logarithm undefined for $base of 1.0.'); + throw new InvalidArgumentException('Logarithm undefined for $base of 1.0.'); } return php_log($number, $base); diff --git a/packages/support/src/Namespace/functions.php b/packages/support/src/Namespace/functions.php index 06bc5ba26..22308bdb1 100644 --- a/packages/support/src/Namespace/functions.php +++ b/packages/support/src/Namespace/functions.php @@ -123,9 +123,11 @@ function prepare_namespace(Stringable|string $path, null|Stringable|string $root // If the path is a to a PHP file, we exclude the file name. Otherwise, // it's a path to a directory, which should be included in the namespace. if ($normalized->endsWith('.php')) { - return $normalized->contains(['/', '\\']) - ? $normalized->beforeLast(['/', '\\']) - : new ImmutableString(); + return ( + $normalized->contains(['/', '\\']) + ? $normalized->beforeLast(['/', '\\']) + : new ImmutableString() + ); } return $normalized; diff --git a/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php b/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php index 8d332b2bc..e4462f07e 100644 --- a/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php +++ b/packages/support/src/Paginator/Exceptions/ArgumentWasInvalid.php @@ -4,6 +4,4 @@ use InvalidArgumentException as PhpInvalidArgumentException; -final class ArgumentWasInvalid extends PhpInvalidArgumentException implements PaginationException -{ -} +final class ArgumentWasInvalid extends PhpInvalidArgumentException implements PaginationException {} diff --git a/packages/support/src/Paginator/Exceptions/PaginationException.php b/packages/support/src/Paginator/Exceptions/PaginationException.php index 261508265..1baf9d68a 100644 --- a/packages/support/src/Paginator/Exceptions/PaginationException.php +++ b/packages/support/src/Paginator/Exceptions/PaginationException.php @@ -2,6 +2,4 @@ namespace Tempest\Support\Paginator\Exceptions; -interface PaginationException -{ -} +interface PaginationException {} diff --git a/packages/support/src/Path/Path.php b/packages/support/src/Path/Path.php index f5f320620..c24967c11 100644 --- a/packages/support/src/Path/Path.php +++ b/packages/support/src/Path/Path.php @@ -24,7 +24,7 @@ public function __construct(Stringable|string ...$paths) protected function createOrModify(Stringable|string $string): self { - return new static($string); + return new self($string); } /** diff --git a/packages/support/src/Path/functions.php b/packages/support/src/Path/functions.php index 4a8295234..f11d6675f 100644 --- a/packages/support/src/Path/functions.php +++ b/packages/support/src/Path/functions.php @@ -55,7 +55,7 @@ function is_absolute_path(null|Stringable|string ...$parts): bool { $path = namespace\normalize(...$parts); - if (strlen($path) === 0 || '.' === $path[0]) { + if ($path === '' || '.' === $path[0]) { return false; } @@ -149,7 +149,7 @@ function normalize(null|Stringable|string ...$paths): string // Restore virtual phar prefix if (str_starts_with($path, 'phar:')) { - $path = str_replace('phar:', 'phar://', $path); + return str_replace('phar:', 'phar://', $path); } return $path; diff --git a/packages/support/src/Regex/InvalidPatternException.php b/packages/support/src/Regex/InvalidPatternException.php index c607821b7..6814b90a1 100644 --- a/packages/support/src/Regex/InvalidPatternException.php +++ b/packages/support/src/Regex/InvalidPatternException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class InvalidPatternException extends RuntimeException -{ -} +final class InvalidPatternException extends RuntimeException {} diff --git a/packages/support/src/Str/ImmutableString.php b/packages/support/src/Str/ImmutableString.php index 86302f21f..b29d8a931 100644 --- a/packages/support/src/Str/ImmutableString.php +++ b/packages/support/src/Str/ImmutableString.php @@ -56,6 +56,6 @@ public function when(mixed $condition, Closure $callback): self */ protected function createOrModify(Stringable|string $string): self { - return new static($string); + return new self($string); } } diff --git a/packages/support/src/Str/ManipulatesString.php b/packages/support/src/Str/ManipulatesString.php index 140f4e72c..868d6e82c 100644 --- a/packages/support/src/Str/ManipulatesString.php +++ b/packages/support/src/Str/ManipulatesString.php @@ -7,8 +7,11 @@ use ArrayAccess; use Closure; use Countable; +use RuntimeException; use Stringable; +use Tempest\Debug\Debug; use Tempest\Intl; +use Tempest\Intl\Pluralizer\Pluralizer; use Tempest\Support\Arr\ImmutableArray; use Tempest\Support\Random; use Tempest\Support\Regex; @@ -837,8 +840,8 @@ public function length(): int private function ensurePluralizerInstalled(string $function): void { - if (! interface_exists(Intl\Pluralizer\Pluralizer::class)) { - throw new \RuntimeException("The `tempest/intl` package is required to use `{$function}`."); + if (! interface_exists(Pluralizer::class)) { + throw new RuntimeException("The `tempest/intl` package is required to use `{$function}`."); } } @@ -874,7 +877,7 @@ public function dump(mixed ...$dumps): self private function debugLog(array $items, bool $terminate = false): void { - $debugClass = \Tempest\Debug\Debug::class; + $debugClass = Debug::class; if (class_exists($debugClass)) { $debugClass::resolve()->log($items); diff --git a/packages/support/src/Str/StringInterface.php b/packages/support/src/Str/StringInterface.php index 1fc7f43f2..c56f72700 100644 --- a/packages/support/src/Str/StringInterface.php +++ b/packages/support/src/Str/StringInterface.php @@ -10,6 +10,4 @@ /** * @internal This interface is not meant to be used in userland. */ -interface StringInterface extends Stringable, JsonSerializable -{ -} +interface StringInterface extends Stringable, JsonSerializable {} diff --git a/packages/support/src/Str/functions.php b/packages/support/src/Str/functions.php index 5842b86a7..89a22f7d8 100644 --- a/packages/support/src/Str/functions.php +++ b/packages/support/src/Str/functions.php @@ -29,7 +29,7 @@ function to_title_case(Stringable|string $string): string function to_sentence_case(Stringable|string $string): string { $words = array_map( - callback: fn (string $string) => to_lower_case($string), + callback: to_lower_case(...), array: to_words($string), ); @@ -658,13 +658,7 @@ function slice(Stringable|string $string, int $start, ?int $length = null): stri */ function contains(Stringable|string $string, Stringable|string|array $needle): bool { - foreach (Arr\wrap($needle) as $item) { - if (str_contains((string) $string, (string) $item)) { - return true; - } - } - - return false; + return array_any(Arr\wrap($needle), fn ($item) => str_contains((string) $string, (string) $item)); } /** @@ -698,9 +692,7 @@ function chunk(Stringable|string $string, int $length): array $chunks = []; - foreach (str_split($string, $length) as $chunk) { - $chunks[] = $chunk; - } + $chunks = str_split($string, $length); return $chunks; } diff --git a/packages/support/src/Uri/Uri.php b/packages/support/src/Uri/Uri.php index aedf22f6d..49c7ad062 100644 --- a/packages/support/src/Uri/Uri.php +++ b/packages/support/src/Uri/Uri.php @@ -4,20 +4,21 @@ namespace Tempest\Support\Uri; +use Stringable; use Tempest\Support\Str; use Tempest\Support\Str\ImmutableString; use Tempest\Support\Str\MutableString; use function parse_url; -final class Uri +final class Uri implements Stringable { /** * The path segments as an array. */ public array $segments { get { - if ($this->path === null || $this->path === '' || $this->path === '/') { + if (in_array($this->path, [null, '', '/'], true)) { return []; } @@ -180,10 +181,8 @@ public function withoutQuery(mixed ...$query): self foreach ($query as $key => $value) { if (is_int($key)) { unset($currentQuery[$value]); - } else { - if (isset($currentQuery[$key]) && $currentQuery[$key] === $value) { - unset($currentQuery[$key]); - } + } elseif (isset($currentQuery[$key]) && $currentQuery[$key] === $value) { + unset($currentQuery[$key]); } } diff --git a/packages/support/src/Uri/functions.php b/packages/support/src/Uri/functions.php index 325c5308a..ce250ea3a 100644 --- a/packages/support/src/Uri/functions.php +++ b/packages/support/src/Uri/functions.php @@ -25,7 +25,7 @@ function merge_query(string $uri, mixed ...$query): string */ function without_query(string $uri, mixed ...$query): string { - if (count($query) === 0) { + if ($query === []) { return Uri::from($uri)->removeQuery()->toString(); } diff --git a/packages/support/src/VarExport/EmptyFileNameException.php b/packages/support/src/VarExport/EmptyFileNameException.php index ea0c884e9..971c27016 100644 --- a/packages/support/src/VarExport/EmptyFileNameException.php +++ b/packages/support/src/VarExport/EmptyFileNameException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class EmptyFileNameException extends RuntimeException -{ -} +final class EmptyFileNameException extends RuntimeException {} diff --git a/packages/support/src/VarExport/FileDoesNotExistException.php b/packages/support/src/VarExport/FileDoesNotExistException.php index 4b60ade07..42e029314 100644 --- a/packages/support/src/VarExport/FileDoesNotExistException.php +++ b/packages/support/src/VarExport/FileDoesNotExistException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class FileDoesNotExistException extends RuntimeException -{ -} +final class FileDoesNotExistException extends RuntimeException {} diff --git a/packages/support/src/VarExport/VarExportPhpFile.php b/packages/support/src/VarExport/VarExportPhpFile.php index 3cc625266..fb17b7e3a 100644 --- a/packages/support/src/VarExport/VarExportPhpFile.php +++ b/packages/support/src/VarExport/VarExportPhpFile.php @@ -47,9 +47,9 @@ public function export(mixed $data): void $serializedData = VarExporter::export($data); $phpFileContent = <<filename, $phpFileContent, LOCK_EX); } diff --git a/packages/support/tests/Arr/ImmutableArrayTest.php b/packages/support/tests/Arr/ImmutableArrayTest.php index 07cdb1ebe..77ffa5a23 100644 --- a/packages/support/tests/Arr/ImmutableArrayTest.php +++ b/packages/support/tests/Arr/ImmutableArrayTest.php @@ -62,8 +62,8 @@ public function test_add_diverse_values(): void ); $this->assertSame( - actual: $collection->add('name')->toArray(), expected: ['name'], + actual: $collection->add('name')->toArray(), ); } diff --git a/packages/support/tests/Arr/ManipulatesArrayTest.php b/packages/support/tests/Arr/ManipulatesArrayTest.php index 46744bc84..fd42145c3 100644 --- a/packages/support/tests/Arr/ManipulatesArrayTest.php +++ b/packages/support/tests/Arr/ManipulatesArrayTest.php @@ -950,8 +950,8 @@ public function test_add_diverse_values(): void ); $this->assertSame( - actual: $collection->add('name')->toArray(), expected: ['name'], + actual: $collection->add('name')->toArray(), ); } @@ -1639,9 +1639,7 @@ public function test_find_key_with_complex_closure(): void ['age' => 35, 'active' => true], ]); - $result = $collection->findKey(function ($item) { - return $item['age'] > 28 && $item['active'] === true; - }); + $result = $collection->findKey(fn ($item) => $item['age'] > 28 && $item['active'] === true); $this->assertSame(2, $result); } @@ -1698,18 +1696,18 @@ public function test_append(): void $collection = arr(['foo', 'bar']); $this->assertSame( - actual: $collection->append('foo')->toArray(), expected: ['foo', 'bar', 'foo'], + actual: $collection->append('foo')->toArray(), ); $this->assertSame( - actual: $collection->append(1, 'b')->toArray(), expected: ['foo', 'bar', 1, 'b'], + actual: $collection->append(1, 'b')->toArray(), ); $this->assertSame( - actual: $collection->append(['a' => 'b'])->toArray(), expected: ['foo', 'bar', ['a' => 'b']], + actual: $collection->append(['a' => 'b'])->toArray(), ); } @@ -1718,18 +1716,18 @@ public function test_prepend(): void $collection = arr(['foo', 'bar']); $this->assertSame( - actual: $collection->prepend('foo')->toArray(), expected: ['foo', 'foo', 'bar'], + actual: $collection->prepend('foo')->toArray(), ); $this->assertSame( - actual: $collection->prepend(1, 'b')->toArray(), expected: [1, 'b', 'foo', 'bar'], + actual: $collection->prepend(1, 'b')->toArray(), ); $this->assertSame( - actual: $collection->prepend(['a' => 'b'])->toArray(), expected: [['a' => 'b'], 'foo', 'bar'], + actual: $collection->prepend(['a' => 'b'])->toArray(), ); } @@ -1809,7 +1807,7 @@ public function test_at(array $input, int $index, mixed $expected, mixed $defaul public function test_partition(): void { - $this->assertSame([[true, true], [false]], arr([true, true, false])->partition(fn (bool $value) => $value === true)->toArray()); + $this->assertSame([[true, true], [false]], arr([true, true, false])->partition(fn (bool $value) => $value)->toArray()); } public function test_json_encode(): void diff --git a/packages/support/tests/Arr/MutableArrayTest.php b/packages/support/tests/Arr/MutableArrayTest.php index 561b85268..e159cf599 100644 --- a/packages/support/tests/Arr/MutableArrayTest.php +++ b/packages/support/tests/Arr/MutableArrayTest.php @@ -62,8 +62,8 @@ public function test_add_diverse_values(): void ); $this->assertSame( - actual: $collection->add('name')->toArray(), expected: [1, 2, '', null, false, [], 'name'], + actual: $collection->add('name')->toArray(), ); } diff --git a/packages/support/tests/Comparison/ComparisonTest.php b/packages/support/tests/Comparison/ComparisonTest.php index 2eea88cc7..9d5379926 100644 --- a/packages/support/tests/Comparison/ComparisonTest.php +++ b/packages/support/tests/Comparison/ComparisonTest.php @@ -3,6 +3,7 @@ namespace Tempest\Support\Tests\Comparison; use Generator; +use Override; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Tempest\Support\Comparison; @@ -20,10 +21,10 @@ public function test_it_can_compare(mixed $a, mixed $b, Order $expected): void public function test_it_can_fail_comparing(): void { - $a = static::createIncomparableWrapper(1); - $b = static::createIncomparableWrapper(2); + $a = $this->createIncomparableWrapper(1); + $b = $this->createIncomparableWrapper(2); - $this->expectException(Comparison\Exception\IncomparableException::class); + $this->expectException(IncomparableException::class); $this->expectExceptionMessage('Unable to compare "int" with "int".'); Comparison\compare($a, $b); @@ -31,10 +32,10 @@ public function test_it_can_fail_comparing(): void public function test_it_can_fail_comparing_with_additional_info(): void { - $a = static::createIncomparableWrapper(1, 'Can only compare even numbers'); - $b = static::createIncomparableWrapper(2); + $a = $this->createIncomparableWrapper(1, 'Can only compare even numbers'); + $b = $this->createIncomparableWrapper(2); - $this->expectException(Comparison\Exception\IncomparableException::class); + $this->expectException(IncomparableException::class); $this->expectExceptionMessage('Unable to compare "int" with "int": Can only compare even numbers'); Comparison\compare($a, $b); @@ -48,35 +49,35 @@ public static function provideComparisonCases(): Generator yield 'scalar-greater' => [1, 0, Order::GREATER]; yield 'comparable-default' => [ - static::createComparableIntWrapper(0), - static::createComparableIntWrapper(0), + self::createComparableIntWrapper(0), + self::createComparableIntWrapper(0), Order::default(), ]; yield 'comparable-equal' => [ - static::createComparableIntWrapper(0), - static::createComparableIntWrapper(0), + self::createComparableIntWrapper(0), + self::createComparableIntWrapper(0), Order::EQUAL, ]; yield 'comparable-less' => [ - static::createComparableIntWrapper(0), - static::createComparableIntWrapper(1), + self::createComparableIntWrapper(0), + self::createComparableIntWrapper(1), Order::LESS, ]; yield 'comparable-greater' => [ - static::createComparableIntWrapper(1), - static::createComparableIntWrapper(0), + self::createComparableIntWrapper(1), + self::createComparableIntWrapper(0), Order::GREATER, ]; } private static function createComparableIntWrapper(int $i): Comparable { - return new class($i) implements Comparable { + return new readonly class($i) implements Comparable { public function __construct( - public readonly int $int, + public int $int, ) {} - #[\Override] + #[Override] public function compare(mixed $other): Order { return Order::from($this->int <=> $other->int); @@ -84,15 +85,15 @@ public function compare(mixed $other): Order }; } - private static function createIncomparableWrapper(int $i, string $additionalInfo = ''): Comparable + private function createIncomparableWrapper(int $i, string $additionalInfo = ''): Comparable { - return new class($i, $additionalInfo) implements Comparable { + return new readonly class($i, $additionalInfo) implements Comparable { public function __construct( - public readonly int $int, - public readonly string $additionalInfo, + public int $int, + public string $additionalInfo, ) {} - #[\Override] + #[Override] public function compare(mixed $other): Order { throw IncomparableException::fromValues($this->int, $other->int, $this->additionalInfo); diff --git a/packages/support/tests/Filesystem/UnixFunctionsTest.php b/packages/support/tests/Filesystem/UnixFunctionsTest.php index d30c3a8a7..7838eea55 100644 --- a/packages/support/tests/Filesystem/UnixFunctionsTest.php +++ b/packages/support/tests/Filesystem/UnixFunctionsTest.php @@ -2,6 +2,8 @@ namespace Tempest\Support\Tests\Filesystem; +use JsonSerializable; +use Phar; use PHPUnit\Framework\Attributes\PostCondition; use PHPUnit\Framework\Attributes\PreCondition; use PHPUnit\Framework\Attributes\Test; @@ -849,7 +851,7 @@ public function write_json_serializable(): void { $file = $this->fixtures . '/tmp/file.json'; - $data = new class implements \JsonSerializable { + $data = new class implements JsonSerializable { public function jsonSerialize(): array { return ['key' => 'value']; @@ -1008,12 +1010,12 @@ public function delete_file_for_invalid_symlink(): void #[Test] public function normalize_path_in_phar(): void { - if (\Phar::canWrite() === false) { + if (Phar::canWrite() === false) { $this->markTestSkipped('phar.readonly is enabled in php.ini.'); } $pharFile = $this->fixtures . '/phar.phar'; - $phar = new \Phar($pharFile, 0, 'phar.phar'); + $phar = new Phar($pharFile, 0, 'phar.phar'); $phar->addFile(__DIR__ . '/../../src/Filesystem/functions.php', 'functions.php'); $phar->addFile(__DIR__ . '/../Fixtures/Phar/normalize_path.php', 'index.php'); $phar->createDefaultStub('index.php'); diff --git a/packages/support/tests/Json/JsonTest.php b/packages/support/tests/Json/JsonTest.php index f8b746760..e944de6f3 100644 --- a/packages/support/tests/Json/JsonTest.php +++ b/packages/support/tests/Json/JsonTest.php @@ -4,6 +4,8 @@ use PHPUnit\Framework\TestCase; use Tempest\Support\Json; +use Tempest\Support\Json\Exception\JsonCouldNotBeDecoded; +use Tempest\Support\Json\Exception\JsonCouldNotBeEncoded; use Tempest\Support\Math; use Tempest\Support\Str; @@ -33,7 +35,7 @@ public function test_decode(): void public function test_decode_throws_for_invalid_syntax(): void { - $this->expectException(Json\Exception\JsonCouldNotBeDecoded::class); + $this->expectException(JsonCouldNotBeDecoded::class); $this->expectExceptionMessage('The decoded property name is invalid.'); Json\decode('{"\u0000": 1}', false); @@ -41,7 +43,7 @@ public function test_decode_throws_for_invalid_syntax(): void public function test_decode_malformed_utf8(): void { - $this->expectException(Json\Exception\JsonCouldNotBeDecoded::class); + $this->expectException(JsonCouldNotBeDecoded::class); $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded.'); Json\decode("\"\xC1\xBF\""); @@ -65,27 +67,27 @@ public function test_pretty_encode(): void ], true); $json = Str\replace(<<assertSame($json, $actual); } public function test_encode_throws_for_malformed_utf8(): void { - $this->expectException(Json\Exception\JsonCouldNotBeEncoded::class); + $this->expectException(JsonCouldNotBeEncoded::class); $this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded.'); Json\encode(["bad utf\xFF"]); @@ -93,7 +95,7 @@ public function test_encode_throws_for_malformed_utf8(): void public function test_encode_throws_with_nan(): void { - $this->expectException(Json\Exception\JsonCouldNotBeEncoded::class); + $this->expectException(JsonCouldNotBeEncoded::class); $this->expectExceptionMessage('Inf and NaN cannot be JSON encoded.'); Json\encode(Math\NAN); @@ -101,7 +103,7 @@ public function test_encode_throws_with_nan(): void public function test_encode_throws_with_inf(): void { - $this->expectException(Json\Exception\JsonCouldNotBeEncoded::class); + $this->expectException(JsonCouldNotBeEncoded::class); $this->expectExceptionMessage('Inf and NaN cannot be JSON encoded.'); Json\encode(Math\INFINITY); @@ -143,7 +145,7 @@ public function test_base64_encode_and_decode(): void public function test_base64_decode_failure(): void { - $this->expectException(Json\Exception\JsonCouldNotBeDecoded::class); + $this->expectException(JsonCouldNotBeDecoded::class); $this->expectExceptionMessage('The provided base64 string is not valid.'); Json\decode('invalid_base64', base64: true); diff --git a/packages/support/tests/Math/MathsTest.php b/packages/support/tests/Math/MathsTest.php index 937195336..cc232784c 100644 --- a/packages/support/tests/Math/MathsTest.php +++ b/packages/support/tests/Math/MathsTest.php @@ -8,6 +8,10 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\TestCase; use Tempest\Support\Math; +use Tempest\Support\Math\Exception\ArithmeticException; +use Tempest\Support\Math\Exception\DivisionByZeroException; +use Tempest\Support\Math\Exception\InvalidArgumentException; +use Tempest\Support\Math\Exception\OverflowException; use function Tempest\Support\Arr\range; @@ -96,7 +100,7 @@ public function test_clamp(int|float $expected, int|float $number, int|float $mi public function test_clamp_invalid_min_max(): void { - $this->expectException(Math\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected $min to be lower or equal to $max.'); Math\clamp(10, 20, 10); @@ -123,7 +127,7 @@ public function test_div(int $expected, int $numerator, int $denominator): void public function test_div_by_zero(): void { - $this->expectException(Math\Exception\DivisionByZeroException::class); + $this->expectException(DivisionByZeroException::class); $this->expectExceptionMessage('Division by zero.'); Math\div(10, 0); @@ -131,7 +135,7 @@ public function test_div_by_zero(): void public function test_div_int64_min_by_minus_one(): void { - $this->expectException(Math\Exception\ArithmeticException::class); + $this->expectException(ArithmeticException::class); $this->expectExceptionMessage('Division of Math\INT64_MIN by -1 is not an integer.'); Math\div(Math\INT64_MIN, -1); @@ -166,7 +170,7 @@ public function test_from_base(int $expected, string $value, int $from_base): vo public function test_invalid_digit_throws(): void { - $this->expectException(Math\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid digit Z in base 16'); Math\from_base('Z', 16); @@ -174,7 +178,7 @@ public function test_invalid_digit_throws(): void public function test_special_char_throws(): void { - $this->expectException(Math\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid digit * in base 16'); Math\from_base('*', 16); @@ -184,7 +188,7 @@ public function test_throws_for_overflow(): void { $number = str_repeat('A', times: 100); - $this->expectException(Math\Exception\OverflowException::class); + $this->expectException(OverflowException::class); $this->expectExceptionMessage('Unexpected integer overflow parsing ' . $number . ' from base 32'); Math\from_base($number, 32); @@ -201,7 +205,7 @@ public function test_log(float $expected, float $number, ?float $base = null): v public function test_negative_input_throws(): void { - $this->expectException(Math\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('$number must be positive.'); Math\log(-45); @@ -209,7 +213,7 @@ public function test_negative_input_throws(): void public function test_non_positive_base_throws(): void { - $this->expectException(Math\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('$base must be positive.'); Math\log(4.4, 0.0); @@ -217,7 +221,7 @@ public function test_non_positive_base_throws(): void public function test_base_one_throws_for_undefined_logarithm(): void { - $this->expectException(Math\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Logarithm undefined for $base of 1.0.'); Math\log(4.4, 1.0); @@ -234,7 +238,7 @@ public static function provide_max_by_cases(): Generator yield [ 'bazqux', ['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'], - static fn (string $value): int => mb_strlen($value), + mb_strlen(...), ]; yield [ @@ -244,7 +248,7 @@ public static function provide_max_by_cases(): Generator ['foo', 'bar'], ['foo', 'bar', 'baz'], ], - static fn (array $arr): int => count($arr), + count(...), ]; yield [ @@ -328,7 +332,7 @@ public static function provide_min_by_cases(): Generator yield [ 'qux', ['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'], - static fn (string $value): int => mb_strlen($value), + mb_strlen(...), ]; yield [ @@ -338,7 +342,7 @@ public static function provide_min_by_cases(): Generator ['foo', 'bar'], ['foo', 'bar', 'baz'], ], - static fn (array $arr): int => count($arr), + count(...), ]; yield [ diff --git a/packages/support/tests/Namespace/FunctionsTest.php b/packages/support/tests/Namespace/FunctionsTest.php index 6deb9d923..e0057a6b2 100644 --- a/packages/support/tests/Namespace/FunctionsTest.php +++ b/packages/support/tests/Namespace/FunctionsTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use Tempest\Support\Namespace\PathCouldNotBeMappedToNamespace; use Tempest\Support\Namespace\Psr4Namespace; +use Tempest\Vite\Vite; use function Tempest\Support\Namespace\to_base_class_name; use function Tempest\Support\Namespace\to_fqcn; @@ -72,7 +73,7 @@ public function to_composer_namespace_exceptions(string $path, string $expected, #[TestWith(['spp/Vite.php', 'Vite'])] #[TestWith(['Vite.php', 'Vite'])] #[TestWith(['Vite', 'Vite'])] - #[TestWith([\Tempest\Vite\Vite::class, 'Vite'])] + #[TestWith([Vite::class, 'Vite'])] #[Test] public function to_base_class_name(string $path, string $expected): void { diff --git a/packages/support/tests/Paginator/PaginatorTest.php b/packages/support/tests/Paginator/PaginatorTest.php index c93a7b3fd..f48db6711 100644 --- a/packages/support/tests/Paginator/PaginatorTest.php +++ b/packages/support/tests/Paginator/PaginatorTest.php @@ -140,9 +140,7 @@ public function test_it_creates_paginated_data_with_callback(): void { $paginator = $this->createPaginator(totalItems: 100, itemsPerPage: 10, currentPage: 3); - $dataFetcher = function (int $_limit, int $offset): array { - return ["item_{$offset}_1", "item_{$offset}_2"]; - }; + $dataFetcher = fn (int $_limit, int $offset): array => ["item_{$offset}_1", "item_{$offset}_2"]; $paginatedData = $paginator->paginateWith($dataFetcher); diff --git a/packages/upgrade/src/Set/TempestLevelSetList.php b/packages/upgrade/src/Set/TempestLevelSetList.php index 859b32034..663a94398 100644 --- a/packages/upgrade/src/Set/TempestLevelSetList.php +++ b/packages/upgrade/src/Set/TempestLevelSetList.php @@ -7,6 +7,8 @@ final class TempestLevelSetList { public const string UP_TO_TEMPEST_20 = __DIR__ . '/../../config/sets/level/up-to-tempest-20.php'; + public const string UP_TO_TEMPEST_28 = __DIR__ . '/../../config/sets/level/up-to-tempest-28.php'; + public const string UP_TO_TEMPEST_30 = __DIR__ . '/../../config/sets/level/up-to-tempest-30.php'; } diff --git a/packages/upgrade/src/Set/TempestSetList.php b/packages/upgrade/src/Set/TempestSetList.php index 8c4bcaa29..1c6f09154 100644 --- a/packages/upgrade/src/Set/TempestSetList.php +++ b/packages/upgrade/src/Set/TempestSetList.php @@ -7,6 +7,8 @@ final class TempestSetList { public const string TEMPEST_20 = __DIR__ . '/../../config/sets/tempest20.php'; + public const string TEMPEST_28 = __DIR__ . '/../../config/sets/tempest28.php'; + public const string TEMPEST_30 = __DIR__ . '/../../config/sets/tempest30.php'; } diff --git a/packages/upgrade/src/Tempest2/MigrationRector.php b/packages/upgrade/src/Tempest2/MigrationRector.php index d0c36722f..674bd0331 100644 --- a/packages/upgrade/src/Tempest2/MigrationRector.php +++ b/packages/upgrade/src/Tempest2/MigrationRector.php @@ -3,8 +3,11 @@ namespace Tempest\Upgrade\Tempest2; use PhpParser\Node; +use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Name; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Return_; use Rector\Rector\AbstractRector; final class MigrationRector extends AbstractRector @@ -12,13 +15,13 @@ final class MigrationRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\Stmt\Class_::class, + Class_::class, ]; } public function refactor(Node $node): ?int { - if (! $node instanceof Node\Stmt\Class_) { + if (! $node instanceof Class_) { return null; } @@ -27,7 +30,7 @@ public function refactor(Node $node): ?int $implementsDatabaseMigration = array_find_key( $implements, - static fn (Node\Name $name) => $name->toString() === 'Tempest\Database\DatabaseMigration', + static fn (Name $name) => $name->toString() === 'Tempest\Database\DatabaseMigration', ); if ($implementsDatabaseMigration === null) { @@ -38,7 +41,7 @@ public function refactor(Node $node): ?int unset($implements[$implementsDatabaseMigration]); // Add the new MigrateUp interface - $implements[] = new Node\Name('\Tempest\Database\MigratesUp'); + $implements[] = new Name('\Tempest\Database\MigratesUp'); $node->getMethod('up')->returnType = new Name('QueryStatement'); // Check whether the migration has a down method implemented or not @@ -47,11 +50,11 @@ public function refactor(Node $node): ?int $migratesDown = true; foreach ($downStatements as $statement) { - if (! $statement instanceof Node\Stmt\Return_) { + if (! $statement instanceof Return_) { continue; } - if (! $statement->expr instanceof Node\Expr\ConstFetch) { + if (! $statement->expr instanceof ConstFetch) { continue; } @@ -62,7 +65,7 @@ public function refactor(Node $node): ?int if ($migratesDown) { // If the migration has a down method implemented, we'll add the new MigrateDown interface - $implements[] = new Node\Name('\Tempest\Database\MigratesDown'); + $implements[] = new Name('\Tempest\Database\MigratesDown'); $node->getMethod('down')->returnType = new Name('QueryStatement'); } else { // If the migration does not have a down method implemented, we'll remove it entirely diff --git a/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php b/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php index c6d627480..90906215b 100644 --- a/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php +++ b/packages/upgrade/src/Tempest2/RemoveDatabaseMigrationImportRector.php @@ -3,6 +3,7 @@ namespace Tempest\Upgrade\Tempest2; use PhpParser\Node; +use PhpParser\Node\UseItem; use PhpParser\NodeVisitor; use Rector\Rector\AbstractRector; @@ -11,13 +12,13 @@ final class RemoveDatabaseMigrationImportRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, + UseItem::class, ]; } public function refactor(Node $node): ?int { - if (! $node instanceof Node\UseItem) { + if (! $node instanceof UseItem) { return null; } diff --git a/packages/upgrade/src/Tempest2/RemoveIdImportRector.php b/packages/upgrade/src/Tempest2/RemoveIdImportRector.php index d8b5ccf28..2481736ec 100644 --- a/packages/upgrade/src/Tempest2/RemoveIdImportRector.php +++ b/packages/upgrade/src/Tempest2/RemoveIdImportRector.php @@ -3,6 +3,7 @@ namespace Tempest\Upgrade\Tempest2; use PhpParser\Node; +use PhpParser\Node\UseItem; use PhpParser\NodeVisitor; use Rector\Rector\AbstractRector; @@ -11,13 +12,13 @@ final class RemoveIdImportRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, + UseItem::class, ]; } public function refactor(Node $node): ?int { - if (! $node instanceof Node\UseItem) { + if (! $node instanceof UseItem) { return null; } diff --git a/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php b/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php index 0ee1a6f0c..323b16c8c 100644 --- a/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php +++ b/packages/upgrade/src/Tempest2/UpdateUriImportsRector.php @@ -3,6 +3,8 @@ namespace Tempest\Upgrade\Tempest2; use PhpParser\Node; +use PhpParser\Node\Name; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateUriImportsRector extends AbstractRector @@ -10,22 +12,22 @@ final class UpdateUriImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, + UseItem::class, ]; } public function refactor(Node $node): ?int { - if (! $node instanceof Node\UseItem) { + if (! $node instanceof UseItem) { return null; } if ($node->name->toString() === 'Tempest\uri') { - $node->name = new Node\Name('Tempest\Router\uri'); + $node->name = new Name('Tempest\Router\uri'); } if ($node->name->toString() === 'Tempest\is_current_uri') { - $node->name = new Node\Name('Tempest\Router\is_current_uri'); + $node->name = new Name('Tempest\Router\is_current_uri'); } return null; diff --git a/packages/upgrade/src/Tempest28/WriteableRouteRector.php b/packages/upgrade/src/Tempest28/WriteableRouteRector.php index 630a8055e..ce93fe661 100644 --- a/packages/upgrade/src/Tempest28/WriteableRouteRector.php +++ b/packages/upgrade/src/Tempest28/WriteableRouteRector.php @@ -4,6 +4,8 @@ use PhpParser\Modifiers; use PhpParser\Node; +use PhpParser\Node\Name; +use PhpParser\Node\Stmt\Class_; use Rector\Rector\AbstractRector; use Tempest\Router\Route; @@ -12,13 +14,13 @@ final class WriteableRouteRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\Stmt\Class_::class, + Class_::class, ]; } public function refactor(Node $node): ?int { - if (! $node instanceof Node\Stmt\Class_) { + if (! $node instanceof Class_) { return null; } @@ -27,7 +29,7 @@ public function refactor(Node $node): ?int $implementsRoute = array_find_key( $implements, - static fn (Node\Name $name) => $name->toString() === Route::class, + static fn (Name $name) => $name->toString() === Route::class, ); if ($implementsRoute === null) { diff --git a/packages/upgrade/src/Tempest3/UpdateArrMapFunctionRector.php b/packages/upgrade/src/Tempest3/UpdateArrMapFunctionRector.php index 1433c62e4..aa6fefc97 100644 --- a/packages/upgrade/src/Tempest3/UpdateArrMapFunctionRector.php +++ b/packages/upgrade/src/Tempest3/UpdateArrMapFunctionRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateArrMapFunctionRector extends AbstractRector @@ -10,26 +14,26 @@ final class UpdateArrMapFunctionRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\Support\Arr\map_iterable') { - $node->name = new Node\Name('Tempest\Support\Arr\map'); + $node->name = new Name('Tempest\Support\Arr\map'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\Support\Arr\map_iterable') { - $node->name = new Node\Name\FullyQualified('Tempest\Support\Arr\map'); + $node->name = new FullyQualified('Tempest\Support\Arr\map'); return null; } diff --git a/packages/upgrade/src/Tempest3/UpdateBindableResolveReturnTypeRector.php b/packages/upgrade/src/Tempest3/UpdateBindableResolveReturnTypeRector.php index 43544b8de..2fb347216 100644 --- a/packages/upgrade/src/Tempest3/UpdateBindableResolveReturnTypeRector.php +++ b/packages/upgrade/src/Tempest3/UpdateBindableResolveReturnTypeRector.php @@ -6,6 +6,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\NullableType; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Interface_; use Rector\Rector\AbstractRector; @@ -15,7 +16,7 @@ final class UpdateBindableResolveReturnTypeRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\Stmt\Class_::class, + Class_::class, Interface_::class, ]; } @@ -32,7 +33,7 @@ public function refactor(Node $node): ?int return null; } - if (! $node instanceof Node\Stmt\Class_) { + if (! $node instanceof Class_) { return null; } @@ -67,7 +68,11 @@ private function hasBindableName(array $names): bool private function refactorMethods(array $methods): void { foreach ($methods as $method) { - if ($method->name->toString() !== 'resolve' || ! $method->isStatic()) { + if ($method->name->toString() !== 'resolve') { + continue; + } + + if (! $method->isStatic()) { continue; } diff --git a/packages/upgrade/src/Tempest3/UpdateCommandFunctionImportsRector.php b/packages/upgrade/src/Tempest3/UpdateCommandFunctionImportsRector.php index 9aad37e1a..8233e11b2 100644 --- a/packages/upgrade/src/Tempest3/UpdateCommandFunctionImportsRector.php +++ b/packages/upgrade/src/Tempest3/UpdateCommandFunctionImportsRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateCommandFunctionImportsRector extends AbstractRector @@ -10,26 +14,26 @@ final class UpdateCommandFunctionImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\command') { - $node->name = new Node\Name('Tempest\CommandBus\command'); + $node->name = new Name('Tempest\CommandBus\command'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\command') { - $node->name = new Node\Name\FullyQualified('Tempest\CommandBus\command'); + $node->name = new FullyQualified('Tempest\CommandBus\command'); return null; } diff --git a/packages/upgrade/src/Tempest3/UpdateContainerFunctionImportsRector.php b/packages/upgrade/src/Tempest3/UpdateContainerFunctionImportsRector.php index 106193e62..cbbd9934c 100644 --- a/packages/upgrade/src/Tempest3/UpdateContainerFunctionImportsRector.php +++ b/packages/upgrade/src/Tempest3/UpdateContainerFunctionImportsRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateContainerFunctionImportsRector extends AbstractRector @@ -10,36 +14,36 @@ final class UpdateContainerFunctionImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\get') { - $node->name = new Node\Name('Tempest\Container\get'); + $node->name = new Name('Tempest\Container\get'); } if ($node->name->toString() === 'Tempest\invoke') { - $node->name = new Node\Name('Tempest\Container\invoke'); + $node->name = new Name('Tempest\Container\invoke'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\get') { - $node->name = new Node\Name\FullyQualified('Tempest\Container\get'); + $node->name = new FullyQualified('Tempest\Container\get'); return null; } if ($functionName === 'Tempest\invoke') { - $node->name = new Node\Name\FullyQualified('Tempest\Container\invoke'); + $node->name = new FullyQualified('Tempest\Container\invoke'); return null; } diff --git a/packages/upgrade/src/Tempest3/UpdateEventFunctionImportsRector.php b/packages/upgrade/src/Tempest3/UpdateEventFunctionImportsRector.php index 30962f6b5..e62e5c27d 100644 --- a/packages/upgrade/src/Tempest3/UpdateEventFunctionImportsRector.php +++ b/packages/upgrade/src/Tempest3/UpdateEventFunctionImportsRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateEventFunctionImportsRector extends AbstractRector @@ -10,36 +14,36 @@ final class UpdateEventFunctionImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\event') { - $node->name = new Node\Name('Tempest\EventBus\event'); + $node->name = new Name('Tempest\EventBus\event'); } if ($node->name->toString() === 'Tempest\listen') { - $node->name = new Node\Name('Tempest\EventBus\listen'); + $node->name = new Name('Tempest\EventBus\listen'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\event') { - $node->name = new Node\Name\FullyQualified('Tempest\EventBus\event'); + $node->name = new FullyQualified('Tempest\EventBus\event'); return null; } if ($functionName === 'Tempest\listen') { - $node->name = new Node\Name\FullyQualified('Tempest\EventBus\listen'); + $node->name = new FullyQualified('Tempest\EventBus\listen'); return null; } diff --git a/packages/upgrade/src/Tempest3/UpdateExceptionProcessorRector.php b/packages/upgrade/src/Tempest3/UpdateExceptionProcessorRector.php index 7bb7dc54a..157c539b9 100644 --- a/packages/upgrade/src/Tempest3/UpdateExceptionProcessorRector.php +++ b/packages/upgrade/src/Tempest3/UpdateExceptionProcessorRector.php @@ -3,8 +3,11 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateExceptionProcessorRector extends AbstractRector @@ -12,24 +15,24 @@ final class UpdateExceptionProcessorRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Stmt\Class_::class, + UseItem::class, + Class_::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { $name = $node->name->toString(); if ($name === 'Tempest\Core\ExceptionProcessor' || $name === 'ExceptionProcessor') { - $node->name = new Node\Name('Tempest\Core\Exceptions\ExceptionReporter'); + $node->name = new Name('Tempest\Core\Exceptions\ExceptionReporter'); } return null; } - if (! $node instanceof Node\Stmt\Class_) { + if (! $node instanceof Class_) { return null; } @@ -37,14 +40,14 @@ public function refactor(Node $node): ?int $implementsExceptionProcessor = array_find_key( array: $implements, - callback: static fn (Node\Name $name) => $name->toString() === 'Tempest\Core\ExceptionProcessor' || $name->toString() === 'ExceptionProcessor', + callback: static fn (Name $name) => $name->toString() === 'Tempest\Core\ExceptionProcessor' || $name->toString() === 'ExceptionProcessor', ); if ($implementsExceptionProcessor === null) { return null; } - $implements[$implementsExceptionProcessor] = new Node\Name('\Tempest\Core\Exceptions\ExceptionReporter'); + $implements[$implementsExceptionProcessor] = new Name('\Tempest\Core\Exceptions\ExceptionReporter'); $node->implements = $implements; foreach ($node->stmts as $statement) { @@ -53,7 +56,7 @@ public function refactor(Node $node): ?int } if ($statement->name->toString() === 'process') { - $statement->name = new Node\Identifier('report'); + $statement->name = new Identifier('report'); break; } } diff --git a/packages/upgrade/src/Tempest3/UpdateHasContextRector.php b/packages/upgrade/src/Tempest3/UpdateHasContextRector.php index 20c115c46..6cf7b0d5d 100644 --- a/packages/upgrade/src/Tempest3/UpdateHasContextRector.php +++ b/packages/upgrade/src/Tempest3/UpdateHasContextRector.php @@ -3,6 +3,9 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Name; +use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateHasContextRector extends AbstractRector @@ -10,24 +13,24 @@ final class UpdateHasContextRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Stmt\Class_::class, + UseItem::class, + Class_::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { $name = $node->name->toString(); if ($name === 'Tempest\Core\HasContext' || $name === 'HasContext') { - $node->name = new Node\Name('Tempest\Core\ProvidesContext'); + $node->name = new Name('Tempest\Core\ProvidesContext'); } return null; } - if (! $node instanceof Node\Stmt\Class_) { + if (! $node instanceof Class_) { return null; } @@ -35,14 +38,14 @@ public function refactor(Node $node): ?int $implementsHasContext = array_find_key( array: $implements, - callback: static fn (Node\Name $name) => $name->toString() === 'Tempest\Core\HasContext' || $name->toString() === 'HasContext', + callback: static fn (Name $name) => $name->toString() === 'Tempest\Core\HasContext' || $name->toString() === 'HasContext', ); if ($implementsHasContext === null) { return null; } - $implements[$implementsHasContext] = new Node\Name('\Tempest\Core\ProvidesContext'); + $implements[$implementsHasContext] = new Name('\Tempest\Core\ProvidesContext'); $node->implements = $implements; return null; diff --git a/packages/upgrade/src/Tempest3/UpdateMapperFunctionImportsRector.php b/packages/upgrade/src/Tempest3/UpdateMapperFunctionImportsRector.php index 310bc1929..60c8b4bf6 100644 --- a/packages/upgrade/src/Tempest3/UpdateMapperFunctionImportsRector.php +++ b/packages/upgrade/src/Tempest3/UpdateMapperFunctionImportsRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateMapperFunctionImportsRector extends AbstractRector @@ -10,36 +14,36 @@ final class UpdateMapperFunctionImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\map') { - $node->name = new Node\Name('Tempest\Mapper\map'); + $node->name = new Name('Tempest\Mapper\map'); } if ($node->name->toString() === 'Tempest\make') { - $node->name = new Node\Name('Tempest\Mapper\make'); + $node->name = new Name('Tempest\Mapper\make'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\map') { - $node->name = new Node\Name\FullyQualified('Tempest\Mapper\map'); + $node->name = new FullyQualified('Tempest\Mapper\map'); return null; } if ($functionName === 'Tempest\make') { - $node->name = new Node\Name\FullyQualified('Tempest\Mapper\make'); + $node->name = new FullyQualified('Tempest\Mapper\make'); return null; } diff --git a/packages/upgrade/src/Tempest3/UpdateReflectionFunctionImportsRector.php b/packages/upgrade/src/Tempest3/UpdateReflectionFunctionImportsRector.php index 1d12c45ea..7fa793c7c 100644 --- a/packages/upgrade/src/Tempest3/UpdateReflectionFunctionImportsRector.php +++ b/packages/upgrade/src/Tempest3/UpdateReflectionFunctionImportsRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateReflectionFunctionImportsRector extends AbstractRector @@ -10,26 +14,26 @@ final class UpdateReflectionFunctionImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\reflect') { - $node->name = new Node\Name('Tempest\Reflection\reflect'); + $node->name = new Name('Tempest\Reflection\reflect'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\reflect') { - $node->name = new Node\Name\FullyQualified('Tempest\Reflection\reflect'); + $node->name = new FullyQualified('Tempest\Reflection\reflect'); return null; } diff --git a/packages/upgrade/src/Tempest3/UpdateViewFunctionImportsRector.php b/packages/upgrade/src/Tempest3/UpdateViewFunctionImportsRector.php index fdef676f5..c01f1b383 100644 --- a/packages/upgrade/src/Tempest3/UpdateViewFunctionImportsRector.php +++ b/packages/upgrade/src/Tempest3/UpdateViewFunctionImportsRector.php @@ -3,6 +3,10 @@ namespace Tempest\Upgrade\Tempest3; use PhpParser\Node; +use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; +use PhpParser\Node\UseItem; use Rector\Rector\AbstractRector; final class UpdateViewFunctionImportsRector extends AbstractRector @@ -10,26 +14,26 @@ final class UpdateViewFunctionImportsRector extends AbstractRector public function getNodeTypes(): array { return [ - Node\UseItem::class, - Node\Expr\FuncCall::class, + UseItem::class, + FuncCall::class, ]; } public function refactor(Node $node): ?int { - if ($node instanceof Node\UseItem) { + if ($node instanceof UseItem) { if ($node->name->toString() === 'Tempest\view') { - $node->name = new Node\Name('Tempest\View\view'); + $node->name = new Name('Tempest\View\view'); } return null; } - if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) { + if ($node instanceof FuncCall && $node->name instanceof Name) { $functionName = $node->name->toString(); if ($functionName === 'Tempest\view') { - $node->name = new Node\Name\FullyQualified('Tempest\View\view'); + $node->name = new FullyQualified('Tempest\View\view'); return null; } diff --git a/packages/upgrade/tests/RectorTester.php b/packages/upgrade/tests/RectorTester.php index b4925df5d..f3aa25ed1 100644 --- a/packages/upgrade/tests/RectorTester.php +++ b/packages/upgrade/tests/RectorTester.php @@ -12,6 +12,7 @@ final class RectorTester { private(set) string $fixturePath; + private(set) string $actual; public function __construct( diff --git a/packages/upgrade/tests/Tempest20/Tempest20RectorTest.php b/packages/upgrade/tests/Tempest20/Tempest20RectorTest.php index 774a10036..71df9adb7 100644 --- a/packages/upgrade/tests/Tempest20/Tempest20RectorTest.php +++ b/packages/upgrade/tests/Tempest20/Tempest20RectorTest.php @@ -23,7 +23,7 @@ public function test_migration_with_up_and_down(): void $this->rector ->runFixture(__DIR__ . '/Fixtures/MigrateUpAndDownMigration.input.php') ->assertContains('implements \Tempest\Database\MigratesUp, \Tempest\Database\MigratesDown') - ->assertContains('return new DropTableStatement(\'table\')') + ->assertContains("return new DropTableStatement('table')") ->assertNotContains('Tempest\Database\DatabaseMigration') ->assertContains('public function down(): QueryStatement'); } diff --git a/packages/validation/src/Rules/HasCount.php b/packages/validation/src/Rules/HasCount.php index 7f8d62bf0..f22030918 100644 --- a/packages/validation/src/Rules/HasCount.php +++ b/packages/validation/src/Rules/HasCount.php @@ -5,6 +5,7 @@ namespace Tempest\Validation\Rules; use Attribute; +use Countable; use InvalidArgumentException; use Tempest\Validation\HasTranslationVariables; use Tempest\Validation\Rule; @@ -26,7 +27,7 @@ public function __construct( public function isValid(mixed $value): bool { - if (! is_array($value) && ! $value instanceof \Countable) { + if (! is_array($value) && ! $value instanceof Countable) { return false; } diff --git a/packages/validation/src/Rules/HasDateTimeFormat.php b/packages/validation/src/Rules/HasDateTimeFormat.php index 6e53f1287..7f67b121e 100644 --- a/packages/validation/src/Rules/HasDateTimeFormat.php +++ b/packages/validation/src/Rules/HasDateTimeFormat.php @@ -10,6 +10,7 @@ use Tempest\DateTime\FormatPattern; use Tempest\Validation\HasTranslationVariables; use Tempest\Validation\Rule; +use Throwable; /** * Validates that the value is a valid date string in a specified format. @@ -37,7 +38,7 @@ private function validateIcuFormat(string $value): bool { try { return $value === DateTime::fromPattern($value, $this->format)->format($this->format); - } catch (\Throwable) { + } catch (Throwable) { return false; } } diff --git a/packages/validation/src/Rules/IsBetweenDates.php b/packages/validation/src/Rules/IsBetweenDates.php index 7ba9a4d43..703d1f119 100644 --- a/packages/validation/src/Rules/IsBetweenDates.php +++ b/packages/validation/src/Rules/IsBetweenDates.php @@ -19,6 +19,7 @@ final readonly class IsBetweenDates implements Rule, HasTranslationVariables { private DateTimeInterface $first; + private DateTimeInterface $second; public function __construct( diff --git a/packages/validation/src/Rules/IsFloat.php b/packages/validation/src/Rules/IsFloat.php index 27b0813c4..87714f44c 100644 --- a/packages/validation/src/Rules/IsFloat.php +++ b/packages/validation/src/Rules/IsFloat.php @@ -24,7 +24,7 @@ public function isValid(mixed $value): bool return true; } - if ($value === null || $value === false || $value === '' || $value === []) { + if (in_array($value, [null, false, '', []], true)) { return false; } diff --git a/packages/validation/src/Rules/IsInteger.php b/packages/validation/src/Rules/IsInteger.php index 883647deb..237161ef7 100644 --- a/packages/validation/src/Rules/IsInteger.php +++ b/packages/validation/src/Rules/IsInteger.php @@ -24,7 +24,7 @@ public function isValid(mixed $value): bool return true; } - if ($value === null || $value === false || $value === '' || $value === []) { + if (in_array($value, [null, false, '', []], true)) { return false; } diff --git a/packages/validation/src/Rules/IsNumeric.php b/packages/validation/src/Rules/IsNumeric.php index bbb3adcd0..9090bb605 100644 --- a/packages/validation/src/Rules/IsNumeric.php +++ b/packages/validation/src/Rules/IsNumeric.php @@ -19,6 +19,6 @@ public function isValid(mixed $value): bool return false; } - return boolval(preg_match('/^[0-9]+$/', $value)); + return boolval(preg_match('/^\d+$/', $value)); } } diff --git a/packages/validation/src/Rules/IsPassword.php b/packages/validation/src/Rules/IsPassword.php index 04447f081..85f059fe6 100644 --- a/packages/validation/src/Rules/IsPassword.php +++ b/packages/validation/src/Rules/IsPassword.php @@ -48,11 +48,7 @@ public function isValid(mixed $value): bool return false; } - if ($this->symbols && ! preg_match('/\p{Z}|\p{S}|\p{P}/u', $value)) { - return false; - } - - return true; + return ! ($this->symbols && ! preg_match('/\p{Z}|\p{S}|\p{P}/u', $value)); } public function getTranslationVariables(): array diff --git a/packages/validation/src/Rules/IsTime.php b/packages/validation/src/Rules/IsTime.php index 3d41add97..86759024b 100644 --- a/packages/validation/src/Rules/IsTime.php +++ b/packages/validation/src/Rules/IsTime.php @@ -25,10 +25,10 @@ public function isValid(mixed $value): bool } if ($this->twentyFourHour) { - return preg_match('/^([0-1][0-9]|2[0-3]):?[0-5][0-9]$|^(([0-1]?[0-9]|2[0-3]):[0-5][0-9])$/', $value) === 1; + return preg_match('/^([0-1]\d|2[0-3]):?[0-5]\d$|^(([0-1]?\d|2[0-3]):[0-5]\d)$/', $value) === 1; } - return preg_match('/^([0-1]?[0-9]):[0-5][0-9]\s([aApP].[mM].|[aApP][mM])$/', $value) === 1; + return preg_match('/^([0-1]?\d):[0-5]\d\s([aApP].[mM].|[aApP][mM])$/', $value) === 1; } public function getTranslationVariables(): array diff --git a/packages/validation/src/Rules/ValidateWith.php b/packages/validation/src/Rules/ValidateWith.php index 28a1c9ff4..a56d69081 100644 --- a/packages/validation/src/Rules/ValidateWith.php +++ b/packages/validation/src/Rules/ValidateWith.php @@ -18,14 +18,10 @@ #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] final readonly class ValidateWith implements Rule { - private Closure $callback; - public function __construct( - Closure $callback, + private Closure $callback, ) { - $this->callback = $callback; - - $reflection = new ReflectionFunction($callback); + $reflection = new ReflectionFunction($this->callback); // Must be static if (! $reflection->isStatic()) { diff --git a/packages/validation/src/SkipValidation.php b/packages/validation/src/SkipValidation.php index dddf690fc..0ae0fa7b1 100644 --- a/packages/validation/src/SkipValidation.php +++ b/packages/validation/src/SkipValidation.php @@ -7,6 +7,4 @@ use Attribute; #[Attribute(Attribute::TARGET_PROPERTY)] -final class SkipValidation -{ -} +final class SkipValidation {} diff --git a/packages/validation/src/Validator.php b/packages/validation/src/Validator.php index 7c692884f..3ed45600e 100644 --- a/packages/validation/src/Validator.php +++ b/packages/validation/src/Validator.php @@ -68,9 +68,7 @@ public function createValidationFailureException(array $failingRules, null|objec return new ValidationFailed( failingRules: $failingRules, subject: $subject, - errorMessages: Arr\map($failingRules, function (array $rules, string $field) { - return Arr\map($rules, fn (FailingRule $rule) => $this->getErrorMessage($rule, $field)); - }), + errorMessages: Arr\map($failingRules, fn (array $rules, string $field) => Arr\map($rules, fn (FailingRule $rule) => $this->getErrorMessage($rule, $field))), targetClass: $targetClass, ); } diff --git a/packages/validation/tests/Rules/IsTimeTest.php b/packages/validation/tests/Rules/IsTimeTest.php index 9b0987e48..673f3a4d6 100644 --- a/packages/validation/tests/Rules/IsTimeTest.php +++ b/packages/validation/tests/Rules/IsTimeTest.php @@ -5,6 +5,7 @@ namespace Tempest\Validation\Tests\Rules; use PHPUnit\Framework\TestCase; +use stdClass; use Tempest\Validation\Rules\IsTime; /** @@ -85,7 +86,7 @@ public function test_non_string_pregmatch_subject(): void $rule = new IsTime(twentyFourHour: true); $this->assertFalse($rule->isValid([])); - $this->assertFalse($rule->isValid(new \stdClass())); + $this->assertFalse($rule->isValid(new stdClass())); $this->assertFalse($rule->isValid(null)); } } diff --git a/packages/validation/tests/Rules/MatchesRegExTest.php b/packages/validation/tests/Rules/MatchesRegExTest.php index 06971c5dc..5752755e2 100644 --- a/packages/validation/tests/Rules/MatchesRegExTest.php +++ b/packages/validation/tests/Rules/MatchesRegExTest.php @@ -5,6 +5,7 @@ namespace Tempest\Validation\Tests\Rules; use PHPUnit\Framework\TestCase; +use stdClass; use Tempest\Validation\Rules\MatchesRegEx; /** @@ -26,12 +27,12 @@ public function test_regex_rule(): void public function test_non_imvalid_types(): void { - $rule = new MatchesRegEx('/^[0-9]+$/'); + $rule = new MatchesRegEx('/^\d+$/'); // Invalid types should return false, not a TypeError. $this->assertFalse($rule->isValid(false)); $this->assertFalse($rule->isValid([])); - $this->assertFalse($rule->isValid(new \stdClass())); + $this->assertFalse($rule->isValid(new stdClass())); $this->assertFalse($rule->isValid(null)); } } diff --git a/packages/validation/tests/Rules/ValidateWithTest.php b/packages/validation/tests/Rules/ValidateWithTest.php index 1a63700b6..371b3b2c9 100644 --- a/packages/validation/tests/Rules/ValidateWithTest.php +++ b/packages/validation/tests/Rules/ValidateWithTest.php @@ -4,6 +4,7 @@ namespace Tempest\Validation\Tests\Rules; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use ReflectionProperty; use Tempest\Validation\Rules\ValidateWith; @@ -52,7 +53,7 @@ public function test_non_string_value_fails(): void public function test_static_closure_required(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new ValidateWith(fn (mixed $value): bool => str_contains((string) $value, '@')); } diff --git a/packages/validation/tests/ValidatorTest.php b/packages/validation/tests/ValidatorTest.php index 6631364a9..e817df893 100644 --- a/packages/validation/tests/ValidatorTest.php +++ b/packages/validation/tests/ValidatorTest.php @@ -51,18 +51,14 @@ public function test_validate_value(): void public function test_closure_fails_with_false_response(): void { - $failingRules = $this->validator->validateValue('a', function (mixed $_) { - return false; - }); + $failingRules = $this->validator->validateValue('a', fn (mixed $_) => false); $this->assertCount(1, $failingRules); } public function test_closure_fails_with_string_response(): void { - $failingRules = $this->validator->validateValue('a', function (mixed $_) { - return 'I expected b'; - }); + $failingRules = $this->validator->validateValue('a', fn (mixed $_) => 'I expected b'); $rule = $failingRules[0]->rule; @@ -74,9 +70,7 @@ public function test_closure_fails_with_string_response(): void public function test_closure_passes_with_null_response(): void { $validator = $this->validator; - $validator->validateValue('a', function (mixed $_) { - return null; - }); + $validator->validateValue('a', fn (mixed $_) => null); $this->expectNotToPerformAssertions(); } @@ -84,9 +78,7 @@ public function test_closure_passes_with_null_response(): void public function test_closure_passes_with_true_response(): void { $validator = $this->validator; - $validator->validateValue('a', function (mixed $_) { - return true; - }); + $validator->validateValue('a', fn (mixed $_) => true); $this->expectNotToPerformAssertions(); } @@ -95,17 +87,9 @@ public function test_closure_passes(): void { $validator = $this->validator; - $validator->validateValue('a', function (mixed $value) { - return $value === 'a'; - }); + $validator->validateValue('a', fn (mixed $value) => $value === 'a'); - $validator->validateValue('a', function (mixed $value) { - if ($value === 'a') { - return true; - } - - return false; - }); + $validator->validateValue('a', fn (mixed $value) => $value === 'a'); $this->expectNotToPerformAssertions(); } diff --git a/packages/view/src/Attributes/ExpressionAttribute.php b/packages/view/src/Attributes/ExpressionAttribute.php index 75b09d39f..43f8b57d9 100644 --- a/packages/view/src/Attributes/ExpressionAttribute.php +++ b/packages/view/src/Attributes/ExpressionAttribute.php @@ -35,7 +35,7 @@ public function apply(Element $element): Element $element->setAttribute( ltrim($this->name, ':'), - sprintf('%s', $value), + $value, ); } else { $attributeName = ltrim($this->name, ':'); diff --git a/packages/view/src/Commands/ClearViewCacheCommand.php b/packages/view/src/Commands/ClearViewCacheCommand.php index e293687b0..c1ceb8c91 100644 --- a/packages/view/src/Commands/ClearViewCacheCommand.php +++ b/packages/view/src/Commands/ClearViewCacheCommand.php @@ -10,7 +10,7 @@ use Tempest\Container\Container; use Tempest\View\ViewCache; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final readonly class ClearViewCacheCommand { use HasConsole; diff --git a/packages/view/src/Commands/MakeViewCommand.php b/packages/view/src/Commands/MakeViewCommand.php index ecb515cf6..a49cf4197 100644 --- a/packages/view/src/Commands/MakeViewCommand.php +++ b/packages/view/src/Commands/MakeViewCommand.php @@ -17,7 +17,7 @@ use function Tempest\Support\str; -if (class_exists(\Tempest\Console\ConsoleCommand::class)) { +if (class_exists(ConsoleCommand::class)) { final class MakeViewCommand { use PublishesFiles; @@ -82,7 +82,11 @@ private function getStubFileFromViewType(ViewType $viewType): StubFile default => throw new InvalidArgumentException(sprintf('The "%s" view type has no supported stub file.', $viewType->value)), }; } catch (InvalidArgumentException $invalidArgumentException) { - throw new FileGenerationFailedException(sprintf('Cannot retrieve stub file: %s', $invalidArgumentException->getMessage())); + throw new FileGenerationFailedException( + sprintf('Cannot retrieve stub file: %s', $invalidArgumentException->getMessage()), + $invalidArgumentException->getCode(), + $invalidArgumentException, + ); } } } diff --git a/packages/view/src/Components/x-component.view.php b/packages/view/src/Components/x-component.view.php index c35181f9d..7847fd8c4 100644 --- a/packages/view/src/Components/x-component.view.php +++ b/packages/view/src/Components/x-component.view.php @@ -17,10 +17,10 @@ $content = $slots[Slot::DEFAULT]->content ?? ''; $template = sprintf(<<<'HTML' -<%s %s> -%s - -HTML, $is, $attributeString, $content, $is); + <%s %s> + %s + + HTML, $is, $attributeString, $content, $is); $data = $scopedVariables ?? $_data ?? []; $data = is_array($data) ? $data : []; diff --git a/packages/view/src/Components/x-form.view.php b/packages/view/src/Components/x-form.view.php index 95bd8ee2a..c8f43f47a 100644 --- a/packages/view/src/Components/x-form.view.php +++ b/packages/view/src/Components/x-form.view.php @@ -14,7 +14,7 @@ $method = $method->value; } -$needsSpoofing = Method::trySpoofingFrom($method) !== null; +$needsSpoofing = Method::trySpoofingFrom($method) instanceof Method; $formMethod = $needsSpoofing ? 'POST' : $method; ?> diff --git a/packages/view/src/Components/x-icon.view.php b/packages/view/src/Components/x-icon.view.php index f6bb76c74..8e1e46d47 100644 --- a/packages/view/src/Components/x-icon.view.php +++ b/packages/view/src/Components/x-icon.view.php @@ -24,7 +24,7 @@ fn (ImmutableString $s): ImmutableString => str(""), ) ->replace( - search: " width=\"1em\" height=\"1em\"", + search: ' width="1em" height="1em"', replace: '', ) ->when( @@ -54,7 +54,7 @@ fn (ImmutableString $s): ImmutableString => $s ->replace( search: 'toString(); diff --git a/packages/view/src/Elements/ElementFactory.php b/packages/view/src/Elements/ElementFactory.php index 2ee353519..f656ede43 100644 --- a/packages/view/src/Elements/ElementFactory.php +++ b/packages/view/src/Elements/ElementFactory.php @@ -44,12 +44,7 @@ public function withIsHtml(bool $isHtml): self public function make(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 - ) { + if (in_array($token->type, [TokenType::OPEN_TAG_END, TokenType::ATTRIBUTE_NAME, TokenType::ATTRIBUTE_VALUE, TokenType::SELF_CLOSING_TAG_END], true)) { return null; } diff --git a/packages/view/src/Elements/GenericElement.php b/packages/view/src/Elements/GenericElement.php index b0266a9b7..662fdd9d4 100644 --- a/packages/view/src/Elements/GenericElement.php +++ b/packages/view/src/Elements/GenericElement.php @@ -41,11 +41,7 @@ public function compile(): string $attributes = []; foreach ($this->getAttributes() as $name => $value) { - if ($value !== null && $value !== '') { - $attributes[] = $name . '="' . $value . '"'; - } else { - $attributes[] = $name; - } + $attributes[] = $value !== null && $value !== '' ? $name . '="' . $value . '"' : $name; } $attributes = implode(' ', [...$attributes, ...$this->rawAttributes]); @@ -58,9 +54,9 @@ public function compile(): string if (is_void_tag($this->tag)) { if ($this->isHtml) { return "<{$this->tag}{$attributes}>"; - } else { - return "<{$this->tag}{$attributes} />"; } + + return "<{$this->tag}{$attributes} />"; } return "<{$this->tag}{$attributes}>{$content}tag}>"; diff --git a/packages/view/src/Elements/IsElement.php b/packages/view/src/Elements/IsElement.php index 415566d21..09a60a504 100644 --- a/packages/view/src/Elements/IsElement.php +++ b/packages/view/src/Elements/IsElement.php @@ -26,11 +26,7 @@ trait IsElement public function getAttributes(): array { - if ($this instanceof WrapsElement) { - $wrappingAttributes = $this->getWrappingElement()->getAttributes(); - } else { - $wrappingAttributes = []; - } + $wrappingAttributes = $this instanceof WrapsElement ? $this->getWrappingElement()->getAttributes() : []; $attributes = [...$this->attributes, ...$wrappingAttributes]; diff --git a/packages/view/src/Elements/PhpForeachElement.php b/packages/view/src/Elements/PhpForeachElement.php index ef85107db..63da10c88 100644 --- a/packages/view/src/Elements/PhpForeachElement.php +++ b/packages/view/src/Elements/PhpForeachElement.php @@ -27,7 +27,7 @@ public function getWrappingElement(): Element public function setElse(Element $element): self { - if ($this->else !== null) { + if ($this->else instanceof Element) { throw new ElementWasInvalid('There can only be one forelse element.'); } @@ -40,7 +40,7 @@ public function compile(): string { $foreachAttribute = $this->wrappingElement->consumeAttribute(':foreach'); - if ($viewComponent = $this->unwrap(ViewComponentElement::class)) { + if (($viewComponent = $this->unwrap(ViewComponentElement::class)) instanceof ViewComponentElement) { $name = trim(str($foreachAttribute)->explode('as')->last()); $viewComponent->addVariable($name); @@ -59,7 +59,7 @@ public function compile(): string $compiled, ); - if ($this->else !== null) { + if ($this->else instanceof Element) { $collectionName = str($foreachAttribute)->match('/^(?.*)\s+as/', 'match'); $this->else->consumeAttribute(':forelse'); diff --git a/packages/view/src/Elements/PhpIfElement.php b/packages/view/src/Elements/PhpIfElement.php index 6f40d221c..55160f1c1 100644 --- a/packages/view/src/Elements/PhpIfElement.php +++ b/packages/view/src/Elements/PhpIfElement.php @@ -35,7 +35,7 @@ public function addElseif(Element $element): self public function setElse(Element $element): self { - if ($this->else !== null) { + if ($this->else instanceof Element) { throw new ElementWasInvalid('There can only be one else element.'); } @@ -70,7 +70,7 @@ public function compile(): string ); } - if ($this->else !== null) { + if ($this->else instanceof Element) { $this->else->consumeAttribute(':else'); $compiled = sprintf( diff --git a/packages/view/src/Elements/RawElement.php b/packages/view/src/Elements/RawElement.php index cb071cea8..800288b76 100644 --- a/packages/view/src/Elements/RawElement.php +++ b/packages/view/src/Elements/RawElement.php @@ -34,17 +34,9 @@ public function compile(): string foreach ($this->getAttributes() as $name => $value) { $name = str($name); - if ($name->startsWith(':')) { - $name = ':' . $name->kebab()->toString(); - } else { - $name = $name->kebab()->toString(); - } - - if ($value) { - $attributes[] = $name . '="' . $value . '"'; - } else { - $attributes[] = $name; - } + $name = $name->startsWith(':') ? ':' . $name->kebab()->toString() : $name->kebab()->toString(); + + $attributes[] = $value ? $name . '="' . $value . '"' : $name; } $attributes = implode(' ', [...$attributes, ...$this->rawAttributes]); diff --git a/packages/view/src/Elements/RootElement.php b/packages/view/src/Elements/RootElement.php index ec54f92a3..fc5256b9c 100644 --- a/packages/view/src/Elements/RootElement.php +++ b/packages/view/src/Elements/RootElement.php @@ -19,7 +19,7 @@ public function compile(): string $compiled[] = $element->compile(); } - return implode($compiled); + return implode('', $compiled); } public function getImports(): array diff --git a/packages/view/src/Elements/TextElement.php b/packages/view/src/Elements/TextElement.php index 41db6c590..361028c4e 100644 --- a/packages/view/src/Elements/TextElement.php +++ b/packages/view/src/Elements/TextElement.php @@ -22,16 +22,12 @@ public function compile(): string // Render {{ ->replaceRegex( regex: '/{{(?.*?)}}/', - replace: function (array $matches): string { - return sprintf('escape(%s); ?>', $matches['match']); - }, + replace: fn (array $matches): string => sprintf('escape(%s); ?>', $matches['match']), ) // Render {!! ->replaceRegex( regex: '/{!!(?.*?)!!}/', - replace: function (array $matches): string { - return sprintf('', $matches['match']); - }, + replace: fn (array $matches): string => sprintf('', $matches['match']), ) ->toString(); } diff --git a/packages/view/src/Elements/ViewComponentElement.php b/packages/view/src/Elements/ViewComponentElement.php index 4f42d0627..b1284af2f 100644 --- a/packages/view/src/Elements/ViewComponentElement.php +++ b/packages/view/src/Elements/ViewComponentElement.php @@ -255,6 +255,7 @@ private function applyFallthroughAttribute(ImmutableArray $attributes, string $n if ($hasDataAttribute) { $attributes[$name]->append(' ' . $this->dataAttributes[$name]); } + if ($hasExpressionAttribute) { $attributes[$name]->append(sprintf(' ', $name)); } @@ -283,7 +284,7 @@ public function getImports(): array { $imports = []; - if ($this->parent) { + if ($this->parent instanceof Element) { $imports = [...$imports, ...$this->parent->getImports()]; } diff --git a/packages/view/src/Exceptions/ViewCompilationFailed.php b/packages/view/src/Exceptions/ViewCompilationFailed.php index 0b5273e5b..2b6e94782 100644 --- a/packages/view/src/Exceptions/ViewCompilationFailed.php +++ b/packages/view/src/Exceptions/ViewCompilationFailed.php @@ -18,7 +18,7 @@ public function __construct( private(set) readonly ?int $sourceLine = null, ) { parent::__construct( - message: sprintf($previous->getMessage()), + message: $previous->getMessage(), previous: $previous, ); diff --git a/packages/view/src/Exceptions/XmlDeclarationCouldNotBeParsed.php b/packages/view/src/Exceptions/XmlDeclarationCouldNotBeParsed.php index bafa5a693..b61502ec8 100644 --- a/packages/view/src/Exceptions/XmlDeclarationCouldNotBeParsed.php +++ b/packages/view/src/Exceptions/XmlDeclarationCouldNotBeParsed.php @@ -10,6 +10,6 @@ final class XmlDeclarationCouldNotBeParsed extends Exception { public function __construct() { - parent::__construct('Cannot compile views with XML declarations when PHP\'s `short_open_tag` is enabled.'); + parent::__construct("Cannot compile views with XML declarations when PHP's `short_open_tag` is enabled."); } } diff --git a/packages/view/src/Export/ExportableViewObject.php b/packages/view/src/Export/ExportableViewObject.php index c05f64774..4be43a25a 100644 --- a/packages/view/src/Export/ExportableViewObject.php +++ b/packages/view/src/Export/ExportableViewObject.php @@ -6,9 +6,7 @@ interface ExportableViewObject { - public ImmutableArray $exportData { - get; - } + public ImmutableArray $exportData { get; } public static function restore(mixed ...$data): self; } diff --git a/packages/view/src/Parser/TempestViewCompiler.php b/packages/view/src/Parser/TempestViewCompiler.php index 0a7b21d70..41dee8235 100644 --- a/packages/view/src/Parser/TempestViewCompiler.php +++ b/packages/view/src/Parser/TempestViewCompiler.php @@ -172,11 +172,7 @@ private function applyAttributes(Element $parentElement): Element foreach ($childElement->getAttributes() as $name => $value) { // TODO: possibly refactor attribute construction to ElementFactory? - if ($value instanceof Attribute) { - $attribute = $value; - } else { - $attribute = $this->attributeFactory->make($name); - } + $attribute = $value instanceof Attribute ? $value : $this->attributeFactory->make($name); $childElement = $attribute->apply($childElement); @@ -210,11 +206,11 @@ public function compileElement(Element $rootElement): string $sourcePath = $sourceLocation['sourcePath']; if ($sourcePath !== null) { - $compiled[] = self::sourcePathMarker($sourcePath); + $compiled[] = $this->sourcePathMarker($sourcePath); } } - $compiled[] = self::sourceLineMarker($sourceLocation['sourceLine']); + $compiled[] = $this->sourceLineMarker($sourceLocation['sourceLine']); } $compiled[] = $element->compile(); @@ -225,12 +221,12 @@ public function compileElement(Element $rootElement): string ->toString(); } - private static function sourcePathMarker(string $sourcePath): string + private function sourcePathMarker(string $sourcePath): string { return sprintf('', self::SOURCE_PATH_MARKER, base64_encode($sourcePath)); } - private static function sourceLineMarker(int $sourceLine): string + private function sourceLineMarker(int $sourceLine): string { return sprintf('', self::SOURCE_LINE_MARKER, $sourceLine); } @@ -348,8 +344,11 @@ private function extractSourceMap(string $compiled, ?string $sourcePath): array $compiledLine++; $cleanedLines[] = $line; + if ($sourceLine === null) { + continue; + } - if ($sourceLine === null || $currentSourcePath === null) { + if ($currentSourcePath === null) { continue; } diff --git a/packages/view/src/Parser/TempestViewLexer.php b/packages/view/src/Parser/TempestViewLexer.php index 1f5c8931d..36750baae 100644 --- a/packages/view/src/Parser/TempestViewLexer.php +++ b/packages/view/src/Parser/TempestViewLexer.php @@ -148,8 +148,8 @@ private function lexTag(): array ); if ($hasValue) { - $quote = $this->seek() === '\'' - ? '\'' + $quote = $this->seek() === "'" + ? "'" : '"'; $attributeValueLine = $this->line; diff --git a/packages/view/src/Parser/TempestViewParser.php b/packages/view/src/Parser/TempestViewParser.php index 77309107b..7c4402ca3 100644 --- a/packages/view/src/Parser/TempestViewParser.php +++ b/packages/view/src/Parser/TempestViewParser.php @@ -29,7 +29,7 @@ public function parse(): TempestViewAst $withinTag = false; foreach ($this->tokens as $token) { - if ($this->currentScope === null) { + if (! $this->currentScope instanceof Token) { $ast->add($token); } diff --git a/packages/view/src/Renderers/TempestViewRenderer.php b/packages/view/src/Renderers/TempestViewRenderer.php index 1b2f3e604..3fc747bea 100644 --- a/packages/view/src/Renderers/TempestViewRenderer.php +++ b/packages/view/src/Renderers/TempestViewRenderer.php @@ -12,6 +12,7 @@ use Tempest\Support\Filesystem; use Tempest\Support\Html\HtmlString; use Tempest\View\Attributes\AttributeFactory; +use Tempest\View\CompiledView; use Tempest\View\Elements\ElementFactory; use Tempest\View\Exceptions\ViewCompilationFailed; use Tempest\View\Exceptions\ViewVariableWasReserved; @@ -93,7 +94,7 @@ public function render(string|View $view): string }, ); - if ($compiledView !== null) { + if ($compiledView instanceof CompiledView) { $this->viewCache->saveSourceMap($path, $compiledView->sourcePath, $compiledView->lineMap); } @@ -111,7 +112,7 @@ public function includeViewComponent(string $path): Closure private function processView(View $view): View { foreach ($this->viewConfig->viewProcessors as $viewProcessorClass) { - if ($this->container) { + if ($this->container instanceof Container) { /** @var \Tempest\View\ViewProcessor $viewProcessor */ $viewProcessor = $this->container->get($viewProcessorClass); } else { @@ -226,8 +227,11 @@ private function resolveSourceLocationFromThrowable(Throwable $throwable, string foreach ($throwable->getTrace() as $frame) { $framePath = $frame['file'] ?? null; $frameLine = $frame['line'] ?? null; + if (! is_string($framePath)) { + continue; + } - if (! is_string($framePath) || ! is_int($frameLine)) { + if (! is_int($frameLine)) { continue; } @@ -397,7 +401,11 @@ private function closestLineToFallback(array $lines, int $fallbackLine): int private function resolveSourceLine(int $compiledLine, ?string $defaultSourcePath, array $lineMap): ?array { foreach ($lineMap as $entry) { - if ($compiledLine < $entry['compiledStartLine'] || $compiledLine > $entry['compiledEndLine']) { + if ($compiledLine < $entry['compiledStartLine']) { + continue; + } + + if ($compiledLine > $entry['compiledEndLine']) { continue; } diff --git a/packages/view/src/ShouldBeRemoved.php b/packages/view/src/ShouldBeRemoved.php index 017adba67..318373f37 100644 --- a/packages/view/src/ShouldBeRemoved.php +++ b/packages/view/src/ShouldBeRemoved.php @@ -2,6 +2,4 @@ namespace Tempest\View; -interface ShouldBeRemoved -{ -} +interface ShouldBeRemoved {} diff --git a/packages/view/src/View.php b/packages/view/src/View.php index 0f9695dc0..9a585116d 100644 --- a/packages/view/src/View.php +++ b/packages/view/src/View.php @@ -6,17 +6,11 @@ interface View { - public string $path { - get; - } + public string $path { get; } - public ?string $relativeRootPath { - get; - } + public ?string $relativeRootPath { get; } - public array $data { - get; - } + public array $data { get; } public function get(string $key): mixed; diff --git a/packages/view/src/WithToken.php b/packages/view/src/WithToken.php index 23e4fe2ab..20922797e 100644 --- a/packages/view/src/WithToken.php +++ b/packages/view/src/WithToken.php @@ -8,7 +8,5 @@ interface WithToken { - public Token $token { - get; - } + public Token $token { get; } } diff --git a/packages/view/tests/FallthroughAttributesTest.php b/packages/view/tests/FallthroughAttributesTest.php index 89a6f8475..d6670dec6 100644 --- a/packages/view/tests/FallthroughAttributesTest.php +++ b/packages/view/tests/FallthroughAttributesTest.php @@ -29,10 +29,10 @@ public function render(): void ); $this->assertEquals(str_replace([' ', PHP_EOL], '', <<<'HTML' -
-
-
-
- HTML), str_replace([' ', PHP_EOL], '', $html)); +
+
+
+
+ HTML), str_replace([' ', PHP_EOL], '', $html)); } } diff --git a/packages/view/tests/StandaloneViewRendererTest.php b/packages/view/tests/StandaloneViewRendererTest.php index 0a8ab7910..6630e9d21 100644 --- a/packages/view/tests/StandaloneViewRendererTest.php +++ b/packages/view/tests/StandaloneViewRendererTest.php @@ -33,10 +33,10 @@ public function test_render(): void ); $this->assertSnippetsMatch(<<<'HTML' -
- Hi -
- HTML, $html); +
+ Hi +
+ HTML, $html); } public function test_invalid_view_component_paths(): void @@ -86,10 +86,10 @@ public function test_with_cache_enabled(): void ); $this->assertSnippetsMatch(<<<'HTML' - - Hi - - HTML, $html); + + Hi + + HTML, $html); } public function test_with_cache_disabled(): void @@ -103,10 +103,10 @@ public function test_with_cache_disabled(): void ); $this->assertSnippetsMatch(<<<'HTML' - - Hi - - HTML, $html); + + Hi + + HTML, $html); } public function test_xml_declaration_with_short_open_tag(): void diff --git a/packages/view/tests/TempestViewLexerTest.php b/packages/view/tests/TempestViewLexerTest.php index 0ba62e288..335d58069 100644 --- a/packages/view/tests/TempestViewLexerTest.php +++ b/packages/view/tests/TempestViewLexerTest.php @@ -14,8 +14,8 @@ final class TempestViewLexerTest extends TestCase public function test_lexer(): void { $html = <<hello - HTML; + hello + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -144,15 +144,15 @@ public function test_closing_tag(string $tag): void public function test_multiline_attributes(): void { $html = <<<'HTML' -
+
-
- HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -183,8 +183,8 @@ class=', TokenType::ATTRIBUTE_NAME), public function test_whitespace(): void { $html = <<<'HTML' -

Test Test

- HTML; +

Test Test

+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -210,8 +210,8 @@ public function test_whitespace(): void public function test_lexer_with_falsy_values(): void { $html = <<<'HTML' - a0a - HTML; + a0a + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -245,8 +245,8 @@ public function test_lexer_attribute_values(): void public function test_php_within_tag(): void { $html = <<<'HTML' -
class="foo" >
- HTML; +
class="foo" >
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -267,8 +267,8 @@ public function test_php_within_tag(): void public function test_doctype(): void { $html = <<<'HTML' - - HTML; + + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -283,8 +283,8 @@ public function test_doctype(): void ); $html = <<<'HTML' - - HTML; + + HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -343,8 +343,8 @@ public function test_unclosed_comment_tag(): void public function test_cdata(): void { $tokens = new TempestViewLexer(<<<'RSS' - <![CDATA[ {{ $post['title'] }} ]]> - RSS)->lex(); + <![CDATA[ {{ $post['title'] }} ]]> + RSS)->lex(); $this->assertTokens( expected: [ @@ -362,8 +362,8 @@ public function test_cdata(): void public function test_xml(): void { $tokens = new TempestViewLexer(<<<'XML' - - XML)->lex(); + + XML)->lex(); $this->assertTokens( expected: [ @@ -376,8 +376,8 @@ public function test_xml(): void public function test_single_quote_attributes(): void { $html = << - HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); @@ -385,7 +385,7 @@ public function test_single_quote_attributes(): void expected: [ new Token('', TokenType::OPEN_TAG_END), new Token('', TokenType::CLOSING_TAG), ], diff --git a/packages/view/tests/TempestViewParserTest.php b/packages/view/tests/TempestViewParserTest.php index c38135f41..0b1cff5e1 100644 --- a/packages/view/tests/TempestViewParserTest.php +++ b/packages/view/tests/TempestViewParserTest.php @@ -34,8 +34,8 @@ public function test_parser(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - hello - HTML, $parsed->compile()); + hello + HTML, $parsed->compile()); } public function test_parse_self_closing_tag_with_attributes(): void @@ -52,8 +52,8 @@ public function test_parse_self_closing_tag_with_attributes(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $parsed->compile()); + + HTML, $parsed->compile()); } public function test_self_closing_tags_with_attributes(): void @@ -63,8 +63,8 @@ public function test_self_closing_tags_with_attributes(): void $ast = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $ast->compile()); + + HTML, $ast->compile()); } public function test_invalid_closing_tag(): void @@ -79,19 +79,19 @@ public function test_invalid_closing_tag(): void public function test_invalid_closing_tag_ignores_commented_out_code(): void { $tokens = new TempestViewLexer(<< - - - HTML)->lex(); +

+ +

+ HTML)->lex(); $compiled = new TempestViewParser($tokens)->parse()->compile(); $this->assertSame(<< - - - HTML, $compiled); +

+ +

+ HTML, $compiled); } public function test_doctype(): void @@ -106,15 +106,15 @@ public function test_doctype(): void $parsed = new TempestViewParser($tokens)->parse(); $this->assertSame(<<<'HTML' - - HTML, $parsed->compile()); + + HTML, $parsed->compile()); } public function test_void_tags(): void { $html = <<<'HTML' -
- HTML; +
+ HTML; $tokens = new TempestViewLexer($html)->lex(); diff --git a/packages/vite/src/Exceptions/EntrypointNotFoundException.php b/packages/vite/src/Exceptions/EntrypointNotFoundException.php index 980fc9464..f81400d09 100644 --- a/packages/vite/src/Exceptions/EntrypointNotFoundException.php +++ b/packages/vite/src/Exceptions/EntrypointNotFoundException.php @@ -4,6 +4,4 @@ namespace Tempest\Vite\Exceptions; -interface EntrypointNotFoundException extends ViteException -{ -} +interface EntrypointNotFoundException extends ViteException {} diff --git a/packages/vite/src/Exceptions/ViteException.php b/packages/vite/src/Exceptions/ViteException.php index e65746b26..4d176327d 100644 --- a/packages/vite/src/Exceptions/ViteException.php +++ b/packages/vite/src/Exceptions/ViteException.php @@ -4,6 +4,4 @@ namespace Tempest\Vite\Exceptions; -interface ViteException -{ -} +interface ViteException {} diff --git a/packages/vite/src/Installer/ViteInstaller.php b/packages/vite/src/Installer/ViteInstaller.php index 4c428a5cd..35eef9dc0 100644 --- a/packages/vite/src/Installer/ViteInstaller.php +++ b/packages/vite/src/Installer/ViteInstaller.php @@ -5,6 +5,7 @@ namespace Tempest\Vite\Installer; use Tempest\Console\Input\ConsoleArgumentBag; +use Tempest\Console\Input\ConsoleInputArgument; use Tempest\Core\Installer; use Tempest\Core\PublishesFiles; use Tempest\Support\JavaScript\DependencyInstaller; @@ -31,7 +32,7 @@ private function shouldInstallTailwind(): bool { $argument = $this->consoleArgumentBag->get('tailwindcss'); - if ($argument === null || ! is_bool($argument->value)) { + if (! $argument instanceof ConsoleInputArgument || ! is_bool($argument->value)) { return $this->console->confirm('Install Tailwind CSS as well?', default: true); } diff --git a/packages/vite/src/Manifest/Chunk.php b/packages/vite/src/Manifest/Chunk.php index 9815fc41e..fc8515d84 100644 --- a/packages/vite/src/Manifest/Chunk.php +++ b/packages/vite/src/Manifest/Chunk.php @@ -25,7 +25,7 @@ public static function fromArray(array $manifestEntry): static $isEntry = $manifestEntry['isEntry'] ?? false; $isLegacyEntry = str_contains($file, '-legacy'); - return new static( + return new self( file: $file, src: $manifestEntry['src'] ?? null, isEntry: $isEntry, diff --git a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php index 9e86e52d1..ab8b83a1c 100644 --- a/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php +++ b/packages/vite/src/TagsResolver/DevelopmentTagsResolver.php @@ -71,13 +71,13 @@ private function fileToAssetPath(string $file): string private function createReactRefreshTag(): string { return << - import RefreshRuntime from '{$this->bridgeFile->url}/@react-refresh'; - RefreshRuntime.injectIntoGlobalHook(window); - window.\$RefreshReg$ = () => {}; - window.\$RefreshSig$ = () => (type) => type; - window.__vite_plugin_react_preamble_installed__ = true; - - HTML; + + HTML; } } diff --git a/packages/vite/src/TagsResolver/ManifestTagsResolver.php b/packages/vite/src/TagsResolver/ManifestTagsResolver.php index 17da4e616..5fe0f004f 100644 --- a/packages/vite/src/TagsResolver/ManifestTagsResolver.php +++ b/packages/vite/src/TagsResolver/ManifestTagsResolver.php @@ -179,11 +179,11 @@ private function resolvePrefetchingScript(Chunk $chunk): ?string }; $assets = array_values(array_map( - callback: fn (array $asset) => array_map('strval', $asset), + callback: fn (array $asset) => array_map(strval(...), $asset), array: array_unique($findPrefetchableAssets($chunk), flags: SORT_REGULAR), )); - if (count($assets) === 0) { + if ($assets === []) { return null; } @@ -191,48 +191,48 @@ private function resolvePrefetchingScript(Chunk $chunk): ?string $script = match ($this->viteConfig->prefetching->strategy) { PrefetchStrategy::AGGRESSIVE => <<viteConfig->prefetching->prefetchEvent}', () => window.setTimeout(() => { - function makeLink(asset) { - const link = document.createElement('link') - Object.keys(asset).forEach((attribute) => link.setAttribute(attribute, asset[attribute])) - return link - } + window.addEventListener('{$this->viteConfig->prefetching->prefetchEvent}', () => window.setTimeout(() => { + function makeLink(asset) { + const link = document.createElement('link') + Object.keys(asset).forEach((attribute) => link.setAttribute(attribute, asset[attribute])) + return link + } - const fragment = new DocumentFragment(); - {$assets}.forEach((asset) => fragment.append(makeLink(asset))) - document.head.append(fragment) - })) - JS, + const fragment = new DocumentFragment(); + {$assets}.forEach((asset) => fragment.append(makeLink(asset))) + document.head.append(fragment) + })) + JS, PrefetchStrategy::WATERFALL => <<viteConfig->prefetching->prefetchEvent}', () => { - function makeLink(asset) { - const link = document.createElement('link') - Object.entries(asset).forEach(([key, value]) => link.setAttribute(key, value)) - return link - } + window.addEventListener('{$this->viteConfig->prefetching->prefetchEvent}', () => { + function makeLink(asset) { + const link = document.createElement('link') + Object.entries(asset).forEach(([key, value]) => link.setAttribute(key, value)) + return link + } - function loadNext(assets, count) { - if (!assets.length) return + function loadNext(assets, count) { + if (!assets.length) return - const fragment = new DocumentFragment() - const limit = Math.min(count, assets.length) + const fragment = new DocumentFragment() + const limit = Math.min(count, assets.length) - for (let i = 0; i < limit; i++) { - const link = makeLink(assets.shift()) - fragment.append(link) + for (let i = 0; i < limit; i++) { + const link = makeLink(assets.shift()) + fragment.append(link) - if (assets.length) { - link.onload = () => loadNext(assets, 1) - link.onerror = () => loadNext(assets, 1) + if (assets.length) { + link.onload = () => loadNext(assets, 1) + link.onerror = () => loadNext(assets, 1) + } } - } - document.head.append(fragment) - } + document.head.append(fragment) + } - setTimeout(() => loadNext({$assets}, {$this->viteConfig->prefetching->concurrent})) - }) - JS, + setTimeout(() => loadNext({$assets}, {$this->viteConfig->prefetching->concurrent})) + }) + JS, PrefetchStrategy::NONE => '', }; diff --git a/packages/vite/src/Vite.php b/packages/vite/src/Vite.php index fe21d7a39..2d15d94a3 100644 --- a/packages/vite/src/Vite.php +++ b/packages/vite/src/Vite.php @@ -58,7 +58,7 @@ public function getTags(?array $entrypoints = null): array */ public function clearManifestCache(): self { - static::$manifest = null; + self::$manifest = null; return $this; } @@ -68,7 +68,7 @@ public function clearManifestCache(): self */ public function clearBridgeCache(): self { - static::$bridgeFile = null; + self::$bridgeFile = null; return $this; } @@ -94,15 +94,15 @@ private function getTagsResolver(): TagsResolver private function getManifest(): Manifest { - if (static::$manifest !== null) { - return static::$manifest; + if (self::$manifest instanceof Manifest) { + return self::$manifest; } if (! is_file($path = root_path('public', $this->viteConfig->buildDirectory, $this->viteConfig->manifest))) { throw new ManifestWasNotFound($path); } - return static::$manifest = Manifest::fromArray(Json\decode( + return self::$manifest = Manifest::fromArray(Json\decode( Filesystem\read_file($path), )); } @@ -113,11 +113,7 @@ private function shouldUseManifest(): bool return false; } - if ($this->isDevelopmentServerRunning()) { - return false; - } - - return true; + return ! $this->isDevelopmentServerRunning(); } private function isDevelopmentServerRunning(): bool @@ -127,8 +123,8 @@ private function isDevelopmentServerRunning(): bool private function getBridgeFile(): ViteBridgeFile { - if (static::$bridgeFile !== null) { - return static::$bridgeFile; + if (self::$bridgeFile instanceof ViteBridgeFile) { + return self::$bridgeFile; } if (! $this->isDevelopmentServerRunning()) { @@ -138,7 +134,7 @@ private function getBridgeFile(): ViteBridgeFile $file = Filesystem\read_file($this->getBridgeFilePath()); $content = arr(Json\decode($file)); - return static::$bridgeFile = new ViteBridgeFile( + return self::$bridgeFile = new ViteBridgeFile( url: $content->get('url'), needsReactRefresh: $content->get('needsReactRefresh', default: false), ); diff --git a/src/Tempest/Framework/Commands/DatabaseSeedCommand.php b/src/Tempest/Framework/Commands/DatabaseSeedCommand.php index 1c79e48f3..d33579c20 100644 --- a/src/Tempest/Framework/Commands/DatabaseSeedCommand.php +++ b/src/Tempest/Framework/Commands/DatabaseSeedCommand.php @@ -10,13 +10,13 @@ use Tempest\Container\Container; use Tempest\Database\Config\SeederConfig; -final class DatabaseSeedCommand +final readonly class DatabaseSeedCommand { use HasConsole; public function __construct( - private readonly Container $container, - private readonly SeederConfig $seederConfig, + private Container $container, + private SeederConfig $seederConfig, ) {} #[ConsoleCommand( diff --git a/src/Tempest/Framework/Commands/MetaViewComponentCommand.php b/src/Tempest/Framework/Commands/MetaViewComponentCommand.php index 1ce98f187..ef9c5b0e1 100644 --- a/src/Tempest/Framework/Commands/MetaViewComponentCommand.php +++ b/src/Tempest/Framework/Commands/MetaViewComponentCommand.php @@ -15,12 +15,12 @@ use function Tempest\Support\Filesystem\is_file; use function Tempest\Support\str; -final class MetaViewComponentCommand +final readonly class MetaViewComponentCommand { use HasConsole; public function __construct( - private readonly ViewConfig $viewConfig, + private ViewConfig $viewConfig, ) {} #[ConsoleCommand(name: 'meta:view-component', hidden: true)] @@ -33,7 +33,7 @@ public function __invoke( $viewComponent = $this->resolveViewComponent($viewComponentName); - if ($viewComponent === null) { + if (! $viewComponent instanceof ViewComponent) { $this->error('Unknown view component `' . $viewComponentName . '`'); return; } diff --git a/src/Tempest/Framework/Testing/Http/HttpRouterTester.php b/src/Tempest/Framework/Testing/Http/HttpRouterTester.php index f5bf6cddf..2f11ad8f5 100644 --- a/src/Tempest/Framework/Testing/Http/HttpRouterTester.php +++ b/src/Tempest/Framework/Testing/Http/HttpRouterTester.php @@ -262,11 +262,7 @@ public function makePsrRequest( $_COOKIE = $cookies; - if (is_array($body)) { - $_POST = $body; - } else { - $_POST = []; - } + $_POST = is_array($body) ? $body : []; return ServerRequestFactory::fromGlobals()->withUploadedFiles($files); } @@ -278,11 +274,11 @@ private function createHeaders(array $headers = []): array callback: fn (mixed $_, string $headerKey): bool => strcasecmp($headerKey, 'accept') === 0, ); - if ($this->contentType !== null) { + if ($this->contentType instanceof ContentType) { $headers[$key ?? 'accept'] = $this->contentType->value; } - if ($this->includeSecFetchHeaders === true) { + if ($this->includeSecFetchHeaders) { if (! array_key_exists('sec-fetch-site', array_change_key_case($headers, case: CASE_LOWER))) { $headers['sec-fetch-site'] = SecFetchSite::SAME_ORIGIN; } diff --git a/src/Tempest/Framework/Testing/Http/TestResponseHelper.php b/src/Tempest/Framework/Testing/Http/TestResponseHelper.php index 497669ed0..977af753d 100644 --- a/src/Tempest/Framework/Testing/Http/TestResponseHelper.php +++ b/src/Tempest/Framework/Testing/Http/TestResponseHelper.php @@ -327,7 +327,7 @@ public function assertHasSession(string $key, ?Closure $callback = null): self ), ); - if ($callback !== null) { + if ($callback instanceof Closure) { $callback($session, $data); } @@ -352,7 +352,7 @@ public function assertHasValidationError(string $key, ?Closure $callback = null) ), ); - if ($callback !== null) { + if ($callback instanceof Closure) { $callback($validationErrors); } @@ -428,7 +428,7 @@ public function assertViewData(string $key, ?Closure $callback = null): self ), ); - if ($callback !== null && $callback($data, $value) === false) { + if ($callback instanceof Closure && $callback($data, $value) === false) { Assert::fail(sprintf('Failed validating view data for [%s]', $key)); } @@ -509,7 +509,7 @@ public function assertViewModel(string $expected, ?Closure $callback = null): se actual: $this->body, ); - if ($callback !== null && $callback($this->body) === false) { + if ($callback instanceof Closure && $callback($this->body) === false) { Assert::fail('Failed validating view model'); } @@ -711,7 +711,7 @@ public function assertHasNoJsonValidationErrors(): self */ public function dd(): never { - if ($this->throwable !== null) { + if ($this->throwable instanceof Throwable) { dump(sprintf('There was a [%s] exception during this request handling: %s', $this->throwable::class, $this->throwable->getMessage())); // @phpstan-ignore disallowed.function } @@ -720,7 +720,7 @@ public function dd(): never private function assertHasContainer(): void { - if ($this->container === null) { + if (! $this->container instanceof Container) { Assert::fail('This assertion requires a container.'); } } diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index 7c600b78b..af00cfcb1 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -120,7 +120,8 @@ protected function setUp(): void { parent::setUp(); - $this->setupKernel() + $this + ->setupKernel() ->setupConsole() ->setupTesters() ->setupBaseRequest(); @@ -246,7 +247,7 @@ protected function assertException(string $expectedExceptionClass, Closure $hand } catch (Throwable $throwable) { $this->assertInstanceOf($expectedExceptionClass, $throwable); - if ($assertException !== null) { + if ($assertException instanceof Closure) { $assertException($throwable); } diff --git a/tests/Benchmark/Extension/MarkdownExtension.php b/tests/Benchmark/Extension/MarkdownExtension.php index e0108766e..790629033 100644 --- a/tests/Benchmark/Extension/MarkdownExtension.php +++ b/tests/Benchmark/Extension/MarkdownExtension.php @@ -13,20 +13,16 @@ final class MarkdownExtension implements ExtensionInterface { - public function configure(OptionsResolver $resolver): void - { - } + public function configure(OptionsResolver $resolver): void {} public function load(Container $container): void { $container->register( MarkdownRenderer::class, - function (Container $container) { - return new MarkdownRenderer( - $container->get(ConsoleExtension::SERVICE_OUTPUT_STD), - $container->get(ExpressionExtension::SERVICE_PLAIN_PRINTER), - ); - }, + fn (Container $container) => new MarkdownRenderer( + $container->get(ConsoleExtension::SERVICE_OUTPUT_STD), + $container->get(ExpressionExtension::SERVICE_PLAIN_PRINTER), + ), [ ReportExtension::TAG_REPORT_RENDERER => [ 'name' => 'markdown', diff --git a/tests/Benchmark/Extension/MarkdownRendererTest.php b/tests/Benchmark/Extension/MarkdownRendererTest.php index 4faae9d60..fc0efaee5 100644 --- a/tests/Benchmark/Extension/MarkdownRendererTest.php +++ b/tests/Benchmark/Extension/MarkdownRendererTest.php @@ -40,14 +40,14 @@ public function it_renders_a_compact_aggregate_report_table(): void $renderer->render($reports, new Config('markdown', ['file' => null])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - | Benchmark | Set | Mem. Peak | Time | Variability | - | --------- | --- | --------- | ---- | ----------- | - | ContainerBench(benchAutowireSimple) | - | 3.952mb 0.00% | 4.187μs +0.17% | ±2.05% +108.06% | + | Benchmark | Set | Mem. Peak | Time | Variability | + | --------- | --- | --------- | ---- | ----------- | + | ContainerBench(benchAutowireSimple) | - | 3.952mb 0.00% | 4.187μs +0.17% | ±2.05% +108.06% | - MARKDOWN, + MARKDOWN, $output->fetch()); } @@ -70,12 +70,12 @@ public function it_keeps_non_aggregate_table_columns_unchanged(): void $renderer->render($reports, new Config('markdown', ['file' => null])); $this->assertSame(<<<'MARKDOWN' - | name | value | - | ---- | ----- | - | Example | 123 | + | name | value | + | ---- | ----- | + | Example | 123 | - MARKDOWN, $output->fetch()); + MARKDOWN, $output->fetch()); } #[Test] @@ -113,14 +113,14 @@ public function it_can_filter_compact_rows_by_minimum_time_difference(): void $renderer->render($reports, new Config('markdown', ['file' => null, 'outlier_min_diff' => 1.0])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - | Benchmark | Set | Mem. Peak | Time | Variability | - | --------- | --- | --------- | ---- | ----------- | - | ContainerBench(benchAutowireNested) | - | 3.952mb +0.10% | 14.791μs +1.55% | ±0.69% +0.50% | + | Benchmark | Set | Mem. Peak | Time | Variability | + | --------- | --- | --------- | ---- | ----------- | + | ContainerBench(benchAutowireNested) | - | 3.952mb +0.10% | 14.791μs +1.55% | ±0.69% +0.50% | - MARKDOWN, + MARKDOWN, $output->fetch()); } @@ -160,12 +160,12 @@ public function it_shows_an_informative_message_when_no_outliers_match(): void $renderer->render($reports, new Config('markdown', ['file' => null, 'outlier_min_diff' => 5.0])); $this->assertSame(<<<'MARKDOWN' - ## Benchmark Results + ## Benchmark Results - _No benchmark changes above ±5%._ + _No benchmark changes above ±5%._ - MARKDOWN, + MARKDOWN, $output->fetch()); } diff --git a/tests/Benchmark/Http/GenericRouterBench.php b/tests/Benchmark/Http/GenericRouterBench.php index d99bcb26d..85918bfe9 100644 --- a/tests/Benchmark/Http/GenericRouterBench.php +++ b/tests/Benchmark/Http/GenericRouterBench.php @@ -36,7 +36,7 @@ final class GenericRouterBench public function setUp(): void { - $routeConfig = self::makeRouteConfig(); + $routeConfig = $this->makeRouteConfig(); $routeConfig->middleware = new Middleware( HandleRouteExceptionMiddleware::class, @@ -53,7 +53,7 @@ public function setUp(): void $this->router = new GenericRouter($container, $routeConfig); - $routeConfigWithoutExceptionMiddleware = self::makeRouteConfig(); + $routeConfigWithoutExceptionMiddleware = $this->makeRouteConfig(); $routeConfigWithoutExceptionMiddleware->middleware = new Middleware( MatchRouteMiddleware::class, ); @@ -109,7 +109,7 @@ public function handleWithParam(string $id): Ok return new Ok('OK'); } - private static function makeRouteConfig(): RouteConfig + private function makeRouteConfig(): RouteConfig { $handler = new MethodReflector(new ReflectionMethod(self::class, 'handle')); $handlerWithParam = new MethodReflector(new ReflectionMethod(self::class, 'handleWithParam')); diff --git a/tests/Benchmark/Http/Routing/Matching/GenericRouteMatcherBench.php b/tests/Benchmark/Http/Routing/Matching/GenericRouteMatcherBench.php index 95794f418..34c3ee039 100644 --- a/tests/Benchmark/Http/Routing/Matching/GenericRouteMatcherBench.php +++ b/tests/Benchmark/Http/Routing/Matching/GenericRouteMatcherBench.php @@ -22,7 +22,7 @@ final class GenericRouteMatcherBench public function __construct() { - $config = self::makeRouteConfig(); + $config = $this->makeRouteConfig(); $this->matcher = new GenericRouteMatcher($config); } @@ -46,7 +46,7 @@ public function provideDynamicMatchingCases(): Generator yield 'Static route' => ['uri' => '/test/5']; } - private static function makeRouteConfig(): RouteConfig + private function makeRouteConfig(): RouteConfig { $routeBuilder = new FakeRouteBuilder(); $constructor = new RouteConfigurator(); diff --git a/tests/Fixtures/Commands/HelloWorldTestCommand.php b/tests/Fixtures/Commands/HelloWorldTestCommand.php index 313d75eb9..88a406a09 100644 --- a/tests/Fixtures/Commands/HelloWorldTestCommand.php +++ b/tests/Fixtures/Commands/HelloWorldTestCommand.php @@ -9,7 +9,5 @@ final readonly class HelloWorldTestCommand { #[ConsoleCommand] - public function __invoke(): void - { - } + public function __invoke(): void {} } diff --git a/tests/Fixtures/Commands/MyBrokenCommand.php b/tests/Fixtures/Commands/MyBrokenCommand.php index 29aad2368..3bf5bb19e 100644 --- a/tests/Fixtures/Commands/MyBrokenCommand.php +++ b/tests/Fixtures/Commands/MyBrokenCommand.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Commands; -final class MyBrokenCommand -{ -} +final class MyBrokenCommand {} diff --git a/tests/Fixtures/Commands/MyCommand.php b/tests/Fixtures/Commands/MyCommand.php index 24ea8316d..6bc340bee 100644 --- a/tests/Fixtures/Commands/MyCommand.php +++ b/tests/Fixtures/Commands/MyCommand.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Commands; -final class MyCommand -{ -} +final class MyCommand {} diff --git a/tests/Fixtures/Console/CommandWithDifferentArguments.php b/tests/Fixtures/Console/CommandWithDifferentArguments.php index 3bcf7c6cb..3a488f0e0 100644 --- a/tests/Fixtures/Console/CommandWithDifferentArguments.php +++ b/tests/Fixtures/Console/CommandWithDifferentArguments.php @@ -21,6 +21,5 @@ public function __invoke( string $camelCaseStringWithDefault = 'foo', bool $camelCaseBoolWithTrueDefault = true, bool $camelCaseBoolWithFalseDefault = false, - ): void { - } + ): void {} } diff --git a/tests/Fixtures/Console/StylingCommand.php b/tests/Fixtures/Console/StylingCommand.php index 3d5f252cf..475490226 100644 --- a/tests/Fixtures/Console/StylingCommand.php +++ b/tests/Fixtures/Console/StylingCommand.php @@ -14,7 +14,8 @@ #[ConsoleCommand(name: 'test:style')] public function __invoke(): void { - $this->info('info') + $this + ->info('info') ->success('success') ->warning('warning') ->error('error'); diff --git a/tests/Fixtures/Controllers/DocsController.php b/tests/Fixtures/Controllers/DocsController.php index 56d4ccda0..d8367974b 100644 --- a/tests/Fixtures/Controllers/DocsController.php +++ b/tests/Fixtures/Controllers/DocsController.php @@ -9,7 +9,5 @@ final readonly class DocsController { #[Get('/docs/{category}/{slug}')] - public function __invoke(string $category, string $slug): void - { - } + public function __invoke(string $category, string $slug): void {} } diff --git a/tests/Fixtures/Events/EventForListenerWithoutPropagation.php b/tests/Fixtures/Events/EventForListenerWithoutPropagation.php index 3dc5f4037..ccf11b102 100644 --- a/tests/Fixtures/Events/EventForListenerWithoutPropagation.php +++ b/tests/Fixtures/Events/EventForListenerWithoutPropagation.php @@ -2,6 +2,4 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class EventForListenerWithoutPropagation -{ -} +final readonly class EventForListenerWithoutPropagation {} diff --git a/tests/Fixtures/Events/EventInterface.php b/tests/Fixtures/Events/EventInterface.php index 55882c827..8af3a0201 100644 --- a/tests/Fixtures/Events/EventInterface.php +++ b/tests/Fixtures/Events/EventInterface.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Events; -interface EventInterface -{ -} +interface EventInterface {} diff --git a/tests/Fixtures/Events/EventInterfaceImplementation.php b/tests/Fixtures/Events/EventInterfaceImplementation.php index 3f6002b47..d0d06f3a0 100644 --- a/tests/Fixtures/Events/EventInterfaceImplementation.php +++ b/tests/Fixtures/Events/EventInterfaceImplementation.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class EventInterfaceImplementation implements EventInterface -{ -} +final readonly class EventInterfaceImplementation implements EventInterface {} diff --git a/tests/Fixtures/Events/EventWithoutPropagation.php b/tests/Fixtures/Events/EventWithoutPropagation.php index c18a33a2b..63674a320 100644 --- a/tests/Fixtures/Events/EventWithoutPropagation.php +++ b/tests/Fixtures/Events/EventWithoutPropagation.php @@ -5,6 +5,4 @@ use Tempest\EventBus\StopsPropagation; #[StopsPropagation] -final readonly class EventWithoutPropagation -{ -} +final readonly class EventWithoutPropagation {} diff --git a/tests/Fixtures/Events/ItHappened.php b/tests/Fixtures/Events/ItHappened.php index 09dac2f71..5b7a4df83 100644 --- a/tests/Fixtures/Events/ItHappened.php +++ b/tests/Fixtures/Events/ItHappened.php @@ -4,6 +4,4 @@ namespace Tests\Tempest\Fixtures\Events; -final readonly class ItHappened -{ -} +final readonly class ItHappened {} diff --git a/tests/Fixtures/GlobalHiddenDiscovery.php b/tests/Fixtures/GlobalHiddenDiscovery.php index dc75910e7..a784f8c7e 100644 --- a/tests/Fixtures/GlobalHiddenDiscovery.php +++ b/tests/Fixtures/GlobalHiddenDiscovery.php @@ -13,9 +13,7 @@ final class GlobalHiddenDiscovery implements Discovery use IsDiscovery; - public function discover(DiscoveryLocation $location, ClassReflector $class): void - { - } + public function discover(DiscoveryLocation $location, ClassReflector $class): void {} public function apply(): void { diff --git a/tests/Fixtures/GlobalHiddenPathDiscovery.php b/tests/Fixtures/GlobalHiddenPathDiscovery.php index 737b4694c..7c12bcf71 100644 --- a/tests/Fixtures/GlobalHiddenPathDiscovery.php +++ b/tests/Fixtures/GlobalHiddenPathDiscovery.php @@ -13,9 +13,7 @@ final class GlobalHiddenPathDiscovery implements Discovery use IsDiscovery; - public function discover(DiscoveryLocation $location, ClassReflector $class): void - { - } + public function discover(DiscoveryLocation $location, ClassReflector $class): void {} public function apply(): void { diff --git a/tests/Fixtures/Handlers/MyCommandHandler.php b/tests/Fixtures/Handlers/MyCommandHandler.php index 4b6a9d1e3..be53f3b94 100644 --- a/tests/Fixtures/Handlers/MyCommandHandler.php +++ b/tests/Fixtures/Handlers/MyCommandHandler.php @@ -10,7 +10,5 @@ final class MyCommandHandler { #[CommandHandler] - public function __invoke(MyCommand $command): void - { - } + public function __invoke(MyCommand $command): void {} } diff --git a/tests/Fixtures/TestInstallerClass.php b/tests/Fixtures/TestInstallerClass.php index 25e10c22c..e3a6abdbc 100644 --- a/tests/Fixtures/TestInstallerClass.php +++ b/tests/Fixtures/TestInstallerClass.php @@ -7,6 +7,4 @@ use Tempest\Discovery\SkipDiscovery; #[SkipDiscovery] -final readonly class TestInstallerClass -{ -} +final readonly class TestInstallerClass {} diff --git a/tests/Integration/Auth/AccessControl/AccessControlTest.php b/tests/Integration/Auth/AccessControl/AccessControlTest.php index 7bde20515..33be4a382 100644 --- a/tests/Integration/Auth/AccessControl/AccessControlTest.php +++ b/tests/Integration/Auth/AccessControl/AccessControlTest.php @@ -134,7 +134,7 @@ public function view(): bool #[Policy(Article::class, action: 'edit')] public function edit(Article $article, ?TestUser $subject): bool { - if ($subject === null) { + if (! $subject instanceof TestUser) { return false; } @@ -144,7 +144,7 @@ public function edit(Article $article, ?TestUser $subject): bool #[Policy(Article::class, action: 'delete')] public function delete(Article $article, ?TestUser $subject): bool|AccessDecision { - if ($subject === null) { + if (! $subject instanceof TestUser) { return AccessDecision::denied('Authentication required'); } @@ -177,7 +177,7 @@ public function view(): bool #[Policy(ArticleComment::class, action: 'edit')] public function edit(ArticleComment $comment, ?TestUser $subject): bool { - if ($subject === null) { + if (! $subject instanceof TestUser) { return false; } diff --git a/tests/Integration/Auth/AccessControl/PolicyBasedAccessControlTest.php b/tests/Integration/Auth/AccessControl/PolicyBasedAccessControlTest.php index 4c4d1bde6..9adc1746c 100644 --- a/tests/Integration/Auth/AccessControl/PolicyBasedAccessControlTest.php +++ b/tests/Integration/Auth/AccessControl/PolicyBasedAccessControlTest.php @@ -474,11 +474,7 @@ final class MultiAuthenticatablePolicy #[Policy] public function view(?Document $_resource, null|User|ServiceAccount $subject): bool { - if (! $subject instanceof Authenticatable) { - return false; - } - - return true; + return $subject instanceof Authenticatable; } } @@ -517,7 +513,7 @@ final class PolicyWithoutActionNames #[Policy(Post::class)] public function canMarkAsPublished(?Post $post, ?User $user): bool { - if ($user === null) { + if (! $user instanceof User) { return false; } @@ -527,7 +523,7 @@ public function canMarkAsPublished(?Post $post, ?User $user): bool #[Policy(Post::class)] public function approveForPublication(?Post $post, ?User $user): bool { - if ($user === null) { + if (! $user instanceof User) { return false; } diff --git a/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php b/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php index c23d41d08..b061e602b 100644 --- a/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php +++ b/tests/Integration/Auth/Authentication/SessionAuthenticatorTest.php @@ -42,7 +42,7 @@ protected function configure(): void Filesystem\ensure_directory_empty($this->path); $this->container->get(FrameworkKernel::class)->internalStorage = realpath($this->path); - $this->container->config(new FileSessionConfig(path: 'sessions', expiration: Duration::hours(2))); + $this->container->config(new FileSessionConfig(expiration: Duration::hours(2), path: 'sessions')); $this->container->config(new AuthConfig(authenticatables: [User::class])); $this->container->singleton(SessionManager::class, fn () => new FileSessionManager( $this->container->get(Clock::class), diff --git a/tests/Integration/Cache/RedisCacheTest.php b/tests/Integration/Cache/RedisCacheTest.php index 690ef341e..9f7531eab 100644 --- a/tests/Integration/Cache/RedisCacheTest.php +++ b/tests/Integration/Cache/RedisCacheTest.php @@ -3,12 +3,14 @@ namespace Tests\Tempest\Integration\Cache; use Predis; +use Predis\Client; use Symfony\Component\Cache\Adapter\RedisAdapter; use Tempest\Cache\GenericCache; use Tempest\KeyValue\Redis\Config\RedisConfig; use Tempest\KeyValue\Redis\PhpRedisClient; use Tempest\KeyValue\Redis\PredisClient; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; +use Throwable; final class RedisCacheTest extends FrameworkIntegrationTestCase { @@ -38,7 +40,7 @@ public function test_php_redis_cache(): void try { $redis->connect(); - } catch (\Throwable) { + } catch (Throwable) { $this->markTestSkipped('Could not connect to Redis.'); } @@ -52,11 +54,11 @@ public function test_php_redis_cache(): void public function test_predis_cache(): void { - if (! class_exists(Predis\Client::class)) { + if (! class_exists(Client::class)) { $this->markTestSkipped('The `predis/predis` package is not installed.'); } - $redis = new PredisClient(new Predis\Client( + $redis = new PredisClient(new Client( parameters: [ 'database' => 6, 'timeout' => .2, @@ -66,7 +68,7 @@ public function test_predis_cache(): void try { $redis->connect(); - } catch (\Throwable) { + } catch (Throwable) { $this->markTestSkipped('Could not connect to Redis.'); } diff --git a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php index e4cb3ac20..c5d6358b6 100644 --- a/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticProgressBarComponentTest.php @@ -25,11 +25,11 @@ public function test_progress_bar(): void }) ->assertContains( << ] (1/3) - [====================> ] (2/3) - [===============================] (3/3) - ["aa","bb","cc"] - TXT, + [==========> ] (1/3) + [====================> ] (2/3) + [===============================] (3/3) + ["aa","bb","cc"] + TXT, true, ); } diff --git a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php index 447de2dce..c1608c974 100644 --- a/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php +++ b/tests/Integration/Console/Components/Static/StaticSearchComponentTest.php @@ -26,22 +26,22 @@ public function test_search_component(): void ->submit('a') ->assertContains( <<submit(1) ->submit('b') ->assertContains( <<submit(2) @@ -62,9 +62,9 @@ public function test_no_answer(): void ->submit() ->assertContains( text: <<submit(0) @@ -86,9 +86,9 @@ public function test_default_answer(): void ->submit() ->assertContains( text: <<submit(0) diff --git a/tests/Integration/Console/Components/TaskComponentTest.php b/tests/Integration/Console/Components/TaskComponentTest.php index 68428409e..9b633ba60 100644 --- a/tests/Integration/Console/Components/TaskComponentTest.php +++ b/tests/Integration/Console/Components/TaskComponentTest.php @@ -64,7 +64,7 @@ public function test_process_task(): void $frames = iterator_to_array($component->render($terminal)); $this->assertStringContainsString('Task in progress', $frames[0]); - $this->assertStringContainsString('Done in', $frames[array_key_last($frames)]); + $this->assertStringContainsString('Done in', array_last($frames)); }); } @@ -100,7 +100,7 @@ public function test_failing_task(): void $frames = iterator_to_array($component->render($terminal)); $this->assertStringContainsString('Task in progress', $frames[0]); - $this->assertStringContainsString('An error occurred.', $frames[array_key_last($frames)]); + $this->assertStringContainsString('An error occurred.', array_last($frames)); }); } } diff --git a/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php b/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php index 48118f0f0..ec9b88813 100644 --- a/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php +++ b/tests/Integration/Console/Fixtures/CommandWithNonCommandMethods.php @@ -8,16 +8,10 @@ final class CommandWithNonCommandMethods { - public function __invoke(): void - { - } + public function __invoke(): void {} #[ConsoleCommand('test:not-empty')] - public function do(): void - { - } + public function do(): void {} - public function empty(): void - { - } + public function empty(): void {} } diff --git a/tests/Integration/Console/Fixtures/CompletionTestCommand.php b/tests/Integration/Console/Fixtures/CompletionTestCommand.php index a41a36690..9cc3c6c42 100644 --- a/tests/Integration/Console/Fixtures/CompletionTestCommand.php +++ b/tests/Integration/Console/Fixtures/CompletionTestCommand.php @@ -13,6 +13,5 @@ public function __invoke( string $value, bool $flag = false, array $items = [], - ): void { - } + ): void {} } diff --git a/tests/Integration/Console/Fixtures/MyConsole.php b/tests/Integration/Console/Fixtures/MyConsole.php index d45b635e8..453fd2454 100644 --- a/tests/Integration/Console/Fixtures/MyConsole.php +++ b/tests/Integration/Console/Fixtures/MyConsole.php @@ -17,6 +17,5 @@ public function handle( int $times = 1, bool $force = false, ?string $optional = null, - ): void { - } + ): void {} } diff --git a/tests/Integration/Console/Fixtures/Package.php b/tests/Integration/Console/Fixtures/Package.php index 56dd3b7b5..44239f29e 100644 --- a/tests/Integration/Console/Fixtures/Package.php +++ b/tests/Integration/Console/Fixtures/Package.php @@ -10,9 +10,7 @@ final readonly class Package { #[ConsoleCommand] - public function list(): void - { - } + public function list(): void {} #[ConsoleCommand(help: 'help text')] public function info( @@ -23,6 +21,5 @@ public function info( aliases: ['n'], )] string $name, - ): void { - } + ): void {} } diff --git a/tests/Integration/Console/Fixtures/TestConsoleException.php b/tests/Integration/Console/Fixtures/TestConsoleException.php index 5ba91f6e1..e8f42d415 100644 --- a/tests/Integration/Console/Fixtures/TestConsoleException.php +++ b/tests/Integration/Console/Fixtures/TestConsoleException.php @@ -9,7 +9,5 @@ final class TestConsoleException extends ConsoleException { - public function render(Console $console): void - { - } + public function render(Console $console): void {} } diff --git a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php index 341f23e52..552c26c26 100644 --- a/tests/Integration/Console/Scheduler/GenericSchedulerTest.php +++ b/tests/Integration/Console/Scheduler/GenericSchedulerTest.php @@ -117,12 +117,8 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v } // dummy handler for testing - public function handler(): void - { - } + public function handler(): void {} // dummy command for testing - public function command(): void - { - } + public function command(): void {} } diff --git a/tests/Integration/Console/Scheduler/HandlerInvocationTest.php b/tests/Integration/Console/Scheduler/HandlerInvocationTest.php index 30e697d49..54c058a4f 100644 --- a/tests/Integration/Console/Scheduler/HandlerInvocationTest.php +++ b/tests/Integration/Console/Scheduler/HandlerInvocationTest.php @@ -30,7 +30,5 @@ public function test_name_gets_constructed_properly(): void } // dummy handler method - public function handler(): void - { - } + public function handler(): void {} } diff --git a/tests/Integration/Core/Config/LoadConfigTest.php b/tests/Integration/Core/Config/LoadConfigTest.php index 365fff006..d3b51d6b3 100644 --- a/tests/Integration/Core/Config/LoadConfigTest.php +++ b/tests/Integration/Core/Config/LoadConfigTest.php @@ -117,14 +117,14 @@ private function setupFixtures(array $configs): void $db = str_replace('.php', '.sqlite', $config); Filesystem\write_file(__DIR__ . '/Fixtures/' . $config, <<logs[] = ['level' => 'emergency', 'message' => $message, 'context' => $context]; } - public function alert(string|\Stringable $message, array $context = []): void + public function alert(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'alert', 'message' => $message, 'context' => $context]; } - public function critical(string|\Stringable $message, array $context = []): void + public function critical(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'critical', 'message' => $message, 'context' => $context]; } - public function error(string|\Stringable $message, array $context = []): void + public function error(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'error', 'message' => $message, 'context' => $context]; } - public function warning(string|\Stringable $message, array $context = []): void + public function warning(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'warning', 'message' => $message, 'context' => $context]; } - public function notice(string|\Stringable $message, array $context = []): void + public function notice(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'notice', 'message' => $message, 'context' => $context]; } - public function info(string|\Stringable $message, array $context = []): void + public function info(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'info', 'message' => $message, 'context' => $context]; } - public function debug(string|\Stringable $message, array $context = []): void + public function debug(string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => 'debug', 'message' => $message, 'context' => $context]; } - public function log(mixed $level, string|\Stringable $message, array $context = []): void + public function log(mixed $level, string|Stringable $message, array $context = []): void { $this->logs[] = ['level' => $level, 'message' => $message, 'context' => $context]; } diff --git a/tests/Integration/Core/Fixtures/MiddlewareA.php b/tests/Integration/Core/Fixtures/MiddlewareA.php index 255c68684..29fb6aec2 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareA.php +++ b/tests/Integration/Core/Fixtures/MiddlewareA.php @@ -2,6 +2,4 @@ namespace Tests\Tempest\Integration\Core\Fixtures; -final class MiddlewareA -{ -} +final class MiddlewareA {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareB.php b/tests/Integration/Core/Fixtures/MiddlewareB.php index a70fe5fd8..4347a2fc8 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareB.php +++ b/tests/Integration/Core/Fixtures/MiddlewareB.php @@ -2,6 +2,4 @@ namespace Tests\Tempest\Integration\Core\Fixtures; -final class MiddlewareB -{ -} +final class MiddlewareB {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareC.php b/tests/Integration/Core/Fixtures/MiddlewareC.php index b845eaeb4..281c47798 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareC.php +++ b/tests/Integration/Core/Fixtures/MiddlewareC.php @@ -2,6 +2,4 @@ namespace Tests\Tempest\Integration\Core\Fixtures; -final class MiddlewareC -{ -} +final class MiddlewareC {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareFramework.php b/tests/Integration/Core/Fixtures/MiddlewareFramework.php index 7e538bb6d..932d6ae1f 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareFramework.php +++ b/tests/Integration/Core/Fixtures/MiddlewareFramework.php @@ -5,6 +5,4 @@ use Tempest\Core\Priority; #[Priority(Priority::FRAMEWORK)] -final class MiddlewareFramework -{ -} +final class MiddlewareFramework {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareHigh.php b/tests/Integration/Core/Fixtures/MiddlewareHigh.php index 2eb5fcb6b..b8831399d 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareHigh.php +++ b/tests/Integration/Core/Fixtures/MiddlewareHigh.php @@ -5,6 +5,4 @@ use Tempest\Core\Priority; #[Priority(Priority::HIGH)] -final class MiddlewareHigh -{ -} +final class MiddlewareHigh {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareHighest.php b/tests/Integration/Core/Fixtures/MiddlewareHighest.php index 74c7ee1fc..0ddae4af6 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareHighest.php +++ b/tests/Integration/Core/Fixtures/MiddlewareHighest.php @@ -5,6 +5,4 @@ use Tempest\Core\Priority; #[Priority(Priority::HIGHEST)] -final class MiddlewareHighest -{ -} +final class MiddlewareHighest {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareLow.php b/tests/Integration/Core/Fixtures/MiddlewareLow.php index 3dc6f0af8..7dfff0f0f 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareLow.php +++ b/tests/Integration/Core/Fixtures/MiddlewareLow.php @@ -5,6 +5,4 @@ use Tempest\Core\Priority; #[Priority(Priority::LOW)] -final class MiddlewareLow -{ -} +final class MiddlewareLow {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareLowest.php b/tests/Integration/Core/Fixtures/MiddlewareLowest.php index f1c635a87..4302774b9 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareLowest.php +++ b/tests/Integration/Core/Fixtures/MiddlewareLowest.php @@ -5,6 +5,4 @@ use Tempest\Core\Priority; #[Priority(Priority::LOWEST)] -final class MiddlewareLowest -{ -} +final class MiddlewareLowest {} diff --git a/tests/Integration/Core/Fixtures/MiddlewareNormal.php b/tests/Integration/Core/Fixtures/MiddlewareNormal.php index 7b45ef132..7201eca48 100644 --- a/tests/Integration/Core/Fixtures/MiddlewareNormal.php +++ b/tests/Integration/Core/Fixtures/MiddlewareNormal.php @@ -5,6 +5,4 @@ use Tempest\Core\Priority; #[Priority(Priority::NORMAL)] -final class MiddlewareNormal -{ -} +final class MiddlewareNormal {} diff --git a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php index 0fe939733..c367d1d95 100644 --- a/tests/Integration/Database/Builder/InsertQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/InsertQueryBuilderTest.php @@ -189,11 +189,11 @@ public function test_insert_mapping(): void $expected = match ($dialect) { DatabaseDialect::POSTGRESQL => <<<'SQL' - INSERT INTO authors (name) VALUES (?) RETURNING * - SQL, + INSERT INTO authors (name) VALUES (?) RETURNING * + SQL, default => <<<'SQL' - INSERT INTO `authors` (`name`) VALUES (?) - SQL, + INSERT INTO `authors` (`name`) VALUES (?) + SQL, }; $this->assertSame($expected, $query->compile()->toString()); diff --git a/tests/Integration/Database/Builder/InsertRelationsTest.php b/tests/Integration/Database/Builder/InsertRelationsTest.php index 0f6c6c092..75068f4d2 100644 --- a/tests/Integration/Database/Builder/InsertRelationsTest.php +++ b/tests/Integration/Database/Builder/InsertRelationsTest.php @@ -364,7 +364,7 @@ final class Spell public PrimaryKey $spell_id; - #[BelongsTo(ownerJoin: 'creator_uuid', relationJoin: 'mage_uuid')] + #[BelongsTo(relationJoin: 'mage_uuid', ownerJoin: 'creator_uuid')] public ?Mage $creator = null; public function __construct( @@ -395,7 +395,7 @@ final class Adventurer public PrimaryKey $adventurer_id; - #[BelongsTo(ownerJoin: 'party_uuid', relationJoin: 'party_id')] + #[BelongsTo(relationJoin: 'party_id', ownerJoin: 'party_uuid')] public ?Party $party = null; public function __construct( diff --git a/tests/Integration/Database/Builder/IsDatabaseModelTest.php b/tests/Integration/Database/Builder/IsDatabaseModelTest.php index 1a312bad0..f3a60efe7 100644 --- a/tests/Integration/Database/Builder/IsDatabaseModelTest.php +++ b/tests/Integration/Database/Builder/IsDatabaseModelTest.php @@ -771,6 +771,7 @@ public function test_on_database_does_not_mutate_original(): void // Original still works against default database $foo->update(bar: 'updated'); + $refreshed = Foo::get($foo->id); $this->assertSame('updated', $refreshed->bar); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index c4d257591..1c3c26212 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -316,9 +316,11 @@ public function test_chunk(): void $this->assertCount(4, $results); $results = []; - Book::select()->whereRaw("title <> 'A'")->chunk(function (array $chunk) use (&$results): void { - $results = [...$results, ...$chunk]; - }, 2); + Book::select() + ->whereRaw("title <> 'A'") + ->chunk(function (array $chunk) use (&$results): void { + $results = [...$results, ...$chunk]; + }, 2); $this->assertCount(3, $results); } @@ -337,9 +339,11 @@ public function test_chunk_with_relation(): void Book::new(title: 'B', author: $author)->save(); $results = []; - Book::select()->with('author')->chunk(function (array $chunk) use (&$results): void { - $results = [...$results, ...$chunk]; - }, 1); + Book::select() + ->with('author') + ->chunk(function (array $chunk) use (&$results): void { + $results = [...$results, ...$chunk]; + }, 1); $this->assertCount(2, $results); } diff --git a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php index 0fd8271db..a81f9a998 100644 --- a/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/UpdateQueryBuilderTest.php @@ -310,11 +310,11 @@ public function test_update_mapping(): void $expected = match ($dialect) { DatabaseDialect::POSTGRESQL => <<<'SQL' - UPDATE authors SET name = ? WHERE authors.id = ? - SQL, + UPDATE authors SET name = ? WHERE authors.id = ? + SQL, default => <<<'SQL' - UPDATE `authors` SET `name` = ? WHERE `authors`.`id` = ? - SQL, + UPDATE `authors` SET `name` = ? WHERE `authors`.`id` = ? + SQL, }; $this->assertSame($expected, $query->compile()->toString()); diff --git a/tests/Integration/Database/Builder/UpdateRelationsTest.php b/tests/Integration/Database/Builder/UpdateRelationsTest.php index 8763cba18..9309bf6a9 100644 --- a/tests/Integration/Database/Builder/UpdateRelationsTest.php +++ b/tests/Integration/Database/Builder/UpdateRelationsTest.php @@ -506,7 +506,7 @@ final class UpdateSpell public PrimaryKey $spell_id; - #[BelongsTo(ownerJoin: 'creator_uuid', relationJoin: 'mage_uuid')] + #[BelongsTo(relationJoin: 'mage_uuid', ownerJoin: 'creator_uuid')] public ?UpdateMage $creator = null; public function __construct( @@ -539,7 +539,7 @@ final class UpdateAdventurer public PrimaryKey $adventurer_id; - #[BelongsTo(ownerJoin: 'party_uuid', relationJoin: 'party_id')] + #[BelongsTo(relationJoin: 'party_id', ownerJoin: 'party_uuid')] public ?UpdateParty $party = null; public function __construct( diff --git a/tests/Integration/Database/ConvenientWhereMethodsTest.php b/tests/Integration/Database/ConvenientWhereMethodsTest.php index c64f156bb..6917c3c93 100644 --- a/tests/Integration/Database/ConvenientWhereMethodsTest.php +++ b/tests/Integration/Database/ConvenientWhereMethodsTest.php @@ -4,6 +4,7 @@ namespace Tests\Tempest\Integration\Database; +use InvalidArgumentException; use Tempest\Database\Builder\WhereOperator; use Tempest\Database\IsDatabaseModel; use Tempest\Database\MigratesUp; @@ -363,7 +364,7 @@ public function test_chaining_or_conditions(): void public function test_where_in_throws_exception_for_invalid_value(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('IN operator requires an array of values'); query(User::class) @@ -374,7 +375,7 @@ public function test_where_in_throws_exception_for_invalid_value(): void public function test_where_between_throws_exception_for_invalid_array(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('BETWEEN operator requires an array with exactly 2 values'); query(User::class) @@ -385,7 +386,7 @@ public function test_where_between_throws_exception_for_invalid_array(): void public function test_where_between_throws_exception_for_too_many_values(): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('BETWEEN operator requires an array with exactly 2 values'); query(User::class) diff --git a/tests/Integration/Database/GenericDatabaseTest.php b/tests/Integration/Database/GenericDatabaseTest.php index a8a257101..8ca68639f 100644 --- a/tests/Integration/Database/GenericDatabaseTest.php +++ b/tests/Integration/Database/GenericDatabaseTest.php @@ -65,9 +65,9 @@ public function test_query_with_semicolons(): void $db = $this->container->get(Database::class); $db->execute( new Query(<<assertSame(1, query(Publisher::class)->count()->execute()); diff --git a/tests/Integration/Database/ModelInspector/BelongsToTest.php b/tests/Integration/Database/ModelInspector/BelongsToTest.php index 11ca41900..0cf57fd75 100644 --- a/tests/Integration/Database/ModelInspector/BelongsToTest.php +++ b/tests/Integration/Database/ModelInspector/BelongsToTest.php @@ -256,10 +256,10 @@ final class SelfReferencingCategoryModel public string $name; - #[BelongsTo(ownerJoin: 'parent_id', relationJoin: 'id')] + #[BelongsTo(relationJoin: 'id', ownerJoin: 'parent_id')] public ?SelfReferencingCategoryModel $parent = null; - #[BelongsTo(ownerJoin: 'category_parent_id', relationJoin: 'id')] + #[BelongsTo(relationJoin: 'id', ownerJoin: 'category_parent_id')] public ?SelfReferencingCategoryModel $parentWithCustomOwnerJoin = null; /** @var \Tests\Tempest\Integration\Database\ModelInspector\SelfReferencingCategoryModel[] */ diff --git a/tests/Integration/Database/QueryStatements/CompoundStatementTest.php b/tests/Integration/Database/QueryStatements/CompoundStatementTest.php index ad98a5e17..6090a01d4 100644 --- a/tests/Integration/Database/QueryStatements/CompoundStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CompoundStatementTest.php @@ -18,9 +18,9 @@ public function test_it_can_compile_create_enum_type_statement(): void $this->assertSame( <<compile(DatabaseDialect::SQLITE), ); } diff --git a/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php b/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php index 3fa2f5928..f8dddf12f 100644 --- a/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php +++ b/tests/Integration/Database/QueryStatements/CreateEnumTypeStatementTest.php @@ -16,8 +16,8 @@ enumClass: CreateEnumTypeStatementTestEnumForCreateTable::class, $this->assertSame( <<compile(DatabaseDialect::POSTGRESQL), ); } diff --git a/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php b/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php index 83a0fccd0..191efae8a 100644 --- a/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php +++ b/tests/Integration/Database/QueryStatements/DropEnumTypeStatementTest.php @@ -16,8 +16,8 @@ enumClass: DropEnumTypeStatementTestEnumForCreateTable::class, $this->assertSame( <<compile(DatabaseDialect::POSTGRESQL), ); } diff --git a/tests/Integration/EventBus/EventBusTesterTest.php b/tests/Integration/EventBus/EventBusTesterTest.php index 1c4c41900..e20a7ec39 100644 --- a/tests/Integration/EventBus/EventBusTesterTest.php +++ b/tests/Integration/EventBus/EventBusTesterTest.php @@ -56,14 +56,10 @@ public function assert_dispatched_with_callback(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch('event-bus-fake-event'); - $this->eventBus->assertDispatched('event-bus-fake-event', function (string $event) { - return $event === 'event-bus-fake-event'; - }); + $this->eventBus->assertDispatched('event-bus-fake-event', fn (string $event) => $event === 'event-bus-fake-event'); $this->bus->dispatch(new FakeEvent('foo')); - $this->eventBus->assertDispatched(FakeEvent::class, function (FakeEvent $event) { - return $event->value === 'foo'; - }); + $this->eventBus->assertDispatched(FakeEvent::class, fn (FakeEvent $event) => $event->value === 'foo'); } #[Test] @@ -108,9 +104,7 @@ public function assert_dispatched_with_callback_failure(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch('event-bus-fake-event'); - $this->eventBus->assertDispatched('event-bus-fake-event', function (string $event) { - return $event !== 'event-bus-fake-event'; - }); + $this->eventBus->assertDispatched('event-bus-fake-event', fn (string $event) => $event !== 'event-bus-fake-event'); } #[Test] @@ -122,9 +116,7 @@ public function assert_dispatched_object_with_callback_failure(): void $this->eventBus->preventEventHandling(); $this->bus->dispatch(new FakeEvent('foo')); - $this->eventBus->assertDispatched(FakeEvent::class, function (FakeEvent $event) { - return $event->value === 'foobar'; - }); + $this->eventBus->assertDispatched(FakeEvent::class, fn (FakeEvent $event) => $event->value === 'foobar'); } #[Test] diff --git a/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php b/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php index 7be91e7e8..ad74ad792 100644 --- a/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php +++ b/tests/Integration/Framework/Commands/MetaViewComponentCommandTest.php @@ -29,33 +29,33 @@ public function test_show_meta_for_view_component(): void ->assertSee('x-view-component-with-named-slots.view.php') ->assertSee('"name": "x-view-component-with-named-slots",') ->assertSee(<<<'JSON' - "variables": [ - { - "type": "string", - "name": "$title", - "attributeName": "title", - "description": null - }, - { - "type": "\\Tests\\Tempest\\Fixtures\\Modules\\Books\\Models\\Book", - "name": "$book", - "attributeName": "book", - "description": "Any kind of book will work" - }, - { - "type": "string", - "name": "$dataFoo", - "attributeName": "data-foo", - "description": null - } - ] - JSON) + "variables": [ + { + "type": "string", + "name": "$title", + "attributeName": "title", + "description": null + }, + { + "type": "\\Tests\\Tempest\\Fixtures\\Modules\\Books\\Models\\Book", + "name": "$book", + "attributeName": "book", + "description": "Any kind of book will work" + }, + { + "type": "string", + "name": "$dataFoo", + "attributeName": "data-foo", + "description": null + } + ] + JSON) ->assertSee(<<<'JSON' - "slots": [ - "default", - "foo", - "bar" - ], - JSON); + "slots": [ + "default", + "foo", + "bar" + ], + JSON); } } diff --git a/tests/Integration/FrameworkIntegrationTestCase.php b/tests/Integration/FrameworkIntegrationTestCase.php index 87ce6e656..6a1c91959 100644 --- a/tests/Integration/FrameworkIntegrationTestCase.php +++ b/tests/Integration/FrameworkIntegrationTestCase.php @@ -60,12 +60,10 @@ protected function assertSnippetsMatch(string $expected, string $actual): void protected function assertSameWithoutBackticks(Stringable|string $expected, Stringable|string $actual): void { - $clean = function (string $string): string { - return str($string) - ->replace('`', '') - ->replaceRegex('/AS \"(?.*?)\"/', fn (array $matches) => "AS {$matches['alias']}") - ->toString(); - }; + $clean = fn (string $string): string => str($string) + ->replace('`', '') + ->replaceRegex('/AS \"(?.*?)\"/', fn (array $matches) => "AS {$matches['alias']}") + ->toString(); $this->assertSame( $clean((string) $expected), diff --git a/tests/Integration/Http/CleanupSessionsCommandTest.php b/tests/Integration/Http/CleanupSessionsCommandTest.php index ded6c52a9..982297fb4 100644 --- a/tests/Integration/Http/CleanupSessionsCommandTest.php +++ b/tests/Integration/Http/CleanupSessionsCommandTest.php @@ -28,8 +28,8 @@ public function destroy_sessions(): void $clock = $this->clock('2024-01-01 00:00:00'); $this->container->config(new FileSessionConfig( - path: 'tests/sessions', expiration: Duration::seconds(10), + path: 'tests/sessions', )); $sessionManager = $this->container->get(SessionManager::class); diff --git a/tests/Integration/Http/DatabaseSessionTest.php b/tests/Integration/Http/DatabaseSessionTest.php index 17cb0457d..f6315c2a4 100644 --- a/tests/Integration/Http/DatabaseSessionTest.php +++ b/tests/Integration/Http/DatabaseSessionTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\Attributes\Test; use Tempest\Clock\Clock; use Tempest\Database\Migrations\CreateMigrationsTable; +use Tempest\DateTime\DateTime; use Tempest\DateTime\Duration; use Tempest\Http\Session\Config\DatabaseSessionConfig; use Tempest\Http\Session\Installer\CreateSessionsTable; @@ -270,7 +271,7 @@ private function assertSessionDataInDatabase(SessionId $sessionId, array $data): } } - private function getSessionLastActiveTimestamp(SessionId $sessionId): \Tempest\DateTime\DateTime + private function getSessionLastActiveTimestamp(SessionId $sessionId): DateTime { $session = query(DatabaseSession::class) ->select() diff --git a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php index 653695a58..2b7cde3b9 100644 --- a/tests/Integration/Http/Exceptions/ExceptionRendererTest.php +++ b/tests/Integration/Http/Exceptions/ExceptionRendererTest.php @@ -201,9 +201,7 @@ private function callExceptionHandler(Closure $callback): void } } -final class CustomValidationException extends Exception -{ -} +final class CustomValidationException extends Exception {} #[Priority(Priority::HIGH)] final readonly class CustomJsonValidationRenderer implements ExceptionRenderer diff --git a/tests/Integration/Http/FileSessionTest.php b/tests/Integration/Http/FileSessionTest.php index eb87ddb83..2e624e4f8 100644 --- a/tests/Integration/Http/FileSessionTest.php +++ b/tests/Integration/Http/FileSessionTest.php @@ -45,8 +45,8 @@ protected function configure(): void $this->container->get(FrameworkKernel::class)->internalStorage = realpath($this->path); $this->container->config(new FileSessionConfig( - path: 'sessions', expiration: Duration::hours(2), + path: 'sessions', )); $this->container->singleton(SessionManager::class, fn () => new FileSessionManager( @@ -160,8 +160,8 @@ public function is_valid_checks_expiration(): void $clock = $this->clock('2025-01-01 00:00:00'); $this->container->config(new FileSessionConfig( - path: 'test_sessions', expiration: Duration::seconds(10), + path: 'test_sessions', )); $session = $this->manager->getOrCreate(new SessionId('expiration_test')); @@ -185,8 +185,8 @@ public function delete_expired_sessions_removes_old_files(): void $clock = $this->clock('2023-01-01 00:00:00'); $this->container->config(new FileSessionConfig( - path: 'test_sessions', expiration: Duration::minutes(30), + path: 'test_sessions', )); $active = $this->manager->getOrCreate(new SessionId('active')); diff --git a/tests/Integration/Http/SessionFromCookieTest.php b/tests/Integration/Http/SessionFromCookieTest.php index 50f009dea..7e3b8a639 100644 --- a/tests/Integration/Http/SessionFromCookieTest.php +++ b/tests/Integration/Http/SessionFromCookieTest.php @@ -18,8 +18,8 @@ final class SessionFromCookieTest extends FrameworkIntegrationTestCase public function test_resolving_session_from_cookie(): void { $this->container->config(new FileSessionConfig( - path: 'test_sessions', expiration: Duration::hours(2), + path: 'test_sessions', )); $cookieManager = $this->container->get(CookieManager::class); @@ -38,8 +38,8 @@ public function test_cookie_expiration(): void $clock = $this->clock('2023-01-01 00:00:00'); $this->container->config(new FileSessionConfig( - path: 'test_sessions', expiration: Duration::second(), + path: 'test_sessions', )); // Resolve the session so that the ID is set diff --git a/tests/Integration/Icon/IconTest.php b/tests/Integration/Icon/IconTest.php index a5b040b79..5ad73e2c3 100644 --- a/tests/Integration/Icon/IconTest.php +++ b/tests/Integration/Icon/IconTest.php @@ -14,6 +14,7 @@ use Tempest\Http\Status; use Tempest\HttpClient\HttpClient; use Tempest\Icon; +use Tempest\Icon\IconCache; use Tempest\Icon\IconConfig; use Tempest\Icon\IconDownloaded; use Tempest\Icon\IconDownloadFailed; @@ -68,7 +69,7 @@ public function test_failure_retry_after(): void serverHits: $this->exactly(2), ); - $iconCache = $this->container->get(Icon\IconCache::class); + $iconCache = $this->container->get(IconCache::class); $icon = $this->container->get(Icon\Icon::class); // first fetch, we cache the failure @@ -136,7 +137,7 @@ private function registerMocks( $this->container->register(HttpClient::class, fn () => $mockHttpClient); - $this->container->singleton(Icon\IconCache::class, new Icon\IconCache( + $this->container->singleton(IconCache::class, new IconCache( enabled: true, pool: new ArrayAdapter(clock: $clock?->toPsrClock()), )); diff --git a/tests/Integration/Intl/FunctionsTest.php b/tests/Integration/Intl/FunctionsTest.php index 2a6ec3e5f..fe8524d46 100644 --- a/tests/Integration/Intl/FunctionsTest.php +++ b/tests/Integration/Intl/FunctionsTest.php @@ -7,6 +7,7 @@ use Countable; use PHPUnit\Framework\Attributes\TestWith; use Tempest\Intl; +use Tempest\Intl\Locale; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; /** @@ -48,6 +49,6 @@ public function test_pluralize_last_word(): void public function test_current_locale(): void { - $this->assertSame(Intl\Locale::ENGLISH_UNITED_STATES, Intl\current_locale()); + $this->assertSame(Locale::ENGLISH_UNITED_STATES, Intl\current_locale()); } } diff --git a/tests/Integration/KeyValue/RedisTest.php b/tests/Integration/KeyValue/RedisTest.php index 2a756ba19..009c0390b 100644 --- a/tests/Integration/KeyValue/RedisTest.php +++ b/tests/Integration/KeyValue/RedisTest.php @@ -29,7 +29,7 @@ protected function configure(): void try { $this->redis->connect(); - } catch (\Throwable) { + } catch (Throwable) { $this->markTestSkipped('Could not connect to Redis.'); } } diff --git a/tests/Integration/Mailer/SentEmailTest.php b/tests/Integration/Mailer/SentEmailTest.php index 79e4b0168..39d396cb9 100644 --- a/tests/Integration/Mailer/SentEmailTest.php +++ b/tests/Integration/Mailer/SentEmailTest.php @@ -68,10 +68,11 @@ public function test_with_default_sender(): void public function test_send_to_address_vo(): void { - $this->sendTestEmail( - to: [new EmailAddress('recipient1@example.com', 'Jon Doe'), 'recipient2@example.com'], - from: 'no-reply@tempestphp.com', - ) + $this + ->sendTestEmail( + to: [new EmailAddress('recipient1@example.com', 'Jon Doe'), 'recipient2@example.com'], + from: 'no-reply@tempestphp.com', + ) ->assertSentTo('recipient1@example.com') ->assertSentTo('recipient2@example.com'); } @@ -89,10 +90,11 @@ public function test_send_to_address_with_brackets(): void public function test_assert_sent_to(): void { - $this->sendTestEmail( - to: ['recipient1@example.com', 'recipient2@example.com'], - from: 'no-reply@tempestphp.com', - ) + $this + ->sendTestEmail( + to: ['recipient1@example.com', 'recipient2@example.com'], + from: 'no-reply@tempestphp.com', + ) ->assertSentTo('recipient1@example.com') ->assertSentTo('recipient2@example.com') ->assertSentTo(['recipient1@example.com', 'recipient2@example.com']) @@ -205,12 +207,12 @@ private function sendTestEmail( $content = match (true) { $html instanceof View => $html, $html !== null => << - -

{$html}

- - - HTML_WRAP, + + +

{$html}

+ + + HTML_WRAP, $text !== null => $text, default => 'Hello Jon in Text', }; diff --git a/tests/Integration/Mapper/MapperContextTest.php b/tests/Integration/Mapper/MapperContextTest.php index 66f58e237..46117d97a 100644 --- a/tests/Integration/Mapper/MapperContextTest.php +++ b/tests/Integration/Mapper/MapperContextTest.php @@ -6,6 +6,12 @@ use PHPUnit\Framework\Attributes\TestWith; use Tempest\Core\Priority; use Tempest\Mapper; +use Tempest\Mapper\Caster; +use Tempest\Mapper\CasterFactory; +use Tempest\Mapper\DynamicCaster; +use Tempest\Mapper\DynamicSerializer; +use Tempest\Mapper\Serializer; +use Tempest\Mapper\SerializerFactory; use Tempest\Reflection\PropertyReflector; use Tempest\Reflection\TypeReflector; use Tests\Tempest\Fixtures\Modules\Books\Models\Author; @@ -36,8 +42,8 @@ public function uses_serializers_from_given_context(mixed $context): void name: 'test', ); - $factory = $this->container->get(Mapper\SerializerFactory::class); - $factory->addSerializer(CustomStringSerializer::class, context: $context, priority: Priority::HIGHEST); + $factory = $this->container->get(SerializerFactory::class); + $factory->addSerializer(CustomStringSerializer::class, priority: Priority::HIGHEST, context: $context); $serialized = Mapper\map($author) ->in($context) @@ -51,7 +57,7 @@ public function uses_serializers_from_given_context(mixed $context): void #[TestWith([TestMapperContextEnum::VALUE], name: 'enum')] public function uses_casters_from_given_context(mixed $context): void { - $factory = $this->container->get(Mapper\CasterFactory::class); + $factory = $this->container->get(CasterFactory::class); $factory->addCaster(CustomStringSerializer::class, context: $context); $author = Mapper\make(Author::class) @@ -64,7 +70,7 @@ public function uses_casters_from_given_context(mixed $context): void } } -final readonly class CustomStringSerializer implements Mapper\Serializer, Mapper\Caster, Mapper\DynamicSerializer, Mapper\DynamicCaster +final readonly class CustomStringSerializer implements Serializer, Caster, DynamicSerializer, DynamicCaster { public static function accepts(PropertyReflector|TypeReflector $input): bool { diff --git a/tests/Integration/Process/ProcessTesterAssertNotRanTest.php b/tests/Integration/Process/ProcessTesterAssertNotRanTest.php index 61e992a6a..03a6e07b2 100644 --- a/tests/Integration/Process/ProcessTesterAssertNotRanTest.php +++ b/tests/Integration/Process/ProcessTesterAssertNotRanTest.php @@ -30,10 +30,10 @@ public function test_succeeds_with_callback_when_other_commands_ran(): void $this->process->mockProcessResult('echo *', 'hello'); $this->executor->run('echo "hello"'); - $this->process->assertCommandDidNotRun(function (PendingProcess $process) { + $this->process->assertCommandDidNotRun( // this returns false, so expectation succeeds - return $process->command === 'echo "world"'; - }); + fn (PendingProcess $process) => $process->command === 'echo "world"', + ); } public function test_fails_with_callback_when_returning_false(): void @@ -44,9 +44,9 @@ public function test_fails_with_callback_when_returning_false(): void $this->process->mockProcessResult('echo *', 'hello'); $this->executor->run('echo "hello"'); - $this->process->assertCommandDidNotRun(function (PendingProcess $process) { + $this->process->assertCommandDidNotRun( // this returns true, so expectation fails - return $process->command === 'echo "hello"'; - }); + fn (PendingProcess $process) => $process->command === 'echo "hello"', + ); } } diff --git a/tests/Integration/Process/ProcessTesterAssertRanTest.php b/tests/Integration/Process/ProcessTesterAssertRanTest.php index 3e0472bec..0048d2e74 100644 --- a/tests/Integration/Process/ProcessTesterAssertRanTest.php +++ b/tests/Integration/Process/ProcessTesterAssertRanTest.php @@ -29,9 +29,7 @@ public function test_expectation_succeeds_when_command_is_ran_and_callback_retur { $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', function (ProcessResult $result) { - return $result->output === "hello\n"; - }); + $this->process->assertCommandRan('echo *', fn (ProcessResult $result) => $result->output === "hello\n"); } public function test_expectation_fails_when_specified_command_is_not_ran(): void @@ -51,9 +49,7 @@ public function test_expectation_fails_when_command_is_ran_and_callback_returns_ $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertCommandRan('echo *', function (ProcessResult $result) { - return $result->output !== "hello\n"; - }); + $this->process->assertCommandRan('echo *', fn (ProcessResult $result) => $result->output !== "hello\n"); } public function test_expectation_succeeds_when_callback_returns_nothing(): void @@ -68,9 +64,7 @@ public function test_expectation_succeeds_when_callback_returns_true(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(function (PendingProcess $process): bool { - return $process->command === 'echo "hello"'; - }); + $this->process->assertRan(fn (PendingProcess $process): bool => $process->command === 'echo "hello"'); } public function test_returning_false_from_callback_fails_expectation(): void @@ -81,9 +75,7 @@ public function test_returning_false_from_callback_fails_expectation(): void $this->process->mockProcessResult('echo *', "hello\n"); $this->executor->run('echo "hello"'); - $this->process->assertRan(function (PendingProcess $_process): bool { - return false; - }); + $this->process->assertRan(fn (PendingProcess $_process): bool => false); } public function test_returning_true_from_callback_skips_other_iterations(): void diff --git a/tests/Integration/Validator/TranslationKeyTest.php b/tests/Integration/Validator/TranslationKeyTest.php index 52bafe0ed..20de2461e 100644 --- a/tests/Integration/Validator/TranslationKeyTest.php +++ b/tests/Integration/Validator/TranslationKeyTest.php @@ -7,6 +7,7 @@ use Tempest\Intl\Locale; use Tempest\Validation\Exceptions\ValidationFailed; use Tempest\Validation\Rules; +use Tempest\Validation\Rules\HasLength; use Tempest\Validation\TranslationKey; use Tempest\Validation\Validator; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; @@ -35,7 +36,7 @@ public function translates_property_key(): void final class ValidatableObject { public function __construct( - #[Rules\HasLength(min: 5, max: 50)] + #[HasLength(min: 5, max: 50)] #[TranslationKey('book_title')] public string $title, ) {} diff --git a/tests/Integration/Validator/TranslationsTest.php b/tests/Integration/Validator/TranslationsTest.php index e2e0691e8..1553cba1e 100644 --- a/tests/Integration/Validator/TranslationsTest.php +++ b/tests/Integration/Validator/TranslationsTest.php @@ -6,6 +6,55 @@ use Tempest\DateTime\FormatPattern; use Tempest\Validation\Rule; use Tempest\Validation\Rules; +use Tempest\Validation\Rules\DoesNotEndWith; +use Tempest\Validation\Rules\DoesNotStartWith; +use Tempest\Validation\Rules\EndsWith; +use Tempest\Validation\Rules\Exists; +use Tempest\Validation\Rules\HasCount; +use Tempest\Validation\Rules\HasDateTimeFormat; +use Tempest\Validation\Rules\HasLength; +use Tempest\Validation\Rules\IsAfterDate; +use Tempest\Validation\Rules\IsAlpha; +use Tempest\Validation\Rules\IsAlphaNumeric; +use Tempest\Validation\Rules\IsArrayList; +use Tempest\Validation\Rules\IsBeforeDate; +use Tempest\Validation\Rules\IsBetween; +use Tempest\Validation\Rules\IsBetweenDates; +use Tempest\Validation\Rules\IsBoolean; +use Tempest\Validation\Rules\IsDivisibleBy; +use Tempest\Validation\Rules\IsEmail; +use Tempest\Validation\Rules\IsEnum; +use Tempest\Validation\Rules\IsEvenNumber; +use Tempest\Validation\Rules\IsFalsy; +use Tempest\Validation\Rules\IsFloat; +use Tempest\Validation\Rules\IsHexColor; +use Tempest\Validation\Rules\IsIn; +use Tempest\Validation\Rules\IsInteger; +use Tempest\Validation\Rules\IsIP; +use Tempest\Validation\Rules\IsIPv4; +use Tempest\Validation\Rules\IsIPv6; +use Tempest\Validation\Rules\IsJsonString; +use Tempest\Validation\Rules\IsLowercase; +use Tempest\Validation\Rules\IsMacAddress; +use Tempest\Validation\Rules\IsMultipleOf; +use Tempest\Validation\Rules\IsNotEmptyString; +use Tempest\Validation\Rules\IsNotIn; +use Tempest\Validation\Rules\IsNotNull; +use Tempest\Validation\Rules\IsNumeric; +use Tempest\Validation\Rules\IsOddNumber; +use Tempest\Validation\Rules\IsPassword; +use Tempest\Validation\Rules\IsPhoneNumber; +use Tempest\Validation\Rules\IsString; +use Tempest\Validation\Rules\IsTime; +use Tempest\Validation\Rules\IsTimezone; +use Tempest\Validation\Rules\IsTruthy; +use Tempest\Validation\Rules\IsUlid; +use Tempest\Validation\Rules\IsUnixTimestamp; +use Tempest\Validation\Rules\IsUppercase; +use Tempest\Validation\Rules\IsUrl; +use Tempest\Validation\Rules\IsUuid; +use Tempest\Validation\Rules\MatchesRegEx; +use Tempest\Validation\Rules\StartsWith; use Tempest\Validation\Validator; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; @@ -29,12 +78,12 @@ public function test_after_date(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be after or equal to January 1, 2024', $field, expected: 'Date'), - actual: $this->translate(new Rules\IsAfterDate(date: '2024-01-01', inclusive: true), field: $field), + actual: $this->translate(new IsAfterDate(date: '2024-01-01', inclusive: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be after January 1, 2024', $field, expected: 'Date'), - actual: $this->translate(new Rules\IsAfterDate(date: '2024-01-01', inclusive: false), field: $field), + actual: $this->translate(new IsAfterDate(date: '2024-01-01', inclusive: false), field: $field), ); } @@ -44,12 +93,12 @@ public function test_before_date(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a date before or equal to January 1, 2024', $field, expected: 'Date'), - actual: $this->translate(new Rules\IsBeforeDate(date: '2024-01-01', inclusive: true), field: $field), + actual: $this->translate(new IsBeforeDate(date: '2024-01-01', inclusive: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a date before January 1, 2024', $field, expected: 'Date'), - actual: $this->translate(new Rules\IsBeforeDate(date: '2024-01-01', inclusive: false), field: $field), + actual: $this->translate(new IsBeforeDate(date: '2024-01-01', inclusive: false), field: $field), ); } @@ -59,12 +108,12 @@ public function test_between_dates(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a date between January 1, 2024 and January 1, 2025, included', $field, expected: 'Date'), - actual: $this->translate(new Rules\IsBetweenDates(first: '2024-01-01', second: '2025-01-01', inclusive: true), field: $field), + actual: $this->translate(new IsBetweenDates(first: '2024-01-01', second: '2025-01-01', inclusive: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a date between January 1, 2024 and January 1, 2025', $field, expected: 'Date'), - actual: $this->translate(new Rules\IsBetweenDates(first: '2024-01-01', second: '2025-01-01'), field: $field), + actual: $this->translate(new IsBetweenDates(first: '2024-01-01', second: '2025-01-01'), field: $field), ); } @@ -74,7 +123,7 @@ public function test_alpha(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must contain only alphabetic characters', $field), - actual: $this->translate(new Rules\IsAlpha(), field: $field), + actual: $this->translate(new IsAlpha(), field: $field), ); } @@ -84,7 +133,7 @@ public function test_alpha_numeric(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must contain only alphanumeric characters', $field), - actual: $this->translate(new Rules\IsAlphaNumeric(), field: $field), + actual: $this->translate(new IsAlphaNumeric(), field: $field), ); } @@ -94,7 +143,7 @@ public function test_array_list(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a list', $field), - actual: $this->translate(new Rules\IsArrayList(), field: $field), + actual: $this->translate(new IsArrayList(), field: $field), ); } @@ -104,12 +153,12 @@ public function test_between(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be between 0 and 2', $field, expected: 'Number'), - actual: $this->translate(new Rules\IsBetween(min: 0, max: 2), field: $field), + actual: $this->translate(new IsBetween(min: 0, max: 2), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be between 2 and 4', $field, expected: 'Number'), - actual: $this->translate(new Rules\IsBetween(min: 2, max: 4), field: $field), + actual: $this->translate(new IsBetween(min: 2, max: 4), field: $field), ); } @@ -119,27 +168,27 @@ public function test_count(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must have at least 3 items', $field), - actual: $this->translate(new Rules\HasCount(min: 3), field: $field), + actual: $this->translate(new HasCount(min: 3), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must have at least 0 items', $field), - actual: $this->translate(new Rules\HasCount(min: 0), field: $field), + actual: $this->translate(new HasCount(min: 0), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must have at most 10 items', $field), - actual: $this->translate(new Rules\HasCount(max: 10), field: $field), + actual: $this->translate(new HasCount(max: 10), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must have between 3 and 10 items', $field), - actual: $this->translate(new Rules\HasCount(min: 3, max: 10), field: $field), + actual: $this->translate(new HasCount(min: 3, max: 10), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must have between 0 and 2 items', $field), - actual: $this->translate(new Rules\HasCount(min: 0, max: 2), field: $field), + actual: $this->translate(new HasCount(min: 0, max: 2), field: $field), ); } @@ -149,12 +198,12 @@ public function test_date_time_format(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must use the format yyyy-MM-dd', $field), - actual: $this->translate(new Rules\HasDateTimeFormat('yyyy-MM-dd'), field: $field), + actual: $this->translate(new HasDateTimeFormat('yyyy-MM-dd'), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must use the format MM/dd/yyyy', $field), - actual: $this->translate(new Rules\HasDateTimeFormat(FormatPattern::AMERICAN), field: $field), + actual: $this->translate(new HasDateTimeFormat(FormatPattern::AMERICAN), field: $field), ); } @@ -164,7 +213,7 @@ public function test_divisible_by(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be divisible by 1', $field, expected: 'Number'), - actual: $this->translate(new Rules\IsDivisibleBy(divisor: 1), field: $field), + actual: $this->translate(new IsDivisibleBy(divisor: 1), field: $field), ); } @@ -174,7 +223,7 @@ public function test_does_not_end_with(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must not end with "foo"', $field), - actual: $this->translate(new Rules\DoesNotEndWith(needle: 'foo'), field: $field), + actual: $this->translate(new DoesNotEndWith(needle: 'foo'), field: $field), ); } @@ -184,7 +233,7 @@ public function test_email(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid email address', $field, expected: 'Email'), - actual: $this->translate(new Rules\IsEmail(), field: $field), + actual: $this->translate(new IsEmail(), field: $field), ); } @@ -194,7 +243,7 @@ public function test_does_not_start_with(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must not start with "foo"', $field), - actual: $this->translate(new Rules\DoesNotStartWith(needle: 'foo'), field: $field), + actual: $this->translate(new DoesNotStartWith(needle: 'foo'), field: $field), ); } @@ -204,7 +253,7 @@ public function test_ends_with(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must end with "foo"', $field), - actual: $this->translate(new Rules\EndsWith(needle: 'foo'), field: $field), + actual: $this->translate(new EndsWith(needle: 'foo'), field: $field), ); } @@ -214,7 +263,7 @@ public function test_exists(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s could not be found', $field), - actual: $this->translate(new Rules\Exists(table: 'non-existing-table', column: 'non-existing-column'), field: $field), + actual: $this->translate(new Exists(table: 'non-existing-table', column: 'non-existing-column'), field: $field), ); } @@ -224,7 +273,7 @@ public function test_even(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be even', $field, expected: 'Number'), - actual: $this->translate(new Rules\IsEvenNumber(), field: $field), + actual: $this->translate(new IsEvenNumber(), field: $field), ); } @@ -234,7 +283,7 @@ public function test_hex_color(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a hexadecimal color', $field), - actual: $this->translate(new Rules\IsHexColor(), field: $field), + actual: $this->translate(new IsHexColor(), field: $field), ); } @@ -244,17 +293,17 @@ public function test_in(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a', $field), - actual: $this->translate(new Rules\IsIn(['a']), field: $field), + actual: $this->translate(new IsIn(['a']), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a or b', $field), - actual: $this->translate(new Rules\IsIn(['a', 'b']), field: $field), + actual: $this->translate(new IsIn(['a', 'b']), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a, b or c', $field), - actual: $this->translate(new Rules\IsIn(['a', 'b', 'c']), field: $field), + actual: $this->translate(new IsIn(['a', 'b', 'c']), field: $field), ); } @@ -267,9 +316,9 @@ public function test_in(?string $field = null): void public function test_ip(string $ip, ?string $field = null): void { $class = match ($ip) { - 'IPv4' => Rules\IsIPv4::class, - 'IPv6' => Rules\IsIPv6::class, - default => Rules\IsIP::class, + 'IPv4' => IsIPv4::class, + 'IPv6' => IsIPv6::class, + default => IsIP::class, }; $this->assertSame( @@ -299,12 +348,12 @@ public function test_is_boolean(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a boolean', $field), - actual: $this->translate(new Rules\IsBoolean(), field: $field), + actual: $this->translate(new IsBoolean(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a boolean if specified', $field), - actual: $this->translate(new Rules\IsBoolean(orNull: true), field: $field), + actual: $this->translate(new IsBoolean(orNull: true), field: $field), ); } @@ -314,22 +363,22 @@ public function test_is_enum(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be FOO, BAR or BAZ', $field), - actual: $this->translate(new Rules\IsEnum(UnitEnumFixture::class), field: $field), + actual: $this->translate(new IsEnum(UnitEnumFixture::class), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be FOO or BAZ', $field), - actual: $this->translate(new Rules\IsEnum(UnitEnumFixture::class, except: [UnitEnumFixture::BAR]), field: $field), + actual: $this->translate(new IsEnum(UnitEnumFixture::class, except: [UnitEnumFixture::BAR]), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be foo, bar or baz', $field), - actual: $this->translate(new Rules\IsEnum(BackedEnumFixture::class), field: $field), + actual: $this->translate(new IsEnum(BackedEnumFixture::class), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be foo or baz', $field), - actual: $this->translate(new Rules\IsEnum(BackedEnumFixture::class, except: [BackedEnumFixture::BAR]), field: $field), + actual: $this->translate(new IsEnum(BackedEnumFixture::class, except: [BackedEnumFixture::BAR]), field: $field), ); } @@ -339,12 +388,12 @@ public function test_is_float(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a floating point number', $field), - actual: $this->translate(new Rules\IsFloat(), field: $field), + actual: $this->translate(new IsFloat(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a floating point number if specified', $field), - actual: $this->translate(new Rules\IsFloat(orNull: true), field: $field), + actual: $this->translate(new IsFloat(orNull: true), field: $field), ); } @@ -354,12 +403,12 @@ public function test_is_integer(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a number', $field), - actual: $this->translate(new Rules\IsInteger(), field: $field), + actual: $this->translate(new IsInteger(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a number if specified', $field), - actual: $this->translate(new Rules\IsInteger(orNull: true), field: $field), + actual: $this->translate(new IsInteger(orNull: true), field: $field), ); } @@ -369,12 +418,12 @@ public function test_is_string(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a string', $field), - actual: $this->translate(new Rules\IsString(), field: $field), + actual: $this->translate(new IsString(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a string or be empty', $field), - actual: $this->translate(new Rules\IsString(orNull: true), field: $field), + actual: $this->translate(new IsString(orNull: true), field: $field), ); } @@ -384,7 +433,7 @@ public function test_is_json(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid JSON string', $field), - actual: $this->translate(new Rules\IsJsonString(), field: $field), + actual: $this->translate(new IsJsonString(), field: $field), ); } @@ -394,17 +443,17 @@ public function test_length(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be at least 0', $field), - actual: $this->translate(new Rules\HasLength(min: 0), field: $field), + actual: $this->translate(new HasLength(min: 0), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be at most 0', $field), - actual: $this->translate(new Rules\HasLength(max: 0), field: $field), + actual: $this->translate(new HasLength(max: 0), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be between 0 and 2', $field), - actual: $this->translate(new Rules\HasLength(min: 0, max: 2), field: $field), + actual: $this->translate(new HasLength(min: 0, max: 2), field: $field), ); } @@ -414,7 +463,7 @@ public function test_lowercase(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a lowercase string', $field), - actual: $this->translate(new Rules\IsLowercase(), field: $field), + actual: $this->translate(new IsLowercase(), field: $field), ); } @@ -424,7 +473,7 @@ public function test_mac_address(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid MAC address', $field), - actual: $this->translate(new Rules\IsMacAddress(), field: $field), + actual: $this->translate(new IsMacAddress(), field: $field), ); } @@ -434,7 +483,7 @@ public function test_multiple_of(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a multiple of 5', $field, expected: 'Number'), - actual: $this->translate(new Rules\IsMultipleOf(divisor: 5), field: $field), + actual: $this->translate(new IsMultipleOf(divisor: 5), field: $field), ); } @@ -444,7 +493,7 @@ public function test_not_empty(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must not be empty', $field), - actual: $this->translate(new Rules\IsNotEmptyString(), field: $field), + actual: $this->translate(new IsNotEmptyString(), field: $field), ); } @@ -454,17 +503,17 @@ public function test_not_in(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must not be a', $field), - actual: $this->translate(new Rules\IsNotIn(['a']), field: $field), + actual: $this->translate(new IsNotIn(['a']), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must not be a or b', $field), - actual: $this->translate(new Rules\IsNotIn(['a', 'b']), field: $field), + actual: $this->translate(new IsNotIn(['a', 'b']), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must not be a, b or c', $field), - actual: $this->translate(new Rules\IsNotIn(['a', 'b', 'c']), field: $field), + actual: $this->translate(new IsNotIn(['a', 'b', 'c']), field: $field), ); } @@ -474,7 +523,7 @@ public function test_not_null(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be specified', $field), - actual: $this->translate(new Rules\IsNotNull(), field: $field), + actual: $this->translate(new IsNotNull(), field: $field), ); } @@ -484,7 +533,7 @@ public function test_numeric(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be numeric', $field), - actual: $this->translate(new Rules\IsNumeric(), field: $field), + actual: $this->translate(new IsNumeric(), field: $field), ); } @@ -494,7 +543,7 @@ public function test_odd(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be odd', $field, expected: 'Number'), - actual: $this->translate(new Rules\IsOddNumber(), field: $field), + actual: $this->translate(new IsOddNumber(), field: $field), ); } @@ -504,32 +553,32 @@ public function test_password(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(), field: $field), + actual: $this->translate(new IsPassword(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 4 characters', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(min: 4), field: $field), + actual: $this->translate(new IsPassword(min: 4), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one uppercase and one lowercase letter', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(mixedCase: true), field: $field), + actual: $this->translate(new IsPassword(mixedCase: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters and one number', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(numbers: true), field: $field), + actual: $this->translate(new IsPassword(numbers: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters and one symbol', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(symbols: true), field: $field), + actual: $this->translate(new IsPassword(symbols: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters and one letter', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(letters: true), field: $field), + actual: $this->translate(new IsPassword(letters: true), field: $field), ); $this->assertSame( @@ -538,42 +587,42 @@ public function test_password(?string $field = null): void $field, expected: 'Password', ), - actual: $this->translate(new Rules\IsPassword(mixedCase: true, numbers: true, symbols: true), field: $field), + actual: $this->translate(new IsPassword(mixedCase: true, numbers: true, symbols: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one uppercase and one lowercase letter, and one number', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(mixedCase: true, numbers: true), field: $field), + actual: $this->translate(new IsPassword(mixedCase: true, numbers: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one uppercase and one lowercase letter, and one symbol', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(mixedCase: true, symbols: true), field: $field), + actual: $this->translate(new IsPassword(mixedCase: true, symbols: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one number, one letter and one symbol', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(letters: true, numbers: true, symbols: true), field: $field), + actual: $this->translate(new IsPassword(numbers: true, letters: true, symbols: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one number and one letter', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(letters: true, numbers: true), field: $field), + actual: $this->translate(new IsPassword(numbers: true, letters: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one letter and one symbol', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(letters: true, symbols: true), field: $field), + actual: $this->translate(new IsPassword(letters: true, symbols: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one number and one symbol', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(numbers: true, symbols: true), field: $field), + actual: $this->translate(new IsPassword(numbers: true, symbols: true), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must contain at least 12 characters, one number and one letter', $field, expected: 'Password'), - actual: $this->translate(new Rules\IsPassword(letters: true, numbers: true), field: $field), + actual: $this->translate(new IsPassword(numbers: true, letters: true), field: $field), ); } @@ -583,7 +632,7 @@ public function test_phone_number(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a phone number', $field), - actual: $this->translate(new Rules\IsPhoneNumber(), field: $field), + actual: $this->translate(new IsPhoneNumber(), field: $field), ); } @@ -593,7 +642,7 @@ public function test_regex(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must match the pattern /[A-Z]/', $field), - actual: $this->translate(new Rules\MatchesRegEx('/[A-Z]/'), field: $field), + actual: $this->translate(new MatchesRegEx('/[A-Z]/'), field: $field), ); } @@ -603,7 +652,7 @@ public function test_should_be_false(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be false', $field), - actual: $this->translate(new Rules\IsFalsy(), field: $field), + actual: $this->translate(new IsFalsy(), field: $field), ); } @@ -613,7 +662,7 @@ public function test_should_be_true(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be true', $field), - actual: $this->translate(new Rules\IsTruthy(), field: $field), + actual: $this->translate(new IsTruthy(), field: $field), ); } @@ -623,7 +672,7 @@ public function test_starts_with(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must start with foo', $field), - actual: $this->translate(new Rules\StartsWith('foo'), field: $field), + actual: $this->translate(new StartsWith('foo'), field: $field), ); } @@ -633,12 +682,12 @@ public function test_time(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid time in 24-hour format', $field), - actual: $this->translate(new Rules\IsTime(), field: $field), + actual: $this->translate(new IsTime(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a valid time in 12-hour format', $field), - actual: $this->translate(new Rules\IsTime(false), field: $field), + actual: $this->translate(new IsTime(false), field: $field), ); } @@ -648,7 +697,7 @@ public function test_timestamp(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid timestamp', $field), - actual: $this->translate(new Rules\IsUnixTimestamp(), field: $field), + actual: $this->translate(new IsUnixTimestamp(), field: $field), ); } @@ -658,7 +707,7 @@ public function test_timezone(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid timezone', $field), - actual: $this->translate(new Rules\IsTimezone(), field: $field), + actual: $this->translate(new IsTimezone(), field: $field), ); } @@ -668,7 +717,7 @@ public function test_ulid(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a lexicographically sortable identifier', $field), - actual: $this->translate(new Rules\IsUlid(), field: $field), + actual: $this->translate(new IsUlid(), field: $field), ); } @@ -678,7 +727,7 @@ public function test_uppercase(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be an uppercase string', $field), - actual: $this->translate(new Rules\IsUppercase(), field: $field), + actual: $this->translate(new IsUppercase(), field: $field), ); } @@ -688,22 +737,22 @@ public function test_url(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a valid URL', $field), - actual: $this->translate(new Rules\IsUrl(), field: $field), + actual: $this->translate(new IsUrl(), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a URL using https', $field), - actual: $this->translate(new Rules\IsUrl(['https']), field: $field), + actual: $this->translate(new IsUrl(['https']), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a URL using https or http', $field), - actual: $this->translate(new Rules\IsUrl(['https', 'http']), field: $field), + actual: $this->translate(new IsUrl(['https', 'http']), field: $field), ); $this->assertSame( expected: $this->formatWithField('%s must be a URL using ftp, https or http', $field), - actual: $this->translate(new Rules\IsUrl(['ftp', 'https', 'http']), field: $field), + actual: $this->translate(new IsUrl(['ftp', 'https', 'http']), field: $field), ); } @@ -713,7 +762,7 @@ public function test_uuid(?string $field = null): void { $this->assertSame( expected: $this->formatWithField('%s must be a universally unique identifier', $field), - actual: $this->translate(new Rules\IsUuid(), field: $field), + actual: $this->translate(new IsUuid(), field: $field), ); } } diff --git a/tests/Integration/View/BladeViewRendererTest.php b/tests/Integration/View/BladeViewRendererTest.php index 3aec90c9c..9492407f9 100644 --- a/tests/Integration/View/BladeViewRendererTest.php +++ b/tests/Integration/View/BladeViewRendererTest.php @@ -33,10 +33,10 @@ public function test_blade(): void $html = $renderer->render(view('index')); $this->assertSame(<< - Hi - + + Hi + - HTML, $html); + HTML, $html); } } diff --git a/tests/Integration/View/Components/MarkdownComponentTest.php b/tests/Integration/View/Components/MarkdownComponentTest.php index 77faeaaf1..4bf287c90 100644 --- a/tests/Integration/View/Components/MarkdownComponentTest.php +++ b/tests/Integration/View/Components/MarkdownComponentTest.php @@ -9,8 +9,8 @@ final class MarkdownComponentTest extends FrameworkIntegrationTestCase public function test_render_markdown_as_content(): void { $html = $this->view->render(<<<'HTML' - # hi - HTML); + # hi + HTML); $this->assertSame('

hi

', $html); } @@ -18,8 +18,8 @@ public function test_render_markdown_as_content(): void public function test_render_markdown_as_variable(): void { $html = $this->view->render(<<<'HTML' - - HTML, text: '# hi'); + + HTML, text: '# hi'); $this->assertSame('

hi

', $html); } diff --git a/tests/Integration/View/ElementFactoryTest.php b/tests/Integration/View/ElementFactoryTest.php index c9f1aa76a..603fa9072 100644 --- a/tests/Integration/View/ElementFactoryTest.php +++ b/tests/Integration/View/ElementFactoryTest.php @@ -24,16 +24,16 @@ public function test_parental_relations(): void { // See https://github.com/php/php-src/issues/16960 $contents = <<<'HTML' - - - - Hello - - - - - - HTML; + + + + Hello + + + + + + HTML; $ast = TempestViewParser::ast($contents); diff --git a/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php b/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php index 57389816a..636856210 100644 --- a/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php +++ b/tests/Integration/View/TempestViewRendererCombinedExpressionsTest.php @@ -24,44 +24,44 @@ protected function setUp(): void public function test_if_with_data_expression(): void { $view = <<<'HTML' - - {{ $label }} - - - {{ $label }} - -
Nothing
- HTML; + + {{ $label }} + + + {{ $label }} + +
Nothing
+ HTML; $html = $this->view->render(view($view, href: '#', label: 'Label')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - - Label - HTML, $html); + + Label + HTML, $html); $html = $this->view->render(view($view, label: 'Label')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - - Label - HTML, $html); + + Label + HTML, $html); $html = $this->view->render(view($view)); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
Nothing
- HTML, $html); +
Nothing
+ HTML, $html); } public function test_foreach_with_if_and_else_expression(): void { $view = <<<'HTML' -
- {{ $label }} {{ $item }} -
- - No label - - HTML; +
+ {{ $label }} {{ $item }} +
+ + No label + + HTML; $html = $this->view->render(view($view, items: ['a', 'b'], label: 'Label')); $this->assertStringContainsString('Label a', $html); @@ -76,16 +76,16 @@ public function test_foreach_with_if_and_else_expression(): void public function test_foreach_with_if_and_forelse_expression(): void { $view = <<<'HTML' -
- {{ $label }} {{ $item }} -
- - No items - - - No label - - HTML; +
+ {{ $label }} {{ $item }} +
+ + No items + + + No label + + HTML; $html = $this->view->render(view($view)); $this->assertStringNotContainsString('Label a', $html); diff --git a/tests/Integration/View/TempestViewRendererDataPassingTest.php b/tests/Integration/View/TempestViewRendererDataPassingTest.php index 1bd3d479b..f9df80e92 100644 --- a/tests/Integration/View/TempestViewRendererDataPassingTest.php +++ b/tests/Integration/View/TempestViewRendererDataPassingTest.php @@ -63,8 +63,8 @@ public function test_normal_attribute_with_php_short_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://', ), ); @@ -77,8 +77,8 @@ public function test_normal_attribute_with_view_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://&', ), ); @@ -91,8 +91,8 @@ public function test_normal_attribute_with_raw_view_echo(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://&', ), ); @@ -105,8 +105,8 @@ public function test_expression_attribute_with_view_echo_not_allowed(): void $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -117,8 +117,8 @@ public function test_expression_attribute_with_raw_view_echo_not_allowed(): void $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -129,8 +129,8 @@ public function test_expression_attribute_with_short_php_echo_not_allowed(): voi $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ); } @@ -141,8 +141,8 @@ public function test_expression_attribute_with_object_without_view_component_not $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() {}, ); } @@ -154,16 +154,16 @@ public function test_expression_attribute_with_object_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() { public string $url = 'https://'; }, @@ -178,16 +178,16 @@ public function test_expression_attribute_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, href: 'https://', ), ); @@ -200,16 +200,16 @@ public function test_normal_attribute_on_view_component(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); $this->assertSame( 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, ), ); } @@ -221,8 +221,8 @@ public function test_expression_attribute_with_same_name(): void $this->view->registerViewComponent( 'x-link', <<<'HTML' - - HTML, + + HTML, ); /* There's a name collision here: @@ -237,8 +237,8 @@ public function test_expression_attribute_with_same_name(): void 'a', $this->view->render( <<<'HTML' - a - HTML, + a + HTML, object: new class() { public string $url = 'https://'; }, @@ -251,15 +251,15 @@ public function test_boolean_attributes(): void $this->assertSame( '', $this->view->render(<<<'HTML' - - HTML, value: 'value', selected: true, name: 'name'), + + HTML, value: 'value', selected: true, name: 'name'), ); $this->assertSame( '', $this->view->render(<<<'HTML' - - HTML, value: 'value', selected: false, name: 'name'), + + HTML, value: 'value', selected: false, name: 'name'), ); $this->assertSame( @@ -275,12 +275,12 @@ public function test_boolean_attributes(): void public function test_falsy_bool_attribute(mixed $value): void { $html = $this->view->render(<< - HTML, show: false); +
+ HTML, show: false); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } #[TestWith(['true'])] @@ -288,23 +288,23 @@ public function test_falsy_bool_attribute(mixed $value): void public function test_truthy_bool_attribute(mixed $value): void { $html = $this->view->render(<< - HTML, show: true); +
+ HTML, show: true); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_multiple_boolean_attribute(): void { $html = $this->view->render(<< - HTML); +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_expression_attribute_in_raw_element(): void @@ -312,20 +312,20 @@ public function test_expression_attribute_in_raw_element(): void $this->view->registerViewComponent( 'x-test', <<<'HTML' -
- HTML, +
+ HTML, ); $html = $this->view->render(<<<'HTML' - -
foo

bar

-
- HTML, language: 'php'); + +
foo

bar

+
+ HTML, language: 'php'); $this->assertSnippetsMatch( <<<'HTML' -
foo

bar

- HTML, +
foo

bar

+ HTML, $html, ); } @@ -335,31 +335,31 @@ public function test_echo_in_attributes(): void $this->assertSame( '
', $this->view->render(<< - HTML), +
+ HTML), ); $this->assertSame( '
', $this->view->render(<< - HTML), +
+ HTML), ); } public function test_boolean_attributes_in_view_component(): void { $this->view->registerViewComponent('x-test', << - -
- HTML); +
+ +
+ HTML); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertStringContainsString(' href="hi"', $html); } @@ -367,19 +367,19 @@ public function test_boolean_attributes_in_view_component(): void public function test_global_variables_are_kept(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
{{ $item }}
- HTML); +
{{ $item }}
+ HTML); $html = $this->view->render(<<<'HTML' - - - - HTML, item: 'foo'); + + + + HTML, item: 'foo'); $this->assertSnippetsMatch(<<<'HTML' -
foo
-
foo
-
foo
- HTML, $html); +
foo
+
foo
+
foo
+ HTML, $html); } } diff --git a/tests/Integration/View/TempestViewRendererTest.php b/tests/Integration/View/TempestViewRendererTest.php index cbd9aaf58..cd516aa04 100644 --- a/tests/Integration/View/TempestViewRendererTest.php +++ b/tests/Integration/View/TempestViewRendererTest.php @@ -270,9 +270,9 @@ public function test_foreach_attribute(): void { $this->assertStringEqualsStringIgnoringLineEndings( <<<'HTML' -
a
-
b
- HTML, +
a
+
b
+ HTML, $this->view->render(view('
{{ $foo }}
')->data(items: ['a', 'b'])), ); } @@ -281,39 +281,39 @@ public function test_foreach_consumes_attribute(): void { $html = $this->view->render( <<<'HTML' - - - - - -
{{ $item }}
-
- HTML, + + + + + +
{{ $item }}
+
+ HTML, items: ['a', 'b'], ); $this->assertSnippetsMatch( <<<'HTML' - - - Home - - - - - - - - - - - -
a
b
- - - - - HTML, + + + Home + + + + + + + + + + + +
a
b
+ + + + + HTML, $html, ); } @@ -322,15 +322,15 @@ public function test_forelse_attribute(): void { $this->assertSame( <<<'HTML' -
Empty
- HTML, +
Empty
+ HTML, $this->view->render(view('
{{ $foo }}
Empty
')->data(items: [])), ); $this->assertSame( <<<'HTML' -
a
- HTML, +
a
+ HTML, $this->view->render(view('
{{ $foo }}
Empty
')->data(items: ['a'])), ); } @@ -339,8 +339,8 @@ public function test_forelse_with_other_expression_attribute(): void { $this->assertSame( <<<'HTML' -
Empty
- HTML, +
Empty
+ HTML, $this->view->render('
{{ $foo }}
Empty
', items: [], data: 'test'), ); } @@ -349,14 +349,14 @@ public function test_default_slot(): void { $this->assertSnippetsMatch( <<<'HTML' -
Test
- HTML, +
Test
+ HTML, $this->view->render( <<<'HTML' - - Test - - HTML, + + Test + + HTML, ), ); } @@ -365,18 +365,18 @@ public function test_implicit_default_slot(): void { $this->assertSnippetsMatch( <<<'HTML' -
- - Test +
+ + Test -
- HTML, +
+ HTML, $this->view->render( <<<'HTML' - - Test - - HTML, + + Test + + HTML, ), ); } @@ -385,41 +385,41 @@ public function test_multiple_slots(): void { $this->assertSnippetsMatch( <<<'HTML' - injected scripts - + injected scripts + -
- - Test - - +
+ + Test + + - - Hi + + Hi -
+
- injected styles - HTML, - $this->view->render( - <<<'HTML' - - Test - - - injected scripts - - - injected styles - - - Hi - HTML, + $this->view->render( + <<<'HTML' + + Test + + + injected scripts + + + + injected styles + + + Hi + + HTML, ), ); } @@ -428,18 +428,18 @@ public function test_pre(): void { $this->assertStringEqualsStringIgnoringLineEndings( <<<'HTML' -
a
-                    b
-                c
-            
- HTML, - $this->view->render( - <<<'HTML'
a
                         b
                     c
                 
HTML, + $this->view->render( + <<<'HTML' +
a
+                            b
+                        c
+                    
+ HTML, ), ); } @@ -456,10 +456,10 @@ public function test_raw_and_escaped(): void $html = $this->view->render(view(__DIR__ . '/../../Fixtures/Views/raw-escaped.view.php', var: '

hi

')); $this->assertStringEqualsStringIgnoringLineEndings(<<<'HTML' - <h1>hi</h1> - <H1>HI</H1> -

hi

- HTML, $html); + <h1>hi</h1> + <H1>HI</H1> +

hi

+ HTML, $html); } public function test_html_string(): void @@ -468,10 +468,10 @@ public function test_html_string(): void $this->assertStringEqualsStringIgnoringLineEndings( expected: <<<'HTML' -

hi

- <H1>HI</H1> -

hi

- HTML, +

hi

+ <H1>HI</H1> +

hi

+ HTML, actual: $html, ); } @@ -482,10 +482,10 @@ public function test_no_double_else_attributes(): void $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); } @@ -493,25 +493,25 @@ public function test_else_must_be_after_if_or_elseif(): void { $this->view->render( <<<'HTML' -
-
- HTML, +
+
+ HTML, ); $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -519,18 +519,18 @@ public function test_elseif_must_be_after_if_or_elseif(): void { $this->view->render( <<<'HTML' -
-
-
- HTML, +
+
+
+ HTML, ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -538,17 +538,17 @@ public function test_forelse_must_be_before_foreach(): void { $this->view->render( view(<<<'HTML' -
-
- HTML, foo: []), +
+
+ HTML, foo: []), ); $this->expectException(ElementWasInvalid::class); $this->view->render( <<<'HTML' -
- HTML, +
+ HTML, ); } @@ -556,19 +556,19 @@ public function test_no_double_forelse_attributes(): void { $this->view->render( view(<<<'HTML' -
-
- HTML, foo: []), +
+
+ HTML, foo: []), ); $this->expectException(ElementWasInvalid::class); $this->view->render( view(<<<'HTML' -
-
-
- HTML, foo: []), +
+
+
+ HTML, foo: []), ); } @@ -576,8 +576,8 @@ public function test_render_element_with_attribute_with_dash(): void { $view = view( <<
- HTML, +
+ HTML, ); $html = $this->view->render($view); @@ -612,19 +612,19 @@ public function test_slot_with_comment(): void { $this->assertSnippetsMatch( <<<'HTML' -
+
- Test + Test -
- HTML, +
+ HTML, $this->view->render( <<<'HTML' - - - Test - - HTML, + + + Test + + HTML, ), ); } @@ -652,21 +652,21 @@ public function test_self_closing_component_tags_are_compiled(): void public function test_html_tags(): void { $view = <<<'HTML' - - - - - Tempest - - - - - - -

Tempest

- - - HTML; + + + + + Tempest + + + + + + +

Tempest

+ + + HTML; $html = $this->view->render($view); @@ -693,8 +693,8 @@ public function test_with_at_symbol_in_html_tag(): void $this->assertStringEqualsStringIgnoringLineEndings( <<test - HTML, + + HTML, $rendered, ); } @@ -707,8 +707,8 @@ public function test_with_colon_symbol_in_html_tag(): void $this->assertStringEqualsStringIgnoringLineEndings( <<test - HTML, + + HTML, $rendered, ); } @@ -718,10 +718,10 @@ public function test_loop_variable_can_be_used_within_the_looped_tag(): void $html = $this->view->render( view( <<<'HTML' - - {{ $item->title }} - - HTML, + + {{ $item->title }} + + HTML, ) ->data(items: [ new class { @@ -738,16 +738,16 @@ public function test_loop_variable_can_be_used_within_the_looped_tag(): void ); $this->assertSnippetsMatch(<<<'HTML' - Item 1Item 2 - HTML, $html); + Item 1Item 2 + HTML, $html); } public function test_if_and_foreach_precedence(): void { $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, items: [ (object) ['name' => 'A', 'show' => true], (object) ['name' => 'B', 'show' => false], @@ -759,8 +759,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: true, items: [ (object) ['name' => 'A', 'show' => true], @@ -773,8 +773,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: true, items: [ (object) ['name' => 'A', 'show' => true], @@ -787,8 +787,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: false, items: [ (object) ['name' => 'A', 'show' => true], @@ -801,8 +801,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, show: false, items: [ (object) ['name' => 'A', 'show' => true], @@ -815,8 +815,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, item: (object) ['show' => true], items: [ (object) ['name' => 'A', 'show' => true], @@ -829,8 +829,8 @@ public function test_if_and_foreach_precedence(): void $html = $this->view->render( <<<'HTML' -
{{ $item->name }}
- HTML, +
{{ $item->name }}
+ HTML, items: [ (object) ['name' => 'A', 'show' => true], (object) ['name' => 'B', 'show' => false], @@ -851,8 +851,8 @@ public function test_escape_expression_attribute(): void public function test_unclosed_php_tag(): void { $html = $this->view->render(<<<'HTML' - assertSame('hi', $html); } @@ -860,8 +860,8 @@ public function test_unclosed_php_tag(): void public function test_view_comments(): void { $html = $this->view->render(<<<'HTML' -

{{-- this is a comment --}}this is rendered text

{{-- this is a comment --}} - HTML); +

{{-- this is a comment --}}this is rendered text

{{-- this is a comment --}} + HTML); $this->assertSnippetsMatch('

this is rendered text

', $html); } @@ -869,19 +869,19 @@ public function test_view_comments(): void public function test_multiline_view_comments(): void { $html = $this->view->render(<<<'HTML' - {{-- this is a comment -
- - {{ Tempest\Intl\translate('test_2') }} - - -
- --}} -

This should be rendered

- HTML); + {{-- this is a comment +
+ + {{ Tempest\Intl\translate('test_2') }} + + +
+ --}} +

This should be rendered

+ HTML); $this->assertSnippetsMatch('

This should be rendered

', $html); } @@ -893,17 +893,17 @@ public function test_parse_rss_feed(): void } $rss = <<<'XML' - - - https://tempestphp.com/rss - - Tempest - - <![CDATA[ {!! $post['title'] !!} ]]> - - - - XML; + + + https://tempestphp.com/rss + + Tempest + + <![CDATA[ {!! $post['title'] !!} ]]> + + + + XML; $parsed = $this->view->render($rss, posts: [ ['title' => '

A

', 'url' => 'https://tempestphp.com/a'], @@ -911,27 +911,27 @@ public function test_parse_rss_feed(): void ]); $this->assertSnippetsMatch(<<<'RSS' - - - https://tempestphp.com/rss - - Tempest - - <![CDATA[ <h1>A</h1> ]]> - - - <![CDATA[ B ]]> - - - - RSS, $parsed); + + + https://tempestphp.com/rss + + Tempest + + <![CDATA[ <h1>A</h1> ]]> + + + <![CDATA[ B ]]> + + + + RSS, $parsed); } public function test_attributes_with_single_quotes(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch('
', $html); } @@ -939,8 +939,8 @@ public function test_attributes_with_single_quotes(): void public function test_zero_in_attribute(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch('
', $html); } diff --git a/tests/Integration/View/TwigViewRendererTest.php b/tests/Integration/View/TwigViewRendererTest.php index 68fbb9b2f..0a009df02 100644 --- a/tests/Integration/View/TwigViewRendererTest.php +++ b/tests/Integration/View/TwigViewRendererTest.php @@ -33,9 +33,9 @@ public function test_twig(): void $html = $renderer->render(view('index.twig', ...['foo' => 'bar'])); $this->assertStringEqualsStringIgnoringLineEndings(<< - bar - - HTML, $html); + + bar + + HTML, $html); } } diff --git a/tests/Integration/View/ViewComponentDiscoveryTest.php b/tests/Integration/View/ViewComponentDiscoveryTest.php index 5953dff51..117daef48 100644 --- a/tests/Integration/View/ViewComponentDiscoveryTest.php +++ b/tests/Integration/View/ViewComponentDiscoveryTest.php @@ -87,8 +87,8 @@ public function test_auto_registration(): void $discovery->apply(); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('Hello World', $html); } @@ -101,8 +101,8 @@ public function test_auto_registration_with_x_component(): void $discovery->apply(); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('Hello World', $html); } diff --git a/tests/Integration/View/ViewComponentTest.php b/tests/Integration/View/ViewComponentTest.php index 5b1a47103..2ed4064ed 100644 --- a/tests/Integration/View/ViewComponentTest.php +++ b/tests/Integration/View/ViewComponentTest.php @@ -59,8 +59,8 @@ public function test_view_component_with_php_code_in_attribute(): void expected: '
', actual: $this->view->render( <<<'HTML' - - HTML, + + HTML, input: 'hello', ), ); @@ -77,47 +77,47 @@ public function test_view_component_with_php_code_in_slot(): void public function test_view_can_access_dynamic_slots(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
-
{{ $slot->name }}
-
{{ $slot->attributes['language'] }}
-
{{ $slot->language }}
-
{!! $slot->content !!}
-
- HTML); +
+
{{ $slot->name }}
+
{{ $slot->attributes['language'] }}
+
{{ $slot->language }}
+
{!! $slot->content !!}
+
+ HTML); $html = $this->view->render(<<<'HTML_WRAP' - - PHP Body - HTML Body - - HTML_WRAP); + + PHP Body + HTML Body + + HTML_WRAP); $this->assertSnippetsMatch(<<<'HTML_WRAP' -
slot-php
PHP
PHP
PHP Body
-
slot-html
HTML
HTML
HTML Body
- HTML_WRAP, $html); +
slot-php
PHP
PHP
PHP Body
+
slot-html
HTML
HTML
HTML Body
+ HTML_WRAP, $html); } public function test_dynamic_slots_are_cleaned_up(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
-
{{ $slot->name }}
-
- - HTML); +
+
{{ $slot->name }}
+
+ + HTML); $html = $this->view->render(<<<'HTML' - - - -
internal slots still here
-
internal slots are cleared
-
+ + + +
internal slots still here
+
internal slots are cleared
+
-
slots still here
-
slots are cleared
- HTML); +
slots still here
+
slots are cleared
+ HTML); $this->assertStringContainsString('
internal slots still here
', $html); $this->assertStringContainsString('
slots are cleared
', $html); @@ -126,17 +126,17 @@ public function test_dynamic_slots_are_cleaned_up(): void public function test_dynamic_slots_include_the_default_slot(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
{{ $slots['default']->name }}
-
{{ $slots['default']->content }}
- HTML); +
{{ $slots['default']->name }}
+
{{ $slots['default']->content }}
+ HTML); $html = $this->view->render('Hello'); $this->assertSnippetsMatch( <<<'HTML' -
default
-
Hello
- HTML, +
default
+
Hello
+ HTML, $html, ); } @@ -144,29 +144,29 @@ public function test_dynamic_slots_include_the_default_slot(): void public function test_slots_with_nested_view_components(): void { $this->view->registerViewComponent('x-a', <<<'HTML' - -
-
A{{ $slot->name }}
-
- HTML); + +
+
A{{ $slot->name }}
+
+ HTML); $this->view->registerViewComponent('x-b', <<<'HTML' -
-
B{{ $slot->name }}
-
- HTML); +
+
B{{ $slot->name }}
+
+ HTML); $html = $this->view->render(<<<'HTML' - - - - - + + + + + - - - - HTML); + + + + HTML); $this->assertStringContainsString('
B1
', $html); $this->assertStringContainsString('
B2
', $html); @@ -185,9 +185,9 @@ public function test_slots_is_a_reserved_variable(): void public function test_scope_does_not_leak_data(): void { $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertStringContainsString('', $html); $this->assertStringContainsString('view->render(''); $this->assertSnippetsMatch(<<<'HTML' - hi + hi - -
- HTML, $html); + +
+ HTML, $html); } public function test_component_with_anther_component_included_with_slot(): void @@ -213,13 +213,13 @@ public function test_component_with_anther_component_included_with_slot(): void $html = $this->view->render('test'); $this->assertSnippetsMatch(<<<'HTML' - hi + hi - -
- test -
- HTML, $html); + +
+ test +
+ HTML, $html); } public function test_view_component_with_injected_view(): void @@ -238,8 +238,8 @@ public function test_view_component_with_injected_view(): void $html = $this->view->render(view( <<<'HTML' - - HTML, + + HTML, )); $validator = $this->container->get(Validator::class); @@ -265,8 +265,8 @@ public function test_component_with_if(): void public function test_component_with_foreach(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch( expected: '
a
b
', @@ -278,8 +278,8 @@ public function test_anonymous_view_component(): void { $this->assertSame( <<hi - HTML, +
hi
+ HTML, $this->view->render('hi'), ); } @@ -302,8 +302,8 @@ public function test_with_passed_variable(): void $this->assertSnippetsMatch( <<test - HTML, +
test
+ HTML, $rendered, ); } @@ -316,8 +316,8 @@ public function test_with_passed_data(): void $this->assertSnippetsMatch( <<test - HTML, +
test
+ HTML, $rendered, ); } @@ -326,14 +326,14 @@ public function test_with_passed_php_data(): void { $rendered = $this->view->render( view(<<
- HTML), + + HTML), ); $this->assertSnippetsMatch( <<TEST - HTML, +
TEST
+ HTML, $rendered, ); } @@ -360,8 +360,8 @@ public function test_with_passed_variable_within_loop(): void { $rendered = $this->view->render( <<<'HTML' - - HTML, + + HTML, variables: ['a', 'b', 'c'], ); @@ -386,8 +386,8 @@ public function test_view_component_attribute_variables_without_this(): void $html = $this->view->render(view(__DIR__ . '/../../Fixtures/Views/view-component-attribute-without-this-b.view.php')); $this->assertSame(<<view->render(view(__DIR__ . '/../../Fixtures/Views/view-component-with-non-self-closing-slot-b.view.php')); $this->assertSnippetsMatch(<<view->registerViewComponent('x-test', <<<'HTML' - {{ $metaType ?? 'nothing' }} - HTML); + {{ $metaType ?? 'nothing' }} + HTML); $this->assertSame('test', $this->view->render('')); $this->assertSame('test', $this->view->render('')); @@ -432,19 +432,19 @@ public function test_template_component(): void { $html = $this->view->render( <<<'HTML' - -
item {{ $item }}
-
boo
-
- HTML, + +
item {{ $item }}
+
boo
+
+ HTML, items: ['a', 'b', 'c'], ); $this->assertSnippetsMatch(<<<'HTML' -
item a
boo
-
item b
boo
-
item c
boo
- HTML, $html); +
item a
boo
+
item b
boo
+
item c
boo
+ HTML, $html); } public static function view_components(): Generator @@ -480,29 +480,29 @@ public static function view_components(): Generator public function test_full_html_document_as_component(): void { $this->view->registerViewComponent('x-layout', <<<'HTML' - - - Tempest View - - - - - - HTML); + + + Tempest View + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - Hello World - - HTML); + + Hello World + + HTML); $this->assertStringContainsString(<<<'HTML' - - - Tempest View - - - HTML, $html); + + + Tempest View + + + HTML, $html); $this->assertStringContainsString('Hello World', $html); $this->assertStringContainsString('', $html); $this->assertStringContainsString('', $html); @@ -513,23 +513,23 @@ public function test_empty_slots_are_commented_out(): void $this->container->singleton(Environment::class, Environment::LOCAL); $this->view->registerViewComponent('x-layout', <<<'HTML' - - - - - - - - HTML); + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_empty_slots_are_removed_in_production(): void @@ -537,131 +537,131 @@ public function test_empty_slots_are_removed_in_production(): void $this->container->singleton(Environment::class, Environment::PRODUCTION); $this->view->registerViewComponent('x-layout', <<<'HTML' - - - - - - - - HTML); + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - - - HTML); + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_custom_components_in_head(): void { $this->view->registerViewComponent('x-custom-link', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - - HTML, $html); + + + HTML, $html); } public function test_head_injection(): void { $this->view->registerViewComponent('x-custom-link', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - - Foo - - - - - b - - HTML); + + + + Foo + + + + + b + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - Foo - b - - HTML, $html); + + Foo + b + + HTML, $html); } public function test_attributes_variable_in_view_component(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_fallthrough_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merged_fallthrough_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_fallthrough_attributes_with_other_attributes(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_file_name_component(): void @@ -674,79 +674,79 @@ public function test_file_name_component(): void public function test_array_attribute(): void { $html = $this->view->render(<<<'HTML' -
- HTML); +
+ HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merge_class(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_merge_class_from_template_to_component(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- HTML); +
+ HTML); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- HTML, $html); +
+ HTML, $html); } public function test_does_not_duplicate_br(): void { $this->view->registerViewComponent('x-html-base', <<<'HTML' - - - - - - - - - HTML); + + + + + + + + + HTML); $html = $this->view->render(<<<'HTML' - -
-
-
- HTML); + +
+
+
+ HTML); $this->assertSnippetsMatch(<<<'HTML' - -

- HTML, $html); + +

+ HTML, $html); } public function test_renders_minified_html_with_void_elements(): void { $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); } public function test_multiple_instances_of_custom_component_using_slots(): void @@ -754,48 +754,48 @@ public function test_multiple_instances_of_custom_component_using_slots(): void $this->view->registerViewComponent('x-foo-bar', 'FOO-BAR'); $this->view->registerViewComponent('x-test', <<<'HTML' -
- - -
- HTML); +
+ + +
+ HTML); $html = $this->view->render(<<<'HTML' - - - - - - HTML); + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
FOO-BAR - FOO-BAR -
- HTML, $html); +
FOO-BAR + FOO-BAR +
+ HTML, $html); } public function test_slots_with_hyphens(): void { $this->view->registerViewComponent('x-test', <<<'HTML' -
- -
- HTML); +
+ +
+ HTML); $html = $this->view->render(<<<'HTML' - - - Hi - - - HTML); + + + Hi + + + HTML); $this->assertSnippetsMatch(<<<'HTML' -
- Hi -
- HTML, $html); +
+ Hi +
+ HTML, $html); } public function test_nested_table_components(): void @@ -807,34 +807,34 @@ public function test_nested_table_components(): void $this->view->registerViewComponent('x-my-table-th', ''); $html = $this->view->render(<<<'HTML' - - - - Header 1 - - - - - Row 1, Cell 1 - - -
- HTML); - - $this->assertSnippetsMatch(<<<'HTML' - - - - - - - - - - + + + Header 1 + + + + + Row 1, Cell 1 + +
Header1
Row 1, Cell 1
- HTML, $html); + HTML); + + $this->assertSnippetsMatch(<<<'HTML' + + + + + + + + + + + +
Header1
Row 1, Cell 1
+ HTML, $html); } public function test_dynamic_view_component_with_string_name(): void @@ -842,8 +842,8 @@ public function test_dynamic_view_component_with_string_name(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML); + + HTML); $this->assertSame('
test
', $html); } @@ -853,8 +853,8 @@ public function test_dynamic_view_component_with_expression_name(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML, name: 'x-test'); + + HTML, name: 'x-test'); $this->assertSame('
test
', $html); } @@ -864,8 +864,8 @@ public function test_dynamic_view_component_with_variable_attribute(): void $this->view->registerViewComponent('x-test', '
{{ $prop }}
'); $html = $this->view->render(<<<'HTML' - - HTML, name: 'x-test', input: 'test'); + + HTML, name: 'x-test', input: 'test'); $this->assertSame('
test
', $html); } @@ -875,8 +875,8 @@ public function test_dynamic_view_component_with_slot(): void $this->view->registerViewComponent('x-test', '
'); $html = $this->view->render(<<<'HTML' - test - HTML, name: 'x-test'); + test + HTML, name: 'x-test'); $this->assertSnippetsMatch('
test
', $html); } @@ -888,8 +888,8 @@ public function dynamic_view_component_keeps_foreach_scope(): void $html = $this->view->render( <<<'HTML' - {{ $item }} - HTML, + {{ $item }} + HTML, name: 'x-test', items: ['a', 'b'], ); @@ -903,10 +903,10 @@ public function test_nested_slots(): void $this->view->registerViewComponent('x-b', ''); $html = $this->view->render(<<<'HTML' - - hi - - HTML); + + hi + + HTML); $this->assertSnippetsMatch('hi', $html); } @@ -915,18 +915,18 @@ public function test_nested_slots_with_escaping(): void { $this->view->registerViewComponent('x-a', ''); $this->view->registerViewComponent('x-b', <<<'HTML' - - {{ get(Environment::class)->value }} - HTML); + + {{ get(Environment::class)->value }} + HTML); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertSnippetsMatch('testing', $html); } @@ -936,10 +936,10 @@ public function test_repeated_local_var_across_view_components(): void $this->view->registerViewComponent('x-test', '
{{ $thing }}
'); $html = $this->view->render(<<<'HTML' - - - - HTML); + + + + HTML); $this->assertSnippetsMatch('
a
@@ -960,17 +960,17 @@ public function test_escape_expression_attribute_in_view_components(): void public function test_default_slot_value(): void { $this->view->registerViewComponent('x-test', <<<'HTML' - Default - Default A - Default B - HTML); + Default + Default A + Default B + HTML); $this->assertSnippetsMatch( <<<'HTML' - Overwritten - Overwritten A - Overwritten B - HTML, + Overwritten + Overwritten A + Overwritten B + HTML, $this->view->render(' Overwritten Overwritten A @@ -980,10 +980,10 @@ public function test_default_slot_value(): void $this->assertSnippetsMatch( <<<'HTML' - Overwritten - Default A - Overwritten B - HTML, + Overwritten + Default A + Overwritten B + HTML, $this->view->render(' Overwritten Overwritten B @@ -991,10 +991,10 @@ public function test_default_slot_value(): void ); $this->assertSnippetsMatch(<<<'HTML' - Default - Default A - Default B - HTML, $this->view->render('')); + Default + Default A + Default B + HTML, $this->view->render('')); } public function test_view_variables_are_passed_into_the_component(): void @@ -1002,10 +1002,10 @@ public function test_view_variables_are_passed_into_the_component(): void $this->view->registerViewComponent('x-a', ''); $html = $this->view->render(<<<'HTML' - - {{ $title }} - - HTML, title: 'test'); + + {{ $title }} + + HTML, title: 'test'); $this->assertSnippetsMatch('test', $html); } @@ -1017,12 +1017,12 @@ public function test_capture_outer_scope_view_component_variables(): void $html = $this->view->render( <<<'HTML' - - - {{ $item }} - - - HTML, + + + {{ $item }} + + + HTML, items: ['a', 'b'], ); @@ -1042,13 +1042,13 @@ public function test_imports_in_slots_from_root_node(): void $this->view->registerViewComponent('x-test', '
'); $html = $this->view->render(<<<'HTML' - + - {{ uri(HomeController::class) }} - HTML); + {{ uri(HomeController::class) }} + HTML); $this->assertSame('
/
', $html); } @@ -1056,25 +1056,25 @@ public function test_imports_in_slots_from_root_node(): void public function test_combined_imports_from_root_node_and_view_component(): void { $this->view->registerViewComponent('x-parent', <<<'HTML' -
- HTML); +
+ HTML); $this->view->registerViewComponent('x-child', <<<'HTML' - -
- HTML); + +
+ HTML); $html = $this->view->render(<<<'HTML' - + - - {{ uri(HomeController::class) }} - - HTML); + + {{ uri(HomeController::class) }} + + HTML); $this->assertSnippetsMatch('
/
', $html); } @@ -1173,22 +1173,22 @@ function (ViewCompilationFailed $exception) use ($exceptionRenderer): void { public function test_imports_with_nested_view_components(): void { $this->view->registerViewComponent('x-card', <<<'HTML' -
- HTML); +
+ HTML); $this->view->registerViewComponent('x-footer', <<<'HTML' - - HTML); + + HTML); $html = $this->view->render(<<<'HTML' - - - {{ uri(HomeController::class) }} - - HTML); + + + {{ uri(HomeController::class) }} + + HTML); $this->assertSnippetsMatch('
/
', $html); } @@ -1199,18 +1199,18 @@ public function test_imports_in_nested_html_elements(): void $this->view->registerViewComponent('x-b', '
">'); $html = $this->view->render(<<<'HTML' - - -
- - {{ uri(HomeController::class) }} - -
-
- HTML); + + +
+ + {{ uri(HomeController::class) }} + +
+
+ HTML); $this->assertSnippetsMatch('
/
">
">', $html); } diff --git a/tests/Integration/View/ViewTest.php b/tests/Integration/View/ViewTest.php index 90a8c587d..317043aa1 100644 --- a/tests/Integration/View/ViewTest.php +++ b/tests/Integration/View/ViewTest.php @@ -41,8 +41,8 @@ public function test_render_with_view_model(): void $html = $this->view->render($view); $expected = <<assertEquals($expected, $html); } diff --git a/tests/Integration/Vite/DevelopmentTagsResolverTest.php b/tests/Integration/Vite/DevelopmentTagsResolverTest.php index 20fa38008..cc67d2e77 100644 --- a/tests/Integration/Vite/DevelopmentTagsResolverTest.php +++ b/tests/Integration/Vite/DevelopmentTagsResolverTest.php @@ -29,11 +29,6 @@ protected function setUp(): void public function test_resolve_tags(): void { $this->vite->call( - files: [ - 'src/main.ts' => '', - 'src/foo.ts' => '', - 'src/tailwind.css' => '', - ], callback: function (): void { $resolver = new DevelopmentTagsResolver( bridgeFile: new ViteBridgeFile(url: 'http://localhost'), @@ -50,6 +45,11 @@ public function test_resolve_tags(): void actual: $resolver->resolveTags(['src/main.ts', 'src/foo.ts', 'src/tailwind.css']), ); }, + files: [ + 'src/main.ts' => '', + 'src/foo.ts' => '', + 'src/tailwind.css' => '', + ], ); } @@ -58,9 +58,6 @@ public function test_throw_if_entrypoint_not_found(): void $this->expectException(FileSystemEntrypointWasNotFoundException::class); $this->vite->call( - files: [ - 'src/main.ts' => '', - ], callback: function (): void { $resolver = new DevelopmentTagsResolver( bridgeFile: new ViteBridgeFile(url: 'http://localhost'), @@ -69,6 +66,9 @@ public function test_throw_if_entrypoint_not_found(): void $resolver->resolveTags(['src/main.ts', 'src/foo.ts']); }, + files: [ + 'src/main.ts' => '', + ], ); } @@ -80,11 +80,6 @@ public function test_automatically_converts_relative_paths(): void ); $this->vite->call( - files: [ - 'src/main.ts' => '', - 'src/foo.ts' => '', - 'src/bar/baz.ts' => '', - ], callback: function (): void { $resolver = new DevelopmentTagsResolver( bridgeFile: new ViteBridgeFile(url: 'http://localhost'), @@ -101,6 +96,11 @@ public function test_automatically_converts_relative_paths(): void actual: $resolver->resolveTags(['src/main.ts', 'src/foo.ts', './src/bar/baz.ts']), ); }, + files: [ + 'src/main.ts' => '', + 'src/foo.ts' => '', + 'src/bar/baz.ts' => '', + ], ); } } diff --git a/tests/Integration/Vite/GenericTagCompilerTest.php b/tests/Integration/Vite/GenericTagCompilerTest.php index 36aa6387a..7b6819788 100644 --- a/tests/Integration/Vite/GenericTagCompilerTest.php +++ b/tests/Integration/Vite/GenericTagCompilerTest.php @@ -41,7 +41,7 @@ public function test_generate_legacy_script_tag(): void public function test_generate_legacy_script_tag_with_polyfills(): void { $generator = $this->container->get(GenericTagCompiler::class); - $tag = $generator->compileScriptTag('/build/main.js', $this->createChunk(legacy: true, src: 'vite/legacy-polyfills')); + $tag = $generator->compileScriptTag('/build/main.js', $this->createChunk(src: 'vite/legacy-polyfills', legacy: true)); $this->assertStringContainsString('Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -63,19 +63,19 @@ public function test_dev_entrypoints(): void )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -96,19 +96,19 @@ public function test_dev_entrypoints_from_config(): void )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: <<Foo - - HTML, + Foo + + HTML, actual: $html, ); }, @@ -129,26 +129,26 @@ public function test_dev_entrypoints_from_config_and_react_refresh_from_bridgefi )); $html = $this->view->render(<<<'HTML' - - - - - Foo - - HTML); + + + + + Foo + + HTML); $this->assertSnippetsMatch( expected: << - Foo - - HTML, + + Foo + + HTML, actual: $html, ); }, @@ -173,17 +173,17 @@ public function test_production_entrypoint_from_config(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), @@ -201,17 +201,17 @@ public function test_production_entrypoint(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), @@ -229,17 +229,17 @@ public function test_production_entrypoints(): void )); $html = $this->view->render(<<<'HTML' - - - - - - - HTML); + + + + + + + HTML); $this->assertSnippetsMatch(<<<'HTML' - - HTML, $html); + + HTML, $html); }, files: [ 'public/build/manifest.json' => $this->fixture('two-unrelated-entrypoints.json'), diff --git a/tests/Integration/Vite/ViteTest.php b/tests/Integration/Vite/ViteTest.php index 9fcceb0cf..1cee1c955 100644 --- a/tests/Integration/Vite/ViteTest.php +++ b/tests/Integration/Vite/ViteTest.php @@ -190,7 +190,6 @@ public function test_get_tags_with_entrypoints_and_global_entrypoints(): void public function test_discovery(): void { $this->vite->call( - root: __DIR__ . '/Fixtures/tmp', callback: function (string $path): void { $discovery = $this->container->get(ViteDiscovery::class); $discovery->setItems(new DiscoveryItems([])); @@ -209,6 +208,7 @@ public function test_discovery(): void 'src/main.entrypoint.ts' => '', 'public/vite-tempest' => ['url' => 'http://localhost:5173'], ], + root: __DIR__ . '/Fixtures/tmp', ); } } From 27c68da7b6cf3b1c2ea3e11caacfeb211f16db34 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 12 Mar 2026 18:03:16 +0100 Subject: [PATCH 14/14] run mago linting --- mago.toml | 1 + .../src/AccessControl/PolicyDiscovery.php | 1 - packages/auth/tests/OAuthTest.php | 2 +- .../command-bus/src/MonitorAsyncCommands.php | 54 ++++++------ packages/command-bus/src/functions.php | 1 - .../src/Completion/CompletionEngine.php | 6 +- .../Components/Interactive/TaskComponent.php | 6 +- .../console/src/Input/ConsoleArgumentBag.php | 36 ++++---- .../console/tests/OptionCollectionTest.php | 4 +- packages/container/src/functions.php | 1 - .../tests/Fixtures/SlowDependency.php | 2 +- packages/core/src/Composer.php | 10 ++- .../core/src/InsightsProviderDiscovery.php | 1 - .../core/src/Kernel/LoadDiscoveryClasses.php | 6 +- packages/core/src/PublishesFiles.php | 6 +- packages/core/src/functions.php | 1 - .../database/src/Builder/ModelInspector.php | 6 +- packages/database/src/IsDatabaseModel.php | 9 +- .../src/Migrations/MigrationManager.php | 4 +- .../src/Migrations/RunnableMigrations.php | 12 ++- .../QueryStatements/CreateTableStatement.php | 4 +- packages/database/src/functions.php | 5 +- packages/datetime/src/SecondsStyle.php | 2 +- packages/datetime/src/functions.php | 8 -- packages/datetime/tests/DateTimeTest.php | 38 ++++---- packages/datetime/tests/DurationTest.php | 58 ++++++------- packages/datetime/tests/SecondsStyleTest.php | 2 +- packages/datetime/tests/TimestampTest.php | 52 +++++------ packages/datetime/tests/TimezoneTest.php | 14 +-- packages/debug/tests/StacktraceTest.php | 6 +- packages/event-bus/src/functions.php | 2 - .../src/Php/ManipulatesPhpClasses.php | 6 +- .../src/Php/SimplifiesClassNames.php | 6 +- .../generation/src/Php/StubFileGenerator.php | 1 - .../TypeScript/Writers/DirectoryWriter.php | 34 ++++---- .../Session/SessionIdResolverInitializer.php | 1 - .../PsrRequestToGenericRequestMapperTest.php | 4 +- .../tests/IdempotencyMiddlewareTest.php | 2 +- .../tests/IdempotentCommandMiddlewareTest.php | 2 +- packages/intl/src/GenericTranslator.php | 2 - packages/intl/src/IntlConfig.php | 1 - .../src/PluralRules/PluralRulesMatcher.php | 26 +++--- packages/intl/src/TranslationFailure.php | 1 - .../intl/src/TranslationMessageDiscovery.php | 1 - packages/intl/src/TranslationMiss.php | 2 - packages/intl/src/Translator.php | 2 - packages/intl/src/TranslatorInitializer.php | 1 - packages/intl/src/functions.php | 2 - packages/intl/tests/FunctionsTest.php | 82 +++++++++--------- packages/intl/tests/LocaleTest.php | 24 ++++-- packages/log/src/TailLogsCommand.php | 1 - packages/mail/src/MailerInitializer.php | 1 - packages/mail/src/Testing/MailTester.php | 12 +-- .../src/Mappers/ObjectToArrayMapper.php | 6 +- packages/mapper/src/functions.php | 1 - .../src/Testing/InvokedTestingProcess.php | 12 ++- .../process/src/Testing/ProcessTester.php | 12 ++- packages/reflection/src/functions.php | 2 - .../tests/Fixtures/NoReturnType.php | 1 - .../src/Exceptions/HtmlExceptionRenderer.php | 6 +- packages/router/src/MatchRouteMiddleware.php | 11 +-- .../router/src/RouteBindingInitializer.php | 10 ++- .../RouteMatchingRegexBuilder.php | 2 +- .../router/src/Static/StaticCleanCommand.php | 6 +- packages/router/src/functions.php | 1 - packages/support/src/Arr/functions.php | 32 ++++--- .../Json/Exception/JsonCouldNotBeDecoded.php | 1 - .../Json/Exception/JsonCouldNotBeEncoded.php | 1 - packages/support/src/Math/constants.php | 30 +++---- packages/support/src/Math/functions.php | 24 ++++-- packages/support/src/Str/functions.php | 4 +- packages/support/src/Uri/Uri.php | 4 +- .../tests/Arr/ManipulatesArrayTest.php | 4 +- packages/support/tests/Math/MathsTest.php | 86 +++++++++---------- .../support/tests/Regex/FunctionsTest.php | 2 +- packages/support/tests/Str/FunctionsTest.php | 2 +- .../tests/Rules/IsJsonStringTest.php | 2 +- .../validation/tests/Rules/IsPasswordTest.php | 4 +- packages/view/src/Elements/IsElement.php | 8 +- packages/view/src/Elements/RootElement.php | 6 +- .../src/Elements/ViewComponentElement.php | 6 +- .../src/Initializers/ViewCacheInitializer.php | 4 +- packages/view/src/functions.php | 3 - packages/vite/src/ViteDiscovery.php | 1 - packages/vite/src/functions.php | 2 - phpstan-baseline.neon | 4 - .../Auth/AccessControl/HasPolicyTests.php | 6 +- tests/Integration/Cache/CacheTest.php | 8 +- .../Console/ConsoleArgumentBagTest.php | 6 +- .../Console/Fixtures/InteractiveCommand.php | 2 +- .../Input/ConsoleInputArgumentTest.php | 8 +- .../Builder/SelectQueryBuilderTest.php | 6 +- .../ConvenientDateWhereMethodsTest.php | 6 +- .../Mapper/Fixtures/SerializableObject.php | 6 +- tests/Integration/Route/ClientTest.php | 2 +- .../Route/RequestToObjectMapperTest.php | 2 +- .../Integration/Validator/ExistsRuleTest.php | 6 +- 97 files changed, 467 insertions(+), 465 deletions(-) diff --git a/mago.toml b/mago.toml index b67ba28df..28dd67d5a 100644 --- a/mago.toml +++ b/mago.toml @@ -70,3 +70,4 @@ single-class-per-file = { enabled = false } no-isset = { enabled = false } instanceof-stringable = { enabled = false } prefer-static-closure = { enabled = false } +sensitive-parameter = { enabled = false } diff --git a/packages/auth/src/AccessControl/PolicyDiscovery.php b/packages/auth/src/AccessControl/PolicyDiscovery.php index 92f28c4aa..85319bdff 100644 --- a/packages/auth/src/AccessControl/PolicyDiscovery.php +++ b/packages/auth/src/AccessControl/PolicyDiscovery.php @@ -2,7 +2,6 @@ namespace Tempest\Auth\AccessControl; -use Tempest\Auth\AccessControl\Policy; use Tempest\Auth\AuthConfig; use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; diff --git a/packages/auth/tests/OAuthTest.php b/packages/auth/tests/OAuthTest.php index 8f9271d55..503f16643 100644 --- a/packages/auth/tests/OAuthTest.php +++ b/packages/auth/tests/OAuthTest.php @@ -185,7 +185,7 @@ public function oauth_user_creation(): void avatar: 'https://example.com/avatar.jpg', provider: 'github', raw: [ - 'id' => 123456, + 'id' => 123_456, 'login' => 'frieren', 'name' => 'Frieren the Mage', 'email' => 'frieren@elven-mage.magic', diff --git a/packages/command-bus/src/MonitorAsyncCommands.php b/packages/command-bus/src/MonitorAsyncCommands.php index 2aaa2f36d..1faa47600 100644 --- a/packages/command-bus/src/MonitorAsyncCommands.php +++ b/packages/command-bus/src/MonitorAsyncCommands.php @@ -35,33 +35,35 @@ public function __invoke(): void while (true) { // @phpstan-ignore-line foreach ($processes as $uuid => $process) { - if ($process->isTerminated()) { - if ($process->isSuccessful()) { - $this->console->keyValue( - key: "{$uuid}", - value: "SUCCESS", - ); - } else { - $this->console->keyValue( - key: "{$uuid}", - value: "FAILED", - ); - } - - $output = trim($process->getOutput()); - - if ($output !== '' && $output !== '0') { - $this->writeln($output); - } - - $errorOutput = trim($process->getErrorOutput()); - - if ($errorOutput !== '' && $errorOutput !== '0') { - $this->writeln($errorOutput); - } - - unset($processes[$uuid]); + if (! $process->isTerminated()) { + continue; } + + if ($process->isSuccessful()) { + $this->console->keyValue( + key: "{$uuid}", + value: "SUCCESS", + ); + } else { + $this->console->keyValue( + key: "{$uuid}", + value: "FAILED", + ); + } + + $output = trim($process->getOutput()); + + if ($output !== '' && $output !== '0') { + $this->writeln($output); + } + + $errorOutput = trim($process->getErrorOutput()); + + if ($errorOutput !== '' && $errorOutput !== '0') { + $this->writeln($errorOutput); + } + + unset($processes[$uuid]); } $availableCommands = arr($this->repository->getPendingCommands()) diff --git a/packages/command-bus/src/functions.php b/packages/command-bus/src/functions.php index e9dfbceda..3333d44a5 100644 --- a/packages/command-bus/src/functions.php +++ b/packages/command-bus/src/functions.php @@ -4,7 +4,6 @@ namespace Tempest\CommandBus; -use Tempest\CommandBus\CommandBus; use Tempest\Container; /** diff --git a/packages/console/src/Completion/CompletionEngine.php b/packages/console/src/Completion/CompletionEngine.php index 52043027a..de86d1b3e 100644 --- a/packages/console/src/Completion/CompletionEngine.php +++ b/packages/console/src/Completion/CompletionEngine.php @@ -135,9 +135,11 @@ private function selectCompletionValue(CompletionFlag $flag, string $current): ? $candidates[] = $flag->flag; foreach ($flag->aliases as $alias) { - if (str_starts_with($alias, '--')) { - $candidates[] = $alias; + if (! str_starts_with($alias, '--')) { + continue; } + + $candidates[] = $alias; } } elseif (str_starts_with($current, '-')) { foreach ($flag->aliases as $alias) { diff --git a/packages/console/src/Components/Interactive/TaskComponent.php b/packages/console/src/Components/Interactive/TaskComponent.php index 08875a722..8e30a6f6c 100644 --- a/packages/console/src/Components/Interactive/TaskComponent.php +++ b/packages/console/src/Components/Interactive/TaskComponent.php @@ -139,9 +139,11 @@ private function renderTask(Terminal $terminal, ?string $line = null): string private function cleanupSockets(): void { foreach ($this->sockets as $socket) { - if (is_resource($socket)) { - @fclose($socket); + if (! is_resource($socket)) { + continue; } + + @fclose($socket); } $this->sockets = []; diff --git a/packages/console/src/Input/ConsoleArgumentBag.php b/packages/console/src/Input/ConsoleArgumentBag.php index 6cb10bbca..b8d396b53 100644 --- a/packages/console/src/Input/ConsoleArgumentBag.php +++ b/packages/console/src/Input/ConsoleArgumentBag.php @@ -117,9 +117,11 @@ public function findArrayFor(ConsoleArgumentDefinition $argumentDefinition): Con $values = []; foreach ($this->arguments as $argument) { - if ($argumentDefinition->matchesArgument($argument)) { - $values[] = $argument->value; + if (! $argumentDefinition->matchesArgument($argument)) { + continue; } + + $values[] = $argument->value; } return new ConsoleInputArgument( @@ -137,13 +139,15 @@ public function findForVariadicArgument(ConsoleArgumentDefinition $argumentDefin $arguments = []; foreach ($this->arguments as $argument) { - if ($argument->position >= $argumentDefinition->position) { - $arguments[] = new ConsoleInputArgument( - name: $argumentDefinition->name, - position: $argument->position, - value: $this->resolveArgumentValue($argumentDefinition, $argument)->value, - ); + if ($argument->position < $argumentDefinition->position) { + continue; } + + $arguments[] = new ConsoleInputArgument( + name: $argumentDefinition->name, + position: $argument->position, + value: $this->resolveArgumentValue($argumentDefinition, $argument)->value, + ); } return $arguments; @@ -173,16 +177,18 @@ public function addMany(array $arguments): self // Otherwise, $arguments is an array of flags or positional argument. foreach ($arguments as $key => $argument) { - if (str_starts_with($argument, '-') && ! str_starts_with($argument, '--')) { - $flags = str_split($argument); - unset($flags[0]); + if (! (str_starts_with($argument, '-') && ! str_starts_with($argument, '--'))) { + continue; + } - foreach ($flags as $flag) { - $arguments[] = "-{$flag}"; - } + $flags = str_split($argument); + unset($flags[0]); - unset($arguments[$key]); + foreach ($flags as $flag) { + $arguments[] = "-{$flag}"; } + + unset($arguments[$key]); } $position = count($this->arguments); diff --git a/packages/console/tests/OptionCollectionTest.php b/packages/console/tests/OptionCollectionTest.php index 2a4f86da8..81ab5effb 100644 --- a/packages/console/tests/OptionCollectionTest.php +++ b/packages/console/tests/OptionCollectionTest.php @@ -31,7 +31,7 @@ public function test_filter(): void $options->filter('ergljherkigjerg'); $this->assertCount(0, $options->getOptions()); - $this->assertSame(null, $options->getActive()); + $this->assertNull($options->getActive()); } public function test_keeps_active_on_filter(): void @@ -50,7 +50,7 @@ public function test_keeps_active_on_filter(): void $this->assertSame('baz', $options->getActive()->value); $options->filter('bazz'); - $this->assertSame(null, $options->getActive()); + $this->assertNull($options->getActive()); } public function test_navigate(): void diff --git a/packages/container/src/functions.php b/packages/container/src/functions.php index 32eee772b..a58062e56 100644 --- a/packages/container/src/functions.php +++ b/packages/container/src/functions.php @@ -4,7 +4,6 @@ namespace Tempest\Container; -use Tempest\Container\GenericContainer; use Tempest\Reflection\FunctionReflector; use Tempest\Reflection\MethodReflector; diff --git a/packages/container/tests/Fixtures/SlowDependency.php b/packages/container/tests/Fixtures/SlowDependency.php index 087c27502..868ab2700 100644 --- a/packages/container/tests/Fixtures/SlowDependency.php +++ b/packages/container/tests/Fixtures/SlowDependency.php @@ -12,7 +12,7 @@ public function __construct(float $delay = 0.1, int $counter = 0) // usleep apparently is buggy on windows... $start = microtime(true); while ((microtime(true) - $start) < $delay) { - usleep(intval($delay * 1000000)); + usleep(intval($delay * 1_000_000)); } $this->value = 'value' . $counter; diff --git a/packages/core/src/Composer.php b/packages/core/src/Composer.php index a14ab5a5b..c74ea335e 100644 --- a/packages/core/src/Composer.php +++ b/packages/core/src/Composer.php @@ -44,11 +44,13 @@ public function load(): self ->toArray(); foreach ($this->namespaces as $namespace) { - if (Str\starts_with(Str\ensure_ends_with($namespace->path, '/'), ['app/', 'src/', 'source/', 'lib/'])) { - $this->mainNamespace = $namespace; - - break; + if (! Str\starts_with(Str\ensure_ends_with($namespace->path, '/'), ['app/', 'src/', 'source/', 'lib/'])) { + continue; } + + $this->mainNamespace = $namespace; + + break; } if (! isset($this->mainNamespace) && count($this->namespaces)) { diff --git a/packages/core/src/InsightsProviderDiscovery.php b/packages/core/src/InsightsProviderDiscovery.php index f456bf22b..bad000651 100644 --- a/packages/core/src/InsightsProviderDiscovery.php +++ b/packages/core/src/InsightsProviderDiscovery.php @@ -4,7 +4,6 @@ namespace Tempest\Core; -use Tempest\Core\AppConfig; use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; diff --git a/packages/core/src/Kernel/LoadDiscoveryClasses.php b/packages/core/src/Kernel/LoadDiscoveryClasses.php index 073e1674a..289531902 100644 --- a/packages/core/src/Kernel/LoadDiscoveryClasses.php +++ b/packages/core/src/Kernel/LoadDiscoveryClasses.php @@ -259,9 +259,11 @@ private function discoverPath(string $input, DiscoveryLocation $location, array } foreach ($discoveries as $discovery) { - if ($discovery instanceof DiscoversPath) { - $discovery->discoverPath($location, $input); + if (! $discovery instanceof DiscoversPath) { + continue; } + + $discovery->discoverPath($location, $input); } } diff --git a/packages/core/src/PublishesFiles.php b/packages/core/src/PublishesFiles.php index 0ebe8dbc3..09b1a1fd9 100644 --- a/packages/core/src/PublishesFiles.php +++ b/packages/core/src/PublishesFiles.php @@ -245,9 +245,11 @@ function (string $content) use ($callback) { // PHP will output empty arrays for empty dependencies, // which is invalid and will make package managers crash. foreach (['dependencies', 'devDependencies', 'peerDependencies'] as $key) { - if (isset($json[$key]) && ! $json[$key]) { - unset($json[$key]); + if (! (isset($json[$key]) && ! $json[$key])) { + continue; } + + unset($json[$key]); } $content = preg_replace_callback( diff --git a/packages/core/src/functions.php b/packages/core/src/functions.php index 3e93e0267..4d64ccfd4 100644 --- a/packages/core/src/functions.php +++ b/packages/core/src/functions.php @@ -6,7 +6,6 @@ use Closure; use Stringable; -use Tempest\Container; use Tempest\Core\Composer; use Tempest\Core\DeferredTasks; use Tempest\Core\EnvironmentVariableValidationFailed; diff --git a/packages/database/src/Builder/ModelInspector.php b/packages/database/src/Builder/ModelInspector.php index 89712b5ba..be33d03d2 100644 --- a/packages/database/src/Builder/ModelInspector.php +++ b/packages/database/src/Builder/ModelInspector.php @@ -312,9 +312,11 @@ public function getRelations(): ImmutableArray $relationFields = arr(); foreach ($this->reflector->getPublicProperties() as $property) { - if (($relation = $this->getRelation($property->getName())) instanceof Relation) { - $relationFields[] = $relation; + if (! ($relation = $this->getRelation($property->getName())) instanceof Relation) { + continue; } + + $relationFields[] = $relation; } return $relationFields; diff --git a/packages/database/src/IsDatabaseModel.php b/packages/database/src/IsDatabaseModel.php index ebb837d6a..ba7eafd14 100644 --- a/packages/database/src/IsDatabaseModel.php +++ b/packages/database/src/IsDatabaseModel.php @@ -51,10 +51,7 @@ public function onDatabase(null|string|UnitEnum $databaseTag): self /** @return QueryBuilder */ protected static function queryBuilder(): QueryBuilder { - /** @var QueryBuilder $query */ - $query = query(self::class); - - return $query; + return query(self::class); } /** @@ -64,9 +61,7 @@ protected static function queryBuilder(): QueryBuilder */ public static function select(): SelectQueryBuilder { - $query = self::queryBuilder()->select(); - - return $query; + return self::queryBuilder()->select(); } /** diff --git a/packages/database/src/Migrations/MigrationManager.php b/packages/database/src/Migrations/MigrationManager.php index 3f8c31ec2..edc25a22c 100644 --- a/packages/database/src/Migrations/MigrationManager.php +++ b/packages/database/src/Migrations/MigrationManager.php @@ -329,8 +329,6 @@ private function getMinifiedSqlFromStatement(?QueryStatement $statement): string $sql = preg_replace('/\/\*[\s\S]*?\*\//', '', $sql); // Remove block comments // Remove blank lines and excessive spaces - $sql = preg_replace('/\s+/', ' ', trim($sql)); - - return $sql; + return preg_replace('/\s+/', ' ', trim($sql)); } } diff --git a/packages/database/src/Migrations/RunnableMigrations.php b/packages/database/src/Migrations/RunnableMigrations.php index c90a8de19..1fabaa706 100644 --- a/packages/database/src/Migrations/RunnableMigrations.php +++ b/packages/database/src/Migrations/RunnableMigrations.php @@ -36,9 +36,11 @@ public function getIterator(): Traversable public function up(): Traversable { foreach ($this->getIterator() as $migration) { - if ($migration instanceof MigratesUp) { - yield $migration; + if (! $migration instanceof MigratesUp) { + continue; } + + yield $migration; } } @@ -48,9 +50,11 @@ public function up(): Traversable public function down(): Traversable { foreach ($this->getIterator() as $migration) { - if ($migration instanceof MigratesDown) { - yield $migration; + if (! $migration instanceof MigratesDown) { + continue; } + + yield $migration; } } } diff --git a/packages/database/src/QueryStatements/CreateTableStatement.php b/packages/database/src/QueryStatements/CreateTableStatement.php index 3e759a985..28e9b2d6e 100644 --- a/packages/database/src/QueryStatements/CreateTableStatement.php +++ b/packages/database/src/QueryStatements/CreateTableStatement.php @@ -395,7 +395,7 @@ public function raw(string $statement): self public function compile(DatabaseDialect $dialect): string { - $createTable = sprintf( + return sprintf( 'CREATE TABLE %s (%s);', new TableDefinition($this->tableName), arr($this->statements) @@ -407,7 +407,5 @@ public function compile(DatabaseDialect $dialect): string ->wrap(before: PHP_EOL . ' ', after: PHP_EOL) ->toString(), ); - - return $createTable; } } diff --git a/packages/database/src/functions.php b/packages/database/src/functions.php index 73c135a17..423f93212 100644 --- a/packages/database/src/functions.php +++ b/packages/database/src/functions.php @@ -14,10 +14,7 @@ */ function query(string|object $model): QueryBuilder { - /** @var QueryBuilder $query */ - $query = new QueryBuilder($model); - - return $query; + return new QueryBuilder($model); } /** diff --git a/packages/datetime/src/SecondsStyle.php b/packages/datetime/src/SecondsStyle.php index ed6bb914a..5b2b82540 100644 --- a/packages/datetime/src/SecondsStyle.php +++ b/packages/datetime/src/SecondsStyle.php @@ -38,7 +38,7 @@ public static function fromTimestamp(Timestamp $timestamp): SecondsStyle return match (true) { $nanoseconds === 0 => static::Seconds, - ($nanoseconds % 1000000) === 0 => static::Milliseconds, + ($nanoseconds % 1_000_000) === 0 => static::Milliseconds, ($nanoseconds % 1000) === 0 => static::Microseconds, default => static::Nanoseconds, }; diff --git a/packages/datetime/src/functions.php b/packages/datetime/src/functions.php index 2fb6d6c88..40f83707b 100644 --- a/packages/datetime/src/functions.php +++ b/packages/datetime/src/functions.php @@ -6,14 +6,8 @@ use IntlDateFormatter; use IntlTimeZone; use RuntimeException; -use Tempest\DateTime\DateStyle; use Tempest\DateTime\Exception\OverflowException; use Tempest\DateTime\Exception\ParserException; -use Tempest\DateTime\FormatPattern; -use Tempest\DateTime\SecondsStyle; -use Tempest\DateTime\Timestamp; -use Tempest\DateTime\TimeStyle; -use Tempest\DateTime\Timezone; use Tempest\Intl\Locale; use ValueError; @@ -21,8 +15,6 @@ use function microtime; use function Tempest\Intl\current_locale; -use const Tempest\DateTime\NANOSECONDS_PER_SECOND; - /** * Get the current date and time as a {@see \Tempest\DateTime\DateTime} object. */ diff --git a/packages/datetime/tests/DateTimeTest.php b/packages/datetime/tests/DateTimeTest.php index ba7428573..26f1342e5 100644 --- a/packages/datetime/tests/DateTimeTest.php +++ b/packages/datetime/tests/DateTimeTest.php @@ -242,13 +242,13 @@ public function test_parse_icu(): void $parsed = DateTime::fromPattern('2025-01-01 10:00', pattern: 'yyyy-MM-dd HH:mm'); $this->assertEquals('2025-01-01 10:00', $parsed->format(pattern: 'yyyy-MM-dd HH:mm')); - $this->assertEquals(1735725600, $parsed->getTimestamp()->getSeconds()); + $this->assertEquals(1_735_725_600, $parsed->getTimestamp()->getSeconds()); } public function test_parse_timestamp(): void { - $expected = DateTime::fromTimestamp(1747670452940); - $parsed = DateTime::parse(1747670452940); + $expected = DateTime::fromTimestamp(1_747_670_452_940); + $parsed = DateTime::parse(1_747_670_452_940); $this->assertEquals($expected->getTimestamp(), $parsed->getTimestamp()); $this->assertSame($expected->getTimezone(), $parsed->getTimezone()); @@ -629,7 +629,7 @@ public function test_end_of_day(): void $this->assertSame(23, $new->getHours()); $this->assertSame(59, $new->getMinutes()); $this->assertSame(59, $new->getSeconds()); - $this->assertSame(999999999, $new->getNanoseconds()); + $this->assertSame(999_999_999, $new->getNanoseconds()); } public function test_start_of_week(): void @@ -696,7 +696,7 @@ public function test_convert_time_zone(): void public function test_is_same_year(): void { $date1 = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 12, 0, 0, 0); - $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999999999); + $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); $date3 = DateTime::fromParts(Timezone::default(), 2025, Month::JANUARY, 1, 0, 0, 0, 0); $this->assertTrue($date1->isSameYear($date2)); @@ -707,7 +707,7 @@ public function test_is_same_year(): void public function test_is_same_month(): void { $date1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 1, 12, 0, 0, 0); - $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 29, 23, 59, 59, 999999999); + $date2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 29, 23, 59, 59, 999_999_999); $date3 = DateTime::fromParts(Timezone::default(), 2024, Month::MARCH, 1, 0, 0, 0, 0); $date4 = DateTime::fromParts(Timezone::default(), 2025, Month::FEBRUARY, 15, 12, 0, 0, 0); @@ -733,7 +733,7 @@ public function test_is_same_week(): void public function test_is_same_day(): void { $morning = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 8, 30, 0, 0); - $evening = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 20, 45, 30, 123456789); + $evening = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 20, 45, 30, 123_456_789); $nextDay = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 8, 30, 0, 0); $this->assertTrue($morning->isSameDay($evening)); @@ -744,7 +744,7 @@ public function test_is_same_day(): void public function test_is_same_hour(): void { $time1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 15, 30, 0); - $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 45, 59, 999999999); + $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 45, 59, 999_999_999); $time3 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 15, 15, 30, 0); $differentDay = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 14, 15, 30, 0); @@ -757,7 +757,7 @@ public function test_is_same_hour(): void public function test_is_same_minute(): void { $time1 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 15, 0); - $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 45, 999999999); + $time2 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 30, 45, 999_999_999); $time3 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 14, 31, 15, 0); $differentHour = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 15, 30, 15, 0); @@ -770,7 +770,7 @@ public function test_is_same_minute(): void public function test_is_next_day(): void { $today = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $tomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 15, 30, 45, 123456789); + $tomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 6, 15, 30, 45, 123_456_789); $dayAfterTomorrow = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 7, 8, 0, 0, 0); $this->assertTrue($tomorrow->isNextDay($today)); @@ -782,7 +782,7 @@ public function test_is_next_day(): void public function test_is_previous_day(): void { $today = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $yesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 4, 8, 15, 30, 987654321); + $yesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 4, 8, 15, 30, 987_654_321); $dayBeforeYesterday = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 3, 20, 0, 0, 0); $this->assertTrue($yesterday->isPreviousDay($today)); @@ -846,9 +846,9 @@ public function test_is_last_day_of_month(): void public function test_is_first_day_of_year(): void { $newYearsDay = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 0, 0, 0, 0); - $newYearsDayDifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 23, 59, 59, 999999999); + $newYearsDayDifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 1, 23, 59, 59, 999_999_999); $secondDay = DateTime::fromParts(Timezone::default(), 2024, Month::JANUARY, 2, 0, 0, 0, 0); - $december31 = DateTime::fromParts(Timezone::default(), 2023, Month::DECEMBER, 31, 23, 59, 59, 999999999); + $december31 = DateTime::fromParts(Timezone::default(), 2023, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); $this->assertTrue($newYearsDay->isFirstDayOfYear()); $this->assertTrue($newYearsDayDifferentTime->isFirstDayOfYear()); @@ -859,8 +859,8 @@ public function test_is_first_day_of_year(): void public function test_is_last_day_of_year(): void { $december31 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 0, 0, 0, 0); - $december31DifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999999999); - $december30 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 30, 23, 59, 59, 999999999); + $december31DifferentTime = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 31, 23, 59, 59, 999_999_999); + $december30 = DateTime::fromParts(Timezone::default(), 2024, Month::DECEMBER, 30, 23, 59, 59, 999_999_999); $january1 = DateTime::fromParts(Timezone::default(), 2025, Month::JANUARY, 1, 0, 0, 0, 0); $this->assertTrue($december31->isLastDayOfYear()); @@ -917,13 +917,13 @@ public function test_time_of_day_methods(): void public function test_time_edge_cases(): void { - $boundary5_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 5, 59, 59, 999999999); + $boundary5_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 5, 59, 59, 999_999_999); $boundary6_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 6, 0, 0, 0); - $boundary11_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 11, 59, 59, 999999999); + $boundary11_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 11, 59, 59, 999_999_999); $boundary12_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 12, 0, 0, 0); - $boundary17_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 17, 59, 59, 999999999); + $boundary17_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 17, 59, 59, 999_999_999); $boundary18_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 18, 0, 0, 0); - $boundary21_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 21, 59, 59, 999999999); + $boundary21_59 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 21, 59, 59, 999_999_999); $boundary22_00 = DateTime::fromParts(Timezone::default(), 2024, Month::FEBRUARY, 5, 22, 0, 0, 0); $this->assertTrue($boundary5_59->isNight()); diff --git a/packages/datetime/tests/DurationTest.php b/packages/datetime/tests/DurationTest.php index 650e549e8..053de5a5c 100644 --- a/packages/datetime/tests/DurationTest.php +++ b/packages/datetime/tests/DurationTest.php @@ -49,13 +49,13 @@ public function test_named_constructors(): void } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 2.777777777777778E-13])] + #[TestWith([0, 0, 0, 1, 2.777_777_777_777_778E-13])] #[TestWith([1, 0, 0, 0, 1.0])] #[TestWith([1, 30, 0, 0, 1.5])] - #[TestWith([2, 15, 30, 0, 2.2583333333333333])] + #[TestWith([2, 15, 30, 0, 2.258_333_333_333_333_3])] #[TestWith([-1, 0, 0, 0, -1.0])] #[TestWith([-1, -30, 0, 0, -1.5])] - #[TestWith([-2, -15, -30, 0, -2.2583333333333333])] + #[TestWith([-2, -15, -30, 0, -2.258_333_333_333_333_3])] public function test_get_total_hours( int $hours, int $minutes, @@ -68,7 +68,7 @@ public function test_get_total_hours( } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 1.6666666666666667E-11])] + #[TestWith([0, 0, 0, 1, 1.666_666_666_666_666_7E-11])] #[TestWith([1, 0, 0, 0, 60.0])] #[TestWith([1, 30, 0, 0, 90.0])] #[TestWith([2, 15, 30, 0, 135.5])] @@ -82,7 +82,7 @@ public function test_get_total_minutes(int $hours, int $minutes, int $seconds, i } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 0.000000001])] + #[TestWith([0, 0, 0, 1, 0.000_000_001])] #[TestWith([1, 0, 0, 0, 3600.0])] #[TestWith([1, 30, 0, 0, 5400.0])] #[TestWith([2, 15, 30, 0, 8130.0])] @@ -96,13 +96,13 @@ public function test_get_total_seconds(int $hours, int $minutes, int $seconds, i } #[TestWith([0, 0, 0, 0, 0.0])] - #[TestWith([0, 0, 0, 1, 0.000001])] - #[TestWith([1, 0, 0, 0, 3600000.0])] - #[TestWith([1, 30, 0, 0, 5400000.0])] - #[TestWith([2, 15, 30, 0, 8130000.0])] - #[TestWith([-1, 0, 0, 0, -3600000.0])] - #[TestWith([-1, -30, 0, 0, -5400000.0])] - #[TestWith([-2, -15, -30, 0, -8130000.0])] + #[TestWith([0, 0, 0, 1, 0.000_001])] + #[TestWith([1, 0, 0, 0, 3_600_000.0])] + #[TestWith([1, 30, 0, 0, 5_400_000.0])] + #[TestWith([2, 15, 30, 0, 8_130_000.0])] + #[TestWith([-1, 0, 0, 0, -3_600_000.0])] + #[TestWith([-1, -30, 0, 0, -5_400_000.0])] + #[TestWith([-2, -15, -30, 0, -8_130_000.0])] public function test_get_total_milliseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMilliseconds): void { $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); @@ -111,12 +111,12 @@ public function test_get_total_milliseconds(int $hours, int $minutes, int $secon #[TestWith([0, 0, 0, 0, 0.0])] #[TestWith([0, 0, 0, 1, 0.001])] - #[TestWith([1, 0, 0, 0, 3600000000.0])] - #[TestWith([1, 30, 0, 0, 5400000000.0])] - #[TestWith([2, 15, 30, 0, 8130000000.0])] - #[TestWith([-1, 0, 0, 0, -3600000000.0])] - #[TestWith([-1, -30, 0, 0, -5400000000.0])] - #[TestWith([-2, -15, -30, 0, -8130000000.0])] + #[TestWith([1, 0, 0, 0, 3_600_000_000.0])] + #[TestWith([1, 30, 0, 0, 5_400_000_000.0])] + #[TestWith([2, 15, 30, 0, 8_130_000_000.0])] + #[TestWith([-1, 0, 0, 0, -3_600_000_000.0])] + #[TestWith([-1, -30, 0, 0, -5_400_000_000.0])] + #[TestWith([-2, -15, -30, 0, -8_130_000_000.0])] public function test_get_total_microseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMicroseconds): void { $time = Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); @@ -145,10 +145,10 @@ public function test_fractions_of_second(): void [0, 0, 1, 42], Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts(), ); - $this->assertSame([0, 0, 0, 42000], Duration::microseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42000], Duration::microseconds(1000042)->getParts()); - $this->assertSame([0, 0, 0, 42000000], Duration::milliseconds(42)->getParts()); - $this->assertSame([0, 0, 1, 42000000], Duration::milliseconds(1042)->getParts()); + $this->assertSame([0, 0, 0, 42_000], Duration::microseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42_000], Duration::microseconds(1_000_042)->getParts()); + $this->assertSame([0, 0, 0, 42_000_000], Duration::milliseconds(42)->getParts()); + $this->assertSame([0, 0, 1, 42_000_000], Duration::milliseconds(1042)->getParts()); } #[TestWith([0, 0, 0, 0])] @@ -272,15 +272,15 @@ public function test_operations(): void #[TestWith([0, 0, 0, 0, '0 second(s)'])] #[TestWith([0, 0, 0, 42, '0 second(s)'])] #[TestWith([0, 0, 1, 42, '1 second(s)'])] - #[TestWith([0, 0, 1, 20000000, '1.02 second(s)'])] + #[TestWith([0, 0, 1, 20_000_000, '1.02 second(s)'])] #[TestWith([1, 2, 0, 0, '1 hour(s), 2 minute(s)'])] #[TestWith([1, 0, 3, 0, '1 hour(s), 0 minute(s), 3 second(s)'])] #[TestWith([0, 2, 3, 0, '2 minute(s), 3 second(s)'])] #[TestWith([1, 2, 3, 0, '1 hour(s), 2 minute(s), 3 second(s)'])] - #[TestWith([1, 0, 0, 42000000, '1 hour(s), 0 minute(s), 0.042 second(s)'])] + #[TestWith([1, 0, 0, 42_000_000, '1 hour(s), 0 minute(s), 0.042 second(s)'])] #[TestWith([-42, 0, -42, 0, '-42 hour(s), 0 minute(s), -42 second(s)'])] - #[TestWith([-42, 0, -42, -420000000, '-42 hour(s), 0 minute(s), -42.42 second(s)'])] - #[TestWith([0, 0, 0, -420000000, '-0.42 second(s)'])] + #[TestWith([-42, 0, -42, -420_000_000, '-42 hour(s), 0 minute(s), -42.42 second(s)'])] + #[TestWith([0, 0, 0, -420_000_000, '-0.42 second(s)'])] public function test_to_string(int $h, int $m, int $s, int $ns, string $expected): void { $this->assertSame($expected, Duration::fromParts($h, $m, $s, $ns)->toString()); @@ -288,7 +288,7 @@ public function test_to_string(int $h, int $m, int $s, int $ns, string $expected public function test_serialization(): void { - $timeInterval = Duration::fromParts(1, 30, 45, 500000000); + $timeInterval = Duration::fromParts(1, 30, 45, 500_000_000); $serialized = serialize($timeInterval); $deserialized = unserialize($serialized); @@ -297,10 +297,10 @@ public function test_serialization(): void public function test_json_encoding(): void { - $timeInterval = Duration::fromParts(1, 30, 45, 500000000); + $timeInterval = Duration::fromParts(1, 30, 45, 500_000_000); $jsonEncoded = Json\encode($timeInterval); $jsonDecoded = Json\decode($jsonEncoded, associative: true); - $this->assertSame(['hours' => 1, 'minutes' => 30, 'seconds' => 45, 'nanoseconds' => 500000000], $jsonDecoded); + $this->assertSame(['hours' => 1, 'minutes' => 30, 'seconds' => 45, 'nanoseconds' => 500_000_000], $jsonDecoded); } } diff --git a/packages/datetime/tests/SecondsStyleTest.php b/packages/datetime/tests/SecondsStyleTest.php index a0efa3c9f..b2c092dbb 100644 --- a/packages/datetime/tests/SecondsStyleTest.php +++ b/packages/datetime/tests/SecondsStyleTest.php @@ -23,7 +23,7 @@ public static function provide_from_timestamp_data(): array { return [ [SecondsStyle::Seconds, Timestamp::fromParts(0)], - [SecondsStyle::Milliseconds, Timestamp::fromParts(0, 1000000)], + [SecondsStyle::Milliseconds, Timestamp::fromParts(0, 1_000_000)], [SecondsStyle::Microseconds, Timestamp::fromParts(0, 1000)], [SecondsStyle::Nanoseconds, Timestamp::fromParts(0, 1)], ]; diff --git a/packages/datetime/tests/TimestampTest.php b/packages/datetime/tests/TimestampTest.php index 297abff2a..42ba40ed5 100644 --- a/packages/datetime/tests/TimestampTest.php +++ b/packages/datetime/tests/TimestampTest.php @@ -144,50 +144,50 @@ public function test_parse_fails(): void public static function provide_format_parsing_data(): iterable { yield [ - 1711917897, + 1_711_917_897, FormatPattern::FULL_DATE_TIME, Timezone::UTC, Locale::ENGLISH, 'Sunday, March 31, 2024 20:44:57', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::FULL_DATE_TIME, Timezone::ASIA_SHANGHAI, Locale::CHINESE_TRADITIONAL, '星期一, 4月 01, 2024 04:44:57', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::COOKIE, Timezone::AMERICA_NEW_YORK, Locale::ENGLISH_UNITED_STATES, 'Sunday, 31-Mar-2024 16:44:57 EDT', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::HTTP, Timezone::EUROPE_VIENNA, Locale::GERMAN_AUSTRIA, 'So., 31 März 2024 22:44:57 MESZ', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::EMAIL, Timezone::EUROPE_MADRID, Locale::SPANISH_SPAIN, 'dom, 31 mar 2024 22:44:57 GMT+02:00', ]; yield [ - 1711917897, + 1_711_917_897, FormatPattern::SQL_DATE_TIME, Timezone::AFRICA_TUNIS, Locale::ARABIC_TUNISIA, '2024-03-31 21:44:57', ]; - yield [1711832400, FormatPattern::ISO_ORDINAL_DATE, Timezone::EUROPE_MOSCOW, Locale::RUSSIAN_RUSSIA, '2024-091']; + yield [1_711_832_400, FormatPattern::ISO_ORDINAL_DATE, Timezone::EUROPE_MOSCOW, Locale::RUSSIAN_RUSSIA, '2024-091']; yield [ - 1711917897, + 1_711_917_897, FormatPattern::ISO8601, Timezone::EUROPE_LONDON, Locale::ENGLISH_UNITED_KINGDOM, @@ -444,15 +444,15 @@ public function test_convert_to_timezone(): void public function test_json_serialization(): void { - $serialized = Timestamp::fromParts(1711917232, 12)->jsonSerialize(); + $serialized = Timestamp::fromParts(1_711_917_232, 12)->jsonSerialize(); - $this->assertSame(1711917232, $serialized['seconds']); + $this->assertSame(1_711_917_232, $serialized['seconds']); $this->assertSame(12, $serialized['nanoseconds']); } public function test_to_rfc3999(): void { - $timestamp = Timestamp::fromParts(1711917232, 12); + $timestamp = Timestamp::fromParts(1_711_917_232, 12); $this->assertSame('2024-03-31T20:33:52.12+00:00', $timestamp->toRfc3339()); $this->assertSame('2024-03-31T20:33:52+00:00', $timestamp->toRfc3339(secondsStyle: SecondsStyle::Seconds)); @@ -494,9 +494,9 @@ public function test_temporal_convenience_methods(): void public function test_at_the_same_time_edge_cases(): void { - $timestamp1 = Timestamp::fromParts(1234567890, 123456789); - $timestamp2 = Timestamp::fromParts(1234567890, 123456789); - $timestamp3 = Timestamp::fromParts(1234567890, 123456790); + $timestamp1 = Timestamp::fromParts(1_234_567_890, 123_456_789); + $timestamp2 = Timestamp::fromParts(1_234_567_890, 123_456_789); + $timestamp3 = Timestamp::fromParts(1_234_567_890, 123_456_790); $this->assertTrue($timestamp1->atTheSameTime($timestamp2)); $this->assertFalse($timestamp1->atTheSameTime($timestamp3)); @@ -547,9 +547,9 @@ public function test_between_time_reversed_parameters(): void public function test_nano_precision_temporal_comparisons(): void { - $base = Timestamp::fromParts(1234567890, 0); - $plusOneNano = Timestamp::fromParts(1234567890, 1); - $minusOneNano = Timestamp::fromParts(1234567889, 999999999); + $base = Timestamp::fromParts(1_234_567_890, 0); + $plusOneNano = Timestamp::fromParts(1_234_567_890, 1); + $minusOneNano = Timestamp::fromParts(1_234_567_889, 999_999_999); $this->assertTrue($base->isAfter($minusOneNano)); $this->assertTrue($base->isBefore($plusOneNano)); @@ -592,20 +592,20 @@ public function test_future_past_comprehensive(): void public function test_since_and_between_duration_methods(): void { - $start = Timestamp::fromParts(1000, 500000000); - $end = Timestamp::fromParts(1005, 750000000); + $start = Timestamp::fromParts(1000, 500_000_000); + $end = Timestamp::fromParts(1005, 750_000_000); $duration = $end->since($start); $this->assertSame(5, $duration->getSeconds()); - $this->assertSame(250000000, $duration->getNanoseconds()); + $this->assertSame(250_000_000, $duration->getNanoseconds()); $reverseDuration = $start->since($end); $this->assertSame(-5, $reverseDuration->getSeconds()); - $this->assertSame(-250000000, $reverseDuration->getNanoseconds()); + $this->assertSame(-250_000_000, $reverseDuration->getNanoseconds()); $betweenDuration = $start->between($end); $this->assertSame(-5, $betweenDuration->getSeconds()); - $this->assertSame(-250000000, $betweenDuration->getNanoseconds()); + $this->assertSame(-250_000_000, $betweenDuration->getNanoseconds()); $sameDuration = $start->since($start); $this->assertSame(0, $sameDuration->getSeconds()); @@ -614,8 +614,8 @@ public function test_since_and_between_duration_methods(): void public function test_temporal_comparison_with_large_values(): void { - $large1 = Timestamp::fromParts(9223372036, 999999999); - $large2 = Timestamp::fromParts(9223372036, 999999998); + $large1 = Timestamp::fromParts(9_223_372_036, 999_999_999); + $large2 = Timestamp::fromParts(9_223_372_036, 999_999_998); $this->assertTrue($large1->isAfter($large2)); $this->assertFalse($large1->isBefore($large2)); @@ -626,8 +626,8 @@ public function test_temporal_comparison_with_large_values(): void public function test_temporal_comparison_edge_case_overflow_boundary(): void { - $maxSeconds = Timestamp::fromParts(9223372036854775806, 0); - $nearMax = Timestamp::fromParts(9223372036854775805, 999999999); + $maxSeconds = Timestamp::fromParts(9_223_372_036_854_775_806, 0); + $nearMax = Timestamp::fromParts(9_223_372_036_854_775_805, 999_999_999); $this->assertTrue($maxSeconds->isAfter($nearMax)); $this->assertFalse($maxSeconds->isBefore($nearMax)); diff --git a/packages/datetime/tests/TimezoneTest.php b/packages/datetime/tests/TimezoneTest.php index 526e83a48..73d8ebca1 100644 --- a/packages/datetime/tests/TimezoneTest.php +++ b/packages/datetime/tests/TimezoneTest.php @@ -24,13 +24,13 @@ public function test_default(): void public function test_get_offset(): void { - $temporal = Timestamp::fromParts(seconds: 1716956903); + $temporal = Timestamp::fromParts(seconds: 1_716_956_903); $this->assertSame(3600., Timezone::EUROPE_LONDON->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(-14400., Timezone::AMERICA_NEW_YORK->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(28800., Timezone::ASIA_SHANGHAI->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(12600., Timezone::PLUS_0330->getOffset($temporal)->getTotalSeconds()); - $this->assertSame(-12600., Timezone::MINUS_0330->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(-14_400., Timezone::AMERICA_NEW_YORK->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(28_800., Timezone::ASIA_SHANGHAI->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(12_600., Timezone::PLUS_0330->getOffset($temporal)->getTotalSeconds()); + $this->assertSame(-12_600., Timezone::MINUS_0330->getOffset($temporal)->getTotalSeconds()); $this->assertSame(3600., Timezone::PLUS_0100->getOffset($temporal)->getTotalSeconds()); $this->assertSame(-3600., Timezone::MINUS_0100->getOffset($temporal)->getTotalSeconds()); @@ -45,8 +45,8 @@ public function test_get_offset(): void } #[TestWith([Timezone::EUROPE_LONDON, 0])] - #[TestWith([Timezone::AMERICA_NEW_YORK, -18000])] - #[TestWith([Timezone::ASIA_SHANGHAI, 28800])] + #[TestWith([Timezone::AMERICA_NEW_YORK, -18_000])] + #[TestWith([Timezone::ASIA_SHANGHAI, 28_800])] public function test_raw_offset(Timezone $timezone, int $expected): void { $this->assertSame($expected, (int) $timezone->getRawOffset()->getTotalSeconds()); diff --git a/packages/debug/tests/StacktraceTest.php b/packages/debug/tests/StacktraceTest.php index 6edf46f7b..5e78c6afd 100644 --- a/packages/debug/tests/StacktraceTest.php +++ b/packages/debug/tests/StacktraceTest.php @@ -213,9 +213,11 @@ public function stacktrace_uses_root_path_for_vendor_detection(): void $this->assertNotEmpty($frames); foreach ($frames as $frame) { - if (str_starts_with($frame->absoluteFile, $rootPath)) { - $this->assertFalse($frame->isVendor); + if (! str_starts_with($frame->absoluteFile, $rootPath)) { + continue; } + + $this->assertFalse($frame->isVendor); } } diff --git a/packages/event-bus/src/functions.php b/packages/event-bus/src/functions.php index 3869d85c1..01a7064ad 100644 --- a/packages/event-bus/src/functions.php +++ b/packages/event-bus/src/functions.php @@ -6,8 +6,6 @@ use Closure; use Tempest\Container; -use Tempest\EventBus\EventBus; -use Tempest\EventBus\EventBusConfig; /** * Dispatches the given `$event`, triggering all associated event listeners. diff --git a/packages/generation/src/Php/ManipulatesPhpClasses.php b/packages/generation/src/Php/ManipulatesPhpClasses.php index c4eeea3e8..fb9e1221f 100644 --- a/packages/generation/src/Php/ManipulatesPhpClasses.php +++ b/packages/generation/src/Php/ManipulatesPhpClasses.php @@ -89,9 +89,11 @@ public function removeClassAttribute(string $attributeName): self $attributes = $this->classType->getAttributes(); foreach ($attributes as $key => $attribute) { - if ($attribute->getName() === $attributeName) { - unset($attributes[$key]); + if ($attribute->getName() !== $attributeName) { + continue; } + + unset($attributes[$key]); } $this->classType->setAttributes($attributes); diff --git a/packages/generation/src/Php/SimplifiesClassNames.php b/packages/generation/src/Php/SimplifiesClassNames.php index 20aff5779..acd890ba5 100644 --- a/packages/generation/src/Php/SimplifiesClassNames.php +++ b/packages/generation/src/Php/SimplifiesClassNames.php @@ -136,9 +136,11 @@ function ($param) use (&$types): void { } foreach ($type->getTypes() as $subtype) { - if ($subtype->isClass() && ! $subtype->isClassKeyword()) { - $namespace->addUse((string) $subtype); + if (! ($subtype->isClass() && ! $subtype->isClassKeyword())) { + continue; } + + $namespace->addUse((string) $subtype); } } } diff --git a/packages/generation/src/Php/StubFileGenerator.php b/packages/generation/src/Php/StubFileGenerator.php index 5d636a602..32fac0ba8 100644 --- a/packages/generation/src/Php/StubFileGenerator.php +++ b/packages/generation/src/Php/StubFileGenerator.php @@ -8,7 +8,6 @@ use Tempest\Generation\Php\DataObjects\StubFile; use Tempest\Generation\Php\Exceptions\FileGenerationFailedException; use Tempest\Generation\Php\Exceptions\FileGenerationWasAborted; -use Tempest\Generation\Php\StubFileType; use Tempest\Support\Filesystem; use Tempest\Support\Str\ImmutableString; use Throwable; diff --git a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php index 127381d59..3005b5d52 100644 --- a/packages/generation/src/TypeScript/Writers/DirectoryWriter.php +++ b/packages/generation/src/TypeScript/Writers/DirectoryWriter.php @@ -88,24 +88,26 @@ private function collectImports(array $namespaces, TypeScriptOutput $output): ar foreach ($namespaces as $namespace => $definitions) { foreach ($definitions as $definition) { - if ($definition instanceof InterfaceDefinition) { - foreach ($definition->properties as $property) { - if ($property->fqcn === null) { - continue; - } - - $targetNamespace = Str\before_last($property->fqcn, '\\'); + if (! $definition instanceof InterfaceDefinition) { + continue; + } - if (in_array($targetNamespace, $currentNamespaces, strict: true)) { - continue; - } + foreach ($definition->properties as $property) { + if ($property->fqcn === null) { + continue; + } - $typeName = Str\after_last($property->fqcn, '\\'); - $importPath = $this->computeImportPath($namespace, $targetNamespace); - $importKey = "{$importPath}::{$typeName}"; + $targetNamespace = Str\before_last($property->fqcn, '\\'); - $imports[$importKey] ??= "import type { {$typeName} } from '{$importPath}';"; + if (in_array($targetNamespace, $currentNamespaces, strict: true)) { + continue; } + + $typeName = Str\after_last($property->fqcn, '\\'); + $importPath = $this->computeImportPath($namespace, $targetNamespace); + $importKey = "{$importPath}::{$typeName}"; + + $imports[$importKey] ??= "import type { {$typeName} } from '{$importPath}';"; } } } @@ -186,8 +188,6 @@ private function computeImportPath(string $sourceNamespace, string $targetNamesp $upPath = $upLevels > 0 ? str_repeat('../', $upLevels) : './'; $downPath = $targetKebab !== [] ? (string) Arr\implode($targetKebab, glue: '/') : ''; - $fullPath = rtrim($upPath . $downPath, '/'); - - return $fullPath; + return rtrim($upPath . $downPath, '/'); } } diff --git a/packages/http/src/Session/SessionIdResolverInitializer.php b/packages/http/src/Session/SessionIdResolverInitializer.php index 1fb27a9b2..72c9cc2de 100644 --- a/packages/http/src/Session/SessionIdResolverInitializer.php +++ b/packages/http/src/Session/SessionIdResolverInitializer.php @@ -11,7 +11,6 @@ use Tempest\Http\Cookie\CookieManager; use Tempest\Http\Request; use Tempest\Http\Session\Resolvers\CookieSessionIdResolver; -use Tempest\Http\Session\SessionConfig; final readonly class SessionIdResolverInitializer implements Initializer { diff --git a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php index bbc1d781c..b368c3a26 100644 --- a/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php +++ b/packages/http/tests/Mappers/PsrRequestToGenericRequestMapperTest.php @@ -146,8 +146,6 @@ private function createServerRequest(string $method, array $body = []): ServerRe } $stream = new Stream('php://temp', 'r+'); - $request = $request->withBody($stream); - - return $request; + return $request->withBody($stream); } } diff --git a/packages/idempotency/tests/IdempotencyMiddlewareTest.php b/packages/idempotency/tests/IdempotencyMiddlewareTest.php index e23fa37a4..90bfa0a8d 100644 --- a/packages/idempotency/tests/IdempotencyMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotencyMiddlewareTest.php @@ -455,7 +455,7 @@ public function takes_over_a_pending_record_owned_by_a_dead_process(): void key: 'stale-order', fingerprint: new RequestFingerprintGenerator()->generate($request), ttlInSeconds: 120, - pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99999999, 'stale-owner'), + pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99_999_999, 'stale-owner'), pendingHeartbeatAt: time(), ); diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index e0bf1d171..33850d36c 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -181,7 +181,7 @@ public function takes_over_a_pending_record_owned_by_a_dead_process(): void key: $fingerprint, fingerprint: $fingerprint, ttlInSeconds: 120, - pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99999999, 'stale-owner'), + pendingOwner: sprintf('%s|%d|%s', php_uname('n'), 99_999_999, 'stale-owner'), pendingHeartbeatAt: time(), ); diff --git a/packages/intl/src/GenericTranslator.php b/packages/intl/src/GenericTranslator.php index a8421b6df..ccf0df00a 100644 --- a/packages/intl/src/GenericTranslator.php +++ b/packages/intl/src/GenericTranslator.php @@ -4,8 +4,6 @@ use Tempest\EventBus\EventBus; use Tempest\Intl\Catalog\Catalog; -use Tempest\Intl\IntlConfig; -use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; use Throwable; diff --git a/packages/intl/src/IntlConfig.php b/packages/intl/src/IntlConfig.php index 2d141be77..d7e4ad2e9 100644 --- a/packages/intl/src/IntlConfig.php +++ b/packages/intl/src/IntlConfig.php @@ -2,7 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; use Tempest\Intl\MessageFormat\FormattingFunction; use Tempest\Intl\MessageFormat\MarkupFormatter; use Tempest\Intl\MessageFormat\SelectorFunction; diff --git a/packages/intl/src/PluralRules/PluralRulesMatcher.php b/packages/intl/src/PluralRules/PluralRulesMatcher.php index eb89ced57..3ed30faa4 100644 --- a/packages/intl/src/PluralRules/PluralRulesMatcher.php +++ b/packages/intl/src/PluralRules/PluralRulesMatcher.php @@ -57,7 +57,7 @@ private static function getCompactExponent(float|int $n): int $abs = abs($n); - if ($abs >= 1000000) { + if ($abs >= 1_000_000) { return 6; } @@ -518,7 +518,7 @@ private static function getPluralCategoryBr(float|int $n): string return 'few'; } - if (! self::isEqual($n, 0) && self::isEqual($n % 1000000, 0)) { + if (! self::isEqual($n, 0) && self::isEqual($n % 1_000_000, 0)) { return 'many'; } @@ -580,7 +580,7 @@ private static function getPluralCategoryCa(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -980,7 +980,7 @@ private static function getPluralCategoryEs(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -1132,7 +1132,7 @@ private static function getPluralCategoryFr(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -1639,7 +1639,7 @@ private static function getPluralCategoryIt(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -2098,8 +2098,8 @@ private static function getPluralCategoryKw(float|int $n): string || self::isEqual($n % 100, 62) || self::isEqual($n % 100, 82) || self::isEqual($n % 1000, 0) - && (self::inRange($n % 100000, 1000, 20000) || self::isEqual($n % 100000, 40000) || self::isEqual($n % 100000, 60000) || self::isEqual($n % 100000, 80000)) - || self::isEqual($n % 1000000, 100000) + && (self::inRange($n % 100_000, 1000, 20_000) || self::isEqual($n % 100_000, 40_000) || self::isEqual($n % 100_000, 60_000) || self::isEqual($n % 100_000, 80_000)) + || self::isEqual($n % 1_000_000, 100_000) ) { return 'two'; } @@ -2238,7 +2238,7 @@ private static function getPluralCategoryLld(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -2998,7 +2998,7 @@ private static function getPluralCategoryPt(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -3020,7 +3020,7 @@ private static function getPluralCategoryPt_PT(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -3216,7 +3216,7 @@ private static function getPluralCategoryScn(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } @@ -4150,7 +4150,7 @@ private static function getPluralCategoryVec(float|int $n): string return 'one'; } - if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1000000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { + if (self::isEqual($e, 0) && ! self::isEqual($i, 0) && self::isEqual($i % 1_000_000, 0) && self::isEqual($v, 0) || ! self::inRange($e, 0, 5)) { return 'many'; } diff --git a/packages/intl/src/TranslationFailure.php b/packages/intl/src/TranslationFailure.php index 726281858..8f1462559 100644 --- a/packages/intl/src/TranslationFailure.php +++ b/packages/intl/src/TranslationFailure.php @@ -2,7 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; use Throwable; final readonly class TranslationFailure diff --git a/packages/intl/src/TranslationMessageDiscovery.php b/packages/intl/src/TranslationMessageDiscovery.php index 9f3a88466..f0662fda3 100644 --- a/packages/intl/src/TranslationMessageDiscovery.php +++ b/packages/intl/src/TranslationMessageDiscovery.php @@ -8,7 +8,6 @@ use Tempest\Discovery\Discovery; use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; -use Tempest\Intl\Locale; use Tempest\Reflection\ClassReflector; use function Tempest\Support\arr; diff --git a/packages/intl/src/TranslationMiss.php b/packages/intl/src/TranslationMiss.php index 394a1647d..fe86fead2 100644 --- a/packages/intl/src/TranslationMiss.php +++ b/packages/intl/src/TranslationMiss.php @@ -2,8 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; - final readonly class TranslationMiss { public function __construct( diff --git a/packages/intl/src/Translator.php b/packages/intl/src/Translator.php index def5ead83..e4e25c316 100644 --- a/packages/intl/src/Translator.php +++ b/packages/intl/src/Translator.php @@ -2,8 +2,6 @@ namespace Tempest\Intl; -use Tempest\Intl\Locale; - interface Translator { /** diff --git a/packages/intl/src/TranslatorInitializer.php b/packages/intl/src/TranslatorInitializer.php index 477b7a77d..4f1a1cbbe 100644 --- a/packages/intl/src/TranslatorInitializer.php +++ b/packages/intl/src/TranslatorInitializer.php @@ -7,7 +7,6 @@ use Tempest\Container\Singleton; use Tempest\EventBus\EventBus; use Tempest\Intl\Catalog\Catalog; -use Tempest\Intl\IntlConfig; use Tempest\Intl\MessageFormat\Formatter\MessageFormatter; final class TranslatorInitializer implements Initializer diff --git a/packages/intl/src/functions.php b/packages/intl/src/functions.php index 768d7ce0d..ac45bd815 100644 --- a/packages/intl/src/functions.php +++ b/packages/intl/src/functions.php @@ -5,9 +5,7 @@ use Countable; use Stringable; use Tempest\Container\GenericContainer; -use Tempest\Intl\Locale; use Tempest\Intl\Pluralizer\Pluralizer; -use Tempest\Intl\Translator; use function Tempest\Container\get; diff --git a/packages/intl/tests/FunctionsTest.php b/packages/intl/tests/FunctionsTest.php index 3d3c1914d..1bce00620 100644 --- a/packages/intl/tests/FunctionsTest.php +++ b/packages/intl/tests/FunctionsTest.php @@ -21,12 +21,12 @@ public function test_format_number(): void $this->assertSame('10', Number\format(10)); $this->assertSame('25', Number\format(25)); $this->assertSame('100', Number\format(100)); - $this->assertSame('100,000', Number\format(100000)); - $this->assertSame('100,000.00', Number\format(100000, precision: 2)); - $this->assertSame('100,000.12', Number\format(100000.123, precision: 2)); - $this->assertSame('100,000.123', Number\format(100000.1234, maxPrecision: 3)); - $this->assertSame('100,000.124', Number\format(100000.1236, maxPrecision: 3)); - $this->assertSame('123,456,789', Number\format(123456789)); + $this->assertSame('100,000', Number\format(100_000)); + $this->assertSame('100,000.00', Number\format(100_000, precision: 2)); + $this->assertSame('100,000.12', Number\format(100_000.123, precision: 2)); + $this->assertSame('100,000.123', Number\format(100_000.123_4, maxPrecision: 3)); + $this->assertSame('100,000.124', Number\format(100_000.123_6, maxPrecision: 3)); + $this->assertSame('123,456,789', Number\format(123_456_789)); $this->assertSame('-1', Number\format(-1)); $this->assertSame('-10', Number\format(-10)); @@ -77,8 +77,8 @@ public function test_spellout_with_threshold(): void $this->assertSame('10', Number\spell_out(10, until: 10)); $this->assertSame('11', Number\spell_out(11, until: 10)); - $this->assertSame('ten thousand', Number\spell_out(10000, until: 50000)); - $this->assertSame('100,000', Number\spell_out(100000, until: 50000)); + $this->assertSame('ten thousand', Number\spell_out(10_000, until: 50_000)); + $this->assertSame('100,000', Number\spell_out(100_000, until: 50_000)); } #[RequiresPhpExtension('intl')] @@ -114,10 +114,10 @@ public function test_to_percent(): void $this->assertSame('2%', Number\to_percentage(1.75)); $this->assertSame('1.75%', Number\to_percentage(1.75, precision: 2)); $this->assertSame('1.750%', Number\to_percentage(1.75, precision: 3)); - $this->assertSame('0%', Number\to_percentage(0.12345)); + $this->assertSame('0%', Number\to_percentage(0.123_45)); $this->assertSame('0.00%', Number\to_percentage(0, precision: 2)); - $this->assertSame('0.12%', Number\to_percentage(0.12345, precision: 2)); - $this->assertSame('0.1235%', Number\to_percentage(0.12345, precision: 4)); + $this->assertSame('0.12%', Number\to_percentage(0.123_45, precision: 2)); + $this->assertSame('0.1235%', Number\to_percentage(0.123_45, precision: 4)); } #[RequiresPhpExtension('intl')] @@ -147,8 +147,8 @@ public function test_to_currency_with_different_locale(): void $this->assertSame('1,00 $', Number\currency(1, Currency::USD, Locale::GERMAN)); $this->assertSame('1,00 £', Number\currency(1, Currency::GBP, Locale::GERMAN)); - $this->assertSame('123.456.789,12 $', Number\currency(123456789.12345, Currency::USD, Locale::GERMAN)); - $this->assertSame('123.456.789,12 €', Number\currency(123456789.12345, Currency::EUR, Locale::GERMAN)); + $this->assertSame('123.456.789,12 $', Number\currency(123_456_789.123_45, Currency::USD, Locale::GERMAN)); + $this->assertSame('123.456.789,12 €', Number\currency(123_456_789.123_45, Currency::EUR, Locale::GERMAN)); $this->assertSame('1 234,56 $US', Number\currency(1234.56, Currency::USD, Locale::FRENCH)); } @@ -180,7 +180,7 @@ public function test_bytes_to_human(): void $this->assertSame('2 KiB', Number\to_file_size(2048, useBinaryPrefix: true)); $this->assertSame('2.00 KiB', Number\to_file_size(2048, precision: 2, useBinaryPrefix: true)); $this->assertSame('1.23 KiB', Number\to_file_size(1264, precision: 2, useBinaryPrefix: true)); - $this->assertSame('1.234 KiB', Number\to_file_size(1264.12345, maxPrecision: 3, useBinaryPrefix: true)); + $this->assertSame('1.234 KiB', Number\to_file_size(1_264.123_45, maxPrecision: 3, useBinaryPrefix: true)); $this->assertSame('1.234 KiB', Number\to_file_size(1264, 3, useBinaryPrefix: true)); $this->assertSame('5 GiB', Number\to_file_size(1024 * 1024 * 1024 * 5, useBinaryPrefix: true)); $this->assertSame('10 TiB', Number\to_file_size((1024 ** 4) * 10, useBinaryPrefix: true)); @@ -204,31 +204,31 @@ public function test_summarize(): void $this->assertSame('1K', Number\to_human_readable(1000, maxPrecision: 2)); $this->assertSame('1K', Number\to_human_readable(1230)); $this->assertSame('1.2K', Number\to_human_readable(1230, maxPrecision: 1)); - $this->assertSame('1M', Number\to_human_readable(1000000)); - $this->assertSame('1B', Number\to_human_readable(1000000000)); - $this->assertSame('1T', Number\to_human_readable(1000000000000)); - $this->assertSame('1Q', Number\to_human_readable(1000000000000000)); - $this->assertSame('1KQ', Number\to_human_readable(1000000000000000000)); + $this->assertSame('1M', Number\to_human_readable(1_000_000)); + $this->assertSame('1B', Number\to_human_readable(1_000_000_000)); + $this->assertSame('1T', Number\to_human_readable(1_000_000_000_000)); + $this->assertSame('1Q', Number\to_human_readable(1_000_000_000_000_000)); + $this->assertSame('1KQ', Number\to_human_readable(1_000_000_000_000_000_000)); $this->assertSame('123', Number\to_human_readable(123)); $this->assertSame('1K', Number\to_human_readable(1234)); $this->assertSame('1.23K', Number\to_human_readable(1234, precision: 2)); - $this->assertSame('12K', Number\to_human_readable(12345)); - $this->assertSame('1M', Number\to_human_readable(1234567)); - $this->assertSame('1B', Number\to_human_readable(1234567890)); - $this->assertSame('1T', Number\to_human_readable(1234567890123)); - $this->assertSame('1.23T', Number\to_human_readable(1234567890123, precision: 2)); - $this->assertSame('1Q', Number\to_human_readable(1234567890123456)); - $this->assertSame('1.23KQ', Number\to_human_readable(1234567890123456789, precision: 2)); - $this->assertSame('490K', Number\to_human_readable(489939)); - $this->assertSame('489.9390K', Number\to_human_readable(489939, precision: 4)); - $this->assertSame('500.00000M', Number\to_human_readable(500000000, precision: 5)); - - $this->assertSame('1MQ', Number\to_human_readable(1000000000000000000000)); - $this->assertSame('1BQ', Number\to_human_readable(1000000000000000000000000)); - $this->assertSame('1TQ', Number\to_human_readable(1000000000000000000000000000)); - $this->assertSame('1QQ', Number\to_human_readable(1000000000000000000000000000000)); - $this->assertSame('1KQQ', Number\to_human_readable(1000000000000000000000000000000000)); + $this->assertSame('12K', Number\to_human_readable(12_345)); + $this->assertSame('1M', Number\to_human_readable(1_234_567)); + $this->assertSame('1B', Number\to_human_readable(1_234_567_890)); + $this->assertSame('1T', Number\to_human_readable(1_234_567_890_123)); + $this->assertSame('1.23T', Number\to_human_readable(1_234_567_890_123, precision: 2)); + $this->assertSame('1Q', Number\to_human_readable(1_234_567_890_123_456)); + $this->assertSame('1.23KQ', Number\to_human_readable(1_234_567_890_123_456_789, precision: 2)); + $this->assertSame('490K', Number\to_human_readable(489_939)); + $this->assertSame('489.9390K', Number\to_human_readable(489_939, precision: 4)); + $this->assertSame('500.00000M', Number\to_human_readable(500_000_000, precision: 5)); + + $this->assertSame('1MQ', Number\to_human_readable(1_000_000_000_000_000_000_000)); + $this->assertSame('1BQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000)); + $this->assertSame('1TQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000)); + $this->assertSame('1QQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000_000)); + $this->assertSame('1KQQ', Number\to_human_readable(1_000_000_000_000_000_000_000_000_000_000_000)); $this->assertSame('0', Number\to_human_readable(0)); $this->assertSame('0', Number\to_human_readable(0.0)); @@ -241,12 +241,12 @@ public function test_summarize(): void $this->assertSame('-1K', Number\to_human_readable(-1000)); $this->assertSame('-1.23K', Number\to_human_readable(-1234, precision: 2)); $this->assertSame('-1.2K', Number\to_human_readable(-1234, maxPrecision: 1)); - $this->assertSame('-1M', Number\to_human_readable(-1000000)); - $this->assertSame('-1B', Number\to_human_readable(-1000000000)); - $this->assertSame('-1T', Number\to_human_readable(-1000000000000)); - $this->assertSame('-1.1T', Number\to_human_readable(-1100000000000, maxPrecision: 1)); - $this->assertSame('-1Q', Number\to_human_readable(-1000000000000000)); - $this->assertSame('-1KQ', Number\to_human_readable(-1000000000000000000)); + $this->assertSame('-1M', Number\to_human_readable(-1_000_000)); + $this->assertSame('-1B', Number\to_human_readable(-1_000_000_000)); + $this->assertSame('-1T', Number\to_human_readable(-1_000_000_000_000)); + $this->assertSame('-1.1T', Number\to_human_readable(-1_100_000_000_000, maxPrecision: 1)); + $this->assertSame('-1Q', Number\to_human_readable(-1_000_000_000_000_000)); + $this->assertSame('-1KQ', Number\to_human_readable(-1_000_000_000_000_000_000)); } public function test_parse_int(): void diff --git a/packages/intl/tests/LocaleTest.php b/packages/intl/tests/LocaleTest.php index 2060115d6..79c3d5715 100644 --- a/packages/intl/tests/LocaleTest.php +++ b/packages/intl/tests/LocaleTest.php @@ -175,9 +175,11 @@ public function test_it_returns_the_language_and_human_readable_name(Locale $loc public static function getLocalesWithScript(): Generator { foreach (Locale::cases() as $locale) { - if ($locale->hasScript()) { - yield $locale->value => [$locale]; + if (! $locale->hasScript()) { + continue; } + + yield $locale->value => [$locale]; } return null; @@ -196,9 +198,11 @@ public function test_it_returns_the_script(Locale $locale): void public static function getLocalesWithoutScript(): Generator { foreach (Locale::cases() as $locale) { - if (! $locale->hasScript()) { - yield $locale->value => [$locale]; + if ($locale->hasScript()) { + continue; } + + yield $locale->value => [$locale]; } return null; @@ -217,9 +221,11 @@ public function test_it_does_not_returns_the_script(Locale $locale): void public static function getLocalesWithRegion(): Generator { foreach (Locale::cases() as $locale) { - if ($locale->hasRegion()) { - yield $locale->value => [$locale]; + if (! $locale->hasRegion()) { + continue; } + + yield $locale->value => [$locale]; } return null; @@ -239,9 +245,11 @@ public function test_it_returns_the_region(Locale $locale): void public static function getLocalesWithoutRegion(): Generator { foreach (Locale::cases() as $locale) { - if (! $locale->hasRegion()) { - yield $locale->value => [$locale]; + if ($locale->hasRegion()) { + continue; } + + yield $locale->value => [$locale]; } return null; diff --git a/packages/log/src/TailLogsCommand.php b/packages/log/src/TailLogsCommand.php index 434909129..c3d36f623 100644 --- a/packages/log/src/TailLogsCommand.php +++ b/packages/log/src/TailLogsCommand.php @@ -11,7 +11,6 @@ use Tempest\Container\Tag; use Tempest\Highlight\Highlighter; use Tempest\Log\Channels\AppendLogChannel; -use Tempest\Log\LogConfig; use Tempest\Support\Filesystem; final readonly class TailLogsCommand diff --git a/packages/mail/src/MailerInitializer.php b/packages/mail/src/MailerInitializer.php index 3a5da65eb..3869579ac 100644 --- a/packages/mail/src/MailerInitializer.php +++ b/packages/mail/src/MailerInitializer.php @@ -6,7 +6,6 @@ use Tempest\Container\Initializer; use Tempest\Container\Singleton; use Tempest\EventBus\EventBus; -use Tempest\Mail\MailerConfig; final class MailerInitializer implements Initializer { diff --git a/packages/mail/src/Testing/MailTester.php b/packages/mail/src/Testing/MailTester.php index 0dc014b71..c56980685 100644 --- a/packages/mail/src/Testing/MailTester.php +++ b/packages/mail/src/Testing/MailTester.php @@ -369,13 +369,15 @@ public function assertAttached(string $filename, ?Closure $callback = null): sel ); foreach ($attachments as $attachment) { - if ($attachment->getFilename() === $filename) { - if ($callback && $callback(new AttachmentTester($attachment)) === false) { - Assert::fail(sprintf('The assertion callback returned `false` for attachment `%s`.', $filename)); - } + if ($attachment->getFilename() !== $filename) { + continue; + } - return $this; + if ($callback && $callback(new AttachmentTester($attachment)) === false) { + Assert::fail(sprintf('The assertion callback returned `false` for attachment `%s`.', $filename)); } + + return $this; } Assert::fail(sprintf( diff --git a/packages/mapper/src/Mappers/ObjectToArrayMapper.php b/packages/mapper/src/Mappers/ObjectToArrayMapper.php index 72083e0f7..675d1c012 100644 --- a/packages/mapper/src/Mappers/ObjectToArrayMapper.php +++ b/packages/mapper/src/Mappers/ObjectToArrayMapper.php @@ -65,9 +65,11 @@ private function resolvePropertyValue(PropertyReflector $property, object $objec if ($property->getIterableType()?->isClass()) { foreach ($propertyValue as $key => $value) { - if (is_object($value)) { - $propertyValue[$key] = map($value)->toArray(); + if (! is_object($value)) { + continue; } + + $propertyValue[$key] = map($value)->toArray(); } return $propertyValue; diff --git a/packages/mapper/src/functions.php b/packages/mapper/src/functions.php index 59aeb2f29..1329d2398 100644 --- a/packages/mapper/src/functions.php +++ b/packages/mapper/src/functions.php @@ -5,7 +5,6 @@ namespace Tempest\Mapper; use Tempest\Container; -use Tempest\Mapper\ObjectFactory; /** * Creates a factory which allows instantiating `$objectOrClass` with the data specified by the {@see \Tempest\Mapper\ObjectFactory::from()} method. diff --git a/packages/process/src/Testing/InvokedTestingProcess.php b/packages/process/src/Testing/InvokedTestingProcess.php index a9180d4aa..5044ebf1e 100644 --- a/packages/process/src/Testing/InvokedTestingProcess.php +++ b/packages/process/src/Testing/InvokedTestingProcess.php @@ -43,9 +43,11 @@ final class InvokedTestingProcess implements InvokedProcess $output = []; for ($i = 0; $i < $this->nextOutputIndex; $i++) { - if ($this->description->output[$i]['type'] === OutputChannel::OUTPUT) { - $output[] = $this->description->output[$i]['buffer']; + if ($this->description->output[$i]['type'] !== OutputChannel::OUTPUT) { + continue; } + + $output[] = $this->description->output[$i]['buffer']; } return rtrim(implode('', $output), "\n") . "\n"; @@ -59,9 +61,11 @@ final class InvokedTestingProcess implements InvokedProcess $output = []; for ($i = 0; $i < $this->nextErrorOutputIndex; $i++) { - if ($this->description->output[$i]['type'] === OutputChannel::ERROR) { - $output[] = $this->description->output[$i]['buffer']; + if ($this->description->output[$i]['type'] !== OutputChannel::ERROR) { + continue; } + + $output[] = $this->description->output[$i]['buffer']; } return rtrim(implode('', $output), "\n") . "\n"; diff --git a/packages/process/src/Testing/ProcessTester.php b/packages/process/src/Testing/ProcessTester.php index f08d5d3f1..f000ef21d 100644 --- a/packages/process/src/Testing/ProcessTester.php +++ b/packages/process/src/Testing/ProcessTester.php @@ -247,9 +247,11 @@ public function assertRanTimes(string|Closure $command, int $times): self $count = 0; foreach ($this->executor->executions as $executions) { foreach ($executions as [$process, $result]) { - if ($command($process, $result) === true) { - $count++; + if ($command($process, $result) !== true) { + continue; } + + $count++; } } } else { // @mago-expects linter:no-else-clause @@ -275,9 +277,11 @@ private function findExecutionsByPattern(string $pattern): array $executions = []; foreach ($this->executor->executions as $command => $commandExecutions) { - if ($this->executor->commandMatchesPattern($command, $pattern)) { - $executions[] = $commandExecutions; + if (! $this->executor->commandMatchesPattern($command, $pattern)) { + continue; } + + $executions[] = $commandExecutions; } return Arr\flatten($executions, depth: 1); diff --git a/packages/reflection/src/functions.php b/packages/reflection/src/functions.php index 20f07a96e..ee66d5e29 100644 --- a/packages/reflection/src/functions.php +++ b/packages/reflection/src/functions.php @@ -6,8 +6,6 @@ use ReflectionClass as PHPReflectionClass; use ReflectionProperty as PHPReflectionProperty; -use Tempest\Reflection\ClassReflector; -use Tempest\Reflection\PropertyReflector; /** * Creates a new {@see Reflector} instance based on the given `$classOrProperty`. diff --git a/packages/reflection/tests/Fixtures/NoReturnType.php b/packages/reflection/tests/Fixtures/NoReturnType.php index bf5dbbb1d..9d686184c 100644 --- a/packages/reflection/tests/Fixtures/NoReturnType.php +++ b/packages/reflection/tests/Fixtures/NoReturnType.php @@ -6,7 +6,6 @@ final class NoReturnType { - // @mago-expect lint:return-type public function noReturnType() { return 2137; diff --git a/packages/router/src/Exceptions/HtmlExceptionRenderer.php b/packages/router/src/Exceptions/HtmlExceptionRenderer.php index fb1bf0345..ed5b1f0be 100644 --- a/packages/router/src/Exceptions/HtmlExceptionRenderer.php +++ b/packages/router/src/Exceptions/HtmlExceptionRenderer.php @@ -159,9 +159,11 @@ private function filterSensitiveFields(Request $request, ?string $targetClass): $reflector = new ClassReflector($targetClass); foreach ($reflector->getPublicProperties() as $property) { - if ($property->hasAttribute(SensitiveField::class)) { - unset($body[$property->getName()]); + if (! $property->hasAttribute(SensitiveField::class)) { + continue; } + + unset($body[$property->getName()]); } return $body; diff --git a/packages/router/src/MatchRouteMiddleware.php b/packages/router/src/MatchRouteMiddleware.php index 901f7b68f..efef027ac 100644 --- a/packages/router/src/MatchRouteMiddleware.php +++ b/packages/router/src/MatchRouteMiddleware.php @@ -56,12 +56,13 @@ private function resolveRequest(Request $request, MatchedRoute $matchedRoute): R // We'll loop over all the handler's parameters foreach ($matchedRoute->route->handler->getParameters() as $parameter) { // If the parameter's type is an instance of Request… - if ($parameter->getType()->matches(Request::class)) { - // We'll use that specific request class - $requestClass = $parameter->getType()->getName(); - - break; + if (! $parameter->getType()->matches(Request::class)) { + continue; } + + $requestClass = $parameter->getType()->getName(); + + break; } if ($requestClass !== Request::class && $requestClass !== GenericRequest::class) { diff --git a/packages/router/src/RouteBindingInitializer.php b/packages/router/src/RouteBindingInitializer.php index b9f3b00fc..027e83d49 100644 --- a/packages/router/src/RouteBindingInitializer.php +++ b/packages/router/src/RouteBindingInitializer.php @@ -24,11 +24,13 @@ public function initialize(ClassReflector $class, null|string|UnitEnum $tag, Con $parameter = null; foreach ($matchedRoute->route->handler->getParameters() as $searchParameter) { - if ($searchParameter->getType()->equals($class->getType())) { - $parameter = $searchParameter; - - break; + if (! $searchParameter->getType()->equals($class->getType())) { + continue; } + + $parameter = $searchParameter; + + break; } if ($parameter === null) { diff --git a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php index aea61940a..d526eca01 100644 --- a/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php +++ b/packages/router/src/Routing/Construction/RouteMatchingRegexBuilder.php @@ -9,7 +9,7 @@ final readonly class RouteMatchingRegexBuilder { // This limit is guesstimated using a small script with an ever in pattern feed into preg_match - private const int PREG_REGEX_SIZE_LIMIT = 32768; + private const int PREG_REGEX_SIZE_LIMIT = 32_768; private const int REGEX_SIZE_MARGIN = 256; diff --git a/packages/router/src/Static/StaticCleanCommand.php b/packages/router/src/Static/StaticCleanCommand.php index a85a569a4..057fd0f75 100644 --- a/packages/router/src/Static/StaticCleanCommand.php +++ b/packages/router/src/Static/StaticCleanCommand.php @@ -56,9 +56,11 @@ private function removeFiles(RecursiveDirectoryIterator $directoryIterator): voi /** @var SplFileInfo $file */ foreach (new RecursiveIteratorIterator($directoryIterator) as $file) { - if ($file->getExtension() === 'html') { - $files[] = $file; + if ($file->getExtension() !== 'html') { + continue; } + + $files[] = $file; } foreach ($files as $file) { diff --git a/packages/router/src/functions.php b/packages/router/src/functions.php index 083c5f837..fa96034e9 100644 --- a/packages/router/src/functions.php +++ b/packages/router/src/functions.php @@ -7,7 +7,6 @@ use Tempest\DateTime\DateTime; use Tempest\DateTime\Duration; use Tempest\Reflection\MethodReflector; -use Tempest\Router\UriGenerator; use function Tempest\Container\get; diff --git a/packages/support/src/Arr/functions.php b/packages/support/src/Arr/functions.php index 8c80d9cde..e4ab61dbf 100644 --- a/packages/support/src/Arr/functions.php +++ b/packages/support/src/Arr/functions.php @@ -63,9 +63,7 @@ function chunk(iterable $array, int $size, bool $preserveKeys = true): array } $chunks = []; - $chunks = array_chunk($array, $size, $preserveKeys); - - return $chunks; + return array_chunk($array, $size, $preserveKeys); } /** @@ -201,9 +199,11 @@ function forget_values(array &$array, mixed $values): array $values = is_array($values) ? $values : [$values]; foreach ($values as $value) { - if (! is_null($key = array_find_key($array, fn (mixed $match) => $value === $match))) { - unset($array[$key]); + if (is_null($key = array_find_key($array, fn (mixed $match) => $value === $match))) { + continue; } + + unset($array[$key]); } return $array; @@ -755,10 +755,7 @@ function implode(iterable $array, string $glue): ImmutableString */ function keys(iterable $array): array { - /** @var list $result */ - $result = array_keys(to_array($array)); - - return $result; + return array_keys(to_array($array)); } /** @@ -773,10 +770,7 @@ function keys(iterable $array): array */ function values(iterable $array): array { - /** @var list $result */ - $result = array_values(to_array($array)); - - return $result; + return array_values(to_array($array)); } /** @@ -797,9 +791,11 @@ function filter(iterable $array, ?Closure $filter = null): array $filter ??= static fn (mixed $value, mixed $_) => ! in_array($value, [false, null], strict: true); foreach (to_array($array) as $key => $value) { - if ($filter($value, $key)) { - $result[$key] = $value; + if (! $filter($value, $key)) { + continue; } + + $result[$key] = $value; } return $result; @@ -1533,9 +1529,11 @@ function to_array(mixed $input): array $result = []; for ($i = 0; $i < $count; $i++) { - if (isset($input[$i])) { - $result[$i] = $input[$i]; + if (! isset($input[$i])) { + continue; } + + $result[$i] = $input[$i]; } return $result; diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php index 54e0cb013..73d53c7af 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeDecoded.php @@ -5,6 +5,5 @@ namespace Tempest\Support\Json\Exception; use InvalidArgumentException; -use Tempest\Support\Json\Exception\JsonException; final class JsonCouldNotBeDecoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php index 643d92ddd..9148a3c7b 100644 --- a/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php +++ b/packages/support/src/Json/Exception/JsonCouldNotBeEncoded.php @@ -5,6 +5,5 @@ namespace Tempest\Support\Json\Exception; use InvalidArgumentException; -use Tempest\Support\Json\Exception\JsonException; final class JsonCouldNotBeEncoded extends InvalidArgumentException implements JsonException {} diff --git a/packages/support/src/Math/constants.php b/packages/support/src/Math/constants.php index 8d296b290..3c6f7b403 100644 --- a/packages/support/src/Math/constants.php +++ b/packages/support/src/Math/constants.php @@ -26,21 +26,21 @@ * * @var float */ -const E = 2.7182818284590452353602875; +const E = 2.718_281_828_459_045_235_360_287_5; /** * The ratio of the circumference of a circle to its diameter, or approximately 3.141592653589793238462643. * * @var float */ -const PI = 3.141592653589793238462643; +const PI = 3.141_592_653_589_793_238_462_643; /** * The maximum integer value representable in a 64-bit binary-coded decimal. * * @var int */ -const INT64_MAX = 9223372036854775807; +const INT64_MAX = 9_223_372_036_854_775_807; /** * The minimum integer value representable in a 64-bit binary-coded decimal. @@ -54,42 +54,42 @@ * * @var int */ -const INT53_MAX = 9007199254740992; +const INT53_MAX = 9_007_199_254_740_992; /** * The minimum integer value representable in a 53-bit binary-coded decimal. * * @var int */ -const INT53_MIN = -9007199254740993; +const INT53_MIN = -9_007_199_254_740_993; /** * The maximum integer value representable in a 32-bit binary-coded decimal. * * @var int */ -const INT32_MAX = 2147483647; +const INT32_MAX = 2_147_483_647; /** * The minimum integer value representable in a 32-bit binary-coded decimal. * * @var int */ -const INT32_MIN = -2147483648; +const INT32_MIN = -2_147_483_648; /** * The maximum integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const INT16_MAX = 32767; +const INT16_MAX = 32_767; /** * The minimum integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const INT16_MIN = -32768; +const INT16_MIN = -32_768; /** * The maximum integer value representable in a 8-bit binary-coded decimal. @@ -110,14 +110,14 @@ * * @var int */ -const UINT32_MAX = 4294967295; +const UINT32_MAX = 4_294_967_295; /** * The maximum unsigned integer value representable in a 16-bit binary-coded decimal. * * @var int */ -const UINT16_MAX = 65535; +const UINT16_MAX = 65_535; /** * The maximum unsigned integer value representable in a 8-bit binary-coded decimal. @@ -131,25 +131,25 @@ * * @var float */ -const FLOAT32_MAX = 3.40282347E+38; +const FLOAT32_MAX = 3.402_823_47E+38; /** * The minimum floating point value representable in a 32-bit binary-coded decimal. * * @var float */ -const FLOAT32_MIN = -3.40282347E+38; +const FLOAT32_MIN = -3.402_823_47E+38; /** * The maximum floating point value representable in a 64-bit binary-coded decimal. * * @var float */ -const FLOAT64_MAX = 1.7976931348623157E+308; +const FLOAT64_MAX = 1.797_693_134_862_315_7E+308; /** * The minimum floating point value representable in a 64-bit binary-coded decimal. * * @var float */ -const FLOAT64_MIN = -1.7976931348623157E+308; +const FLOAT64_MIN = -1.797_693_134_862_315_7E+308; diff --git a/packages/support/src/Math/functions.php b/packages/support/src/Math/functions.php index 853d7163f..298464ae4 100644 --- a/packages/support/src/Math/functions.php +++ b/packages/support/src/Math/functions.php @@ -360,9 +360,11 @@ function max(array $numbers): null|int|float $max = null; foreach ($numbers as $number) { - if (null === $max || $number > $max) { - $max = $number; + if (null !== $max && $number <= $max) { + continue; } + + $max = $number; } return $max; @@ -384,9 +386,11 @@ function maxva(int|float $first, int|float $second, int|float ...$rest): int|flo $max = \max($first, $second); foreach ($rest as $number) { - if ($number > $max) { - $max = $number; + if ($number <= $max) { + continue; } + + $max = $number; } return $max; @@ -492,9 +496,11 @@ function min(array $numbers): null|float|int $min = null; foreach ($numbers as $number) { - if (null === $min || $number < $min) { - $min = $number; + if (null !== $min && $number >= $min) { + continue; } + + $min = $number; } return $min; @@ -516,9 +522,11 @@ function minva(int|float $first, int|float $second, int|float ...$rest): int|flo $min = \min($first, $second); foreach ($rest as $number) { - if ($number < $min) { - $min = $number; + if ($number >= $min) { + continue; } + + $min = $number; } return $min; diff --git a/packages/support/src/Str/functions.php b/packages/support/src/Str/functions.php index 89a22f7d8..17fc68cd2 100644 --- a/packages/support/src/Str/functions.php +++ b/packages/support/src/Str/functions.php @@ -692,9 +692,7 @@ function chunk(Stringable|string $string, int $length): array $chunks = []; - $chunks = str_split($string, $length); - - return $chunks; + return str_split($string, $length); } /** diff --git a/packages/support/src/Uri/Uri.php b/packages/support/src/Uri/Uri.php index 49c7ad062..4070039bf 100644 --- a/packages/support/src/Uri/Uri.php +++ b/packages/support/src/Uri/Uri.php @@ -262,9 +262,7 @@ private function buildQueryString(array $query): ?string } $queryString = http_build_query($processedQuery, arg_separator: '&', encoding_type: PHP_QUERY_RFC3986); - $queryString = preg_replace('/([^=&]+)=(?=&|$)/', replacement: '$1', subject: $queryString); - - return $queryString; + return preg_replace('/([^=&]+)=(?=&|$)/', replacement: '$1', subject: $queryString); } /** diff --git a/packages/support/tests/Arr/ManipulatesArrayTest.php b/packages/support/tests/Arr/ManipulatesArrayTest.php index fd42145c3..f1150610e 100644 --- a/packages/support/tests/Arr/ManipulatesArrayTest.php +++ b/packages/support/tests/Arr/ManipulatesArrayTest.php @@ -203,7 +203,7 @@ public function test_unshift(): void public function test_last(): void { - $this->assertSame(null, arr()->last()); + $this->assertNull(arr()->last()); $this->assertSame('c', arr(['a', 'b', 'c'])->last()); $this->assertSame('foo', arr()->last(default: 'foo')); @@ -213,7 +213,7 @@ public function test_last(): void public function test_first(): void { $this->assertSame('a', arr(['a', 'b', 'c'])->first()); - $this->assertSame(null, arr()->first()); + $this->assertNull(arr()->first()); $this->assertSame('foo', arr()->first(default: 'foo')); $this->assertSame(1, arr([1, 2])->first(default: 'foo')); diff --git a/packages/support/tests/Math/MathsTest.php b/packages/support/tests/Math/MathsTest.php index cc232784c..8c3a09423 100644 --- a/packages/support/tests/Math/MathsTest.php +++ b/packages/support/tests/Math/MathsTest.php @@ -27,37 +27,37 @@ public function test_abs(int|float $expected, int|float $number): void } #[TestWith([0.0, 1.0])] - #[TestWith([1.2661036727794992, 0.3])] - #[TestWith([1.0471975511965979, 0.5])] + #[TestWith([1.266_103_672_779_499_2, 0.3])] + #[TestWith([1.047_197_551_196_597_9, 0.5])] public function test_acos(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\acos($number)); } - #[TestWith([0.5235987755982989, 0.5])] - #[TestWith([0.9272952180016123, 0.8])] + #[TestWith([0.523_598_775_598_298_9, 0.5])] + #[TestWith([0.927_295_218_001_612_3, 0.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.41151684606748806, 0.4])] + #[TestWith([0.411_516_846_067_488_06, 0.4])] public function test_asin(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\asin($number)); } - #[TestWith([0.7853981633974483, 1.0, 1.0])] - #[TestWith([0.8960553845713439, 1.0, 0.8])] + #[TestWith([0.785_398_163_397_448_3, 1.0, 1.0])] + #[TestWith([0.896_055_384_571_343_9, 1.0, 0.8])] #[TestWith([0.0, 0.0, 0.0])] - #[TestWith([0.7853981633974483, 0.4, 0.4])] - #[TestWith([-2.260001062633476, -0.5, -0.412])] + #[TestWith([0.785_398_163_397_448_3, 0.4, 0.4])] + #[TestWith([-2.260_001_062_633_476, -0.5, -0.412])] public function test_atan2(float $expected, float $y, float $x): void { $this->assertFloatEquals($expected, Math\atan2($y, $x)); } - #[TestWith([0.7853981633974483, 1.0])] - #[TestWith([0.6747409422235527, 0.8])] + #[TestWith([0.785_398_163_397_448_3, 1.0])] + #[TestWith([0.674_740_942_223_552_7, 0.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.3805063771123649, 0.4])] - #[TestWith([-0.4636476090008061, -0.5])] + #[TestWith([0.380_506_377_112_364_9, 0.4])] + #[TestWith([-0.463_647_609_000_806_1, -0.5])] public function test_atan(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\atan($number)); @@ -106,11 +106,11 @@ public function test_clamp_invalid_min_max(): void Math\clamp(10, 20, 10); } - #[TestWith([0.5403023058681398, 1.0])] + #[TestWith([0.540_302_305_868_139_8, 1.0])] #[TestWith([1.0, 0.0])] - #[TestWith([0.10291095660695612, 45.45])] - #[TestWith([0.28366218546322625, -5])] - #[TestWith([-0.9983206000589924, -15.65])] + #[TestWith([0.102_910_956_606_956_12, 45.45])] + #[TestWith([0.283_662_185_463_226_25, -5])] + #[TestWith([-0.998_320_600_058_992_4, -15.65])] public function test_cos(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\cos($number)); @@ -141,9 +141,9 @@ public function test_div_int64_min_by_minus_one(): void Math\div(Math\INT64_MIN, -1); } - #[TestWith([162754.79141900392, 12.0])] - #[TestWith([298.8674009670603, 5.7])] - #[TestWith([Math\INFINITY, 1000000])] + #[TestWith([162_754.791_419_003_92, 12.0])] + #[TestWith([298.867_400_967_060_3, 5.7])] + #[TestWith([Math\INFINITY, 1_000_000])] public function test_exp(float $expected, float $number): void { $this->assertSame($expected, Math\exp($number)); @@ -160,7 +160,7 @@ public function test_floor(float $expected, float $number): void } #[TestWith([5497, '1010101111001', 2])] - #[TestWith([2014587925987, 'pphlmw9v', 36])] + #[TestWith([2_014_587_925_987, 'pphlmw9v', 36])] #[TestWith([Math\INT32_MAX, 'zik0zj', 36])] #[TestWith([15, 'F', 16])] public function test_from_base(int $expected, string $value, int $from_base): void @@ -194,9 +194,9 @@ public function test_throws_for_overflow(): void Math\from_base($number, 32); } - #[TestWith([1.6863989535702288, 5.4, null])] - #[TestWith([0.6574784600188808, 5.4, 13])] - #[TestWith([1.7323937598229686, 54.0, 10])] + #[TestWith([1.686_398_953_570_228_8, 5.4, null])] + #[TestWith([0.657_478_460_018_880_8, 5.4, 13])] + #[TestWith([1.732_393_759_822_968_6, 54.0, 10])] #[TestWith([0, 1, null])] public function test_log(float $expected, float $number, ?float $base = null): void { @@ -297,8 +297,8 @@ public static function provide_mean_cases(): array { return [ [5.0, [10, 5, 0, 2, 4, 6, 8]], - [7.357142857142858, [18, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]], - [26.785714285714285, [19, 15, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 52, 64]], + [7.357_142_857_142_858, [18, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15]], + [26.785_714_285_714_285, [19, 15, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 52, 64]], [100.0, array_fill(0, 100, 100)], [null, []], ]; @@ -388,33 +388,33 @@ public static function provide_min_va_cases(): array ]; } - #[TestWith([5.46, 5.45663, 2])] + #[TestWith([5.46, 5.456_63, 2])] #[TestWith([4.8, 4.811, 1])] #[TestWith([5.0, 5.42, 0])] #[TestWith([5.0, 4.8, 0])] #[TestWith([0.0, 0.4242, 0])] #[TestWith([0.5, 0.4634, 1])] - #[TestWith([-6.57778, -6.5777777777, 5])] + #[TestWith([-6.577_78, -6.577_777_777_7, 5])] public function test_round(float $expected, float $number, int $precision = 0): void { $this->assertSame($expected, Math\round($number, $precision)); } - #[TestWith([-0.9589242746631385, 5.0])] - #[TestWith([-0.9961646088358407, 4.8])] + #[TestWith([-0.958_924_274_663_138_5, 5.0])] + #[TestWith([-0.996_164_608_835_840_7, 4.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.3894183423086505, 0.4])] - #[TestWith([-0.21511998808781552, -6.5])] + #[TestWith([0.389_418_342_308_650_5, 0.4])] + #[TestWith([-0.215_119_988_087_815_52, -6.5])] public function test_sin(float $expected, float $number): void { $this->assertFloatEquals($expected, Math\sin($number)); } - #[TestWith([2.23606797749979, 5.0])] - #[TestWith([2.1908902300206643, 4.8])] - #[TestWith([0.6324555320336759, 0.4])] - #[TestWith([2.5495097567963922, 6.5])] - #[TestWith([1.4142135623730951, 2])] + #[TestWith([2.236_067_977_499_79, 5.0])] + #[TestWith([2.190_890_230_020_664_3, 4.8])] + #[TestWith([0.632_455_532_033_675_9, 0.4])] + #[TestWith([2.549_509_756_796_392_2, 6.5])] + #[TestWith([1.414_213_562_373_095_1, 2])] #[TestWith([1, 1])] public function test_sqrt(float $expected, float $number): void { @@ -430,7 +430,7 @@ public function test_sum_floats(float $expected, array $numbers): void public static function provide_sum_floats_data(): array { return [ - [116.70000000000005, [10.9, 5, ...range(0, 9.8798, 0.48)]], + [116.700_000_000_000_05, [10.9, 5, ...range(0, 9.8798, 0.48)]], [103.0, [18, 15, ...range(0, 10), 15]], [323.54, [19.5, 15.8, ...range(0.5, 45, 5.98), 52.8, 64]], ]; @@ -451,18 +451,18 @@ public static function provide_sum_data(): array ]; } - #[TestWith([-3.380515006246586, 5.0, 0.00000000000001])] - #[TestWith([-11.384870654242922, 4.8])] + #[TestWith([-3.380_515_006_246_586, 5.0, 0.000_000_000_000_01])] + #[TestWith([-11.384_870_654_242_922, 4.8])] #[TestWith([0.0, 0.0])] - #[TestWith([0.4227932187381618, 0.4])] - #[TestWith([-0.22027720034589682, -6.5])] + #[TestWith([0.422_793_218_738_161_8, 0.4])] + #[TestWith([-0.220_277_200_345_896_82, -6.5])] public function test_tan(float $expected, float $number, float $epsilon = PHP_FLOAT_EPSILON): void { $this->assertFloatEquals($expected, Math\tan($number), $epsilon); } #[TestWith(['1010101111001', 5497, 2])] - #[TestWith(['pphlmw9v', 2014587925987, 36])] + #[TestWith(['pphlmw9v', 2_014_587_925_987, 36])] #[TestWith(['zik0zj', Math\INT32_MAX, 36])] #[TestWith(['f', 15, 16])] public function test_to_base(string $expected, int $value, int $to_base): void diff --git a/packages/support/tests/Regex/FunctionsTest.php b/packages/support/tests/Regex/FunctionsTest.php index 47e4b2033..e616102bb 100644 --- a/packages/support/tests/Regex/FunctionsTest.php +++ b/packages/support/tests/Regex/FunctionsTest.php @@ -87,7 +87,7 @@ public function test_get_match(): void $this->assertSame('10', get_match('10-abc', '/(\d+)-.*/', match: 1)); $this->assertSame([0 => '10-abc', 1 => '10'], get_match('10-abc', '/(\d+)-.*/')); $this->assertSame('10-abc', get_match('10-abc', '/\d+-.*/', match: 0)); - $this->assertSame(null, get_match('10-abc', '/\d+-.*/', match: 1)); + $this->assertNull(get_match('10-abc', '/\d+-.*/', match: 1)); $this->assertSame( expected: [ diff --git a/packages/support/tests/Str/FunctionsTest.php b/packages/support/tests/Str/FunctionsTest.php index 0f8278043..ee16f2315 100644 --- a/packages/support/tests/Str/FunctionsTest.php +++ b/packages/support/tests/Str/FunctionsTest.php @@ -16,7 +16,7 @@ public function test_parse(): void $this->assertSame('1', Str\parse('1')); $this->assertSame('1', Str\parse(1)); $this->assertSame('', Str\parse(new stdClass())); - $this->assertSame(null, Str\parse(new stdClass(), default: null)); + $this->assertNull(Str\parse(new stdClass(), default: null)); $this->assertSame('', Str\parse(new stdClass(), default: '')); $this->assertSame('foo', Str\parse(new stdClass(), default: 'foo')); $this->assertSame('foo', Str\parse(new MutableString('foo'))); diff --git a/packages/validation/tests/Rules/IsJsonStringTest.php b/packages/validation/tests/Rules/IsJsonStringTest.php index 0003c143f..dc94da5f0 100644 --- a/packages/validation/tests/Rules/IsJsonStringTest.php +++ b/packages/validation/tests/Rules/IsJsonStringTest.php @@ -37,7 +37,7 @@ public function test_it_allows_to_specify_flags(): void { // Not sure if there is a better way of asserting that a php function was called with a given argument $this->expectException(ValueError::class); - $rule = new IsJsonString(flags: 232312312); // we intentionally send something that is not valid + $rule = new IsJsonString(flags: 232_312_312); // we intentionally send something that is not valid $rule->isValid('{"test": "test"}'); } } diff --git a/packages/validation/tests/Rules/IsPasswordTest.php b/packages/validation/tests/Rules/IsPasswordTest.php index 09b306e65..964d5d84a 100644 --- a/packages/validation/tests/Rules/IsPasswordTest.php +++ b/packages/validation/tests/Rules/IsPasswordTest.php @@ -23,8 +23,8 @@ public function test_defaults(): void public function test_invalid_input(): void { $rule = new IsPassword(); - $this->assertFalse($rule->isValid(123456789012)); - $this->assertFalse($rule->isValid([123456789012])); + $this->assertFalse($rule->isValid(123_456_789_012)); + $this->assertFalse($rule->isValid([123_456_789_012])); } public function test_minimum(): void diff --git a/packages/view/src/Elements/IsElement.php b/packages/view/src/Elements/IsElement.php index 09a60a504..ce501bb48 100644 --- a/packages/view/src/Elements/IsElement.php +++ b/packages/view/src/Elements/IsElement.php @@ -33,10 +33,12 @@ public function getAttributes(): array $tailingAttributes = []; foreach ($attributes as $name => $value) { - if ($name === ':foreach' || $name === ':if') { - unset($attributes[$name]); - $tailingAttributes[$name] = $value; + if ($name !== ':foreach' && $name !== ':if') { + continue; } + + unset($attributes[$name]); + $tailingAttributes[$name] = $value; } // Tailing attributes are reversed because they need to be applied in reverse order diff --git a/packages/view/src/Elements/RootElement.php b/packages/view/src/Elements/RootElement.php index fc5256b9c..e4fc209c5 100644 --- a/packages/view/src/Elements/RootElement.php +++ b/packages/view/src/Elements/RootElement.php @@ -29,9 +29,11 @@ public function getImports(): array $this->mergeImports($imports, $this->inheritedImports); foreach ($this->children as $child) { - if ($child instanceof PhpElement) { - $this->mergeImports($imports, $child->getImports()); + if (! $child instanceof PhpElement) { + continue; } + + $this->mergeImports($imports, $child->getImports()); } return array_values($imports); diff --git a/packages/view/src/Elements/ViewComponentElement.php b/packages/view/src/Elements/ViewComponentElement.php index b1284af2f..d4bf9180b 100644 --- a/packages/view/src/Elements/ViewComponentElement.php +++ b/packages/view/src/Elements/ViewComponentElement.php @@ -289,9 +289,11 @@ public function getImports(): array } foreach ($this->getChildren() as $child) { - if ($child instanceof PhpElement) { - $imports = [...$imports, ...$child->getImports()]; + if (! $child instanceof PhpElement) { + continue; } + + $imports = [...$imports, ...$child->getImports()]; } return $imports; diff --git a/packages/view/src/Initializers/ViewCacheInitializer.php b/packages/view/src/Initializers/ViewCacheInitializer.php index 14befdca9..f1e3c888c 100644 --- a/packages/view/src/Initializers/ViewCacheInitializer.php +++ b/packages/view/src/Initializers/ViewCacheInitializer.php @@ -15,11 +15,9 @@ final class ViewCacheInitializer implements Initializer #[Singleton] public function initialize(Container $container): ViewCache { - $viewCache = new ViewCache( + return new ViewCache( enabled: $this->shouldCacheBeEnabled(), ); - - return $viewCache; } private function shouldCacheBeEnabled(): bool diff --git a/packages/view/src/functions.php b/packages/view/src/functions.php index 49c43d5f0..ce34bc3fd 100644 --- a/packages/view/src/functions.php +++ b/packages/view/src/functions.php @@ -4,9 +4,6 @@ namespace Tempest\View; -use Tempest\View\GenericView; -use Tempest\View\View; - /** * Returns a {@see View} instance for the specified `$path`. */ diff --git a/packages/vite/src/ViteDiscovery.php b/packages/vite/src/ViteDiscovery.php index ffbde22b3..4ab4d0ed2 100644 --- a/packages/vite/src/ViteDiscovery.php +++ b/packages/vite/src/ViteDiscovery.php @@ -9,7 +9,6 @@ use Tempest\Discovery\DiscoveryLocation; use Tempest\Discovery\IsDiscovery; use Tempest\Reflection\ClassReflector; -use Tempest\Vite\ViteConfig; use function Tempest\Support\str; diff --git a/packages/vite/src/functions.php b/packages/vite/src/functions.php index b217c0504..217fb0e4d 100644 --- a/packages/vite/src/functions.php +++ b/packages/vite/src/functions.php @@ -4,8 +4,6 @@ namespace Tempest\Vite; -use Tempest\Vite\Vite; - use function Tempest\Container\get; /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2d624b923..bb0b91c2b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -9,10 +9,6 @@ parameters: identifier: method.templateTypeNotInParameter paths: - packages/database/src/functions.php - - - identifier: return.type - paths: - - packages/database/src/functions.php - identifier: return.unresolvableType paths: diff --git a/tests/Integration/Auth/AccessControl/HasPolicyTests.php b/tests/Integration/Auth/AccessControl/HasPolicyTests.php index e0dfdae9c..493e3a20f 100644 --- a/tests/Integration/Auth/AccessControl/HasPolicyTests.php +++ b/tests/Integration/Auth/AccessControl/HasPolicyTests.php @@ -16,9 +16,11 @@ public function registerPoliciesFrom(string|object $class): self $config = $this->container->get(AuthConfig::class); foreach (new ClassReflector($class)->getPublicMethods() as $method) { - if ($policy = $method->getAttribute(Policy::class)) { - $config->registerPolicy($method, $policy); + if (! ($policy = $method->getAttribute(Policy::class))) { + continue; } + + $config->registerPolicy($method, $policy); } return $this; diff --git a/tests/Integration/Cache/CacheTest.php b/tests/Integration/Cache/CacheTest.php index 3d11de9e6..cd59661cd 100644 --- a/tests/Integration/Cache/CacheTest.php +++ b/tests/Integration/Cache/CacheTest.php @@ -38,7 +38,7 @@ public function test_put(): void $item = $pool->getItem('a'); $this->assertFalse($item->isHit()); - $this->assertSame(null, $item->get()); + $this->assertNull($item->get()); $item = $pool->getItem('b'); $this->assertTrue($item->isHit()); @@ -152,7 +152,7 @@ public function test_get(): void $clock->plus($interval); - $this->assertSame(null, $cache->get('a')); + $this->assertNull($cache->get('a')); $this->assertSame('b', $cache->get('b')); } @@ -171,7 +171,7 @@ public function test_get_many(): void $values = $cache->getMany(['foo2', 'foo3']); $this->assertSame('bar2', $values['foo2']); - $this->assertSame(null, $values['foo3']); + $this->assertNull($values['foo3']); } public function test_resolve(): void @@ -188,7 +188,7 @@ public function test_resolve(): void $clock->plus($interval); - $this->assertSame(null, $cache->get('a')); + $this->assertNull($cache->get('a')); $this->assertSame('b', $cache->get('b')); $b = $cache->resolve('b', fn () => 'b'); diff --git a/tests/Integration/Console/ConsoleArgumentBagTest.php b/tests/Integration/Console/ConsoleArgumentBagTest.php index b9999ac95..8423d1358 100644 --- a/tests/Integration/Console/ConsoleArgumentBagTest.php +++ b/tests/Integration/Console/ConsoleArgumentBagTest.php @@ -36,13 +36,13 @@ public function test_argument_bag_works(): void $this->assertNull($firstArg->name); $forceFlag = $bag->all()[1]; - $this->assertSame(true, $forceFlag->value); - $this->assertSame(null, $forceFlag->position); + $this->assertTrue($forceFlag->value); + $this->assertNull($forceFlag->position); $this->assertSame('force', $forceFlag->name); $timesFlag = $bag->all()[2]; $this->assertSame('2', $timesFlag->value); - $this->assertSame(null, $timesFlag->position); + $this->assertNull($timesFlag->position); $this->assertSame('times', $timesFlag->name); $this->assertSame( diff --git a/tests/Integration/Console/Fixtures/InteractiveCommand.php b/tests/Integration/Console/Fixtures/InteractiveCommand.php index afa941cbb..429ee2492 100644 --- a/tests/Integration/Console/Fixtures/InteractiveCommand.php +++ b/tests/Integration/Console/Fixtures/InteractiveCommand.php @@ -132,7 +132,7 @@ public function progress(): void $result = $this->console->progressBar( data: array_fill(0, 10, 'a'), handler: function ($i) { - usleep(100000); + usleep(100_000); return $i . $i; }, diff --git a/tests/Integration/Console/Input/ConsoleInputArgumentTest.php b/tests/Integration/Console/Input/ConsoleInputArgumentTest.php index 6f53ef679..e708acc1c 100644 --- a/tests/Integration/Console/Input/ConsoleInputArgumentTest.php +++ b/tests/Integration/Console/Input/ConsoleInputArgumentTest.php @@ -41,19 +41,19 @@ public function test_parse_named_arguments(): void $input = ConsoleInputArgument::fromString('--noFooBar'); $this->assertSame('foo-bar', $input->name); - $this->assertSame(false, $input->value); + $this->assertFalse($input->value); $input = ConsoleInputArgument::fromString('--no-interaction'); $this->assertSame('interaction', $input->name); - $this->assertSame(false, $input->value); + $this->assertFalse($input->value); $input = ConsoleInputArgument::fromString('--no-interaction=true'); $this->assertSame('interaction', $input->name); - $this->assertSame(false, $input->value); + $this->assertFalse($input->value); $input = ConsoleInputArgument::fromString('--no-interaction=false'); $this->assertSame('interaction', $input->name); - $this->assertSame(true, $input->value); + $this->assertTrue($input->value); $input = ConsoleInputArgument::fromString('--no-foo=baz'); $this->assertSame('no-foo', $input->name); diff --git a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php index 1c3c26212..2b3b84909 100644 --- a/tests/Integration/Database/Builder/SelectQueryBuilderTest.php +++ b/tests/Integration/Database/Builder/SelectQueryBuilderTest.php @@ -534,9 +534,9 @@ public function test_paginate(): void $this->assertSame(0, $page1->offset); $this->assertSame(2, $page1->limit); $this->assertSame(2, $page1->nextPage); - $this->assertSame(null, $page1->previousPage); - $this->assertSame(true, $page1->hasNext); - $this->assertSame(false, $page1->hasPrevious); + $this->assertNull($page1->previousPage); + $this->assertTrue($page1->hasNext); + $this->assertFalse($page1->hasPrevious); $this->assertSame('LOTR 1.1', $page1->data[0]->title); $this->assertSame('LOTR 1.2', $page1->data[1]->title); diff --git a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php index 39ee9049a..a3b798550 100644 --- a/tests/Integration/Database/ConvenientDateWhereMethodsTest.php +++ b/tests/Integration/Database/ConvenientDateWhereMethodsTest.php @@ -226,9 +226,11 @@ public function test_where_this_year(): void $this->assertCount(10, $events); foreach ($events as $event) { - if ($event->name !== 'Last year event') { - $this->assertTrue($event->event_date->isCurrentYear()); + if ($event->name === 'Last year event') { + continue; } + + $this->assertTrue($event->event_date->isCurrentYear()); } } diff --git a/tests/Integration/Mapper/Fixtures/SerializableObject.php b/tests/Integration/Mapper/Fixtures/SerializableObject.php index 3c61c6a39..4f1a29b11 100644 --- a/tests/Integration/Mapper/Fixtures/SerializableObject.php +++ b/tests/Integration/Mapper/Fixtures/SerializableObject.php @@ -6,11 +6,7 @@ final class SerializableObject implements Serializable { - /* - * @mago-expect lint:return-type - * @phpstan-ignore return.unusedType - */ - public function serialize() + public function serialize(): string { return 'a'; } diff --git a/tests/Integration/Route/ClientTest.php b/tests/Integration/Route/ClientTest.php index e5e93dbf1..f8ccf0357 100644 --- a/tests/Integration/Route/ClientTest.php +++ b/tests/Integration/Route/ClientTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $this->server->start(); // Server needs to start - usleep(100000); + usleep(100_000); // We'll use the client interface directly because we want to write raw post data in this test $this->driver = $this->container->get(ClientInterface::class); diff --git a/tests/Integration/Route/RequestToObjectMapperTest.php b/tests/Integration/Route/RequestToObjectMapperTest.php index 176ccc11f..2e5680114 100644 --- a/tests/Integration/Route/RequestToObjectMapperTest.php +++ b/tests/Integration/Route/RequestToObjectMapperTest.php @@ -81,7 +81,7 @@ public function test_query_params_with_types(): void $this->assertSame(1, $request->intParam); $this->assertSame('a', $request->stringParam); - $this->assertSame(true, $request->boolParam); + $this->assertTrue($request->boolParam); $this->assertSame(0.1, $request->floatParam); } diff --git a/tests/Integration/Validator/ExistsRuleTest.php b/tests/Integration/Validator/ExistsRuleTest.php index c4f328521..fe0d38849 100644 --- a/tests/Integration/Validator/ExistsRuleTest.php +++ b/tests/Integration/Validator/ExistsRuleTest.php @@ -45,8 +45,8 @@ public function non_existent_record_returns_false(): void { Book::create(title: 'Timeline Taxi'); - $this->assertFalse(new Exists(Book::class)->isValid(99999)); - $this->assertFalse(new Exists(Book::class)->isValid(12345)); + $this->assertFalse(new Exists(Book::class)->isValid(99_999)); + $this->assertFalse(new Exists(Book::class)->isValid(12_345)); $this->assertFalse(new Exists(Book::class, column: 'title')->isValid('Timeline Taxi 2')); } @@ -60,6 +60,6 @@ public function validates_multiple_existing_records(): void $this->assertTrue(new Exists(Book::class)->isValid($book1->id)); $this->assertTrue(new Exists(Book::class)->isValid($book2->id)); $this->assertTrue(new Exists(Book::class)->isValid($book3->id)); - $this->assertFalse(new Exists(Book::class)->isValid(99999)); + $this->assertFalse(new Exists(Book::class)->isValid(99_999)); } }