diff --git a/composer.json b/composer.json index ac53d17f..5928b83f 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "ibexa/doctrine-schema": "~6.0.x-dev", "ibexa/http-cache": "~6.0.x-dev", "ibexa/notifications": "~6.0.x-dev", + "ibexa/phpstan": "~6.0.x-dev", "ibexa/rector": "~6.0.x-dev", "ibexa/rest": "~6.0.x-dev", "ibexa/test-core": "~6.0.x-dev", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bee431fb..7366b226 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-symfony/extension.neon + - vendor/ibexa/phpstan/extension.neon - phpstan-baseline.neon parameters: diff --git a/src/lib/FieldType/Mapper/UserAccountFieldValueFormMapper.php b/src/lib/FieldType/Mapper/UserAccountFieldValueFormMapper.php index 271b4536..592b5a92 100644 --- a/src/lib/FieldType/Mapper/UserAccountFieldValueFormMapper.php +++ b/src/lib/FieldType/Mapper/UserAccountFieldValueFormMapper.php @@ -78,7 +78,7 @@ public function getModelTransformerForTranslation(FieldDefinition $fieldDefiniti static function (ApiUserValue $data): UserAccountFieldData { return new UserAccountFieldData($data->login, null, $data->email, $data->enabled); }, - static function (UserAccountFieldData $submittedData) use ($fieldDefinition) { + static function (UserAccountFieldData $submittedData) use ($fieldDefinition): ApiUserValue { /** @var \Ibexa\Core\FieldType\User\Value $userValue */ $userValue = clone $fieldDefinition->defaultValue; diff --git a/tests/lib/Event/FormActionEventTest.php b/tests/lib/Event/FormActionEventTest.php index 8d608e63..83f36826 100644 --- a/tests/lib/Event/FormActionEventTest.php +++ b/tests/lib/Event/FormActionEventTest.php @@ -18,7 +18,7 @@ final class FormActionEventTest extends TestCase { public function testConstruct(): void { - $form = $this->createStub(FormInterface::class); + $form = self::createStub(FormInterface::class); $data = new stdClass(); $clickedButton = 'fooButton'; $options = ['languageCode' => 'eng-GB', 'foo' => 'bar']; @@ -33,7 +33,7 @@ public function testConstruct(): void public function testEventDoesntHaveResponse(): void { $event = new FormActionEvent( - $this->createStub(FormInterface::class), + self::createStub(FormInterface::class), new stdClass(), 'fooButton' ); @@ -44,7 +44,7 @@ public function testEventDoesntHaveResponse(): void public function testEventSetResponse(): void { $event = new FormActionEvent( - $this->createStub(FormInterface::class), + self::createStub(FormInterface::class), new stdClass(), 'fooButton' ); @@ -63,7 +63,7 @@ public function testGetOption(): void $options = ['languageCode' => 'eng-GB', 'foo' => 'bar', 'obj' => $objectOption]; $event = new FormActionEvent( - $this->createStub(FormInterface::class), + self::createStub(FormInterface::class), new stdClass(), 'fooButton', $options diff --git a/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php b/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php index 94c6d591..cafebc34 100644 --- a/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php +++ b/tests/lib/FieldType/DataTransformer/FieldValueTransformerTest.php @@ -32,7 +32,7 @@ public function testTransformNull(): void public function testTransform(): void { - $value = $this->createStub(Value::class); + $value = self::createStub(Value::class); $valueHash = ['lorem' => 'Lorem ipsum dolor...']; $fieldType = $this->createMock(FieldType::class); @@ -49,7 +49,7 @@ public function testTransform(): void public function testReverseTransformNull(): void { - $emptyValue = $this->createStub(Value::class); + $emptyValue = self::createStub(Value::class); $fieldType = $this->createMock(FieldType::class); $fieldType @@ -68,7 +68,7 @@ public function testReverseTransformNull(): void public function testReverseTransform(): void { $value = 'Lorem ipsum dolor...'; - $expected = $this->createStub(Value::class); + $expected = self::createStub(Value::class); $fieldType = $this->createMock(FieldType::class); $fieldType diff --git a/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php b/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php index b239e0f1..fad6b492 100644 --- a/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php +++ b/tests/lib/FieldType/FieldTypeFormMapperDispatcherTest.php @@ -42,7 +42,7 @@ public function testMapFieldValue(): void 'fieldDefinition' => new FieldDefinition(['fieldTypeIdentifier' => 'first_type']), ]); - $formMock = $this->createStub(FormInterface::class); + $formMock = self::createStub(FormInterface::class); $this->fieldTypeAliasResolverMock ->method('resolveIdentifier') diff --git a/tests/lib/FieldType/Mapper/BaseMapperTestCase.php b/tests/lib/FieldType/Mapper/BaseMapperTestCase.php index 6a3e71c7..897a5af1 100644 --- a/tests/lib/FieldType/Mapper/BaseMapperTestCase.php +++ b/tests/lib/FieldType/Mapper/BaseMapperTestCase.php @@ -35,7 +35,7 @@ protected function setUp(): void $this->fieldTypeService = $this->createMock(FieldTypeService::class); $this->fieldTypeService ->method('getFieldType') - ->willReturn($this->createStub(FieldType::class)); + ->willReturn(self::createStub(FieldType::class)); $this->config = $this->createMock(FormConfigInterface::class); $this->fieldForm = $this->createMock(FormInterface::class); @@ -43,7 +43,7 @@ protected function setUp(): void $formFactory ->expects(self::once()) ->method('createBuilder') - ->willReturn($this->createStub(FormBuilder::class)); + ->willReturn(self::createStub(FormBuilder::class)); $this->config ->expects(self::once()) diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php index ece42b95..0821c727 100644 --- a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -29,7 +29,7 @@ final class FixUrlProtocolListenerTest extends TestCase #[DataProvider('provideUrlCases')] public function testUrlProtocolHandling(?string $inputData, ?string $expectedData, string $defaultProtocol = 'https'): void { - $form = $this->createStub(FormInterface::class); + $form = self::createStub(FormInterface::class); $listener = new FixUrlProtocolListener($defaultProtocol); $event = new FormEvent($form, $inputData); diff --git a/tests/lib/Form/Processor/ContentFormProcessorTest.php b/tests/lib/Form/Processor/ContentFormProcessorTest.php index aabb3682..9332edf8 100644 --- a/tests/lib/Form/Processor/ContentFormProcessorTest.php +++ b/tests/lib/Form/Processor/ContentFormProcessorTest.php @@ -108,10 +108,10 @@ public function testProcessPublish( // The deferred (async) redirect resolves its location from the content tree root config // and the location lookup. - $configResolver = $this->createStub(ConfigResolverInterface::class); + $configResolver = self::createStub(ConfigResolverInterface::class); $configResolver->method('getParameter')->willReturn(self::TREE_ROOT_LOCATION_ID); - $locationService = $this->createStub(LocationService::class); + $locationService = self::createStub(LocationService::class); $locationService->method('loadLocation')->willReturn( new Location([ 'id' => self::TREE_ROOT_LOCATION_ID, @@ -242,16 +242,16 @@ private function createDraft(?int $mainLocationId, int $status): Content 'status' => $status, ]); - $versionInfo = $this->createStub(VersionInfo::class); + $versionInfo = self::createStub(VersionInfo::class); $versionInfo->method('getInitialLanguage')->willReturn( new Language(['languageCode' => self::LANGUAGE_CODE]) ); $versionInfo->method('getContentInfo')->willReturn($contentInfo); - $draft = $this->createStub(Content::class); + $draft = self::createStub(Content::class); $draft->method('getVersionInfo')->willReturn($versionInfo); $draft->method('getContentInfo')->willReturn($contentInfo); - $draft->method('getContentType')->willReturn($this->createStub(ContentType::class)); + $draft->method('getContentType')->willReturn(self::createStub(ContentType::class)); return $draft; } @@ -265,7 +265,7 @@ private function createPublishedContent(): Content 'status' => ContentInfo::STATUS_PUBLISHED, ]); - $publishedContent = $this->createStub(Content::class); + $publishedContent = self::createStub(Content::class); $publishedContent->method('getContentInfo')->willReturn($contentInfo); $publishedContent->method('getId')->willReturn(self::CONTENT_ID); @@ -293,13 +293,13 @@ private function createCreateData(): ContentCreateData */ private function createForm(?string $redirectUrlAfterPublish = null): FormInterface { - $formConfig = $this->createStub(FormConfigInterface::class); + $formConfig = self::createStub(FormConfigInterface::class); $formConfig->method('getOption')->willReturn(self::LANGUAGE_CODE); - $redirectUrlField = $this->createStub(FormInterface::class); + $redirectUrlField = self::createStub(FormInterface::class); $redirectUrlField->method('getData')->willReturn($redirectUrlAfterPublish); - $form = $this->createStub(FormInterface::class); + $form = self::createStub(FormInterface::class); $form->method('getConfig')->willReturn($formConfig); $form->method('offsetGet')->willReturn($redirectUrlField); diff --git a/tests/lib/Validator/Constraints/PasswordTest.php b/tests/lib/Validator/Constraints/PasswordTest.php index f7607ef3..2e4d9043 100644 --- a/tests/lib/Validator/Constraints/PasswordTest.php +++ b/tests/lib/Validator/Constraints/PasswordTest.php @@ -47,7 +47,7 @@ public function testGetTargets(): void public function testNamedArguments(): void { - $contentType = $this->createStub(ContentType::class); + $contentType = self::createStub(ContentType::class); $payload = new \stdClass(); $constraint = new Password( diff --git a/tests/lib/Validator/Constraints/PasswordValidatorTest.php b/tests/lib/Validator/Constraints/PasswordValidatorTest.php index 8971bf83..dbc6995f 100644 --- a/tests/lib/Validator/Constraints/PasswordValidatorTest.php +++ b/tests/lib/Validator/Constraints/PasswordValidatorTest.php @@ -54,15 +54,15 @@ public function testValidateShouldBeSkipped(mixed $value): void public function testValid(): void { $password = 'pass'; - $contentType = $this->createStub(ContentType::class); + $contentType = self::createStub(ContentType::class); $this->userService ->expects(self::once()) ->method('validatePassword') - ->willReturnCallback(function ($actualPassword, $actualContext) use ($password, $contentType): array { - $this->assertEquals($password, $actualPassword); - $this->assertInstanceOf(PasswordValidationContext::class, $actualContext); - $this->assertSame($contentType, $actualContext->contentType); + ->willReturnCallback(static function ($actualPassword, $actualContext) use ($password, $contentType): array { + self::assertEquals($password, $actualPassword); + self::assertInstanceOf(PasswordValidationContext::class, $actualContext); + self::assertSame($contentType, $actualContext->contentType); return []; }); @@ -76,7 +76,7 @@ public function testValid(): void public function testInvalid(): void { - $contentType = $this->createStub(ContentType::class); + $contentType = self::createStub(ContentType::class); $password = 'pass'; $errorParameter = 'foo'; $errorMessage = 'error'; @@ -84,10 +84,10 @@ public function testInvalid(): void $this->userService ->expects(self::once()) ->method('validatePassword') - ->willReturnCallback(function ($actualPassword, $actualContext) use ($password, $contentType, $errorMessage, $errorParameter): array { - $this->assertEquals($password, $actualPassword); - $this->assertInstanceOf(PasswordValidationContext::class, $actualContext); - $this->assertSame($contentType, $actualContext->contentType); + ->willReturnCallback(static function ($actualPassword, $actualContext) use ($password, $contentType, $errorMessage, $errorParameter): array { + self::assertEquals($password, $actualPassword); + self::assertInstanceOf(PasswordValidationContext::class, $actualContext); + self::assertSame($contentType, $actualContext->contentType); return [ new ValidationError($errorMessage, null, ['%foo%' => $errorParameter]), diff --git a/tests/lib/Validator/Constraints/UserAccountPasswordTest.php b/tests/lib/Validator/Constraints/UserAccountPasswordTest.php index 7fa71007..f8641418 100644 --- a/tests/lib/Validator/Constraints/UserAccountPasswordTest.php +++ b/tests/lib/Validator/Constraints/UserAccountPasswordTest.php @@ -40,7 +40,7 @@ public function testGetTargets(): void public function testNamedArguments(): void { - $contentType = $this->createStub(ContentType::class); + $contentType = self::createStub(ContentType::class); $constraint = new UserAccountPassword(contentType: $contentType); diff --git a/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php b/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php index 73633125..abedc535 100644 --- a/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php +++ b/tests/lib/Validator/Constraints/UserAccountPasswordValidatorTest.php @@ -63,15 +63,15 @@ public static function dataProviderForValidateNotSupportedValueType(): array public function testValid(): void { $userAccount = new UserAccountFieldData('user', 'pass', 'user@ibexa.co'); - $contentType = $this->createStub(ContentType::class); + $contentType = self::createStub(ContentType::class); $this->userService ->expects(self::once()) ->method('validatePassword') - ->willReturnCallback(function ($actualPassword, $actualContext) use ($userAccount, $contentType): array { - $this->assertEquals($userAccount->password, $actualPassword); - $this->assertInstanceOf(PasswordValidationContext::class, $actualContext); - $this->assertSame($contentType, $actualContext->contentType); + ->willReturnCallback(static function ($actualPassword, $actualContext) use ($userAccount, $contentType): array { + self::assertEquals($userAccount->password, $actualPassword); + self::assertInstanceOf(PasswordValidationContext::class, $actualContext); + self::assertSame($contentType, $actualContext->contentType); return []; }); @@ -85,7 +85,7 @@ public function testValid(): void public function testInvalid(): void { - $contentType = $this->createStub(ContentType::class); + $contentType = self::createStub(ContentType::class); $userAccount = new UserAccountFieldData('user', 'pass', 'user@ibexa.co'); $errorParameter = 'foo'; $errorMessage = 'error'; @@ -93,10 +93,10 @@ public function testInvalid(): void $this->userService ->expects(self::once()) ->method('validatePassword') - ->willReturnCallback(function ($actualPassword, $actualContext) use ($userAccount, $contentType, $errorMessage, $errorParameter): array { - $this->assertEquals($userAccount->password, $actualPassword); - $this->assertInstanceOf(PasswordValidationContext::class, $actualContext); - $this->assertSame($contentType, $actualContext->contentType); + ->willReturnCallback(static function ($actualPassword, $actualContext) use ($userAccount, $contentType, $errorMessage, $errorParameter): array { + self::assertEquals($userAccount->password, $actualPassword); + self::assertInstanceOf(PasswordValidationContext::class, $actualContext); + self::assertSame($contentType, $actualContext->contentType); return [ new ValidationError($errorMessage, null, ['%foo%' => $errorParameter]),