From 14afb15b263dcd8944516093e366f814760d79b2 Mon Sep 17 00:00:00 2001 From: tuutti Date: Mon, 27 Nov 2023 09:30:05 +0200 Subject: [PATCH] UHF-9213: Run phpstan --- .github/workflows/ci.yml | 7 +++++-- phpstan.neon | 12 ++++++++++++ src/Plugin/DebugDataItem/Robots.php | 6 +++--- tests/src/Kernel/RobotsResponseSubscriberTest.php | 1 + .../Kernel/TunnistamoRedirectUrlSubscriberTest.php | 4 +++- 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68b6bba..c3212a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,8 +66,11 @@ jobs: - name: Run PHPCS working-directory: ${{ env.DRUPAL_ROOT }} - run: | - vendor/bin/phpcs $MODULE_FOLDER --standard=Drupal --extensions=php,module,inc,install,test,info + run: vendor/bin/phpcs $MODULE_FOLDER --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,info + + - name: Run phpstan + working-directory: ${{ env.DRUPAL_ROOT }} + run: vendor/bin/phpstan analyze -c $MODULE_FOLDER/phpstan.neon $MODULE_FOLDER - name: Start services working-directory: ${{ env.DRUPAL_ROOT }} diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..0c4c2ca --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +parameters: + fileExtensions: + - php + - module + - install + paths: + - ./ + excludePaths: + - vendor + level: 3 + checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false diff --git a/src/Plugin/DebugDataItem/Robots.php b/src/Plugin/DebugDataItem/Robots.php index 213b351..c097b56 100644 --- a/src/Plugin/DebugDataItem/Robots.php +++ b/src/Plugin/DebugDataItem/Robots.php @@ -17,7 +17,7 @@ * description = @Translation("Robots data") * ) */ -class Robots extends DebugDataItemPluginBase implements ContainerFactoryPluginInterface { +final class Robots extends DebugDataItemPluginBase implements ContainerFactoryPluginInterface { /** * Robots header enabled settings value. @@ -29,8 +29,8 @@ class Robots extends DebugDataItemPluginBase implements ContainerFactoryPluginIn /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - $instance = new static($configuration, $plugin_id, $plugin_definition); + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : self { + $instance = new self($configuration, $plugin_id, $plugin_definition); $instance->robotsHeader = (bool) $container->get('config.factory') ->get('helfi_proxy.settings') diff --git a/tests/src/Kernel/RobotsResponseSubscriberTest.php b/tests/src/Kernel/RobotsResponseSubscriberTest.php index a8b9abb..af95a0d 100644 --- a/tests/src/Kernel/RobotsResponseSubscriberTest.php +++ b/tests/src/Kernel/RobotsResponseSubscriberTest.php @@ -58,6 +58,7 @@ private function getResponseEvent(Request $request = NULL) : ResponseEvent { $this->container->get('http_kernel'), $request, // @todo Rename this once Core requires 7.0 symfony. + // @phpstan-ignore-next-line HttpKernelInterface::MASTER_REQUEST, new HtmlResponse() ); diff --git a/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php b/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php index f85b1f9..f44d142 100644 --- a/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php +++ b/tests/src/Kernel/TunnistamoRedirectUrlSubscriberTest.php @@ -132,7 +132,9 @@ private function configureTunnistamoClient(): void { */ private function getRedirectUri() : string { $client = OpenIDConnectClientEntity::load('tunnistamo')->getPlugin(); - $url = $client->authorize()->getTargetUrl(); + /** @var \Symfony\Component\HttpFoundation\RedirectResponse $response */ + $response = $client->authorize(); + $url = $response->getTargetUrl(); parse_str(parse_url($url, PHP_URL_QUERY), $query); return $query['redirect_uri'];