From 3069f0f0ccf5c933d11b61e6064014be6a23abf6 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:07:36 +0100 Subject: [PATCH 01/15] phpcs, phpcompat github actions --- .github/workflows/phpcompatibility.yml | 9 +++++++++ .github/workflows/phpcs.yml | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 .github/workflows/phpcompatibility.yml create mode 100644 .github/workflows/phpcs.yml diff --git a/.github/workflows/phpcompatibility.yml b/.github/workflows/phpcompatibility.yml new file mode 100644 index 0000000..655d94c --- /dev/null +++ b/.github/workflows/phpcompatibility.yml @@ -0,0 +1,9 @@ +name: PHPCompatibility +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: 7.0-7.1 + run: docker run --rm -v $PWD:/code domw/phpcompatibility phpcs --standard=PHPCompatibility --runtime-set testVersion 7.0-7.1 --colors --ignore=./Test/ ./ diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 0000000..9787dcd --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,9 @@ +name: phpcs +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Magento 2 Ruleset + run: docker run --rm -v $PWD:/code domw/phpcs phpcs --colors --standard=Magento2 ./ From a8a06f673294af9a1a4985589846ee81a7ec112e Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:16:24 +0100 Subject: [PATCH 02/15] phpstan --- .github/workflows/phpstan.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/phpstan.yml diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..53d2946 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,15 @@ +name: PHPStan +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: MilesChou/composer-action@master + with: + args: config http-basic.repo.magento.com 7bdd660a63609d2af9fcbc033a9eae8d 77c0cedb4871620c63acbd82aeb92f38 + - uses: MilesChou/composer-action@master + with: + args: install --prefer-dist --no-dev --ignore-platform-reqs + - name: PHPStan + run: docker run --rm -v $PWD:/code domw/phpstan phpstan analyze ./ \ No newline at end of file From c05e05a82acf549c7c6532df8b4b4f425f5227a4 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:20:30 +0100 Subject: [PATCH 03/15] phpstan --- phpstan.neon | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index d2755cc..d94871d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,20 +1,10 @@ parameters: level: max - inferPrivatePropertyTypeFromConstructor: true - paths: - - . - bootstrapFiles: - - vendor/bitexpert/phpstan-magento/autoload.php excludes_analyse: - - %currentWorkingDirectory%/vendor/* + - 'vendor' ignoreErrors: - - '/ has no return typehint specified./' - - - message: '/Use service contracts to persist entities in favour of Magento\\Cron\\Model\\Schedule\:\:save\(\) method/' - path: Cron/ScheduleJob.php - - - message: '/Call to deprecated method save\(\) of class Magento\\Framework\\Model\\AbstractModel/' - path: Cron/ScheduleJob.php - - - message: '/Parameter \#1 \$autoload_function of function spl_autoload_register expects callable\(string\)\: void, array\(Magento\\Framework\\TestFramework\\Unit\\Autoloader\\GeneratedClassesAutoloader/' - path: Test/bootstrap.php + - '#has no return typehint specified#' + - '#Use service contracts to persist entities#' + - '#Call to deprecated method save#' + - '#Parameter \#1 \$autoload_function of function spl_autoload_register#' + reportUnmatchedIgnoredErrors: false \ No newline at end of file From 3e3fa34a58f644895a298c3613834bc79a808d16 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:25:18 +0100 Subject: [PATCH 04/15] phpstan --- .github/workflows/phpstan.yml | 2 +- phpstan.neon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 53d2946..784dece 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -10,6 +10,6 @@ jobs: args: config http-basic.repo.magento.com 7bdd660a63609d2af9fcbc033a9eae8d 77c0cedb4871620c63acbd82aeb92f38 - uses: MilesChou/composer-action@master with: - args: install --prefer-dist --no-dev --ignore-platform-reqs + args: install --prefer-dist --ignore-platform-reqs - name: PHPStan run: docker run --rm -v $PWD:/code domw/phpstan phpstan analyze ./ \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index d94871d..e57d7bb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,7 +3,7 @@ parameters: excludes_analyse: - 'vendor' ignoreErrors: - - '#has no return typehint specified#' + - '#typehint#' - '#Use service contracts to persist entities#' - '#Call to deprecated method save#' - '#Parameter \#1 \$autoload_function of function spl_autoload_register#' From a2df58311f2c09956f94751849b0d0a57bf66cbc Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:26:48 +0100 Subject: [PATCH 05/15] ignore factor classes --- phpstan.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon b/phpstan.neon index e57d7bb..75e69ef 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,6 +4,7 @@ parameters: - 'vendor' ignoreErrors: - '#typehint#' + - '#Factory#' - '#Use service contracts to persist entities#' - '#Call to deprecated method save#' - '#Parameter \#1 \$autoload_function of function spl_autoload_register#' From b56fe7623af4b4e017ed4977ac1742bb1d6e3f3a Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:32:38 +0100 Subject: [PATCH 06/15] PHP CS Fixer --- .github/workflows/phpcsfixer.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/phpcsfixer.yml diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml new file mode 100644 index 0000000..a228d9d --- /dev/null +++ b/.github/workflows/phpcsfixer.yml @@ -0,0 +1,9 @@ +name: php-cs-fixer +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: PHP CS Fixer + run: docker run --rm -v $PWD:/code domw/php-cs-fixer php-cs-fixer fix --dry-run --diff --stop-on-violation --allow-risky=yes ./ From 4c280f60f7fab99289e129c08efa29e25cf0c17c Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 21:38:58 +0100 Subject: [PATCH 07/15] XML linter --- .github/workflows/xmllint.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/xmllint.yml diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml new file mode 100644 index 0000000..6adeb82 --- /dev/null +++ b/.github/workflows/xmllint.yml @@ -0,0 +1,15 @@ +name: xmllint +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: MilesChou/composer-action@master + with: + args: config http-basic.repo.magento.com 7bdd660a63609d2af9fcbc033a9eae8d 77c0cedb4871620c63acbd82aeb92f38 + - uses: MilesChou/composer-action@master + with: + args: install --prefer-dist --ignore-platform-reqs + - name: XML Lint + run: docker run --rm -v $PWD:/code mribeiro/xmllint --schema vendor/magento/module-backend/etc/menu.xsd ./etc/adminhtml/menu.xml From 41d4012693470c63fc314b4d9df23b6772a9c7e8 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 22:17:31 +0100 Subject: [PATCH 08/15] XML lint --- .github/workflows/xmllint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml index 6adeb82..2046ea2 100644 --- a/.github/workflows/xmllint.yml +++ b/.github/workflows/xmllint.yml @@ -12,4 +12,5 @@ jobs: with: args: install --prefer-dist --ignore-platform-reqs - name: XML Lint - run: docker run --rm -v $PWD:/code mribeiro/xmllint --schema vendor/magento/module-backend/etc/menu.xsd ./etc/adminhtml/menu.xml + run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd + run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd From 12afbfcddf903bfbde582acdcbe8daeeed189529 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 22:20:33 +0100 Subject: [PATCH 09/15] Tweak syntax --- .github/workflows/xmllint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml index 2046ea2..d165517 100644 --- a/.github/workflows/xmllint.yml +++ b/.github/workflows/xmllint.yml @@ -12,5 +12,5 @@ jobs: with: args: install --prefer-dist --ignore-platform-reqs - name: XML Lint - run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd - run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd + - run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd + - run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd From be669b9dab1f9a5b37e2f4d38b5084024e6ba4d3 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 22:23:01 +0100 Subject: [PATCH 10/15] XML lint syntax --- .github/workflows/xmllint.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml index d165517..575ec6e 100644 --- a/.github/workflows/xmllint.yml +++ b/.github/workflows/xmllint.yml @@ -12,5 +12,6 @@ jobs: with: args: install --prefer-dist --ignore-platform-reqs - name: XML Lint - - run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd - - run: docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd + run: | + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd From 75547e8b6c5effc123bc9b27434d9a8b48091520 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 22:27:13 +0100 Subject: [PATCH 11/15] Validating other XML files --- .github/workflows/xmllint.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml index 575ec6e..51af8e4 100644 --- a/.github/workflows/xmllint.yml +++ b/.github/workflows/xmllint.yml @@ -15,3 +15,7 @@ jobs: run: | docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/acl.xml --schema ./vendor/magento/framework/Acl/etc/acl.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/cron_groups.xml --schema ./vendor/magento/module-cron/etc/cron_groups.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/crontab.xml --schema ./vendor/magento/module-cron/etc/crontab.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/module.xml --schema ./vendor/magento/framework/Module/etc/module.xsd From 231691f8a38264c3a784b02057d0b0ce0762b220 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Fri, 20 Aug 2021 22:53:29 +0100 Subject: [PATCH 12/15] PHPUnit --- .github/workflows/phpunit.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/phpunit.yml diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 0000000..d771277 --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,15 @@ +name: PHPUnit +on: ["push", "pull_request"] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: MilesChou/composer-action@master + with: + args: config http-basic.repo.magento.com 7bdd660a63609d2af9fcbc033a9eae8d 77c0cedb4871620c63acbd82aeb92f38 + - uses: MilesChou/composer-action@master + with: + args: install --prefer-dist --ignore-platform-reqs + - name: PHPUnit + run: vendor/bin/phpunit -c Test/phpunit.xml Test/ From 063f33933014682d05943beea4109ba2a1c922d2 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Sat, 21 Aug 2021 01:09:42 +0100 Subject: [PATCH 13/15] Make json path configurable --- Makefile | 2 ++ Storage/FileStorage.php | 21 ++++++++++++++++++--- etc/acl.xml | 7 +++++++ etc/adminhtml/system.xml | 20 ++++++++++++++++++++ etc/config.xml | 10 ++++++++++ 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 etc/adminhtml/system.xml create mode 100644 etc/config.xml diff --git a/Makefile b/Makefile index a8140fe..9d42d20 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,10 @@ checkstyle: checkquality: vendor/bin/phpstan analyse + xmllint --noout --schema ./vendor/magento/module-store/etc/config.xsd etc/config.xml xmllint --noout --schema vendor/magento/module-backend/etc/menu.xsd etc/adminhtml/menu.xml xmllint --noout --schema vendor/magento/framework/App/etc/routes.xsd etc/adminhtml/routes.xml + xmllint --noout --schema vendor/magento/module-config/etc/system.xsd etc/adminhtml/system.xml xmllint --noout --schema vendor/magento/framework/Acl/etc/acl.xsd etc/acl.xml xmllint --noout --schema vendor/magento/module-cron/etc/cron_groups.xsd etc/cron_groups.xml xmllint --noout --schema vendor/magento/module-cron/etc/crontab.xsd etc/crontab.xml diff --git a/Storage/FileStorage.php b/Storage/FileStorage.php index fd62678..9650d0f 100644 --- a/Storage/FileStorage.php +++ b/Storage/FileStorage.php @@ -5,23 +5,30 @@ namespace Baldwin\UrlDataIntegrityChecker\Storage; use Baldwin\UrlDataIntegrityChecker\Exception\SerializationException; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem; class FileStorage extends AbstractStorage implements StorageInterface { + const CONFIG_PATH = 'url/checker/path'; + private $filesystem; + private $scopeConfig; public function __construct( - Filesystem $filesystem + Filesystem $filesystem, + ScopeConfigInterface $scopeConfig ) { $this->filesystem = $filesystem; + $this->scopeConfig = $scopeConfig; } public function write(string $identifier, array $data): bool { - $directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP); + $directory = $this->filesystem->getDirectoryWrite($this->getPath() ?: DirectoryList::TMP); $directory->create(); $filename = $this->getFilename($identifier); @@ -39,7 +46,7 @@ public function write(string $identifier, array $data): bool public function read(string $identifier): array { - $directory = $this->filesystem->getDirectoryRead(DirectoryList::TMP); + $directory = $this->filesystem->getDirectoryRead($this->getPath() ?: DirectoryList::TMP); $filename = $this->getFilename($identifier); $data = ''; @@ -57,4 +64,12 @@ private function getFilename(string $identifier): string { return 'baldwin-url-data-integrity-checker-' . $identifier . '.json'; } + + private function getPath(): string + { + return $this->scopeConfig->getValue( + self::CONFIG_PATH, + ScopeInterface::SCOPE_STORE + ); + } } diff --git a/etc/acl.xml b/etc/acl.xml index 7359fe4..55694a1 100644 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -6,6 +6,13 @@ + + + + + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..abdac4b --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,20 @@ + + + + + + +
+ + baldwin + Baldwin_UrlDataIntegrityChecker::config_baldwin_urldataintegritychecker + + + + + Path where to store json files eg tmp or media + + +
+
+
\ No newline at end of file diff --git a/etc/config.xml b/etc/config.xml new file mode 100644 index 0000000..96629ec --- /dev/null +++ b/etc/config.xml @@ -0,0 +1,10 @@ + + + + + + tmp + + + + \ No newline at end of file From 07416d15ca621df52ed5748d6318a6cc559f6f36 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Sat, 21 Aug 2021 01:12:28 +0100 Subject: [PATCH 14/15] Test additional xml --- .github/workflows/xmllint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml index 51af8e4..114a85e 100644 --- a/.github/workflows/xmllint.yml +++ b/.github/workflows/xmllint.yml @@ -13,8 +13,10 @@ jobs: args: install --prefer-dist --ignore-platform-reqs - name: XML Lint run: | + docker run --rm -v $PWD:/code domw/xmllint --noout ./config.xml --schema ./vendor/magento/module-store/etc/config.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/system.xml --schema vendor/magento/module-config/etc/system.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/acl.xml --schema ./vendor/magento/framework/Acl/etc/acl.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/cron_groups.xml --schema ./vendor/magento/module-cron/etc/cron_groups.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/crontab.xml --schema ./vendor/magento/module-cron/etc/crontab.xsd From 6b12032691da118644e8d1a1353194987b72d597 Mon Sep 17 00:00:00 2001 From: Dominic Watts Date: Sat, 21 Aug 2021 01:17:08 +0100 Subject: [PATCH 15/15] Fix xml paths --- .github/workflows/xmllint.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/xmllint.yml b/.github/workflows/xmllint.yml index 114a85e..09f192b 100644 --- a/.github/workflows/xmllint.yml +++ b/.github/workflows/xmllint.yml @@ -13,7 +13,7 @@ jobs: args: install --prefer-dist --ignore-platform-reqs - name: XML Lint run: | - docker run --rm -v $PWD:/code domw/xmllint --noout ./config.xml --schema ./vendor/magento/module-store/etc/config.xsd + docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/config.xml --schema ./vendor/magento/module-store/etc/config.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/menu.xml --schema ./vendor/magento/module-backend/etc/menu.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/routes.xml --schema ./vendor/magento/framework/App/etc/routes.xsd docker run --rm -v $PWD:/code domw/xmllint --noout ./etc/adminhtml/system.xml --schema vendor/magento/module-config/etc/system.xsd diff --git a/Makefile b/Makefile index 9d42d20..ad3d293 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ checkstyle: checkquality: vendor/bin/phpstan analyse - xmllint --noout --schema ./vendor/magento/module-store/etc/config.xsd etc/config.xml + xmllint --noout --schema vendor/magento/module-store/etc/config.xsd etc/config.xml xmllint --noout --schema vendor/magento/module-backend/etc/menu.xsd etc/adminhtml/menu.xml xmllint --noout --schema vendor/magento/framework/App/etc/routes.xsd etc/adminhtml/routes.xml xmllint --noout --schema vendor/magento/module-config/etc/system.xsd etc/adminhtml/system.xml