From 0f96d4cc29813a3ee89fdaddf7948e978328a03c Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 25 Jul 2022 07:18:12 +0200 Subject: [PATCH] Update php-cs-fixer and phpstan (#152) * Update php-cs-fixer * Remove php-cs-fixer from PHP 7.2 pipeline * Update phpstan * Add phpstan baseline * Add PHP 8.1 pipeline * Fix php-cs * Fix ci for removing php-cs-fixer/shim --- .github/workflows/test-application.yaml | 13 +- .gitignore | 1 + .php-cs-fixer.dist.php | 55 ++++ Admin/CommunityAdmin.php | 19 +- Build/CommunityBuilder.php | 5 - Command/InitCommand.php | 15 +- Controller/AbstractController.php | 23 +- .../BlacklistConfirmationController.php | 16 +- Controller/BlacklistItemController.php | 11 +- Controller/CompletionController.php | 6 +- Controller/ConfirmationController.php | 6 +- Controller/EmailConfirmationController.php | 10 +- Controller/LoginController.php | 2 +- Controller/ProfileController.php | 4 +- Controller/RegistrationController.php | 4 +- Controller/SaveMediaTrait.php | 5 +- .../CommunityManagerCompilerPass.php | 63 +++- .../CommunityValidatorCompilerPass.php | 5 +- .../CompilerPass/Normalizer.php | 2 +- DependencyInjection/Configuration.php | 83 +++-- .../SuluCommunityExtension.php | 6 - Entity/BlacklistItem.php | 8 +- Entity/BlacklistItemRepository.php | 1 + Entity/BlacklistUser.php | 6 +- Entity/InvalidTypeException.php | 2 +- Event/AbstractCommunityEvent.php | 24 +- EventListener/BlacklistListener.php | 2 +- EventListener/CompletionListener.php | 13 +- Form/Type/CompletionContactType.php | 10 +- Form/Type/CompletionType.php | 7 +- Form/Type/PasswordForgetType.php | 6 - Form/Type/PasswordResetType.php | 6 - Form/Type/ProfileType.php | 6 - Form/Type/RegistrationType.php | 8 +- Mail/Mail.php | 6 +- Mail/MailFactory.php | 5 +- Manager/BlacklistItemManager.php | 11 +- Manager/CommunityManager.php | 51 +-- Manager/CommunityManagerInterface.php | 61 +++- Manager/CommunityManagerRegistry.php | 10 +- Manager/UserManager.php | 22 +- SuluCommunityBundle.php | 3 - Tests/Application/Kernel.php | 16 +- Tests/Application/bin/console.php | 16 +- Tests/Application/config/bootstrap.php | 10 +- .../BlacklistItemControllerTest.php | 46 +-- .../EmailConfirmationControllerTest.php | 27 +- .../Controller/LoginControllerTest.php | 7 +- .../Controller/ProfileControllerTest.php | 40 ++- .../Controller/RegistrationTest.php | 36 ++- .../Entity/BlacklistItemRepositoryTest.php | 8 +- Tests/Unit/Controller/SaveMediaTraitTest.php | 24 +- Tests/Unit/Entity/BlacklistItemTest.php | 24 +- Tests/Unit/Listener/BlacklistListenerTest.php | 24 +- .../EmailConfirmationListenerTest.php | 41 ++- Tests/Unit/Mail/MailFactoryTest.php | 34 +- .../Unit/Manager/BlacklistItemManagerTest.php | 18 +- .../Manager/CommunityManagerRegistryTest.php | 2 +- Tests/phpstan/console-application.php | 24 ++ Tests/phpstan/object-manager.php | 45 +++ Validator/Constraints/Blocked.php | 3 - Validator/Constraints/BlockedValidator.php | 2 +- Validator/Constraints/Exist.php | 3 - Validator/Constraints/ExistValidator.php | 2 +- composer.json | 50 +-- phpstan-baseline.neon | 297 ++++++++++++++++++ phpstan.neon | 9 +- 67 files changed, 988 insertions(+), 442 deletions(-) create mode 100644 .php-cs-fixer.dist.php create mode 100644 Tests/phpstan/console-application.php create mode 100644 Tests/phpstan/object-manager.php create mode 100644 phpstan-baseline.neon diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 97a8048a..d4cb96d5 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -27,7 +27,7 @@ jobs: SYMFONY_DEPRECATIONS_HELPER: disabled - php-version: '7.4' - lint: true + lint: false dependency-versions: 'highest' tools: 'composer:v2' env: @@ -40,6 +40,13 @@ jobs: env: SYMFONY_DEPRECATIONS_HELPER: weak + - php-version: '8.1' + lint: true + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: weak + services: mysql: image: mysql:5.7 @@ -60,6 +67,10 @@ jobs: extensions: 'mysql, gd' tools: ${{ matrix.tools }} + - name: Remove php-cs-fixer/shim package + if: ${{ matrix.php-version == '7.2' }} + run: composer remove php-cs-fixer/shim --dev --no-interaction + - name: Install composer dependencies uses: ramsey/composer-install@v1 with: diff --git a/.gitignore b/.gitignore index ca3f1561..1a35515c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # PHPCS .php_cs.cache +.php-cs-fixer.cache # composer /composer.phar diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..7434ac29 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,55 @@ +exclude(['var/cache', 'var/coverage.php']) + ->in(__DIR__); + +$config = new PhpCsFixer\Config(); +$config->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'ordered_imports' => true, + 'concat_space' => ['spacing' => 'one'], + 'array_syntax' => ['syntax' => 'short'], + 'phpdoc_align' => ['align' => 'left'], + 'class_definition' => [ + 'multi_line_extends_each_single_line' => true, + ] , + 'linebreak_after_opening_tag' => true, +// 'declare_strict_types' => true, + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + 'native_constant_invocation' => true, + 'native_function_casing' => true, + 'native_function_invocation' => ['include' => ['@internal']], + 'no_php4_constructor' => true, + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true], + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'php_unit_strict' => true, + 'phpdoc_order' => true, + 'semicolon_after_instruction' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'array_indentation' => true, + 'multiline_whitespace_before_semicolons' => true, + 'single_line_throw' => false, + 'visibility_required' => ['elements' => ['property', 'method', 'const']], + 'phpdoc_to_comment' => [ + 'ignored_tags' => ['todo', 'var'], + ], + 'trailing_comma_in_multiline' => ['elements' => ['arrays', /*'arguments', 'parameters' */]], + ]) + ->setFinder($finder); + +return $config; diff --git a/Admin/CommunityAdmin.php b/Admin/CommunityAdmin.php index 1da69787..b760d1ac 100644 --- a/Admin/CommunityAdmin.php +++ b/Admin/CommunityAdmin.php @@ -27,10 +27,10 @@ */ class CommunityAdmin extends Admin { - const BLACKLIST_ITEM_SECURITY_CONTEXT = 'sulu.community.blacklist_items'; - const BLACKLIST_ITEM_LIST_VIEW = 'sulu_community.blacklist_item'; - const BLACKLIST_ITEM_ADD_FORM_VIEW = 'sulu_community.blacklist_item.add_form'; - const BLACKLIST_ITEM_EDIT_FORM_VIEW = 'sulu_community.blacklist_item.edit_form'; + public const BLACKLIST_ITEM_SECURITY_CONTEXT = 'sulu.community.blacklist_items'; + public const BLACKLIST_ITEM_LIST_VIEW = 'sulu_community.blacklist_item'; + public const BLACKLIST_ITEM_ADD_FORM_VIEW = 'sulu_community.blacklist_item.add_form'; + public const BLACKLIST_ITEM_EDIT_FORM_VIEW = 'sulu_community.blacklist_item.edit_form'; /** * @var SecurityCheckerInterface @@ -142,36 +142,33 @@ public function configureViews(ViewCollection $viewCollection): void } } - /** - * {@inheritdoc} - */ public function getSecurityContexts() { $systems = []; $webspaceCollection = $this->webspaceManager->getWebspaceCollection(); - $webspaceKeys = array_keys($webspaceCollection->getWebspaces()); + $webspaceKeys = \array_keys($webspaceCollection->getWebspaces()); foreach ($this->webspacesConfiguration as $webspaceKey => $webspaceConfig) { $webspace = $webspaceCollection->getWebspace($webspaceKey); if (!$webspace) { - throw new \InvalidArgumentException(sprintf('Webspace "%s" not found for "sulu_community" expected one of %s.', $webspaceKey, '"' . implode('", "', $webspaceKeys) . '"')); + throw new \InvalidArgumentException(\sprintf('Webspace "%s" not found for "sulu_community" expected one of %s.', $webspaceKey, '"' . \implode('", "', $webspaceKeys) . '"')); } /** @var Security|null $security */ $security = $webspace->getSecurity(); if (!$security) { - throw new \InvalidArgumentException(sprintf('Missing "Website" configuration in webspace "%s" for "sulu_community".', $webspaceKey)); + throw new \InvalidArgumentException(\sprintf('Missing "Website" configuration in webspace "%s" for "sulu_community".', $webspaceKey)); } $system = $security->getSystem(); $systems[$system] = []; } - return array_merge( + return \array_merge( $systems, [ 'Sulu' => [ diff --git a/Build/CommunityBuilder.php b/Build/CommunityBuilder.php index 918169b9..67ac6042 100644 --- a/Build/CommunityBuilder.php +++ b/Build/CommunityBuilder.php @@ -19,17 +19,12 @@ */ class CommunityBuilder extends SuluBuilder { - /** - * {@inheritdoc} - */ public function getName() { return 'community'; } /** - * {@inheritdoc} - * * @return string[] */ public function getDependencies(): array diff --git a/Command/InitCommand.php b/Command/InitCommand.php index d6137f30..39c196ec 100644 --- a/Command/InitCommand.php +++ b/Command/InitCommand.php @@ -31,7 +31,7 @@ */ class InitCommand extends Command { - const NAME = 'sulu:community:init'; + public const NAME = 'sulu:community:init'; /** * @var EntityManagerInterface @@ -66,18 +66,12 @@ public function __construct( parent::__construct(self::NAME); } - /** - * {@inheritdoc} - */ public function configure(): void { $this->setDescription('Create the user roles for the community.') ->addArgument('webspace', null, 'A specific webspace key.'); } - /** - * {@inheritdoc} - */ protected function execute(InputInterface $input, OutputInterface $output) { /** @var string|null $webspaceKey */ @@ -87,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); if (!$webspace) { - throw new \InvalidArgumentException(sprintf('Given webspace "%s" is invalid', $webspaceKey)); + throw new \InvalidArgumentException(\sprintf('Given webspace "%s" is invalid', $webspaceKey)); } $this->initWebspace($webspace, $output); @@ -122,12 +116,13 @@ private function initWebspace(Webspace $webspace, OutputInterface $output): void } $communityManager = $this->communityManagerRegistry->get($webspaceKey); + /** @var string $roleName */ $roleName = $communityManager->getConfigProperty(Configuration::ROLE); $system = $security->getSystem(); // Create role if not exists $output->writeln( - sprintf( + \sprintf( $this->createRoleIfNotExists($roleName, $system, $webspaceKey), $roleName, $system @@ -203,7 +198,7 @@ private function addPermissions(RoleInterface $role, string $system, string $web } } - if (0 === strpos($securityContext, 'sulu.webspaces.') + if (0 === \strpos($securityContext, 'sulu.webspaces.') && $webspaceSecurityContext !== $securityContext ) { // Do not add permissions for other webspaces diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 02a89d3f..38cf035d 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -34,7 +34,7 @@ abstract class AbstractController extends SymfonyAbstractController { /** - * @var string + * @var string|null */ private $webspaceKey; @@ -52,7 +52,7 @@ protected function getCommunityManager(string $webspaceKey): CommunityManagerInt protected function getWebspaceKey(): string { if (null === $this->webspaceKey) { - return $this->getRequestAnalyzer()->getWebspace()->getKey(); + $this->webspaceKey = $this->getRequestAnalyzer()->getWebspace()->getKey(); } return $this->webspaceKey; @@ -63,6 +63,7 @@ protected function getWebspaceKey(): string */ protected function setUserPasswordAndSalt(User $user, FormInterface $form): User { + /** @var string|null $plainPassword */ $plainPassword = $form->get('plainPassword')->getData(); if (null === $plainPassword) { return $user; @@ -85,6 +86,7 @@ protected function setUserPasswordAndSalt(User $user, FormInterface $form): User */ protected function checkAutoLogin(string $type): bool { + /** @var bool */ return $this->getCommunityManager($this->getWebspaceKey())->getConfigTypeProperty( $type, Configuration::AUTO_LOGIN @@ -98,11 +100,14 @@ protected function checkAutoLogin(string $type): bool */ protected function renderTemplate(string $type, array $data = []): Response { + /** @var string $template */ + $template = $this->getCommunityManager($this->getWebspaceKey())->getConfigTypeProperty( + $type, + Configuration::TEMPLATE + ); + return $this->render( - $this->getCommunityManager($this->getWebspaceKey())->getConfigTypeProperty( - $type, - Configuration::TEMPLATE - ), + $template, $data ); } @@ -128,8 +133,6 @@ private function getTemplateAttributes(array $custom = []): array } /** - * {@inheritdoc} - * * @return User */ public function getUser(): ?User @@ -170,8 +173,6 @@ private function addAddress(User $user): void } /** - * {@inheritdoc} - * * @param mixed[] $parameters */ public function render(string $view, array $parameters = [], Response $response = null): Response @@ -184,8 +185,6 @@ public function render(string $view, array $parameters = [], Response $response } /** - * {@inheritdoc} - * * @param mixed[] $parameters */ public function renderView(string $view, array $parameters = []): string diff --git a/Controller/BlacklistConfirmationController.php b/Controller/BlacklistConfirmationController.php index 1fd1d3fd..450ce94e 100644 --- a/Controller/BlacklistConfirmationController.php +++ b/Controller/BlacklistConfirmationController.php @@ -33,8 +33,11 @@ class BlacklistConfirmationController extends AbstractController */ public function confirmAction(Request $request): Response { + /** @var string $token */ + $token = $request->get('token'); + /** @var BlacklistUser|null $blacklistUser */ - $blacklistUser = $this->getBlacklistUserRepository()->findByToken($request->get('token')); + $blacklistUser = $this->getBlacklistUserRepository()->findByToken($token); if (null === $blacklistUser) { throw new NotFoundHttpException(); @@ -62,8 +65,11 @@ public function denyAction(Request $request): Response { $entityManager = $this->getEntityManager(); + /** @var string $token */ + $token = $request->get('token'); + /** @var BlacklistUser|null $blacklistUser */ - $blacklistUser = $this->getBlacklistUserRepository()->findByToken($request->get('token')); + $blacklistUser = $this->getBlacklistUserRepository()->findByToken($token); if (null === $blacklistUser) { throw new NotFoundHttpException(); @@ -75,9 +81,9 @@ public function denyAction(Request $request): Response $communityManager = $this->getCommunityManager($blacklistUser->getWebspaceKey()); if (true === $communityManager->getConfigTypeProperty( - Configuration::TYPE_BLACKLIST_DENIED, - Configuration::DELETE_USER - ) + Configuration::TYPE_BLACKLIST_DENIED, + Configuration::DELETE_USER + ) ) { $entityManager->remove($user->getContact()); $entityManager->remove($user); diff --git a/Controller/BlacklistItemController.php b/Controller/BlacklistItemController.php index cddd5f37..1d46d1ce 100644 --- a/Controller/BlacklistItemController.php +++ b/Controller/BlacklistItemController.php @@ -81,7 +81,7 @@ public function __construct( */ public function fieldsAction(): Response { - return $this->handleView($this->view(array_values($this->getFieldDescriptors()), 200)); + return $this->handleView($this->view(\array_values($this->getFieldDescriptors()), 200)); } /** @@ -148,9 +148,9 @@ public function deleteAction(int $id): Response */ public function cdeleteAction(Request $request): Response { - $ids = array_map(function($id) { + $ids = \array_map(function ($id) { return (int) $id; - }, array_filter(explode(',', (string) $request->query->get('ids', '')))); + }, \array_filter(\explode(',', (string) $request->query->get('ids', '')))); $this->blacklistItemManager->delete($ids); $this->entityManager->flush(); @@ -222,9 +222,10 @@ private function getFieldDescriptors(): array */ private function prepareListResponse(Request $request, ListBuilderInterface $listBuilder, array $fieldDescriptors) { + /** @var string $idsParameter */ $idsParameter = $request->get('ids'); - $ids = array_filter(explode(',', $idsParameter)); - if (null !== $idsParameter && 0 === count($ids)) { + $ids = \array_filter(\explode(',', $idsParameter)); + if (null !== $idsParameter && 0 === \count($ids)) { return []; } diff --git a/Controller/CompletionController.php b/Controller/CompletionController.php index 3034ce3a..72a4f706 100644 --- a/Controller/CompletionController.php +++ b/Controller/CompletionController.php @@ -25,7 +25,7 @@ class CompletionController extends AbstractController getSubscribedServices as getSubscribedServicesOfSaveMediaTrait; } - const TYPE = Configuration::TYPE_COMPLETION; + public const TYPE = Configuration::TYPE_COMPLETION; /** * Handle registration form. @@ -40,6 +40,8 @@ public function indexAction(Request $request): Response $communityManager = $this->getCommunityManager($this->getWebspaceKey()); + $formType = $communityManager->getConfigTypeProperty(self::TYPE, Configuration::FORM_TYPE); + // Create Form $form = $this->createForm( $communityManager->getConfigTypeProperty(self::TYPE, Configuration::FORM_TYPE), @@ -90,6 +92,6 @@ public function indexAction(Request $request): Response */ public static function getSubscribedServices(): array { - return array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait()); + return \array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait()); } } diff --git a/Controller/ConfirmationController.php b/Controller/ConfirmationController.php index dd0cafef..8316ae69 100644 --- a/Controller/ConfirmationController.php +++ b/Controller/ConfirmationController.php @@ -22,7 +22,7 @@ */ class ConfirmationController extends AbstractController { - const TYPE = Configuration::TYPE_CONFIRMATION; + public const TYPE = Configuration::TYPE_CONFIRMATION; /** * Confirm user email address by token. @@ -49,8 +49,8 @@ public function indexAction(Request $request, string $token): Response $redirectTo = $communityManager->getConfigTypeProperty(self::TYPE, Configuration::REDIRECT_TO); if ($redirectTo) { - if (0 === strpos($redirectTo, '/')) { - $url = str_replace('{localization}', $request->getLocale(), $redirectTo); + if (0 === \strpos($redirectTo, '/')) { + $url = \str_replace('{localization}', $request->getLocale(), $redirectTo); } else { $url = $this->getRouter()->generate($redirectTo); } diff --git a/Controller/EmailConfirmationController.php b/Controller/EmailConfirmationController.php index 5c9e8811..0822aff2 100644 --- a/Controller/EmailConfirmationController.php +++ b/Controller/EmailConfirmationController.php @@ -12,7 +12,6 @@ namespace Sulu\Bundle\CommunityBundle\Controller; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; -use Sulu\Bundle\CommunityBundle\Entity\EmailConfirmationToken; use Sulu\Bundle\CommunityBundle\Entity\EmailConfirmationTokenRepository; use Sulu\Bundle\ContactBundle\Entity\Email; use Sulu\Bundle\ContactBundle\Entity\EmailType; @@ -25,7 +24,7 @@ */ class EmailConfirmationController extends AbstractController { - const TYPE = Configuration::TYPE_EMAIL_CONFIRMATION; + public const TYPE = Configuration::TYPE_EMAIL_CONFIRMATION; /** * Overwrite user email with contact email. @@ -36,15 +35,16 @@ public function indexAction(Request $request): Response $repository = $this->getEmailConfirmationTokenRepository(); $success = false; - /** @var EmailConfirmationToken $token */ - $token = $repository->findByToken($request->get('token')); + /** @var string $token */ + $token = $request->get('token'); + $token = $repository->findByToken($token); if (null !== $token) { /** @var User $user */ $user = $token->getUser(); $user->setEmail($user->getContact()->getMainEmail()); $userContact = $user->getContact(); - if (0 === count($userContact->getEmails())) { + if (0 === \count($userContact->getEmails())) { /** @var EmailType $emailType */ $emailType = $entityManager->getReference(EmailType::class, 1); diff --git a/Controller/LoginController.php b/Controller/LoginController.php index 46539173..f9ef9c76 100644 --- a/Controller/LoginController.php +++ b/Controller/LoginController.php @@ -22,7 +22,7 @@ */ class LoginController extends AbstractController { - const TYPE = Configuration::TYPE_LOGIN; + public const TYPE = Configuration::TYPE_LOGIN; /** * Show Login page. diff --git a/Controller/ProfileController.php b/Controller/ProfileController.php index ec673d7c..96c45edf 100644 --- a/Controller/ProfileController.php +++ b/Controller/ProfileController.php @@ -24,7 +24,7 @@ class ProfileController extends AbstractController getSubscribedServices as getSubscribedServicesOfSaveMediaTrait; } - const TYPE = Configuration::TYPE_PROFILE; + public const TYPE = Configuration::TYPE_PROFILE; /** * Handle profile form. @@ -84,6 +84,6 @@ public function indexAction(Request $request): Response */ public static function getSubscribedServices(): array { - return array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait()); + return \array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait()); } } diff --git a/Controller/RegistrationController.php b/Controller/RegistrationController.php index 5d1ef0c0..47dafe3b 100644 --- a/Controller/RegistrationController.php +++ b/Controller/RegistrationController.php @@ -24,7 +24,7 @@ class RegistrationController extends AbstractController getSubscribedServices as getSubscribedServicesOfSaveMediaTrait; } - const TYPE = Configuration::TYPE_REGISTRATION; + public const TYPE = Configuration::TYPE_REGISTRATION; /** * Handle registration form. @@ -89,6 +89,6 @@ public function indexAction(Request $request): Response */ public static function getSubscribedServices(): array { - return array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait()); + return \array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait()); } } diff --git a/Controller/SaveMediaTrait.php b/Controller/SaveMediaTrait.php index dfacb1c5..15762e4f 100644 --- a/Controller/SaveMediaTrait.php +++ b/Controller/SaveMediaTrait.php @@ -42,7 +42,7 @@ private function saveDocuments(FormInterface $form, User $user, string $locale): return []; } - if (!is_array($uploadedFiles)) { + if (!\is_array($uploadedFiles)) { $uploadedFiles = [$uploadedFiles]; } @@ -64,6 +64,7 @@ protected function saveAvatar(FormInterface $form, User $user, string $locale): return null; } + /** @var UploadedFile|null $uploadedFile */ $uploadedFile = $form->get('avatar')->getData(); if (null === $uploadedFile) { return null; @@ -72,7 +73,7 @@ protected function saveAvatar(FormInterface $form, User $user, string $locale): $avatar = $user->getContact()->getAvatar(); /** @var MediaInterface|null $avatar */ - $apiMedia = $this->saveMedia($uploadedFile, (null !== $avatar ? $avatar->getId() : null), $locale, $user->getId()); + $apiMedia = $this->saveMedia($uploadedFile, null !== $avatar ? $avatar->getId() : null, $locale, $user->getId()); $user->getContact()->setAvatar($apiMedia->getEntity()); diff --git a/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php b/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php index 17c41f52..bde28d33 100644 --- a/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php +++ b/DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\CommunityBundle\DependencyInjection\CompilerPass; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; +use Sulu\Bundle\CommunityBundle\Manager\CommunityManagerInterface; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -19,15 +20,55 @@ /** * Create foreach configured webspace a community manager. + * + * @phpstan-type TypeConfigProperties array{ + * enabled: bool, + * template: string, + * service: string|null, + * embed_template: string, + * type: string, + * options: mixed[], + * activate_user: bool, + * auto_login: bool, + * redirect_to: string|null, + * email: array{ + * subject: string, + * admin_template: string|null, + * user_template: string|null, + * }, + * delete_user: bool, + * } + * + * @phpstan-type Config array{ + * from: string|string[], + * to: string|string[], + * webspace_key: string, + * role: string|null, + * firewall: string|null, + * maintenance: array{ + * enabled: bool, + * template: string, + * }, + * login: TypeConfigProperties, + * registration: TypeConfigProperties, + * completion: TypeConfigProperties, + * confirmation: TypeConfigProperties, + * password_forget: TypeConfigProperties, + * password_reset: TypeConfigProperties, + * profile: TypeConfigProperties, + * blacklisted: TypeConfigProperties, + * blacklist_confirmed: TypeConfigProperties, + * blacklist_denied: TypeConfigProperties, + * email_confirmation: TypeConfigProperties, + * } + * + * @phpstan-import-type Config from CommunityManagerInterface as CommunityConfig */ class CommunityManagerCompilerPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ public function process(ContainerBuilder $container): void { - /** @var mixed[] $webspacesConfig */ + /** @var array $webspacesConfig */ $webspacesConfig = $container->getParameter('sulu_community.webspaces_config'); $references = []; @@ -39,14 +80,14 @@ public function process(ContainerBuilder $container): void $definition->replaceArgument(0, $webspaceConfig); $definition->replaceArgument(1, $webspaceKey); - $id = sprintf('sulu_community.%s.community_manager', Normalizer::normalize($webspaceKey)); + $id = \sprintf('sulu_community.%s.community_manager', Normalizer::normalize($webspaceKey)); $references[$webspaceKey] = new Reference($id); $container->setDefinition($id, $definition); - if (false !== strpos($webspaceKey, '-')) { + if (false !== \strpos($webspaceKey, '-')) { $container->setAlias( - sprintf('sulu_community.%s.community_manager', $webspaceKey), - sprintf('sulu_community.%s.community_manager', Normalizer::normalize($webspaceKey)) + \sprintf('sulu_community.%s.community_manager', $webspaceKey), + \sprintf('sulu_community.%s.community_manager', Normalizer::normalize($webspaceKey)) ); } } @@ -58,9 +99,9 @@ public function process(ContainerBuilder $container): void /** * Update webspace config. * - * @param mixed[] $webspaceConfig + * @param Config $webspaceConfig * - * @return mixed[] + * @return CommunityConfig */ private function updateWebspaceConfig( ContainerBuilder $container, @@ -77,7 +118,7 @@ private function updateWebspaceConfig( // Set role by webspace key if (null === $webspaceConfig[Configuration::ROLE]) { - $webspaceConfig[Configuration::ROLE] = ucfirst($webspaceKey) . 'User'; + $webspaceConfig[Configuration::ROLE] = \ucfirst($webspaceKey) . 'User'; } // Set email from diff --git a/DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php b/DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php index e21c210c..8804cb31 100644 --- a/DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php +++ b/DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php @@ -21,11 +21,8 @@ */ class CommunityValidatorCompilerPass implements CompilerPassInterface { - const COMPLETION_LISTENER_SERVICE_ID = 'sulu_community.completion_listener'; + public const COMPLETION_LISTENER_SERVICE_ID = 'sulu_community.completion_listener'; - /** - * {@inheritdoc} - */ public function process(ContainerBuilder $container): void { // If no listener exists do nothing diff --git a/DependencyInjection/CompilerPass/Normalizer.php b/DependencyInjection/CompilerPass/Normalizer.php index 7287a738..a7026268 100644 --- a/DependencyInjection/CompilerPass/Normalizer.php +++ b/DependencyInjection/CompilerPass/Normalizer.php @@ -20,6 +20,6 @@ class Normalizer { public static function normalize(string $text): string { - return str_replace('-', '_', $text); + return \str_replace('-', '_', $text); } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9720a91b..ce818d04 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -30,32 +30,32 @@ */ class Configuration implements ConfigurationInterface { - const WEBSPACES = 'webspaces'; + public const WEBSPACES = 'webspaces'; // Basic Webspace configuration - const EMAIL_FROM = 'from'; - const EMAIL_FROM_NAME = 'name'; - const EMAIL_FROM_EMAIL = 'email'; - const EMAIL_TO = 'to'; - const EMAIL_TO_NAME = 'name'; - const EMAIL_TO_EMAIL = 'email'; - const ROLE = 'role'; - const WEBSPACE_KEY = 'webspace_key'; - const FIREWALL = 'firewall'; - const MAINTENANCE = 'maintenance'; + public const EMAIL_FROM = 'from'; + public const EMAIL_FROM_NAME = 'name'; + public const EMAIL_FROM_EMAIL = 'email'; + public const EMAIL_TO = 'to'; + public const EMAIL_TO_NAME = 'name'; + public const EMAIL_TO_EMAIL = 'email'; + public const ROLE = 'role'; + public const WEBSPACE_KEY = 'webspace_key'; + public const FIREWALL = 'firewall'; + public const MAINTENANCE = 'maintenance'; // Form types - const TYPE_LOGIN = 'login'; - const TYPE_REGISTRATION = 'registration'; - const TYPE_COMPLETION = 'completion'; - const TYPE_CONFIRMATION = 'confirmation'; - const TYPE_PASSWORD_FORGET = 'password_forget'; - const TYPE_PASSWORD_RESET = 'password_reset'; - const TYPE_BLACKLISTED = 'blacklisted'; - const TYPE_BLACKLIST_CONFIRMED = 'blacklist_confirmed'; - const TYPE_BLACKLIST_DENIED = 'blacklist_denied'; - const TYPE_PROFILE = 'profile'; - const TYPE_EMAIL_CONFIRMATION = 'email_confirmation'; + public const TYPE_LOGIN = 'login'; + public const TYPE_REGISTRATION = 'registration'; + public const TYPE_COMPLETION = 'completion'; + public const TYPE_CONFIRMATION = 'confirmation'; + public const TYPE_PASSWORD_FORGET = 'password_forget'; + public const TYPE_PASSWORD_RESET = 'password_reset'; + public const TYPE_BLACKLISTED = 'blacklisted'; + public const TYPE_BLACKLIST_CONFIRMED = 'blacklist_confirmed'; + public const TYPE_BLACKLIST_DENIED = 'blacklist_denied'; + public const TYPE_PROFILE = 'profile'; + public const TYPE_EMAIL_CONFIRMATION = 'email_confirmation'; public static $TYPES = [ self::TYPE_LOGIN, @@ -72,28 +72,25 @@ class Configuration implements ConfigurationInterface ]; // Type configurations - const ENABLED = 'enabled'; - const TEMPLATE = 'template'; - const SERVICE = 'service'; - const EMBED_TEMPLATE = 'embed_template'; - const FORM_TYPE = 'type'; - const FORM_TYPE_OPTIONS = 'options'; - const ACTIVATE_USER = 'activate_user'; - const AUTO_LOGIN = 'auto_login'; - const REDIRECT_TO = 'redirect_to'; - const EMAIL = 'email'; - const EMAIL_SUBJECT = 'subject'; - const EMAIL_ADMIN_TEMPLATE = 'admin_template'; - const EMAIL_USER_TEMPLATE = 'user_template'; - const DELETE_USER = 'delete_user'; + public const ENABLED = 'enabled'; + public const TEMPLATE = 'template'; + public const SERVICE = 'service'; + public const EMBED_TEMPLATE = 'embed_template'; + public const FORM_TYPE = 'type'; + public const FORM_TYPE_OPTIONS = 'options'; + public const ACTIVATE_USER = 'activate_user'; + public const AUTO_LOGIN = 'auto_login'; + public const REDIRECT_TO = 'redirect_to'; + public const EMAIL = 'email'; + public const EMAIL_SUBJECT = 'subject'; + public const EMAIL_ADMIN_TEMPLATE = 'admin_template'; + public const EMAIL_USER_TEMPLATE = 'user_template'; + public const DELETE_USER = 'delete_user'; // Other configurations - const LAST_LOGIN = 'last_login'; - const REFRESH_INTERVAL = 'refresh_interval'; + public const LAST_LOGIN = 'last_login'; + public const REFRESH_INTERVAL = 'refresh_interval'; - /** - * {@inheritdoc} - */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('sulu_community'); @@ -139,7 +136,7 @@ public function getConfigTreeBuilder() ->end() ->beforeNormalization() ->ifString() - ->then(function($value) { + ->then(function ($value) { return [ self::EMAIL_FROM_NAME => $value, self::EMAIL_FROM_EMAIL => $value, @@ -154,7 +151,7 @@ public function getConfigTreeBuilder() ->end() ->beforeNormalization() ->ifString() - ->then(function($value) { + ->then(function ($value) { return [ self::EMAIL_TO_NAME => $value, self::EMAIL_TO_EMAIL => $value, diff --git a/DependencyInjection/SuluCommunityExtension.php b/DependencyInjection/SuluCommunityExtension.php index cb4e6404..d456bdac 100644 --- a/DependencyInjection/SuluCommunityExtension.php +++ b/DependencyInjection/SuluCommunityExtension.php @@ -27,9 +27,6 @@ class SuluCommunityExtension extends Extension implements PrependExtensionInterf { use PersistenceExtensionTrait; - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); @@ -57,9 +54,6 @@ public function load(array $configs, ContainerBuilder $container): void } } - /** - * {@inheritdoc} - */ public function prepend(ContainerBuilder $container): void { if ($container->hasExtension('sulu_admin')) { diff --git a/Entity/BlacklistItem.php b/Entity/BlacklistItem.php index 0aab9fe2..e7bfd6ee 100644 --- a/Entity/BlacklistItem.php +++ b/Entity/BlacklistItem.php @@ -16,8 +16,8 @@ */ class BlacklistItem { - const TYPE_REQUEST = 'request'; - const TYPE_BLOCK = 'block'; + public const TYPE_REQUEST = 'request'; + public const TYPE_BLOCK = 'block'; /** * @var string[] @@ -79,7 +79,7 @@ public function getPattern(): ?string public function setPattern(string $pattern): self { $this->pattern = $pattern; - $this->regexp = str_replace('\*', '[^@]*', preg_quote($pattern)); + $this->regexp = \str_replace('\*', '[^@]*', \preg_quote($pattern)); return $this; } @@ -105,7 +105,7 @@ public function getType(): ?string */ public function setType(string $type): self { - if (!in_array($type, self::$types)) { + if (!\in_array($type, self::$types, true)) { throw new InvalidTypeException(self::$types, $type); } diff --git a/Entity/BlacklistItemRepository.php b/Entity/BlacklistItemRepository.php index af6eeef8..7bc842a9 100644 --- a/Entity/BlacklistItemRepository.php +++ b/Entity/BlacklistItemRepository.php @@ -33,6 +33,7 @@ public function findBySender($email) ->where('REGEXP(:email, entity.regexp) = true') ->setParameter('email', $email); + /** @var BlacklistItem[] */ return $queryBuilder->getQuery()->getResult(); } } diff --git a/Entity/BlacklistUser.php b/Entity/BlacklistUser.php index 98b04087..52d38a16 100644 --- a/Entity/BlacklistUser.php +++ b/Entity/BlacklistUser.php @@ -18,9 +18,9 @@ */ class BlacklistUser { - const TYPE_NEW = 0; - const TYPE_CONFIRMED = 1; - const TYPE_DENIED = 2; + public const TYPE_NEW = 0; + public const TYPE_CONFIRMED = 1; + public const TYPE_DENIED = 2; /** * @var int diff --git a/Entity/InvalidTypeException.php b/Entity/InvalidTypeException.php index 4e74eb1a..4d2a94fd 100644 --- a/Entity/InvalidTypeException.php +++ b/Entity/InvalidTypeException.php @@ -32,7 +32,7 @@ class InvalidTypeException extends \InvalidArgumentException public function __construct(array $validTypes, string $type) { parent::__construct( - sprintf('Invalid type "%s" given. Valid types are [%s]', $type, implode(', ', $validTypes)), + \sprintf('Invalid type "%s" given. Valid types are [%s]', $type, \implode(', ', $validTypes)), 10000 ); diff --git a/Event/AbstractCommunityEvent.php b/Event/AbstractCommunityEvent.php index 8f3e584d..1b714d5c 100644 --- a/Event/AbstractCommunityEvent.php +++ b/Event/AbstractCommunityEvent.php @@ -11,11 +11,15 @@ namespace Sulu\Bundle\CommunityBundle\Event; +use Sulu\Bundle\CommunityBundle\Manager\CommunityManagerInterface; use Sulu\Bundle\SecurityBundle\Entity\User; use Symfony\Contracts\EventDispatcher\Event; /** * Event for community actions with config and the user which throw the event. + * + * @phpstan-import-type Config from CommunityManagerInterface + * @phpstan-import-type TypeConfigProperties from CommunityManagerInterface */ abstract class AbstractCommunityEvent extends Event { @@ -25,14 +29,14 @@ abstract class AbstractCommunityEvent extends Event protected $user; /** - * @var mixed[] + * @var Config */ protected $config; /** * CommunityEvent constructor. * - * @param mixed[] $config + * @param Config $config */ public function __construct(User $user, array $config) { @@ -51,7 +55,7 @@ public function getUser(): User /** * Get config. * - * @return mixed[] + * @return Config */ public function getConfig(): array { @@ -61,7 +65,11 @@ public function getConfig(): array /** * Get config property. * - * @return mixed + * @template TConfig of string&key-of + * + * @param TConfig $property + * + * @return Config[TTypeConfig] */ public function getConfigProperty(string $property) { @@ -71,7 +79,13 @@ public function getConfigProperty(string $property) /** * Get config type property. * - * @return mixed + * @template TConfig of string&key-of + * @template TTypeConfigProperty of string&key-of + * + * @param TConfig $type + * @param TTypeConfigProperty $property + * + * @return Config[TConfig][TTypeConfigProperty] */ public function getConfigTypeProperty(string $type, string $property) { diff --git a/EventListener/BlacklistListener.php b/EventListener/BlacklistListener.php index fbb963d2..b248842a 100644 --- a/EventListener/BlacklistListener.php +++ b/EventListener/BlacklistListener.php @@ -106,7 +106,7 @@ private function getType(string $email): ?string { $items = $this->blacklistItemRepository->findBySender($email); - if (0 === count($items)) { + if (0 === \count($items)) { return null; } diff --git a/EventListener/CompletionListener.php b/EventListener/CompletionListener.php index 8a68480f..d61acb1e 100644 --- a/EventListener/CompletionListener.php +++ b/EventListener/CompletionListener.php @@ -12,6 +12,7 @@ namespace Sulu\Bundle\CommunityBundle\EventListener; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; +use Sulu\Bundle\CommunityBundle\Manager\CommunityManagerInterface; use Sulu\Bundle\CommunityBundle\Validator\User\CompletionInterface; use Sulu\Bundle\SecurityBundle\Entity\User; use Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface; @@ -28,6 +29,8 @@ * Validates the current user entity. * * @internal Register a validator of type CompletionInterface to change the validation + * + * @phpstan-import-type Config from CommunityManagerInterface */ class CompletionListener implements EventSubscriberInterface { @@ -57,7 +60,7 @@ class CompletionListener implements EventSubscriberInterface protected $validators; /** - * @var mixed[] + * @var array */ protected $config; @@ -65,7 +68,7 @@ class CompletionListener implements EventSubscriberInterface * CompletionListener constructor. * * @param CompletionInterface[] $validators - * @param mixed[] $config + * @param array $config */ public function __construct( RequestAnalyzerInterface $requestAnalyzer, @@ -131,10 +134,12 @@ public function onRequest(RequestEvent $event): void $expectedFirewall = $this->config[$webspaceKey][Configuration::FIREWALL] ?? null; // TODO find a better way to detect the current firewall - $currentFirewall = str_replace( + /** @var string $firewallContext */ + $firewallContext = $request->attributes->get('_firewall_context', ''); + $currentFirewall = \str_replace( 'security.firewall.map.context.', '', - $request->attributes->get('_firewall_context', '') + $firewallContext ); if ($expectedFirewall !== $currentFirewall) { diff --git a/Form/Type/CompletionContactType.php b/Form/Type/CompletionContactType.php index a46cc431..2d94245b 100644 --- a/Form/Type/CompletionContactType.php +++ b/Form/Type/CompletionContactType.php @@ -22,11 +22,9 @@ */ class CompletionContactType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { + /** @var Contact $contact */ $contact = $builder->getData(); if (!$contact->getFirstName()) { @@ -38,9 +36,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void } } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ @@ -49,9 +44,6 @@ public function configureOptions(OptionsResolver $resolver): void ]); } - /** - * {@inheritdoc} - */ public function getBlockPrefix() { return 'contact'; diff --git a/Form/Type/CompletionType.php b/Form/Type/CompletionType.php index 5aaabeb7..9ca76d14 100644 --- a/Form/Type/CompletionType.php +++ b/Form/Type/CompletionType.php @@ -24,11 +24,9 @@ */ class CompletionType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { + /** @var User $user */ $user = $builder->getData(); if (!$user->getUsername()) { @@ -54,9 +52,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('submit', SubmitType::class); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults( diff --git a/Form/Type/PasswordForgetType.php b/Form/Type/PasswordForgetType.php index dcba7638..98501934 100644 --- a/Form/Type/PasswordForgetType.php +++ b/Form/Type/PasswordForgetType.php @@ -24,9 +24,6 @@ */ class PasswordForgetType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('email_username', TextType::class, [ @@ -40,9 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('submit', SubmitType::class); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ diff --git a/Form/Type/PasswordResetType.php b/Form/Type/PasswordResetType.php index 4f91f140..ab4a379f 100644 --- a/Form/Type/PasswordResetType.php +++ b/Form/Type/PasswordResetType.php @@ -23,9 +23,6 @@ */ class PasswordResetType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add( @@ -39,9 +36,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('submit', SubmitType::class); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults( diff --git a/Form/Type/ProfileType.php b/Form/Type/ProfileType.php index fe443377..babb4fa5 100644 --- a/Form/Type/ProfileType.php +++ b/Form/Type/ProfileType.php @@ -29,9 +29,6 @@ */ class ProfileType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('plainPassword', PasswordType::class, ['mapped' => false, 'required' => false]); @@ -101,9 +98,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('submit', SubmitType::class); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults( diff --git a/Form/Type/RegistrationType.php b/Form/Type/RegistrationType.php index 5efadd48..176ea05f 100644 --- a/Form/Type/RegistrationType.php +++ b/Form/Type/RegistrationType.php @@ -29,9 +29,6 @@ */ class RegistrationType extends AbstractType { - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('username', TextType::class); @@ -70,16 +67,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('submit', SubmitType::class); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults( [ 'data_class' => User::class, 'validation_groups' => ['registration'], - 'empty_data' => function(FormInterface $form) { + 'empty_data' => function (FormInterface $form) { $user = new User(); $user->setContact(new Contact()); diff --git a/Mail/Mail.php b/Mail/Mail.php index 44a22c75..76f0d352 100644 --- a/Mail/Mail.php +++ b/Mail/Mail.php @@ -23,7 +23,11 @@ class Mail * * @param string|string[] $from * @param string|string[] $to - * @param mixed[] $config + * @param array{ + * subject: string, + * user_template: string|null, + * admin_template: string|null, + * } $config * * @return Mail */ diff --git a/Mail/MailFactory.php b/Mail/MailFactory.php index 4d28643f..663ca4eb 100644 --- a/Mail/MailFactory.php +++ b/Mail/MailFactory.php @@ -43,16 +43,13 @@ public function __construct(\Swift_Mailer $mailer, Environment $twig, Translator $this->translator = $translator; } - /** - * {@inheritdoc} - */ public function sendEmails(Mail $mail, User $user, array $parameters = []): void { $email = $mail->getUserEmail(); if (!$email) { $email = $user->getEmail(); } - $data = array_merge($parameters, ['user' => $user]); + $data = \array_merge($parameters, ['user' => $user]); // Send User Email if (null !== $mail->getUserTemplate() && $email) { diff --git a/Manager/BlacklistItemManager.php b/Manager/BlacklistItemManager.php index 3668c02f..6f3b0b4b 100644 --- a/Manager/BlacklistItemManager.php +++ b/Manager/BlacklistItemManager.php @@ -36,9 +36,6 @@ public function __construct(EntityManagerInterface $entityManager, BlacklistItem $this->blacklistItemRepository = $blacklistItemRepository; } - /** - * {@inheritdoc} - */ public function find(int $id): BlacklistItem { /** @var BlacklistItem $blacklistItem */ @@ -47,9 +44,6 @@ public function find(int $id): BlacklistItem return $blacklistItem; } - /** - * {@inheritdoc} - */ public function create(): BlacklistItem { $item = $this->blacklistItemRepository->createNew(); @@ -59,12 +53,9 @@ public function create(): BlacklistItem return $item; } - /** - * {@inheritdoc} - */ public function delete($ids): void { - if (!is_array($ids)) { + if (!\is_array($ids)) { $ids = [$ids]; } diff --git a/Manager/CommunityManager.php b/Manager/CommunityManager.php index 338bc20f..9e2a073f 100644 --- a/Manager/CommunityManager.php +++ b/Manager/CommunityManager.php @@ -33,11 +33,14 @@ /** * Handles registration, confirmation, password reset and forget. + * + * @phpstan-import-type Config from CommunityManagerInterface + * @phpstan-import-type TypeConfigProperties from CommunityManagerInterface */ class CommunityManager implements CommunityManagerInterface { /** - * @var mixed[] + * @var Config */ protected $config; @@ -82,7 +85,7 @@ class CommunityManager implements CommunityManagerInterface protected $mailFactory; /** - * @param mixed[] $config + * @param Config $config */ public function __construct( array $config, @@ -100,17 +103,11 @@ public function __construct( $this->mailFactory = $mailFactory; } - /** - * {@inheritdoc} - */ public function getWebspaceKey(): string { return $this->webspaceKey; } - /** - * {@inheritdoc} - */ public function register(User $user): User { /** @var string|null $userLocale */ @@ -139,9 +136,6 @@ public function register(User $user): User return $user; } - /** - * {@inheritdoc} - */ public function completion(User $user): User { // Event @@ -151,9 +145,6 @@ public function completion(User $user): User return $user; } - /** - * {@inheritdoc} - */ public function login(User $user, Request $request): void { if (!$user->getEnabled()) { @@ -173,9 +164,6 @@ public function login(User $user, Request $request): void $this->eventDispatcher->dispatch($event, SecurityEvents::INTERACTIVE_LOGIN); } - /** - * {@inheritdoc} - */ public function confirm(string $token): ?User { $user = $this->userManager->findByConfirmationKey($token); @@ -195,9 +183,6 @@ public function confirm(string $token): ?User return $user; } - /** - * {@inheritdoc} - */ public function passwordForget(string $emailUsername): ?User { $user = $this->userManager->findUser($emailUsername); @@ -220,9 +205,6 @@ public function passwordForget(string $emailUsername): ?User return $user; } - /** - * {@inheritdoc} - */ public function passwordReset(User $user): User { $user->setPasswordResetTokenExpiresAt(null); @@ -236,9 +218,6 @@ public function passwordReset(User $user): User return $user; } - /** - * {@inheritdoc} - */ public function sendEmails(string $type, User $user): void { $this->mailFactory->sendEmails( @@ -251,9 +230,6 @@ public function sendEmails(string $type, User $user): void ); } - /** - * {@inheritdoc} - */ public function saveProfile(User $user): ?User { $this->userManager->updateUser($user); @@ -265,33 +241,24 @@ public function saveProfile(User $user): ?User return $user; } - /** - * {@inheritdoc} - */ public function getConfig(): array { return $this->config; } - /** - * {@inheritdoc} - */ public function getConfigProperty(string $property) { - if (!array_key_exists($property, $this->config)) { - throw new \InvalidArgumentException(sprintf('Property "%s" not found for webspace "%s" in Community Manager.', $property, $this->webspaceKey)); + if (!\array_key_exists($property, $this->config)) { + throw new \InvalidArgumentException(\sprintf('Property "%s" not found for webspace "%s" in Community Manager.', $property, $this->webspaceKey)); } return $this->config[$property]; } - /** - * {@inheritdoc} - */ public function getConfigTypeProperty(string $type, string $property) { - if (!array_key_exists($type, $this->config) || !array_key_exists($property, $this->config[$type])) { - throw new \InvalidArgumentException(sprintf('Property "%s" from type "%s" not found for webspace "%s" in Community Manager.', $property, $type, $this->webspaceKey)); + if (!\array_key_exists($type, $this->config) || !\array_key_exists($property, $this->config[$type])) { + throw new \InvalidArgumentException(\sprintf('Property "%s" from type "%s" not found for webspace "%s" in Community Manager.', $property, $type, $this->webspaceKey)); } return $this->config[$type][$property]; diff --git a/Manager/CommunityManagerInterface.php b/Manager/CommunityManagerInterface.php index f513f31f..f26e8a16 100644 --- a/Manager/CommunityManagerInterface.php +++ b/Manager/CommunityManagerInterface.php @@ -16,6 +16,47 @@ /** * Handles registration, confirmation, password reset and forget. + * + * @phpstan-type TypeConfigProperties array{ + * enabled: bool, + * template: string, + * service: string|null, + * embed_template: string, + * type: string, + * options: mixed[], + * activate_user: bool, + * auto_login: bool, + * redirect_to: string|null, + * email: array{ + * subject: string, + * admin_template: string|null, + * user_template: string|null, + * }, + * delete_user: bool, + * } + * + * @phpstan-type Config array{ + * from: string|string[], + * to: string|string[], + * webspace_key: string, + * role: string, + * firewall: string, + * maintenance: array{ + * enabled: bool, + * template: string, + * }, + * login: TypeConfigProperties, + * registration: TypeConfigProperties, + * completion: TypeConfigProperties, + * confirmation: TypeConfigProperties, + * password_forget: TypeConfigProperties, + * password_reset: TypeConfigProperties, + * profile: TypeConfigProperties, + * blacklisted: TypeConfigProperties, + * blacklist_confirmed: TypeConfigProperties, + * blacklist_denied: TypeConfigProperties, + * email_confirmation: TypeConfigProperties, + * } */ interface CommunityManagerInterface { @@ -57,25 +98,35 @@ public function passwordReset(User $user): User; /** * Get community webspace config. * - * @return mixed[] + * @return Config */ public function getConfig(): array; /** * Get community webspace config property. * - * @return mixed + * @template TConfig of string&key-of + * + * @param TConfig $property * - * @throws \Exception + * @throws \InvalidArgumentException + * + * @return Config[TTypeConfig] */ public function getConfigProperty(string $property); /** * Get community webspace config type property. * - * @return mixed + * @template TConfig of string&key-of + * @template TTypeConfigProperty of string&key-of + * + * @param TConfig $type + * @param TTypeConfigProperty $property + * + * @throws \InvalidArgumentException * - * @throws \Exception + * @return Config[TConfig][TTypeConfigProperty] */ public function getConfigTypeProperty(string $type, string $property); diff --git a/Manager/CommunityManagerRegistry.php b/Manager/CommunityManagerRegistry.php index ed1d7cfe..f982181c 100644 --- a/Manager/CommunityManagerRegistry.php +++ b/Manager/CommunityManagerRegistry.php @@ -26,23 +26,17 @@ public function __construct(array $managers = []) $this->managers = $managers; } - /** - * {@inheritdoc} - */ public function get(string $webspaceKey): CommunityManagerInterface { if (!$this->has($webspaceKey)) { - throw new \InvalidArgumentException(sprintf('Webspace "%s" is not configured.', $webspaceKey)); + throw new \InvalidArgumentException(\sprintf('Webspace "%s" is not configured.', $webspaceKey)); } return $this->managers[$webspaceKey]; } - /** - * {@inheritdoc} - */ public function has(string $webspaceKey): bool { - return array_key_exists($webspaceKey, $this->managers); + return \array_key_exists($webspaceKey, $this->managers); } } diff --git a/Manager/UserManager.php b/Manager/UserManager.php index 67a34158..649d74a8 100644 --- a/Manager/UserManager.php +++ b/Manager/UserManager.php @@ -87,9 +87,6 @@ public function __construct( $this->contactManager = $contactManager; } - /** - * {@inheritdoc} - */ public function createUser(User $user, string $webspaceKey, string $roleName): User { // User needs contact @@ -116,9 +113,6 @@ public function createUser(User $user, string $webspaceKey, string $roleName): U return $user; } - /** - * {@inheritdoc} - */ public function updateUser(User $user): User { $contact = $user->getContact(); @@ -152,9 +146,6 @@ public function updateUser(User $user): User return $user; } - /** - * {@inheritdoc} - */ public function getUniqueToken(string $field): string { $token = $this->tokenGenerator->generateToken(); @@ -181,7 +172,7 @@ protected function createUserRole(User $user, string $webspaceKey, string $roleN $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); if (!$webspace) { - throw new \InvalidArgumentException(sprintf('Webspace with key "%s" could not be found.', $webspaceKey)); + throw new \InvalidArgumentException(\sprintf('Webspace with key "%s" could not be found.', $webspaceKey)); } foreach ($webspace->getLocalizations() as $localization) { @@ -189,7 +180,7 @@ protected function createUserRole(User $user, string $webspaceKey, string $roleN } /** @var string $localeString */ - $localeString = json_encode($locales); + $localeString = \json_encode($locales); $userRole->setLocale($localeString); $userRole->setRole($role); @@ -198,9 +189,6 @@ protected function createUserRole(User $user, string $webspaceKey, string $roleN return $userRole; } - /** - * {@inheritdoc} - */ public function findByPasswordResetToken(string $token): ?User { /** @var User|null $user */ @@ -213,9 +201,6 @@ public function findByPasswordResetToken(string $token): ?User return $user; } - /** - * {@inheritdoc} - */ public function findByConfirmationKey(string $token): ?User { $user = $this->userRepository->findOneBy(['confirmationKey' => $token]); @@ -227,9 +212,6 @@ public function findByConfirmationKey(string $token): ?User return $user; } - /** - * {@inheritdoc} - */ public function findUser(string $identifier): ?User { try { diff --git a/SuluCommunityBundle.php b/SuluCommunityBundle.php index a980f160..9d72133a 100644 --- a/SuluCommunityBundle.php +++ b/SuluCommunityBundle.php @@ -26,9 +26,6 @@ class SuluCommunityBundle extends Bundle { use PersistenceBundleTrait; - /** - * {@inheritdoc} - */ public function build(ContainerBuilder $container): void { $this->buildPersistence( diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index 2293284a..d7cf5351 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -18,12 +18,10 @@ class Kernel extends SuluTestKernel { - /** - * {@inheritdoc} - */ public function registerBundles(): iterable { $bundles = parent::registerBundles(); + $bundles = \is_array($bundles) ? $bundles : \iterator_to_array($bundles); $bundles[] = new SuluCommunityBundle(); if (SuluTestKernel::CONTEXT_WEBSITE === $this->getContext()) { @@ -33,22 +31,24 @@ public function registerBundles(): iterable return $bundles; } - /** - * {@inheritdoc} - */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { parent::registerContainerConfiguration($loader); $loader->load(__DIR__ . '/config/config_' . $this->getContext() . '.yml'); } + /** + * @return array + */ protected function getKernelParameters(): array { $parameters = parent::getKernelParameters(); $gedmoReflection = new \ReflectionClass(\Gedmo\Exception::class); - $parameters['gedmo_directory'] = \dirname($gedmoReflection->getFileName()); + /** @var string $fileName */ + $fileName = $gedmoReflection->getFileName(); + $parameters['gedmo_directory'] = \dirname($fileName); return $parameters; } diff --git a/Tests/Application/bin/console.php b/Tests/Application/bin/console.php index 5bffa804..4d74bbdd 100755 --- a/Tests/Application/bin/console.php +++ b/Tests/Application/bin/console.php @@ -13,9 +13,9 @@ // if you don't want to setup permissions the proper way, just uncomment the following PHP line // read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information -//umask(0000); +// umask(0000); -set_time_limit(0); +\set_time_limit(0); require_once __DIR__ . '/../config/bootstrap.php'; @@ -25,18 +25,14 @@ use Symfony\Component\ErrorHandler\Debug; $input = new ArgvInput(); -$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev'); -$debug = '0' !== getenv('SYMFONY_DEBUG') && !$input->hasParameterOption(['--no-debug', '']) && 'prod' !== $env; +$env = $input->getParameterOption(['--env', '-e'], \getenv('SYMFONY_ENV') ?: 'dev'); +$debug = '0' !== \getenv('SYMFONY_DEBUG') && !$input->hasParameterOption(['--no-debug', '']) && 'prod' !== $env; if ($debug) { - // Clean up when sf 4.3 support is removed - if (class_exists(Debug::class)) { - Debug::enable(); - } else { - \Symfony\Component\Debug\Debug::enable(); - } + Debug::enable(); } +/** @phpstan-ignore-next-line */ $kernel = new Kernel($env, $debug, $suluContext); $application = new Application($kernel); $application->run($input); diff --git a/Tests/Application/config/bootstrap.php b/Tests/Application/config/bootstrap.php index 3bc0a8fd..7314acf9 100644 --- a/Tests/Application/config/bootstrap.php +++ b/Tests/Application/config/bootstrap.php @@ -15,7 +15,7 @@ $file = __DIR__ . '/../../../vendor/autoload.php'; -if (!file_exists($file)) { +if (!\file_exists($file)) { throw new RuntimeException('Install dependencies to run test suite.'); } @@ -23,17 +23,17 @@ // Load cached env vars if the .env.local.php file exists // Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) -if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) { +if (\is_array($env = @include \dirname(__DIR__) . '/.env.local.php')) { $_SERVER += $env; $_ENV += $env; -} elseif (!class_exists(Dotenv::class)) { +} elseif (!\class_exists(Dotenv::class)) { throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); } else { - $path = dirname(__DIR__) . '/.env'; + $path = \dirname(__DIR__) . '/.env'; $dotenv = new Dotenv(); $dotenv->loadEnv($path); } $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; $_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; -$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; +$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || \filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/Tests/Functional/Controller/BlacklistItemControllerTest.php b/Tests/Functional/Controller/BlacklistItemControllerTest.php index 20e68192..ecdc480b 100644 --- a/Tests/Functional/Controller/BlacklistItemControllerTest.php +++ b/Tests/Functional/Controller/BlacklistItemControllerTest.php @@ -22,7 +22,7 @@ class BlacklistItemControllerTest extends SuluTestCase */ private $client; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->client = $this->createAuthenticatedClient(); @@ -36,10 +36,10 @@ public function testCgetEmpty(): void /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals(0, $result['total']); + $this->assertSame(0, $result['total']); $this->assertCount(0, $result['_embedded']['blacklist_items']); } @@ -57,11 +57,11 @@ public function testPost(string $pattern = '*@sulu.io'): array /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals($pattern, $result['pattern']); - $this->assertEquals(BlacklistItem::TYPE_REQUEST, $result['type']); + $this->assertSame($pattern, $result['pattern']); + $this->assertSame(BlacklistItem::TYPE_REQUEST, $result['type']); return $result; } @@ -78,12 +78,12 @@ public function testGet(): array /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals($item['id'], $result['id']); - $this->assertEquals($item['pattern'], $result['pattern']); - $this->assertEquals($item['type'], $result['type']); + $this->assertSame($item['id'], $result['id']); + $this->assertSame($item['pattern'], $result['pattern']); + $this->assertSame($item['type'], $result['type']); return $result; } @@ -97,14 +97,14 @@ public function testCget(): void /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals(1, $result['total']); + $this->assertSame(1, $result['total']); $this->assertCount(1, $result['_embedded']['blacklist_items']); - $this->assertEquals($item['id'], $result['_embedded']['blacklist_items'][0]['id']); - $this->assertEquals($item['pattern'], $result['_embedded']['blacklist_items'][0]['pattern']); - $this->assertEquals($item['type'], $result['_embedded']['blacklist_items'][0]['type']); + $this->assertSame($item['id'], $result['_embedded']['blacklist_items'][0]['id']); + $this->assertSame($item['pattern'], $result['_embedded']['blacklist_items'][0]['pattern']); + $this->assertSame($item['type'], $result['_embedded']['blacklist_items'][0]['type']); } public function testDelete(): void @@ -119,10 +119,10 @@ public function testDelete(): void /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals(0, $result['total']); + $this->assertSame(0, $result['total']); $this->assertCount(0, $result['_embedded']['blacklist_items']); } @@ -131,7 +131,7 @@ public function testCDelete(): void $item1 = $this->testPost(); $item2 = $this->testPost('test@sulu.io'); - $this->client->request('DELETE', '/admin/api/blacklist-items?ids=' . implode(',', [$item1['id'], $item2['id']])); + $this->client->request('DELETE', '/admin/api/blacklist-items?ids=' . \implode(',', [$item1['id'], $item2['id']])); $this->assertHttpStatusCode(204, $this->client->getResponse()); $this->client->request('GET', '/admin/api/blacklist-items'); @@ -139,10 +139,10 @@ public function testCDelete(): void /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals(0, $result['total']); + $this->assertSame(0, $result['total']); $this->assertCount(0, $result['_embedded']['blacklist_items']); } @@ -169,11 +169,11 @@ public function testPut(): void /** @var string $content */ $content = $this->client->getResponse()->getContent(); - $result = json_decode($content, true); + $result = \json_decode($content, true); $this->assertIsArray($result); - $this->assertEquals('test@sulu.io', $result['pattern']); - $this->assertEquals(BlacklistItem::TYPE_BLOCK, $result['type']); + $this->assertSame('test@sulu.io', $result['pattern']); + $this->assertSame(BlacklistItem::TYPE_BLOCK, $result['type']); } public function testPutInvalidType(): void diff --git a/Tests/Functional/Controller/EmailConfirmationControllerTest.php b/Tests/Functional/Controller/EmailConfirmationControllerTest.php index f11b7898..e19bb659 100644 --- a/Tests/Functional/Controller/EmailConfirmationControllerTest.php +++ b/Tests/Functional/Controller/EmailConfirmationControllerTest.php @@ -15,6 +15,7 @@ use Doctrine\ORM\Id\AssignedGenerator; use Doctrine\ORM\Mapping\ClassMetadata; use Sulu\Bundle\CommunityBundle\Entity\EmailConfirmationToken; +use Sulu\Bundle\CommunityBundle\Entity\EmailConfirmationTokenRepository; use Sulu\Bundle\ContactBundle\Entity\Contact; use Sulu\Bundle\ContactBundle\Entity\Email; use Sulu\Bundle\ContactBundle\Entity\EmailType; @@ -35,7 +36,7 @@ class EmailConfirmationControllerTest extends SuluTestCase */ private $client; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->client = $this->createAuthenticatedClient(); @@ -103,7 +104,7 @@ public function testConfirm(): User $this->assertInstanceOf(User::class, $user); $contact = $user->getContact(); - $this->assertEquals($user->getEmail(), $contact->getMainEmail()); + $this->assertSame($user->getEmail(), $contact->getMainEmail()); return $user; } @@ -119,22 +120,36 @@ public function testConfirmWrongToken(): void /** @var EntityManagerInterface $entityManager */ $entityManager = $this->getEntityManager(); - $this->assertNotNull($entityManager->getRepository(EmailConfirmationToken::class)->findByToken('123-123-123')); + /** @var EmailConfirmationTokenRepository $respository */ + $respository = $entityManager->getRepository(EmailConfirmationToken::class); + + $this->assertNotNull($respository->findByToken('123-123-123')); } public function testConfirmWithoutEmail(): void { - $this->getEntityManager()->remove($this->user->getContact()->getEmails()->first()); + /** @var Contact $contact */ + $contact = $this->user->getContact(); + /** @var Email $email */ + $email = $contact->getEmails()->first(); + $this->getEntityManager()->remove($email); $this->user->getContact()->getEmails()->clear(); $this->getEntityManager()->flush(); /** @var User $user */ $user = $this->testConfirm(); - $this->assertCount(1, $user->getContact()->getEmails()); - $this->assertEquals($user->getEmail(), $user->getContact()->getEmails()->first()->getEmail()); + $this->assertCount(1, $contact->getEmails()); + /** @var Email $email */ + $email = $contact->getEmails()->first(); + $this->assertSame($user->getEmail(), $email->getEmail()); } + /** + * @return array{ + * 'sulu.context': SuluKernel::CONTEXT_WEBSITE, + * } + */ protected static function getKernelConfiguration(): array { return [ diff --git a/Tests/Functional/Controller/LoginControllerTest.php b/Tests/Functional/Controller/LoginControllerTest.php index 5b706532..f71601fd 100644 --- a/Tests/Functional/Controller/LoginControllerTest.php +++ b/Tests/Functional/Controller/LoginControllerTest.php @@ -22,7 +22,7 @@ class LoginControllerTest extends SuluTestCase */ private $client; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->client = $this->createWebsiteClient(); @@ -40,6 +40,11 @@ public function testLoginForm(): void $this->assertCount(1, $crawler->filter('button')); } + /** + * @return array{ + * 'sulu.context': SuluKernel::CONTEXT_WEBSITE, + * } + */ protected static function getKernelConfiguration(): array { return [ diff --git a/Tests/Functional/Controller/ProfileControllerTest.php b/Tests/Functional/Controller/ProfileControllerTest.php index c5ec3f87..5818682b 100644 --- a/Tests/Functional/Controller/ProfileControllerTest.php +++ b/Tests/Functional/Controller/ProfileControllerTest.php @@ -30,7 +30,7 @@ class ProfileControllerTest extends SuluTestCase */ private $client; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->client = $this->createAuthenticatedClient(); @@ -43,14 +43,14 @@ public function setUp(): void $addressType->setName('Home'); $addressType->setId(1); - $metadata = $entityManager->getClassMetadata(get_class($addressType)); + $metadata = $entityManager->getClassMetadata(\get_class($addressType)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $emailType = new EmailType(); $emailType->setName('work'); $emailType->setId(1); - $metadata = $entityManager->getClassMetadata(get_class($emailType)); + $metadata = $entityManager->getClassMetadata(\get_class($emailType)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $entityManager->persist($addressType); @@ -107,7 +107,7 @@ private function submitProfile(array $data): User $this->assertCount(1, $crawler->filter('#profile_countryCode')); $this->assertCount(1, $crawler->filter('#profile_note')); - $form = $crawler->selectButton('profile[submit]')->form(array_merge( + $form = $crawler->selectButton('profile[submit]')->form(\array_merge( $data, [ 'profile[_token]' => $crawler->filter('#profile__token')->first()->attr('value'), @@ -124,6 +124,7 @@ private function submitProfile(array $data): User /** @var UserRepository $repository */ $repository = $this->getEntityManager()->getRepository(User::class); + /** @var User */ return $repository->findOneBy(['username' => 'test']); } @@ -135,21 +136,23 @@ public function testProfile(): void 'profile[lastName]' => 'Sulu', 'profile[mainEmail]' => 'sulu@example.org', 'profile[street]' => 'Rathausstraße', - 'profile[number]' => 16, - 'profile[zip]' => 12351, + 'profile[number]' => '16', + 'profile[zip]' => '12351', 'profile[city]' => 'USS Excelsior', 'profile[countryCode]' => 'AT', 'profile[note]' => 'Test', ]); - $this->assertEquals(0, $user->getContact()->getFormOfAddress()); - $this->assertEquals('Hikaru Sulu', $user->getFullname()); - $this->assertEquals('Rathausstraße', $user->getContact()->getMainAddress()->getStreet()); - $this->assertEquals('USS Excelsior', $user->getContact()->getMainAddress()->getCity()); - $this->assertEquals(16, $user->getContact()->getMainAddress()->getNumber()); - $this->assertEquals(12351, $user->getContact()->getMainAddress()->getZip()); - $this->assertEquals('AT', $user->getContact()->getMainAddress()->getCountryCode()); - $this->assertEquals('Test', $user->getContact()->getNote()); + $this->assertSame(0, $user->getContact()->getFormOfAddress()); + $this->assertSame('Hikaru Sulu', $user->getFullname()); + $mainAddress = $user->getContact()->getMainAddress(); + $this->assertNotNull($mainAddress); + $this->assertSame('Rathausstraße', $mainAddress->getStreet()); + $this->assertSame('USS Excelsior', $mainAddress->getCity()); + $this->assertSame('16', $mainAddress->getNumber()); + $this->assertSame('12351', $mainAddress->getZip()); + $this->assertSame('AT', $mainAddress->getCountryCode()); + $this->assertSame('Test', $user->getContact()->getNote()); } public function testProfileWithoutNote(): void @@ -160,8 +163,8 @@ public function testProfileWithoutNote(): void 'profile[lastName]' => 'Sulu', 'profile[mainEmail]' => 'sulu@example.org', 'profile[street]' => 'Rathausstraße', - 'profile[number]' => 16, - 'profile[zip]' => 12351, + 'profile[number]' => '16', + 'profile[zip]' => '12351', 'profile[city]' => 'USS Excelsior', 'profile[countryCode]' => 'AT', ]); @@ -169,6 +172,11 @@ public function testProfileWithoutNote(): void $this->assertNull($user->getContact()->getNote()); } + /** + * @return array{ + * 'sulu.context': SuluKernel::CONTEXT_WEBSITE, + * } + */ protected static function getKernelConfiguration(): array { return [ diff --git a/Tests/Functional/Controller/RegistrationTest.php b/Tests/Functional/Controller/RegistrationTest.php index 64e69671..50201359 100644 --- a/Tests/Functional/Controller/RegistrationTest.php +++ b/Tests/Functional/Controller/RegistrationTest.php @@ -25,6 +25,7 @@ use Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpKernel\Profiler\Profile; /** * This testcases covers the whole registration, confirmation and login process. @@ -38,7 +39,7 @@ class RegistrationTest extends SuluTestCase */ private $client; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->client = $this->createClient(); @@ -55,7 +56,7 @@ public function setUp(): void $emailType->setName('private'); $emailType->setId(1); - $metadata = $entityManager->getClassMetadata(get_class($emailType)); + $metadata = $entityManager->getClassMetadata(\get_class($emailType)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $entityManager->persist($role); @@ -129,7 +130,7 @@ public function testLogin(): void $this->assertHttpStatusCode(302, $this->client->getResponse()); $this->assertInstanceOf(RedirectResponse::class, $this->client->getResponse()); - $this->assertEquals('http://localhost/profile', $this->client->getResponse()->getTargetUrl()); + $this->assertSame('http://localhost/profile', $this->client->getResponse()->getTargetUrl()); } public function testLoginWrongPassword(): void @@ -152,7 +153,7 @@ public function testLoginWrongPassword(): void $this->assertHttpStatusCode(302, $this->client->getResponse()); $this->assertInstanceOf(RedirectResponse::class, $this->client->getResponse()); - $this->assertEquals('http://localhost/login', $this->client->getResponse()->getTargetUrl()); + $this->assertSame('http://localhost/login', $this->client->getResponse()->getTargetUrl()); } public function testRegistrationBlacklistedBlocked(): void @@ -204,14 +205,15 @@ public function testRegistrationBlacklistedRequested(): \Swift_Message $this->assertNotNull($this->findUser()); // check email to admin + /** @var Profile $profile */ $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); /** @var MessageDataCollector $mailCollector */ $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertEquals(1, $mailCollector->getMessageCount()); + $this->assertSame(1, $mailCollector->getMessageCount()); $message = $mailCollector->getMessages()[0]; - $this->assertEquals('admin@localhost', key($message->getTo())); + $this->assertSame('admin@localhost', \key($message->getTo())); return $message; } @@ -235,14 +237,15 @@ public function testBlacklistConfirm(): void $this->assertStringContainsString('User "hikaru@sulu.io" confirmed', $content); // check email to user + /** @var Profile $profile */ $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); /** @var MessageDataCollector $mailCollector */ $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertEquals(1, $mailCollector->getMessageCount()); + $this->assertSame(1, $mailCollector->getMessageCount()); $message = $mailCollector->getMessages()[0]; - $this->assertEquals('hikaru@sulu.io', key($message->getTo())); + $this->assertSame('hikaru@sulu.io', \key($message->getTo())); } public function testBlacklistBlocked(): void @@ -264,12 +267,13 @@ public function testBlacklistBlocked(): void $this->assertStringContainsString('User "hikaru@sulu.io" denied', $content); // check email to user + /** @var Profile $profile */ $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); /** @var MessageDataCollector $mailCollector */ $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertEquals(0, $mailCollector->getMessageCount()); + $this->assertSame(0, $mailCollector->getMessageCount()); } public function testPasswordForget(): void @@ -290,14 +294,15 @@ public function testPasswordForget(): void $this->client->submit($form); // check email to user + /** @var Profile $profile */ $profile = $this->client->getProfile(); $this->assertNotFalse($profile, 'Could not found response profile, is profiler activated?'); /** @var MessageDataCollector $mailCollector */ $mailCollector = $profile->getCollector('swiftmailer'); - $this->assertEquals(1, $mailCollector->getMessageCount()); + $this->assertSame(1, $mailCollector->getMessageCount()); $message = $mailCollector->getMessages()[0]; - $this->assertEquals('hikaru@sulu.io', key($message->getTo())); + $this->assertSame('hikaru@sulu.io', \key($message->getTo())); $emailCrawler = new Crawler(); $emailCrawler->addContent($message->getBody()); @@ -324,7 +329,9 @@ public function testPasswordForget(): void /** @var User $user */ $user = $this->findUser(); - $this->assertStringStartsWith('my-new-password', $user->getPassword()); + $password = $user->getPassword(); + $this->assertNotNull($password); + $this->assertStringStartsWith('my-new-password', $password); } /** @@ -347,6 +354,11 @@ private function findUser(string $username = 'sulu'): ?User } } + /** + * @return array{ + * 'sulu.context': SuluKernel::CONTEXT_WEBSITE, + * } + */ protected static function getKernelConfiguration(): array { return [ diff --git a/Tests/Functional/Entity/BlacklistItemRepositoryTest.php b/Tests/Functional/Entity/BlacklistItemRepositoryTest.php index ccb8206d..6f9e2016 100644 --- a/Tests/Functional/Entity/BlacklistItemRepositoryTest.php +++ b/Tests/Functional/Entity/BlacklistItemRepositoryTest.php @@ -13,11 +13,12 @@ use Doctrine\ORM\EntityManagerInterface; use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; +use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; class BlacklistItemRepositoryTest extends SuluTestCase { - public function setUp(): void + protected function setUp(): void { $this->purgeDatabase(); } @@ -29,6 +30,7 @@ public function testFindBySender(): void /** @var EntityManagerInterface $entityManager */ $entityManager = $this->getEntityManager(); + /** @var BlacklistItemRepository $repository */ $repository = $entityManager->getRepository(BlacklistItem::class); $entityManager->persist($item1); @@ -36,8 +38,8 @@ public function testFindBySender(): void $entityManager->flush(); $entityManager->clear(); - $items = array_map( - function(BlacklistItem $item) { + $items = \array_map( + function (BlacklistItem $item) { return ['pattern' => $item->getPattern(), 'type' => $item->getType()]; }, $repository->findBySender('test@sulu.io') diff --git a/Tests/Unit/Controller/SaveMediaTraitTest.php b/Tests/Unit/Controller/SaveMediaTraitTest.php index d0045505..b2ebcc65 100644 --- a/Tests/Unit/Controller/SaveMediaTraitTest.php +++ b/Tests/Unit/Controller/SaveMediaTraitTest.php @@ -31,17 +31,17 @@ class SaveMediaTraitTest extends TestCase } /** - * @var ObjectProphecy|MediaManagerInterface + * @var ObjectProphecy */ private $mediaManager; /** - * @var ObjectProphecy|SystemCollectionManagerInterface + * @var ObjectProphecy */ private $systemCollectionManager; /** - * @var ObjectProphecy|User + * @var ObjectProphecy */ private $user; @@ -51,17 +51,17 @@ class SaveMediaTraitTest extends TestCase private $locale; /** - * @var ObjectProphecy|FormInterface + * @var ObjectProphecy */ private $form; /** - * @var ObjectProphecy|FormInterface + * @var ObjectProphecy */ private $avatarForm; /** - * @var ObjectProphecy|FormInterface + * @var ObjectProphecy */ private $mediasForm; @@ -71,17 +71,17 @@ class SaveMediaTraitTest extends TestCase private $tempFilePaths = []; /** - * @var ObjectProphecy|Contact + * @var ObjectProphecy */ private $contact; /** - * @var ObjectProphecy|Media + * @var ObjectProphecy */ private $media; /** - * @var ObjectProphecy|ApiMedia + * @var ObjectProphecy */ private $apiMedia; @@ -105,7 +105,7 @@ protected function setUp(): void protected function tearDown(): void { foreach ($this->tempFilePaths as $tempFilePath) { - unlink($tempFilePath); + \unlink($tempFilePath); } } @@ -302,10 +302,10 @@ private function getSystemCollectionManager(): SystemCollectionManagerInterface private function createTempnam(): string { - $filename = tempnam(sys_get_temp_dir(), 'sulu_community_test_media'); + $filename = \tempnam(\sys_get_temp_dir(), 'sulu_community_test_media'); if (false === $filename) { - throw new \RuntimeException('Could not create tempnam in: ' . sys_get_temp_dir()); + throw new \RuntimeException('Could not create tempnam in: ' . \sys_get_temp_dir()); } $this->tempFilePaths[] = $filename; diff --git a/Tests/Unit/Entity/BlacklistItemTest.php b/Tests/Unit/Entity/BlacklistItemTest.php index 28cb8f62..dfa173c1 100644 --- a/Tests/Unit/Entity/BlacklistItemTest.php +++ b/Tests/Unit/Entity/BlacklistItemTest.php @@ -20,17 +20,17 @@ class BlacklistItemTest extends TestCase public function testConstructor(): void { $item = new BlacklistItem('*@sulu.io', BlacklistItem::TYPE_REQUEST); - $this->assertEquals('*@sulu.io', $item->getPattern()); - $this->assertEquals('[^@]*@sulu\.io', $item->getRegexp()); - $this->assertEquals(BlacklistItem::TYPE_REQUEST, $item->getType()); + $this->assertSame('*@sulu.io', $item->getPattern()); + $this->assertSame('[^@]*@sulu\.io', $item->getRegexp()); + $this->assertSame(BlacklistItem::TYPE_REQUEST, $item->getType()); } public function testEmptyConstructor(): void { $item = new BlacklistItem(); - $this->assertEquals(null, $item->getPattern()); - $this->assertEquals(null, $item->getRegexp()); - $this->assertEquals(null, $item->getType()); + $this->assertNull($item->getPattern()); + $this->assertNull($item->getRegexp()); + $this->assertNull($item->getType()); } public function testSetPattern(): void @@ -38,8 +38,8 @@ public function testSetPattern(): void $item = new BlacklistItem(); $item->setPattern('*@sulu.io'); - $this->assertEquals('*@sulu.io', $item->getPattern()); - $this->assertEquals('[^@]*@sulu\.io', $item->getRegexp()); + $this->assertSame('*@sulu.io', $item->getPattern()); + $this->assertSame('[^@]*@sulu\.io', $item->getRegexp()); } public function testSetPatternNoWildcard(): void @@ -47,8 +47,8 @@ public function testSetPatternNoWildcard(): void $item = new BlacklistItem(); $item->setPattern('test@sulu.io'); - $this->assertEquals('test@sulu.io', $item->getPattern()); - $this->assertEquals('test@sulu\.io', $item->getRegexp()); + $this->assertSame('test@sulu.io', $item->getPattern()); + $this->assertSame('test@sulu\.io', $item->getRegexp()); } public function testSetTypeRequest(): void @@ -56,7 +56,7 @@ public function testSetTypeRequest(): void $item = new BlacklistItem(); $item->setType(BlacklistItem::TYPE_REQUEST); - $this->assertEquals(BlacklistItem::TYPE_REQUEST, $item->getType()); + $this->assertSame(BlacklistItem::TYPE_REQUEST, $item->getType()); } public function testSetTypeBlock(): void @@ -64,7 +64,7 @@ public function testSetTypeBlock(): void $item = new BlacklistItem(); $item->setType(BlacklistItem::TYPE_BLOCK); - $this->assertEquals(BlacklistItem::TYPE_BLOCK, $item->getType()); + $this->assertSame(BlacklistItem::TYPE_BLOCK, $item->getType()); } public function testSetTypeBlockInvalid(): void diff --git a/Tests/Unit/Listener/BlacklistListenerTest.php b/Tests/Unit/Listener/BlacklistListenerTest.php index 0eaa4c30..a80079f4 100644 --- a/Tests/Unit/Listener/BlacklistListenerTest.php +++ b/Tests/Unit/Listener/BlacklistListenerTest.php @@ -14,6 +14,7 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; @@ -27,13 +28,32 @@ class BlacklistListenerTest extends TestCase { + /** + * @var ObjectProphecy + */ private $repository; + + /** + * @var ObjectProphecy + */ private $entityManager; + + /** + * @var ObjectProphecy + */ private $tokenGenerator; + + /** + * @var ObjectProphecy + */ private $mailFactory; + + /** + * @var BlacklistListener + */ private $listener; - public function setUp(): void + protected function setUp(): void { $this->repository = $this->prophesize(BlacklistItemRepository::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); @@ -72,7 +92,7 @@ public function testValidateEmail(): void $this->entityManager->persist( Argument::that( - function(BlacklistUser $item) use ($user) { + function (BlacklistUser $item) use ($user) { return '123-123-123' === $item->getToken() && 'sulu-io' === $item->getWebspaceKey() && $item->getUser() === $user->reveal(); diff --git a/Tests/Unit/Listener/EmailConfirmationListenerTest.php b/Tests/Unit/Listener/EmailConfirmationListenerTest.php index df1fc701..7da5a115 100644 --- a/Tests/Unit/Listener/EmailConfirmationListenerTest.php +++ b/Tests/Unit/Listener/EmailConfirmationListenerTest.php @@ -14,6 +14,7 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration; use Sulu\Bundle\CommunityBundle\Entity\EmailConfirmationToken; use Sulu\Bundle\CommunityBundle\Entity\EmailConfirmationTokenRepository; @@ -27,20 +28,52 @@ class EmailConfirmationListenerTest extends TestCase { + /** + * @var ObjectProphecy + */ private $mailFactory; + + /** + * @var ObjectProphecy + */ private $entityManager; + + /** + * @var ObjectProphecy + */ private $repository; + + /** + * @var ObjectProphecy + */ private $tokenGenerator; + + /** + * @var EmailConfirmationListener + */ private $listener; + + /** + * @var ObjectProphecy + */ private $event; + + /** + * @var ObjectProphecy + */ private $user; + + /** + * @var ObjectProphecy + */ private $contact; - private $token; /** - * {@inheritdoc} + * @var ObjectProphecy */ - public function setUp(): void + private $token; + + protected function setUp(): void { $this->mailFactory = $this->prophesize(MailFactoryInterface::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); @@ -81,7 +114,7 @@ public function testSendConfirmation(): void $this->entityManager->persist( Argument::that( - function(EmailConfirmationToken $token) { + function (EmailConfirmationToken $token) { return '123-123-123' === $token->getToken() && $token->getUser() === $this->user->reveal(); } ) diff --git a/Tests/Unit/Mail/MailFactoryTest.php b/Tests/Unit/Mail/MailFactoryTest.php index 9d2e58d2..e2c7f3a5 100644 --- a/Tests/Unit/Mail/MailFactoryTest.php +++ b/Tests/Unit/Mail/MailFactoryTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\CommunityBundle\Mail\Mail; use Sulu\Bundle\CommunityBundle\Mail\MailFactory; use Sulu\Bundle\SecurityBundle\Entity\User; @@ -21,13 +22,32 @@ class MailFactoryTest extends TestCase { + /** + * @var ObjectProphecy<\Swift_Mailer> + */ private $mailer; + + /** + * @var ObjectProphecy + */ private $twig; + + /** + * @var ObjectProphecy + */ private $translator; + + /** + * @var MailFactory + */ private $mailFactory; + + /** + * @var ObjectProphecy + */ private $user; - public function setUp(): void + protected function setUp(): void { $this->mailer = $this->prophesize(\Swift_Mailer::class); $this->twig = $this->prophesize(Environment::class); @@ -51,7 +71,7 @@ public function testSendEmails(): void $this->mailer->send( Argument::that( - function(\Swift_Message $message) { + function (\Swift_Message $message) { return 'User-Template' === $message->getBody() && $message->getFrom() === ['test@sulu.io' => null] && $message->getTo() === ['test@example.com' => null]; @@ -60,7 +80,7 @@ function(\Swift_Message $message) { )->shouldBeCalledTimes(1); $this->mailer->send( Argument::that( - function(\Swift_Message $message) { + function (\Swift_Message $message) { return 'Admin-Template' === $message->getBody() && $message->getFrom() === ['test@sulu.io' => null] && $message->getTo() === ['user@sulu.io' => null]; @@ -81,7 +101,7 @@ public function testSendEmailsNoAdminTemplate(): void $this->mailer->send( Argument::that( - function(\Swift_Message $message) { + function (\Swift_Message $message) { return 'User-Template' === $message->getBody() && $message->getFrom() === ['test@sulu.io' => null] && $message->getTo() === ['test@example.com' => null]; @@ -90,7 +110,7 @@ function(\Swift_Message $message) { )->shouldBeCalledTimes(1); $this->mailer->send( Argument::that( - function(\Swift_Message $message) { + function (\Swift_Message $message) { return 'Admin-Template' === $message->getBody() && $message->getFrom() === ['test@sulu.io' => null] && $message->getTo() === ['user@sulu.io' => null]; @@ -111,7 +131,7 @@ public function testSendEmailsNoUserTemplate(): void $this->mailer->send( Argument::that( - function(\Swift_Message $message) { + function (\Swift_Message $message) { return 'User-Template' === $message->getBody() && $message->getFrom() === ['test@sulu.io' => null] && $message->getTo() === ['test@example.com' => null]; @@ -120,7 +140,7 @@ function(\Swift_Message $message) { )->shouldNotBeCalled(); $this->mailer->send( Argument::that( - function(\Swift_Message $message) { + function (\Swift_Message $message) { return 'Admin-Template' === $message->getBody() && $message->getFrom() === ['test@sulu.io' => null] && $message->getTo() === ['user@sulu.io' => null]; diff --git a/Tests/Unit/Manager/BlacklistItemManagerTest.php b/Tests/Unit/Manager/BlacklistItemManagerTest.php index e27689d0..5bbdbc7e 100644 --- a/Tests/Unit/Manager/BlacklistItemManagerTest.php +++ b/Tests/Unit/Manager/BlacklistItemManagerTest.php @@ -13,17 +13,29 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\CommunityBundle\Entity\BlacklistItem; use Sulu\Bundle\CommunityBundle\Entity\BlacklistItemRepository; use Sulu\Bundle\CommunityBundle\Manager\BlacklistItemManager; class BlacklistItemManagerTest extends TestCase { + /** + * @var ObjectProphecy + */ private $repository; + + /** + * @var ObjectProphecy + */ private $entityManager; + + /** + * @var BlacklistItemManager + */ private $manager; - public function setUp(): void + protected function setUp(): void { $this->repository = $this->prophesize(BlacklistItemRepository::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); @@ -38,7 +50,7 @@ public function testCreate(): void $this->repository->createNew()->willReturn($entity)->shouldBeCalled(); $this->entityManager->persist($entity)->shouldBeCalled(); - $this->assertEquals($entity, $this->manager->create()); + $this->assertSame($entity, $this->manager->create()); } public function testFind(): void @@ -46,7 +58,7 @@ public function testFind(): void $entity = new BlacklistItem(); $this->repository->find(1)->willReturn($entity)->shouldBeCalled(); - $this->assertEquals($entity, $this->manager->find(1)); + $this->assertSame($entity, $this->manager->find(1)); } public function testDeleteSingle(): void diff --git a/Tests/Unit/Manager/CommunityManagerRegistryTest.php b/Tests/Unit/Manager/CommunityManagerRegistryTest.php index 6f1997d1..570f311d 100644 --- a/Tests/Unit/Manager/CommunityManagerRegistryTest.php +++ b/Tests/Unit/Manager/CommunityManagerRegistryTest.php @@ -22,7 +22,7 @@ public function testGet(): void $manager = $this->prophesize(CommunityManager::class); $registry = new CommunityManagerRegistry(['sulu_io' => $manager->reveal()]); - $this->assertEquals($manager->reveal(), $registry->get('sulu_io')); + $this->assertSame($manager->reveal(), $registry->get('sulu_io')); } public function testGetNotExists(): void diff --git a/Tests/phpstan/console-application.php b/Tests/phpstan/console-application.php new file mode 100644 index 00000000..9a867739 --- /dev/null +++ b/Tests/phpstan/console-application.php @@ -0,0 +1,24 @@ +bootEnv(\dirname(__DIR__) . '/Application/.env'); + +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG'], Kernel::CONTEXT_ADMIN); +$kernel->boot(); + +return new Application($kernel); diff --git a/Tests/phpstan/object-manager.php b/Tests/phpstan/object-manager.php new file mode 100644 index 00000000..8a0eff18 --- /dev/null +++ b/Tests/phpstan/object-manager.php @@ -0,0 +1,45 @@ +bootEnv(\dirname(__DIR__) . '/Application/.env'); + +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG'], Kernel::CONTEXT_ADMIN); +$kernel->boot(); + +/** @var ContainerInterface $container */ +$container = $kernel->getContainer(); + +/** @var EntityManager $objectManager */ +$objectManager = $container->get('doctrine')->getManager(); + +// remove ResolveTargetEntityListener from returned EntityManager to not resolve SuluPersistenceBundle classes +// this is a workaround for the following phpstan issue: https://github.com/phpstan/phpstan-doctrine/issues/98 +$resolveTargetEntityListener = \current(\array_filter( + $objectManager->getEventManager()->getListeners('loadClassMetadata'), + static function ($listener) { + return $listener instanceof ResolveTargetEntityListener; + } +)); +if ($resolveTargetEntityListener) { + $objectManager->getEventManager()->removeEventListener([Events::loadClassMetadata], $resolveTargetEntityListener); +} + +return $objectManager; diff --git a/Validator/Constraints/Blocked.php b/Validator/Constraints/Blocked.php index 6ec07ced..2fd8ba2b 100644 --- a/Validator/Constraints/Blocked.php +++ b/Validator/Constraints/Blocked.php @@ -23,9 +23,6 @@ class Blocked extends Constraint */ public $message = 'The email "%email%" is blocked.'; - /** - * {@inheritdoc} - */ public function validatedBy() { return 'blocked_validator'; diff --git a/Validator/Constraints/BlockedValidator.php b/Validator/Constraints/BlockedValidator.php index 6660bb66..dbe55e4c 100644 --- a/Validator/Constraints/BlockedValidator.php +++ b/Validator/Constraints/BlockedValidator.php @@ -32,7 +32,7 @@ public function __construct(BlacklistItemRepository $blacklistItemRepository) } /** - * {@inheritdoc} + * @param string $value */ public function validate($value, Constraint $constraint): void { diff --git a/Validator/Constraints/Exist.php b/Validator/Constraints/Exist.php index 8dc6e62d..0e06b735 100644 --- a/Validator/Constraints/Exist.php +++ b/Validator/Constraints/Exist.php @@ -33,9 +33,6 @@ class Exist extends Constraint */ public $entity = ''; - /** - * {@inheritdoc} - */ public function validatedBy() { return 'exist_validator'; diff --git a/Validator/Constraints/ExistValidator.php b/Validator/Constraints/ExistValidator.php index 291d1cb2..fbf19e02 100644 --- a/Validator/Constraints/ExistValidator.php +++ b/Validator/Constraints/ExistValidator.php @@ -35,7 +35,7 @@ public function __construct(EntityManagerInterface $entityManager) } /** - * {@inheritdoc} + * @param string $value */ public function validate($value, Constraint $constraint): void { diff --git a/composer.json b/composer.json index 3dde2b45..0d6bbec9 100644 --- a/composer.json +++ b/composer.json @@ -7,44 +7,44 @@ "php": "^7.2 || ^8.0", "beberlei/doctrineextensions": "^1.0", "doctrine/doctrine-bundle": "^1.10 || ^2.0", - "doctrine/persistence": "^1.3 || ^2.0", "doctrine/orm": "^2.5.3", + "doctrine/persistence": "^1.3 || ^2.0", "jms/serializer-bundle": "^3.3 || ^4.0", "massive/build-bundle": "^0.3 || ^0.4 || ^0.5", "sulu/sulu": "^2.0.6 || ^2.5@dev", - "symfony/config": "^4.3 || ^5.0", - "symfony/console": "^4.3 || ^5.0", - "symfony/dependency-injection": "^4.3 || ^5.0", - "symfony/event-dispatcher": "^4.3 || ^5.0", - "symfony/form": "^4.3 || ^5.0", - "symfony/framework-bundle": "^4.3 || ^5.0", - "symfony/http-foundation": "^4.3 || ^5.0", - "symfony/http-kernel": "^4.3 || ^5.0", - "symfony/intl": "^4.3 || ^5.0", - "symfony/routing": "^4.3 || ^5.0", - "symfony/security-bundle": "^4.3 || ^5.0", + "symfony/config": "^4.4 || ^5.0", + "symfony/console": "^4.4 || ^5.0", + "symfony/dependency-injection": "^4.4 || ^5.0", + "symfony/event-dispatcher": "^4.4 || ^5.0", + "symfony/form": "^4.4 || ^5.0", + "symfony/framework-bundle": "^4.4 || ^5.0", + "symfony/http-foundation": "^4.4 || ^5.0", + "symfony/http-kernel": "^4.4 || ^5.0", + "symfony/intl": "^4.4 || ^5.0", + "symfony/routing": "^4.4 || ^5.0", + "symfony/security-bundle": "^4.4 || ^5.0", "symfony/swiftmailer-bundle": "^3.1.4" }, "require-dev": { "doctrine/data-fixtures": "^1.3.3", - "friendsofphp/php-cs-fixer": "^2.17", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4", - "jangregor/phpstan-prophecy": "^0.8", + "jangregor/phpstan-prophecy": "^1.0", "massive/search-bundle": "^2.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-symfony": "^0.12", + "php-cs-fixer/shim": "^3.9", + "phpstan/phpstan": "1.0", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^8.2", - "symfony/browser-kit": "^4.3 || ^5.0", - "symfony/css-selector": "^4.3 || ^5.0", - "symfony/dotenv": "^4.3 || ^5.0", + "symfony/browser-kit": "^4.4 || ^5.0", + "symfony/css-selector": "^4.4 || ^5.0", + "symfony/dotenv": "^4.4 || ^5.0", "symfony/monolog-bundle": "^3.1", - "symfony/phpunit-bridge": "^4.3 || ^5.0", - "symfony/stopwatch": "^4.3 || ^5.0", - "symfony/var-dumper": "^4.3 || ^5.0", - "thecodingmachine/phpstan-strict-rules": "^0.12" + "symfony/phpunit-bridge": "^4.4 || ^5.0", + "symfony/stopwatch": "^4.4 || ^5.0", + "symfony/var-dumper": "^4.4 || ^5.0", + "thecodingmachine/phpstan-strict-rules": "^1.0" }, "keywords": [ "registration", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 00000000..3c960b48 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,297 @@ +parameters: + ignoreErrors: + - + message: "#^Strict comparison using \\=\\=\\= between true and array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} will always evaluate to false\\.$#" + count: 1 + path: Controller/BlacklistConfirmationController.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: Controller/CompletionController.php + + - + message: "#^Parameter \\#1 \\$type of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:createForm\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/CompletionController.php + + - + message: "#^Parameter \\#1 \\$url of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:redirect\\(\\) expects string, array\\\\|string\\>\\|string given\\.$#" + count: 1 + path: Controller/CompletionController.php + + - + message: "#^Parameter \\#1 \\$user of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Manager\\\\CommunityManagerInterface\\:\\:completion\\(\\) expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User, mixed given\\.$#" + count: 1 + path: Controller/CompletionController.php + + - + message: "#^Parameter \\#2 \\$user of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Controller\\\\CompletionController\\:\\:saveMediaFields\\(\\) expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User, mixed given\\.$#" + count: 1 + path: Controller/CompletionController.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: Controller/CompletionController.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: Controller/ConfirmationController.php + + - + message: "#^Parameter \\#1 \\$haystack of function strpos expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/ConfirmationController.php + + - + message: "#^Parameter \\#1 \\$name of method Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\:\\:generate\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/ConfirmationController.php + + - + message: "#^Parameter \\#1 \\$url of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:redirect\\(\\) expects string, array\\\\|string\\>\\|string given\\.$#" + count: 1 + path: Controller/ConfirmationController.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: Controller/ConfirmationController.php + + - + message: "#^Parameter \\#1 \\$view of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Controller\\\\AbstractController\\:\\:render\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/LoginController.php + + - + message: "#^If condition is always true\\.$#" + count: 2 + path: Controller/PasswordController.php + + - + message: "#^Parameter \\#1 \\$emailUsername of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Manager\\\\CommunityManagerInterface\\:\\:passwordForget\\(\\) expects string, mixed given\\.$#" + count: 1 + path: Controller/PasswordController.php + + - + message: "#^Parameter \\#1 \\$type of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:createForm\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 2 + path: Controller/PasswordController.php + + - + message: "#^Parameter \\#1 \\$url of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:redirect\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 2 + path: Controller/PasswordController.php + + - + message: "#^Parameter \\#1 \\$user of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Controller\\\\AbstractController\\:\\:setUserPasswordAndSalt\\(\\) expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User, mixed given\\.$#" + count: 1 + path: Controller/PasswordController.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 2 + path: Controller/PasswordController.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: Controller/ProfileController.php + + - + message: "#^Parameter \\#1 \\$type of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:createForm\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/ProfileController.php + + - + message: "#^Parameter \\#1 \\$url of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:redirect\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/ProfileController.php + + - + message: "#^Parameter \\#1 \\$user of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Controller\\\\AbstractController\\:\\:setUserPasswordAndSalt\\(\\) expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User, mixed given\\.$#" + count: 1 + path: Controller/ProfileController.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: Controller/ProfileController.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: Controller/RegistrationController.php + + - + message: "#^Parameter \\#1 \\$type of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:createForm\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/RegistrationController.php + + - + message: "#^Parameter \\#1 \\$url of method Symfony\\\\Bundle\\\\FrameworkBundle\\\\Controller\\\\AbstractController\\:\\:redirect\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Controller/RegistrationController.php + + - + message: "#^Parameter \\#1 \\$user of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Controller\\\\AbstractController\\:\\:setUserPasswordAndSalt\\(\\) expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User, mixed given\\.$#" + count: 1 + path: Controller/RegistrationController.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: Controller/RegistrationController.php + + - + message: "#^Cannot access offset 'template' on mixed\\.$#" + count: 3 + path: DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\DependencyInjection\\\\CompilerPass\\\\CommunityManagerCompilerPass\\:\\:updateWebspaceConfig\\(\\) should return array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} but returns non\\-empty\\-array\\.$#" + count: 1 + path: DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php + + - + message: "#^Offset 'email' does not exist on array\\\\|string\\.$#" + count: 2 + path: DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php + + - + message: "#^Offset 'from' on array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} in isset\\(\\) always exists and is not nullable\\.$#" + count: 1 + path: DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php + + - + message: "#^Offset 'name' does not exist on array\\\\|string\\.$#" + count: 2 + path: DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php + + - + message: "#^Offset 'to' on array\\{from\\: non\\-empty\\-array\\, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} in isset\\(\\) always exists and is not nullable\\.$#" + count: 1 + path: DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php + + - + message: "#^Cannot access offset 'completion' on mixed\\.$#" + count: 1 + path: DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php + + - + message: "#^Cannot access offset 'service' on mixed\\.$#" + count: 1 + path: DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php + + - + message: "#^Parameter \\#1 \\$id of class Symfony\\\\Component\\\\DependencyInjection\\\\Reference constructor expects string, mixed given\\.$#" + count: 1 + path: DependencyInjection/CompilerPass/CommunityValidatorCompilerPass.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Event\\\\AbstractCommunityEvent\\:\\:getConfigProperty\\(\\) should return array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} but returns array\\\\|string\\.$#" + count: 1 + path: Event/AbstractCommunityEvent.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Event\\\\AbstractCommunityEvent\\:\\:getConfigTypeProperty\\(\\) should return array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} but returns array\\|bool\\|string\\|null\\.$#" + count: 1 + path: Event/AbstractCommunityEvent.php + + - + message: "#^Offset TTypeConfigProperty of string does not exist on array\\\\|string\\.$#" + count: 1 + path: Event/AbstractCommunityEvent.php + + - + message: "#^Parameter \\#1 \\$from of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\\\|string, array\\\\|string\\> given\\.$#" + count: 1 + path: EventListener/BlacklistListener.php + + - + message: "#^Parameter \\#2 \\$to of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\\\|string, array\\\\|string\\> given\\.$#" + count: 1 + path: EventListener/BlacklistListener.php + + - + message: "#^Parameter \\#2 \\$webspaceKey of class Sulu\\\\Bundle\\\\CommunityBundle\\\\Entity\\\\BlacklistUser constructor expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: EventListener/BlacklistListener.php + + - + message: "#^Parameter \\#3 \\$config of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\{subject\\: string, user_template\\: string\\|null, admin_template\\: string\\|null\\}, array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} given\\.$#" + count: 1 + path: EventListener/BlacklistListener.php + + - + message: "#^Parameter \\#1 \\$from of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\\\|string, array\\\\|string\\> given\\.$#" + count: 1 + path: EventListener/EmailConfirmationListener.php + + - + message: "#^Parameter \\#2 \\$to of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\\\|string, array\\\\|string\\> given\\.$#" + count: 1 + path: EventListener/EmailConfirmationListener.php + + - + message: "#^Parameter \\#3 \\$config of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\{subject\\: string, user_template\\: string\\|null, admin_template\\: string\\|null\\}, array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} given\\.$#" + count: 1 + path: EventListener/EmailConfirmationListener.php + + - + message: "#^Offset 'email' does not exist on array\\\\|string\\.$#" + count: 1 + path: EventListener/MailListener.php + + - + message: "#^Parameter \\#3 \\$config of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\{subject\\: string, user_template\\: string\\|null, admin_template\\: string\\|null\\}, array\\|bool\\|string\\|null given\\.$#" + count: 1 + path: EventListener/MailListener.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Manager\\\\CommunityManager\\:\\:getConfigProperty\\(\\) should return array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} but returns array\\\\|string\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Method Sulu\\\\Bundle\\\\CommunityBundle\\\\Manager\\\\CommunityManager\\:\\:getConfigTypeProperty\\(\\) should return array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} but returns array\\|bool\\|string\\|null\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#1 \\$enabled of method Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User\\:\\:setEnabled\\(\\) expects bool, array\\\\|string\\> given\\.$#" + count: 2 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#1 \\$from of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\\\|string, array\\\\|string\\> given\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#2 \\$array of function array_key_exists expects array, array\\\\|string given\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#2 \\$to of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\\\|string, array\\\\|string\\> given\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#3 \\$config of static method Sulu\\\\Bundle\\\\CommunityBundle\\\\Mail\\\\Mail\\:\\:create\\(\\) expects array\\{subject\\: string, user_template\\: string\\|null, admin_template\\: string\\|null\\}, array\\{from\\: array\\\\|string, to\\: array\\\\|string, webspace_key\\: string, role\\: string, firewall\\: string, maintenance\\: array\\{enabled\\: bool, template\\: string\\}, login\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, registration\\: array\\{enabled\\: bool, template\\: string, service\\: string\\|null, embed_template\\: string, type\\: string, options\\: array, activate_user\\: bool, auto_login\\: bool, \\.\\.\\.\\}, \\.\\.\\.\\} given\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#3 \\$roleName of method Sulu\\\\Bundle\\\\CommunityBundle\\\\Manager\\\\UserManagerInterface\\:\\:createUser\\(\\) expects string, array\\\\|string\\> given\\.$#" + count: 1 + path: Manager/CommunityManager.php + + - + message: "#^Parameter \\#3 \\$roles of class Symfony\\\\Component\\\\Security\\\\Core\\\\Authentication\\\\Token\\\\UsernamePasswordToken constructor expects array\\, array\\\\|string\\> given\\.$#" + count: 1 + path: Manager/CommunityManager.php + diff --git a/phpstan.neon b/phpstan.neon index 9afaf118..93a2d7ae 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,15 +5,20 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon + - phpstan-baseline.neon parameters: paths: - . level: max - excludes_analyse: + excludePaths: - %currentWorkingDirectory%/DependencyInjection/Configuration.php + - %currentWorkingDirectory%/Tests/Application/var/* - %currentWorkingDirectory%/vendor/* - - %currentWorkingDirectory%/Tests/* symfony: container_xml_path: %currentWorkingDirectory%/Tests/Application/var/cache/admin/dev/Sulu_Bundle_CommunityBundle_Tests_Application_KernelDevDebugContainer.xml + console_application_loader: Tests/phpstan/console-application.php + constant_hassers: false checkGenericClassInNonGenericObjectType: false + doctrine: + objectManagerLoader: Tests/phpstan/object-manager.php