From bfb4f97b8d7a618dbff5fcd66147e9f08490e3a2 Mon Sep 17 00:00:00 2001 From: zonky Date: Wed, 26 Jul 2023 18:52:46 +0200 Subject: [PATCH] Add old PR and delete DCI --- .composer-require-checker.json | 10 ++ .github/workflows/diagnostics.yml | 72 ++++++++---- .phpcq.lock | 1 + .phpcq.yaml.dist | 106 ++++++++++++++++++ .phpmd.xml | 37 ++++++ build.xml | 12 -- composer.json | 30 +++-- phpunit.xml.dist | 27 +++++ psalm.xml | 12 ++ src/Contao/Widget/FormMultiColumnWizard.php | 28 +++-- .../MultiColumnWizardFrontendExtension.php | 80 ------------- src/MultiColumnWizardFrontendBundle.php | 25 +---- 12 files changed, 280 insertions(+), 160 deletions(-) create mode 100644 .composer-require-checker.json create mode 100644 .phpcq.lock create mode 100644 .phpcq.yaml.dist create mode 100644 .phpmd.xml delete mode 100644 build.xml create mode 100644 phpunit.xml.dist create mode 100644 psalm.xml delete mode 100644 src/DependencyInjection/MultiColumnWizardFrontendExtension.php diff --git a/.composer-require-checker.json b/.composer-require-checker.json new file mode 100644 index 0000000..4887b86 --- /dev/null +++ b/.composer-require-checker.json @@ -0,0 +1,10 @@ +{ + "symbol-whitelist": [ + "array", "bool", "false", "int", "null", "self", "static", "parent", "string", "true", "void", + "ampersand", "array_insert", "array_is_assoc", "nl2br_html5", "TL_ERROR", + "Contao\\ManagerBundle\\ContaoManagerBundle", + "Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface", + "Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig", + "Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface" + ] +} diff --git a/.github/workflows/diagnostics.yml b/.github/workflows/diagnostics.yml index 0a599e6..bddb943 100644 --- a/.github/workflows/diagnostics.yml +++ b/.github/workflows/diagnostics.yml @@ -1,49 +1,75 @@ -name: DC General +name: Code Quality Diagnostics on: - push: pull_request: + push: + branches: jobs: build: runs-on: ubuntu-latest + name: 'PHP: ${{ matrix.php }} Contao: ${{ matrix.contao }}' strategy: + fail-fast: false matrix: - php: [7.4] - contao: [~4.9.0] + php: [ '8.1', '8.2' ] + contao: [ '~4.13.0' ] + phpcq_install: [ 'update' ] + output: [ '-o github-action -o default' ] steps: - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Pull source - uses: actions/checkout@v2 - with: - fetch-depth: 0 + - name: Pull source + uses: actions/checkout@v3 - # see https://github.com/shivammathur/setup-php - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Setup PHP. + - name: Setup PHP with PECL extension uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - coverage: none - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache composer cache directory - uses: actions/cache@v1 + # setup caches + - name: Cache composer cache directory + uses: actions/cache@v3 env: cache-name: composer-cache-dir with: path: ~/.cache/composer - key: ${{ runner.os }}-build-${{ env.cache-name }} + key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }} - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Cache vendor directory - uses: actions/cache@v1 + - name: Cache vendor directory + uses: actions/cache@v3 env: - cache-name: composer-vendor + cache-name: vendor with: path: vendor - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}- + + - name: Cache phpcq directory + uses: actions/cache@v3 + env: + cache-name: phpcq + with: + path: .phpcq + key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}-${{ hashFiles('**/.phpcq.lock') }} restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Install composer dependencies - run: composer update --prefer-dist --no-interaction --no-suggest + ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}- + + # install dependencies and tools + - name: Install composer dependencies + run: | + composer require contao/core-bundle ${{ matrix.contao }} --no-update + composer install + - name: Install phpcq toolchain + run: ./vendor/bin/phpcq ${{ matrix.phpcq_install }} -v - - name: PHP ${{ matrix.php }} ${{ matrix.contao }} Run tests - run: ant -keep-going + # run tests + - name: Run tests + run: ./vendor/bin/phpcq run -v ${{ matrix.output }} + + - name: Upload build directory to artifact + uses: actions/upload-artifact@v3 + if: ${{ success() }} || ${{ failure() }} + with: + name: phpcq-builds-php-${{ matrix.php }}-${{ matrix.contao }} + path: .phpcq/build/ diff --git a/.phpcq.lock b/.phpcq.lock new file mode 100644 index 0000000..21bdc05 --- /dev/null +++ b/.phpcq.lock @@ -0,0 +1 @@ +{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.5.26","url":"https://phar.phpunit.de/phpunit-9.5.26.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"e36595f47bb81f244e03fc437328cfaa123e99ffd183c3217235926ff0978397"},"signature":"https://phar.phpunit.de/phpunit-9.5.26.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/psalm-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"4.29.0","url":"https://github.com/vimeo/psalm/releases/download/4.29.0/psalm.phar","requirements":{"php":{"php":"^7.1|^8","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/4.29.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"3.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar","requirements":{"php":{"php":"^7.4 || ^8.0","ext-json":"*","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/3.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.13.0","url":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.13.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.7.1","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcs.phar.asc"},"phpcbf":{"version":"3.7.1","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.1/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.28.3","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.28.3/composer-normalize.phar","requirements":{"php":{"php":"^7.4 || ^8.0"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.28.3/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/.phpcq.yaml.dist b/.phpcq.yaml.dist new file mode 100644 index 0000000..ed969b0 --- /dev/null +++ b/.phpcq.yaml.dist @@ -0,0 +1,106 @@ +phpcq: + repositories: + - https://phpcq.github.io/repository/repository.json + directories: + - src + - tests + artifact: .phpcq/build + + plugins: + phpunit: + version: ^1.0 + signed: false + psalm: + version: ^1.1 + signed: false + composer-require-checker: + version: ^1.0 + signed: false + requirements: + composer-require-checker: + signed: false + version: ^3.3 + phpmd: + version: ^1.0 + signed: false + requirements: + phpmd: + signed: false + phpcpd: + version: ^1.0 + signed: false + requirements: + phpcpd: + version: ^6.0 + phploc: + version: ^1.0 + signed: false + phpcs: + version: ^1.0 + signed: false + composer-normalize: + version: ^1.0 + signed: false + trusted-keys: + # sb@sebastian-bergmann.de + - 4AA394086372C20A + # psalm + - 8A03EA3B385DBAA1 + - 12CE0F1D262429A5 + # magl@magll.net + - D2CCAC42F6295E7D + # PHP_CodeSniffer + - 31C7E470E2138192 + # Composer normalize + - C00543248C87FB13 + # phpmd + - 0F9684B8B16B7AB0 + - A4E55EA12C7C085C + # composer-require-checker + - 033E5F8D801A2F8D + +tasks: + fix: + - composer-normalize-fix + - phpcbf + verify: + - composer-require-checker + - composer-normalize + analyze: + - phploc + - phpcpd + - phpmd + - phpcs + - psalm + - phpunit + default: + - verify + - analyze + + phpmd: + plugin: phpmd + config: + ruleset: + - ./.phpmd.xml + + composer-normalize-fix: + plugin: composer-normalize + config: + dry_run: false + + composer-require-checker: + plugin: composer-require-checker + config: + config_file: '.composer-require-checker.json' + + phpcs: + plugin: phpcs + config: &phpcs-config + standard: PSR12 + custom_flags: + - '--extensions=php' + + phpcbf: + plugin: phpcs + config: + <<: *phpcs-config diff --git a/.phpmd.xml b/.phpmd.xml new file mode 100644 index 0000000..70c17ee --- /dev/null +++ b/.phpmd.xml @@ -0,0 +1,37 @@ + + + + PHPMD rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.xml b/build.xml deleted file mode 100644 index b059102..0000000 --- a/build.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/composer.json b/composer.json index 5fc5bcd..48adf3b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "name": "contao-community-alliance/contao-multicolumnwizard-frontend-bundle", - "type": "contao-bundle", "description": "Frontend support for the MultiColumnWizard", + "license": "LGPL-3.0-or-later", + "type": "contao-bundle", "keywords": [ "contao", "multicolumnwizard", @@ -11,8 +12,6 @@ "metamodels", "cca" ], - "homepage": "https://c-c-a.org/", - "license": "LGPL-3.0-or-later", "authors": [ { "name": "Richard Henkenjohann", @@ -20,18 +19,23 @@ "role": "Developer" } ], + "homepage": "https://c-c-a.org/", "support": { "issues": "https://github.com/contao-community-alliance/contao-multicolumnwizard-frontend/issues", "source": "https://github.com/contao-community-alliance/contao-multicolumnwizard-frontend" }, "require": { - "php": "^7.4 || ^8.0", - "contao/core-bundle": "^4.13.0, <5.0", - "menatwork/contao-multicolumnwizard-bundle": "^3.4.7" + "php": "^8.1", + "ext-json": "*", + "contao/core-bundle": "^4.13.0 <5.0", + "menatwork/contao-multicolumnwizard-bundle": "^3.4.7", + "symfony/http-foundation": "^5.4", + "symfony/http-kernel": "^5.4" }, "require-dev": { - "phpcq/all-tasks": "~1.2", - "contao/manager-bundle": "^4.13.0, <5.0" + "contao/manager-bundle": "^4.13.0 <5.0", + "phpcq/runner-bootstrap": "^1.0@dev", + "roave/security-advisories": "dev-latest" }, "autoload": { "psr-4": { @@ -43,10 +47,16 @@ "ContaoCommunityAlliance\\MultiColumnWizardFrontendBundle\\Test\\": "tests/" } }, + "config": { + "allow-plugins": { + "contao-components/installer": false, + "contao/manager-plugin": true + } + }, "extra": { - "contao-manager-plugin": "ContaoCommunityAlliance\\MultiColumnWizardFrontendBundle\\ContaoManager\\Plugin", "branch-alias": { "dev-feature/2.3.0": "2.3.x-dev" - } + }, + "contao-manager-plugin": "ContaoCommunityAlliance\\MultiColumnWizardFrontendBundle\\ContaoManager\\Plugin" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3a8d53a --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,27 @@ + + + + + + + ./tests/ + + + + + + ./src/ + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..ceb6754 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/src/Contao/Widget/FormMultiColumnWizard.php b/src/Contao/Widget/FormMultiColumnWizard.php index 0fb0ba0..083a680 100644 --- a/src/Contao/Widget/FormMultiColumnWizard.php +++ b/src/Contao/Widget/FormMultiColumnWizard.php @@ -3,7 +3,7 @@ /** * This file is part of contao-community-alliance/contao-multicolumnwizard-frontend-bundle. * - * (c) 2020 - 2022 Contao Community Alliance. + * (c) 2020-2023 Contao Community Alliance. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Richard Henkenjohann * @author Stefan Heimes * @author Ingolf Steinhardt - * @copyright 2020 - 2022 Contao Community Alliance. + * @copyright 2020-2023 Contao Community Alliance. * @license https://github.com/contao-community-alliance/contao-multicolumnwizard-frontend-bundle/blob/master/LICENSE * LGPL-3.0-or-later * @filesource @@ -25,6 +25,7 @@ use Contao\Controller; use Contao\CoreBundle\Exception\ResponseException; use Contao\Input; +use Contao\Widget; use MenAtWork\MultiColumnWizardBundle\Contao\Widgets\MultiColumnWizard; use Symfony\Component\HttpFoundation\Response; @@ -36,6 +37,7 @@ class FormMultiColumnWizard extends MultiColumnWizard * @param array|null $arrAttributes * * @noinspection PhpMissingParentConstructorInspection + * @SuppressWarnings(PHPMD.Superglobals) */ public function __construct($arrAttributes = null) { @@ -59,7 +61,7 @@ public function __construct($arrAttributes = null) * * @return Response */ - protected function convertToResponse($str) + protected function convertToResponse(string $str): Response { return new Response(Controller::replaceOldBePaths($str)); } @@ -67,14 +69,14 @@ protected function convertToResponse($str) /** * @inheritdoc */ - public function generate($overwriteRowCurrRow = null, $onlyRows = false) + public function generate($overwriteRowCurrRow = null, $onlyRows = false): string { // 'action=mcwCreateNewRow&name=' + fieldName + '&maxRowId=' + maxRowId; $action = Input::post('action'); $name = Input::post('name'); $maxRowCount = Input::post('maxRowId'); - if ('mcwCreateNewRow' == $action && $name == $this->strName) { + if ('mcwCreateNewRow' === $action && $name === $this->strName) { // Rewrite the values. $newRowCount = ($maxRowCount + 1); foreach (\array_keys($this->columnFields) as $strKey) { @@ -92,10 +94,10 @@ public function generate($overwriteRowCurrRow = null, $onlyRows = false) /** * @inheritdoc */ - protected function initializeWidget(&$arrField, $intRow, $strKey, $varValue) + protected function initializeWidget(&$arrField, $intRow, $strKey, $varValue): ?Widget { - // If null replace it with an empty string. - if ($varValue == '' && isset($arrField['default']) && $arrField['default'] == null) { + // If null, replace it with an empty string. + if ($varValue === '' && isset($arrField['default']) && $arrField['default'] === null) { $arrField['default'] = ''; } @@ -104,8 +106,10 @@ protected function initializeWidget(&$arrField, $intRow, $strKey, $varValue) /** * @inheritDoc + * + * @throws \JsonException */ - protected function generateScriptBlock($strId, $maxCount, $minCount) + protected function generateScriptBlock($strId, $maxCount, $minCount): string { $script = <<