From 44959a69372cc4f4b517f315ce14235cf594a453 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Fri, 10 Feb 2023 10:06:55 +0100 Subject: [PATCH 01/11] Used phpstan-drupal for code analysis --- composer.json | 6 +- composer.lock | 264 ++------------------------------------------------ phpstan.neon | 18 ++++ 3 files changed, 29 insertions(+), 259 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index a665a7a0..a55ecb9a 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,7 @@ "require-dev": { "drupal/core-dev": "^9.1", "drupal/mail_debugger": "^1.4", - "mglaman/drupal-check": "^1.3" + "mglaman/phpstan-drupal": "^1.1" }, "conflict": { "drupal/drupal": "*" @@ -207,7 +207,9 @@ ], "coding-standards-apply": [ "@coding-standards-apply/phpcs" + ], + "code-analysis/phpstan": [ + "vendor/bin/phpstan analyse" ] - } } diff --git a/composer.lock b/composer.lock index 3596ca4c..540309c5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a53ec5d72c701507d70e51859f296f97", + "content-hash": "254632f7dcddf79c41aa42279f2db10d", "packages": [ { "name": "asm89/stack-cors", @@ -19297,65 +19297,6 @@ }, "time": "2022-10-28T13:30:35+00:00" }, - { - "name": "jean85/pretty-package-versions", - "version": "2.0.5", - "source": { - "type": "git", - "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af", - "shasum": "" - }, - "require": { - "composer-runtime-api": "^2.0.0", - "php": "^7.1|^8.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.17", - "jean85/composer-provided-replaced-stub-package": "^1.0", - "phpstan/phpstan": "^0.12.66", - "phpunit/phpunit": "^7.5|^8.5|^9.4", - "vimeo/psalm": "^4.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Jean85\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Alessandro Lai", - "email": "alessandro.lai85@gmail.com" - } - ], - "description": "A library to get pretty versions strings of installed dependencies", - "keywords": [ - "composer", - "package", - "release", - "versions" - ], - "support": { - "issues": "https://github.com/Jean85/pretty-package-versions/issues", - "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.5" - }, - "time": "2021-10-08T21:21:46+00:00" - }, { "name": "justinrainbow/json-schema", "version": "5.2.12", @@ -19426,81 +19367,6 @@ }, "time": "2022-04-13T08:02:27+00:00" }, - { - "name": "mglaman/drupal-check", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/mglaman/drupal-check.git", - "reference": "e78eff7b10f79659c020a45baaa1f3035cb9a06a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mglaman/drupal-check/zipball/e78eff7b10f79659c020a45baaa1f3035cb9a06a", - "reference": "e78eff7b10f79659c020a45baaa1f3035cb9a06a", - "shasum": "" - }, - "require": { - "composer/xdebug-handler": "^1.1 || ^2.0.1 || ^3.0", - "jean85/pretty-package-versions": "^1.5.0 || ^2.0.1", - "mglaman/phpstan-drupal": "^1.0.0", - "nette/neon": "^3.1", - "php": "^7.2.5|^8.0", - "phpstan/phpstan-deprecation-rules": "^1.0.0", - "symfony/console": "~3.4.5 || ^4.2|| ^5.0 || ^6.0", - "symfony/process": "~3.4.5 || ^4.2|| ^5.0 || ^6.0", - "webflo/drupal-finder": "^1.1" - }, - "require-dev": { - "phpstan/phpstan": "^1.0.0", - "phpstan/phpstan-strict-rules": "^1.0.0", - "squizlabs/php_codesniffer": "^3.4" - }, - "bin": [ - "drupal-check" - ], - "type": "project", - "extra": { - "violinist": { - "one_pull_request_per_package": 1 - } - }, - "autoload": { - "psr-4": { - "DrupalCheck\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "Matt Glaman", - "email": "nmd.matt@gmail.com" - } - ], - "description": "CLI tool for running checks on a Drupal code base", - "support": { - "issues": "https://github.com/mglaman/drupal-check/issues", - "source": "https://github.com/mglaman/drupal-check/tree/1.4.0" - }, - "funding": [ - { - "url": "https://github.com/mglaman", - "type": "github" - }, - { - "url": "https://opencollective.com/phpstan-drupal", - "type": "open_collective" - }, - { - "url": "https://tidelift.com/funding/github/packagist/mglaman/drupal-check", - "type": "tidelift" - } - ], - "time": "2022-04-29T02:26:28+00:00" - }, { "name": "mglaman/phpstan-drupal", "version": "1.1.28", @@ -19715,74 +19581,6 @@ ], "time": "2022-03-03T13:19:32+00:00" }, - { - "name": "nette/neon", - "version": "v3.3.3", - "source": { - "type": "git", - "url": "https://github.com/nette/neon.git", - "reference": "22e384da162fab42961d48eb06c06d3ad0c11b95" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nette/neon/zipball/22e384da162fab42961d48eb06c06d3ad0c11b95", - "reference": "22e384da162fab42961d48eb06c06d3ad0c11b95", - "shasum": "" - }, - "require": { - "ext-json": "*", - "php": ">=7.1" - }, - "require-dev": { - "nette/tester": "^2.0", - "phpstan/phpstan": "^0.12", - "tracy/tracy": "^2.7" - }, - "bin": [ - "bin/neon-lint" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause", - "GPL-2.0-only", - "GPL-3.0-only" - ], - "authors": [ - { - "name": "David Grudl", - "homepage": "https://davidgrudl.com" - }, - { - "name": "Nette Community", - "homepage": "https://nette.org/contributors" - } - ], - "description": "🍸 Nette NEON: encodes and decodes NEON file format.", - "homepage": "https://ne-on.org", - "keywords": [ - "export", - "import", - "neon", - "nette", - "yaml" - ], - "support": { - "issues": "https://github.com/nette/neon/issues", - "source": "https://github.com/nette/neon/tree/v3.3.3" - }, - "time": "2022-03-10T02:04:26+00:00" - }, { "name": "phar-io/manifest", "version": "2.0.3", @@ -20129,16 +19927,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.9.14", + "version": "1.9.17", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e5fcc96289cf737304286a9b505fbed091f02e58" + "reference": "204e459e7822f2c586463029f5ecec31bb45a1f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e5fcc96289cf737304286a9b505fbed091f02e58", - "reference": "e5fcc96289cf737304286a9b505fbed091f02e58", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/204e459e7822f2c586463029f5ecec31bb45a1f2", + "reference": "204e459e7822f2c586463029f5ecec31bb45a1f2", "shasum": "" }, "require": { @@ -20168,7 +19966,7 @@ ], "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.9.14" + "source": "https://github.com/phpstan/phpstan/tree/1.9.17" }, "funding": [ { @@ -20184,55 +19982,7 @@ "type": "tidelift" } ], - "time": "2023-01-19T10:47:09+00:00" - }, - { - "name": "phpstan/phpstan-deprecation-rules", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "2c6792eda026d9c474c14aa018aed312686714db" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/2c6792eda026d9c474c14aa018aed312686714db", - "reference": "2c6792eda026d9c474c14aa018aed312686714db", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.9.3" - }, - "require-dev": { - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-php-parser": "^1.1", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "rules.neon" - ] - } - }, - "autoload": { - "psr-4": { - "PHPStan\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", - "support": { - "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.1.1" - }, - "time": "2022-12-13T14:26:20+00:00" + "time": "2023-02-08T12:25:00+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..2b6ed71f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,18 @@ +parameters: + drupal: + drupal_root: /app/web + level: 6 + paths: + - web/modules/custom + ignoreErrors: + - + # Ignore some weird errors reported by PHPStan + # @todo Investigate further + messages: + - '#no value type specified in iterable type array.#' + - '#has no return type specified.#' + - '#with no type specified.#' +includes: + - vendor/mglaman/phpstan-drupal/extension.neon + - vendor/mglaman/phpstan-drupal/rules.neon + From 5aa223cf20a7b5bd3be5e104bad75eea71e8fab4 Mon Sep 17 00:00:00 2001 From: martinyde Date: Fri, 10 Feb 2023 14:29:42 +0100 Subject: [PATCH 02/11] FORMS-718: Changed phpstan setup --- composer.json | 13 +-- composer.lock | 106 ++++++++++++++++-- phpstan.neon | 3 - .../AdvancedQueue/JobType/PostSubmission.php | 2 +- .../Plugin/WebformHandler/WebformHandler.php | 2 +- .../AdvancedQueue/JobType/ArchiveDocument.php | 2 +- .../GetOrganizedWebformHandler.php | 2 +- .../src/Plugin/Block/UserMenuBlock.php | 2 +- 8 files changed, 109 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 4c60efb5..84154ada 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,10 @@ "require-dev": { "drupal/core-dev": "^9.1", "drupal/mail_debugger": "^1.4", - "mglaman/phpstan-drupal": "^1.1" + "mglaman/phpstan-drupal": "^1.1", + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-deprecation-rules": "^1.1" }, "conflict": { "drupal/drupal": "*" @@ -191,11 +194,8 @@ "install-codestandards": [ "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" ], - "code-analysis/drupal-check": [ - "vendor/bin/drupal-check --deprecations --analysis web/modules/custom" - ], "code-analysis": [ - "@code-analysis/drupal-check" + "vendor/bin/phpstan analyse" ], "coding-standards-check/phpcs": [ "vendor/bin/phpcs --standard=phpcs.xml.dist" @@ -208,9 +208,6 @@ ], "coding-standards-apply": [ "@coding-standards-apply/phpcs" - ], - "code-analysis/phpstan": [ - "vendor/bin/phpstan analyse" ] } } diff --git a/composer.lock b/composer.lock index 971af1a7..f9656e3a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e6d29182617fc175c89d74b26f3a66a4", + "content-hash": "9bb1c79ff1906fa54dc1774a2d6e9fcc", "packages": [ { "name": "asm89/stack-cors", @@ -19369,16 +19369,16 @@ }, { "name": "mglaman/phpstan-drupal", - "version": "1.1.28", + "version": "1.1.29", "source": { "type": "git", "url": "https://github.com/mglaman/phpstan-drupal.git", - "reference": "55c3f437e52d0e10e7ac59ffb20e338625b79594" + "reference": "e6f6191c53b159013fcbd186d7f85511f3f96ff8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mglaman/phpstan-drupal/zipball/55c3f437e52d0e10e7ac59ffb20e338625b79594", - "reference": "55c3f437e52d0e10e7ac59ffb20e338625b79594", + "url": "https://api.github.com/repos/mglaman/phpstan-drupal/zipball/e6f6191c53b159013fcbd186d7f85511f3f96ff8", + "reference": "e6f6191c53b159013fcbd186d7f85511f3f96ff8", "shasum": "" }, "require": { @@ -19453,7 +19453,7 @@ "description": "Drupal extension and rules for PHPStan", "support": { "issues": "https://github.com/mglaman/phpstan-drupal/issues", - "source": "https://github.com/mglaman/phpstan-drupal/tree/1.1.28" + "source": "https://github.com/mglaman/phpstan-drupal/tree/1.1.29" }, "funding": [ { @@ -19469,7 +19469,7 @@ "type": "tidelift" } ], - "time": "2023-02-01T21:17:43+00:00" + "time": "2023-02-08T21:44:03+00:00" }, { "name": "mikey179/vfsstream", @@ -19925,6 +19925,50 @@ }, "time": "2023-02-02T15:41:36+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f06dbb052ddc394e7896fcd1cfcd533f9f6ace40" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f06dbb052ddc394e7896fcd1cfcd533f9f6ace40", + "reference": "f06dbb052ddc394e7896fcd1cfcd533f9f6ace40", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.8.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.2.0" + }, + "time": "2022-10-17T12:59:16+00:00" + }, { "name": "phpstan/phpstan", "version": "1.9.17", @@ -19984,6 +20028,54 @@ ], "time": "2023-02-08T12:25:00+00:00" }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "2c6792eda026d9c474c14aa018aed312686714db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/2c6792eda026d9c474c14aa018aed312686714db", + "reference": "2c6792eda026d9c474c14aa018aed312686714db", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.3" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-php-parser": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.1.1" + }, + "time": "2022-12-13T14:26:20+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.24", diff --git a/phpstan.neon b/phpstan.neon index 2b6ed71f..5a8f83a2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,7 +12,4 @@ parameters: - '#no value type specified in iterable type array.#' - '#has no return type specified.#' - '#with no type specified.#' -includes: - - vendor/mglaman/phpstan-drupal/extension.neon - - vendor/mglaman/phpstan-drupal/rules.neon diff --git a/web/modules/custom/os2forms_api_request_handler/src/Plugin/AdvancedQueue/JobType/PostSubmission.php b/web/modules/custom/os2forms_api_request_handler/src/Plugin/AdvancedQueue/JobType/PostSubmission.php index 70af5424..7b9edb94 100644 --- a/web/modules/custom/os2forms_api_request_handler/src/Plugin/AdvancedQueue/JobType/PostSubmission.php +++ b/web/modules/custom/os2forms_api_request_handler/src/Plugin/AdvancedQueue/JobType/PostSubmission.php @@ -20,7 +20,7 @@ * label = @Translation("Post form submission to API endpoint"), * ) */ -class PostSubmission extends JobTypeBase implements ContainerFactoryPluginInterface { +final class PostSubmission extends JobTypeBase implements ContainerFactoryPluginInterface { /** * The post helper. * diff --git a/web/modules/custom/os2forms_api_request_handler/src/Plugin/WebformHandler/WebformHandler.php b/web/modules/custom/os2forms_api_request_handler/src/Plugin/WebformHandler/WebformHandler.php index ad3d4d38..4360d569 100644 --- a/web/modules/custom/os2forms_api_request_handler/src/Plugin/WebformHandler/WebformHandler.php +++ b/web/modules/custom/os2forms_api_request_handler/src/Plugin/WebformHandler/WebformHandler.php @@ -30,7 +30,7 @@ * submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED, * ) */ -class WebformHandler extends WebformHandlerBase { +final class WebformHandler extends WebformHandlerBase { /** * The queue id. * diff --git a/web/modules/custom/os2forms_get_organized/src/Plugin/AdvancedQueue/JobType/ArchiveDocument.php b/web/modules/custom/os2forms_get_organized/src/Plugin/AdvancedQueue/JobType/ArchiveDocument.php index e246c5e4..2a565af0 100644 --- a/web/modules/custom/os2forms_get_organized/src/Plugin/AdvancedQueue/JobType/ArchiveDocument.php +++ b/web/modules/custom/os2forms_get_organized/src/Plugin/AdvancedQueue/JobType/ArchiveDocument.php @@ -20,7 +20,7 @@ * label = @Translation("Archive document in GetOrganized"), * ) */ -class ArchiveDocument extends JobTypeBase implements ContainerFactoryPluginInterface { +final class ArchiveDocument extends JobTypeBase implements ContainerFactoryPluginInterface { /** * The archiving helper. * diff --git a/web/modules/custom/os2forms_get_organized/src/Plugin/WebformHandler/GetOrganizedWebformHandler.php b/web/modules/custom/os2forms_get_organized/src/Plugin/WebformHandler/GetOrganizedWebformHandler.php index 9d40054d..d338793e 100644 --- a/web/modules/custom/os2forms_get_organized/src/Plugin/WebformHandler/GetOrganizedWebformHandler.php +++ b/web/modules/custom/os2forms_get_organized/src/Plugin/WebformHandler/GetOrganizedWebformHandler.php @@ -29,7 +29,7 @@ * submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED, * ) */ -class GetOrganizedWebformHandler extends WebformHandlerBase { +final class GetOrganizedWebformHandler extends WebformHandlerBase { /** * The submission logger. * diff --git a/web/modules/custom/os2forms_user_menu/src/Plugin/Block/UserMenuBlock.php b/web/modules/custom/os2forms_user_menu/src/Plugin/Block/UserMenuBlock.php index d086da28..4f7bf569 100644 --- a/web/modules/custom/os2forms_user_menu/src/Plugin/Block/UserMenuBlock.php +++ b/web/modules/custom/os2forms_user_menu/src/Plugin/Block/UserMenuBlock.php @@ -22,7 +22,7 @@ * category = @Translation("OS2Forms") * ) */ -class UserMenuBlock extends BlockBase implements ContainerFactoryPluginInterface { +final class UserMenuBlock extends BlockBase implements ContainerFactoryPluginInterface { use StringTranslationTrait; /** From f5651406c0b8562d4f5ad5409a44440b48d09e77 Mon Sep 17 00:00:00 2001 From: martinyde Date: Fri, 10 Feb 2023 14:32:26 +0100 Subject: [PATCH 03/11] Changed github action --- .github/workflows/pr.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 2221ef8f..b4f90cc4 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -113,13 +113,9 @@ jobs: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - - name: Install Dependencies - run: | - # Using `--no-scripts` breaks something with mglaman/drupal-check. - composer install --no-interaction --no-progress --no-scripts - name: drupal-check run: | - composer code-analysis/drupal-check + composer code-analysis coding-standards-custom-themes: name: Yarn - Check Coding Standards in custom themes From 2bff69d867cb2b0dd2f3ba55f8ed3978841ac939 Mon Sep 17 00:00:00 2001 From: martinyde Date: Fri, 10 Feb 2023 14:33:21 +0100 Subject: [PATCH 04/11] Changed github action --- .github/workflows/pr.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b4f90cc4..45009d84 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -113,6 +113,10 @@ jobs: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- + - name: Install Dependencies + run: | + # Using `--no-scripts` breaks something with mglaman/drupal-check. + composer install --no-interaction --no-progress --no-scripts - name: drupal-check run: | composer code-analysis From e6d84b33140147c5cf0ffde7abfb6c3367b895e6 Mon Sep 17 00:00:00 2001 From: martinyde Date: Fri, 10 Feb 2023 14:36:42 +0100 Subject: [PATCH 05/11] Changed github action --- .github/workflows/pr.yaml | 4 ++-- CHANGELOG.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 45009d84..69254bde 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -116,8 +116,8 @@ jobs: - name: Install Dependencies run: | # Using `--no-scripts` breaks something with mglaman/drupal-check. - composer install --no-interaction --no-progress --no-scripts - - name: drupal-check + composer install --no-interaction --no-progress + - name: code-analysis run: | composer code-analysis diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d3e18a3..8a9b0901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Nedenfor ses dato for release og beskrivelse af opgaver som er implementeret. * Installerede [OS2Forms organisation 1.0.0](https://github.com/itk-dev/os2forms_organisation/releases/tag/1.0.0). +* Phpstan config ### Opdateret From 80ad4dd35f8a4a6453be71436c532db2769d9771 Mon Sep 17 00:00:00 2001 From: martinyde Date: Fri, 10 Feb 2023 14:41:13 +0100 Subject: [PATCH 06/11] Changed github action --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 69254bde..65e1770b 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -116,7 +116,7 @@ jobs: - name: Install Dependencies run: | # Using `--no-scripts` breaks something with mglaman/drupal-check. - composer install --no-interaction --no-progress + composer install --no-interaction --no-progress --no-scripts - name: code-analysis run: | composer code-analysis From 1682776fbfed58ee7396f0229ed1561fd5235e25 Mon Sep 17 00:00:00 2001 From: martinyde Date: Tue, 14 Feb 2023 08:51:58 +0100 Subject: [PATCH 07/11] Changed github action --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 65e1770b..f98e4853 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -116,7 +116,7 @@ jobs: - name: Install Dependencies run: | # Using `--no-scripts` breaks something with mglaman/drupal-check. - composer install --no-interaction --no-progress --no-scripts + composer install --no-interaction --no-progress --no-scripts -vvv - name: code-analysis run: | composer code-analysis From 0e310dce969a714501402507a0d90263b4bb5cfd Mon Sep 17 00:00:00 2001 From: martinyde Date: Tue, 14 Feb 2023 09:38:16 +0100 Subject: [PATCH 08/11] Changed github action --- .github/workflows/pr.yaml | 2 +- composer.json | 2 +- phpstan.neon | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index f98e4853..65e1770b 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -116,7 +116,7 @@ jobs: - name: Install Dependencies run: | # Using `--no-scripts` breaks something with mglaman/drupal-check. - composer install --no-interaction --no-progress --no-scripts -vvv + composer install --no-interaction --no-progress --no-scripts - name: code-analysis run: | composer code-analysis diff --git a/composer.json b/composer.json index 84154ada..b5329da1 100644 --- a/composer.json +++ b/composer.json @@ -195,7 +195,7 @@ "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" ], "code-analysis": [ - "vendor/bin/phpstan analyse" + "vendor/bin/phpstan analyse" ], "coding-standards-check/phpcs": [ "vendor/bin/phpcs --standard=phpcs.xml.dist" diff --git a/phpstan.neon b/phpstan.neon index 5a8f83a2..4e70c987 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: drupal: - drupal_root: /app/web + drupal_root: %currentWorkingDirectory% level: 6 paths: - web/modules/custom From 00d007dfdde3ec43b79c8e9b6a37d528ab9b3d72 Mon Sep 17 00:00:00 2001 From: martinyde Date: Tue, 14 Feb 2023 10:28:09 +0100 Subject: [PATCH 09/11] Applied phpstan drupal-check --- .../custom/os2forms_get_organized/src/Helper/ArchiveHelper.php | 3 +-- .../src/Helper/MaestroTemplateHelper.php | 2 +- .../src/Plugin/WebformElement/UserFieldElement.php | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php b/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php index e9315019..7473d9fe 100644 --- a/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php +++ b/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php @@ -300,8 +300,7 @@ private function createSubCase($caseId, string $caseName) { * Uploads attachment document to GetOrganized case. */ private function uploadDocumentToCase($caseId, $webformAttachmentElementId, WebformSubmission $submission, $shouldBeFinalized) { - - $element = $submission->getWebform()->getElement($webformAttachmentElementId, $submission); + $element = $submission->getWebform()->getElement($webformAttachmentElementId); $fileContent = WebformEntityPrintAttachment::getFileContent($element, $submission); // Create temp file with attachment-element contents. diff --git a/web/modules/custom/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php b/web/modules/custom/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php index dc64855e..b1dace45 100644 --- a/web/modules/custom/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php +++ b/web/modules/custom/os2forms_permissions_by_term/src/Helper/MaestroTemplateHelper.php @@ -296,7 +296,7 @@ public function viewsQueryAlter(ViewExecutable $view, QueryPluginBase $query) { $displayId = $view->getDisplay()->display['id']; /** @var \Drupal\Core\Session\AccountInterface $user */ $user = $this->entityTypeManager->getStorage('user')->load($this->account->id()); - $maestroTemplates = $this->entityTypeManager->getStorage('maestro_template')->getQuery()->execute(); + $maestroTemplates = $this->entityTypeManager->getStorage('maestro_template')->getQuery()->accessCheck(TRUE)->execute(); $allowedList = []; foreach ($maestroTemplates as $template) { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $templateEntity */ diff --git a/web/modules/custom/os2forms_user_field_lookup/src/Plugin/WebformElement/UserFieldElement.php b/web/modules/custom/os2forms_user_field_lookup/src/Plugin/WebformElement/UserFieldElement.php index 2260f11e..7a9a7601 100644 --- a/web/modules/custom/os2forms_user_field_lookup/src/Plugin/WebformElement/UserFieldElement.php +++ b/web/modules/custom/os2forms_user_field_lookup/src/Plugin/WebformElement/UserFieldElement.php @@ -38,7 +38,6 @@ public function alterForm(array &$element, array &$form, FormStateInterface $for if ($user->hasField($fieldName)) { $value = $user->get($fieldName)->value; if (!empty($value)) { - // @phpstan-ignore-next-line $element['#value'] = is_scalar($value) ? $value : json_encode($value); NestedArray::setValue($form['elements'], $element['#webform_parents'], $element); } From 239debea061035529a4cda184fda0c7e0c6475c8 Mon Sep 17 00:00:00 2001 From: martinyde Date: Tue, 14 Feb 2023 11:15:52 +0100 Subject: [PATCH 10/11] Removed type error from phpstan ignore errors --- phpstan.neon | 2 -- .../os2forms_get_organized/src/Helper/ArchiveHelper.php | 7 +++---- .../os2forms_permissions_by_term.module | 8 ++++---- .../os2forms_selvbetjening/os2forms_selvbetjening.module | 2 +- .../os2forms_selvbetjening/src/Helper/FormHelper.php | 3 +-- .../os2forms_user_field_lookup.module | 2 +- .../src/WebformElementHelper.php | 2 +- .../custom/os2forms_user_menu/os2forms_user_menu.module | 2 +- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 4e70c987..4ecad86f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,9 +7,7 @@ parameters: ignoreErrors: - # Ignore some weird errors reported by PHPStan - # @todo Investigate further messages: - '#no value type specified in iterable type array.#' - '#has no return type specified.#' - - '#with no type specified.#' diff --git a/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php b/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php index 7473d9fe..13fee08d 100644 --- a/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php +++ b/web/modules/custom/os2forms_get_organized/src/Helper/ArchiveHelper.php @@ -257,7 +257,7 @@ private function archiveToCitizen(string $submissionId, array $handlerConfigurat /** * Creates citizen parent case in GetOrganized. */ - private function createCitizenCase($cprElementValue, $cprNameElementValue) { + private function createCitizenCase(string $cprElementValue, string $cprNameElementValue) { $metadataArray = [ 'ows_Title' => $cprElementValue . ' - ' . $cprNameElementValue, @@ -278,8 +278,7 @@ private function createCitizenCase($cprElementValue, $cprNameElementValue) { /** * Creates citizen subcase in GetOrganized. */ - private function createSubCase($caseId, string $caseName) { - + private function createSubCase(string $caseId, string $caseName) { $metadataArray = [ 'ows_Title' => $caseName, 'ows_CCMParentCase' => $caseId, @@ -299,7 +298,7 @@ private function createSubCase($caseId, string $caseName) { /** * Uploads attachment document to GetOrganized case. */ - private function uploadDocumentToCase($caseId, $webformAttachmentElementId, WebformSubmission $submission, $shouldBeFinalized) { + private function uploadDocumentToCase(string $caseId, string $webformAttachmentElementId, WebformSubmission $submission, bool $shouldBeFinalized) { $element = $submission->getWebform()->getElement($webformAttachmentElementId); $fileContent = WebformEntityPrintAttachment::getFileContent($element, $submission); diff --git a/web/modules/custom/os2forms_permissions_by_term/os2forms_permissions_by_term.module b/web/modules/custom/os2forms_permissions_by_term/os2forms_permissions_by_term.module index d63be5f6..efae9500 100644 --- a/web/modules/custom/os2forms_permissions_by_term/os2forms_permissions_by_term.module +++ b/web/modules/custom/os2forms_permissions_by_term/os2forms_permissions_by_term.module @@ -19,7 +19,7 @@ use Drupal\Core\Session\AccountInterface; * We need the hook_options_list_alter() in this module to trigger after the one * in permissions_by_term module. */ -function os2forms_permissions_by_term_module_implements_alter(&$implementations, $hook) { +function os2forms_permissions_by_term_module_implements_alter(array &$implementations, string $hook) { switch ($hook) { // Move our hook_options_list_alter() implementation to the end of the list // so it is handled after permissions_by_term module. @@ -63,7 +63,7 @@ function os2forms_permissions_by_term_form_node_form_alter(array &$form, FormSta * * Deny access to webforms based on permissions_by_term. */ -function os2forms_permissions_by_term_webform_access(WebformInterface $webform, $operation, AccountInterface $account) { +function os2forms_permissions_by_term_webform_access(WebformInterface $webform, string $operation, AccountInterface $account) { return \Drupal::service('os2forms_permissions_by_term.helper')->webformAccess($webform, $operation, $account); } @@ -72,7 +72,7 @@ function os2forms_permissions_by_term_webform_access(WebformInterface $webform, * * Allow/deny access to node. */ -function os2forms_permissions_by_term_node_access(NodeInterface $node, $operation, AccountInterface $account) { +function os2forms_permissions_by_term_node_access(NodeInterface $node, string $operation, AccountInterface $account) { return \Drupal::service('os2forms_permissions_by_term.helper')->nodeAccess($node, $operation, $account); } @@ -99,7 +99,7 @@ function os2forms_permissions_by_term_form_maestro_template_edit_form_alter(arra * * Deny access to Maestro templates based on permissions_by_term. */ -function os2forms_permissions_by_term_maestro_template_access(ConfigEntityInterface $maestroTemplate, $operation, AccountInterface $account) { +function os2forms_permissions_by_term_maestro_template_access(ConfigEntityInterface $maestroTemplate, string $operation, AccountInterface $account) { return \Drupal::service('os2forms_permissions_by_term.maestro_template_helper')->maestroTemplateAccess($maestroTemplate, $operation, $account); } diff --git a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.module b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.module index 651d079d..0a19ab20 100644 --- a/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.module +++ b/web/modules/custom/os2forms_selvbetjening/os2forms_selvbetjening.module @@ -13,7 +13,7 @@ use Drupal\os2forms_selvbetjening\Helper\FormHelper; * * Allows altering of forms. */ -function os2forms_selvbetjening_form_alter(&$form, FormStateInterface $form_state, $form_id) { +function os2forms_selvbetjening_form_alter(array &$form, FormStateInterface $form_state, string $form_id) { Drupal::service(FormHelper::class)->formAlter($form, $form_state, $form_id); } diff --git a/web/modules/custom/os2forms_selvbetjening/src/Helper/FormHelper.php b/web/modules/custom/os2forms_selvbetjening/src/Helper/FormHelper.php index 729cc7ff..529c710a 100644 --- a/web/modules/custom/os2forms_selvbetjening/src/Helper/FormHelper.php +++ b/web/modules/custom/os2forms_selvbetjening/src/Helper/FormHelper.php @@ -27,8 +27,7 @@ public function __construct(ConfigFactoryInterface $config) { /** * Allows altering of forms. */ - public function formAlter(&$form, FormStateInterface $form_state, $form_id) { - + public function formAlter(array &$form, FormStateInterface $form_state, string $form_id) { // Add description to the message body section of the email handler. if ('webform_handler_form' === $form_id && 'email' === ($form['#webform_handler_plugin_id'] ?? NULL)) { diff --git a/web/modules/custom/os2forms_user_field_lookup/os2forms_user_field_lookup.module b/web/modules/custom/os2forms_user_field_lookup/os2forms_user_field_lookup.module index bdbdfec0..cac299e5 100644 --- a/web/modules/custom/os2forms_user_field_lookup/os2forms_user_field_lookup.module +++ b/web/modules/custom/os2forms_user_field_lookup/os2forms_user_field_lookup.module @@ -31,6 +31,6 @@ function os2forms_user_field_lookup_webform_element_translatable_properties_alte * * @see WebformElementHelper::alterConfigurationForm() */ -function os2forms_user_field_lookup_webform_element_configuration_form_alter(&$form, FormStateInterface $form_state) { +function os2forms_user_field_lookup_webform_element_configuration_form_alter(array &$form, FormStateInterface $form_state) { Drupal::service(WebformElementHelper::class)->alterConfigurationForm($form, $form_state); } diff --git a/web/modules/custom/os2forms_user_field_lookup/src/WebformElementHelper.php b/web/modules/custom/os2forms_user_field_lookup/src/WebformElementHelper.php index 4b070b08..39bc96ae 100644 --- a/web/modules/custom/os2forms_user_field_lookup/src/WebformElementHelper.php +++ b/web/modules/custom/os2forms_user_field_lookup/src/WebformElementHelper.php @@ -50,7 +50,7 @@ public function alterTranslatableProperties(array &$properties, array &$definiti /** * Implements hook_webform_element_configuration_form_alter(). */ - public function alterConfigurationForm(&$form, FormStateInterface $form_state) { + public function alterConfigurationForm(array &$form, FormStateInterface $form_state) { /** @var \Drupal\webform_ui\Form\WebformUiElementFormBase $formObject */ $formObject = $form_state->getFormObject(); $elementPlugin = $formObject->getWebformElementPlugin(); diff --git a/web/modules/custom/os2forms_user_menu/os2forms_user_menu.module b/web/modules/custom/os2forms_user_menu/os2forms_user_menu.module index 79ba8437..656c5e52 100644 --- a/web/modules/custom/os2forms_user_menu/os2forms_user_menu.module +++ b/web/modules/custom/os2forms_user_menu/os2forms_user_menu.module @@ -8,7 +8,7 @@ /** * Implements hook_theme(). */ -function os2forms_user_menu_theme($existing, $type, $theme, $path) { +function os2forms_user_menu_theme(array $existing, string $type, string $theme, string $path): array { return [ 'os2forms_user_menu' => [ 'variables' => [ From 26394e82eaba8399c0ae50dce7bcf2d520b1fcd9 Mon Sep 17 00:00:00 2001 From: martinyde Date: Tue, 14 Feb 2023 12:57:38 +0100 Subject: [PATCH 11/11] Changed usage of phpstan --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b5329da1..f3161357 100644 --- a/composer.json +++ b/composer.json @@ -194,8 +194,11 @@ "install-codestandards": [ "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" ], + "code-analysis/phpstan": [ + "vendor/bin/phpstan analyse" + ], "code-analysis": [ - "vendor/bin/phpstan analyse" + "@code-analysis/phpstan" ], "coding-standards-check/phpcs": [ "vendor/bin/phpcs --standard=phpcs.xml.dist"