From 754285524bbd8e1e4458856a529785321224fabd Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 16 Jun 2020 22:58:56 +0200 Subject: [PATCH 1/2] Update phpstan --- Admin/AutomationAdmin.php | 2 +- Controller/TaskController.php | 12 ++++++++---- Controller/TaskHandlerController.php | 7 +++++-- DependencyInjection/SuluAutomationExtension.php | 4 ++-- Entity/Task.php | 6 +++--- Handler/DocumentPublishHandler.php | 2 +- Handler/DocumentUnpublishHandler.php | 2 +- Metadata/FormMetadataLoader.php | 3 +++ PageTree/AutomationPageTreeUpdater.php | 2 +- PageTree/PageTreeRouteUpdateHandler.php | 2 +- Serializer/TaskSerializerSubscriber.php | 4 ++-- SuluAutomationBundle.php | 2 +- TaskHandler/TaskHandlerConfiguration.php | 2 +- Tasks/Model/TaskInterface.php | 4 ++-- Tasks/Scheduler/TaskScheduler.php | 4 ++-- composer.json | 12 ++++++------ phpstan.neon | 5 +++-- 17 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Admin/AutomationAdmin.php b/Admin/AutomationAdmin.php index 2023e06..f3e8c92 100644 --- a/Admin/AutomationAdmin.php +++ b/Admin/AutomationAdmin.php @@ -76,7 +76,7 @@ public function configureViews(ViewCollection $viewCollection): void } /** - * {@inheritdoc} + * @return mixed[] */ public function getSecurityContexts() { diff --git a/Controller/TaskController.php b/Controller/TaskController.php index 329da64..ed9037f 100644 --- a/Controller/TaskController.php +++ b/Controller/TaskController.php @@ -16,7 +16,6 @@ use FOS\RestBundle\View\ViewHandlerInterface; use JMS\Serializer\DeserializationContext; use JMS\Serializer\SerializerInterface; -use Nette\Utils\DateTime; use Sulu\Bundle\AutomationBundle\Admin\AutomationAdmin; use Sulu\Bundle\AutomationBundle\Entity\Task; use Sulu\Bundle\AutomationBundle\Exception\TaskNotFoundException; @@ -44,6 +43,9 @@ */ class TaskController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface { + /** + * @var string[] + */ private static $scheduleComparators = [ 'future' => ListBuilderInterface::WHERE_COMPARATOR_GREATER_THAN, 'past' => ListBuilderInterface::WHERE_COMPARATOR_LESS, @@ -287,7 +289,7 @@ public function postAction(Request $request): Response $context ); - /** @var DateTime $date */ + /** @var \DateTime $date */ $date = date_create_from_format('Y-m-d:H:i:s', $data['date'] . ':' . $data['time']); $task->setSchedule($date); @@ -325,7 +327,9 @@ public function putAction(string $id, Request $request): Response $context ); - $task->setSchedule(date_create_from_format('Y-m-d:H:i:s', $data['date'] . ':' . $data['time'])); + /** @var \DateTime $dateTime */ + $dateTime = date_create_from_format('Y-m-d:H:i:s', $data['date'] . ':' . $data['time']); + $task->setSchedule($dateTime); $task = $this->taskManager->update($task); $this->entityManager->flush(); @@ -379,7 +383,7 @@ private function getFieldDescriptors(string $type = null): array } /** - * {@inheritdoc} + * @return string */ public function getSecurityContext() { diff --git a/Controller/TaskHandlerController.php b/Controller/TaskHandlerController.php index 9dea40d..69f0ef9 100644 --- a/Controller/TaskHandlerController.php +++ b/Controller/TaskHandlerController.php @@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Task\Handler\TaskHandlerFactoryInterface; +use Task\TaskBundle\Handler\TaskHandlerFactory; /** * Provides simple-api for task-handler. @@ -28,9 +28,12 @@ class TaskHandlerController { use RequestParametersTrait; + /** + * @var TaskHandlerFactory + */ protected $taskHandlerFactory; - public function __construct(TaskHandlerFactoryInterface $taskHandlerFactory) + public function __construct(TaskHandlerFactory $taskHandlerFactory) { $this->taskHandlerFactory = $taskHandlerFactory; } diff --git a/DependencyInjection/SuluAutomationExtension.php b/DependencyInjection/SuluAutomationExtension.php index c56ee22..6906bbf 100644 --- a/DependencyInjection/SuluAutomationExtension.php +++ b/DependencyInjection/SuluAutomationExtension.php @@ -27,7 +27,7 @@ class SuluAutomationExtension extends Extension implements PrependExtensionInter use PersistenceExtensionTrait; /** - * {@inheritdoc} + * @return void */ public function prepend(ContainerBuilder $container) { @@ -83,7 +83,7 @@ public function prepend(ContainerBuilder $container) } /** - * {@inheritdoc} + * @return void */ public function load(array $configs, ContainerBuilder $container) { diff --git a/Entity/Task.php b/Entity/Task.php index 8b5af55..2494ab6 100644 --- a/Entity/Task.php +++ b/Entity/Task.php @@ -54,7 +54,7 @@ class Task implements TaskInterface private $entityId; /** - * @var string + * @var string|null */ private $taskId; @@ -163,7 +163,7 @@ public function setEntityId(string $entityId): self return $this; } - public function getTaskId(): string + public function getTaskId(): ?string { return $this->taskId; } @@ -171,7 +171,7 @@ public function getTaskId(): string /** * @return self */ - public function setTaskId(string $taskId): TaskInterface + public function setTaskId(?string $taskId): TaskInterface { $this->taskId = $taskId; diff --git a/Handler/DocumentPublishHandler.php b/Handler/DocumentPublishHandler.php index a0f427f..55a4bea 100644 --- a/Handler/DocumentPublishHandler.php +++ b/Handler/DocumentPublishHandler.php @@ -26,7 +26,7 @@ public function __construct(DocumentManagerInterface $documentManager, Translato } /** - * {@inheritdoc} + * @param string $locale */ protected function handleDocument(WorkflowStageBehavior $document, $locale): void { diff --git a/Handler/DocumentUnpublishHandler.php b/Handler/DocumentUnpublishHandler.php index 70357fb..7eccb45 100644 --- a/Handler/DocumentUnpublishHandler.php +++ b/Handler/DocumentUnpublishHandler.php @@ -26,7 +26,7 @@ public function __construct(DocumentManagerInterface $documentManager, Translato } /** - * {@inheritdoc} + * @param string $locale */ protected function handleDocument(WorkflowStageBehavior $document, $locale): void { diff --git a/Metadata/FormMetadataLoader.php b/Metadata/FormMetadataLoader.php index cc1eb7b..0005352 100644 --- a/Metadata/FormMetadataLoader.php +++ b/Metadata/FormMetadataLoader.php @@ -40,6 +40,9 @@ public function __construct( $this->taskHandlerFactory = $taskHandlerFactory; } + /** + * @param mixed[] $metadataOptions + */ public function getMetadata(string $key, string $locale, array $metadataOptions): ?MetadataInterface { if ('task_details' !== $key) { diff --git a/PageTree/AutomationPageTreeUpdater.php b/PageTree/AutomationPageTreeUpdater.php index 4456fa2..96935ff 100644 --- a/PageTree/AutomationPageTreeUpdater.php +++ b/PageTree/AutomationPageTreeUpdater.php @@ -49,7 +49,7 @@ public function __construct( } /** - * {@inheritdoc} + * @return void */ public function update(BasePageDocument $document) { diff --git a/PageTree/PageTreeRouteUpdateHandler.php b/PageTree/PageTreeRouteUpdateHandler.php index 6e8c003..8005471 100644 --- a/PageTree/PageTreeRouteUpdateHandler.php +++ b/PageTree/PageTreeRouteUpdateHandler.php @@ -65,7 +65,7 @@ public function configureOptionsResolver(OptionsResolver $optionsResolver): Opti /** * {@inheritdoc} */ - public function supports($entityClass): bool + public function supports(string $entityClass): bool { return is_subclass_of($entityClass, BasePageDocument::class); } diff --git a/Serializer/TaskSerializerSubscriber.php b/Serializer/TaskSerializerSubscriber.php index fb82cbd..478e230 100644 --- a/Serializer/TaskSerializerSubscriber.php +++ b/Serializer/TaskSerializerSubscriber.php @@ -45,7 +45,7 @@ public function __construct( } /** - * {@inheritdoc} + * @return mixed[] */ public static function getSubscribedEvents() { @@ -80,7 +80,7 @@ public function onTaskSerialize(ObjectEvent $event): void ); } - $executions = $this->taskExecutionRepository->findByTaskUuid($object->getTaskId()); + $executions = $this->taskExecutionRepository->findByTaskUuid((string) $object->getTaskId()); if (0 < count($executions)) { /** @var SerializationVisitorInterface $serializationVisitor */ $serializationVisitor = $event->getVisitor(); diff --git a/SuluAutomationBundle.php b/SuluAutomationBundle.php index c363e09..fe29f05 100644 --- a/SuluAutomationBundle.php +++ b/SuluAutomationBundle.php @@ -24,7 +24,7 @@ class SuluAutomationBundle extends Bundle use PersistenceBundleTrait; /** - * {@inheritdoc} + * @return void */ public function build(ContainerBuilder $container) { diff --git a/TaskHandler/TaskHandlerConfiguration.php b/TaskHandler/TaskHandlerConfiguration.php index 181d988..ae9b7e3 100644 --- a/TaskHandler/TaskHandlerConfiguration.php +++ b/TaskHandler/TaskHandlerConfiguration.php @@ -19,7 +19,7 @@ class TaskHandlerConfiguration /** * Create a new configuration. * - * @return static + * @return TaskHandlerConfiguration */ public static function create(string $title) { diff --git a/Tasks/Model/TaskInterface.php b/Tasks/Model/TaskInterface.php index 4ab0124..3ba98c2 100644 --- a/Tasks/Model/TaskInterface.php +++ b/Tasks/Model/TaskInterface.php @@ -63,14 +63,14 @@ public function getEntityId(): string; /** * Returns taskId. */ - public function getTaskId(): string; + public function getTaskId(): ?string; /** * Set taskId. * * @return TaskInterface */ - public function setTaskId(string $taskId): self; + public function setTaskId(?string $taskId): self; /** * Returns host. diff --git a/Tasks/Scheduler/TaskScheduler.php b/Tasks/Scheduler/TaskScheduler.php index e45b48f..d0ce0f5 100644 --- a/Tasks/Scheduler/TaskScheduler.php +++ b/Tasks/Scheduler/TaskScheduler.php @@ -76,7 +76,7 @@ public function reschedule(TaskInterface $task): void { $workload = $this->createWorkload($task); - $phpTask = $this->taskRepository->findByUuid($task->getTaskId()); + $phpTask = $this->taskRepository->findByUuid((string) $task->getTaskId()); $executions = $this->taskExecutionRepository->findByTask($phpTask); if ($task->getSchedule() == $phpTask->getFirstExecution() @@ -105,7 +105,7 @@ public function reschedule(TaskInterface $task): void */ public function remove(TaskInterface $task): void { - $phpTask = $this->taskRepository->findByUuid($task->getTaskId()); + $phpTask = $this->taskRepository->findByUuid((string) $task->getTaskId()); $this->taskRepository->remove($phpTask); } diff --git a/composer.json b/composer.json index ad105b3..c47d6b8 100644 --- a/composer.json +++ b/composer.json @@ -34,12 +34,12 @@ "php-ffmpeg/php-ffmpeg": "^0.14.0", "jackalope/jackalope-doctrine-dbal": "^1.3.0", "zendframework/zendsearch": "@dev", - "phpstan/phpstan": "^0.11.12", - "phpstan/phpstan-doctrine": "^0.11.5", - "phpstan/phpstan-phpunit": "^0.11.2", - "phpstan/phpstan-symfony": "^0.11.6", - "thecodingmachine/phpstan-strict-rules": "^0.11.2", - "jangregor/phpstan-prophecy": "^0.4.1" + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-doctrine": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-symfony": "^0.12", + "thecodingmachine/phpstan-strict-rules": "^0.12", + "jangregor/phpstan-prophecy": "^0.8" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 39f0821..5be10b3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ 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 @@ -16,9 +16,10 @@ parameters: - %currentWorkingDirectory%/Tests/* - %currentWorkingDirectory%/vendor/* symfony: - container_xml_path: %rootDir%/../../../Tests/Application/var/cache/admin/dev/adminAdminDevDebugProjectContainer.xml + container_xml_path: %rootDir%/../../../Tests/Application/var/cache/admin/test/Sulu_Bundle_AutomationBundle_Tests_Application_KernelTestDebugContainer.xml console_application_loader: Tests/phpstan/console-application.php doctrine: objectManagerLoader: Tests/phpstan/object-manager.php + checkGenericClassInNonGenericObjectType: false ignoreErrors: - '#Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch()#' From 517119a05ff66991af7210ee52705396b7982c13 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 16 Jun 2020 23:05:35 +0200 Subject: [PATCH 2/2] replace void typehint --- DependencyInjection/SuluAutomationExtension.php | 10 ++-------- PageTree/AutomationPageTreeUpdater.php | 5 +---- SuluAutomationBundle.php | 5 +---- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/DependencyInjection/SuluAutomationExtension.php b/DependencyInjection/SuluAutomationExtension.php index 6906bbf..99bb48a 100644 --- a/DependencyInjection/SuluAutomationExtension.php +++ b/DependencyInjection/SuluAutomationExtension.php @@ -26,10 +26,7 @@ class SuluAutomationExtension extends Extension implements PrependExtensionInter { use PersistenceExtensionTrait; - /** - * @return void - */ - public function prepend(ContainerBuilder $container) + public function prepend(ContainerBuilder $container): void { if ($container->hasExtension('jms_serializer')) { $container->prependExtensionConfig( @@ -82,10 +79,7 @@ public function prepend(ContainerBuilder $container) } } - /** - * @return void - */ - 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/PageTree/AutomationPageTreeUpdater.php b/PageTree/AutomationPageTreeUpdater.php index 96935ff..e60c2e3 100644 --- a/PageTree/AutomationPageTreeUpdater.php +++ b/PageTree/AutomationPageTreeUpdater.php @@ -48,10 +48,7 @@ public function __construct( $this->requestStack = $requestStack; } - /** - * @return void - */ - public function update(BasePageDocument $document) + public function update(BasePageDocument $document): void { $request = $this->requestStack->getCurrentRequest(); if (!$request) { diff --git a/SuluAutomationBundle.php b/SuluAutomationBundle.php index fe29f05..c8b6433 100644 --- a/SuluAutomationBundle.php +++ b/SuluAutomationBundle.php @@ -23,10 +23,7 @@ class SuluAutomationBundle extends Bundle { use PersistenceBundleTrait; - /** - * @return void - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { $this->buildPersistence( [