diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 373ce692..2d19efd2 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -31,8 +31,26 @@ jobs: dependency-versions: 'highest' tools: 'composer:v2' env: - SYMFONY_DEPRECATIONS_HELPER: weak + SYMFONY_DEPRECATIONS_HELPER: disabled + - php-version: '8.0' + lint: true + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: disabled + - php-version: '8.1' + lint: true + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: disabled + - php-version: '8.2' + lint: true + dependency-versions: 'highest' + tools: 'composer:v2' + env: + SYMFONY_DEPRECATIONS_HELPER: weak services: mysql: image: mysql:5.7 diff --git a/.gitignore b/.gitignore index 5990b792..d2e292e4 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,5 @@ Tests/Application/var Tests/Application/.env.test.local # php-cs-fixer -.php_cs.cache +.php-cs-fixer.cache php-cs-fixer diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..62f43995 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,49 @@ +exclude(['var/cache', 'tests/Resources/cache', 'node_modules']) + ->in(__DIR__); + +$config = new PhpCsFixer\Config(); +$config->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'class_definition' => false, + 'concat_space' => ['spacing' => 'one'], + 'function_declaration' => ['closure_function_spacing' => 'none'], + 'header_comment' => ['header' => $header], + 'native_constant_invocation' => true, + 'native_function_casing' => true, + 'native_function_invocation' => ['include' => ['@internal']], + 'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false], + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true], + 'ordered_imports' => true, + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_types_order' => false, + 'single_line_throw' => false, + 'single_line_comment_spacing' => false, + 'phpdoc_to_comment' => [ + 'ignored_tags' => ['todo', 'var'], + ], + 'phpdoc_separation' => [ + 'groups' => [ + ['Serializer\\*', 'VirtualProperty', 'Accessor', 'Type', 'Groups', 'Expose', 'Exclude', 'SerializedName', 'Inline', 'ExclusionPolicy'], + ], + ], + 'get_class_to_class_keyword' => false, // should be enabled as soon as support for php < 8 is dropped + 'nullable_type_declaration_for_default_null_value' => true, + 'no_null_property_initialization' => false, + ]) + ->setFinder($finder); + +return $config; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 0bf9e0c5..00000000 --- a/.php_cs.dist +++ /dev/null @@ -1,28 +0,0 @@ -exclude(['var/cache']) - ->in(__DIR__); - -return PhpCsFixer\Config::create() - ->setRules([ - '@Symfony' => true, - 'array_syntax' => ['syntax' => 'short'], - 'class_definition' => false, - 'concat_space' => ['spacing' => 'one'], - 'function_declaration' => ['closure_function_spacing' => 'none'], - 'header_comment' => ['header' => $header], - 'ordered_imports' => true, - 'phpdoc_align' => ['align' => 'left'], - 'phpdoc_types_order' => false, - ]) - ->setFinder($finder); diff --git a/Admin/CommentAdmin.php b/Admin/CommentAdmin.php index 2652981f..d8e69408 100644 --- a/Admin/CommentAdmin.php +++ b/Admin/CommentAdmin.php @@ -27,15 +27,15 @@ */ class CommentAdmin extends Admin { - const COMMENT_SECURITY_CONTEXT = 'sulu.comment.comments'; - const COMMENT_LIST_VIEW = 'sulu_comment.comments.list'; - const COMMENT_EDIT_FORM_VIEW = 'sulu_comment.comments.edit_form'; - const COMMENT_EDIT_FORM_DETAILS_VIEW = 'sulu_comment.comments.edit_form.details'; + public const COMMENT_SECURITY_CONTEXT = 'sulu.comment.comments'; + public const COMMENT_LIST_VIEW = 'sulu_comment.comments.list'; + public const COMMENT_EDIT_FORM_VIEW = 'sulu_comment.comments.edit_form'; + public const COMMENT_EDIT_FORM_DETAILS_VIEW = 'sulu_comment.comments.edit_form.details'; - const THREAD_SECURITY_CONTEXT = 'sulu.comment.threads'; - const THREAD_LIST_VIEW = 'sulu_comment.threads.list'; - const THREAD_EDIT_FORM_VIEW = 'sulu_comment.threads.edit_form'; - const THREAD_EDIT_FORM_DETAILS_VIEW = 'sulu_comment.threads.edit_form.details'; + public const THREAD_SECURITY_CONTEXT = 'sulu.comment.threads'; + public const THREAD_LIST_VIEW = 'sulu_comment.threads.list'; + public const THREAD_EDIT_FORM_VIEW = 'sulu_comment.threads.edit_form'; + public const THREAD_EDIT_FORM_DETAILS_VIEW = 'sulu_comment.threads.edit_form.details'; /** * @var ViewBuilderFactoryInterface @@ -96,8 +96,7 @@ public function configureViews(ViewCollection $viewCollection): void new ToolbarAction('sulu_admin.delete'), ]; - /** @var array $commentFormToolbarActions */ - $commentFormToolbarActions = array_merge($formToolbarActions, [ + $commentFormToolbarActions = \array_merge($formToolbarActions, [ new TogglerToolbarAction( $this->translator->trans('sulu_admin.publish', [], 'admin'), 'published', diff --git a/Controller/CommentController.php b/Controller/CommentController.php index 32c2fa36..91b70c97 100644 --- a/Controller/CommentController.php +++ b/Controller/CommentController.php @@ -105,23 +105,26 @@ public function cgetAction(Request $request): Response if ($threadType) { $listBuilder->in( $fieldDescriptors['threadType'], - array_filter(explode(',', $threadType)) + \array_filter(\explode(',', $threadType)) ); $request->query->remove('threadType'); } + /** @var string $filterValue */ foreach ($request->query->all() as $filterKey => $filterValue) { if (isset($fieldDescriptors[$filterKey])) { $listBuilder->where($fieldDescriptors[$filterKey], $filterValue); } } + /** @var string $route */ + $route = $request->attributes->get('_route'); $results = $listBuilder->execute(); $list = new ListRepresentation( $results, 'comments', - $request->attributes->get('_route'), + $route, $request->query->all(), $listBuilder->getCurrentPage(), $listBuilder->getLimit(), @@ -149,7 +152,9 @@ public function putAction(int $id, Request $request): Response throw new EntityNotFoundException(CommentInterface::class, $id); } - $comment->setMessage($request->request->get('message')); + /** @var string $message */ + $message = $request->request->get('message'); + $comment->setMessage($message); $this->commentManager->update($comment); $this->entityManager->flush(); @@ -163,8 +168,8 @@ public function cdeleteAction(Request $request): Response $ids = $request->query->get('ids', ''); /** @var int[] $ids */ - $ids = array_filter(explode(',', $ids)); - if (0 === count($ids)) { + $ids = \array_filter(\explode(',', $ids)); + if (0 === \count($ids)) { return $this->handleView($this->view(null, 204)); } diff --git a/Controller/ThreadController.php b/Controller/ThreadController.php index 2fa4e5a6..8c1922a7 100644 --- a/Controller/ThreadController.php +++ b/Controller/ThreadController.php @@ -96,22 +96,26 @@ public function cgetAction(Request $request): Response $fieldDescriptors = $this->fieldDescriptorFactory->getFieldDescriptors('threads'); $this->restHelper->initializeListBuilder($listBuilder, $fieldDescriptors); + /** @var string $filterValue */ foreach ($request->query->all() as $filterKey => $filterValue) { if (isset($fieldDescriptors[$filterKey])) { $listBuilder->where($fieldDescriptors[$filterKey], $filterValue); } } + /** @var string $typeParameter */ $typeParameter = $request->get('types'); if ($typeParameter) { - $listBuilder->in($fieldDescriptors['type'], array_filter(explode(',', $typeParameter))); + $listBuilder->in($fieldDescriptors['type'], \array_filter(\explode(',', $typeParameter))); } $items = $listBuilder->execute(); + /** @var string $route */ + $route = $request->attributes->get('_route'); $list = new ListRepresentation( $items, 'threads', - $request->attributes->get('_route'), + $route, $request->query->all(), $listBuilder->getCurrentPage(), $listBuilder->getLimit(), @@ -139,7 +143,9 @@ public function putAction(int $id, Request $request): Response throw new EntityNotFoundException(ThreadInterface::class, $id); } - $thread->setTitle($request->request->get('title')); + /** @var string $title */ + $title = $request->request->get('title'); + $thread->setTitle($title); $this->commentManager->updateThread($thread); $this->entityManager->flush(); @@ -153,8 +159,8 @@ public function cdeleteAction(Request $request): Response $ids = $request->query->get('ids', ''); /** @var int[] $ids */ - $ids = array_filter(explode(',', $ids)); - if (0 === count($ids)) { + $ids = \array_filter(\explode(',', $ids)); + if (0 === \count($ids)) { return $this->handleView($this->view(null, 204)); } diff --git a/Controller/WebsiteCommentController.php b/Controller/WebsiteCommentController.php index a199cbae..64542016 100644 --- a/Controller/WebsiteCommentController.php +++ b/Controller/WebsiteCommentController.php @@ -16,6 +16,7 @@ use FOS\RestBundle\Controller\Annotations\Post; use FOS\RestBundle\Controller\Annotations\RouteResource; use FOS\RestBundle\Routing\ClassResourceInterface; +use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; use Sulu\Bundle\CommentBundle\Entity\Comment; use Sulu\Bundle\CommentBundle\Entity\CommentInterface; @@ -65,17 +66,17 @@ class WebsiteCommentController extends AbstractRestController implements ClassRe private $commentClass; /** - * @var array + * @var array> */ private $commentTypes; /** - * @var array + * @var array */ private $commentDefaultTemplates; /** - * @var array + * @var array */ private $commentSerializationGroups; @@ -84,6 +85,11 @@ class WebsiteCommentController extends AbstractRestController implements ClassRe */ private $enableNestedCommentsDefault; + /** + * @param array> $commentTypes + * @param array $commentDefaultTemplates + * @param array $commentSerializationGroups + */ public function __construct( ViewHandlerInterface $viewHandler, CommentManagerInterface $commentManager, @@ -118,19 +124,20 @@ public function cgetCommentsAction(string $threadId, Request $request): Response { list($type, $entityId) = $this->getThreadIdParts($threadId); - $limit = $request->query->getInt('limit') ?? 10; - $offset = $request->query->getInt('offset') ?? 0; + $limit = $request->query->getInt('limit', 10); + $offset = $request->query->getInt('offset', 0); + /** @var null|int $pageSize */ $pageSize = $request->get('pageSize'); if ($pageSize) { - @\trigger_deprecation('sulu/comment-bundle', '2.x', 'The usage of the "pageSize" parameter is deprecated. + @trigger_deprecation('sulu/comment-bundle', '2.x', 'The usage of the "pageSize" parameter is deprecated. Please use "limit" and "offset instead.'); $limit = $pageSize; } $page = $request->get('page'); if ($page) { - @\trigger_deprecation('sulu/comment-bundle', '2.x', 'The usage of the "page" parameter is deprecated. + @trigger_deprecation('sulu/comment-bundle', '2.x', 'The usage of the "page" parameter is deprecated. Please use "limit" and "offset instead.'); $offset = ($page - 1) * $limit; @@ -166,7 +173,7 @@ public function cgetCommentsAction(string $threadId, Request $request): Response ] ); - $contentData = array_merge( + $contentData = \array_merge( [ 'form' => $form->createView(), 'nestedComments' => $this->getNestedCommentsEnabled($type), @@ -238,7 +245,9 @@ public function postCommentsAction(string $threadId, Request $request): Response /** @var CommentInterface $comment */ $comment = $this->commentRepository->createNew(); - if ($parent = $request->get('parent')) { + /** @var null|int $parent */ + $parent = $request->get('parent'); + if ($parent) { $comment->setParent($this->commentRepository->findCommentById($parent)); } @@ -257,9 +266,12 @@ public function postCommentsAction(string $threadId, Request $request): Response return new Response(null, 400); } + /** @var CommentInterface $comment */ $comment = $form->getData(); - $this->commentManager->addComment($type, $entityId, $comment, $request->get('threadTitle')); + /** @var string $threadTitle */ + $threadTitle = $request->get('threadTitle'); + $this->commentManager->addComment($type, $entityId, $comment, $threadTitle); $this->entityManager->flush(); if ($referrer = $request->query->get('referrer')) { @@ -288,6 +300,7 @@ public function putCommentAction(string $threadId, string $commentId, Request $r { list($type, $entityId) = $this->getThreadIdParts($threadId); + /** @var string $message */ $message = $request->request->get('message'); /** @var Comment $comment */ @@ -317,7 +330,7 @@ public function putCommentAction(string $threadId, string $commentId, Request $r public function deleteCommentAction(string $threadId, string $commentId, Request $request): Response { /** @var Comment $comment */ - $comment = $this->commentRepository->findCommentById(intval($commentId)); + $comment = $this->commentRepository->findCommentById(\intval($commentId)); $this->entityManager->remove($comment); $this->entityManager->flush(); @@ -333,9 +346,16 @@ public function deleteCommentAction(string $threadId, string $commentId, Request return new Response(); } + /** + * @param null|mixed $data + * @param null|string $statusCode + * @param mixed[] $headers + * + * @return View + */ protected function view($data = null, $statusCode = null, array $headers = []) { - $view = parent::view($data, $statusCode, $headers); + $view = parent::view($data, $statusCode ? (int) $statusCode : null, $headers); $context = new Context(); $context->setGroups($this->commentSerializationGroups); @@ -351,18 +371,21 @@ protected function view($data = null, $statusCode = null, array $headers = []) */ private function getThreadIdParts(string $threadId): array { - $pos = strpos($threadId, '-'); + $pos = \strpos($threadId, '-'); if (false === $pos) { throw new \RuntimeException('Thread id is not valid.'); } - return [substr($threadId, 0, $pos), substr($threadId, $pos + 1)]; + return [\substr($threadId, 0, $pos), \substr($threadId, $pos + 1)]; } private function getTemplate(string $type, string $templateType): string { - if (array_key_exists($type, $this->commentTypes)) { - return $this->commentTypes[$type]['templates'][$templateType]; + if (\array_key_exists($type, $this->commentTypes)) { + /** @var array $templates */ + $templates = $this->commentTypes[$type]['templates']; + + return $templates[$templateType]; } return $this->commentDefaultTemplates[$templateType]; @@ -370,8 +393,11 @@ private function getTemplate(string $type, string $templateType): string private function getNestedCommentsEnabled(string $type): bool { - if (array_key_exists($type, $this->commentTypes)) { - return $this->commentTypes[$type]['nested_comments']; + if (\array_key_exists($type, $this->commentTypes)) { + /** @var bool $result */ + $result = $this->commentTypes[$type]['nested_comments']; + + return $result; } return $this->enableNestedCommentsDefault; diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ca2faec2..d35765de 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,9 +23,6 @@ */ class Configuration implements ConfigurationInterface { - /** - * {@inheritdoc} - */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('sulu_comment'); diff --git a/DependencyInjection/SuluCommentExtension.php b/DependencyInjection/SuluCommentExtension.php index 9135ab9c..cc65500c 100644 --- a/DependencyInjection/SuluCommentExtension.php +++ b/DependencyInjection/SuluCommentExtension.php @@ -25,10 +25,7 @@ class SuluCommentExtension extends Extension implements PrependExtensionInterfac { use PersistenceExtensionTrait; - /** - * {@inheritdoc} - */ - public function prepend(ContainerBuilder $container) + public function prepend(ContainerBuilder $container): void { if ($container->hasExtension('jms_serializer')) { $container->prependExtensionConfig( @@ -79,10 +76,7 @@ public function prepend(ContainerBuilder $container) } } - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/Entity/Comment.php b/Entity/Comment.php index 0f1089f6..9e507e53 100644 --- a/Entity/Comment.php +++ b/Entity/Comment.php @@ -31,7 +31,7 @@ class Comment implements CommentInterface, AuditableInterface protected $state = self::STATE_PUBLISHED; /** - * @var string + * @var string|null */ protected $message; @@ -61,11 +61,11 @@ class Comment implements CommentInterface, AuditableInterface protected $parent; /** - * @var Collection|CommentInterface[] + * @var Collection|CommentInterface[] */ protected $children; - public function __construct(int $state = self::STATE_PUBLISHED, ThreadInterface $thread = null) + public function __construct(int $state = self::STATE_PUBLISHED, ?ThreadInterface $thread = null) { $this->state = $state; $this->thread = $thread; diff --git a/Entity/CommentInterface.php b/Entity/CommentInterface.php index fd989de2..c59570b9 100644 --- a/Entity/CommentInterface.php +++ b/Entity/CommentInterface.php @@ -15,9 +15,9 @@ interface CommentInterface { - const STATE_UNPUBLISHED = 0; + public const STATE_UNPUBLISHED = 0; - const STATE_PUBLISHED = 1; + public const STATE_PUBLISHED = 1; public function getId(): int; @@ -39,12 +39,18 @@ public function setThread(ThreadInterface $thread): self; public function getParent(): ?CommentInterface; - public function setParent(CommentInterface $parent = null): CommentInterface; + public function setParent(?CommentInterface $parent = null): CommentInterface; public function getDepth(): int; + /** + * @return Collection + */ public function getChildren(): Collection; + /** + * @return Collection + */ public function getPublishedChildren(): Collection; public function getCreatorFullName(): string; diff --git a/Entity/CommentRepository.php b/Entity/CommentRepository.php index 38dde5f8..5af91a15 100644 --- a/Entity/CommentRepository.php +++ b/Entity/CommentRepository.php @@ -36,7 +36,10 @@ public function findComments(string $type, string $entityId, int $limit = 10, in $query->setFirstResult($offset); } - return $query->getResult(); + /** @var CommentInterface[] $result */ + $result = $query->getResult(); + + return $result; } public function findPublishedComments( @@ -67,7 +70,10 @@ public function findPublishedComments( $query->setFirstResult($offset); } - return $query->getResult(); + /** @var CommentInterface[] $result */ + $result = $query->getResult(); + + return $result; } public function countPublishedComments(string $type, string $entityId): int @@ -82,7 +88,10 @@ public function countPublishedComments(string $type, string $entityId): int ->setParameter('type', $type) ->setParameter('entityId', $entityId); - return $queryBuilder->getQuery()->getSingleScalarResult(); + /** @var int $result */ + $result = $queryBuilder->getQuery()->getSingleScalarResult(); + + return $result; } public function findCommentsByIds(array $ids): array @@ -95,7 +104,10 @@ public function findCommentsByIds(array $ids): array ->setParameter('ids', $ids) ->getQuery(); - return $query->getResult(); + /** @var CommentInterface[] $result */ + $result = $query->getResult(); + + return $result; } public function findCommentById(int $id): ?CommentInterface @@ -109,7 +121,10 @@ public function findCommentById(int $id): ?CommentInterface ->getQuery(); try { - return $query->getSingleResult(); + /** @var CommentInterface $result */ + $result = $query->getSingleResult(); + + return $result; } catch (NoResultException $e) { return null; } @@ -125,8 +140,9 @@ public function delete(CommentInterface $comment): void $this->getEntityManager()->remove($comment); } - public function createNew() + public function createNew(): CommentInterface { + /** @var CommentInterface $className */ $className = $this->getClassName(); return new $className(); diff --git a/Entity/CommentRepositoryInterface.php b/Entity/CommentRepositoryInterface.php index e2718ef5..48b368da 100644 --- a/Entity/CommentRepositoryInterface.php +++ b/Entity/CommentRepositoryInterface.php @@ -13,6 +13,9 @@ use Sulu\Component\Persistence\Repository\RepositoryInterface; +/** + * @extends RepositoryInterface + */ interface CommentRepositoryInterface extends RepositoryInterface { /** diff --git a/Entity/Thread.php b/Entity/Thread.php index b9e40c27..79d4607a 100644 --- a/Entity/Thread.php +++ b/Entity/Thread.php @@ -47,7 +47,7 @@ class Thread implements ThreadInterface, AuditableInterface protected $commentCount = 0; /** - * @var Collection + * @var Collection */ protected $comments; @@ -71,7 +71,10 @@ class Thread implements ThreadInterface, AuditableInterface */ protected $creator; - public function __construct(string $type, string $entityId, Collection $comments = null, int $commentCount = 0) + /** + * @param Collection|null $comments + */ + public function __construct(string $type, string $entityId, ?Collection $comments = null, int $commentCount = 0) { $this->type = $type; $this->entityId = $entityId; diff --git a/Entity/ThreadInterface.php b/Entity/ThreadInterface.php index 775fc1d6..765a4c68 100644 --- a/Entity/ThreadInterface.php +++ b/Entity/ThreadInterface.php @@ -34,7 +34,7 @@ public function decreaseCommentCount(): self; public function setCommentCount(int $commentCount): self; /** - * @return CommentInterface[]|Collection + * @return CommentInterface[]|Collection */ public function getComments(): Collection; diff --git a/Entity/ThreadRepository.php b/Entity/ThreadRepository.php index 2acc3da8..28bd49c2 100644 --- a/Entity/ThreadRepository.php +++ b/Entity/ThreadRepository.php @@ -13,6 +13,9 @@ use Doctrine\ORM\EntityRepository; +/** + * @extends EntityRepository + */ class ThreadRepository extends EntityRepository implements ThreadRepositoryInterface { public function createNew(string $type, string $entityId): ThreadInterface diff --git a/EventSubscriber/CommentSerializationSubscriber.php b/EventSubscriber/CommentSerializationSubscriber.php index 6e6e0ecc..357fad58 100644 --- a/EventSubscriber/CommentSerializationSubscriber.php +++ b/EventSubscriber/CommentSerializationSubscriber.php @@ -18,6 +18,7 @@ use JMS\Serializer\Visitor\SerializationVisitorInterface; use Sulu\Bundle\CommentBundle\Entity\Comment; use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface; +use Sulu\Bundle\SecurityBundle\Entity\User; use Symfony\Component\HttpFoundation\RequestStack; class CommentSerializationSubscriber implements EventSubscriberInterface @@ -38,7 +39,10 @@ public function __construct(MediaManagerInterface $mediaManager, RequestStack $r $this->requestStack = $requestStack; } - public static function getSubscribedEvents() + /** + * @return array> + */ + public static function getSubscribedEvents(): array { return [ [ @@ -52,9 +56,9 @@ public static function getSubscribedEvents() public function onPostSerialize(ObjectEvent $event): void { $context = $event->getContext(); - - if (!$context->hasAttribute('groups') - || !in_array('commentWithAvatar', $context->getAttribute('groups'))) { + /** @var mixed[] $groups */ + $groups = $context->hasAttribute('groups') ? $context->getAttribute('groups') : []; + if (!\in_array('commentWithAvatar', $groups)) { return; } @@ -63,6 +67,7 @@ public function onPostSerialize(ObjectEvent $event): void if (!$comment instanceof Comment || !$creator = $comment->getCreator()) { return; } + /** @var User $creator */ /** @var SerializationVisitorInterface $visitor */ $visitor = $event->getVisitor(); diff --git a/Events/Events.php b/Events/Events.php index 1243dfe1..a1c922e4 100644 --- a/Events/Events.php +++ b/Events/Events.php @@ -13,25 +13,25 @@ final class Events { - const PRE_PERSIST_EVENT = 'sulu_comment.pre_persist'; + public const PRE_PERSIST_EVENT = 'sulu_comment.pre_persist'; - const POST_PERSIST_EVENT = 'sulu_comment.post_persist'; + public const POST_PERSIST_EVENT = 'sulu_comment.post_persist'; - const PRE_DELETE_EVENT = 'sulu_comment.pre_delete'; + public const PRE_DELETE_EVENT = 'sulu_comment.pre_delete'; - const POST_DELETE_EVENT = 'sulu_comment.post_delete'; + public const POST_DELETE_EVENT = 'sulu_comment.post_delete'; - const PRE_UPDATE_EVENT = 'sulu_comment.pre_update'; + public const PRE_UPDATE_EVENT = 'sulu_comment.pre_update'; - const PUBLISH_EVENT = 'sulu_comment.publish'; + public const PUBLISH_EVENT = 'sulu_comment.publish'; - const UNPUBLISH_EVENT = 'sulu_comment.unpublish'; + public const UNPUBLISH_EVENT = 'sulu_comment.unpublish'; - const THREAD_PRE_UPDATE_EVENT = 'sulu_comment.thread.pre_update'; + public const THREAD_PRE_UPDATE_EVENT = 'sulu_comment.thread.pre_update'; - const THREAD_PRE_DELETE_EVENT = 'sulu_comment.thread.pre_delete'; + public const THREAD_PRE_DELETE_EVENT = 'sulu_comment.thread.pre_delete'; - const THREAD_POST_DELETE_EVENT = 'sulu_comment.thread.post_delete'; + public const THREAD_POST_DELETE_EVENT = 'sulu_comment.thread.post_delete'; /** * Private constructor. diff --git a/Form/Type/CommentType.php b/Form/Type/CommentType.php index a493496a..a54d9faa 100644 --- a/Form/Type/CommentType.php +++ b/Form/Type/CommentType.php @@ -31,7 +31,7 @@ public function __construct(UrlGeneratorInterface $router) $this->router = $router; } - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $attributes = ['threadId' => $options['threadId']]; if ($options['referrer']) { @@ -47,7 +47,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add('submit', SubmitType::class); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired('threadId'); $resolver->setDefault('referrer', null); diff --git a/Manager/CommentManager.php b/Manager/CommentManager.php index 56e01d20..65c5f9c6 100644 --- a/Manager/CommentManager.php +++ b/Manager/CommentManager.php @@ -74,7 +74,7 @@ public function addComment( string $type, string $entityId, CommentInterface $comment, - string $threadTitle = null + ?string $threadTitle = null ): ThreadInterface { $thread = $this->threadRepository->findThread($type, $entityId); if (!$thread) { @@ -106,7 +106,7 @@ public function update(CommentInterface $comment): CommentInterface public function delete(array $ids): void { - if (!is_array($ids)) { + if (!\is_array($ids)) { $ids = [$ids]; } @@ -125,7 +125,7 @@ public function updateThread(ThreadInterface $thread): ThreadInterface public function deleteThreads(array $ids): void { - if (!is_array($ids)) { + if (!\is_array($ids)) { $ids = [$ids]; } diff --git a/SuluCommentBundle.php b/SuluCommentBundle.php index 86c0a14d..ae2bef2f 100644 --- a/SuluCommentBundle.php +++ b/SuluCommentBundle.php @@ -24,10 +24,7 @@ class SuluCommentBundle extends Bundle { use PersistenceBundleTrait; - /** - * {@inheritdoc} - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { $this->buildPersistence( [ diff --git a/Tests/Application/.env b/Tests/Application/.env index 01152b1b..b51d3365 100644 --- a/Tests/Application/.env +++ b/Tests/Application/.env @@ -1,2 +1,2 @@ APP_ENV=test -DATABASE_URL=mysql://root@localhost:3306/su_comment_test +DATABASE_URL=mysql://root@127.0.0.1:3306/su_comment_test diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index 40f9b673..72f051cc 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -20,7 +20,7 @@ class Kernel extends SuluTestKernel { - public function registerBundles() + public function registerBundles(): iterable { $bundles = parent::registerBundles(); $bundles[] = new SuluCommentBundle(); @@ -38,9 +38,15 @@ public function registerContainerConfiguration(LoaderInterface $loader) $context = $this->getContext(); $loader->load(__DIR__ . '/config/config_' . $context . '.yml'); + + if (\version_compare(Kernel::VERSION, '6.0.0', '>=')) { + $loader->load(__DIR__ . '/config/security-6.yml'); + } else { + $loader->load(__DIR__ . '/config/security-5-4.yml'); + } } - protected function getKernelParameters() + protected function getKernelParameters(): array { $parameters = parent::getKernelParameters(); diff --git a/Tests/Application/bin/console.php b/Tests/Application/bin/console.php index 5c7b283d..344c61b8 100644 --- 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,12 +25,12 @@ 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)) { + if (\class_exists(Debug::class)) { Debug::enable(); } else { \Symfony\Component\Debug\Debug::enable(); 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/Application/config/config_admin.yml b/Tests/Application/config/config_admin.yml index c77da5a5..49b8adfe 100644 --- a/Tests/Application/config/config_admin.yml +++ b/Tests/Application/config/config_admin.yml @@ -3,7 +3,7 @@ parameters: database.url: '%env(resolve:DATABASE_URL)%' framework: - router: { resource: "%kernel.root_dir%/config/routing_admin.yml" } + router: { resource: "%kernel.project_dir%/config/routing_admin.yml" } doctrine: orm: diff --git a/Tests/Application/config/config_website.yml b/Tests/Application/config/config_website.yml index 81a150d6..e2996903 100644 --- a/Tests/Application/config/config_website.yml +++ b/Tests/Application/config/config_website.yml @@ -3,15 +3,12 @@ parameters: database.url: '%env(resolve:DATABASE_URL)%' framework: - router: { resource: "%kernel.root_dir%/config/routing_website.yml" } + router: { resource: "%kernel.project_dir%/config/routing_website.yml" } security: access_decision_manager: strategy: affirmative - encoders: - Sulu\Bundle\SecurityBundle\Entity\User: plaintext - providers: testprovider: id: test_user_provider @@ -22,7 +19,6 @@ security: firewalls: test: http_basic: ~ - anonymous: ~ sulu_test: enable_test_user_provider: true diff --git a/Tests/Application/config/security-5-4.yml b/Tests/Application/config/security-5-4.yml new file mode 100644 index 00000000..95e396ba --- /dev/null +++ b/Tests/Application/config/security-5-4.yml @@ -0,0 +1,3 @@ +security: + encoders: + Sulu\Bundle\SecurityBundle\Entity\User: plaintext diff --git a/Tests/Application/config/security-6.yml b/Tests/Application/config/security-6.yml new file mode 100644 index 00000000..37b120e7 --- /dev/null +++ b/Tests/Application/config/security-6.yml @@ -0,0 +1,3 @@ +security: + password_hashers: + Sulu\Bundle\SecurityBundle\Entity\User: plaintext diff --git a/Tests/Functional/Controller/CommentControllerTest.php b/Tests/Functional/Controller/CommentControllerTest.php index 3354f091..98fd2337 100644 --- a/Tests/Functional/Controller/CommentControllerTest.php +++ b/Tests/Functional/Controller/CommentControllerTest.php @@ -18,6 +18,7 @@ use Sulu\Bundle\CommentBundle\Entity\Thread; use Sulu\Bundle\CommentBundle\Entity\ThreadInterface; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; class CommentControllerTest extends SuluTestCase { @@ -26,8 +27,14 @@ class CommentControllerTest extends SuluTestCase */ private $entityManager; + /** + * @var KernelBrowser + */ + private $client; + protected function setUp(): void { + $this->client = $this->createAuthenticatedClient(); $this->entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); $this->purgeDatabase(); @@ -40,11 +47,10 @@ public function testGet() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/comments/' . $comment->getId()); + $this->client->request('GET', '/api/comments/' . $comment->getId()); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals($comment->getId(), $data['id']); $this->assertEquals($comment->getMessage(), $data['message']); @@ -59,11 +65,10 @@ public function testCGet() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/comments'); + $this->client->request('GET', '/api/comments'); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(3, $data['_embedded']['comments']); } @@ -78,11 +83,10 @@ public function testCGetFilter() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/comments?state=' . CommentInterface::STATE_UNPUBLISHED); + $this->client->request('GET', '/api/comments?state=' . CommentInterface::STATE_UNPUBLISHED); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(1, $data['_embedded']['comments']); } @@ -99,11 +103,10 @@ public function testCGetTypeFilter() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/comments?threadType=test-1,test-2'); + $this->client->request('GET', '/api/comments?threadType=test-1,test-2'); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(2, $data['_embedded']['comments']); } @@ -115,11 +118,10 @@ public function testPut() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('PUT', '/api/comments/' . $comment->getId(), ['message' => 'My new Message']); + $this->client->request('PUT', '/api/comments/' . $comment->getId(), ['message' => 'My new Message']); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals($comment->getId(), $data['id']); $this->assertEquals('My new Message', $data['message']); @@ -132,10 +134,9 @@ public function testDelete() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('DELETE', '/api/comments/' . $comment->getId()); + $this->client->request('DELETE', '/api/comments/' . $comment->getId()); - $this->assertHttpStatusCode(204, $client->getResponse()); + $this->assertHttpStatusCode(204, $this->client->getResponse()); $this->assertNull($this->entityManager->find(CommentInterface::class, $comment->getId())); } @@ -151,12 +152,11 @@ public function testCDelete() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request( + $this->client->request( 'DELETE', - '/api/comments?ids=' . implode( + '/api/comments?ids=' . \implode( ',', - array_map( + \array_map( function(CommentInterface $comment) { return $comment->getId(); }, @@ -165,7 +165,7 @@ function(CommentInterface $comment) { ) ); - $this->assertHttpStatusCode(204, $client->getResponse()); + $this->assertHttpStatusCode(204, $this->client->getResponse()); foreach ([$comments[0], $comments[1]] as $comment) { $this->assertNull($this->entityManager->find(CommentInterface::class, $comment->getId())); @@ -183,9 +183,8 @@ public function testPublish() $this->assertFalse($comment->isPublished()); - $client = $this->createAuthenticatedClient(); - $client->request('POST', '/api/comments/' . $comment->getId() . '?action=publish'); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->client->request('POST', '/api/comments/' . $comment->getId() . '?action=publish'); + $this->assertHttpStatusCode(200, $this->client->getResponse()); $result = $this->entityManager->find(CommentInterface::class, $comment->getId()); $this->assertTrue($result->isPublished()); @@ -200,9 +199,8 @@ public function testUnpublish() $this->assertTrue($comment->isPublished()); - $client = $this->createAuthenticatedClient(); - $client->request('POST', '/api/comments/' . $comment->getId() . '?action=unpublish'); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->client->request('POST', '/api/comments/' . $comment->getId() . '?action=unpublish'); + $this->assertHttpStatusCode(200, $this->client->getResponse()); $result = $this->entityManager->find(CommentInterface::class, $comment->getId()); $this->assertFalse($result->isPublished()); diff --git a/Tests/Functional/Controller/ThreadControllerTest.php b/Tests/Functional/Controller/ThreadControllerTest.php index 18d96226..405beeac 100644 --- a/Tests/Functional/Controller/ThreadControllerTest.php +++ b/Tests/Functional/Controller/ThreadControllerTest.php @@ -16,6 +16,7 @@ use Sulu\Bundle\CommentBundle\Entity\Thread; use Sulu\Bundle\CommentBundle\Entity\ThreadInterface; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; class ThreadControllerTest extends SuluTestCase { @@ -24,8 +25,14 @@ class ThreadControllerTest extends SuluTestCase */ private $entityManager; + /** + * @var KernelBrowser + */ + private $client; + protected function setUp(): void { + $this->client = $this->createAuthenticatedClient(); $this->entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); $this->purgeDatabase(); @@ -37,11 +44,10 @@ public function testGet() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/threads/' . $thread->getId()); + $this->client->request('GET', '/api/threads/' . $thread->getId()); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals($thread->getId(), $data['id']); $this->assertEquals($thread->getTitle(), $data['title']); @@ -56,11 +62,10 @@ public function testCGetFilter() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/threads?type=page'); + $this->client->request('GET', '/api/threads?type=page'); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(2, $data['_embedded']['threads']); } @@ -71,11 +76,10 @@ public function testPut() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('PUT', '/api/threads/' . $thread->getId(), ['title' => 'My new Title']); + $this->client->request('PUT', '/api/threads/' . $thread->getId(), ['title' => 'My new Title']); - $this->assertHttpStatusCode(200, $client->getResponse()); - $data = json_decode($client->getResponse()->getContent(), true); + $this->assertHttpStatusCode(200, $this->client->getResponse()); + $data = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals($thread->getId(), $data['id']); $this->assertEquals('My new Title', $data['title']); @@ -87,10 +91,9 @@ public function testDelete() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('DELETE', '/api/threads/' . $thread->getId()); + $this->client->request('DELETE', '/api/threads/' . $thread->getId()); - $this->assertHttpStatusCode(204, $client->getResponse()); + $this->assertHttpStatusCode(204, $this->client->getResponse()); $this->assertNull($this->entityManager->find(ThreadInterface::class, $thread->getId())); } @@ -105,12 +108,11 @@ public function testCDelete() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request( + $this->client->request( 'DELETE', - '/api/threads?ids=' . implode( + '/api/threads?ids=' . \implode( ',', - array_map( + \array_map( function(ThreadInterface $thread) { return $thread->getId(); }, @@ -119,7 +121,7 @@ function(ThreadInterface $thread) { ) ); - $this->assertHttpStatusCode(204, $client->getResponse()); + $this->assertHttpStatusCode(204, $this->client->getResponse()); foreach ([$threads[0], $threads[1]] as $comment) { $this->assertNull($this->entityManager->find(ThreadInterface::class, $comment->getId())); @@ -139,14 +141,13 @@ public function testCGet() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/threads?fields=id,title'); + $this->client->request('GET', '/api/threads?fields=id,title'); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->assertHttpStatusCode(200, $this->client->getResponse()); - $result = json_decode($client->getResponse()->getContent(), true); + $result = \json_decode($this->client->getResponse()->getContent(), true); $result = $result['_embedded']['threads']; - for ($i = 0, $length = count($threads); $i < $length; ++$i) { + for ($i = 0, $length = \count($threads); $i < $length; ++$i) { $this->assertEquals($threads[$i]->getId(), $result[$i]['id']); $this->assertEquals($threads[$i]->getTitle(), $result[$i]['title']); } @@ -163,16 +164,15 @@ public function testCGetTypes() $this->entityManager->flush(); $this->entityManager->clear(); - $client = $this->createAuthenticatedClient(); - $client->request('GET', '/api/threads?fields=id,title&types=Test1,Test3'); + $this->client->request('GET', '/api/threads?fields=id,title&types=Test1,Test3'); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->assertHttpStatusCode(200, $this->client->getResponse()); - $result = json_decode($client->getResponse()->getContent(), true); + $result = \json_decode($this->client->getResponse()->getContent(), true); $result = $result['_embedded']['threads']; $expected = [$threads[0], $threads[2]]; - for ($i = 0, $length = count($expected); $i < $length; ++$i) { + for ($i = 0, $length = \count($expected); $i < $length; ++$i) { $this->assertEquals($expected[$i]->getId(), $result[$i]['id']); $this->assertEquals($expected[$i]->getTitle(), $result[$i]['title']); } diff --git a/Tests/Functional/Controller/WebsiteCommentControllerTest.php b/Tests/Functional/Controller/WebsiteCommentControllerTest.php index e5ef214d..a205e5df 100644 --- a/Tests/Functional/Controller/WebsiteCommentControllerTest.php +++ b/Tests/Functional/Controller/WebsiteCommentControllerTest.php @@ -14,6 +14,7 @@ use Sulu\Bundle\CommentBundle\Entity\CommentInterface; use Sulu\Bundle\CommentBundle\Entity\ThreadInterface; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Component\HttpFoundation\RedirectResponse; /** @@ -21,8 +22,14 @@ */ class WebsiteCommentControllerTest extends SuluTestCase { + /** + * @var KernelBrowser + */ + private $client; + protected function setUp(): void { + $this->client = $this->createAuthenticatedWebsiteClient(); $this->purgeDatabase(); } @@ -43,16 +50,15 @@ public function testPostComment( $message = 'Sulu is awesome', $threadTitle = 'Test Thread' ) { - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments.json', ['message' => $message, 'threadTitle' => $threadTitle] ); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->assertHttpStatusCode(200, $this->client->getResponse()); - $response = json_decode($client->getResponse()->getContent(), true); + $response = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals(CommentInterface::STATE_PUBLISHED, $response['state']); $this->assertEquals($message, $response['message']); @@ -82,16 +88,15 @@ public function testPostCommentWithParent( /** @var CommentInterface $parent */ $parent = $thread->getComments()->first(); - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments.json?parent=' . $parent->getId(), ['message' => $message, 'threadTitle' => $threadTitle] ); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->assertHttpStatusCode(200, $this->client->getResponse()); - $response = json_decode($client->getResponse()->getContent(), true); + $response = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals(CommentInterface::STATE_PUBLISHED, $response['state']); $this->assertEquals($message, $response['message']); @@ -119,15 +124,14 @@ public function testPostCommentWithReferrer( $message = 'Sulu is awesome', $threadTitle = 'Test Thread' ) { - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments?referrer=https://sulu.io', ['message' => $message, 'threadTitle' => $threadTitle] ); /** @var RedirectResponse $response */ - $response = $client->getResponse(); + $response = $this->client->getResponse(); $this->assertHttpStatusCode(302, $response); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals('https://sulu.io', $response->getTargetUrl()); @@ -154,14 +158,13 @@ public function providePostAuditableData() */ public function testPostAuditable($field, $type = 'blog', $entityId = '1') { - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments.json', ['message' => 'Sulu is awesome', 'threadTitle' => 'Test Thread', $field => 1] ); - $this->assertHttpStatusCode(400, $client->getResponse()); + $this->assertHttpStatusCode(400, $this->client->getResponse()); } public function testPostCommentMultiple($type = 'blog', $entityId = '1') @@ -187,14 +190,13 @@ public function testPutComment($type = 'blog', $entityId = '1') $thread = $this->postComment($type, $entityId); $comment = $thread->getComments()->first(); - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments/' . $comment->getId() . '.json', ['message' => 'New message'] ); - $response = json_decode($client->getResponse()->getContent(), true); + $response = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals('New message', $response['message']); $this->getEntityManager()->clear(); @@ -208,15 +210,14 @@ public function testPutCommentWithReferrer($type = 'blog', $entityId = '1') $thread = $this->postComment($type, $entityId); $comment = $thread->getComments()->first(); - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments/' . $comment->getId() . '?referrer=https://sulu.io', ['message' => 'New message'] ); /** @var RedirectResponse $response */ - $response = $client->getResponse(); + $response = $this->client->getResponse(); $this->assertHttpStatusCode(302, $response); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals('https://sulu.io', $response->getTargetUrl()); @@ -232,14 +233,13 @@ public function testDeleteComment($type = 'blog', $entityId = '1') $thread = $this->postComment($type, $entityId); $comment = $thread->getComments()->first(); - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'DELETE', '_api/threads/' . $type . '-' . $entityId . '/comments/' . $comment->getId() . '.json' ); /* Todo: Check if this is correct. */ - $response = json_decode($client->getResponse()->getContent(), true); + $response = \json_decode($this->client->getResponse()->getContent(), true); $this->assertEquals('', $response); $this->getEntityManager()->clear(); @@ -253,14 +253,13 @@ public function testDeleteCommitWithReferrer($type = 'blog', $entityId = '1') $thread = $this->postComment($type, $entityId); $comment = $thread->getComments()->first(); - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'DELETE', '_api/threads/' . $type . '-' . $entityId . '/comments/' . $comment->getId() . '?referrer=https://sulu.io' ); /** @var RedirectResponse $response */ - $response = $client->getResponse(); + $response = $this->client->getResponse(); $this->assertHttpStatusCode(302, $response); $this->assertInstanceOf(RedirectResponse::class, $response); $this->assertEquals('https://sulu.io', $response->getTargetUrl()); @@ -274,19 +273,18 @@ public function testDeleteCommitWithReferrer($type = 'blog', $entityId = '1') public function testGetComments($type = 'blog', $entityId = '1') { $this->postComment($type, $entityId); - sleep(1); + \sleep(1); $this->postComment($type, $entityId, 'My new Comment'); $this->postComment('article', '123-123-123'); - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'GET', '_api/threads/' . $type . '-' . $entityId . '/comments.json' ); - $this->assertHttpStatusCode(200, $client->getResponse()); + $this->assertHttpStatusCode(200, $this->client->getResponse()); - $response = json_decode($client->getResponse()->getContent(), true); + $response = \json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(2, $response); $this->assertEquals(CommentInterface::STATE_PUBLISHED, $response[0]['state']); $this->assertEquals('My new Comment', $response[0]['message']); @@ -300,8 +298,7 @@ private function postComment( $message = 'Sulu is awesome', $threadTitle = 'Test Thread' ) { - $client = $this->createWebsiteClient(); - $client->request( + $this->client->request( 'POST', '_api/threads/' . $type . '-' . $entityId . '/comments.json', ['message' => $message, 'threadTitle' => $threadTitle] @@ -309,6 +306,9 @@ private function postComment( $thread = $this->getContainer()->get('sulu.repository.thread')->findThread($type, $entityId); + // client has to be restarted for the next request to work + $this->client->restart(); + return $thread; } } diff --git a/Tests/Functional/EventSubscriber/CommentSerializationSubscriberTest.php b/Tests/Functional/EventSubscriber/CommentSerializationSubscriberTest.php index afc04428..a34463f0 100644 --- a/Tests/Functional/EventSubscriber/CommentSerializationSubscriberTest.php +++ b/Tests/Functional/EventSubscriber/CommentSerializationSubscriberTest.php @@ -27,7 +27,7 @@ public function testSerializeWithoutGroup() $comment->setMessage('test-message'); $jsonResult = self::getContainer()->get('jms_serializer')->serialize($comment, 'json'); - $arrayResult = json_decode($jsonResult, true); + $arrayResult = \json_decode($jsonResult, true); $this->assertTrue($arrayResult['published']); $this->assertSame('test-message', $arrayResult['message']); @@ -41,7 +41,7 @@ public function testSerializeWithoutCreator() $context = SerializationContext::create()->setGroups(['Default', 'commentWithAvatar']); $jsonResult = self::getContainer()->get('jms_serializer')->serialize($comment, 'json', $context); - $arrayResult = json_decode($jsonResult, true); + $arrayResult = \json_decode($jsonResult, true); $this->assertTrue($arrayResult['published']); $this->assertSame('test-message', $arrayResult['message']); @@ -57,7 +57,7 @@ public function testSerializeWithCreator() $context = SerializationContext::create()->setGroups(['Default', 'commentWithAvatar']); $jsonResult = self::getContainer()->get('jms_serializer')->serialize($comment, 'json', $context); - $arrayResult = json_decode($jsonResult, true); + $arrayResult = \json_decode($jsonResult, true); $this->assertTrue($arrayResult['published']); $this->assertSame('test-message', $arrayResult['message']); diff --git a/Tests/Unit/Manager/CommentManagerTest.php b/Tests/Unit/Manager/CommentManagerTest.php index 805ed926..00b2db33 100644 --- a/Tests/Unit/Manager/CommentManagerTest.php +++ b/Tests/Unit/Manager/CommentManagerTest.php @@ -96,7 +96,7 @@ public function testAddComment($type = 'article', $entityId = '123-123-123') $this->dispatcher->dispatch(Argument::type(CommentEvent::class), Events::PRE_PERSIST_EVENT) ->shouldBeCalledTimes(1) ->will( - function() use ($commentRepository, $comment, $dispatcher, $thread) { + function($args) use ($commentRepository, $comment, $dispatcher, $thread) { $thread->addComment($comment->reveal())->willReturn($thread->reveal()); $commentRepository->persist($comment->reveal()) ->shouldBeCalledTimes(1) @@ -108,6 +108,9 @@ function() use ($dispatcher) { )->shouldBeCalledTimes(1); } ); + + // return the event + return $args[0]; } ); @@ -130,7 +133,7 @@ public function testAddCommentWithThreadTitle($type = 'article', $entityId = '12 $this->dispatcher->dispatch(Argument::type(CommentEvent::class), Events::PRE_PERSIST_EVENT) ->shouldBeCalledTimes(1) ->will( - function() use ($commentRepository, $comment, $dispatcher, $thread) { + function($args) use ($commentRepository, $comment, $dispatcher, $thread) { $thread->addComment($comment->reveal())->willReturn($thread->reveal()); $commentRepository->persist($comment->reveal()) ->shouldBeCalledTimes(1) @@ -142,6 +145,9 @@ function() use ($dispatcher) { )->shouldBeCalledTimes(1); } ); + + // return the event + return $args[0]; } ); @@ -164,7 +170,8 @@ function(CommentEvent $event) use ($comment) { } ), Events::PRE_UPDATE_EVENT - )->shouldBeCalled(); + )->shouldBeCalled() + ->willReturn(new CommentEvent('', '', $this->comment->reveal(), $this->thread->reveal())); $this->assertEquals($comment->reveal(), $this->commentManager->update($comment->reveal())); $this->commentEventCollector->dispatch(); // simulate flush of the comments @@ -181,7 +188,8 @@ function(ThreadEvent $event) use ($thread) { } ), Events::THREAD_PRE_UPDATE_EVENT - )->shouldBeCalled(); + )->shouldBeCalled() + ->willReturn(new ThreadEvent($this->thread->reveal())); $this->assertEquals($thread->reveal(), $this->commentManager->updateThread($thread->reveal())); $this->commentEventCollector->dispatch(); // simulate flush of the comments @@ -214,7 +222,7 @@ function(CommentEvent $event) use ($comment) { ), Events::PRE_DELETE_EVENT )->will( - function() use ($comment, $dispatcher) { + function($args) use ($comment, $dispatcher) { $dispatcher->dispatch( Argument::that( function(CommentEvent $event) use ($comment) { @@ -223,6 +231,9 @@ function(CommentEvent $event) use ($comment) { ), Events::POST_DELETE_EVENT )->shouldBeCalledTimes(1); + + // return the event + return $args[0]; } )->shouldBeCalledTimes(1); @@ -260,7 +271,7 @@ function(CommentEvent $event) use ($comment) { ), Events::PRE_DELETE_EVENT )->will( - function() use ($comment, $dispatcher) { + function($args) use ($comment, $dispatcher) { $dispatcher->dispatch( Argument::that( function(CommentEvent $event) use ($comment) { @@ -269,6 +280,9 @@ function(CommentEvent $event) use ($comment) { ), Events::POST_DELETE_EVENT )->shouldBeCalledTimes(1); + + // return the event + return $args[0]; } )->shouldBeCalledTimes(1); @@ -303,7 +317,7 @@ function(ThreadEvent $event) use ($thread) { ), Events::THREAD_PRE_DELETE_EVENT )->will( - function() use ($thread, $dispatcher) { + function($args) use ($thread, $dispatcher) { $dispatcher->dispatch( Argument::that( function(ThreadEvent $event) use ($thread) { @@ -312,6 +326,9 @@ function(ThreadEvent $event) use ($thread) { ), Events::THREAD_POST_DELETE_EVENT )->shouldBeCalledTimes(1); + + // return the event + return $args[0]; } )->shouldBeCalledTimes(1); @@ -344,7 +361,7 @@ function(ThreadEvent $event) use ($thread) { ), Events::THREAD_PRE_DELETE_EVENT )->will( - function() use ($thread, $dispatcher) { + function($args) use ($thread, $dispatcher) { $dispatcher->dispatch( Argument::that( function(ThreadEvent $event) use ($thread) { @@ -353,6 +370,9 @@ function(ThreadEvent $event) use ($thread) { ), Events::THREAD_POST_DELETE_EVENT )->shouldBeCalledTimes(1); + + // return the event + return $args[0]; } )->shouldBeCalledTimes(1); @@ -379,7 +399,8 @@ function(CommentEvent $event) use ($comment) { } ), Events::PUBLISH_EVENT - )->shouldBeCalledTimes(1); + )->shouldBeCalledTimes(1) + ->willReturn(new CommentEvent('', '', $this->comment->reveal(), $this->thread->reveal())); $this->assertEquals($this->comment->reveal(), $this->commentManager->publish($this->comment->reveal())); $this->commentEventCollector->dispatch(); // simulate flush of the comments @@ -398,7 +419,8 @@ function(CommentEvent $event) use ($comment) { } ), Events::PUBLISH_EVENT - )->shouldNotBeCalled(); + )->shouldNotBeCalled() + ->willReturn(new CommentEvent('', '', $this->comment->reveal(), $this->thread->reveal())); $this->assertEquals($this->comment->reveal(), $this->commentManager->publish($this->comment->reveal())); $this->commentEventCollector->dispatch(); // simulate flush of the comments @@ -418,7 +440,8 @@ function(CommentEvent $event) use ($comment) { } ), Events::UNPUBLISH_EVENT - )->shouldBeCalledTimes(1); + )->shouldBeCalledTimes(1) + ->willReturn(new CommentEvent('', '', $this->comment->reveal(), $this->thread->reveal())); $this->assertEquals($this->comment->reveal(), $this->commentManager->unpublish($this->comment->reveal())); $this->commentEventCollector->dispatch(); // simulate flush of the comments @@ -437,7 +460,8 @@ function(CommentEvent $event) use ($comment) { } ), Events::UNPUBLISH_EVENT - )->shouldNotBeCalled(); + )->shouldNotBeCalled() + ->willReturn(new CommentEvent('', '', $this->comment->reveal(), $this->thread->reveal())); $this->assertEquals($this->comment->reveal(), $this->commentManager->unpublish($this->comment->reveal())); $this->commentEventCollector->dispatch(); // simulate flush of the comments diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 53a1bacd..bdb70242 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -14,7 +14,7 @@ use Symfony\Component\Dotenv\Dotenv; $file = __DIR__ . '/../vendor/autoload.php'; -if (!file_exists($file)) { +if (!\file_exists($file)) { throw new RuntimeException('Install dependencies to run test suite.'); } @@ -22,22 +22,22 @@ // 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__) . '/Tests/Application/.env'; + $path = \dirname(__DIR__) . '/Tests/Application/.env'; $dotenv = new Dotenv(); // load all the .env files - if (method_exists($dotenv, 'loadEnv')) { + if (\method_exists($dotenv, 'loadEnv')) { $dotenv->loadEnv($path); } else { // fallback code in case your Dotenv component is not 4.2 or higher (when loadEnv() was added) - if (file_exists($path) || !file_exists($p = "$path.dist")) { + if (\file_exists($path) || !\file_exists($p = "$path.dist")) { $dotenv->load($path); } else { $dotenv->load($p); @@ -47,16 +47,16 @@ $dotenv->populate(['APP_ENV' => $env = 'dev']); } - if ('test' !== $env && file_exists($p = "$path.local")) { + if ('test' !== $env && \file_exists($p = "$path.local")) { $dotenv->load($p); $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env; } - if (file_exists($p = "$path.$env")) { + if (\file_exists($p = "$path.$env")) { $dotenv->load($p); } - if (file_exists($p = "$path.$env.local")) { + if (\file_exists($p = "$path.$env.local")) { $dotenv->load($p); } } @@ -64,4 +64,4 @@ $_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/phpstan/console-application.php b/Tests/phpstan/console-application.php index a01a00e8..c9f390d1 100644 --- a/Tests/phpstan/console-application.php +++ b/Tests/phpstan/console-application.php @@ -14,7 +14,7 @@ use Sulu\Bundle\CommentBundle\Tests\Application\Kernel; use Symfony\Bundle\FrameworkBundle\Console\Application; -require dirname(__DIR__) . '/bootstrap.php'; +require \dirname(__DIR__) . '/bootstrap.php'; $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG'], Kernel::CONTEXT_ADMIN); $kernel->boot(); diff --git a/Tests/phpstan/object-manager.php b/Tests/phpstan/object-manager.php index 5e94095c..f1c3c1ca 100644 --- a/Tests/phpstan/object-manager.php +++ b/Tests/phpstan/object-manager.php @@ -14,7 +14,7 @@ use Sulu\Bundle\CommentBundle\Tests\Application\Kernel; use Symfony\Component\DependencyInjection\ContainerInterface; -require dirname(__DIR__) . '/bootstrap.php'; +require \dirname(__DIR__) . '/bootstrap.php'; $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG'], Kernel::CONTEXT_ADMIN); $kernel->boot(); diff --git a/composer.json b/composer.json index 5cba07bc..2667d137 100644 --- a/composer.json +++ b/composer.json @@ -4,36 +4,36 @@ "type": "sulu-bundle", "license": "MIT", "require": { - "php": "^7.2", + "php": "^7.2 || ^8.0", "friendsofsymfony/rest-bundle": "^2.6 || ^3.0", - "sulu/sulu": "^2.0.4", - "symfony/config": "^4.3 || ^5.0", - "symfony/dependency-injection": "^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" + "sulu/sulu": "^2.0.4 || ^2.5.10@dev", + "symfony/config": "^4.3 || ^5.0 || ^6.0", + "symfony/dependency-injection": "^4.3 || ^5.0 || ^6.0", + "symfony/framework-bundle": "^4.3 || ^5.0 || ^6.0", + "symfony/http-foundation": "^4.3 || ^5.0 || ^6.0", + "symfony/http-kernel": "^4.3 || ^5.0 || ^6.0" }, "require-dev": { "doctrine/doctrine-bundle": "^1.10 || ^2.0", - "friendsofphp/php-cs-fixer": "^2.17", + "friendsofphp/php-cs-fixer": "^2.17 || ^3.0", "handcraftedinthealps/zendsearch": "^2.0", "jackalope/jackalope-doctrine-dbal": "^1.3.4", - "jangregor/phpstan-prophecy": "^0.5.1", + "jangregor/phpstan-prophecy": "^1.0", "massive/search-bundle": "^2.0.0", - "php-ffmpeg/php-ffmpeg": "^0.13 || ^0.14", + "php-ffmpeg/php-ffmpeg": "^0.14 || ^1.0", "phpspec/prophecy": "^1.17", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpstan/phpstan-symfony": "^0.12", - "phpunit/phpunit": "^8.0", - "symfony/browser-kit": "^4.3", - "symfony/dotenv": "^4.3", - "symfony/form": "^4.3", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-symfony": "^1.0", + "phpunit/phpunit": "^8.0 || ^9.0", + "symfony/browser-kit": "^4.3 || ^5.0 || ^6.0", + "symfony/dotenv": "^4.3 || ^5.0 || ^6.0", + "symfony/form": "^4.3 || ^5.0 || ^6.0", "symfony/monolog-bundle": "^3.1", - "symfony/security-bundle": "^4.3", - "symfony/stopwatch": "^4.3", - "thecodingmachine/phpstan-strict-rules": "^0.12.2" + "symfony/security-bundle": "^4.3 || ^5.0 || ^6.0", + "symfony/stopwatch": "^4.3 || ^5.0 || ^6.0", + "thecodingmachine/phpstan-strict-rules": "^1.0" }, "keywords": [], "authors": [ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index 82f948bf..00000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,227 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^PHPDoc tag @var for variable \\$commentFormToolbarActions has no value type specified in iterable type array\\.$#" - count: 1 - path: Admin/CommentAdmin.php - - - - message: "#^Parameter \\#1 \\$message of method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\CommentInterface\\:\\:setMessage\\(\\) expects string, bool\\|float\\|int\\|string\\|null given\\.$#" - count: 1 - path: Controller/CommentController.php - - - - message: "#^Parameter \\#2 \\$value of method Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\ListBuilderInterface\\:\\:where\\(\\) expects string, array\\\\|bool\\|float\\|int\\|string given\\.$#" - count: 1 - path: Controller/CommentController.php - - - - message: "#^Parameter \\#1 \\$title of method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\ThreadInterface\\:\\:setTitle\\(\\) expects string, bool\\|float\\|int\\|string\\|null given\\.$#" - count: 1 - path: Controller/ThreadController.php - - - - message: "#^Parameter \\#2 \\$value of method Sulu\\\\Component\\\\Rest\\\\ListBuilder\\\\ListBuilderInterface\\:\\:where\\(\\) expects string, array\\\\|bool\\|float\\|int\\|string given\\.$#" - count: 1 - path: Controller/ThreadController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:__construct\\(\\) has parameter \\$commentDefaultTemplates with no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:__construct\\(\\) has parameter \\$commentSerializationGroups with no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:__construct\\(\\) has parameter \\$commentTypes with no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:view\\(\\) has parameter \\$data with no typehint specified\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:view\\(\\) has parameter \\$headers with no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:view\\(\\) has parameter \\$statusCode with no typehint specified\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Parameter \\#1 \\$message of method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:setMessage\\(\\) expects string, bool\\|float\\|int\\|string\\|null given\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:\\$commentDefaultTemplates type has no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:\\$commentSerializationGroups type has no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Controller\\\\WebsiteCommentController\\:\\:\\$commentTypes type has no value type specified in iterable type array\\.$#" - count: 1 - path: Controller/WebsiteCommentController.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\DependencyInjection\\\\SuluCommentExtension\\:\\:load\\(\\) has no return typehint specified\\.$#" - count: 1 - path: DependencyInjection/SuluCommentExtension.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\DependencyInjection\\\\SuluCommentExtension\\:\\:prepend\\(\\) has no return typehint specified\\.$#" - count: 1 - path: DependencyInjection/SuluCommentExtension.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:getChildren\\(\\) return type with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/Comment.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:getPublishedChildren\\(\\) return type with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/Comment.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:\\$children type mapping mismatch\\: property can contain Doctrine\\\\Common\\\\Collections\\\\Collection&iterable\\ but database expects Doctrine\\\\Common\\\\Collections\\\\Collection&iterable\\\\.$#" - count: 1 - path: Entity/Comment.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:\\$children with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/Comment.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:\\$parent type mapping mismatch\\: property can contain Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\CommentInterface\\|null but database expects Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\|null\\.$#" - count: 1 - path: Entity/Comment.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Comment\\:\\:\\$thread type mapping mismatch\\: property can contain Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\ThreadInterface\\|null but database expects Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\|null\\.$#" - count: 1 - path: Entity/Comment.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\CommentInterface\\:\\:getChildren\\(\\) return type with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/CommentInterface.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\CommentInterface\\:\\:getPublishedChildren\\(\\) return type with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/CommentInterface.php - - - - message: "#^Interface Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\CommentRepositoryInterface extends generic interface Sulu\\\\Component\\\\Persistence\\\\Repository\\\\RepositoryInterface but does not specify its types\\: T$#" - count: 1 - path: Entity/CommentRepositoryInterface.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:__construct\\(\\) has parameter \\$comments with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection but does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:getComments\\(\\) return type with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$changer type mapping mismatch\\: database can contain Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User\\|null but property expects Sulu\\\\Component\\\\Security\\\\Authentication\\\\UserInterface\\.$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$changer type mapping mismatch\\: property can contain Sulu\\\\Component\\\\Security\\\\Authentication\\\\UserInterface but database expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User\\|null\\.$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$comments type mapping mismatch\\: property can contain Doctrine\\\\Common\\\\Collections\\\\Collection but database expects Doctrine\\\\Common\\\\Collections\\\\Collection&iterable\\\\.$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$comments with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$creator type mapping mismatch\\: database can contain Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User\\|null but property expects Sulu\\\\Component\\\\Security\\\\Authentication\\\\UserInterface\\.$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$creator type mapping mismatch\\: property can contain Sulu\\\\Component\\\\Security\\\\Authentication\\\\UserInterface but database expects Sulu\\\\Bundle\\\\SecurityBundle\\\\Entity\\\\User\\|null\\.$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Property Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\Thread\\:\\:\\$title type mapping mismatch\\: database can contain string\\|null but property expects string\\.$#" - count: 1 - path: Entity/Thread.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\ThreadInterface\\:\\:getComments\\(\\) return type with generic interface Doctrine\\\\Common\\\\Collections\\\\Collection does not specify its types\\: TKey, T$#" - count: 1 - path: Entity/ThreadInterface.php - - - - message: "#^Class Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\ThreadRepository extends generic class Doctrine\\\\ORM\\\\EntityRepository but does not specify its types\\: TEntityClass$#" - count: 1 - path: Entity/ThreadRepository.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\ThreadRepository\\:\\:createNew\\(\\) should return Sulu\\\\Bundle\\\\CommentBundle\\\\Entity\\\\ThreadInterface but returns object\\.$#" - count: 1 - path: Entity/ThreadRepository.php - - - - message: "#^Call to an undefined method Sulu\\\\Component\\\\Security\\\\Authentication\\\\UserInterface\\:\\:getContact\\(\\)\\.$#" - count: 1 - path: EventSubscriber/CommentSerializationSubscriber.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\EventSubscriber\\\\CommentSerializationSubscriber\\:\\:getSubscribedEvents\\(\\) return type has no value type specified in iterable type array\\.$#" - count: 1 - path: EventSubscriber/CommentSerializationSubscriber.php - - - - message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#" - count: 1 - path: Events/CommentEventCollector.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Form\\\\Type\\\\CommentType\\:\\:buildForm\\(\\) has no return typehint specified\\.$#" - count: 1 - path: Form/Type/CommentType.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\Form\\\\Type\\\\CommentType\\:\\:configureOptions\\(\\) has no return typehint specified\\.$#" - count: 1 - path: Form/Type/CommentType.php - - - - message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#" - count: 5 - path: Manager/CommentManager.php - - - - message: "#^Method Sulu\\\\Bundle\\\\CommentBundle\\\\SuluCommentBundle\\:\\:build\\(\\) has no return typehint specified\\.$#" - count: 1 - path: SuluCommentBundle.php - diff --git a/phpstan.neon b/phpstan.neon index 645bf047..27fbafdc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,18 +1,17 @@ includes: - - vendor/jangregor/phpstan-prophecy/src/extension.neon + - vendor/jangregor/phpstan-prophecy/extension.neon - vendor/phpstan/phpstan-doctrine/extension.neon - vendor/phpstan/phpstan-doctrine/rules.neon - vendor/phpstan/phpstan-symfony/extension.neon - 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/* - %currentWorkingDirectory%/vendor/* @@ -21,3 +20,6 @@ parameters: console_application_loader: Tests/phpstan/console-application.php doctrine: objectManagerLoader: Tests/phpstan/object-manager.php + ignoreErrors: + - "#^Property .* type mapping mismatch\\: property can contain .* but database .*$#" + - "#^Property .* type mapping mismatch\\: database can contain .* but property .*$#"