diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 18ac248..0000000 --- a/.editorconfig +++ /dev/null @@ -1,22 +0,0 @@ -# EditorConfig is awesome: http://EditorConfig.org - -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -charset = utf-8 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true -indent_style = space -indent_size = 2 - -[*.php] -indent_size = 4 - -[*.md] -trim_trailing_whitespace = false - -[Makefile] -indent_style = tabs diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..1deac3a --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,19 @@ + + +| Questions | Answers +| ------------- | ------------------------------------------------------- +| Description? | Please be specific when describing the PR.
Every detail helps: versions, browser/server configuration, specific module/theme, etc. Feel free to add more information below this table. +| Type? | bug fix / improvement / new feature / refacto / critical +| BC breaks? | yes / no +| Deprecations? | yes / no +| Fixed ticket? | Fixes PrestaShop/Prestashop#{issue number here}. +| How to test? | Please indicate how to best verify that this PR is correct. + + diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e1818d4 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 + target-branch: dev +- package-ecosystem: composer + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 + target-branch: dev diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 2b5177c..7209621 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,16 +1,15 @@ +branches: + - master name-template: v$NEXT_PATCH_VERSION tag-template: v$NEXT_PATCH_VERSION categories: - - title: 🔨 Improvements + - title: 🚀 Improvements label: enhancement - title: 🐛 Bug Fixes label: bug - - title: 🚀 New Features - label: Feature change-template: '- #$NUMBER: $TITLE by @$AUTHOR' template: | # Changes $CHANGES - diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index ce9a82b..eec2d6d 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -1,61 +1,62 @@ -name: Build & Release draft - -on: - pull_request: - push: - branches: - - master +name: Build +on: [push, pull_request] jobs: - deploy: - name: build dependencies & create artifact - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2.0.0 - - name: Install composer dependencies - run: composer install --no-dev -o - - name: Clean-up project - uses: PrestaShopCorp/github-action-clean-before-deploy@v1.0 - - name: Create & upload artifact - uses: actions/upload-artifact@v1 - with: - name: ${{ github.event.repository.name }} - path: ../ - update_release_draft: - runs-on: ubuntu-latest - needs: [deploy] - if: github.event_name == 'push' - steps: - - name: Download artifact - uses: actions/download-artifact@v1 - with: - name: ${{ github.event.repository.name }} - - id: release_info - uses: toolmantim/release-drafter@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Prepare for Release - run: | - cd ${{ github.event.repository.name }} - zip -r ${{ github.event.repository.name }}.zip ${{ github.event.repository.name }} - - name: Clean existing assets - shell: bash - run: | - curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1 - assets=`bin/hub api -t repos/${{ github.repository }}/releases/${{ steps.release_info.outputs.id }}/assets | awk '/\].url/ { print $2 }'` - for asset in $assets - do - bin/hub api -X DELETE $asset - done - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Publish to GitHub Release - uses: actions/upload-release-asset@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.release_info.outputs.upload_url }} - asset_path: ./${{ github.event.repository.name }}/${{ github.event.repository.name }}.zip - asset_name: ${{ github.event.repository.name }}.zip - asset_content_type: application/zip + deploy: + name: build dependencies & create artifact + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2.0.0 + - name: Install composer dependencies + run: composer install --no-dev -o + - name: Clean-up project + uses: PrestaShopCorp/github-action-clean-before-deploy@v1.0 + - name: Prepare auto-index tool + run: | + composer global require prestashop/autoindex + - name: Generate index.php + run: | + ~/.composer/vendor/bin/autoindex + - name: Create & upload artifact + uses: actions/upload-artifact@v1 + with: + name: ${{ github.event.repository.name }} + path: ../ + update_release_draft: + runs-on: ubuntu-latest + needs: [deploy] + if: github.event_name == 'push' && github.event.ref == 'refs/heads/master' + steps: + - name: Download artifact + uses: actions/download-artifact@v1 + with: + name: ${{ github.event.repository.name }} + - id: release_info + uses: toolmantim/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare for Release + run: | + cd ${{ github.event.repository.name }} + zip -r ${{ github.event.repository.name }}.zip ${{ github.event.repository.name }} + - name: Clean existing assets + shell: bash + run: | + curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1 + assets=`bin/hub api -t repos/${{ github.repository }}/releases/${{ steps.release_info.outputs.id }}/assets | awk '/\].url/ { print $2 }'` + for asset in $assets + do + bin/hub api -X DELETE $asset + done + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish to GitHub Release + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.release_info.outputs.upload_url }} + asset_path: ./${{ github.event.repository.name }}/${{ github.event.repository.name }}.zip + asset_name: ${{ github.event.repository.name }}.zip + asset_content_type: application/zip diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f5dc3b6..a938b5c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,42 +1,81 @@ name: PHP tests on: [push, pull_request] jobs: + # Check there is no syntax errors in the project php-linter: - name: PHP Syntax check 5.6|7.2|7.3 + name: PHP Syntax check 5.6|7.2|7.3|7.4|8.0|8.1 runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2.0.0 + - name: PHP syntax checker 5.6 uses: prestashop/github-action-php-lint/5.6@master + - name: PHP syntax checker 7.2 uses: prestashop/github-action-php-lint/7.2@master + - name: PHP syntax checker 7.3 uses: prestashop/github-action-php-lint/7.3@master + + - name: PHP syntax checker 7.4 + uses: prestashop/github-action-php-lint/7.4@master + + - name: PHP syntax checker 8.0 + uses: prestashop/github-action-php-lint/8.0@master + + - name: PHP syntax checker 8.1 + uses: prestashop/github-action-php-lint/8.1@master + + # Check the PHP code follow the coding standards php-cs-fixer: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + - name: Checkout uses: actions/checkout@v2.0.0 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: vendor + key: php-${{ hashFiles('composer.lock') }} + + - name: Install dependencies + run: composer install + - name: Run PHP-CS-Fixer - uses: prestashopcorp/github-action-php-cs-fixer@master + run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no --diff-format udiff + + # Run PHPStan against the module and a PrestaShop release phpstan: name: PHPStan runs-on: ubuntu-latest strategy: matrix: - presta-versions: ['1.7.0.3', 'latest'] + presta-versions: ['1.7.6', '1.7.7', '1.7.8', 'latest'] steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + - name: Checkout uses: actions/checkout@v2.0.0 + # Add vendor folder in cache to make next builds faster - name: Cache vendor folder uses: actions/cache@v1 with: path: vendor key: php-${{ hashFiles('composer.lock') }} + # Add composer local folder in cache to make next builds faster - name: Cache composer folder uses: actions/cache@v1 with: @@ -45,8 +84,6 @@ jobs: - run: composer install - - name: Pull PrestaShop files (Tag ${{ matrix.presta-versions }}) - run: docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:${{ matrix.presta-versions }} - - - name : Run PHPStan - run: docker run --rm --volumes-from temp-ps -v $PWD:/web/module -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module phpstan/phpstan:0.12 analyse --configuration=/web/module/tests/phpstan/phpstan.neon + # Docker images prestashop/prestashop may be used, even if the shop remains uninstalled + - name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }}) + run: ./tests/phpstan.sh ${{ matrix.presta-versions }} diff --git a/composer.json b/composer.json index cb5516c..1e74686 100755 --- a/composer.json +++ b/composer.json @@ -35,4 +35,4 @@ "prestashop/php-dev-tools": "~3.0" }, "author": "PrestaShop" -} \ No newline at end of file +} diff --git a/tests/index.php b/tests/index.php new file mode 100755 index 0000000..ed971ff --- /dev/null +++ b/tests/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/tests/phpstan.sh b/tests/phpstan.sh new file mode 100755 index 0000000..42a9a26 --- /dev/null +++ b/tests/phpstan.sh @@ -0,0 +1,28 @@ +#!/bin/bash +PS_VERSION=$1 + +set -e + +# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled +echo "Pull PrestaShop files (Tag ${PS_VERSION})" + +docker rm -f temp-ps || true +docker volume rm -f ps-volume || true + +docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION + +# Clear previous instance of the module in the PrestaShop volume +echo "Clear previous module" + +docker exec -t temp-ps rm -rf /var/www/html/modules/ps_cashondelivery + +# Run a container for PHPStan, having access to the module content and PrestaShop sources. +# This tool is outside the composer.json because of the compatibility with PHP 5.6 +echo "Run PHPStan using phpstan-${PS_VERSION}.neon file" + +docker run --rm --volumes-from temp-ps \ + -v $PWD:/var/www/html/modules/ps_cashondelivery \ + -e _PS_ROOT_DIR_=/var/www/html \ + --workdir=/var/www/html/modules/ps_cashondelivery phpstan/phpstan:0.12 \ + analyse \ + --configuration=/var/www/html/modules/ps_cashondelivery/tests/phpstan/phpstan-$PS_VERSION.neon diff --git a/tests/phpstan/index.php b/tests/phpstan/index.php new file mode 100755 index 0000000..ed971ff --- /dev/null +++ b/tests/phpstan/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2015 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/tests/phpstan/phpstan-1.7.6.neon b/tests/phpstan/phpstan-1.7.6.neon new file mode 100644 index 0000000..39c6792 --- /dev/null +++ b/tests/phpstan/phpstan-1.7.6.neon @@ -0,0 +1,12 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Parameter \#1 \$id of class Customer constructor expects null, int given.#' + - '#Parameter \#9 \$secure_key of method PaymentModuleCore\:\:validateOrder\(\) expects bool, string given.#' + - '#Parameter \#4 \$ssl of method LinkCore\:\:getModuleLink\(\) expects null, true given.#' + - '#Parameter \#7 \$currency_special of method PaymentModuleCore\:\:validateOrder\(\) expects null, int given.#' + - '#Property OrderStateCore\:\:\$name \(string\) does not accept array.#' + - '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array given.#' + - '#Parameter \#1 \$id of class Currency constructor expects null, int given.#' diff --git a/tests/phpstan/phpstan-1.7.7.neon b/tests/phpstan/phpstan-1.7.7.neon new file mode 100644 index 0000000..f10cb0c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.7.neon @@ -0,0 +1,8 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Parameter \#9 \$secure_key of method PaymentModuleCore\:\:validateOrder\(\) expects bool, string given.#' + - '#Parameter \#7 \$currency_special of method PaymentModuleCore\:\:validateOrder\(\) expects null, int given.#' + - '#Property OrderStateCore\:\:\$name \(string\) does not accept array.#' diff --git a/tests/phpstan/phpstan-1.7.8.neon b/tests/phpstan/phpstan-1.7.8.neon new file mode 100644 index 0000000..6c76571 --- /dev/null +++ b/tests/phpstan/phpstan-1.7.8.neon @@ -0,0 +1,6 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Property OrderStateCore\:\:\$template \(array\) does not accept string.#' diff --git a/tests/phpstan/phpstan-latest.neon b/tests/phpstan/phpstan-latest.neon new file mode 100644 index 0000000..6c76571 --- /dev/null +++ b/tests/phpstan/phpstan-latest.neon @@ -0,0 +1,6 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Property OrderStateCore\:\:\$template \(array\) does not accept string.#' diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon index abbf5fd..084d1e2 100644 --- a/tests/phpstan/phpstan.neon +++ b/tests/phpstan/phpstan.neon @@ -2,28 +2,11 @@ includes: - %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon parameters: - paths: - # From PHPStan 0.12, paths to check are relative to the neon file - - ../../controllers - - ../../paymentexample.php - reportUnmatchedIgnoredErrors: false - ignoreErrors: - - '#Property ModuleCore::\$version \(float\) does not accept string.#' - - '#Parameter \#7 \$currency_special of method PaymentModuleCore::validateOrder\(\) expects null, int given.#' - - '#Parameter \#9 \$secure_key of method PaymentModuleCore::validateOrder\(\) expects bool, string given.#' - - '#Strict comparison using === between false and string will always evaluate to false.#' - - '#Strict comparison using === between false and true will always evaluate to false.#' - - '#Parameter \#1 \$id of class Customer constructor expects null, int given.#' - - '#Parameter \#1 \$hook_name of method ModuleCore::registerHook\(\) expects string, array given.#' - - '#Parameter \#6 \$idShop of method LinkCore::getModuleLink\(\) expects null, int given.#' - - '#Parameter \#1 \$id_hook of method ModuleCore::updatePosition\(\) expects bool, int given.#' - - '#Property TabCore::\$name \(string\) does not accept array.#' - - '#Access to an undefined property PaymentModule::\$currentOrderReference.#' - - '#Property CustomerCore::\$passwd \(int\) does not accept bool\|string.#' - - '#Parameter \#4 \$ssl of method LinkCore::getModuleLink\(\) expects null, true given.#' - - '#Parameter \#1 \$id of class Currency constructor expects null, int given.#' - - '#Property OrderStateCore::\$name \(string\) does not accept array.#' - - '#Parameter \#1 \$master of static method DbCore::getInstance\(\) expects bool, int given.#' - - '#Parameter \#2 \$currency of static method ToolsCore::displayPrice\(\) expects array\|object\|null, int given.#' - - level: 5 + paths: + # From PHPStan 0.12, paths to check are relative to the neon file + - ../../paymentexample.php + - ../../controllers/ + - ../../upgrade/ + ignoreErrors: + reportUnmatchedIgnoredErrors: false + level: 5 diff --git a/views/templates/hook/displayOrderConfirmation.tpl b/views/templates/hook/displayOrderConfirmation.tpl index 4731fb3..d3ea551 100644 --- a/views/templates/hook/displayOrderConfirmation.tpl +++ b/views/templates/hook/displayOrderConfirmation.tpl @@ -17,7 +17,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) *} -{if $transaction} +{if !empty($transaction)}

{l s='Your transaction reference is %transaction%.' mod='paymentexample' sprintf=['%transaction%' => $transaction]}

diff --git a/views/templates/hook/displayOrderDetail.tpl b/views/templates/hook/displayOrderDetail.tpl index a556606..a2f6377 100644 --- a/views/templates/hook/displayOrderDetail.tpl +++ b/views/templates/hook/displayOrderDetail.tpl @@ -17,7 +17,7 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) *} -{if $transaction} +{if !empty($transaction)}

{l s='Your transaction reference is %transaction%.' mod='paymentexample' sprintf=['%transaction%' => $transaction]}

diff --git a/views/templates/hook/displayPDFInvoice.tpl b/views/templates/hook/displayPDFInvoice.tpl index 5850772..1a82065 100644 --- a/views/templates/hook/displayPDFInvoice.tpl +++ b/views/templates/hook/displayPDFInvoice.tpl @@ -17,6 +17,6 @@ * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) *} -{if $transaction} +{if !empty($transaction)}

{l s='Your transaction reference is %transaction%.' mod='paymentexample' sprintf=['%transaction%' => $transaction]}

{/if} diff --git a/views/templates/hook/displayPaymentReturn.tpl b/views/templates/hook/displayPaymentReturn.tpl index 7f42472..f4efd36 100644 --- a/views/templates/hook/displayPaymentReturn.tpl +++ b/views/templates/hook/displayPaymentReturn.tpl @@ -18,7 +18,7 @@ *}
- {if $transaction} + {if !empty($transaction)}

{l s='Your transaction reference is %transaction%.' mod='paymentexample' sprintf=['%transaction%' => $transaction]}

{/if} {if $customer.is_logged && !$customer.is_guest}