From fbabcd38f1c200d9a6b3a52abdbfccb3c83d7a4e Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Mon, 13 May 2024 15:32:23 +0200 Subject: [PATCH] phpcs + phpstan --- .github/workflows/continuous-integration.yml | 35 +++ .phpcs.xml | 18 ++ composer.json | 12 +- composer.lock | 292 ++++++++++++++++++- hook.php | 17 +- phpstan.neon | 16 + setup.php | 96 +++--- 7 files changed, 430 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/continuous-integration.yml create mode 100644 .phpcs.xml create mode 100644 phpstan.neon diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..dad5c8e --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,35 @@ +name: "Continuous integration" + +on: + push: + branches: + - "main" + tags: + - "*" + pull_request: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + generate-ci-matrix: + name: "Generate CI matrix" + uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1" + with: + glpi-version: "10.0.x" + ci: + name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" + needs: "generate-ci-matrix" + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.generate-ci-matrix.outputs.matrix) }} + uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1" + with: + plugin-key: "advancedplanning" + glpi-version: "${{ matrix.glpi-version }}" + php-version: "${{ matrix.php-version }}" + db-image: "${{ matrix.db-image }}" diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..083e4a3 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,18 @@ + + + . + /.git/ + ^vendor/ + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 64b664b..36db610 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,21 @@ "php": ">=7.4" }, "require-dev": { - "glpi-project/tools": "^0.7" + "glpi-project/tools": "^0.7.2", + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.11", + "phpstan/phpstan-deprecation-rules": "^1.2", + "squizlabs/php_codesniffer": "^3.9" }, "config": { "optimize-autoloader": true, "platform": { "php": "7.4.0" }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/composer.lock b/composer.lock index 6712198..9c6481a 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": "4bffe68c5863fe18f4230d1c879b2100", + "content-hash": "5c8584eea3b976d67ada69a40ce88db3", "packages": [], "packages-dev": [ { @@ -63,6 +63,216 @@ }, "time": "2024-01-10T09:01:18+00:00" }, + { + "name": "php-parallel-lint/php-parallel-lint", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6db563514f27e19595a19f45a4bf757b6401194e", + "reference": "6db563514f27e19595a19f45a4bf757b6401194e", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "replace": { + "grogy/php-parallel-lint": "*", + "jakub-onderka/php-parallel-lint": "*" + }, + "require-dev": { + "nette/tester": "^1.3 || ^2.0", + "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "suggest": { + "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + }, + "bin": [ + "parallel-lint" + ], + "type": "library", + "autoload": { + "classmap": [ + "./src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "ahoj@jakubonderka.cz" + } + ], + "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", + "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "keywords": [ + "lint", + "static analysis" + ], + "support": { + "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.4.0" + }, + "time": "2024-03-27T12:14:49+00:00" + }, + { + "name": "phpstan/extension-installer", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f45734bfb9984c6c56c4486b71230355f066a58a", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.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.3.1" + }, + "time": "2023-05-24T08:59:17+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "666cb1703742cea9cc80fee631f0940e1592fa6e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/666cb1703742cea9cc80fee631f0940e1592fa6e", + "reference": "666cb1703742cea9cc80fee631f0940e1592fa6e", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-05-13T06:02:22+00:00" + }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "fa8cce7720fa782899a0aa97b6a41225d1bb7b26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/fa8cce7720fa782899a0aa97b6a41225d1bb7b26", + "reference": "fa8cce7720fa782899a0aa97b6a41225d1bb7b26", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.11" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "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.2.0" + }, + "time": "2024-04-20T06:39:48+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -111,6 +321,86 @@ }, "time": "2021-11-05T16:50:12+00:00" }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.9.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "aac1f6f347a5c5ac6bc98ad395007df00990f480" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/aac1f6f347a5c5ac6bc98ad395007df00990f480", + "reference": "aac1f6f347a5c5ac6bc98ad395007df00990f480", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-04-23T20:25:34+00:00" + }, { "name": "symfony/console", "version": "v5.4.35", diff --git a/hook.php b/hook.php index 4412e89..a3fe127 100644 --- a/hook.php +++ b/hook.php @@ -33,8 +33,9 @@ * * @return boolean */ -function plugin_advancedplanning_install() { - return true; +function plugin_advancedplanning_install() +{ + return true; } /** @@ -42,10 +43,12 @@ function plugin_advancedplanning_install() { * * @return boolean */ -function plugin_advancedplanning_uninstall() { - return true; +function plugin_advancedplanning_uninstall() +{ + return true; } -function testhook() { - return "resourceTimeline"; -} \ No newline at end of file +function testhook() +{ + return "resourceTimeline"; +} diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..7eb5ec1 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,16 @@ +parameters: + parallel: + maximumNumberOfProcesses: 2 + level: 5 + bootstrapFiles: + - ../../inc/based_config.php + paths: + - hook.php + - setup.php + scanDirectories: + - ../../inc + - ../../src + stubFiles: + - ../../stubs/glpi_constants.php +rules: + - GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule diff --git a/setup.php b/setup.php index 87f2403..324cd17 100644 --- a/setup.php +++ b/setup.php @@ -38,46 +38,49 @@ * * @return void */ -function plugin_init_advancedplanning() { - global $PLUGIN_HOOKS, $CFG_GLPI; +function plugin_init_advancedplanning() +{ + /** @var array $CFG_GLPI */ + /** @var array $PLUGIN_HOOKS */ + global $PLUGIN_HOOKS, $CFG_GLPI; - $PLUGIN_HOOKS['csrf_compliant']['advancedplanning'] = true; + $PLUGIN_HOOKS['csrf_compliant']['advancedplanning'] = true; // manage list of authorized url where to load js/css - $calendar_urls = [ - "front/planning.php", - "front/reservation.php", - ]; - foreach ($CFG_GLPI['reservation_types'] as $reservation_type) { - $calendar_urls[] = $reservation_type::getFormUrl(false); - } + $calendar_urls = [ + "front/planning.php", + "front/reservation.php", + ]; + foreach ($CFG_GLPI['reservation_types'] as $reservation_type) { + $calendar_urls[] = $reservation_type::getFormUrl(false); + } - $found_url = false; - foreach ($calendar_urls as $url) { - if (strpos($_SERVER['REQUEST_URI'] ?? '', $url) !== false) { - $found_url = true; - break; - } - } + $found_url = false; + foreach ($calendar_urls as $url) { + if (strpos($_SERVER['REQUEST_URI'] ?? '', $url) !== false) { + $found_url = true; + break; + } + } - if ($found_url) { - $sc_lib = "lib/fullcalendar-scheduler-4.4.0/packages-premium"; + if ($found_url) { + $sc_lib = "lib/fullcalendar-scheduler-4.4.0/packages-premium"; - $PLUGIN_HOOKS['add_javascript']['advancedplanning'] = [ - "$sc_lib/resource-common/main.js", - "$sc_lib/timeline/main.js", - "$sc_lib/resource-timeline/main.js" - ]; + $PLUGIN_HOOKS['add_javascript']['advancedplanning'] = [ + "$sc_lib/resource-common/main.js", + "$sc_lib/timeline/main.js", + "$sc_lib/resource-timeline/main.js" + ]; - $PLUGIN_HOOKS['add_css']['advancedplanning'] = [ - "$sc_lib/timeline/main.css", - "$sc_lib/resource-timeline/main.css" - ]; + $PLUGIN_HOOKS['add_css']['advancedplanning'] = [ + "$sc_lib/timeline/main.css", + "$sc_lib/resource-timeline/main.css" + ]; - $PLUGIN_HOOKS['planning_scheduler_key']['advancedplanning'] = function() { - return "GPL-My-Project-Is-Open-Source"; - }; - } + $PLUGIN_HOOKS['planning_scheduler_key']['advancedplanning'] = function () { + return "GPL-My-Project-Is-Open-Source"; + }; + } } @@ -87,18 +90,19 @@ function plugin_init_advancedplanning() { * * @return array */ -function plugin_version_advancedplanning() { - return [ - 'name' => 'advancedplanning', - 'version' => PLUGIN_ADVANCEDPLANNING_VERSION, - 'author' => 'Teclib\'', - 'license' => 'GPLV3', - 'homepage' => '', - 'requirements' => [ - 'glpi' => [ - 'min' => PLUGIN_ADVANCEDPLANNING_GLPIMIN, - 'max' => PLUGIN_ADVANCEDPLANNING_GLPIMAX, - ] - ] - ]; +function plugin_version_advancedplanning() +{ + return [ + 'name' => 'advancedplanning', + 'version' => PLUGIN_ADVANCEDPLANNING_VERSION, + 'author' => 'Teclib\'', + 'license' => 'GPLV3', + 'homepage' => '', + 'requirements' => [ + 'glpi' => [ + 'min' => PLUGIN_ADVANCEDPLANNING_GLPIMIN, + 'max' => PLUGIN_ADVANCEDPLANNING_GLPIMAX, + ] + ] + ]; }