From b4a11e39ecae71cea1084336c8c97aaff3b4e795 Mon Sep 17 00:00:00 2001 From: Al3x Zamponi <562324+alexz707@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:11:54 +0100 Subject: [PATCH] update php and pimcore, fix deprecations (#51) * update php and pimcore, fix deprecations * Apply php-cs-fixer changes * update php and pimcore, fix deprecations --- .github/workflows/cla.yml | 1 - .github/workflows/codeception.yml | 138 +++++++++++++---------- .github/workflows/static-analysis.yml | 125 ++++++++++++-------- composer.json | 6 +- src/Api/Api.php | 2 +- src/Code/CodeCollector.php | 2 +- src/Config/ConfigProvider.php | 2 +- src/Config/SiteConfigProvider.php | 6 +- src/Controller/ReportsControllerBase.php | 2 +- src/Controller/SettingsController.php | 2 +- src/CustomReport/Adapter/Analytics.php | 4 +- src/SiteId/SiteId.php | 2 +- src/SiteId/SiteIdProvider.php | 2 +- src/Tracker/AbstractTracker.php | 4 +- src/Tracker/Tracker.php | 6 +- src/Tracker/TrackerInterface.php | 4 +- 16 files changed, 176 insertions(+), 132 deletions(-) diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml index 8da561e..2c7cc9d 100644 --- a/.github/workflows/cla.yml +++ b/.github/workflows/cla.yml @@ -12,4 +12,3 @@ jobs: if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' secrets: CLA_ACTION_ACCESS_TOKEN: ${{ secrets.CLA_ACTION_ACCESS_TOKEN }} - diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index 235bc22..a8e3c00 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -1,78 +1,94 @@ -name: "Codeception Tests" +name: "Codeception Tests centralised" on: schedule: - - cron: '0 3 * * 1,3,5' - pull_request: - branches: - - "[0-9]+.[0-9]+" - - "[0-9]+.x" + - cron: '0 3 * * 1,3,5' + workflow_dispatch: push: branches: - "[0-9]+.[0-9]+" - "[0-9]+.x" - - "*_actions" + - "feature-*" + pull_request: + types: [opened, synchronize, reopened] env: PIMCORE_PROJECT_ROOT: ${{ github.workspace }} - APP_ENV: test - PIMCORE_TEST: 1 - PIMCORE_TEST_DB_DSN: "mysql://root@127.0.0.1:33006/pimcore_test" + PRIVATE_REPO: ${{ github.event.repository.private }} jobs: - codeception-tests: - name: "Codeception tests" - runs-on: "ubuntu-20.04" - continue-on-error: ${{ matrix.experimental }} - env: - PIMCORE_TEST_DB_DSN: "mysql://root@127.0.0.1:33006/pimcore_test" - strategy: - matrix: - include: - - { php-version: 8.1, database: "mariadb:10.3", dependencies: lowest, pimcore_version: "", experimental: false } - - { php-version: 8.2, database: "mariadb:10.11", dependencies: highest, pimcore_version: "", experimental: false } - - { php-version: 8.3, database: "mariadb:10.11", dependencies: highest, pimcore_version: "11.x-dev as 11.0.0", experimental: true } - services: - mariadb: - image: "${{ matrix.database }}" - ports: - - 33006:3306 - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - + setup-matrix: + runs-on: ubuntu-latest + outputs: + php_versions: ${{ steps.parse-php-versions.outputs.php_versions }} + matrix: ${{ steps.set-matrix.outputs.matrix }} + private_repo: ${{ env.PRIVATE_REPO }} steps: - - name: "Checkout code" - uses: "actions/checkout@v2" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - extensions: imagick - ini-values: display_errors=On, display_startup_errors=On, error_reporting=32767 - php-version: "${{ matrix.php-version }}" + - name: Checkout reusable workflow repo + uses: actions/checkout@v4 + with: + repository: pimcore/workflows-collection-public + ref: main + path: reusable-workflows - - name: Verify MariaDB connection - run: | - cp .github/ci/files/.my.cnf ~/.my.cnf - while ! mysqladmin ping --silent; do - sleep 1 - done - - name: "Setup Pimcore environment" - run: | - mysql -e "CREATE DATABASE pimcore_test CHARSET=utf8mb4;" - .github/ci/scripts/setup-pimcore-environment.sh - - name: "Update Pimcore version" - env: - PIMCORE_VERSION: "${{ matrix.pimcore_version }}" - run: | - if [ ! -z "$PIMCORE_VERSION" ]; then - composer require --no-update pimcore/pimcore:"${PIMCORE_VERSION}" + - name: Parse PHP versions from composer.json + id: parse-php-versions + run: | + if [ -f composer.json ]; then + php_versions=$(jq -r '.require.php' composer.json | grep -oP '\d+\.\d+' | tr '\n' ',' | sed 's/,$//') + if [ -z "$php_versions" ]; then + echo "No PHP versions found in composer.json" + echo "Setting default PHP value" + echo "php_versions=default" >> $GITHUB_OUTPUT + else + echo "php_versions=$php_versions" >> $GITHUB_OUTPUT + echo "#### php versions #### : $php_versions" fi - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" - with: - dependency-versions: "${{ matrix.dependencies }}" + else + echo "composer.json not found" + exit 1 + fi + + - name: Set up matrix + id: set-matrix + run: | + php_versions="${{ steps.parse-php-versions.outputs.php_versions }}" + + MATRIX_JSON=$(cat reusable-workflows/codeception-tests-configuration/matrix-config.json) + + IFS=',' read -ra VERSIONS_ARRAY <<< "$php_versions" + + FILTERED_MATRIX_JSON=$(echo $MATRIX_JSON | jq --arg php_versions "$php_versions" ' + { + matrix: [ + .configs[] | + select(.php_version == $php_versions) | + .matrix[] + ] + }') + + ENCODED_MATRIX_JSON=$(echo $FILTERED_MATRIX_JSON | jq -c .) + + echo "matrix=${ENCODED_MATRIX_JSON}" >> $GITHUB_OUTPUT - - name: "Run Codeception" - run: "vendor/bin/codecept run -c . -vvv --xml" + codeception-tests: + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + uses: pimcore/workflows-collection-public/.github/workflows/reusable-codeception-tests-centralized.yaml@main + with: + APP_ENV: test + PIMCORE_TEST: 1 + PRIVATE_REPO: ${{ needs.setup-matrix.outputs.private_repo}} + PHP_VERSION: ${{ matrix.matrix.php-version }} + DATABASE: ${{ matrix.matrix.database }} + SERVER_VERSION: ${{ matrix.matrix.server_version }} + DEPENDENCIES: ${{ matrix.matrix.dependencies }} + EXPERIMENTAL: ${{ matrix.matrix.experimental }} + PIMCORE_VERSION: ${{ matrix.matrix.pimcore_version }} + secrets: + SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER: ${{ secrets.SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER }} + COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN: ${{ secrets.COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index bea6a7c..cc70aac 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,66 +1,95 @@ -name: "Static Analysis" +name: "Static analysis centralised" on: schedule: - cron: '0 3 * * 1,3,5' - pull_request: - branches: - - "[0-9]+.[0-9]+" - - "[0-9]+.x" - paths-ignore: - - 'doc/**' - - 'src/Resources/public/**' + workflow_dispatch: push: branches: - "[0-9]+.[0-9]+" - "[0-9]+.x" - - "*_actions" + - "feature-*" + pull_request: + types: [ opened, synchronize, reopened ] + + +env: + PIMCORE_PROJECT_ROOT: ${{ github.workspace }} + PRIVATE_REPO: ${{ github.event.repository.private }} jobs: - static-analysis-phpstan: - name: "Static Analysis with PHPStan" - runs-on: "ubuntu-20.04" - strategy: - matrix: - include: - - { php-version: "8.1", dependencies: "lowest", experimental: false } - - { php-version: "8.2", dependencies: "highest", experimental: false } - - { php-version: "8.3", dependencies: "highest", pimcore_version: "11.x-dev as 11.0.0", experimental: true } + setup-matrix: + runs-on: ubuntu-latest + outputs: + php_versions: ${{ steps.parse-php-versions.outputs.php_versions }} + matrix: ${{ steps.set-matrix.outputs.matrix }} + private_repo: ${{ env.PRIVATE_REPO }} steps: - - name: "Checkout code" - uses: "actions/checkout@v2" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - name: Checkout reusable workflow repo + uses: actions/checkout@v4 with: - coverage: "none" - php-version: "${{ matrix.php-version }}" + repository: pimcore/workflows-collection-public + ref: main + path: reusable-workflows - - name: "Setup Pimcore environment" - run: | - .github/ci/scripts/setup-pimcore-environment.sh - - name: "Update Pimcore version" - env: - PIMCORE_VERSION: "${{ matrix.pimcore_version }}" + - name: Parse PHP versions from composer.json + id: parse-php-versions run: | - if [ ! -z "$PIMCORE_VERSION" ]; then - composer require --no-update pimcore/pimcore:"${PIMCORE_VERSION}" + if [ -f composer.json ]; then + php_versions=$(jq -r '.require.php' composer.json | grep -oP '\d+\.\d+' | tr '\n' ',' | sed 's/,$//') + if [ -z "$php_versions" ]; then + echo "No PHP versions found in composer.json" + echo "Setting default PHP value" + echo "php_versions=default" >> $GITHUB_OUTPUT + else + echo "php_versions=$php_versions" >> $GITHUB_OUTPUT + echo "#### php versions #### : $php_versions" + fi + else + echo "composer.json not found" + exit 1 fi - - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" - with: - dependency-versions: "${{ matrix.dependencies }}" - - - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan analyse --memory-limit=-1" - - name: "Generate baseline file" - if: ${{ failure() }} - run: "vendor/bin/phpstan analyse --memory-limit=-1 --generate-baseline" + - name: Set up matrix + id: set-matrix + run: | + php_versions="${{ steps.parse-php-versions.outputs.php_versions }}" + + MATRIX_JSON=$(cat reusable-workflows/phpstan-configuration/matrix-config.json) + + IFS=',' read -ra VERSIONS_ARRAY <<< "$php_versions" + + FILTERED_MATRIX_JSON=$(echo $MATRIX_JSON | jq --arg php_versions "$php_versions" ' + { + matrix: [ + .configs[] | + select(.php_version == $php_versions) | + .matrix[] + ] + }') + + ENCODED_MATRIX_JSON=$(echo $FILTERED_MATRIX_JSON | jq -c .) + + echo "matrix=${ENCODED_MATRIX_JSON}" >> $GITHUB_OUTPUT - - name: "Upload baseline file" - if: ${{ failure() }} - uses: actions/upload-artifact@v2 - with: - name: phpstan-baseline.neon - path: phpstan-baseline.neon + static-analysis: + needs: setup-matrix + strategy: + matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }} + uses: pimcore/workflows-collection-public/.github/workflows/reusable-static-analysis-centralized.yaml@main + with: + APP_ENV: test + PIMCORE_TEST: 1 + PRIVATE_REPO: ${{ needs.setup-matrix.outputs.private_repo}} + PHP_VERSION: ${{ matrix.matrix.php-version }} + SYMFONY: ${{ matrix.matrix.symfony }} + DEPENDENCIES: ${{ matrix.matrix.dependencies }} + EXPERIMENTAL: ${{ matrix.matrix.experimental }} + PIMCORE_VERSION: ${{ matrix.matrix.pimcore_version }} + COMPOSER_OPTIONS: ${{ matrix.matrix.composer_options }} + secrets: + SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER: ${{ secrets.SSH_PRIVATE_KEY_PIMCORE_DEPLOYMENTS_USER }} + COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN: ${{ secrets.COMPOSER_PIMCORE_REPO_PACKAGIST_TOKEN }} \ No newline at end of file diff --git a/composer.json b/composer.json index c7076e5..23c9572 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ } }, "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "pimcore/pimcore": "^11.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", + "pimcore/pimcore": "^11.0 || 12.x-dev", "google/apiclient": "^2.12" }, "require-dev": { - "phpstan/phpstan": "1.10.5", + "phpstan/phpstan": "1.12.15", "phpstan/phpstan-symfony": "^1.2.20", "phpunit/phpunit": "^9.3", "codeception/codeception": "^5.0.10", diff --git a/src/Api/Api.php b/src/Api/Api.php index 8be7a91..a916935 100644 --- a/src/Api/Api.php +++ b/src/Api/Api.php @@ -83,7 +83,7 @@ public static function getClient(string $type = 'service'): Client|bool * * @return Client|false */ - public static function getServiceClient(array $scope = null): Client|bool + public static function getServiceClient(?array $scope = null): Client|bool { if (!self::isServiceConfigured()) { return false; diff --git a/src/Code/CodeCollector.php b/src/Code/CodeCollector.php index 11720f2..95c91c8 100644 --- a/src/Code/CodeCollector.php +++ b/src/Code/CodeCollector.php @@ -60,7 +60,7 @@ public function __construct(array $validBlocks, string $defaultBlock) * * @param SiteId|null $siteId Restrict code part to a specific site */ - public function addCodePart(string $code, string $block = null, string $action = self::ACTION_APPEND, SiteId $siteId = null): void + public function addCodePart(string $code, ?string $block = null, string $action = self::ACTION_APPEND, ?SiteId $siteId = null): void { if (!in_array($action, $this->validActions)) { throw new \InvalidArgumentException(sprintf( diff --git a/src/Config/ConfigProvider.php b/src/Config/ConfigProvider.php index 00d068c..2892aa3 100644 --- a/src/Config/ConfigProvider.php +++ b/src/Config/ConfigProvider.php @@ -29,7 +29,7 @@ class ConfigProvider /** * @param array|null $configObject */ - public function __construct(array $configObject = null) + public function __construct(?array $configObject = null) { $this->configObject = $configObject; } diff --git a/src/Config/SiteConfigProvider.php b/src/Config/SiteConfigProvider.php index 8782835..3d93614 100644 --- a/src/Config/SiteConfigProvider.php +++ b/src/Config/SiteConfigProvider.php @@ -35,7 +35,7 @@ public function __construct( $this->configProvider = $configProvider; } - public function getSiteConfig(Site $site = null): ?array + public function getSiteConfig(?Site $site = null): ?array { $siteId = $this->getSiteId($site); $config = $this->configProvider->getConfig(); @@ -43,7 +43,7 @@ public function getSiteConfig(Site $site = null): ?array return $config->getConfigForSite($siteId->getConfigKey()); } - public function isSiteReportingConfigured(Site $site = null): bool + public function isSiteReportingConfigured(?Site $site = null): bool { $siteId = $this->getSiteId($site); $config = $this->configProvider->getConfig(); @@ -51,7 +51,7 @@ public function isSiteReportingConfigured(Site $site = null): bool return $config->isReportingConfigured($siteId->getConfigKey()); } - private function getSiteId(Site $site = null): SiteId + private function getSiteId(?Site $site = null): SiteId { $siteId = null; if (null === $site) { diff --git a/src/Controller/ReportsControllerBase.php b/src/Controller/ReportsControllerBase.php index 59c15df..e6b555a 100644 --- a/src/Controller/ReportsControllerBase.php +++ b/src/Controller/ReportsControllerBase.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\GoogleMarketingBundle\Controller; +namespace Pimcore\Bundle\GoogleMarketingBundle\Controller; use Pimcore\Config; use Pimcore\Controller\UserAwareController; diff --git a/src/Controller/SettingsController.php b/src/Controller/SettingsController.php index 59b8b9e..5bf1f9e 100644 --- a/src/Controller/SettingsController.php +++ b/src/Controller/SettingsController.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\GoogleMarketingBundle\Controller; +namespace Pimcore\Bundle\GoogleMarketingBundle\Controller; use Exception; use Pimcore\Config\ReportConfigWriter; diff --git a/src/CustomReport/Adapter/Analytics.php b/src/CustomReport/Adapter/Analytics.php index e8a5e46..8445d65 100644 --- a/src/CustomReport/Adapter/Analytics.php +++ b/src/CustomReport/Adapter/Analytics.php @@ -24,7 +24,7 @@ */ class Analytics extends AbstractAdapter { - public function getData(?array $filters, ?string $sort, ?string $dir, ?int $offset, ?int $limit, array $fields = null, array $drillDownFilters = null): array + public function getData(?array $filters, ?string $sort, ?string $dir, ?int $offset, ?int $limit, ?array $fields = null, ?array $drillDownFilters = null): array { $this->setFilters($filters, $drillDownFilters); @@ -104,7 +104,7 @@ protected function setFilters(array $filters, array $drillDownFilters = []): voi * * @throws \Exception */ - protected function getDataHelper(array $fields = null, array $drillDownFilters = null, bool $useDimensionHandling = true): \Google\Service\Analytics\GaData + protected function getDataHelper(?array $fields = null, ?array $drillDownFilters = null, bool $useDimensionHandling = true): \Google\Service\Analytics\GaData { $configuration = clone $this->config; diff --git a/src/SiteId/SiteId.php b/src/SiteId/SiteId.php index f762f9a..5691132 100644 --- a/src/SiteId/SiteId.php +++ b/src/SiteId/SiteId.php @@ -33,7 +33,7 @@ class SiteId private ?Site $site = null; - private function __construct(string $configKey, Site $site = null) + private function __construct(string $configKey, ?Site $site = null) { $this->configKey = $configKey; $this->site = $site; diff --git a/src/SiteId/SiteIdProvider.php b/src/SiteId/SiteIdProvider.php index 81f26e1..7236d58 100644 --- a/src/SiteId/SiteIdProvider.php +++ b/src/SiteId/SiteIdProvider.php @@ -35,7 +35,7 @@ public function __construct(SiteResolver $siteResolver) * * */ - public function getForRequest(Request $request = null): SiteId + public function getForRequest(?Request $request = null): SiteId { if ($this->siteResolver->isSiteRequest($request)) { $site = $this->siteResolver->getSite($request); diff --git a/src/Tracker/AbstractTracker.php b/src/Tracker/AbstractTracker.php index 064c026..6d919b2 100644 --- a/src/Tracker/AbstractTracker.php +++ b/src/Tracker/AbstractTracker.php @@ -31,7 +31,7 @@ public function __construct(SiteIdProvider $siteIdProvider) $this->siteIdProvider = $siteIdProvider; } - public function generateCode(SiteId $siteId = null): ?string + public function generateCode(?SiteId $siteId = null): ?string { if (null === $siteId) { $siteId = $this->siteIdProvider->getForRequest(); @@ -47,7 +47,7 @@ public function generateCode(SiteId $siteId = null): ?string */ abstract protected function buildCode(SiteId $siteId): ?string; - public function addCodePart(string $code, string $block = null, bool $prepend = false, SiteId $siteId = null): void + public function addCodePart(string $code, ?string $block = null, bool $prepend = false, ?SiteId $siteId = null): void { $action = $prepend ? CodeCollector::ACTION_PREPEND : CodeCollector::ACTION_APPEND; diff --git a/src/Tracker/Tracker.php b/src/Tracker/Tracker.php index b5b618e..f430a9d 100644 --- a/src/Tracker/Tracker.php +++ b/src/Tracker/Tracker.php @@ -86,7 +86,7 @@ public function getDefaultPath(): ?string return $this->defaultPath; } - public function setDefaultPath(string $defaultPath = null): void + public function setDefaultPath(?string $defaultPath = null): void { $this->defaultPath = $defaultPath; } @@ -116,7 +116,7 @@ protected function buildCode(SiteId $siteId): ?string * * */ - public function generateCodeForSiteConfig(array $siteConfig, SiteId $siteId = null): string + public function generateCodeForSiteConfig(array $siteConfig, ?SiteId $siteId = null): string { if (null === $siteId) { $siteId = $this->siteIdProvider->getForRequest(); @@ -164,7 +164,7 @@ private function doBuildCode(SiteId $siteId, Config $config, array $siteConfig): * * @return array */ - private function getTrackerConfigurationFromJson(string $configValue = null, array $defaultConfig = []): array + private function getTrackerConfigurationFromJson(?string $configValue = null, array $defaultConfig = []): array { $config = []; if (!empty($configValue)) { diff --git a/src/Tracker/TrackerInterface.php b/src/Tracker/TrackerInterface.php index 517bc1a..11eda08 100644 --- a/src/Tracker/TrackerInterface.php +++ b/src/Tracker/TrackerInterface.php @@ -28,7 +28,7 @@ interface TrackerInterface * * @return null|string Null if no tracking is configured */ - public function generateCode(SiteId $siteId = null): ?string; + public function generateCode(?SiteId $siteId = null): ?string; /** * Adds additional code to the tracker. Code can either be added to all trackers @@ -39,5 +39,5 @@ public function generateCode(SiteId $siteId = null): ?string; * @param bool $prepend Whether to prepend the code to the code block * @param SiteId|null $siteId Restrict code to a specific site */ - public function addCodePart(string $code, string $block = null, bool $prepend = false, SiteId $siteId = null): void; + public function addCodePart(string $code, ?string $block = null, bool $prepend = false, ?SiteId $siteId = null): void; }