From a87a9306d996a14112dfe15806a69a7bb16cb9c4 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Oct 2021 15:28:05 +0200 Subject: [PATCH 1/7] migrate to pimcore x --- .github/workflows/codeception.yml | 47 ++-- .github/workflows/ecs.yml | 38 ++-- .github/workflows/php-stan.yml | 37 ++-- README.md | 39 ++-- UPGRADE.md | 22 +- composer.json | 15 +- docs/00_Setup.md | 2 +- docs/20_IndexNotification.md | 4 +- .../Worker/01_GoogleWorker.md | 2 +- docs/MetaData/30_Middleware.md | 39 +--- docs/MetaData/Extractor/10_CustomExtractor.md | 14 +- ecs.php | 162 ++++++++++++++ phpstan.neon | 10 +- .../Command/QueuedIndexDataCommand.php | 28 +-- .../Controller/Admin/MetaDataController.php | 42 +--- .../Compiler/IndexWorkerPass.php | 16 +- .../Compiler/MetaDataExtractorPass.php | 5 +- .../Compiler/MetaDataIntegratorPass.php | 16 +- .../Compiler/MetaMiddlewareAdapterPass.php | 5 +- .../Compiler/ResourceProcessorPass.php | 5 +- .../RemoveCoreShopExtractorListenerPass.php | 5 +- .../RemoveNewsMetaDataListenerPass.php | 5 +- .../ThirdParty/RemovePimcoreListenerPass.php | 5 +- .../DependencyInjection/Configuration.php | 10 +- .../DependencyInjection/SeoExtension.php | 17 +- .../AutoMetaDataAttachListener.php | 48 +---- .../EventListener/ElementMetaDataListener.php | 23 +- .../Maintenance/QueuedIndexDataTask.php | 13 +- .../EventListener/PimcoreElementListener.php | 57 +---- src/SeoBundle/Helper/ArrayHelper.php | 47 +--- src/SeoBundle/Logger/Logger.php | 18 +- src/SeoBundle/Logger/LoggerInterface.php | 7 +- .../Manager/ElementMetaDataManager.php | 100 ++------- .../ElementMetaDataManagerInterface.php | 50 +---- src/SeoBundle/Manager/QueueManager.php | 102 ++------- .../Manager/QueueManagerInterface.php | 10 +- .../MetaData/Extractor/ExtractorInterface.php | 14 +- .../Extractor/IntegratorExtractor.php | 34 +-- .../ThirdParty/CoreShop/OGExtractor.php | 12 +- .../CoreShop/TitleDescriptionExtractor.php | 12 +- .../ThirdParty/News/EntryMetaExtractor.php | 20 +- .../MetaData/Integrator/HtmlTagIntegrator.php | 42 +--- .../Integrator/IntegratorInterface.php | 65 ++---- .../Integrator/OpenGraphIntegrator.php | 104 +++------ .../MetaData/Integrator/SchemaIntegrator.php | 89 ++------ .../Integrator/TitleDescriptionIntegrator.php | 76 ++----- .../Integrator/TwitterCardIntegrator.php | 99 +++------ src/SeoBundle/MetaData/MetaDataProvider.php | 54 +---- .../MetaData/MetaDataProviderInterface.php | 6 +- src/SeoBundle/Middleware/Middleware.php | 20 +- .../Middleware/MiddlewareAdapterInterface.php | 9 +- .../Middleware/MiddlewareDispatcher.php | 42 +--- .../MiddlewareDispatcherInterface.php | 30 +-- .../Middleware/MiddlewareInterface.php | 7 +- src/SeoBundle/Migrations/.gitkeep | 0 src/SeoBundle/Migrations/Version00000001.php | 33 --- .../Migrations/Version20201015112617.php | 50 ----- src/SeoBundle/Model/ElementMetaData.php | 79 ++----- .../Model/ElementMetaDataInterface.php | 61 ++---- src/SeoBundle/Model/QueueEntry.php | 129 +++-------- src/SeoBundle/Model/QueueEntryInterface.php | 103 +++------ src/SeoBundle/Model/SeoMetaData.php | 200 ++++-------------- src/SeoBundle/Model/SeoMetaDataInterface.php | 109 +++------- src/SeoBundle/Queue/QueueDataProcessor.php | 57 +---- .../Queue/QueueDataProcessorInterface.php | 5 +- .../Registry/IndexWorkerRegistry.php | 28 +-- .../Registry/IndexWorkerRegistryInterface.php | 17 +- .../Registry/MetaDataExtractorRegistry.php | 28 +-- .../MetaDataExtractorRegistryInterface.php | 17 +- .../Registry/MetaDataIntegratorRegistry.php | 28 +-- .../MetaDataIntegratorRegistryInterface.php | 17 +- .../Registry/ResourceProcessorRegistry.php | 28 +-- .../ResourceProcessorRegistryInterface.php | 17 +- .../Repository/ElementMetaDataRepository.php | 19 +- .../ElementMetaDataRepositoryInterface.php | 16 +- .../Repository/QueueEntryRepository.php | 24 +-- .../QueueEntryRepositoryInterface.php | 20 +- .../ResourceProcessorInterface.php | 33 +-- .../Resources/config/services/command.yml | 2 +- .../Resources/config/services/controller.yml | 10 +- .../Resources/install/sql/install.sql | 4 +- src/SeoBundle/Resources/public/css/admin.css | 1 - src/SeoBundle/SeoBundle.php | 38 +--- src/SeoBundle/Tool/Bundle.php | 18 +- src/SeoBundle/Tool/Install.php | 134 ++---------- src/SeoBundle/Tool/LocaleProvider.php | 27 +-- .../Tool/LocaleProviderInterface.php | 8 +- src/SeoBundle/Tool/UrlGenerator.php | 62 ++---- src/SeoBundle/Tool/UrlGeneratorInterface.php | 13 +- src/SeoBundle/Twig/Extension/SeoExtension.php | 24 +-- src/SeoBundle/Worker/GoogleIndexWorker.php | 96 +++------ src/SeoBundle/Worker/IndexWorkerInterface.php | 29 +-- src/SeoBundle/Worker/WorkerResponse.php | 63 +----- .../Worker/WorkerResponseInterface.php | 25 +-- tests/_etc/config.yml | 6 +- tests/_etc/config/app/config.yml | 25 ++- .../app/controller/DefaultController.php | 12 +- tests/_etc/config/app/system.yml | 60 +----- .../{views => templates}/default.html.twig | 4 +- tests/_etc/config/bundle/config_default.yml | 2 +- 100 files changed, 918 insertions(+), 2663 deletions(-) create mode 100644 ecs.php create mode 100644 src/SeoBundle/Migrations/.gitkeep delete mode 100644 src/SeoBundle/Migrations/Version00000001.php delete mode 100644 src/SeoBundle/Migrations/Version20201015112617.php rename tests/_etc/config/app/{views => templates}/default.html.twig (79%) diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index f070b40..26259b9 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -11,16 +11,16 @@ jobs: env: TEST_BUNDLE_NAME: "SeoBundle" TEST_BUNDLE_INSTALLER_CLASS: "SeoBundle\\Tool\\Install" - TEST_BUNDLE_TEST_DIR: "${{ github.workspace }}/tests" + TEST_BUNDLE_TEST_DIR: "${{ github.workspace }}/lib/test-bundle/tests" TEST_PROJECT_ROOT_DIR: "${{ github.workspace }}" PIMCORE_CODECEPTION_FRAMEWORK: "${{ github.workspace }}/pimcore-codeception-framework" - PIMCORE_CODECEPTION_VERSION: "1.0" + PIMCORE_CODECEPTION_VERSION: "2.0" - PIMCORE_ENVIRONMENT: test + APP_ENV: test PIMCORE_TEST_DB_DSN: "mysql://root:root@localhost/dachcom_bundle_test" PIMCORE_TEST_URL: "http://localhost" - PIMCORE_CLASS_DIRECTORY: "${{ github.workspace }}/tests/_output/var/classes/DataObject" + PIMCORE_CLASS_DIRECTORY: "${{ github.workspace }}/lib/test-bundle/tests/_output/var/classes/DataObject" SYMFONY_DEPRECATIONS_HELPER: "weak" PIMCORE_PHP_ERROR_REPORTING: 32767 @@ -32,7 +32,7 @@ jobs: MYSQL_DATABASE: dachcom_bundle_test services: mysql: - image: mysql:5.7 + image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: dachcom_bundle_test @@ -41,27 +41,28 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: matrix: - php: [7.4] - symfony: [^4.4] - pimcore: [~6.6.0, ~6.7.0, ~6.8.0] + php: [ 8.0 ] + symfony: [ ^5.3 ] + pimcore: [ ~10.1.0 ] include: - - pimcore: ~6.6.0 - template_tag: v2.6.0 - - pimcore: ~6.7.0 - template_tag: v2.7.0 - - pimcore: ~6.8.0 - template_tag: v2.8.0 + - pimcore: ~10.1.0 + template_tag: v10.1.0 steps: - uses: actions/checkout@v2 + with: + path: lib/test-bundle - name: Generate Application Structure run: | git clone -b ${{ matrix.template_tag }} --single-branch --depth 1 https://github.com/pimcore/skeleton.git - mv skeleton/app . + mv skeleton/composer.json . mv skeleton/bin . + mv skeleton/config . + mv skeleton/public . + mv skeleton/src . + mv skeleton/templates . mv skeleton/var . - mv skeleton/web . - mv skeleton/src/AppBundle src + rm -r skeleton - name: Setup Pimcore Codeception Framework env: @@ -90,13 +91,11 @@ jobs: - name: Verify MySql Connection run: | sudo apt-get update - sudo apt-get install -y mysql-client-5.7 + sudo apt-get install -y mysql-client-8.0 mysql -uroot -h127.0.0.1 -proot -e "SHOW DATABASES" - name: Setup MySql run: | - mysql -uroot -h127.0.0.1 -proot -e "SET GLOBAL innodb_file_format=Barracuda;" - mysql -uroot -h127.0.0.1 -proot -e "SET GLOBAL innodb_large_prefix=1;" mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE dachcom_bundle_test CHARSET=utf8mb4;" - name: Setup Chromium @@ -106,7 +105,7 @@ jobs: - name: Start Webserver and Chrome run: | wget https://get.symfony.com/cli/installer -O - | bash - ~/.symfony/bin/symfony server:start --port=8080 --dir=web --force-php-discovery --allow-http --no-tls --daemon + ~/.symfony/bin/symfony server:start --port=8080 --dir=public --force-php-discovery --allow-http --no-tls --daemon - name: Get Composer Cache Directory id: composer-cache @@ -131,17 +130,17 @@ jobs: - name: Assets Install run: | - bin/console assets:install web --relative --symlink + bin/console assets:install public --relative --symlink - name: Tests run: | bin/console cache:warmup --env=test - vendor/bin/codecept run --env github -c ${{ env.GITHUB_WORKSPACE }} + vendor/bin/codecept run --env github -c ${{ github.workspace }}/lib/test-bundle - name: Log Output uses: actions/upload-artifact@v2 if: failure() with: name: "Logs (PHP ${{ matrix.php }}, Pimcore ${{ matrix.pimcore }}, Symfony ${{ matrix.symfony }})" - path: tests/_output/ + path: ${{ github.workspace }}/lib/test-bundle/tests/_output/ if-no-files-found: ignore diff --git a/.github/workflows/ecs.yml b/.github/workflows/ecs.yml index ebe00c6..2330e16 100644 --- a/.github/workflows/ecs.yml +++ b/.github/workflows/ecs.yml @@ -11,13 +11,13 @@ jobs: env: TEST_BUNDLE_NAME: "SeoBundle" TEST_BUNDLE_INSTALLER_CLASS: "SeoBundle\\Tool\\Install" - TEST_BUNDLE_TEST_DIR: "${{ github.workspace }}/tests" + TEST_BUNDLE_TEST_DIR: "${{ github.workspace }}/lib/test-bundle/tests" TEST_PROJECT_ROOT_DIR: "${{ github.workspace }}" PIMCORE_CODECEPTION_FRAMEWORK: "${{ github.workspace }}/pimcore-codeception-framework" - PIMCORE_CODECEPTION_VERSION: "1.0" + PIMCORE_CODECEPTION_VERSION: "2.0" - PIMCORE_ENVIRONMENT: test + APP_ENV: test PIMCORE_TEST_DB_DSN: "mysql://root:root@localhost/dachcom_bundle_test" PIMCORE_TEST_URL: "http://localhost" @@ -31,7 +31,7 @@ jobs: MYSQL_DATABASE: dachcom_bundle_test services: mysql: - image: mysql:5.7 + image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: dachcom_bundle_test @@ -40,24 +40,28 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: matrix: - php: [7.4] - symfony: [^4.4] - pimcore: [^6.8] + php: [ 8.0 ] + symfony: [ ^5.3 ] + pimcore: [ ~10.1.0 ] include: - - pimcore: ^6.8 - template_tag: v2.8.0 - + - pimcore: ~10.1.0 + template_tag: v10.1.0 steps: - uses: actions/checkout@v2 + with: + path: lib/test-bundle - name: Generate Application Structure run: | git clone -b ${{ matrix.template_tag }} --single-branch --depth 1 https://github.com/pimcore/skeleton.git - mv skeleton/app . + mv skeleton/composer.json . mv skeleton/bin . + mv skeleton/config . + mv skeleton/public . + mv skeleton/src . + mv skeleton/templates . mv skeleton/var . - mv skeleton/web . - mv skeleton/src/AppBundle src + rm -r skeleton - name: Setup Pimcore Codeception Framework env: @@ -86,13 +90,11 @@ jobs: - name: Verify MySql Connection run: | sudo apt-get update - sudo apt-get install -y mysql-client-5.7 + sudo apt-get install -y mysql-client-8.0 mysql -uroot -h127.0.0.1 -proot -e "SHOW DATABASES" - name: Setup MySql run: | - mysql -uroot -h127.0.0.1 -proot -e "SET GLOBAL innodb_file_format=Barracuda;" - mysql -uroot -h127.0.0.1 -proot -e "SET GLOBAL innodb_large_prefix=1;" mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE dachcom_bundle_test CHARSET=utf8mb4;" - name: Get Composer Cache Directory @@ -118,10 +120,10 @@ jobs: - name: Assets Install run: | - bin/console assets:install web --relative --symlink + bin/console assets:install public --relative --symlink - name: Easy Coding Standard Check continue-on-error: true run: | bin/console cache:warmup --env=test - vendor/bin/ecs check src/SeoBundle --config easy-coding-standard.yml \ No newline at end of file + vendor/bin/ecs check ${{ github.workspace }}/lib/test-bundle/src/SeoBundle --config ${{ github.workspace }}/lib/test-bundle/ecs.php \ No newline at end of file diff --git a/.github/workflows/php-stan.yml b/.github/workflows/php-stan.yml index d390991..07c360e 100644 --- a/.github/workflows/php-stan.yml +++ b/.github/workflows/php-stan.yml @@ -11,13 +11,13 @@ jobs: env: TEST_BUNDLE_NAME: "SeoBundle" TEST_BUNDLE_INSTALLER_CLASS: "SeoBundle\\Tool\\Install" - TEST_BUNDLE_TEST_DIR: "${{ github.workspace }}/tests" + TEST_BUNDLE_TEST_DIR: "${{ github.workspace }}/lib/test-bundle/tests" TEST_PROJECT_ROOT_DIR: "${{ github.workspace }}" PIMCORE_CODECEPTION_FRAMEWORK: "${{ github.workspace }}/pimcore-codeception-framework" - PIMCORE_CODECEPTION_VERSION: "1.0" + PIMCORE_CODECEPTION_VERSION: "2.0" - PIMCORE_ENVIRONMENT: test + APP_ENV: test PIMCORE_TEST_DB_DSN: "mysql://root:root@localhost/dachcom_bundle_test" PIMCORE_TEST_URL: "http://localhost" @@ -31,7 +31,7 @@ jobs: MYSQL_DATABASE: dachcom_bundle_test services: mysql: - image: mysql:5.7 + image: mysql:8.0 env: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: dachcom_bundle_test @@ -40,23 +40,28 @@ jobs: options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 strategy: matrix: - php: [7.4] - symfony: [^4.4] - pimcore: [^6.8] + php: [ 8.0 ] + symfony: [ ^5.3 ] + pimcore: [ ~10.1.0 ] include: - - pimcore: ^6.8 - template_tag: v2.8.0 + - pimcore: ~10.1.0 + template_tag: v10.1.0 steps: - uses: actions/checkout@v2 + with: + path: lib/test-bundle - name: Generate Application Structure run: | git clone -b ${{ matrix.template_tag }} --single-branch --depth 1 https://github.com/pimcore/skeleton.git - mv skeleton/app . + mv skeleton/composer.json . mv skeleton/bin . + mv skeleton/config . + mv skeleton/public . + mv skeleton/src . + mv skeleton/templates . mv skeleton/var . - mv skeleton/web . - mv skeleton/src/AppBundle src + rm -r skeleton - name: Setup Pimcore Codeception Framework env: @@ -85,13 +90,11 @@ jobs: - name: Verify MySql Connection run: | sudo apt-get update - sudo apt-get install -y mysql-client-5.7 + sudo apt-get install -y mysql-client-8.0 mysql -uroot -h127.0.0.1 -proot -e "SHOW DATABASES" - name: Setup MySql run: | - mysql -uroot -h127.0.0.1 -proot -e "SET GLOBAL innodb_file_format=Barracuda;" - mysql -uroot -h127.0.0.1 -proot -e "SET GLOBAL innodb_large_prefix=1;" mysql -uroot -h127.0.0.1 -proot -e "CREATE DATABASE dachcom_bundle_test CHARSET=utf8mb4;" - name: Get Composer Cache Directory @@ -117,9 +120,9 @@ jobs: - name: Assets Install run: | - bin/console assets:install web --relative --symlink + bin/console assets:install public --relative --symlink - name: Php Stan run: | bin/console cache:warmup --env=test - vendor/bin/phpstan analyse -c phpstan.neon -a tests/_phpstan-bootstrap.php src -l 2 \ No newline at end of file + vendor/bin/phpstan analyse -c ${{ github.workspace }}/lib/test-bundle/phpstan.neon -a ${{ github.workspace }}/lib/test-bundle/tests/_phpstan-bootstrap.php ${{ github.workspace }}/lib/test-bundle/src -l 4 \ No newline at end of file diff --git a/README.md b/README.md index 8049333..256c40b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,16 @@ # Pimcore SEO Bundle [![Software License](https://img.shields.io/badge/license-GPLv3-brightgreen.svg?style=flat-square)](LICENSE.md) [![Latest Release](https://img.shields.io/packagist/v/dachcom-digital/seo.svg?style=flat-square)](https://packagist.org/packages/dachcom-digital/seo) -[![Tests](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-seo/Codeception?style=flat-square&logo=github&label=codeception)](https://github.com/dachcom-digital/pimcore-seo/actions?query=workflow%3A%22Codeception%22) -[![PhpStan](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-seo/PHP%20Stan?style=flat-square&logo=github&label=phpstan%20level%202)](https://github.com/dachcom-digital/pimcore-seo/actions?query=workflow%3A%22PHP%20Stan%22) +[![Tests](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-seo/Codeception/master?style=flat-square&logo=github&label=codeception)](https://github.com/dachcom-digital/pimcore-seo/actions?query=workflow%3ACodeception+branch%3Amaster) +[![PhpStan](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-seo/PHP%20Stan/master?style=flat-square&logo=github&label=phpstan%20level%204)](https://github.com/dachcom-digital/pimcore-seo/actions?query=workflow%3A"PHP+Stan"+branch%3Amaster) + +### Release Plan + +| Release | Supported Pimcore Versions | Supported Symfony Versions | Release Date | Maintained | Branch | +|---------|-----------------------------------|----------------------------|--------------|----------------|------------| +| **2.x** | `10.1` | `5.3` | -- | Feature Branch | dev-master | +| **1.x** | `6.0` - `6.9` | `3.4`, `^4.4` | 27.04.2020 | Unsupported | 1.x | + The last SEO Bundle for pimcore you'll ever need! @@ -22,43 +30,22 @@ The last SEO Bundle for pimcore you'll ever need! ## Objects | Tabbed View ![image](https://user-images.githubusercontent.com/700119/79804274-0578ea00-8364-11ea-8780-3cd8b2d72376.png) -#### Requirements -* Pimcore >= 6.0.0 - ## Installation ```json "require" : { - "dachcom-digital/seo" : "~1.0.0", + "dachcom-digital/seo" : "~2.0.0", } ``` -### Installation via Extension Manager -After you have installed the SEO Bundle via composer, open Pimcore backend and go to `Tools` => `Bundles`: -- Click the green `+` Button in `Enable / Disable` row -- Click the green `+` Button in `Install/Uninstall` row - -### Installation via CommandLine -After you have installed the SEO Bundle via composer: - Execute: `$ bin/console pimcore:bundle:enable SeoBundle` - Execute: `$ bin/console pimcore:bundle:install SeoBundle` ## Upgrading - -### Upgrading via Extension Manager -After you have updated the SEO Bundle via composer, open Pimcore backend and go to `Tools` => `Bundles`: -- Click the green `+` Button in `Update` row - -### Upgrading via CommandLine -After you have updated the SEO Bundle via composer: -- Execute: `$ bin/console pimcore:bundle:update SeoBundle` - -### Migrate via CommandLine -Does actually the same as the update command and preferred in CI-Workflow: -- Execute: `$ bin/console pimcore:migrations:migrate -b SeoBundle` +- Execute: `$ bin/console doctrine:migrations:migrate --prefix 'SeoBundle\Migrations'` ## Usage -This Bundle needs some preparation. Please checkout the [Setup && Overview](docs/00_Setup.md) guide first. +This Bundle needs some preparation. Please check out the [Setup && Overview](docs/00_Setup.md) guide first. ## Further Information - [Setup & Overview](docs/00_Setup.md) diff --git a/UPGRADE.md b/UPGRADE.md index caa6fcd..9798c67 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,22 +1,12 @@ # Upgrade Notes -![upgrade](https://user-images.githubusercontent.com/700119/31535145-3c01a264-affa-11e7-8d86-f04c33571f65.png) -*** +## Migrating from Version 1.x to Version 2.0.0 -After every update you should check the pimcore extension manager. -Just click the "update" button or execute the migration command to finish the bundle update. +### Global Changes +- Deprecations have been removed: + - xx +- PHP8 return type declarations added: you may have to adjust your extensions accordingly *** -#### Update from Version 1.1.0 to Version 1.1.1 -- **[ENHANCEMENT]** Improve Dependency Check [#20](https://github.com/dachcom-digital/pimcore-seo/issues/20) - -#### Update from Version 1.0.4 to Version 1.1.0 -- **[ENHANCEMENT]** Respect user locales [#16](https://github.com/dachcom-digital/pimcore-seo/issues/16) -- **[ENHANCEMENT]** Add Permissions. New permissions will be added via migration. Please update your users accordingly [#17](https://github.com/dachcom-digital/pimcore-seo/issues/17) -- **[ENHANCEMENT]** Generate preview data based on user locale [#18](https://github.com/dachcom-digital/pimcore-seo/issues/18) - -#### Update from Version 1.0.3 to Version 1.0.4 -- **[BUGFIX]** Use absolute url in image tags, also don't store path in DB to prevent invalid data (https://github.com/dachcom-digital/pimcore-seo/issues/9) -- **[BUGFIX]** Lower third party extractor priority to allow simple overrides on project layer (https://github.com/dachcom-digital/pimcore-seo/issues/7) -- **[ENHANCEMENT]** Always update document legacy `title` and `description` (https://github.com/dachcom-digital/pimcore-seo/issues/12) +SeoBundle 1.x Upgrade Notes: https://github.com/dachcom-digital/pimcore-seo/blob/1.x/UPGRADE.md diff --git a/composer.json b/composer.json index 966f580..37e6f42 100755 --- a/composer.json +++ b/composer.json @@ -21,10 +21,7 @@ "autoload-dev": { "psr-4": { "": "src/" - }, - "classmap": [ - "app/TestKernel.php" - ] + } }, "extra": { "pimcore": { @@ -34,17 +31,19 @@ } }, "require": { + "pimcore/pimcore": "^10.1", "google/apiclient": "^2.0", - "pimcore/pimcore": "^6.0", "doctrine/orm": "^2.7" }, "require-dev": { - "codeception/codeception": "~2.4.0", + "codeception/codeception": "^4.1", + "codeception/module-webdriver": "^1.4", + "codeception/module-symfony": "^1.6", "phpstan/phpstan": "^0.12", "phpstan/phpstan-symfony": "^0.12", - "symplify/easy-coding-standard": "^5.4" + "symplify/easy-coding-standard": "^9.0" }, "suggest": { - "dachcom-digital/schema": "^1.0" + "dachcom-digital/schema": "^2.0" } } diff --git a/docs/00_Setup.md b/docs/00_Setup.md index 1fe5829..ddc716f 100644 --- a/docs/00_Setup.md +++ b/docs/00_Setup.md @@ -97,7 +97,7 @@ seo: enabled_worker: - worker_name: google_index worker_config: - auth_config: app/config/pimcore/google-api-private-key.json # default pimcore: app/config/pimcore/google-api-private-key.json + auth_config: config/pimcore/google-api-private-key.json # default pimcore: config/pimcore/google-api-private-key.json pimcore_element_watcher: enabled: true ``` \ No newline at end of file diff --git a/docs/20_IndexNotification.md b/docs/20_IndexNotification.md index 84a2867..260fda9 100644 --- a/docs/20_IndexNotification.md +++ b/docs/20_IndexNotification.md @@ -30,7 +30,7 @@ seo: ## Register Service ```yaml -AppBundle\Seo\ResourceProcessor\MyProcessor: +App\Seo\ResourceProcessor\MyProcessor: tags: - { name: seo.index.resource_processor, identifier: my_processor } ``` @@ -40,7 +40,7 @@ AppBundle\Seo\ResourceProcessor\MyProcessor: ````php string = 'Important string!'; } - /** - * {@inheritDoc} - */ public function getTaskArguments(): array { return [$this->string]; } - /** - * {@inheritDoc} - */ - public function onFinish(SeoMetaDataInterface $seoMetadata) + public function onFinish(SeoMetaDataInterface $seoMetadata): void { // nothing to do by default // in some extended usages you may want to finalize and add some data to the SeoMetaData object after all extractors have been dispatched. @@ -61,29 +49,22 @@ In your extractor you could use it like this: ```php getMiddleware('my_custom_adapter'); - $middleware->addTask(function (SeoMetaDataInterface $seoMetadata, string $string) { + $middleware->addTask(static function (SeoMetaDataInterface $seoMetadata, string $string) { $seoMetadata->setTitle($string); // output: "Important string" }); } diff --git a/docs/MetaData/Extractor/10_CustomExtractor.md b/docs/MetaData/Extractor/10_CustomExtractor.md index 5ba75cd..5b75e9d 100644 --- a/docs/MetaData/Extractor/10_CustomExtractor.md +++ b/docs/MetaData/Extractor/10_CustomExtractor.md @@ -2,7 +2,7 @@ Integrating a custom extractor is very easy. ```yaml -AppBundle\MetaData\Extractor\DescriptionExtractor: +App\MetaData\Extractor\DescriptionExtractor: tags: - {name: seo.meta_data.extractor, identifier: my_object_description } ``` @@ -10,25 +10,19 @@ AppBundle\MetaData\Extractor\DescriptionExtractor: ```php setMetaDescription($element->getDescription()); } diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..b5e05a8 --- /dev/null +++ b/ecs.php @@ -0,0 +1,162 @@ +parameters(); + $parameters->set(Option::SETS, [SetList::CLEAN_CODE, SetList::PSR_12]); + + $services = $containerConfigurator->services(); + + $services->set(Fixer\Basic\BracesFixer::class) + ->call('configure', [ + [ + 'allow_single_line_closure' => true, + ] + ]); + + $services->set(Fixer\PhpTag\BlankLineAfterOpeningTagFixer::class); + + $services->set(Fixer\Operator\ConcatSpaceFixer::class) + ->call('configure', [ + [ + 'spacing' => 'one', + ] + ]); + + $services->set(Fixer\Operator\NewWithBracesFixer::class); + + $services->set(Fixer\Phpdoc\PhpdocAlignFixer::class) + ->call('configure', [ + [ + 'tags' => ['method', 'param', 'property', 'return', 'throws', 'type', 'var'], + ] + ]); + + $services->set(Fixer\Operator\BinaryOperatorSpacesFixer::class) + ->call('configure', [ + [ + 'operators' => [ + '=' => 'single_space', + '=>' => 'align', + ] + ] + ]); + $services->set(Fixer\Operator\IncrementStyleFixer::class) + ->call('configure', [ + [ + 'style' => 'post', + ] + ]); + + $services->set(Fixer\Operator\UnaryOperatorSpacesFixer::class); + $services->set(Fixer\Whitespace\BlankLineBeforeStatementFixer::class); + $services->set(Fixer\CastNotation\CastSpacesFixer::class); + $services->set(Fixer\LanguageConstruct\DeclareEqualNormalizeFixer::class); + $services->set(Fixer\FunctionNotation\FunctionTypehintSpaceFixer::class); + $services->set(Fixer\Comment\SingleLineCommentStyleFixer::class) + ->call('configure', [ + [ + 'comment_types' => ['hash'], + ] + ]); + + $services->set(Fixer\ControlStructure\IncludeFixer::class); + $services->set(Fixer\CastNotation\LowercaseCastFixer::class); + $services->set(Fixer\ClassNotation\ClassAttributesSeparationFixer::class) + ->call('configure', [ + [ + 'elements' => [ + 'const' => 'none', + 'method' => 'one', + 'property' => 'none', + 'trait_import' => 'none' + ], + ] + ]); + + $services->set(Fixer\Casing\NativeFunctionCasingFixer::class); + $services->set(Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer::class); + $services->set(Fixer\Phpdoc\NoBlankLinesAfterPhpdocFixer::class); + $services->set(Fixer\Comment\NoEmptyCommentFixer::class); + $services->set(Fixer\Phpdoc\NoEmptyPhpdocFixer::class); + $services->set(Fixer\Phpdoc\PhpdocSeparationFixer::class); + $services->set(Fixer\Semicolon\NoEmptyStatementFixer::class); + $services->set(Fixer\Whitespace\ArrayIndentationFixer::class); + $services->set(Fixer\Whitespace\NoExtraBlankLinesFixer::class) + ->call('configure', [ + [ + 'tokens' => ['curly_brace_block', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'throw', 'use'], + ] + ]); + + $services->set(Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer::class); + $services->set(Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer::class); + $services->set(Fixer\CastNotation\NoShortBoolCastFixer::class); + $services->set(Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer::class); + $services->set(Fixer\Whitespace\NoSpacesAroundOffsetFixer::class); + $services->set(Fixer\ControlStructure\NoTrailingCommaInListCallFixer::class); + $services->set(Fixer\ControlStructure\NoUnneededControlParenthesesFixer::class); + $services->set(Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer::class); + $services->set(Fixer\Whitespace\NoWhitespaceInBlankLineFixer::class); + $services->set(Fixer\ArrayNotation\NormalizeIndexBraceFixer::class); + $services->set(Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer::class); + $services->set(Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer::class); + $services->set(Fixer\Phpdoc\PhpdocIndentFixer::class); + $services->set(Fixer\Phpdoc\PhpdocInlineTagFixer::class); + $services->set(Fixer\Phpdoc\PhpdocNoAccessFixer::class); + $services->set(Fixer\Phpdoc\PhpdocNoEmptyReturnFixer::class); + $services->set(Fixer\Phpdoc\PhpdocNoPackageFixer::class); + $services->set(Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer::class); + $services->set(Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer::class); + $services->set(Fixer\Phpdoc\PhpdocScalarFixer::class); + $services->set(Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer::class); + $services->set(Fixer\Phpdoc\PhpdocSummaryFixer::class); + $services->set(Fixer\Phpdoc\PhpdocToCommentFixer::class); + $services->set(Fixer\Phpdoc\PhpdocTrimFixer::class); + $services->set(Fixer\Phpdoc\PhpdocTypesFixer::class); + $services->set(Fixer\Phpdoc\PhpdocVarWithoutNameFixer::class); + $services->set(Fixer\FunctionNotation\ReturnTypeDeclarationFixer::class); + $services->set(Fixer\ClassNotation\SelfAccessorFixer::class); + $services->set(Fixer\CastNotation\ShortScalarCastFixer::class); + $services->set(Fixer\StringNotation\SingleQuoteFixer::class); + $services->set(Fixer\Semicolon\SpaceAfterSemicolonFixer::class); + $services->set(Fixer\Operator\StandardizeNotEqualsFixer::class); + $services->set(Fixer\Operator\TernaryOperatorSpacesFixer::class); + $services->set(Fixer\ArrayNotation\TrimArraySpacesFixer::class); + $services->set(Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer::class); + + $services->set(Fixer\ClassNotation\ClassDefinitionFixer::class) + ->call('configure', [ + [ + 'single_line' => true, + ] + ]); + + $services->set(Fixer\Casing\MagicConstantCasingFixer::class); + $services->set(Fixer\FunctionNotation\MethodArgumentSpaceFixer::class); + $services->set(Fixer\Alias\NoMixedEchoPrintFixer::class) + ->call('configure', [ + [ + 'use' => 'echo', + ] + ]); + + $services->set(Fixer\Import\NoLeadingImportSlashFixer::class); + $services->set(Fixer\PhpUnit\PhpUnitFqcnAnnotationFixer::class); + $services->set(Fixer\Phpdoc\PhpdocNoAliasTagFixer::class); + $services->set(Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer::class); + $services->set(Fixer\ClassNotation\SingleClassElementPerStatementFixer::class); + + # new since PHP-CS-Fixer 2.6 + $services->set(Fixer\ClassNotation\NoUnneededFinalMethodFixer::class); + $services->set(Fixer\Semicolon\SemicolonAfterInstructionFixer::class); + + # new since 2.11 + $services->set(Fixer\Operator\StandardizeIncrementFixer::class); +}; \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 3c8cfb3..34b9ccb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,16 +1,14 @@ includes: - %currentWorkingDirectory%/vendor/phpstan/phpstan-symfony/extension.neon parameters: + scanFiles: + - %currentWorkingDirectory%/vendor/pimcore/pimcore/stubs/dynamic-constants.php reportUnmatchedIgnoredErrors: false symfony: - container_xml_path: %currentWorkingDirectory%/var/cache/test/appTestKernelTestDebugContainer.xml + container_xml_path: %currentWorkingDirectory%/var/cache/test/TestKernelTestDebugContainer.xml + constant_hassers: false excludes_analyse: # as long we don't install the dependencies :( - '*SeoBundle/MetaData/Extractor/ThirdParty/News/EntryMetaExtractor.php' - '*SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/OGExtractor.php' - '*SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php' - ignoreErrors: - # There is no global constants definition file we could include, ignore it: - - '#Constant PIMCORE_[A-Z\\_]+ not found\.#' - - '#.*NodeDefinition::append.*#' - - '#.*NodeDefinition::addDefaultsIfNotSet.*#' \ No newline at end of file diff --git a/src/SeoBundle/Command/QueuedIndexDataCommand.php b/src/SeoBundle/Command/QueuedIndexDataCommand.php index bb26e1d..c92f49c 100644 --- a/src/SeoBundle/Command/QueuedIndexDataCommand.php +++ b/src/SeoBundle/Command/QueuedIndexDataCommand.php @@ -9,35 +9,23 @@ class QueuedIndexDataCommand extends Command { - /** - * @var QueueDataProcessorInterface - */ - protected $dataProcessor; - - /** - * @param QueueDataProcessorInterface $dataProcessor - */ + protected static $defaultName = 'seo:check-index-queue'; + protected static $defaultDescription = 'For internal use only'; + + protected QueueDataProcessorInterface $dataProcessor; + public function __construct(QueueDataProcessorInterface $dataProcessor) { parent::__construct(); $this->dataProcessor = $dataProcessor; } - /** - * {@inheritdoc} - */ - protected function configure() + protected function configure(): void { - $this - ->setHidden(true) - ->setName('seo:check-index-queue') - ->setDescription('For internal use only'); + $this->setHidden(true); } - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->dataProcessor->process([]); diff --git a/src/SeoBundle/Controller/Admin/MetaDataController.php b/src/SeoBundle/Controller/Admin/MetaDataController.php index 18c2d26..121702f 100644 --- a/src/SeoBundle/Controller/Admin/MetaDataController.php +++ b/src/SeoBundle/Controller/Admin/MetaDataController.php @@ -13,20 +13,9 @@ class MetaDataController extends AdminController { - /** - * @var ElementMetaDataManagerInterface - */ - protected $elementMetaDataManager; - - /** - * @var LocaleProviderInterface - */ - protected $localeProvider; + protected ElementMetaDataManagerInterface $elementMetaDataManager; + protected LocaleProviderInterface $localeProvider; - /** - * @param ElementMetaDataManagerInterface $elementMetaDataManager - * @param LocaleProviderInterface $localeProvider - */ public function __construct( ElementMetaDataManagerInterface $elementMetaDataManager, LocaleProviderInterface $localeProvider @@ -35,10 +24,7 @@ public function __construct( $this->localeProvider = $localeProvider; } - /** - * @return string - */ - public function getMetaDataDefinitionsAction() + public function getMetaDataDefinitionsAction(): JsonResponse { return $this->json([ 'configuration' => $this->elementMetaDataManager->getMetaDataIntegratorConfiguration() @@ -46,13 +32,9 @@ public function getMetaDataDefinitionsAction() } /** - * @param Request $request - * - * @return JsonResponse - * * @throws \Exception */ - public function getElementMetaDataConfigurationAction(Request $request) + public function getElementMetaDataConfigurationAction(Request $request): JsonResponse { $element = null; $availableLocales = null; @@ -79,17 +61,13 @@ public function getElementMetaDataConfigurationAction(Request $request) } /** - * @param Request $request - * - * @return JsonResponse - * * @throws \Exception */ - public function setElementMetaDataConfigurationAction(Request $request) + public function setElementMetaDataConfigurationAction(Request $request): JsonResponse { $elementId = (int) $request->request->get('elementId', 0); $elementType = $request->request->get('elementType'); - $integratorValues = json_decode($request->request->get('integratorValues'), true); + $integratorValues = json_decode($request->request->get('integratorValues'), true, 512, JSON_THROW_ON_ERROR); if (!is_array($integratorValues)) { return $this->adminJson(['success' => true]); @@ -106,18 +84,16 @@ public function setElementMetaDataConfigurationAction(Request $request) } /** - * @param Request $request - * - * @return Response + * @throws \Exception */ - public function generateMetaDataPreviewAction(Request $request) + public function generateMetaDataPreviewAction(Request $request): Response { $elementId = (int) $request->query->get('elementId', 0); $elementType = $request->query->get('elementType', ''); $template = $request->query->get('template', 'none'); $integratorName = $request->query->get('integratorName'); - $data = json_decode($request->query->get('data', ''), true); + $data = json_decode($request->query->get('data', ''), true, 512, JSON_THROW_ON_ERROR); if (empty($data)) { $data = []; diff --git a/src/SeoBundle/DependencyInjection/Compiler/IndexWorkerPass.php b/src/SeoBundle/DependencyInjection/Compiler/IndexWorkerPass.php index 3a23fc8..7039d4d 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/IndexWorkerPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/IndexWorkerPass.php @@ -12,12 +12,7 @@ final class IndexWorkerPass implements CompilerPassInterface { - /** - * {@inheritdoc} - * - * @throws \Exception - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $definition = $container->getDefinition(IndexWorkerRegistry::class); @@ -35,14 +30,7 @@ public function process(ContainerBuilder $container) } } - /** - * @param string $identifier - * @param array $workerConfiguration - * @param Definition $definition - * - * @throws \Exception - */ - public function setDefinitionConfiguration(string $identifier, array $workerConfiguration, Definition $definition) + public function setDefinitionConfiguration(string $identifier, array $workerConfiguration, Definition $definition): void { $options = new OptionsResolver(); /** @var IndexWorkerInterface $class */ diff --git a/src/SeoBundle/DependencyInjection/Compiler/MetaDataExtractorPass.php b/src/SeoBundle/DependencyInjection/Compiler/MetaDataExtractorPass.php index 32d4cb6..2a5d8fa 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/MetaDataExtractorPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/MetaDataExtractorPass.php @@ -10,10 +10,7 @@ final class MetaDataExtractorPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $i = 0; $services = []; diff --git a/src/SeoBundle/DependencyInjection/Compiler/MetaDataIntegratorPass.php b/src/SeoBundle/DependencyInjection/Compiler/MetaDataIntegratorPass.php index a3d458b..3d5bd58 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/MetaDataIntegratorPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/MetaDataIntegratorPass.php @@ -13,12 +13,7 @@ final class MetaDataIntegratorPass implements CompilerPassInterface { - /** - * {@inheritdoc} - * - * @throws \Exception - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $integratorConfiguration = $container->getParameter('seo.meta_data_integrator.configuration'); @@ -35,14 +30,7 @@ public function process(ContainerBuilder $container) } } - /** - * @param string $identifier - * @param array $integratorConfiguration - * @param Definition $definition - * - * @throws \Exception - */ - public function setDefinitionConfiguration(string $identifier, array $integratorConfiguration, Definition $definition) + public function setDefinitionConfiguration(string $identifier, array $integratorConfiguration, Definition $definition): void { $integratorConfig = null; foreach ($integratorConfiguration['enabled_integrator'] as $enabledIntegrator) { diff --git a/src/SeoBundle/DependencyInjection/Compiler/MetaMiddlewareAdapterPass.php b/src/SeoBundle/DependencyInjection/Compiler/MetaMiddlewareAdapterPass.php index 0722047..a7357e1 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/MetaMiddlewareAdapterPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/MetaMiddlewareAdapterPass.php @@ -10,10 +10,7 @@ final class MetaMiddlewareAdapterPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $definition = $container->getDefinition(MiddlewareDispatcher::class); diff --git a/src/SeoBundle/DependencyInjection/Compiler/ResourceProcessorPass.php b/src/SeoBundle/DependencyInjection/Compiler/ResourceProcessorPass.php index 897624b..ddfbb3c 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/ResourceProcessorPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/ResourceProcessorPass.php @@ -10,10 +10,7 @@ final class ResourceProcessorPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $i = 0; $services = []; diff --git a/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveCoreShopExtractorListenerPass.php b/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveCoreShopExtractorListenerPass.php index ecea000..063c6cf 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveCoreShopExtractorListenerPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveCoreShopExtractorListenerPass.php @@ -8,10 +8,7 @@ final class RemoveCoreShopExtractorListenerPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (Bundle::hasBundle('CoreShopSEOBundle', $container->getParameter('kernel.bundles')) === false) { return; diff --git a/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveNewsMetaDataListenerPass.php b/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveNewsMetaDataListenerPass.php index 39db393..04f6b27 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveNewsMetaDataListenerPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemoveNewsMetaDataListenerPass.php @@ -8,10 +8,7 @@ final class RemoveNewsMetaDataListenerPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $definition = 'NewsBundle\EventListener\MetaDataListener'; diff --git a/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemovePimcoreListenerPass.php b/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemovePimcoreListenerPass.php index a8284b5..23d1e49 100644 --- a/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemovePimcoreListenerPass.php +++ b/src/SeoBundle/DependencyInjection/Compiler/ThirdParty/RemovePimcoreListenerPass.php @@ -7,10 +7,7 @@ final class RemovePimcoreListenerPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { // Remove pimcore default DocumentMetaDataListener. We take care about that now! $dataIntegratorConfiguration = $container->getParameter('seo.meta_data_integrator.configuration'); diff --git a/src/SeoBundle/DependencyInjection/Configuration.php b/src/SeoBundle/DependencyInjection/Configuration.php index 2a29137..efe9bb1 100644 --- a/src/SeoBundle/DependencyInjection/Configuration.php +++ b/src/SeoBundle/DependencyInjection/Configuration.php @@ -12,8 +12,8 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('seo'); + $treeBuilder = new TreeBuilder('seo'); + $rootNode = $treeBuilder->getRootNode(); $rootNode->append($this->createIndexProviderConfigurationNode()); $rootNode->append($this->createMetaDataConfigurationNode()); @@ -25,7 +25,7 @@ public function getConfigTreeBuilder() private function createIndexProviderConfigurationNode() { $treeBuilder = new TreeBuilder('index_provider_configuration'); - $node = $treeBuilder->root('index_provider_configuration'); + $node = $treeBuilder->getRootNode(); $node ->addDefaultsIfNotSet() @@ -52,7 +52,7 @@ private function createIndexProviderConfigurationNode() private function createMetaDataConfigurationNode() { $treeBuilder = new TreeBuilder('meta_data_configuration'); - $node = $treeBuilder->root('meta_data_configuration'); + $node = $treeBuilder->getRootNode(); $node ->addDefaultsIfNotSet() @@ -118,7 +118,7 @@ private function createMetaDataConfigurationNode() private function createPersistenceNode() { $treeBuilder = new TreeBuilder('persistence'); - $node = $treeBuilder->root('persistence'); + $node = $treeBuilder->getRootNode(); $node ->addDefaultsIfNotSet() diff --git a/src/SeoBundle/DependencyInjection/SeoExtension.php b/src/SeoBundle/DependencyInjection/SeoExtension.php index b7c7919..461bfbe 100644 --- a/src/SeoBundle/DependencyInjection/SeoExtension.php +++ b/src/SeoBundle/DependencyInjection/SeoExtension.php @@ -10,13 +10,7 @@ class SeoExtension extends Extension { - /** - * @param array $configs - * @param ContainerBuilder $container - * - * @throws \Exception - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); @@ -43,14 +37,7 @@ public function load(array $configs, ContainerBuilder $container) $this->checkThirdPartyExtractors($container, $loader, $config['meta_data_configuration']['meta_data_provider']['third_party']); } - /** - * @param ContainerBuilder $container - * @param YamlFileLoader $loader - * @param array $thirdPartyOptions - * - * @throws \Exception - */ - protected function checkThirdPartyExtractors(ContainerBuilder $container, YamlFileLoader $loader, array $thirdPartyOptions) + protected function checkThirdPartyExtractors(ContainerBuilder $container, YamlFileLoader $loader, array $thirdPartyOptions): void { $bundles = $container->getParameter('kernel.bundles'); diff --git a/src/SeoBundle/EventListener/AutoMetaDataAttachListener.php b/src/SeoBundle/EventListener/AutoMetaDataAttachListener.php index 3a451d1..95454cb 100644 --- a/src/SeoBundle/EventListener/AutoMetaDataAttachListener.php +++ b/src/SeoBundle/EventListener/AutoMetaDataAttachListener.php @@ -7,44 +7,18 @@ use Pimcore\Http\Request\Resolver\PimcoreContextResolver; use Pimcore\Model\Document\Page; use SeoBundle\MetaData\MetaDataProviderInterface; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class AutoMetaDataAttachListener implements EventSubscriberInterface { - /** - * @var array - */ - protected $configuration; + protected array $configuration; + protected MetaDataProviderInterface $metaDataProvider; + protected RequestHelper $requestHelper; + protected PimcoreContextResolver $pimcoreContextResolver; + protected DocumentResolver $documentResolverService; - /** - * @var MetaDataProviderInterface - */ - protected $metaDataProvider; - - /** - * @var RequestHelper - */ - protected $requestHelper; - - /** - * @var PimcoreContextResolver - */ - protected $pimcoreContextResolver; - - /** - * @var DocumentResolver - */ - protected $documentResolverService; - - /** - * @param array $configuration - * @param MetaDataProviderInterface $metaDataProvider - * @param RequestHelper $requestHelper - * @param PimcoreContextResolver $contextResolver - * @param DocumentResolver $documentResolverService - */ public function __construct( array $configuration, MetaDataProviderInterface $metaDataProvider, @@ -59,20 +33,14 @@ public function __construct( $this->documentResolverService = $documentResolverService; } - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['onKernelRequest', -255] ]; } - /** - * @param GetResponseEvent $event - */ - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event): void { $request = $event->getRequest(); diff --git a/src/SeoBundle/EventListener/ElementMetaDataListener.php b/src/SeoBundle/EventListener/ElementMetaDataListener.php index c9708cd..5b51cd1 100644 --- a/src/SeoBundle/EventListener/ElementMetaDataListener.php +++ b/src/SeoBundle/EventListener/ElementMetaDataListener.php @@ -11,23 +11,14 @@ class ElementMetaDataListener implements EventSubscriberInterface { - /** - * @var ElementMetaDataManagerInterface - */ - protected $elementMetaDataManager; + protected ElementMetaDataManagerInterface $elementMetaDataManager; - /** - * @param ElementMetaDataManagerInterface $elementMetaDataManager - */ public function __construct(ElementMetaDataManagerInterface $elementMetaDataManager) { $this->elementMetaDataManager = $elementMetaDataManager; } - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ DataObjectEvents::PRE_DELETE => 'handleObjectDeletion', @@ -35,18 +26,12 @@ public static function getSubscribedEvents() ]; } - /** - * @param DocumentEvent $event - */ - public function handleDocumentDeletion(DocumentEvent $event) + public function handleDocumentDeletion(DocumentEvent $event): void { $this->elementMetaDataManager->deleteElementData('document', $event->getDocument()->getId()); } - /** - * @param DataObjectEvent $event - */ - public function handleObjectDeletion(DataObjectEvent $event) + public function handleObjectDeletion(DataObjectEvent $event): void { $this->elementMetaDataManager->deleteElementData('object', $event->getObject()->getId()); } diff --git a/src/SeoBundle/EventListener/Maintenance/QueuedIndexDataTask.php b/src/SeoBundle/EventListener/Maintenance/QueuedIndexDataTask.php index 4b55e8e..56425d6 100644 --- a/src/SeoBundle/EventListener/Maintenance/QueuedIndexDataTask.php +++ b/src/SeoBundle/EventListener/Maintenance/QueuedIndexDataTask.php @@ -7,23 +7,14 @@ class QueuedIndexDataTask implements TaskInterface { - /** - * @var QueueDataProcessorInterface - */ - protected $dataProcessor; + protected QueueDataProcessorInterface $dataProcessor; - /** - * @param QueueDataProcessorInterface $dataProcessor - */ public function __construct(QueueDataProcessorInterface $dataProcessor) { $this->dataProcessor = $dataProcessor; } - /** - * {@inheritdoc} - */ - public function execute() + public function execute(): void { $this->dataProcessor->process([]); } diff --git a/src/SeoBundle/EventListener/PimcoreElementListener.php b/src/SeoBundle/EventListener/PimcoreElementListener.php index e349b0e..4e52dfc 100644 --- a/src/SeoBundle/EventListener/PimcoreElementListener.php +++ b/src/SeoBundle/EventListener/PimcoreElementListener.php @@ -15,30 +15,16 @@ class PimcoreElementListener implements EventSubscriberInterface { - /** - * @var bool - */ - protected $enabled; - - /** - * @var QueueManagerInterface - */ - protected $queueManager; - - /** - * @param bool $enabled - * @param QueueManagerInterface $queueManager - */ + protected bool $enabled; + protected QueueManagerInterface $queueManager; + public function __construct(bool $enabled, QueueManagerInterface $queueManager) { $this->enabled = $enabled; $this->queueManager = $queueManager; } - /** - * @return array - */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ DocumentEvents::POST_UPDATE => 'onDocumentPostUpdate', @@ -51,10 +37,7 @@ public static function getSubscribedEvents() ]; } - /** - * @param DocumentEvent $event - */ - public function onDocumentPostUpdate(DocumentEvent $event) + public function onDocumentPostUpdate(DocumentEvent $event): void { if ($this->enabled === false) { return; @@ -71,10 +54,7 @@ public function onDocumentPostUpdate(DocumentEvent $event) $this->queueManager->addToQueue($dispatchType, $event->getDocument()); } - /** - * @param DocumentEvent $event - */ - public function onDocumentPreDelete(DocumentEvent $event) + public function onDocumentPreDelete(DocumentEvent $event): void { if ($this->enabled === false) { return; @@ -87,10 +67,7 @@ public function onDocumentPreDelete(DocumentEvent $event) $this->queueManager->addToQueue(IndexWorkerInterface::TYPE_DELETE, $event->getDocument()); } - /** - * @param DataObjectEvent $event - */ - public function onObjectPostUpdate(DataObjectEvent $event) + public function onObjectPostUpdate(DataObjectEvent $event): void { if ($this->enabled === false) { return; @@ -108,10 +85,7 @@ public function onObjectPostUpdate(DataObjectEvent $event) $this->queueManager->addToQueue($dispatchType, $event->getObject()); } - /** - * @param DataObjectEvent $event - */ - public function onObjectPreDelete(DataObjectEvent $event) + public function onObjectPreDelete(DataObjectEvent $event): void { if ($this->enabled === false) { return; @@ -120,10 +94,7 @@ public function onObjectPreDelete(DataObjectEvent $event) $this->queueManager->addToQueue(IndexWorkerInterface::TYPE_DELETE, $event->getObject()); } - /** - * @param AssetEvent $event - */ - public function onAssetPostAdd(AssetEvent $event) + public function onAssetPostAdd(AssetEvent $event): void { if ($this->enabled === false) { return; @@ -132,10 +103,7 @@ public function onAssetPostAdd(AssetEvent $event) $this->queueManager->addToQueue(IndexWorkerInterface::TYPE_ADD, $event->getAsset()); } - /** - * @param AssetEvent $event - */ - public function onAssetPostUpdate(AssetEvent $event) + public function onAssetPostUpdate(AssetEvent $event): void { if ($this->enabled === false) { return; @@ -144,10 +112,7 @@ public function onAssetPostUpdate(AssetEvent $event) $this->queueManager->addToQueue(IndexWorkerInterface::TYPE_UPDATE, $event->getAsset()); } - /** - * @param AssetEvent $event - */ - public function onAssetPreDelete(AssetEvent $event) + public function onAssetPreDelete(AssetEvent $event): void { if ($this->enabled === false) { return; diff --git a/src/SeoBundle/Helper/ArrayHelper.php b/src/SeoBundle/Helper/ArrayHelper.php index 65bec7a..a0cf52b 100644 --- a/src/SeoBundle/Helper/ArrayHelper.php +++ b/src/SeoBundle/Helper/ArrayHelper.php @@ -4,16 +4,7 @@ class ArrayHelper { - /** - * @param array $data - * @param array|null $previousData - * @param string $rowIdentifier - * - * @param string $dataIdentifier - * - * @return array - */ - public function mergeLocaleAwareArrays(array $data, ?array $previousData, string $rowIdentifier = 'name', $dataIdentifier = 'value') + public function mergeLocaleAwareArrays(array $data, ?array $previousData, string $rowIdentifier = 'name', string $dataIdentifier = 'value'): array { // nothing to merge if (!is_array($previousData) || count($previousData) === 0) { @@ -23,7 +14,7 @@ public function mergeLocaleAwareArrays(array $data, ?array $previousData, string $newData = []; foreach ($data as $row) { - $previousRowIndex = array_search($row[$rowIdentifier], array_column($previousData, $rowIdentifier)); + $previousRowIndex = array_search($row[$rowIdentifier], array_column($previousData, $rowIdentifier), true); if ($previousRowIndex === false) { if (null !== $cleanRowValues = $this->cleanEmptyLocaleValues($row[$dataIdentifier])) { @@ -51,20 +42,14 @@ public function mergeLocaleAwareArrays(array $data, ?array $previousData, string return $newData; } - /** - * @param array $values - * @param array $rebuildRow - * - * @return array - */ - public function rebuildLocaleValueRow(array $values, array $rebuildRow) + public function rebuildLocaleValueRow(array $values, array $rebuildRow): array { foreach ($values as $currentRow) { $locale = $currentRow['locale']; $value = $currentRow['value']; - $index = array_search($locale, array_column($rebuildRow, 'locale')); + $index = array_search($locale, array_column($rebuildRow, 'locale'), true); if ($index !== false) { @@ -74,8 +59,6 @@ public function rebuildLocaleValueRow(array $values, array $rebuildRow) $rebuildRow[$index] = $currentRow; } - continue; - } elseif ($value !== null) { $rebuildRow[] = $currentRow; } @@ -85,13 +68,7 @@ public function rebuildLocaleValueRow(array $values, array $rebuildRow) return array_values($rebuildRow); } - /** - * @param array $field - * @param string $dataIdentifier - * - * @return array|null - */ - public function cleanEmptyLocaleRows(array $field, $dataIdentifier = 'value') + public function cleanEmptyLocaleRows(array $field, string $dataIdentifier = 'value'): ?array { if (!is_array($field)) { return $field; @@ -119,12 +96,7 @@ public function cleanEmptyLocaleRows(array $field, $dataIdentifier = 'value') return count($cleanData) === 0 ? null : $cleanData; } - /** - * @param array $field - * - * @return array|null - */ - public function cleanEmptyLocaleValues(array $field) + public function cleanEmptyLocaleValues(array $field): ?array { if (!is_array($field)) { return $field; @@ -140,12 +112,7 @@ public function cleanEmptyLocaleValues(array $field) return count($cleanData) === 0 ? null : $cleanData; } - /** - * @param array $array - * - * @return bool - */ - public function isAssocArray(array $array) + public function isAssocArray(array $array): bool { if ($array === []) { return false; diff --git a/src/SeoBundle/Logger/Logger.php b/src/SeoBundle/Logger/Logger.php index 1a91dec..b349fbe 100644 --- a/src/SeoBundle/Logger/Logger.php +++ b/src/SeoBundle/Logger/Logger.php @@ -6,31 +6,19 @@ class Logger implements LoggerInterface { - /** - * @var ApplicationLogger - */ - protected $applicationLogger; + protected ApplicationLogger $applicationLogger; - /** - * @param ApplicationLogger $applicationLogger - */ public function __construct(ApplicationLogger $applicationLogger) { $this->applicationLogger = $applicationLogger; } - /** - * {@inheritdoc} - */ - public function log($level, $message, array $context = []) + public function log(string $level, string $message, array $context = []): void { $this->getLogger()->log($level, $message, $context); } - /** - * @return ApplicationLogger - */ - protected function getLogger() + protected function getLogger(): ApplicationLogger { return $this->applicationLogger::getInstance('seo-bundle', true); } diff --git a/src/SeoBundle/Logger/LoggerInterface.php b/src/SeoBundle/Logger/LoggerInterface.php index 3153fd8..ed5d42c 100644 --- a/src/SeoBundle/Logger/LoggerInterface.php +++ b/src/SeoBundle/Logger/LoggerInterface.php @@ -4,10 +4,5 @@ interface LoggerInterface { - /** - * @param string $level - * @param string $message - * @param array $context - */ - public function log($level, $message, array $context = []); + public function log(string $level, string $message, array $context = []): void; } diff --git a/src/SeoBundle/Manager/ElementMetaDataManager.php b/src/SeoBundle/Manager/ElementMetaDataManager.php index 47e2aba..9921ebd 100644 --- a/src/SeoBundle/Manager/ElementMetaDataManager.php +++ b/src/SeoBundle/Manager/ElementMetaDataManager.php @@ -13,32 +13,11 @@ class ElementMetaDataManager implements ElementMetaDataManagerInterface { - /** - * @var array - */ - protected $integratorConfiguration; - - /** - * @var EntityManagerInterface - */ - protected $entityManager; + protected array $integratorConfiguration; + protected EntityManagerInterface $entityManager; + protected MetaDataIntegratorRegistryInterface $metaDataIntegratorRegistry; + protected ElementMetaDataRepositoryInterface $elementMetaDataRepository; - /** - * @var MetaDataIntegratorRegistryInterface - */ - protected $metaDataIntegratorRegistry; - - /** - * @var ElementMetaDataRepositoryInterface - */ - protected $elementMetaDataRepository; - - /** - * @param array $integratorConfiguration - * @param EntityManagerInterface $entityManager - * @param MetaDataIntegratorRegistryInterface $metaDataIntegratorRegistry - * @param ElementMetaDataRepositoryInterface $elementMetaDataRepository - */ public function __construct( array $integratorConfiguration, EntityManagerInterface $entityManager, @@ -51,18 +30,12 @@ public function __construct( $this->elementMetaDataRepository = $elementMetaDataRepository; } - /** - * {@inheritdoc} - */ - public function getMetaDataIntegratorConfiguration() + public function getMetaDataIntegratorConfiguration(): array { return $this->integratorConfiguration; } - /** - * {@inheritdoc} - */ - public function getMetaDataIntegratorBackendConfiguration($correspondingElement) + public function getMetaDataIntegratorBackendConfiguration(mixed $correspondingElement): array { $configuration = []; @@ -76,24 +49,16 @@ public function getMetaDataIntegratorBackendConfiguration($correspondingElement) return $configuration; } - /** - * {@inheritdoc} - */ - public function getElementData(string $elementType, int $elementId) + public function getElementData(string $elementType, int $elementId): array { $elementValues = $this->elementMetaDataRepository->findAll($elementType, $elementId); // BC Reason: If old document metadata is available, use it! // @todo: make this decision configurable? We don't need this within fresh installations! - $elementValues = $this->checkForLegacyData($elementValues, $elementType, $elementId); - - return $elementValues; + return $this->checkForLegacyData($elementValues, $elementType, $elementId); } - /** - * {@inheritdoc} - */ - public function getElementDataForBackend(string $elementType, int $elementId) + public function getElementDataForBackend(string $elementType, int $elementId): array { $parsedData = []; $data = $this->getElementData($elementType, $elementId); @@ -105,15 +70,10 @@ public function getElementDataForBackend(string $elementType, int $elementId) // BC Reason: If old document metadata is available, use it! // @todo: make this decision configurable? We don't need this within fresh installations! - $parsedData = $this->checkForLegacyBackendData($parsedData, $elementType, $elementId); - - return $parsedData; + return $this->checkForLegacyBackendData($parsedData, $elementType, $elementId); } - /** - * {@inheritdoc} - */ - public function saveElementData(string $elementType, int $elementId, string $integratorName, array $data) + public function saveElementData(string $elementType, int $elementId, string $integratorName, array $data): void { $elementMetaData = $this->elementMetaDataRepository->findByIntegrator($elementType, $elementId, $integratorName); @@ -143,10 +103,7 @@ public function saveElementData(string $elementType, int $elementId, string $int $this->entityManager->flush(); } - /** - * {@inheritdoc} - */ - public function generatePreviewDataForElement(string $elementType, int $elementId, string $integratorName, ?string $template, array $data) + public function generatePreviewDataForElement(string $elementType, int $elementId, string $integratorName, ?string $template, array $data): array { if ($elementType === 'object') { $element = DataObject::getById($elementId); @@ -159,10 +116,7 @@ public function generatePreviewDataForElement(string $elementType, int $elementI return $metaDataIntegrator->getPreviewParameter($element, $template, $data); } - /** - * {@inheritdoc} - */ - public function deleteElementData(string $elementType, int $elementId) + public function deleteElementData(string $elementType, int $elementId): void { $elementData = $this->elementMetaDataRepository->findAll($elementType, $elementId); @@ -178,13 +132,9 @@ public function deleteElementData(string $elementType, int $elementId) } /** - * @param ElementMetaDataInterface[] $elements - * @param string $elementType - * @param int $elementId - * - * @return array|ElementMetaDataInterface[] + * @return array */ - protected function checkForLegacyData(array $elements, string $elementType, int $elementId) + protected function checkForLegacyData(array $elements, string $elementType, int $elementId): array { // as soon we have configured seo elements, // we'll never check the document again. It's all about performance. @@ -222,14 +172,7 @@ protected function checkForLegacyData(array $elements, string $elementType, int return $elements; } - /** - * @param array $parsedData - * @param string $elementType - * @param int $elementId - * - * @return array - */ - protected function checkForLegacyBackendData(array $parsedData, string $elementType, int $elementId) + protected function checkForLegacyBackendData(array $parsedData, string $elementType, int $elementId): array { // as soon we have configured seo elements, // we'll never check the document again. It's all about performance. @@ -277,20 +220,15 @@ protected function checkForLegacyBackendData(array $parsedData, string $elementT return $parsedData; } - /** - * @param int $documentId - * - * @return array|null - */ - protected function getDocumentLegacyData($documentId) + protected function getDocumentLegacyData(int $documentId): ?array { $enabledIntegrator = $this->integratorConfiguration['enabled_integrator']; if (!is_array($enabledIntegrator) || count($enabledIntegrator) === 0) { return null; } - $hasTitleDescriptionIntegrator = array_search('title_description', array_column($enabledIntegrator, 'integrator_name')); - $hasHtmlTagIntegrator = array_search('html_tag', array_column($enabledIntegrator, 'integrator_name')); + $hasTitleDescriptionIntegrator = array_search('title_description', array_column($enabledIntegrator, 'integrator_name'), true); + $hasHtmlTagIntegrator = array_search('html_tag', array_column($enabledIntegrator, 'integrator_name'), true); // no required integrators are active. skip this task... if ($hasTitleDescriptionIntegrator === false && $hasHtmlTagIntegrator === false) { diff --git a/src/SeoBundle/Manager/ElementMetaDataManagerInterface.php b/src/SeoBundle/Manager/ElementMetaDataManagerInterface.php index 7683fd6..da260a3 100644 --- a/src/SeoBundle/Manager/ElementMetaDataManagerInterface.php +++ b/src/SeoBundle/Manager/ElementMetaDataManagerInterface.php @@ -6,54 +6,20 @@ interface ElementMetaDataManagerInterface { - /** - * @return array - */ - public function getMetaDataIntegratorConfiguration(); + public function getMetaDataIntegratorConfiguration(): array; - /** - * @param mixed $correspondingElement - * - * @return array - */ - public function getMetaDataIntegratorBackendConfiguration($correspondingElement); + public function getMetaDataIntegratorBackendConfiguration(mixed $correspondingElement): array; /** - * @param string $elementType - * @param int $elementId - * - * @return ElementMetaDataInterface[] + * @return array */ - public function getElementData(string $elementType, int $elementId); + public function getElementData(string $elementType, int $elementId): array; - /** - * @param string $elementType - * @param int $elementId - * - * @return array - */ - public function getElementDataForBackend(string $elementType, int $elementId); + public function getElementDataForBackend(string $elementType, int $elementId): array; - /** - * @param string $elementType - * @param int $elementId - * @param string $integratorName - * @param array $data - */ - public function saveElementData(string $elementType, int $elementId, string $integratorName, array $data); + public function saveElementData(string $elementType, int $elementId, string $integratorName, array $data): void; - /** - * @param string $elementType - * @param int $elementId - * @param string $integratorName - * @param string|null $template - * @param array $data - */ - public function generatePreviewDataForElement(string $elementType, int $elementId, string $integratorName, ?string $template, array $data); + public function generatePreviewDataForElement(string $elementType, int $elementId, string $integratorName, ?string $template, array $data): array; - /** - * @param string $elementType - * @param int $elementId - */ - public function deleteElementData(string $elementType, int $elementId); + public function deleteElementData(string $elementType, int $elementId): void; } diff --git a/src/SeoBundle/Manager/QueueManager.php b/src/SeoBundle/Manager/QueueManager.php index ae08756..51c8529 100644 --- a/src/SeoBundle/Manager/QueueManager.php +++ b/src/SeoBundle/Manager/QueueManager.php @@ -14,44 +14,13 @@ class QueueManager implements QueueManagerInterface { - /** - * @var array - */ - protected $enabledWorker; - - /** - * @var EntityManagerInterface - */ - protected $entityManager; - - /** - * @var QueueEntryRepositoryInterface - */ - protected $queueEntryRepository; - - /** - * @var ResourceProcessorRegistryInterface - */ - protected $resourceProcessorRegistry; + protected array $enabledWorker; + protected EntityManagerInterface $entityManager; + protected QueueEntryRepositoryInterface $queueEntryRepository; + protected ResourceProcessorRegistryInterface $resourceProcessorRegistry; + protected IndexWorkerRegistryInterface $indexWorkerRegistry; + protected LoggerInterface $logger; - /** - * @var IndexWorkerRegistryInterface - */ - protected $indexWorkerRegistry; - - /** - * @var LoggerInterface - */ - protected $logger; - - /** - * @param array $enabledWorker - * @param EntityManagerInterface $entityManager - * @param QueueEntryRepositoryInterface $queueEntryRepository - * @param ResourceProcessorRegistryInterface $resourceProcessorRegistry - * @param IndexWorkerRegistryInterface $indexWorkerRegistry - * @param LoggerInterface $logger - */ public function __construct( array $enabledWorker, EntityManagerInterface $entityManager, @@ -68,10 +37,7 @@ public function __construct( $this->logger = $logger; } - /** - * {@inheritdoc} - */ - public function addToQueue(string $processType, $resource) + public function addToQueue(string $processType, mixed $resource): void { foreach ($this->enabledWorker as $workerIdentifier) { foreach ($this->resourceProcessorRegistry->getAll() as $resourceProcessorIdentifier => $resourceProcessor) { @@ -94,10 +60,7 @@ public function addToQueue(string $processType, $resource) } } - /** - * {@inheritdoc} - */ - public function processQueue() + public function processQueue(): void { foreach ($this->enabledWorker as $workerIdentifier) { if ($this->hasQueueData($workerIdentifier) === false) { @@ -122,13 +85,11 @@ public function processQueue() } /** - * @param WorkerResponseInterface $workerResponse - * * @throws \Exception * * @internal */ - public function processResponse(WorkerResponseInterface $workerResponse) + public function processResponse(WorkerResponseInterface $workerResponse): void { $resourceProcessorIdentifier = $workerResponse->getQueueEntry()->getResourceProcessor(); $resourceProcessor = $this->resourceProcessorRegistry->get($resourceProcessorIdentifier); @@ -167,22 +128,12 @@ public function processResponse(WorkerResponseInterface $workerResponse) $this->logger->log('info', $message, $logContext); } - /** - * @param string $workerIdentifier - * - * @return bool - */ - protected function hasQueueData(string $workerIdentifier) + protected function hasQueueData(string $workerIdentifier): bool { return $this->queueEntryRepository->findAtLeastOneForWorker($workerIdentifier) instanceof QueueEntryInterface; } - /** - * @param string $workerIdentifier - * - * @return array - */ - protected function getQueuedData(string $workerIdentifier) + protected function getQueuedData(string $workerIdentifier): array { $data = []; $removableEntries = []; @@ -206,18 +157,8 @@ protected function getQueuedData(string $workerIdentifier) return $data; } - /** - * @param string $processType - * @param string $workerIdentifier - * @param string $resourceProcessorIdentifier - * @param QueueEntryInterface $queueEntry - */ - protected function createQueueEntry(string $processType, string $workerIdentifier, string $resourceProcessorIdentifier, QueueEntryInterface $queueEntry) + protected function createQueueEntry(string $processType, string $workerIdentifier, string $resourceProcessorIdentifier, QueueEntryInterface $queueEntry): void { - if (!$queueEntry instanceof QueueEntryInterface) { - return; - } - if (empty($queueEntry->getDataUrl())) { $this->logger->log( 'warning', @@ -242,12 +183,7 @@ protected function createQueueEntry(string $processType, string $workerIdentifie } } - /** - * @param QueueEntryInterface $queueEntry - * - * @return string - */ - protected function generateEntryKey(QueueEntryInterface $queueEntry) + protected function generateEntryKey(QueueEntryInterface $queueEntry): string { return md5(sprintf( '%s_%s_%s', @@ -257,19 +193,13 @@ protected function generateEntryKey(QueueEntryInterface $queueEntry) )); } - /** - * @param QueueEntryInterface $queueEntry - */ - protected function storeInQueue(QueueEntryInterface $queueEntry) + protected function storeInQueue(QueueEntryInterface $queueEntry): void { $this->entityManager->persist($queueEntry); $this->entityManager->flush(); } - /** - * @param QueueEntryInterface $queueEntry - */ - protected function removeFromQueue(QueueEntryInterface $queueEntry) + protected function removeFromQueue(QueueEntryInterface $queueEntry): void { $this->entityManager->remove($queueEntry); $this->entityManager->flush(); @@ -278,7 +208,7 @@ protected function removeFromQueue(QueueEntryInterface $queueEntry) /** * @param QueueEntryInterface[] $queueEntries */ - protected function removeMultipleFromQueue(array $queueEntries) + protected function removeMultipleFromQueue(array $queueEntries): void { foreach ($queueEntries as $queueEntry) { $this->entityManager->remove($queueEntry); diff --git a/src/SeoBundle/Manager/QueueManagerInterface.php b/src/SeoBundle/Manager/QueueManagerInterface.php index 90ab8c4..931a15a 100644 --- a/src/SeoBundle/Manager/QueueManagerInterface.php +++ b/src/SeoBundle/Manager/QueueManagerInterface.php @@ -4,16 +4,10 @@ interface QueueManagerInterface { - /** - * Send data to queue. - * - * @param string $processType - * @param mixed $resource - */ - public function addToQueue(string $processType, $resource); + public function addToQueue(string $processType, mixed $resource): void; /** * Send QueueEntries to enabled index provider workers. */ - public function processQueue(); + public function processQueue(): void; } diff --git a/src/SeoBundle/MetaData/Extractor/ExtractorInterface.php b/src/SeoBundle/MetaData/Extractor/ExtractorInterface.php index 48a1e5b..ddb5d7b 100755 --- a/src/SeoBundle/MetaData/Extractor/ExtractorInterface.php +++ b/src/SeoBundle/MetaData/Extractor/ExtractorInterface.php @@ -6,17 +6,7 @@ interface ExtractorInterface { - /** - * @param object $element - * - * @return bool - */ - public function supports($element); + public function supports(mixed $element): bool; - /** - * @param object $element - * @param string|null $locale - * @param SeoMetaDataInterface $seoMetadata - */ - public function updateMetaData($element, ?string $locale, SeoMetaDataInterface $seoMetadata); + public function updateMetaData(mixed $element, ?string $locale, SeoMetaDataInterface $seoMetadata): void; } diff --git a/src/SeoBundle/MetaData/Extractor/IntegratorExtractor.php b/src/SeoBundle/MetaData/Extractor/IntegratorExtractor.php index 3c5a94d..18b64b6 100644 --- a/src/SeoBundle/MetaData/Extractor/IntegratorExtractor.php +++ b/src/SeoBundle/MetaData/Extractor/IntegratorExtractor.php @@ -11,26 +11,10 @@ class IntegratorExtractor implements ExtractorInterface { - /** - * @var array - */ - protected $integratorConfiguration; + protected array $integratorConfiguration; + protected ElementMetaDataManagerInterface $elementMetaDataManager; + protected MetaDataIntegratorRegistryInterface $metaDataIntegratorRegistry; - /** - * @var ElementMetaDataManagerInterface - */ - protected $elementMetaDataManager; - - /** - * @var MetaDataIntegratorRegistryInterface - */ - protected $metaDataIntegratorRegistry; - - /** - * @param array $integratorConfiguration - * @param ElementMetaDataManagerInterface $elementMetaDataManager - * @param MetaDataIntegratorRegistryInterface $metaDataIntegratorRegistry - */ public function __construct( array $integratorConfiguration, ElementMetaDataManagerInterface $elementMetaDataManager, @@ -41,17 +25,14 @@ public function __construct( $this->metaDataIntegratorRegistry = $metaDataIntegratorRegistry; } - /** - * {@inheritdoc} - */ - public function supports($element) + public function supports(mixed $element): bool { if ($element instanceof Concrete) { if ($this->integratorConfiguration['objects']['enabled'] === false) { return false; } - return in_array($element->getClassName(), $this->integratorConfiguration['objects']['data_classes']); + return in_array($element->getClassName(), $this->integratorConfiguration['objects']['data_classes'], true); } if ($element instanceof Page) { @@ -61,10 +42,7 @@ public function supports($element) return false; } - /** - * {@inheritdoc} - */ - public function updateMetaData($element, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetaData(mixed $element, ?string $locale, SeoMetaDataInterface $seoMetadata): void { $elementId = null; $elementType = null; diff --git a/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/OGExtractor.php b/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/OGExtractor.php index 09bb553..718d769 100644 --- a/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/OGExtractor.php +++ b/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/OGExtractor.php @@ -8,18 +8,12 @@ final class OGExtractor implements ExtractorInterface { - /** - * {@inheritdoc} - */ - public function supports($object) + public function supports(mixed $element): bool { - return $object instanceof \CoreShop\Component\SEO\Model\SEOOpenGraphAwareInterface; + return $element instanceof \CoreShop\Component\SEO\Model\SEOOpenGraphAwareInterface; } - /** - * {@inheritdoc} - */ - public function updateMetadata($element, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetadata(mixed $element, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (method_exists($element, 'getMetaTitle') && !empty($element->getOGTitle($locale))) { $seoMetadata->addExtraProperty('og:title', $element->getOGTitle($locale)); diff --git a/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php b/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php index 7a4b2d9..96c6bbc 100644 --- a/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php +++ b/src/SeoBundle/MetaData/Extractor/ThirdParty/CoreShop/TitleDescriptionExtractor.php @@ -7,18 +7,12 @@ final class TitleDescriptionExtractor implements ExtractorInterface { - /** - * {@inheritdoc} - */ - public function supports($object) + public function supports(mixed $element): bool { - return $object instanceof \CoreShop\Component\SEO\Model\SEOAwareInterface; + return $element instanceof \CoreShop\Component\SEO\Model\SEOAwareInterface; } - /** - * {@inheritdoc} - */ - public function updateMetadata($element, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetadata(mixed $element, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (method_exists($element, 'getMetaTitle') && !empty($element->getMetaTitle($locale))) { $seoMetadata->setTitle($element->getMetaTitle($locale)); diff --git a/src/SeoBundle/MetaData/Extractor/ThirdParty/News/EntryMetaExtractor.php b/src/SeoBundle/MetaData/Extractor/ThirdParty/News/EntryMetaExtractor.php index 5160220..7cc2cbc 100644 --- a/src/SeoBundle/MetaData/Extractor/ThirdParty/News/EntryMetaExtractor.php +++ b/src/SeoBundle/MetaData/Extractor/ThirdParty/News/EntryMetaExtractor.php @@ -9,31 +9,19 @@ final class EntryMetaExtractor implements ExtractorInterface { - /** - * @var HeadMetaGeneratorInterface - */ - private $headMetaGenerator; + private HeadMetaGeneratorInterface $headMetaGenerator; - /** - * @param HeadMetaGeneratorInterface $headMetaGenerator - */ public function __construct(HeadMetaGeneratorInterface $headMetaGenerator) { $this->headMetaGenerator = $headMetaGenerator; } - /** - * {@inheritdoc} - */ - public function supports($object) + public function supports(mixed $element): bool { - return $object instanceof EntryInterface; + return $element instanceof EntryInterface; } - /** - * {@inheritdoc} - */ - public function updateMetadata($element, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetadata(mixed $element, ?string $locale, SeoMetaDataInterface $seoMetadata): void { $seoMetadata->setMetaDescription($this->headMetaGenerator->generateDescription($element)); $seoMetadata->setTitle($this->headMetaGenerator->generateTitle($element)); diff --git a/src/SeoBundle/MetaData/Integrator/HtmlTagIntegrator.php b/src/SeoBundle/MetaData/Integrator/HtmlTagIntegrator.php index 88ea1ee..018d3f9 100644 --- a/src/SeoBundle/MetaData/Integrator/HtmlTagIntegrator.php +++ b/src/SeoBundle/MetaData/Integrator/HtmlTagIntegrator.php @@ -7,15 +7,9 @@ class HtmlTagIntegrator implements IntegratorInterface { - /** - * @var array - */ - protected $configuration; - - /** - * {@inheritdoc} - */ - public function getBackendConfiguration($element) + protected array $configuration; + + public function getBackendConfiguration(mixed $element): array { return [ 'hasLivePreview' => false, @@ -24,26 +18,17 @@ public function getBackendConfiguration($element) ]; } - /** - * {@inheritdoc} - */ - public function getPreviewParameter($element, ?string $template, array $data) + public function getPreviewParameter(mixed $element, ?string $template, array $data): array { return []; } - /** - * {@inheritdoc} - */ - public function validateBeforeBackend(string $elementType, int $elementId, array $data) + public function validateBeforeBackend(string $elementType, int $elementId, array $data): array { return $data; } - /** - * {@inheritdoc} - */ - public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null) + public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null): ?array { if (is_array($data) && count($data) === 0) { return null; @@ -73,10 +58,7 @@ public function validateBeforePersist(string $elementType, int $elementId, array return $indexedData; } - /** - * {@inheritdoc} - */ - public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetaData(mixed $element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (count($data) === 0) { return; @@ -89,18 +71,12 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa } } - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) + public function setConfiguration(array $configuration): void { $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ - public static function configureOptions(OptionsResolver $resolver) + public static function configureOptions(OptionsResolver $resolver): void { // no options here. } diff --git a/src/SeoBundle/MetaData/Integrator/IntegratorInterface.php b/src/SeoBundle/MetaData/Integrator/IntegratorInterface.php index 3ddf449..5c98430 100644 --- a/src/SeoBundle/MetaData/Integrator/IntegratorInterface.php +++ b/src/SeoBundle/MetaData/Integrator/IntegratorInterface.php @@ -7,56 +7,17 @@ interface IntegratorInterface { - /** - * @param array $configuration - */ - public function setConfiguration(array $configuration); - - /** - * @param OptionsResolver $resolver - */ - public static function configureOptions(OptionsResolver $resolver); - - /** - * @param mixed $element - * - * @return array - */ - public function getBackendConfiguration($element); - - /** - * @param string $elementType - * @param int $elementId - * @param array $data - * - * @return array - */ - public function validateBeforeBackend(string $elementType, int $elementId, array $data); - - /** - * @param string $elementType - * @param int $elementId - * @param array $data - * @param array|null $previousData - * - * @return array|null - */ - public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null); - - /** - * @param mixed $element - * @param string|null $template - * @param array $data - * - * @return array - */ - public function getPreviewParameter($element, ?string $template, array $data); - - /** - * @param mixed $element - * @param array $data - * @param string|null $locale - * @param SeoMetaDataInterface $seoMetadata - */ - public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata); + public function setConfiguration(array $configuration): void; + + public static function configureOptions(OptionsResolver $resolver): void; + + public function getBackendConfiguration(mixed $element): array; + + public function validateBeforeBackend(string $elementType, int $elementId, array $data): array; + + public function validateBeforePersist(string $elementType, int $elementId, array $data, ?array $previousData = null): ?array; + + public function getPreviewParameter(mixed $element, ?string $template, array $data): array; + + public function updateMetaData(mixed $element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata): void; } diff --git a/src/SeoBundle/MetaData/Integrator/OpenGraphIntegrator.php b/src/SeoBundle/MetaData/Integrator/OpenGraphIntegrator.php index cd75383..b7327ac 100644 --- a/src/SeoBundle/MetaData/Integrator/OpenGraphIntegrator.php +++ b/src/SeoBundle/MetaData/Integrator/OpenGraphIntegrator.php @@ -11,28 +11,15 @@ class OpenGraphIntegrator implements IntegratorInterface { - /** - * @var array - */ - protected $configuration; - - /** - * @var UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * @param UrlGeneratorInterface $urlGenerator - */ + protected array $configuration; + protected UrlGeneratorInterface $urlGenerator; + public function __construct(UrlGeneratorInterface $urlGenerator) { $this->urlGenerator = $urlGenerator; } - /** - * {@inheritdoc} - */ - public function getBackendConfiguration($element) + public function getBackendConfiguration($element): array { $useLocalizedFields = $element instanceof DataObject; @@ -48,19 +35,16 @@ public function getBackendConfiguration($element) ]; } - /** - * {@inheritdoc} - */ - public function getPreviewParameter($element, ?string $template, array $data) + public function getPreviewParameter(mixed $element, ?string $template, array $data): array { - $template = in_array($template, ['facebook']) ? $template : 'default'; + $template = $template === 'facebook' ? $template : 'default'; if (null === $url = $this->urlGenerator->generate($element)) { $url = 'http://localhost/no-url-found'; } - $title = isset($data['title']) ? $data['title'] : 'This is a title'; - $description = isset($data['description']) ? $data['description'] : 'This is a very long description which should be not too long.'; + $title = $data['title'] ?? 'This is a title'; + $description = $data['description'] ?? 'This is a very long description which should be not too long.'; $imagePath = 'bundles/seo/img/integrator/demoImage.jpg'; if (isset($data['image']) && is_array($data['image'])) { @@ -70,7 +54,7 @@ public function getPreviewParameter($element, ?string $template, array $data) } return [ - 'path' => sprintf('@SeoBundle/Resources/views/preview/ogGraph/%s.html.twig', $template), + 'path' => sprintf('@Seo/preview/ogGraph/%s.html.twig', $template), 'params' => [ 'title' => $title, 'description' => $description, @@ -80,10 +64,7 @@ public function getPreviewParameter($element, ?string $template, array $data) ]; } - /** - * {@inheritdoc} - */ - public function validateBeforeBackend(string $elementType, int $elementId, array $data) + public function validateBeforeBackend(string $elementType, int $elementId, array $data): array { foreach ($data as &$ogField) { if ($ogField['property'] === 'og:image' && isset($ogField['value']['thumbPath'])) { @@ -94,10 +75,7 @@ public function validateBeforeBackend(string $elementType, int $elementId, array return $data; } - /** - * {@inheritdoc} - */ - public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null) + public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null): ?array { if ($elementType === 'object') { $arrayModifier = new ArrayHelper(); @@ -111,15 +89,14 @@ public function validateBeforePersist(string $elementType, int $elementId, array return $data; } - /** - * {@inheritdoc} - */ - public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (count($data) === 0) { return; } + dump($data); + $addedItems = 0; foreach ($data as $ogItem) { if (!isset($ogItem['value']) || empty($ogItem['value']) || empty($ogItem['property'])) { @@ -137,14 +114,7 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa } } - /** - * @param string $property - * @param array|string $value - * @param string $locale - * - * @return string|null - */ - protected function findLocaleAwareData(string $property, $value, $locale) + protected function findLocaleAwareData(string $property, mixed $value, ?string $locale): int|float|string|bool|null { if ($property === 'og:image') { return isset($value['id']) && is_numeric($value['id']) ? $this->getImagePath($value) : null; @@ -154,15 +124,15 @@ protected function findLocaleAwareData(string $property, $value, $locale) return $value; } - if (empty($locale)) { - return $value; + if (count($value) === 0) { + return null; } - if (count($value) === 0) { + if (empty($locale)) { return null; } - $index = array_search($locale, array_column($value, 'locale')); + $index = array_search($locale, array_column($value, 'locale'), true); if ($index === false) { return null; } @@ -176,16 +146,13 @@ protected function findLocaleAwareData(string $property, $value, $locale) return $value; } - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) + public function setConfiguration(array $configuration): void { - $defaultTypes = array_map(function ($value) { + $defaultTypes = array_map(static function ($value) { return [$value['name'], $value['tag']]; }, $this->getDefaultTypes()); - $defaultProperties = array_map(function ($value) { + $defaultProperties = array_map(static function ($value) { return [$value, $value]; }, $this->getDefaultProperties()); @@ -198,10 +165,7 @@ public function setConfiguration(array $configuration) $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ - public static function configureOptions(OptionsResolver $resolver) + public static function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'facebook_image_thumbnail' => null, @@ -217,12 +181,7 @@ public static function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('properties', ['array']); } - /** - * @param array $data - * - * @return string|null - */ - protected function getImagePath(array $data) + protected function getImagePath(array $data): ?string { $asset = Asset::getById($data['id']); @@ -233,10 +192,7 @@ protected function getImagePath(array $data) return $this->urlGenerator->generate($asset, ['thumbnail' => $this->configuration['facebook_image_thumbnail']]); } - /** - * @return array - */ - protected function getDefaultTypes() + protected function getDefaultTypes(): array { return [ [ @@ -250,10 +206,7 @@ protected function getDefaultTypes() ]; } - /** - * @return array - */ - protected function getDefaultProperties() + protected function getDefaultProperties(): array { return [ 'og:type', @@ -264,10 +217,7 @@ protected function getDefaultProperties() ]; } - /** - * @return array - */ - protected function getDefaultPresets() + protected function getDefaultPresets(): array { return [ [ diff --git a/src/SeoBundle/MetaData/Integrator/SchemaIntegrator.php b/src/SeoBundle/MetaData/Integrator/SchemaIntegrator.php index 11447da..eb7cce9 100644 --- a/src/SeoBundle/MetaData/Integrator/SchemaIntegrator.php +++ b/src/SeoBundle/MetaData/Integrator/SchemaIntegrator.php @@ -10,28 +10,15 @@ class SchemaIntegrator implements IntegratorInterface { - /** - * @var array - */ - protected $configuration; - - /** - * @var MetaDataProviderInterface - */ - protected $metaDataProvider; - - /** - * @param MetaDataProviderInterface $metaDataProvider - */ + protected array $configuration; + protected MetaDataProviderInterface $metaDataProvider; + public function __construct(MetaDataProviderInterface $metaDataProvider) { $this->metaDataProvider = $metaDataProvider; } - /** - * {@inheritdoc} - */ - public function getBackendConfiguration($element) + public function getBackendConfiguration(mixed $element): array { $useLocalizedFields = $element instanceof DataObject; $hasDynamicallyAddedJsonLdData = false; @@ -71,25 +58,19 @@ public function getBackendConfiguration($element) ]; } - /** - * {@inheritdoc} - */ - public function getPreviewParameter($element, ?string $template, array $data) + public function getPreviewParameter(mixed $element, ?string $template, array $data): array { return []; } - /** - * {@inheritdoc} - */ - public function validateBeforeBackend(string $elementType, int $elementId, array $data) + public function validateBeforeBackend(string $elementType, int $elementId, array $data): array { if (!is_array($data) || count($data) === 0) { return $data; } $schemaBlocksConfiguration = []; - $cleanData = function (array $schemaBlock) { + $cleanData = static function (array $schemaBlock) { $cleanData = json_encode($schemaBlock, JSON_PRETTY_PRINT); return sprintf('', $cleanData); @@ -118,10 +99,7 @@ public function validateBeforeBackend(string $elementType, int $elementId, array return $schemaBlocksConfiguration; } - /** - * {@inheritdoc} - */ - public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null) + public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null): ?array { if (is_array($data) && count($data) === 0) { return null; @@ -130,7 +108,7 @@ public function validateBeforePersist(string $elementType, int $elementId, array // assert identifier foreach ($data as $idx => $row) { if (!isset($row['identifier']) || empty($row['identifier'])) { - $data[$idx]['identifier'] = uniqid('si'); + $data[$idx]['identifier'] = uniqid('si', true); } } @@ -183,10 +161,7 @@ public function validateBeforePersist(string $elementType, int $elementId, array return $indexedData; } - /** - * {@inheritdoc} - */ - public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (count($data) === 0) { return; @@ -199,29 +174,17 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa } } - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) + public function setConfiguration(array $configuration): void { $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ - public static function configureOptions(OptionsResolver $resolver) + public static function configureOptions(OptionsResolver $resolver): void { // no options here. } - /** - * @param array $schemaBlock - * @param string $locale - * - * @return array|null - */ - protected function findLocaleAwareData(array $schemaBlock, $locale) + protected function findLocaleAwareData(array $schemaBlock, ?string $locale): ?array { if ($schemaBlock['localized'] === false) { return $schemaBlock['data']; @@ -235,7 +198,7 @@ protected function findLocaleAwareData(array $schemaBlock, $locale) return null; } - $index = array_search($locale, array_column($schemaBlock['data'], 'locale')); + $index = array_search($locale, array_column($schemaBlock['data'], 'locale'), true); if ($index === false) { return null; } @@ -248,12 +211,7 @@ protected function findLocaleAwareData(array $schemaBlock, $locale) return $value; } - /** - * @param string $data - * - * @return array|null - */ - protected function validateSchemaBlock($data) + protected function validateSchemaBlock(mixed $data): ?array { $validatedJsonData = null; @@ -279,14 +237,7 @@ protected function validateSchemaBlock($data) return $validatedJsonData; } - /** - * @param string $jsonLdData - * - * @return bool|array - * - * @throws \Exception - */ - protected function validateJsonLd(string $jsonLdData) + protected function validateJsonLd(string $jsonLdData): bool|array { $jsonLdData = preg_replace( '/[ \t\n]+/', @@ -310,12 +261,12 @@ protected function validateJsonLd(string $jsonLdData) $json = $jsonScripts->item(0)->nodeValue; } - $data = json_decode(trim($json), true); - - if ($data === null) { + try { + $data = json_decode(trim($json), true, 512, JSON_THROW_ON_ERROR); + } catch(\Throwable $e) { return false; } - return $data; + return $data ?? false; } } diff --git a/src/SeoBundle/MetaData/Integrator/TitleDescriptionIntegrator.php b/src/SeoBundle/MetaData/Integrator/TitleDescriptionIntegrator.php index ea7f6e6..d8cd3aa 100644 --- a/src/SeoBundle/MetaData/Integrator/TitleDescriptionIntegrator.php +++ b/src/SeoBundle/MetaData/Integrator/TitleDescriptionIntegrator.php @@ -10,29 +10,18 @@ class TitleDescriptionIntegrator implements IntegratorInterface { - /** - * @var array - */ - protected $configuration; - - /** - * {@inheritdoc} - */ - public function getBackendConfiguration($element) - { - $useLocalizedFields = $element instanceof DataObject; + protected array $configuration; + public function getBackendConfiguration($element): array + { return [ 'hasLivePreview' => true, 'livePreviewTemplates' => [], - 'useLocalizedFields' => $useLocalizedFields + 'useLocalizedFields' => $element instanceof DataObject ]; } - /** - * {@inheritdoc} - */ - public function getPreviewParameter($element, ?string $template, array $data) + public function getPreviewParameter(mixed $element, ?string $template, array $data): array { $url = 'http://localhost'; @@ -43,11 +32,11 @@ public function getPreviewParameter($element, ?string $template, array $data) } $author = 'John Doe'; - $title = isset($data['title']) ? $data['title'] : 'This is a title'; - $description = isset($data['description']) ? $data['description'] : 'This is a very long description which should be not too long.'; + $title = $data['title'] ?? 'This is a title'; + $description = $data['description'] ?? 'This is a very long description which should be not too long.'; return [ - 'path' => '@SeoBundle/Resources/views/preview/titleDescription/preview.html.twig', + 'path' => '@Seo/preview/titleDescription/preview.html.twig', 'params' => [ 'url' => $url, 'author' => $author, @@ -58,18 +47,12 @@ public function getPreviewParameter($element, ?string $template, array $data) ]; } - /** - * {@inheritdoc} - */ - public function validateBeforeBackend(string $elementType, int $elementId, array $data) + public function validateBeforeBackend(string $elementType, int $elementId, array $data): array { return $data; } - /** - * {@inheritdoc} - */ - public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null) + public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null): ?array { if ($elementType === 'object') { $data = $this->mergeStorageAndEditModeLocaleAwareData($data, $previousData); @@ -82,13 +65,7 @@ public function validateBeforePersist(string $elementType, int $elementId, array return $data; } - /** - * @param array $data - * @param array $previousData - * - * @return array - */ - protected function mergeStorageAndEditModeLocaleAwareData(array $data, ?array $previousData) + protected function mergeStorageAndEditModeLocaleAwareData(array $data, ?array $previousData): array { $arrayModifier = new ArrayHelper(); @@ -104,7 +81,7 @@ protected function mergeStorageAndEditModeLocaleAwareData(array $data, ?array $p foreach (['title', 'description'] as $type) { - $rebuildRow = isset($previousData[$type]) ? $previousData[$type] : []; + $rebuildRow = $previousData[$type] ?? []; if (!isset($data[$type]) || !is_array($data[$type])) { $newData[$type] = $rebuildRow; @@ -117,10 +94,7 @@ protected function mergeStorageAndEditModeLocaleAwareData(array $data, ?array $p return $newData; } - /** - * {@inheritdoc} - */ - public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetaData(mixed $element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (!empty($data['description'])) { if (null !== $value = $this->findLocaleAwareData($data['description'], $locale)) { @@ -135,27 +109,21 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa } } - /** - * @param array|string $value - * @param string $locale - * - * @return mixed|null - */ - protected function findLocaleAwareData($value, $locale) + protected function findLocaleAwareData(mixed $value, ?string $locale): int|float|string|bool|null { if (!is_array($value)) { return $value; } - if (empty($locale)) { + if (count($value) === 0) { return null; } - if (count($value) === 0) { + if (empty($locale)) { return null; } - $index = array_search($locale, array_column($value, 'locale')); + $index = array_search($locale, array_column($value, 'locale'), true); if ($index === false) { return null; } @@ -169,18 +137,12 @@ protected function findLocaleAwareData($value, $locale) return $value; } - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) + public function setConfiguration(array $configuration): void { $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ - public static function configureOptions(OptionsResolver $resolver) + public static function configureOptions(OptionsResolver $resolver): void { // no options here. } diff --git a/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php b/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php index 007f8df..8759d1d 100644 --- a/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php +++ b/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php @@ -11,51 +11,33 @@ class TwitterCardIntegrator implements IntegratorInterface { - /** - * @var array - */ - protected $configuration; - - /** - * @var UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * @param UrlGeneratorInterface $urlGenerator - */ + protected array $configuration; + protected UrlGeneratorInterface $urlGenerator; + public function __construct(UrlGeneratorInterface $urlGenerator) { $this->urlGenerator = $urlGenerator; } - /** - * {@inheritdoc} - */ - public function getBackendConfiguration($element) + public function getBackendConfiguration(mixed $element): array { - $useLocalizedFields = $element instanceof DataObject; - return [ 'hasLivePreview' => true, 'livePreviewTemplates' => [], 'properties' => $this->configuration['properties'], 'types' => $this->configuration['types'], - 'useLocalizedFields' => $useLocalizedFields, + 'useLocalizedFields' => $element instanceof DataObject, ]; } - /** - * {@inheritdoc} - */ - public function getPreviewParameter($element, ?string $template, array $data) + public function getPreviewParameter(mixed $element, ?string $template, array $data): array { if (null === $url = $this->urlGenerator->getCurrentSchemeAndHost()) { $url = 'http://localhost'; } - $title = isset($data['title']) ? $data['title'] : 'This is a title'; - $description = isset($data['description']) ? $data['description'] : 'This is a very long description which should be not too long.'; + $title = $data['title'] ?? 'This is a title'; + $description = $data['description'] ?? 'This is a very long description which should be not too long.'; $imagePath = 'bundles/seo/img/integrator/demoImage.jpg'; if (isset($data['image']) && is_array($data['image'])) { @@ -65,7 +47,7 @@ public function getPreviewParameter($element, ?string $template, array $data) } return [ - 'path' => '@SeoBundle/Resources/views/preview/twitterCard/preview.html.twig', + 'path' => '@Seo/preview/twitterCard/preview.html.twig', 'params' => [ 'title' => $title, 'description' => $description, @@ -75,10 +57,7 @@ public function getPreviewParameter($element, ?string $template, array $data) ]; } - /** - * {@inheritdoc} - */ - public function validateBeforeBackend(string $elementType, int $elementId, array $data) + public function validateBeforeBackend(string $elementType, int $elementId, array $data): array { foreach ($data as &$twitterItem) { if ($twitterItem['name'] === 'twitter:image' && isset($twitterItem['value']['thumbPath'])) { @@ -89,10 +68,7 @@ public function validateBeforeBackend(string $elementType, int $elementId, array return $data; } - /** - * {@inheritdoc} - */ - public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null) + public function validateBeforePersist(string $elementType, int $elementId, array $data, $previousData = null): ?array { if ($elementType === 'object') { $arrayModifier = new ArrayHelper(); @@ -106,10 +82,7 @@ public function validateBeforePersist(string $elementType, int $elementId, array return $data; } - /** - * {@inheritdoc} - */ - public function updateMetaData($element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata) + public function updateMetaData(mixed $element, array $data, ?string $locale, SeoMetaDataInterface $seoMetadata): void { if (count($data) === 0) { return; @@ -126,14 +99,7 @@ public function updateMetaData($element, array $data, ?string $locale, SeoMetaDa } } - /** - * @param string $property - * @param array|string $value - * @param string $locale - * - * @return string|null - */ - protected function findLocaleAwareData(string $property, $value, $locale) + protected function findLocaleAwareData(string $property, mixed $value, ?string $locale): int|float|string|bool|null { if ($property === 'twitter:image') { return isset($value['id']) && is_numeric($value['id']) ? $this->getImagePath($value) : null; @@ -143,15 +109,15 @@ protected function findLocaleAwareData(string $property, $value, $locale) return $value; } - if (empty($locale)) { - return $value; + if (count($value) === 0) { + return null; } - if (count($value) === 0) { + if (empty($locale)) { return null; } - $index = array_search($locale, array_column($value, 'locale')); + $index = array_search($locale, array_column($value, 'locale'), true); if ($index === false) { return null; } @@ -165,16 +131,13 @@ protected function findLocaleAwareData(string $property, $value, $locale) return $value; } - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) + public function setConfiguration(array $configuration): void { - $defaultTypes = array_map(function ($value) { + $defaultTypes = array_map(static function ($value) { return [$value['name'], $value['tag']]; }, $this->getDefaultTypes()); - $defaultProperties = array_map(function ($value) { + $defaultProperties = array_map(static function ($value) { return [$value, $value]; }, $this->getDefaultProperties()); @@ -184,10 +147,7 @@ public function setConfiguration(array $configuration) $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ - public static function configureOptions(OptionsResolver $resolver) + public static function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'twitter_image_thumbnail' => null, @@ -200,12 +160,7 @@ public static function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('properties', ['array']); } - /** - * @param array $data - * - * @return string|null - */ - protected function getImagePath(array $data) + protected function getImagePath(array $data): ?string { $asset = Asset::getById($data['id']); @@ -216,10 +171,7 @@ protected function getImagePath(array $data) return $this->urlGenerator->generate($asset, ['thumbnail' => $this->configuration['twitter_image_thumbnail']]); } - /** - * @return array - */ - protected function getDefaultTypes() + protected function getDefaultTypes(): array { return [ [ @@ -241,10 +193,7 @@ protected function getDefaultTypes() ]; } - /** - * @return array - */ - protected function getDefaultProperties() + protected function getDefaultProperties(): array { return [ 'twitter:card', diff --git a/src/SeoBundle/MetaData/MetaDataProvider.php b/src/SeoBundle/MetaData/MetaDataProvider.php index 84790cc..a6f7126 100755 --- a/src/SeoBundle/MetaData/MetaDataProvider.php +++ b/src/SeoBundle/MetaData/MetaDataProvider.php @@ -2,8 +2,8 @@ namespace SeoBundle\MetaData; -use Pimcore\Templating\Helper\HeadMeta; -use Pimcore\Templating\Helper\HeadTitle; +use Pimcore\Twig\Extension\Templating\HeadMeta; +use Pimcore\Twig\Extension\Templating\HeadTitle; use SeoBundle\MetaData\Extractor\ExtractorInterface; use SeoBundle\Middleware\MiddlewareDispatcherInterface; use SeoBundle\Registry\MetaDataExtractorRegistryInterface; @@ -11,32 +11,11 @@ class MetaDataProvider implements MetaDataProviderInterface { - /** - * @var HeadMeta - */ - protected $headMeta; - - /** - * @var HeadTitle - */ - protected $headTitle; + protected HeadMeta $headMeta; + protected HeadTitle $headTitle; + protected MetaDataExtractorRegistryInterface $extractorRegistry; + protected MiddlewareDispatcherInterface $middlewareDispatcher; - /** - * @var MetaDataExtractorRegistryInterface - */ - protected $extractorRegistry; - - /** - * @var MiddlewareDispatcherInterface - */ - protected $middlewareDispatcher; - - /** - * @param HeadMeta $headMeta - * @param HeadTitle $headTitle - * @param MetaDataExtractorRegistryInterface $extractorRegistry - * @param MiddlewareDispatcherInterface $middlewareDispatcher - */ public function __construct( HeadMeta $headMeta, HeadTitle $headTitle, @@ -49,10 +28,7 @@ public function __construct( $this->middlewareDispatcher = $middlewareDispatcher; } - /** - * {@inheritdoc} - */ - public function updateSeoElement($element, ?string $locale) + public function updateSeoElement($element, ?string $locale): void { $seoMetadata = $this->getSeoMetaData($element, $locale); @@ -98,13 +74,7 @@ public function updateSeoElement($element, ?string $locale) } } - /** - * @param mixed $element - * @param string|null $locale - * - * @return SeoMetaData - */ - protected function getSeoMetaData($element, ?string $locale) + protected function getSeoMetaData(mixed $element, ?string $locale): SeoMetaData { $seoMetaData = new SeoMetaData($this->middlewareDispatcher); $extractors = $this->getExtractorsForElement($element); @@ -119,13 +89,11 @@ protected function getSeoMetaData($element, ?string $locale) } /** - * @param object $element - * - * @return ExtractorInterface[] + * @return array */ - protected function getExtractorsForElement($element) + protected function getExtractorsForElement($element): array { - return array_filter($this->extractorRegistry->getAll(), function (ExtractorInterface $extractor) use ($element) { + return array_filter($this->extractorRegistry->getAll(), static function (ExtractorInterface $extractor) use ($element) { return $extractor->supports($element); }); } diff --git a/src/SeoBundle/MetaData/MetaDataProviderInterface.php b/src/SeoBundle/MetaData/MetaDataProviderInterface.php index f649e69..f7c0a6a 100755 --- a/src/SeoBundle/MetaData/MetaDataProviderInterface.php +++ b/src/SeoBundle/MetaData/MetaDataProviderInterface.php @@ -4,9 +4,5 @@ interface MetaDataProviderInterface { - /** - * @param object $element - * @param string|null $locale - */ - public function updateSeoElement($element, ?string $locale); + public function updateSeoElement(mixed $element, ?string $locale): void; } diff --git a/src/SeoBundle/Middleware/Middleware.php b/src/SeoBundle/Middleware/Middleware.php index 08c77b2..a4b0a69 100644 --- a/src/SeoBundle/Middleware/Middleware.php +++ b/src/SeoBundle/Middleware/Middleware.php @@ -4,30 +4,16 @@ class Middleware implements MiddlewareInterface { - /** - * @var string - */ - private $identifier; + private string $identifier; + private MiddlewareDispatcher $middlewareDispatcher; - /** - * @var MiddlewareDispatcher - */ - private $middlewareDispatcher; - - /** - * @param string $identifier - * @param MiddlewareDispatcher $middlewareDispatcher - */ public function __construct(string $identifier, MiddlewareDispatcher $middlewareDispatcher) { $this->identifier = $identifier; $this->middlewareDispatcher = $middlewareDispatcher; } - /** - * {@inheritdoc} - */ - public function addTask($callback) + public function addTask(callable $callback): void { $this->middlewareDispatcher->registerTask($callback, $this->identifier); } diff --git a/src/SeoBundle/Middleware/MiddlewareAdapterInterface.php b/src/SeoBundle/Middleware/MiddlewareAdapterInterface.php index a1bb807..582ca87 100644 --- a/src/SeoBundle/Middleware/MiddlewareAdapterInterface.php +++ b/src/SeoBundle/Middleware/MiddlewareAdapterInterface.php @@ -8,15 +8,12 @@ interface MiddlewareAdapterInterface { /** * Boot your middleware. - * * This method gets called once per request - if middleware gets involved at all! */ - public function boot(); + public function boot(): void; /** * Array with all arguments to inject them into a task. - * - * @return array */ public function getTaskArguments(): array; @@ -27,8 +24,6 @@ public function getTaskArguments(): array; * * After all extractors have been dispatched, the called adapter is allowed to modify the SeoMetaDataInterface * before its data gets appended to the documents head. - * - * @param SeoMetaDataInterface $seoMetadata */ - public function onFinish(SeoMetaDataInterface $seoMetadata); + public function onFinish(SeoMetaDataInterface $seoMetadata): void; } diff --git a/src/SeoBundle/Middleware/MiddlewareDispatcher.php b/src/SeoBundle/Middleware/MiddlewareDispatcher.php index 3da1473..839c7ad 100644 --- a/src/SeoBundle/Middleware/MiddlewareDispatcher.php +++ b/src/SeoBundle/Middleware/MiddlewareDispatcher.php @@ -6,20 +6,9 @@ class MiddlewareDispatcher implements MiddlewareDispatcherInterface { - /** - * @var MiddlewareAdapterInterface[] - */ - protected $middlewareAdapterStack; - - /** - * @var array - */ - protected $middleware; - - /** - * @var array - */ - protected $tasks; + protected array $middlewareAdapterStack; + protected array $middleware; + protected array $tasks; public function __construct() { @@ -28,18 +17,12 @@ public function __construct() $this->tasks = []; } - /** - * {@inheritdoc} - */ - public function registerMiddlewareAdapter(string $identifier, MiddlewareAdapterInterface $middlewareAdapter) + public function registerMiddlewareAdapter(string $identifier, MiddlewareAdapterInterface $middlewareAdapter): void { $this->middlewareAdapterStack[$identifier] = $middlewareAdapter; } - /** - * {@inheritdoc} - */ - public function buildMiddleware(string $identifier, SeoMetaDataInterface $seoMetaData) + public function buildMiddleware(string $identifier, SeoMetaDataInterface $seoMetaData): MiddlewareInterface { if (!isset($this->middlewareAdapterStack[$identifier])) { throw new \Exception(sprintf('SEO MetaData middleware "%s" not registered.', $identifier)); @@ -55,10 +38,7 @@ public function buildMiddleware(string $identifier, SeoMetaDataInterface $seoMet return $this->middleware[$identifier]; } - /** - * {@inheritdoc} - */ - public function registerTask(callable $callback, string $identifier) + public function registerTask(callable $callback, string $identifier): void { if (!is_callable($callback)) { return; @@ -70,10 +50,7 @@ public function registerTask(callable $callback, string $identifier) ]; } - /** - * {@inheritdoc} - */ - public function dispatchTasks(SeoMetaDataInterface $seoMetadata) + public function dispatchTasks(SeoMetaDataInterface $seoMetadata): void { foreach ($this->tasks as $immediateTask) { $middlewareAdapter = $this->middlewareAdapterStack[$immediateTask['identifier']]; @@ -84,10 +61,7 @@ public function dispatchTasks(SeoMetaDataInterface $seoMetadata) $this->tasks = []; } - /** - * {@inheritdoc} - */ - public function dispatchMiddlewareFinisher(SeoMetaDataInterface $seoMetadata) + public function dispatchMiddlewareFinisher(SeoMetaDataInterface $seoMetadata): void { foreach ($this->middleware as $identifier => $middleware) { $middlewareAdapter = $this->middlewareAdapterStack[$identifier]; diff --git a/src/SeoBundle/Middleware/MiddlewareDispatcherInterface.php b/src/SeoBundle/Middleware/MiddlewareDispatcherInterface.php index cae6325..b5095f2 100644 --- a/src/SeoBundle/Middleware/MiddlewareDispatcherInterface.php +++ b/src/SeoBundle/Middleware/MiddlewareDispatcherInterface.php @@ -6,33 +6,13 @@ interface MiddlewareDispatcherInterface { - /** - * @param string $identifier - * @param MiddlewareAdapterInterface $middlewareAdapter - */ - public function registerMiddlewareAdapter(string $identifier, MiddlewareAdapterInterface $middlewareAdapter); + public function registerMiddlewareAdapter(string $identifier, MiddlewareAdapterInterface $middlewareAdapter): void; - /** - * @param string $identifier - * @param SeoMetaDataInterface $seoMetaData - * - * @return MiddlewareAdapterInterface - */ - public function buildMiddleware(string $identifier, SeoMetaDataInterface $seoMetaData); + public function buildMiddleware(string $identifier, SeoMetaDataInterface $seoMetaData): MiddlewareInterface; - /** - * @param callable $callback - * @param string $identifier - */ - public function registerTask(callable $callback, string $identifier); + public function registerTask(callable $callback, string $identifier): void; - /** - * @param SeoMetaDataInterface $seoMetadata - */ - public function dispatchTasks(SeoMetaDataInterface $seoMetadata); + public function dispatchTasks(SeoMetaDataInterface $seoMetadata): void; - /** - * @param SeoMetaDataInterface $seoMetadata - */ - public function dispatchMiddlewareFinisher(SeoMetaDataInterface $seoMetadata); + public function dispatchMiddlewareFinisher(SeoMetaDataInterface $seoMetadata): void; } diff --git a/src/SeoBundle/Middleware/MiddlewareInterface.php b/src/SeoBundle/Middleware/MiddlewareInterface.php index 3e742fd..07ae41a 100644 --- a/src/SeoBundle/Middleware/MiddlewareInterface.php +++ b/src/SeoBundle/Middleware/MiddlewareInterface.php @@ -4,10 +4,5 @@ interface MiddlewareInterface { - /** - * @param callable $callback - * - * @return mixed - */ - public function addTask($callback); + public function addTask(callable $callback): void; } diff --git a/src/SeoBundle/Migrations/.gitkeep b/src/SeoBundle/Migrations/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/SeoBundle/Migrations/Version00000001.php b/src/SeoBundle/Migrations/Version00000001.php deleted file mode 100644 index 0a12113..0000000 --- a/src/SeoBundle/Migrations/Version00000001.php +++ /dev/null @@ -1,33 +0,0 @@ -getMessage())); - } - } - } - - /** - * @param Schema $schema - */ - public function down(Schema $schema) - { - // this down() migration is auto-generated, please modify it to your needs - } -} diff --git a/src/SeoBundle/Model/ElementMetaData.php b/src/SeoBundle/Model/ElementMetaData.php index 6d00fd2..f0935ee 100644 --- a/src/SeoBundle/Model/ElementMetaData.php +++ b/src/SeoBundle/Model/ElementMetaData.php @@ -4,107 +4,58 @@ class ElementMetaData implements ElementMetaDataInterface { - /** - * @var int - */ - protected $id; + protected ?int $id = null; + protected string $elementType; + protected int $elementId; + protected string $integrator; + protected array $data = []; - /** - * @var string - */ - protected $elementType; - - /** - * @var int - */ - protected $elementId; - - /** - * @var string - */ - protected $integrator; - - /** - * @var array - */ - protected $data; - - /** - * {@inheritdoc} - */ - public function setId(string $id) + public function setId(int $id): void { $this->id = $id; } - /** - * {@inheritdoc} - */ - public function getId() + public function getId(): ?int { return $this->id; } - /** - * {@inheritdoc} - */ - public function setElementType(string $elementType) + public function setElementType(string $elementType): void { $this->elementType = $elementType; } - /** - * {@inheritdoc} - */ - public function getElementType() + public function getElementType(): string { return $this->elementType; } - /** - * {@inheritdoc} - */ - public function setElementId($elementId) + public function setElementId($elementId): void { $this->elementId = $elementId; } - /** - * {@inheritdoc} - */ - public function getElementId() + public function getElementId(): int { return $this->elementId; } - /** - * {@inheritdoc} - */ - public function setIntegrator(string $integrator) + public function setIntegrator(string $integrator): void { $this->integrator = $integrator; } - /** - * {@inheritdoc} - */ - public function getIntegrator() + public function getIntegrator(): string { return $this->integrator; } - /** - * {@inheritdoc} - */ - public function setData(array $data) + public function setData(array $data): void { $this->data = $data; } - /** - * {@inheritdoc} - */ - public function getData() + public function getData(): array { return $this->data; } diff --git a/src/SeoBundle/Model/ElementMetaDataInterface.php b/src/SeoBundle/Model/ElementMetaDataInterface.php index f4abf22..77328db 100644 --- a/src/SeoBundle/Model/ElementMetaDataInterface.php +++ b/src/SeoBundle/Model/ElementMetaDataInterface.php @@ -4,48 +4,21 @@ interface ElementMetaDataInterface { - /** - * @return string - */ - public function getId(); - - /** - * @param string $elementType - */ - public function setElementType(string $elementType); - - /** - * @return string - */ - public function getElementType(); - - /** - * @param int $elementId - */ - public function setElementId(int $elementId); - - /** - * @return int - */ - public function getElementId(); - - /** - * @param string $integrator - */ - public function setIntegrator(string $integrator); - - /** - * @return string - */ - public function getIntegrator(); - - /** - * @param array $data - */ - public function setData(array $data); - - /** - * @return array - */ - public function getData(); + public function getId(): ?int; + + public function setElementType(string $elementType): void; + + public function getElementType(): string; + + public function setElementId(int $elementId): void; + + public function getElementId(): int; + + public function setIntegrator(string $integrator): void; + + public function getIntegrator(): string; + + public function setData(array $data): void; + + public function getData(): array; } diff --git a/src/SeoBundle/Model/QueueEntry.php b/src/SeoBundle/Model/QueueEntry.php index 7234f3a..1fc9bc9 100644 --- a/src/SeoBundle/Model/QueueEntry.php +++ b/src/SeoBundle/Model/QueueEntry.php @@ -4,170 +4,91 @@ class QueueEntry implements QueueEntryInterface { - /** - * @var string - */ - protected $uuid; - - /** - * @var string - */ - protected $type; - - /** - * @var string - */ - protected $dataType; - - /** - * @var int - */ - protected $dataId; - - /** - * @var string - */ - protected $dataUrl; - - /** - * @var string - */ - protected $worker; - - /** - * @var string - */ - protected $resourceProcessor; - - /** - * @var \DateTime - */ - protected $creationDate; - - /** - * {@inheritdoc} - */ - public function setUuid(string $uuid) + protected string $uuid; + protected string $type; + protected string $dataType; + protected int $dataId; + protected string $dataUrl; + protected string $worker; + protected string $resourceProcessor; + protected \DateTime $creationDate; + + public function setUuid(string $uuid): void { $this->uuid = $uuid; } - /** - * {@inheritdoc} - */ - public function getUuid() + public function getUuid(): string { return $this->uuid; } - /** - * {@inheritdoc} - */ - public function setType(string $type) + public function setType(string $type): void { $this->type = $type; } - /** - * {@inheritdoc} - */ - public function getType() + public function getType(): string { return $this->type; } - /** - * {@inheritdoc} - */ - public function setDataId($dataId) + public function setDataId($dataId): void { $this->dataId = $dataId; } - /** - * {@inheritdoc} - */ - public function getDataId() + public function getDataId(): int { return $this->dataId; } - /** - * {@inheritdoc} - */ - public function setDataType(string $dataType) + public function setDataType(string $dataType): void { $this->dataType = $dataType; } - /** - * {@inheritdoc} - */ - public function getDataType() + public function getDataType(): string { return $this->dataType; } - /** - * {@inheritdoc} - */ - public function setDataUrl(string $dataUrl) + public function setDataUrl(string $dataUrl): void { $this->dataUrl = $dataUrl; } - /** - * {@inheritdoc} - */ - public function getDataUrl() + public function getDataUrl(): string { return $this->dataUrl; } - /** - * {@inheritdoc} - */ - public function setWorker(string $worker) + public function setWorker(string $worker): void { $this->worker = $worker; } - /** - * {@inheritdoc} - */ - public function getWorker() + public function getWorker(): string { return $this->worker; } - /** - * {@inheritdoc} - */ - public function setResourceProcessor(string $resourceProcessor) + public function setResourceProcessor(string $resourceProcessor): void { $this->resourceProcessor = $resourceProcessor; } - /** - * {@inheritdoc} - */ - public function getResourceProcessor() + public function getResourceProcessor(): string { return $this->resourceProcessor; } - /** - * {@inheritdoc} - */ - public function setCreationDate(\DateTime $date) + public function setCreationDate(\DateTime $date): void { $this->creationDate = $date; } - /** - * {@inheritdoc} - */ - public function getCreationDate() + public function getCreationDate(): \DateTime { return $this->creationDate; } diff --git a/src/SeoBundle/Model/QueueEntryInterface.php b/src/SeoBundle/Model/QueueEntryInterface.php index d4b3272..5d0c0da 100644 --- a/src/SeoBundle/Model/QueueEntryInterface.php +++ b/src/SeoBundle/Model/QueueEntryInterface.php @@ -4,78 +4,33 @@ interface QueueEntryInterface { - /** - * @return string - */ - public function getUuid(); - - /** - * @param string $type - */ - public function setType(string $type); - - /** - * @return string - */ - public function getType(); - - /** - * @param int $dataId - */ - public function setDataId($dataId); - - /** - * @return int - */ - public function getDataId(); - - /** - * @param string $dataType - */ - public function setDataType(string $dataType); - - /** - * @return string - */ - public function getDataType(); - - /** - * @param string $dataUrl - */ - public function setDataUrl(string $dataUrl); - - /** - * @return string - */ - public function getDataUrl(); - - /** - * @param string $worker - */ - public function setWorker(string $worker); - - /** - * @return string - */ - public function getWorker(); - - /** - * @param string $resourceProcessor - */ - public function setResourceProcessor(string $resourceProcessor); - - /** - * @return string - */ - public function getResourceProcessor(); - - /** - * @param \DateTime $date - */ - public function setCreationDate(\DateTime $date); - - /** - * @return \DateTime - */ - public function getCreationDate(); + public function getUuid(): string; + + public function setType(string $type): void; + + public function getType(): string; + + public function setDataId(int $dataId): void; + + public function getDataId(): int; + + public function setDataType(string $dataType): void; + + public function getDataType(): string; + + public function setDataUrl(string $dataUrl): void; + + public function getDataUrl(): string; + + public function setWorker(string $worker): void; + + public function getWorker(): string; + + public function setResourceProcessor(string $resourceProcessor): void; + + public function getResourceProcessor(): string; + + public function setCreationDate(\DateTime $date): void; + + public function getCreationDate(): \DateTime; } diff --git a/src/SeoBundle/Model/SeoMetaData.php b/src/SeoBundle/Model/SeoMetaData.php index 56a3463..c045649 100755 --- a/src/SeoBundle/Model/SeoMetaData.php +++ b/src/SeoBundle/Model/SeoMetaData.php @@ -3,281 +3,163 @@ namespace SeoBundle\Model; use SeoBundle\Middleware\MiddlewareDispatcherInterface; +use SeoBundle\Middleware\MiddlewareInterface; class SeoMetaData implements SeoMetaDataInterface { - /** - * @var MiddlewareDispatcherInterface - */ - private $middlewareDispatcher; + private MiddlewareDispatcherInterface $middlewareDispatcher; + + private int $id; + private string $originalUrl; + private string $metaDescription = ''; + private string $title = ''; + private array $extraProperties = []; + private array $extraNames = []; + private array $extraHttp = []; + private array $schema = []; /** - * @param MiddlewareDispatcherInterface $middlewareDispatcher + * @deprecated */ + private array $raw = []; + public function __construct(MiddlewareDispatcherInterface $middlewareDispatcher) { $this->middlewareDispatcher = $middlewareDispatcher; } - /** - * @var string - */ - private $id; - - /** - * @var string - */ - private $originalUrl; - - /** - * @var string - */ - private $metaDescription; - - /** - * @var string - */ - private $title; - - /** - * @var array - */ - private $extraProperties = []; - - /** - * @var array - */ - private $extraNames = []; - - /** - * @var array - */ - private $extraHttp = []; - - /** - * @var array - */ - private $schema = []; - - /** - * @deprecated - * - * @var array - */ - private $raw = []; - - /** - * @param int $id - */ - public function setId($id) + public function setId(int $id): void { $this->id = $id; } - /** - * @return int - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * {@inheritdoc} - */ - public function getMiddleware(string $middlewareAdapterName) + public function getMiddleware(string $middlewareAdapterName): MiddlewareInterface { return $this->middlewareDispatcher->buildMiddleware($middlewareAdapterName, $this); } - /** - * {@inheritdoc} - */ - public function setMetaDescription($metaDescription) + public function setMetaDescription($metaDescription): void { $this->metaDescription = $metaDescription; } - /** - * {@inheritdoc} - */ - public function getMetaDescription() + public function getMetaDescription(): string { return $this->metaDescription; } - /** - * {@inheritdoc} - */ - public function setOriginalUrl($originalUrl) + public function setOriginalUrl(string $originalUrl): void { $this->originalUrl = $originalUrl; } - /** - * {@inheritdoc} - */ - public function getOriginalUrl() + public function getOriginalUrl(): string { return $this->originalUrl; } - /** - * {@inheritdoc} - */ - public function setTitle($title) + public function setTitle($title): void { $this->title = $title; } - /** - * {@inheritdoc} - */ - public function getTitle() + public function getTitle(): string { return $this->title; } - /** - * {@inheritdoc} - */ - public function setExtraProperties($extraProperties) + public function setExtraProperties(array|\Traversable $extraProperties): void { $this->extraProperties = $this->toArray($extraProperties); } - /** - * {@inheritdoc} - */ - public function getExtraProperties() + public function getExtraProperties(): array { return $this->extraProperties; } - /** - * {@inheritdoc} - */ - public function addExtraProperty($key, $value) + public function addExtraProperty($key, $value): void { $this->extraProperties[$key] = (string) $value; } - /** - * {@inheritdoc} - */ - public function removeExtraProperty($key) + public function removeExtraProperty($key): void { if (array_key_exists($key, $this->extraProperties)) { unset($this->extraProperties[$key]); } } - /** - * {@inheritdoc} - */ - public function setExtraNames($extraNames) + public function setExtraNames(array|\Traversable $extraNames): void { $this->extraNames = $this->toArray($extraNames); } - /** - * {@inheritdoc} - */ - public function getExtraNames() + public function getExtraNames(): array { return $this->extraNames; } - /** - * {@inheritdoc} - */ - public function addExtraName($key, $value) + public function addExtraName(string $key, string $value): void { - $this->extraNames[$key] = (string) $value; + $this->extraNames[$key] = $value; } - /** - * {@inheritdoc} - */ - public function removeExtraName($key) + public function removeExtraName(string $key): void { if (array_key_exists($key, $this->extraNames)) { unset($this->extraNames[$key]); } } - /** - * {@inheritdoc} - */ - public function setExtraHttp($extraHttp) + public function setExtraHttp(array|\Traversable $extraHttp): void { $this->extraHttp = $this->toArray($extraHttp); } - /** - * {@inheritdoc} - */ - public function getExtraHttp() + public function getExtraHttp(): array { return $this->extraHttp; } - /** - * {@inheritdoc} - */ - public function addExtraHttp($key, $value) + public function addExtraHttp(string $key, string $value): void { $this->extraHttp[$key] = (string) $value; } - /** - * {@inheritdoc} - */ - public function removeExtraHttp($key) + public function removeExtraHttp(string $key): void { if (array_key_exists($key, $this->extraHttp)) { unset($this->extraHttp[$key]); } } - /** - * {@inheritdoc} - */ - public function getSchema() + public function getSchema(): array { return $this->schema; } - /** - * {@inheritdoc} - */ - public function addSchema(array $schemaJsonLd) + public function addSchema(array $schemaJsonLd): void { $this->schema[] = $schemaJsonLd; } - /** - * {@inheritdoc} - */ - public function getRaw() + public function getRaw(): array { return $this->raw; } - /** - * {@inheritdoc} - */ - public function addRaw(string $value) + public function addRaw(string $value): void { $this->raw[] = $value; } - /** - * @param mixed $data - * - * @return array - */ - private function toArray($data) + private function toArray(mixed $data): array { if (is_array($data)) { return $data; diff --git a/src/SeoBundle/Model/SeoMetaDataInterface.php b/src/SeoBundle/Model/SeoMetaDataInterface.php index b958b90..ebf9225 100644 --- a/src/SeoBundle/Model/SeoMetaDataInterface.php +++ b/src/SeoBundle/Model/SeoMetaDataInterface.php @@ -7,120 +7,59 @@ interface SeoMetaDataInterface { /** - * @param string $middlewareAdapterName - * - * @return MiddlewareInterface - * * @throws \Exception */ - public function getMiddleware(string $middlewareAdapterName); + public function getMiddleware(string $middlewareAdapterName): MiddlewareInterface; - /** - * @param string $metaDescription - */ - public function setMetaDescription($metaDescription); + public function setMetaDescription(string $metaDescription): void; - /** - * @return string - */ - public function getMetaDescription(); + public function getMetaDescription(): string; - /** - * @param string $originalUrl - */ - public function setOriginalUrl($originalUrl); + public function setOriginalUrl(string $originalUrl): void; - /** - * @return string - */ - public function getOriginalUrl(); + public function getOriginalUrl(): string; - /** - * @param string $title - */ - public function setTitle($title); + public function setTitle(string $title): void; - /** - * @return string - */ - public function getTitle(); + public function getTitle(): string; - /** - * @param array|\Traversable $extraProperties - */ - public function setExtraProperties($extraProperties); + public function setExtraProperties(array|\Traversable $extraProperties): void; - /** - * @param array|\Traversable $extraNames - */ - public function setExtraNames($extraNames); + public function setExtraNames(array|\Traversable $extraNames): void; - /** - * @param array|\Traversable $extraHttp - */ - public function setExtraHttp($extraHttp); + public function setExtraHttp(array|\Traversable $extraHttp): void; - /** - * @return array - */ - public function getExtraProperties(); + public function getExtraProperties(): array; - /** - * @return array - */ - public function getExtraNames(); + public function getExtraNames(): array; - /** - * @return array - */ - public function getExtraHttp(); + public function getExtraHttp(): array; - /** - * @param string $key - * @param string $value - */ - public function addExtraProperty($key, $value); + public function addExtraProperty(string $key, string $value); - /** - * @param string $key - * @param string $value - */ - public function addExtraName($key, $value); + public function addExtraName(string $key, string $value); - /** - * @param string $key - * @param string $value - */ - public function addExtraHttp($key, $value); + public function addExtraHttp(string $key, string $value); - /** - * @return array - */ - public function getSchema(); + public function getSchema(): array; - /** - * @param array $schemaJsonLd - */ - public function addSchema(array $schemaJsonLd); + public function addSchema(array $schemaJsonLd): void; /** - * @return array - * - * @internal Do not use this method! + * Do not use this method! + * It's required to allow a seamless migration from old pimcore installations. * + * @internal * @deprecated */ - public function getRaw(); + public function getRaw(): array; /** * Do not use this method! * It's required to allow a seamless migration from old pimcore installations. * - * @param string $value - * - * @deprecated - * * @internal + * @deprecated */ - public function addRaw(string $value); + public function addRaw(string $value): void; } diff --git a/src/SeoBundle/Queue/QueueDataProcessor.php b/src/SeoBundle/Queue/QueueDataProcessor.php index 2bcf669..df9a77a 100644 --- a/src/SeoBundle/Queue/QueueDataProcessor.php +++ b/src/SeoBundle/Queue/QueueDataProcessor.php @@ -10,20 +10,9 @@ class QueueDataProcessor implements QueueDataProcessorInterface { protected const LOCK_KEY = 'process_index'; - /** - * @var QueueManagerInterface - */ - protected $queueManager; - - /** - * @var LoggerInterface - */ - protected $logger; - - /** - * @param QueueManagerInterface $queueManager - * @param LoggerInterface $logger - */ + protected QueueManagerInterface $queueManager; + protected LoggerInterface $logger; + public function __construct( QueueManagerInterface $queueManager, LoggerInterface $logger @@ -32,10 +21,7 @@ public function __construct( $this->logger = $logger; } - /** - * @param array $options - */ - public function process(array $options) + public function process(array $options): void { if ($this->isLocked(self::LOCK_KEY)) { return; @@ -52,18 +38,12 @@ public function process(array $options) $this->unlock(self::LOCK_KEY); } - /** - * {@inheritdoc} - */ - public function isLocked(string $token) + public function isLocked(string $token): bool { return $this->getLockToken($token) instanceof TmpStore; } - /** - * {@inheritdoc} - */ - public function getLockMessage(string $token) + public function getLockMessage(string $token): string { if (!$this->isLocked($token)) { return 'not-locked'; @@ -83,10 +63,7 @@ public function getLockMessage(string $token) ); } - /** - * {@inheritdoc} - */ - protected function lock(string $token, string $executor, $lifeTime = 14400) + protected function lock(string $token, string $executor, $lifeTime = 14400): void { if ($this->isLocked($token)) { return; @@ -95,31 +72,17 @@ protected function lock(string $token, string $executor, $lifeTime = 14400) TmpStore::add($this->getNamespacedToken($token), $executor, null, $lifeTime); } - /** - * {@inheritdoc} - */ - protected function unlock(string $token) + protected function unlock(string $token): void { TmpStore::delete($this->getNamespacedToken($token)); } - /** - * @param string $token - * - * @return TmpStore|null - */ - protected function getLockToken(string $token) + protected function getLockToken(string $token): ?TmpStore { return TmpStore::get($this->getNamespacedToken($token)); } - /** - * @param string $token - * @param string $namespace - * - * @return string - */ - protected function getNamespacedToken(string $token, string $namespace = 'seo') + protected function getNamespacedToken(string $token, string $namespace = 'seo'): string { return sprintf('%s_%s', $namespace, $token); } diff --git a/src/SeoBundle/Queue/QueueDataProcessorInterface.php b/src/SeoBundle/Queue/QueueDataProcessorInterface.php index 50f3ce4..fdc495a 100644 --- a/src/SeoBundle/Queue/QueueDataProcessorInterface.php +++ b/src/SeoBundle/Queue/QueueDataProcessorInterface.php @@ -4,8 +4,5 @@ interface QueueDataProcessorInterface { - /** - * @param array $options - */ - public function process(array $options); + public function process(array $options): void; } diff --git a/src/SeoBundle/Registry/IndexWorkerRegistry.php b/src/SeoBundle/Registry/IndexWorkerRegistry.php index 5ca66b8..43d8fa6 100644 --- a/src/SeoBundle/Registry/IndexWorkerRegistry.php +++ b/src/SeoBundle/Registry/IndexWorkerRegistry.php @@ -6,16 +6,9 @@ class IndexWorkerRegistry implements IndexWorkerRegistryInterface { - /** - * @var array - */ - protected $services; - - /** - * @param IndexWorkerInterface $service - * @param string $identifier - */ - public function register($service, $identifier) + protected array $services = []; + + public function register(mixed $service, string $identifier): void { if (!in_array(IndexWorkerInterface::class, class_implements($service), true)) { throw new \InvalidArgumentException( @@ -26,18 +19,12 @@ public function register($service, $identifier) $this->services[$identifier] = $service; } - /** - * {@inheritdoc} - */ - public function has($identifier) + public function has($identifier): bool { return isset($this->services[$identifier]); } - /** - * {@inheritdoc} - */ - public function get($identifier) + public function get($identifier): IndexWorkerInterface { if (!$this->has($identifier)) { throw new \Exception('"' . $identifier . '" Index Worker does not exist'); @@ -46,10 +33,7 @@ public function get($identifier) return $this->services[$identifier]; } - /** - * {@inheritdoc} - */ - public function getAll() + public function getAll(): array { return is_array($this->services) ? $this->services : []; } diff --git a/src/SeoBundle/Registry/IndexWorkerRegistryInterface.php b/src/SeoBundle/Registry/IndexWorkerRegistryInterface.php index 6325ffd..ba06fa5 100644 --- a/src/SeoBundle/Registry/IndexWorkerRegistryInterface.php +++ b/src/SeoBundle/Registry/IndexWorkerRegistryInterface.php @@ -6,24 +6,15 @@ interface IndexWorkerRegistryInterface { - /** - * @param string $identifier - * - * @return bool - */ - public function has($identifier); + public function has(string $identifier): bool; /** - * @param string $identifier - * - * @return IndexWorkerInterface - * * @throws \Exception */ - public function get($identifier); + public function get(string $identifier): IndexWorkerInterface; /** - * @return IndexWorkerInterface[] + * @return array */ - public function getAll(); + public function getAll(): array; } diff --git a/src/SeoBundle/Registry/MetaDataExtractorRegistry.php b/src/SeoBundle/Registry/MetaDataExtractorRegistry.php index 1bed58e..e3b61ac 100644 --- a/src/SeoBundle/Registry/MetaDataExtractorRegistry.php +++ b/src/SeoBundle/Registry/MetaDataExtractorRegistry.php @@ -6,16 +6,9 @@ class MetaDataExtractorRegistry implements MetaDataExtractorRegistryInterface { - /** - * @var array - */ - protected $services; - - /** - * @param ExtractorInterface $service - * @param string $identifier - */ - public function register($service, string $identifier) + protected array $services = []; + + public function register(mixed $service, string $identifier): void { if (!in_array(ExtractorInterface::class, class_implements($service), true)) { throw new \InvalidArgumentException( @@ -26,18 +19,12 @@ public function register($service, string $identifier) $this->services[$identifier] = $service; } - /** - * {@inheritdoc} - */ - public function has($identifier) + public function has($identifier): bool { return isset($this->services[$identifier]); } - /** - * {@inheritdoc} - */ - public function get($identifier) + public function get($identifier): ExtractorInterface { if (!$this->has($identifier)) { throw new \Exception('"' . $identifier . '" Meta Data Extractor does not exist'); @@ -46,10 +33,7 @@ public function get($identifier) return $this->services[$identifier]; } - /** - * {@inheritdoc} - */ - public function getAll() + public function getAll(): array { return is_array($this->services) ? $this->services : []; } diff --git a/src/SeoBundle/Registry/MetaDataExtractorRegistryInterface.php b/src/SeoBundle/Registry/MetaDataExtractorRegistryInterface.php index 39ff39d..d2f62f5 100644 --- a/src/SeoBundle/Registry/MetaDataExtractorRegistryInterface.php +++ b/src/SeoBundle/Registry/MetaDataExtractorRegistryInterface.php @@ -6,24 +6,15 @@ interface MetaDataExtractorRegistryInterface { - /** - * @param string $identifier - * - * @return bool - */ - public function has($identifier); + public function has(string $identifier): bool; /** - * @param string $identifier - * - * @return ExtractorInterface - * * @throws \Exception */ - public function get($identifier); + public function get(string $identifier): ExtractorInterface; /** - * @return ExtractorInterface[] + * @return array */ - public function getAll(); + public function getAll(): array; } diff --git a/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php b/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php index 07970cd..906cc08 100644 --- a/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php +++ b/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php @@ -6,16 +6,9 @@ class MetaDataIntegratorRegistry implements MetaDataIntegratorRegistryInterface { - /** - * @var array - */ - protected $services; - - /** - * @param IntegratorInterface $service - * @param string $identifier - */ - public function register($service, string $identifier) + protected array $services = []; + + public function register(mixed $service, string $identifier): void { if (!in_array(IntegratorInterface::class, class_implements($service), true)) { throw new \InvalidArgumentException( @@ -26,18 +19,12 @@ public function register($service, string $identifier) $this->services[$identifier] = $service; } - /** - * {@inheritdoc} - */ - public function has($identifier) + public function has($identifier): bool { return isset($this->services[$identifier]); } - /** - * {@inheritdoc} - */ - public function get($identifier) + public function get($identifier): IntegratorInterface { if (!$this->has($identifier)) { throw new \Exception('"' . $identifier . '" Meta Data Integrator does not exist'); @@ -46,10 +33,7 @@ public function get($identifier) return $this->services[$identifier]; } - /** - * {@inheritdoc} - */ - public function getAll() + public function getAll(): array { return is_array($this->services) ? $this->services : []; } diff --git a/src/SeoBundle/Registry/MetaDataIntegratorRegistryInterface.php b/src/SeoBundle/Registry/MetaDataIntegratorRegistryInterface.php index f27b706..4c97629 100644 --- a/src/SeoBundle/Registry/MetaDataIntegratorRegistryInterface.php +++ b/src/SeoBundle/Registry/MetaDataIntegratorRegistryInterface.php @@ -6,24 +6,15 @@ interface MetaDataIntegratorRegistryInterface { - /** - * @param string $identifier - * - * @return bool - */ - public function has($identifier); + public function has(string $identifier): bool; /** - * @param string $identifier - * - * @return IntegratorInterface - * * @throws \Exception */ - public function get($identifier); + public function get(string $identifier): IntegratorInterface; /** - * @return IntegratorInterface[] + * @return array */ - public function getAll(); + public function getAll(): array; } diff --git a/src/SeoBundle/Registry/ResourceProcessorRegistry.php b/src/SeoBundle/Registry/ResourceProcessorRegistry.php index 666c505..74ca86c 100644 --- a/src/SeoBundle/Registry/ResourceProcessorRegistry.php +++ b/src/SeoBundle/Registry/ResourceProcessorRegistry.php @@ -6,16 +6,9 @@ class ResourceProcessorRegistry implements ResourceProcessorRegistryInterface { - /** - * @var array - */ - protected $services; - - /** - * @param ResourceProcessorInterface $service - * @param string $identifier - */ - public function register($service, string $identifier) + protected array $services = []; + + public function register(mixed $service, string $identifier): void { if (!in_array(ResourceProcessorInterface::class, class_implements($service), true)) { throw new \InvalidArgumentException( @@ -26,18 +19,12 @@ public function register($service, string $identifier) $this->services[$identifier] = $service; } - /** - * {@inheritdoc} - */ - public function has($identifier) + public function has($identifier): bool { return isset($this->services[$identifier]); } - /** - * {@inheritdoc} - */ - public function get($identifier) + public function get($identifier): ResourceProcessorInterface { if (!$this->has($identifier)) { throw new \Exception('"' . $identifier . '" Resource Processor does not exist'); @@ -46,10 +33,7 @@ public function get($identifier) return $this->services[$identifier]; } - /** - * {@inheritdoc} - */ - public function getAll() + public function getAll(): array { return is_array($this->services) ? $this->services : []; } diff --git a/src/SeoBundle/Registry/ResourceProcessorRegistryInterface.php b/src/SeoBundle/Registry/ResourceProcessorRegistryInterface.php index 0001d4a..6f4f33a 100644 --- a/src/SeoBundle/Registry/ResourceProcessorRegistryInterface.php +++ b/src/SeoBundle/Registry/ResourceProcessorRegistryInterface.php @@ -6,24 +6,15 @@ interface ResourceProcessorRegistryInterface { - /** - * @param string $identifier - * - * @return bool - */ - public function has($identifier); + public function has(string $identifier): bool; /** - * @param string $identifier - * - * @return ResourceProcessorInterface - * * @throws \Exception */ - public function get($identifier); + public function get(string $identifier): ResourceProcessorInterface; /** - * @return ResourceProcessorInterface[] + * @return array */ - public function getAll(); + public function getAll(): array; } diff --git a/src/SeoBundle/Repository/ElementMetaDataRepository.php b/src/SeoBundle/Repository/ElementMetaDataRepository.php index 5e15390..dfcf967 100644 --- a/src/SeoBundle/Repository/ElementMetaDataRepository.php +++ b/src/SeoBundle/Repository/ElementMetaDataRepository.php @@ -5,26 +5,18 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use SeoBundle\Model\ElementMetaData; +use SeoBundle\Model\ElementMetaDataInterface; class ElementMetaDataRepository implements ElementMetaDataRepositoryInterface { - /** - * @var EntityRepository - */ - protected $repository; + protected EntityRepository $repository; - /** - * @param EntityManagerInterface $entityManager - */ public function __construct(EntityManagerInterface $entityManager) { $this->repository = $entityManager->getRepository(ElementMetaData::class); } - /** - * {@inheritdoc} - */ - public function findAll(string $elementType, int $elementId) + public function findAll(string $elementType, int $elementId): array { return $this->repository->findBy([ 'elementType' => $elementType, @@ -32,10 +24,7 @@ public function findAll(string $elementType, int $elementId) ]); } - /** - * {@inheritdoc} - */ - public function findByIntegrator(string $elementType, int $elementId, string $integrator) + public function findByIntegrator(string $elementType, int $elementId, string $integrator): ?ElementMetaDataInterface { return $this->repository->findOneBy([ 'elementType' => $elementType, diff --git a/src/SeoBundle/Repository/ElementMetaDataRepositoryInterface.php b/src/SeoBundle/Repository/ElementMetaDataRepositoryInterface.php index 1ecde02..d68fc02 100644 --- a/src/SeoBundle/Repository/ElementMetaDataRepositoryInterface.php +++ b/src/SeoBundle/Repository/ElementMetaDataRepositoryInterface.php @@ -7,19 +7,9 @@ interface ElementMetaDataRepositoryInterface { /** - * @param string $elementType - * @param int $elementId - * - * @return ElementMetaDataInterface[] + * @return array */ - public function findAll(string $elementType, int $elementId); + public function findAll(string $elementType, int $elementId): array; - /** - * @param string $elementType - * @param int $elementId - * @param string $integrator - * - * @return ElementMetaDataInterface|null - */ - public function findByIntegrator(string $elementType, int $elementId, string $integrator); + public function findByIntegrator(string $elementType, int $elementId, string $integrator): ?ElementMetaDataInterface; } diff --git a/src/SeoBundle/Repository/QueueEntryRepository.php b/src/SeoBundle/Repository/QueueEntryRepository.php index f8e6737..e962bc2 100644 --- a/src/SeoBundle/Repository/QueueEntryRepository.php +++ b/src/SeoBundle/Repository/QueueEntryRepository.php @@ -5,42 +5,28 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use SeoBundle\Model\QueueEntry; +use SeoBundle\Model\QueueEntryInterface; class QueueEntryRepository implements QueueEntryRepositoryInterface { - /** - * @var EntityRepository - */ - protected $repository; + protected EntityRepository $repository; - /** - * @param EntityManagerInterface $entityManager - */ public function __construct(EntityManagerInterface $entityManager) { $this->repository = $entityManager->getRepository(QueueEntry::class); } - /** - * {@inheritdoc} - */ - public function findAll(array $orderBy = null) + public function findAll(?array $orderBy = null): array { return $this->repository->findBy([], $orderBy); } - /** - * {@inheritdoc} - */ - public function findAllForWorker(string $workerName, array $orderBy = null) + public function findAllForWorker(string $workerName, ?array $orderBy = null): array { return $this->repository->findBy(['worker' => $workerName], $orderBy); } - /** - * {@inheritdoc} - */ - public function findAtLeastOneForWorker(string $workerName) + public function findAtLeastOneForWorker(string $workerName): ?QueueEntryInterface { return $this->repository->findOneBy(['worker' => $workerName]); } diff --git a/src/SeoBundle/Repository/QueueEntryRepositoryInterface.php b/src/SeoBundle/Repository/QueueEntryRepositoryInterface.php index 8084a15..051ac41 100644 --- a/src/SeoBundle/Repository/QueueEntryRepositoryInterface.php +++ b/src/SeoBundle/Repository/QueueEntryRepositoryInterface.php @@ -7,24 +7,14 @@ interface QueueEntryRepositoryInterface { /** - * @param string $workerName - * - * @return QueueEntryInterface|null + * @return array */ - public function findAtLeastOneForWorker(string $workerName); + public function findAll(?array $orderBy = null): array; /** - * @param array|null $orderBy - * - * @return QueueEntryInterface[] + * @return array */ - public function findAll(array $orderBy = null); + public function findAllForWorker(string $workerName, ?array $orderBy = null): array; - /** - * @param string $workerName - * @param array|null $orderBy - * - * @return QueueEntryInterface[] - */ - public function findAllForWorker(string $workerName, array $orderBy = null); + public function findAtLeastOneForWorker(string $workerName): ?QueueEntryInterface; } diff --git a/src/SeoBundle/ResourceProcessor/ResourceProcessorInterface.php b/src/SeoBundle/ResourceProcessor/ResourceProcessorInterface.php index e16075e..1b22436 100644 --- a/src/SeoBundle/ResourceProcessor/ResourceProcessorInterface.php +++ b/src/SeoBundle/ResourceProcessor/ResourceProcessorInterface.php @@ -8,40 +8,15 @@ interface ResourceProcessorInterface { - /** - * @param string $workerIdentifier - * - * @return bool - */ - public function supportsWorker(string $workerIdentifier); + public function supportsWorker(string $workerIdentifier): bool; - /** - * @param object $resource - * - * @return bool - */ - public function supportsResource($resource); + public function supportsResource(mixed $resource): bool; - /** - * @param object $resource - * - * @return mixed - */ - public function generateQueueContext($resource); + public function generateQueueContext(mixed $resource): mixed; - /** - * @param QueueEntryInterface $queueEntry - * @param string $workerIdentifier - * @param array $context - * @param mixed $resource - * - * @return QueueEntryInterface|null - */ - public function processQueueEntry(QueueEntryInterface $queueEntry, string $workerIdentifier, array $context, $resource); + public function processQueueEntry(QueueEntryInterface $queueEntry, string $workerIdentifier, array $context, mixed $resource): ?QueueEntryInterface; /** - * @param WorkerResponseInterface $workerResponse - * * @throws \Exception * @throws WorkerResponseInterceptException */ diff --git a/src/SeoBundle/Resources/config/services/command.yml b/src/SeoBundle/Resources/config/services/command.yml index 05c6879..d8098c1 100644 --- a/src/SeoBundle/Resources/config/services/command.yml +++ b/src/SeoBundle/Resources/config/services/command.yml @@ -7,4 +7,4 @@ services: SeoBundle\Command\QueuedIndexDataCommand: tags: - - { name: console.command, command: 'seo:check-index-queue' } \ No newline at end of file + - { name: console.command } \ No newline at end of file diff --git a/src/SeoBundle/Resources/config/services/controller.yml b/src/SeoBundle/Resources/config/services/controller.yml index 56f30f1..2dcd89b 100644 --- a/src/SeoBundle/Resources/config/services/controller.yml +++ b/src/SeoBundle/Resources/config/services/controller.yml @@ -1,10 +1,8 @@ services: - _defaults: + SeoBundle\Controller\: + resource: '../../Controller' + public: true autowire: true autoconfigure: true - public: true - - SeoBundle\Controller\Admin\MetaDataController: - calls: - - [setContainer, ['@service_container']] + tags: ['controller.service_arguments'] diff --git a/src/SeoBundle/Resources/install/sql/install.sql b/src/SeoBundle/Resources/install/sql/install.sql index c75da87..882f89a 100644 --- a/src/SeoBundle/Resources/install/sql/install.sql +++ b/src/SeoBundle/Resources/install/sql/install.sql @@ -1,4 +1,4 @@ -CREATE TABLE `seo_element_meta_data` ( +CREATE TABLE IF NOT EXISTS `seo_element_meta_data` ( `id` int(11) NOT NULL AUTO_INCREMENT, `element_type` varchar(255) NOT NULL, `element_id` int(11) NOT NULL, @@ -8,7 +8,7 @@ CREATE TABLE `seo_element_meta_data` ( UNIQUE KEY `element_type_id_integrator` (`element_type`,`element_id`,`integrator`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; -CREATE TABLE `seo_queue_entry` ( +CREATE TABLE IF NOT EXISTS `seo_queue_entry` ( `uuid` varchar(255) NOT NULL, `type` varchar(255) NOT NULL, `data_type` varchar(255) NOT NULL, diff --git a/src/SeoBundle/Resources/public/css/admin.css b/src/SeoBundle/Resources/public/css/admin.css index 37a0c34..a95ae3c 100755 --- a/src/SeoBundle/Resources/public/css/admin.css +++ b/src/SeoBundle/Resources/public/css/admin.css @@ -1,7 +1,6 @@ .seo_icon_meta_data { background: url(/bundles/seo/img/seo_icon_white.svg) no-repeat scroll left center transparent !important; } - .seo_integrator_icon_html_tags { background: url(/bundles/seo/img/integrator/icon_html_tags.svg) center center no-repeat !important; } diff --git a/src/SeoBundle/SeoBundle.php b/src/SeoBundle/SeoBundle.php index 06f0784..8dd7491 100644 --- a/src/SeoBundle/SeoBundle.php +++ b/src/SeoBundle/SeoBundle.php @@ -21,20 +21,14 @@ class SeoBundle extends AbstractPimcoreBundle { use PackageVersionTrait; - const PACKAGE_NAME = 'dachcom-digital/seo'; + public const PACKAGE_NAME = 'dachcom-digital/seo'; - /** - * {@inheritdoc} - */ - public function getInstaller() + public function getInstaller(): Install { return $this->container->get(Install::class); } - /** - * {@inheritdoc} - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { $this->configureDoctrineExtension($container); @@ -50,17 +44,11 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RemoveCoreShopExtractorListenerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 250); } - /** - * {@inheritdoc} - */ protected function getComposerPackageName(): string { return self::PACKAGE_NAME; } - /** - * @param ContainerBuilder $container - */ protected function configureDoctrineExtension(ContainerBuilder $container): void { $container->addCompilerPass( @@ -72,20 +60,14 @@ protected function configureDoctrineExtension(ContainerBuilder $container): void ); } - /** - * @return array - */ - public function getCssPaths() + public function getCssPaths(): array { return [ '/bundles/seo/css/admin.css' ]; } - /** - * @return string[] - */ - public function getJsPaths() + public function getJsPaths(): array { return [ '/bundles/seo/js/plugin.js', @@ -107,18 +89,12 @@ public function getJsPaths() ]; } - /** - * @return string|null - */ - protected function getNamespaceName() + protected function getNamespaceName(): string { return 'SeoBundle\Model'; } - /** - * @return string - */ - protected function getNameSpacePath() + protected function getNameSpacePath(): string { return sprintf( '%s/Resources/config/doctrine/%s', diff --git a/src/SeoBundle/Tool/Bundle.php b/src/SeoBundle/Tool/Bundle.php index 989ab2f..d9e5c25 100644 --- a/src/SeoBundle/Tool/Bundle.php +++ b/src/SeoBundle/Tool/Bundle.php @@ -4,24 +4,12 @@ class Bundle { - /** - * @param string $bundleName - * @param array $installedBundle - * - * @return bool - */ - public static function hasBundle(string $bundleName, array $installedBundle) + public static function hasBundle(string $bundleName, array $installedBundle): bool { return array_key_exists($bundleName, $installedBundle); } - /** - * @param string $bundleName - * @param array $installedBundle - * - * @return bool - */ - public static function hasDachcomBundle(string $bundleName, array $installedBundle) + public static function hasDachcomBundle(string $bundleName, array $installedBundle): bool { if (!array_key_exists($bundleName, $installedBundle)) { return false; @@ -32,7 +20,7 @@ public static function hasDachcomBundle(string $bundleName, array $installedBund return false; } - if (strpos($class::PACKAGE_NAME, 'dachcom-digital') === false) { + if (!str_contains($class::PACKAGE_NAME, 'dachcom-digital')) { return false; } diff --git a/src/SeoBundle/Tool/Install.php b/src/SeoBundle/Tool/Install.php index 9fbb0e7..ef5a332 100644 --- a/src/SeoBundle/Tool/Install.php +++ b/src/SeoBundle/Tool/Install.php @@ -2,172 +2,66 @@ namespace SeoBundle\Tool; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Migrations\AbortMigrationException; -use Doctrine\DBAL\Schema\Schema; -use Doctrine\DBAL\Migrations\MigrationException; -use Doctrine\DBAL\Migrations\Version; use Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver; use Pimcore\Db\Connection; +use Pimcore\Extension\Bundle\Installer\Exception\InstallationException; +use Pimcore\Extension\Bundle\Installer\SettingsStoreAwareInstaller; use Pimcore\Model\User\Permission; -use Pimcore\Extension\Bundle\Installer\MigrationInstaller; -use Pimcore\Migrations\Migration\InstallMigration; use Symfony\Component\Serializer\Encoder\DecoderInterface; -class Install extends MigrationInstaller +class Install extends SettingsStoreAwareInstaller { - /** - * @var array - */ - const REQUIRED_PERMISSION = [ + public const REQUIRED_PERMISSION = [ 'seo_bundle_remove_property', 'seo_bundle_add_property', ]; - /** - * @var TokenStorageUserResolver - */ - protected $resolver; + protected TokenStorageUserResolver $resolver; + protected DecoderInterface $serializer; - /** - * @var DecoderInterface - */ - protected $serializer; - - /** - * @param TokenStorageUserResolver $resolver - */ - public function setTokenStorageUserResolver(TokenStorageUserResolver $resolver) + public function setTokenStorageUserResolver(TokenStorageUserResolver $resolver): void { $this->resolver = $resolver; } - /** - * @param DecoderInterface $serializer - */ - public function setSerializer(DecoderInterface $serializer) + public function setSerializer(DecoderInterface $serializer): void { $this->serializer = $serializer; } - /** - * {@inheritdoc} - */ - public function getMigrationVersion(): string - { - return '00000001'; - } - - /** - * @throws MigrationException - * @throws DBALException - */ - protected function beforeInstallMigration() - { - $migrationConfiguration = $this->migrationManager->getBundleConfiguration($this->bundle); - $this->migrationManager->markVersionAsMigrated($migrationConfiguration->getVersion($migrationConfiguration->getLatestVersion())); - - $this->initializeFreshSetup(); - } - - /** - * @param Schema $schema - * @param Version $version - */ - public function migrateInstall(Schema $schema, Version $version) - { - /** @var InstallMigration $migration */ - $migration = $version->getMigration(); - if ($migration->isDryRun()) { - $this->outputWriter->write('DRY-RUN: Skipping installation'); - - return; - } - } - - /** - * {@inheritdoc} - */ - public function needsReloadAfterInstall() - { - return true; - } - - /** - * @throws AbortMigrationException - * @throws DBALException - */ - public function initializeFreshSetup() + public function install(): void { $this->installDbStructure(); $this->installPermissions(); - } - - /** - * @param Schema $schema - * @param Version $version - */ - public function migrateUninstall(Schema $schema, Version $version) - { - /** @var InstallMigration $migration */ - $migration = $version->getMigration(); - if ($migration->isDryRun()) { - $this->outputWriter->write('DRY-RUN: Skipping uninstallation'); - return; - } - - // currently nothing to do. - } - - /** - * @param string|null $version - */ - protected function beforeUpdateMigration(string $version = null) - { - // currently nothing to do. - return; + parent::install(); } - /** - * @throws DBALException - */ - protected function installDbStructure() + protected function installDbStructure(): void { /** @var Connection $db */ $db = \Pimcore\Db::get(); $db->query(file_get_contents($this->getInstallSourcesPath() . '/sql/install.sql')); } - /** - * @throws AbortMigrationException - */ - protected function installPermissions() + protected function installPermissions(): void { foreach (self::REQUIRED_PERMISSION as $permission) { $definition = Permission\Definition::getByKey($permission); if ($definition) { - $this->outputWriter->write(sprintf( - ' WARNING: Skipping permission "%s" as it already exists', - $permission - )); - continue; } try { Permission\Definition::create($permission); } catch (\Throwable $e) { - throw new AbortMigrationException(sprintf('Failed to create permission "%s": %s', $permission, $e->getMessage())); + throw new InstallationException(sprintf('Failed to create permission "%s": %s', $permission, $e->getMessage())); } } } - /** - * @return string - */ - protected function getInstallSourcesPath() + protected function getInstallSourcesPath(): string { return __DIR__ . '/../Resources/install'; } diff --git a/src/SeoBundle/Tool/LocaleProvider.php b/src/SeoBundle/Tool/LocaleProvider.php index 0c4dad3..93d2df4 100644 --- a/src/SeoBundle/Tool/LocaleProvider.php +++ b/src/SeoBundle/Tool/LocaleProvider.php @@ -9,23 +9,14 @@ class LocaleProvider implements LocaleProviderInterface { - /** - * @var TokenStorageUserResolver - */ - protected $userResolver; - - /** - * @param TokenStorageUserResolver $userResolver - */ + protected TokenStorageUserResolver $userResolver; + public function __construct(TokenStorageUserResolver $userResolver) { $this->userResolver = $userResolver; } - /** - * {@inheritDoc} - */ - public function getAllowedLocalesForObject(?DataObject\AbstractObject $object) + public function getAllowedLocalesForObject(?DataObject\AbstractObject $object): array { $user = $this->userResolver->getUser(); if (!$user instanceof User) { @@ -50,13 +41,7 @@ public function getAllowedLocalesForObject(?DataObject\AbstractObject $object) return $this->sortLocalesByUserDefinition($user, array_keys($allowedEdit)); } - /** - * @param User $user - * @param array $locales - * - * @return array - */ - protected function sortLocalesByUserDefinition(User $user, array $locales) + protected function sortLocalesByUserDefinition(User $user, array $locales): array { $contentLanguages = $user->getContentLanguages(); @@ -66,9 +51,9 @@ protected function sortLocalesByUserDefinition(User $user, array $locales) $orderIdKeys = array_flip($contentLanguages); - usort($locales, function ($l1, $l2) use ($orderIdKeys) { + usort($locales, static function ($l1, $l2) use ($orderIdKeys) { - if (!isset($orderIdKeys[$l1]) || !isset($orderIdKeys[$l2])) { + if (!isset($orderIdKeys[$l1], $orderIdKeys[$l2])) { return 0; } diff --git a/src/SeoBundle/Tool/LocaleProviderInterface.php b/src/SeoBundle/Tool/LocaleProviderInterface.php index 146144a..31f4011 100644 --- a/src/SeoBundle/Tool/LocaleProviderInterface.php +++ b/src/SeoBundle/Tool/LocaleProviderInterface.php @@ -6,10 +6,6 @@ interface LocaleProviderInterface { - /** - * @param DataObject\AbstractObject|null $object - * - * @return array - */ - public function getAllowedLocalesForObject(?DataObject\AbstractObject $object); + + public function getAllowedLocalesForObject(?DataObject\AbstractObject $object): array; } diff --git a/src/SeoBundle/Tool/UrlGenerator.php b/src/SeoBundle/Tool/UrlGenerator.php index 6ab86b0..f0bf569 100644 --- a/src/SeoBundle/Tool/UrlGenerator.php +++ b/src/SeoBundle/Tool/UrlGenerator.php @@ -9,56 +9,40 @@ class UrlGenerator implements UrlGeneratorInterface { - /** - * @var RequestStack - */ - protected $requestStack; - - /** - * @param RequestStack $requestStack - */ + protected RequestStack $requestStack; + public function __construct(RequestStack $requestStack) { $this->requestStack = $requestStack; } - /** - * {@inheritdoc} - */ - public function generate($element, array $options = []) + public function generate($element, array $options = []): ?string { if ($element instanceof Page) { return $this->generateForDocument($element, $options); - } elseif ($element instanceof Asset) { + } + + if ($element instanceof Asset) { return $this->generateForAsset($element, $options); - } elseif ($element instanceof DataObject\Concrete) { + } + + if ($element instanceof DataObject\Concrete) { return $this->generateForObject($element, $options); } return null; } - /** - * {@inheritdoc} - */ - public function getCurrentSchemeAndHost() + public function getCurrentSchemeAndHost(): string { - $scheme = $this->requestStack->getMasterRequest()->getScheme(); - $host = $this->requestStack->getMasterRequest()->getHost(); + $scheme = $this->requestStack->getMainRequest()->getScheme(); + $host = $this->requestStack->getMainRequest()->getHost(); return sprintf('%s://%s', $scheme, $host); } - /** - * @param Page $document - * @param array $options - * - * @return string|null - */ - protected function generateForDocument(Page $document, array $options) + protected function generateForDocument(Page $document, array $options): ?string { - $url = null; - try { $url = $document->getUrl(); } catch (\Exception $e) { @@ -68,18 +52,12 @@ protected function generateForDocument(Page $document, array $options) return $url; } - /** - * @param DataObject\Concrete $object - * @param array $options - * - * @return string|null - */ - protected function generateForObject(DataObject\Concrete $object, array $options) + protected function generateForObject(DataObject\Concrete $object, array $options): ?string { $linkGenerator = $object->getClass()->getLinkGenerator(); if ($linkGenerator instanceof DataObject\ClassDefinition\LinkGeneratorInterface) { $link = $linkGenerator->generate($object, []); - if (strpos($link, 'http') === false) { + if (!str_contains($link, 'http')) { $link = sprintf('%s/%s', $this->getCurrentSchemeAndHost(), ltrim($link, '/')); } @@ -89,13 +67,7 @@ protected function generateForObject(DataObject\Concrete $object, array $options return null; } - /** - * @param Asset $asset - * @param array $options - * - * @return string|null - */ - protected function generateForAsset(Asset $asset, array $options) + protected function generateForAsset(Asset $asset, array $options): ?string { if (!$asset instanceof Asset\Image) { return null; @@ -115,7 +87,7 @@ protected function generateForAsset(Asset $asset, array $options) return null; } - if (strpos($imagePath, 'http') !== false) { + if (str_contains($imagePath, 'http')) { return $imagePath; } diff --git a/src/SeoBundle/Tool/UrlGeneratorInterface.php b/src/SeoBundle/Tool/UrlGeneratorInterface.php index 54206b9..bb3a2e6 100644 --- a/src/SeoBundle/Tool/UrlGeneratorInterface.php +++ b/src/SeoBundle/Tool/UrlGeneratorInterface.php @@ -4,16 +4,7 @@ interface UrlGeneratorInterface { - /** - * @param mixed $element - * @param array $options - * - * @return string|null - */ - public function generate($element, array $options = []); + public function generate(mixed $element, array $options = []): ?string; - /** - * @return string - */ - public function getCurrentSchemeAndHost(); + public function getCurrentSchemeAndHost(): string; } diff --git a/src/SeoBundle/Twig/Extension/SeoExtension.php b/src/SeoBundle/Twig/Extension/SeoExtension.php index 2c9c349..d6b8809 100755 --- a/src/SeoBundle/Twig/Extension/SeoExtension.php +++ b/src/SeoBundle/Twig/Extension/SeoExtension.php @@ -8,42 +8,26 @@ class SeoExtension extends AbstractExtension { - /** - * @var MetaDataProviderInterface - */ - protected $metaDataProvider; + protected MetaDataProviderInterface $metaDataProvider; - /** - * @param MetaDataProviderInterface $metaDataProvider - */ public function __construct(MetaDataProviderInterface $metaDataProvider) { $this->metaDataProvider = $metaDataProvider; } - /** - * {@inheritdoc} - */ - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('seo_update_metadata', [$this, 'updateMetadata']), ]; } - /** - * @param object $element - * @param string|null $locale - */ - public function updateMetadata($element, ?string $locale) + public function updateMetadata(mixed $element, ?string $locale): void { $this->metaDataProvider->updateSeoElement($element, $locale); } - /** - * @return string - */ - public function getName() + public function getName(): string { return 'seo_metadata'; } diff --git a/src/SeoBundle/Worker/GoogleIndexWorker.php b/src/SeoBundle/Worker/GoogleIndexWorker.php index 9704844..98aa41d 100644 --- a/src/SeoBundle/Worker/GoogleIndexWorker.php +++ b/src/SeoBundle/Worker/GoogleIndexWorker.php @@ -11,19 +11,12 @@ class GoogleIndexWorker implements IndexWorkerInterface { - const TMP_STORE_MINUTE_QUOTA_KEY = 'google_index_worker_minute_quota'; + public const TMP_STORE_MINUTE_QUOTA_KEY = 'google_index_worker_minute_quota'; + public const TMP_STORE_DAILY_QUOTA_KEY = 'google_index_worker_daily_quota'; - const TMP_STORE_DAILY_QUOTA_KEY = 'google_index_worker_daily_quota'; + protected array $configuration; - /** - * @var array - */ - protected $configuration; - - /** - * {@inheritdoc} - */ - public function canProcess() + public function canProcess(): string|bool { $dailyQuota = TmpStore::get(self::TMP_STORE_DAILY_QUOTA_KEY); @@ -67,7 +60,7 @@ public function canProcess() * - Push requests per day: 200 * - Push request per minute: 600 */ - public function process(array $queueEntries, array $resultProcessingCallBack) + public function process(array $queueEntries, array $resultCallBack): void { $client = $this->getClient(); @@ -110,7 +103,7 @@ public function process(array $queueEntries, array $resultProcessingCallBack) } $results = $batch->execute(); - $this->parseResults($results, $entriesBlock, $resultProcessingCallBack); + $this->parseResults($results, $entriesBlock, $resultCallBack); // throttle batch requests sleep(1); @@ -125,24 +118,16 @@ public function process(array $queueEntries, array $resultProcessingCallBack) * Daily quotas are refreshed at midnight Pacific Standard Time. * * @see https://developers.google.com/analytics/devguides/config/mgmt/v3/limits-quotas - * - * @return int */ - protected function generateLifeTimeExceed() + protected function generateLifeTimeExceed(): int { $quoteLifetime = Carbon::now('PST')->endOfDay(); $localeQuoteLifeTime = Carbon::createFromTimestamp($quoteLifetime->getTimestamp(), CarbonTimeZone::create()); - $diffInSecondsFromNow = $localeQuoteLifeTime->diffInRealSeconds(Carbon::now()); - return $diffInSecondsFromNow; + return $localeQuoteLifeTime->diffInRealSeconds(Carbon::now()); } - /** - * @param array $results - * @param array $processedQueueEntries - * @param array $callable - */ - protected function parseResults(array $results, array $processedQueueEntries, array $callable) + protected function parseResults(array $results, array $processedQueueEntries, array $callable): void { foreach ($results as $queueEntryResponseId => $result) { $queueEntryId = str_replace('response-', '', $queueEntryResponseId); @@ -150,13 +135,7 @@ protected function parseResults(array $results, array $processedQueueEntries, ar } } - /** - * @param mixed $result - * @param string $queueEntryId - * @param array $processedQueueEntries - * @param array $callable - */ - protected function parseResult($result, string $queueEntryId, array $processedQueueEntries, array $callable) + protected function parseResult(mixed $result, string $queueEntryId, array $processedQueueEntries, array $callable): void { $linkedQueueEntry = array_reduce($processedQueueEntries, function ($result, QueueEntryInterface $item) use ($queueEntryId) { return $item->getUuid() === $queueEntryId ? $item : $result; @@ -174,13 +153,7 @@ protected function parseResult($result, string $queueEntryId, array $processedQu call_user_func_array($callable, [$workerResponse]); } - /** - * @param \Google_Service_Exception $response - * @param QueueEntryInterface $linkedQueueEntry - * - * @return WorkerResponse - */ - protected function buildErrorResponse(\Google_Service_Exception $response, QueueEntryInterface $linkedQueueEntry) + protected function buildErrorResponse(\Google_Service_Exception $response, QueueEntryInterface $linkedQueueEntry): WorkerResponse { $formattedMessages = []; $formattedStatus = (int) $response->getCode(); @@ -194,13 +167,7 @@ protected function buildErrorResponse(\Google_Service_Exception $response, Queue return new WorkerResponse($formattedStatus, $formattedMessage, false, $linkedQueueEntry, $response); } - /** - * @param \Google_Service_Indexing_PublishUrlNotificationResponse $response - * @param QueueEntryInterface $linkedQueueEntry - * - * @return WorkerResponse - */ - protected function buildSuccessResponse(\Google_Service_Indexing_PublishUrlNotificationResponse $response, QueueEntryInterface $linkedQueueEntry) + protected function buildSuccessResponse(\Google_Service_Indexing_PublishUrlNotificationResponse $response, QueueEntryInterface $linkedQueueEntry): WorkerResponse { $formattedMessageMeta = []; @@ -220,29 +187,22 @@ protected function buildSuccessResponse(\Google_Service_Indexing_PublishUrlNotif return new WorkerResponse(200, $formattedMessage, true, $linkedQueueEntry, $response); } - /** - * @param mixed $response - * @param QueueEntryInterface $linkedQueueEntry - * - * @return WorkerResponse - */ - protected function buildUnknownResponse($response, QueueEntryInterface $linkedQueueEntry) + protected function buildUnknownResponse(mixed $response, QueueEntryInterface $linkedQueueEntry): WorkerResponse { return new WorkerResponse(500, 'Unknown Error', true, $linkedQueueEntry, $response); } - /** - * @param string $type - * - * @return string - */ - protected function getUrlType(string $type) + protected function getUrlType(string $type): string { if ($type === IndexWorkerInterface::TYPE_UPDATE) { return 'URL_UPDATED'; - } elseif ($type === IndexWorkerInterface::TYPE_ADD) { + } + + if ($type === IndexWorkerInterface::TYPE_ADD) { return 'URL_UPDATED'; - } elseif ($type === IndexWorkerInterface::TYPE_DELETE) { + } + + if ($type === IndexWorkerInterface::TYPE_DELETE) { return 'URL_DELETED'; } @@ -250,11 +210,9 @@ protected function getUrlType(string $type) } /** - * @return \Google_Client - * - * @throws \Google_Exception + * @throws \Google\Exception */ - protected function getClient() + protected function getClient(): \Google_Client { $configPath = sprintf('%s/%s', PIMCORE_PROJECT_ROOT, ltrim($this->configuration['auth_config'], '/')); @@ -266,18 +224,12 @@ protected function getClient() return $client; } - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) + public function setConfiguration(array $configuration): void { $this->configuration = $configuration; } - /** - * {@inheritdoc} - */ - public static function configureOptions(OptionsResolver $resolver) + public static function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'push_requests_per_day' => 200, diff --git a/src/SeoBundle/Worker/IndexWorkerInterface.php b/src/SeoBundle/Worker/IndexWorkerInterface.php index c9cfceb..a021cf0 100644 --- a/src/SeoBundle/Worker/IndexWorkerInterface.php +++ b/src/SeoBundle/Worker/IndexWorkerInterface.php @@ -7,29 +7,15 @@ interface IndexWorkerInterface { - const TYPE_ADD = 'add'; - - const TYPE_UPDATE = 'update'; - - const TYPE_DELETE = 'delete'; - - /** - * @param array $configuration - */ - public function setConfiguration(array $configuration); - - /** - * @param OptionsResolver $resolver - */ - public static function configureOptions(OptionsResolver $resolver); + public const TYPE_ADD = 'add'; + public const TYPE_UPDATE = 'update'; + public const TYPE_DELETE = 'delete'; /** * Return true or false|string. * If string gets returned, it same as return false but will be added to logs. - * - * @return bool|string */ - public function canProcess(); + public function canProcess(): string|bool; /** * @param QueueEntryInterface[] $queueEntries @@ -37,5 +23,10 @@ public function canProcess(); * * @throws \Exception */ - public function process(array $queueEntries, array $resultCallBack); + public function process(array $queueEntries, array $resultCallBack): void; + + public function setConfiguration(array $configuration): void; + + public static function configureOptions(OptionsResolver $resolver): void; + } diff --git a/src/SeoBundle/Worker/WorkerResponse.php b/src/SeoBundle/Worker/WorkerResponse.php index 122aa5f..b694530 100644 --- a/src/SeoBundle/Worker/WorkerResponse.php +++ b/src/SeoBundle/Worker/WorkerResponse.php @@ -6,39 +6,13 @@ class WorkerResponse implements WorkerResponseInterface { - /** - * @var string - */ - protected $status; + protected string $status; + protected string $message; + protected bool $successFullyProcessed; + protected QueueEntryInterface $queueEntry; + protected mixed $rawResponse; - /** - * @var string - */ - protected $message; - - /** - * @var bool - */ - protected $successFullyProcessed; - - /** - * @var QueueEntryInterface - */ - protected $queueEntry; - - /** - * @var mixed - */ - protected $rawResponse; - - /** - * @param int $status - * @param string $message - * @param bool $successFullyProcessed - * @param QueueEntryInterface $queueEntry - * @param mixed $rawResponse - */ - public function __construct(int $status, ?string $message, bool $successFullyProcessed, QueueEntryInterface $queueEntry, $rawResponse) + public function __construct(int $status, ?string $message, bool $successFullyProcessed, QueueEntryInterface $queueEntry, mixed $rawResponse) { $this->status = $status; $this->message = $message; @@ -47,42 +21,27 @@ public function __construct(int $status, ?string $message, bool $successFullyPro $this->rawResponse = $rawResponse; } - /** - * {@inheritdoc} - */ - public function getStatus() + public function getStatus(): string { return $this->status; } - /** - * {@inheritdoc} - */ - public function getMessage() + public function getMessage(): string { return $this->message; } - /** - * {@inheritdoc} - */ - public function getQueueEntry() + public function getQueueEntry(): QueueEntryInterface { return $this->queueEntry; } - /** - * {@inheritdoc} - */ - public function getRawResponse() + public function getRawResponse(): mixed { return $this->rawResponse; } - /** - * {@inheritdoc} - */ - public function isDone() + public function isDone(): bool { return $this->successFullyProcessed === true; } diff --git a/src/SeoBundle/Worker/WorkerResponseInterface.php b/src/SeoBundle/Worker/WorkerResponseInterface.php index 7748549..f751216 100644 --- a/src/SeoBundle/Worker/WorkerResponseInterface.php +++ b/src/SeoBundle/Worker/WorkerResponseInterface.php @@ -6,28 +6,13 @@ interface WorkerResponseInterface { - /** - * @return string - */ - public function getStatus(); + public function getStatus(): string; - /** - * @return string - */ - public function getMessage(); + public function getMessage(): string; - /** - * @return QueueEntryInterface - */ - public function getQueueEntry(); + public function getQueueEntry(): QueueEntryInterface; - /** - * @return mixed - */ - public function getRawResponse(); + public function getRawResponse(): mixed; - /** - * @return bool - */ - public function isDone(); + public function isDone(): bool; } diff --git a/tests/_etc/config.yml b/tests/_etc/config.yml index e883abb..bc56e46 100644 --- a/tests/_etc/config.yml +++ b/tests/_etc/config.yml @@ -1,7 +1,7 @@ bundles: - { namespace: \SeoBundle\SeoBundle } setup_files: - - { path: app/config.yml, dest: ./app/config/config.yml } + - { path: app/config.yml, dest: ./config/config.yaml } - { path: app/system.yml, dest: ./var/config/system.yml } - - { path: app/controller/DefaultController.php, dest: ./src/AppBundle/Controller/DefaultController.php } - - { path: app/views/default.html.twig, dest: ./app/Resources/views/Default/default.html.twig } + - { path: app/controller/DefaultController.php, dest: ./src/Controller/DefaultController.php } + - { path: app/templates/default.html.twig, dest: ./templates/default/default.html.twig } diff --git a/tests/_etc/config/app/config.yml b/tests/_etc/config/app/config.yml index 73736d7..ddbba0d 100755 --- a/tests/_etc/config/app/config.yml +++ b/tests/_etc/config/app/config.yml @@ -1,18 +1,21 @@ imports: - - { resource: parameters.yml } - - { resource: security.yml } - - { resource: services.yml } + - { resource: services.yaml } - { resource: 'local/' } -# don't send real emails in functional tests -swiftmailer: - disable_delivery: true - -pimcore: - error_handling: - render_error_document: true +services: + App\Controller\DefaultController: + public: true + autowire: true + autoconfigure: true + calls: + - [setContainer, ['@service_container']] framework: profiler: enabled: true - collect: false \ No newline at end of file + collect: false + # don't send real emails in functional tests + mailer: + transports: + main: 'null://null' + pimcore_newsletter: 'null://null' \ No newline at end of file diff --git a/tests/_etc/config/app/controller/DefaultController.php b/tests/_etc/config/app/controller/DefaultController.php index fea9a8b..60f215e 100644 --- a/tests/_etc/config/app/controller/DefaultController.php +++ b/tests/_etc/config/app/controller/DefaultController.php @@ -1,19 +1,15 @@ setViewAutoRender($event->getRequest(), true, 'twig'); - } - - public function defaultAction(Request $request) + public function defaultAction(Request $request): Response { + return $this->renderTemplate('default/default.html.twig'); } } diff --git a/tests/_etc/config/app/system.yml b/tests/_etc/config/app/system.yml index 15ab1b6..2480015 100755 --- a/tests/_etc/config/app/system.yml +++ b/tests/_etc/config/app/system.yml @@ -2,24 +2,23 @@ pimcore: general: timezone: Europe/Berlin language: en - valid_languages: 'en' + valid_languages: 'en,de' + fallback_languages: + en: '' + de: '' path_variable: '' domain: 'localhost' redirect_to_maindomain: false - fallback_languages: - en: '' default_language: en disable_usage_statistics: true debug_admin_translations: false instance_identifier: '' - show_cookie_notice: false documents: versions: steps: 10 days: null error_pages: - default: /error - create_redirect_when_moved: false + default: /404 allow_trailing_slash: 'no' generate_preview: false objects: @@ -34,6 +33,9 @@ pimcore: icc_cmyk_profile: '' hide_edit_image: false disable_tree_preview: true + email: + debug: + email_addresses: opensource@dachcom.ch services: google: client_id: '' @@ -41,39 +43,16 @@ pimcore: simple_api_key: '' browser_api_key: '' full_page_cache: + exclude_cookie: '' enabled: false lifetime: null exclude_patterns: '' - exclude_cookie: '' httpclient: adapter: Socket proxy_host: '' proxy_port: '' proxy_user: '' proxy_pass: '' - email: - sender: - name: '' - email: '' - return: - name: '' - email: '' - method: sendmail - debug: - email_addresses: null - newsletter: - sender: - name: '' - email: '' - return: - name: '' - email: '' - method: sendmail - use_specific: false - debug: - email_addresses: null - webservice: - enabled: false applicationlog: mail_notification: send_log_summary: false @@ -81,29 +60,10 @@ pimcore: mail_receiver: '' archive_treshold: '30' archive_alternative_database: '' + delete_archive_threshold: '6' pimcore_admin: branding: color_login_screen: '' color_admin_interface: '' login_screen_custom_image: '' login_screen_invert_colors: false -swiftmailer: - mailers: - pimcore_mailer: - transport: sendmail - delivery_addresses: { } - host: '' - username: '' - password: '' - port: '' - encryption: null - auth_mode: null - newsletter_mailer: - transport: sendmail - delivery_addresses: { } - host: '' - username: '' - password: '' - port: '' - encryption: null - auth_mode: null diff --git a/tests/_etc/config/app/views/default.html.twig b/tests/_etc/config/app/templates/default.html.twig similarity index 79% rename from tests/_etc/config/app/views/default.html.twig rename to tests/_etc/config/app/templates/default.html.twig index a0a994b..2c65722 100644 --- a/tests/_etc/config/app/views/default.html.twig +++ b/tests/_etc/config/app/templates/default.html.twig @@ -2,7 +2,7 @@ - Test Page for Test Bundle + {{ pimcore_head_title() }} {{ pimcore_head_meta() }} {{ pimcore_head_link() }} @@ -10,7 +10,7 @@
{% if document is defined %} - {{ document.getId() }} + {{ document.id }} {% endif %}
{% block content %} diff --git a/tests/_etc/config/bundle/config_default.yml b/tests/_etc/config/bundle/config_default.yml index 79e34fa..728a4f9 100755 --- a/tests/_etc/config/bundle/config_default.yml +++ b/tests/_etc/config/bundle/config_default.yml @@ -25,6 +25,6 @@ seo: enabled_worker: - worker_name: google_index worker_config: - auth_config: app/config/pimcore/google-api-private-key.json + auth_config: config/pimcore/google-api-private-key.json pimcore_element_watcher: enabled: true From fed834927a313be5e2852ddd91dc43e78129c39b Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Oct 2021 15:41:54 +0200 Subject: [PATCH 2/7] fix phpstan issues --- .../MetaData/Integrator/TwitterCardIntegrator.php | 4 +--- src/SeoBundle/Registry/IndexWorkerRegistry.php | 2 +- src/SeoBundle/Registry/MetaDataExtractorRegistry.php | 2 +- src/SeoBundle/Registry/MetaDataIntegratorRegistry.php | 2 +- src/SeoBundle/Registry/ResourceProcessorRegistry.php | 2 +- src/SeoBundle/Tool/UrlGenerator.php | 8 +------- src/SeoBundle/Worker/GoogleIndexWorker.php | 6 +++--- src/SeoBundle/Worker/WorkerResponse.php | 4 ++-- src/SeoBundle/Worker/WorkerResponseInterface.php | 2 +- 9 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php b/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php index 8759d1d..b0ebdcb 100644 --- a/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php +++ b/src/SeoBundle/MetaData/Integrator/TwitterCardIntegrator.php @@ -32,9 +32,7 @@ public function getBackendConfiguration(mixed $element): array public function getPreviewParameter(mixed $element, ?string $template, array $data): array { - if (null === $url = $this->urlGenerator->getCurrentSchemeAndHost()) { - $url = 'http://localhost'; - } + $url = $this->urlGenerator->getCurrentSchemeAndHost(); $title = $data['title'] ?? 'This is a title'; $description = $data['description'] ?? 'This is a very long description which should be not too long.'; diff --git a/src/SeoBundle/Registry/IndexWorkerRegistry.php b/src/SeoBundle/Registry/IndexWorkerRegistry.php index 43d8fa6..a7d8aff 100644 --- a/src/SeoBundle/Registry/IndexWorkerRegistry.php +++ b/src/SeoBundle/Registry/IndexWorkerRegistry.php @@ -35,6 +35,6 @@ public function get($identifier): IndexWorkerInterface public function getAll(): array { - return is_array($this->services) ? $this->services : []; + return $this->services; } } diff --git a/src/SeoBundle/Registry/MetaDataExtractorRegistry.php b/src/SeoBundle/Registry/MetaDataExtractorRegistry.php index e3b61ac..84e7e9b 100644 --- a/src/SeoBundle/Registry/MetaDataExtractorRegistry.php +++ b/src/SeoBundle/Registry/MetaDataExtractorRegistry.php @@ -35,6 +35,6 @@ public function get($identifier): ExtractorInterface public function getAll(): array { - return is_array($this->services) ? $this->services : []; + return $this->services; } } diff --git a/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php b/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php index 906cc08..6691ea2 100644 --- a/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php +++ b/src/SeoBundle/Registry/MetaDataIntegratorRegistry.php @@ -35,6 +35,6 @@ public function get($identifier): IntegratorInterface public function getAll(): array { - return is_array($this->services) ? $this->services : []; + return $this->services; } } diff --git a/src/SeoBundle/Registry/ResourceProcessorRegistry.php b/src/SeoBundle/Registry/ResourceProcessorRegistry.php index 74ca86c..94d998c 100644 --- a/src/SeoBundle/Registry/ResourceProcessorRegistry.php +++ b/src/SeoBundle/Registry/ResourceProcessorRegistry.php @@ -35,6 +35,6 @@ public function get($identifier): ResourceProcessorInterface public function getAll(): array { - return is_array($this->services) ? $this->services : []; + return $this->services; } } diff --git a/src/SeoBundle/Tool/UrlGenerator.php b/src/SeoBundle/Tool/UrlGenerator.php index f0bf569..6037468 100644 --- a/src/SeoBundle/Tool/UrlGenerator.php +++ b/src/SeoBundle/Tool/UrlGenerator.php @@ -35,10 +35,7 @@ public function generate($element, array $options = []): ?string public function getCurrentSchemeAndHost(): string { - $scheme = $this->requestStack->getMainRequest()->getScheme(); - $host = $this->requestStack->getMainRequest()->getHost(); - - return sprintf('%s://%s', $scheme, $host); + return sprintf('%s://%s', $this->requestStack->getMainRequest()->getScheme(), $this->requestStack->getMainRequest()->getHost()); } protected function generateForDocument(Page $document, array $options): ?string @@ -83,9 +80,6 @@ protected function generateForAsset(Asset $asset, array $options): ?string } $imagePath = $thumbnail->getPath(false); - if (is_null($imagePath)) { - return null; - } if (str_contains($imagePath, 'http')) { return $imagePath; diff --git a/src/SeoBundle/Worker/GoogleIndexWorker.php b/src/SeoBundle/Worker/GoogleIndexWorker.php index 98aa41d..c31bb5f 100644 --- a/src/SeoBundle/Worker/GoogleIndexWorker.php +++ b/src/SeoBundle/Worker/GoogleIndexWorker.php @@ -137,7 +137,7 @@ protected function parseResults(array $results, array $processedQueueEntries, ar protected function parseResult(mixed $result, string $queueEntryId, array $processedQueueEntries, array $callable): void { - $linkedQueueEntry = array_reduce($processedQueueEntries, function ($result, QueueEntryInterface $item) use ($queueEntryId) { + $linkedQueueEntry = array_reduce($processedQueueEntries, static function ($result, QueueEntryInterface $item) use ($queueEntryId) { return $item->getUuid() === $queueEntryId ? $item : $result; }); @@ -162,7 +162,7 @@ protected function buildErrorResponse(\Google_Service_Exception $response, Queue $formattedMessages[] = $error['message']; } - $formattedMessage = join(', ', $formattedMessages); + $formattedMessage = implode(', ', $formattedMessages); return new WorkerResponse($formattedStatus, $formattedMessage, false, $linkedQueueEntry, $response); } @@ -182,7 +182,7 @@ protected function buildSuccessResponse(\Google_Service_Indexing_PublishUrlNotif $formattedMessageMeta[] = sprintf('Latest Remove Info: %s %s', $latestRemoveInfo->getType(), $latestRemoveInfo->getNotifyTime()); } - $formattedMessage = sprintf('Url "%s" successfully submitted to index. %s', $notificationMetaData->getUrl(), join(', ', $formattedMessageMeta)); + $formattedMessage = sprintf('Url "%s" successfully submitted to index. %s', $notificationMetaData->getUrl(), implode(', ', $formattedMessageMeta)); return new WorkerResponse(200, $formattedMessage, true, $linkedQueueEntry, $response); } diff --git a/src/SeoBundle/Worker/WorkerResponse.php b/src/SeoBundle/Worker/WorkerResponse.php index b694530..f1a976f 100644 --- a/src/SeoBundle/Worker/WorkerResponse.php +++ b/src/SeoBundle/Worker/WorkerResponse.php @@ -6,7 +6,7 @@ class WorkerResponse implements WorkerResponseInterface { - protected string $status; + protected int $status; protected string $message; protected bool $successFullyProcessed; protected QueueEntryInterface $queueEntry; @@ -21,7 +21,7 @@ public function __construct(int $status, ?string $message, bool $successFullyPro $this->rawResponse = $rawResponse; } - public function getStatus(): string + public function getStatus(): int { return $this->status; } diff --git a/src/SeoBundle/Worker/WorkerResponseInterface.php b/src/SeoBundle/Worker/WorkerResponseInterface.php index f751216..4e3bc9a 100644 --- a/src/SeoBundle/Worker/WorkerResponseInterface.php +++ b/src/SeoBundle/Worker/WorkerResponseInterface.php @@ -6,7 +6,7 @@ interface WorkerResponseInterface { - public function getStatus(): string; + public function getStatus(): int; public function getMessage(): string; From 289c31d02bc71058b2dc73dec2471305a95a7cb3 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Oct 2021 15:59:50 +0200 Subject: [PATCH 3/7] allow null in locale aware array merger --- src/SeoBundle/Helper/ArrayHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SeoBundle/Helper/ArrayHelper.php b/src/SeoBundle/Helper/ArrayHelper.php index a0cf52b..e59d920 100644 --- a/src/SeoBundle/Helper/ArrayHelper.php +++ b/src/SeoBundle/Helper/ArrayHelper.php @@ -4,7 +4,7 @@ class ArrayHelper { - public function mergeLocaleAwareArrays(array $data, ?array $previousData, string $rowIdentifier = 'name', string $dataIdentifier = 'value'): array + public function mergeLocaleAwareArrays(array $data, ?array $previousData, string $rowIdentifier = 'name', string $dataIdentifier = 'value'): ?array { // nothing to merge if (!is_array($previousData) || count($previousData) === 0) { From ad365efcc9346909869cd93b3d021fad8129c31e Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Oct 2021 16:01:47 +0200 Subject: [PATCH 4/7] adjust upgrade notes --- UPGRADE.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9798c67..6d3c5cd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,8 +3,6 @@ ## Migrating from Version 1.x to Version 2.0.0 ### Global Changes -- Deprecations have been removed: - - xx - PHP8 return type declarations added: you may have to adjust your extensions accordingly *** From 07d14b12af42e27b909492fc8845d2b3446b347d Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Oct 2021 16:09:17 +0200 Subject: [PATCH 5/7] move release plan in readme --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 256c40b..9534e44 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,6 @@ [![Tests](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-seo/Codeception/master?style=flat-square&logo=github&label=codeception)](https://github.com/dachcom-digital/pimcore-seo/actions?query=workflow%3ACodeception+branch%3Amaster) [![PhpStan](https://img.shields.io/github/workflow/status/dachcom-digital/pimcore-seo/PHP%20Stan/master?style=flat-square&logo=github&label=phpstan%20level%204)](https://github.com/dachcom-digital/pimcore-seo/actions?query=workflow%3A"PHP+Stan"+branch%3Amaster) -### Release Plan - -| Release | Supported Pimcore Versions | Supported Symfony Versions | Release Date | Maintained | Branch | -|---------|-----------------------------------|----------------------------|--------------|----------------|------------| -| **2.x** | `10.1` | `5.3` | -- | Feature Branch | dev-master | -| **1.x** | `6.0` - `6.9` | `3.4`, `^4.4` | 27.04.2020 | Unsupported | 1.x | - - The last SEO Bundle for pimcore you'll ever need! - Create title, description and meta tags (OG-Tags, Twitter-Cards) for documents **and** objects! @@ -30,6 +22,14 @@ The last SEO Bundle for pimcore you'll ever need! ## Objects | Tabbed View ![image](https://user-images.githubusercontent.com/700119/79804274-0578ea00-8364-11ea-8780-3cd8b2d72376.png) +### Release Plan + +| Release | Supported Pimcore Versions | Supported Symfony Versions | Release Date | Maintained | Branch | +|---------|-----------------------------------|----------------------------|--------------|----------------|------------| +| **2.x** | `10.1` | `5.3` | -- | Feature Branch | dev-master | +| **1.x** | `6.0` - `6.9` | `3.4`, `^4.4` | 27.04.2020 | Unsupported | 1.x | + + ## Installation ```json From 13999fa8a6f50ee67d0d1e8578fd705ab1c01581 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Wed, 13 Oct 2021 16:11:35 +0200 Subject: [PATCH 6/7] remove legacy ecs config file --- LICENSE.md | 2 +- easy-coding-standard.yml | 108 --------------------------------------- 2 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 easy-coding-standard.yml diff --git a/LICENSE.md b/LICENSE.md index 0c51434..e9304ee 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,5 +1,5 @@ # License -Copyright (C) 2020 DACHCOM.DIGITAL +Copyright (C) 2021 DACHCOM.DIGITAL This software is available under the GNU General Public License version 3 (GPLv3). diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml deleted file mode 100644 index 26db9c0..0000000 --- a/easy-coding-standard.yml +++ /dev/null @@ -1,108 +0,0 @@ -imports: - - { resource: '%vendor_dir%/symplify/easy-coding-standard/config/psr2.yml' } - -services: - PhpCsFixer\Fixer\Basic\BracesFixer: - allow_single_line_closure: true - PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer: ~ - PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: - spacing: one - PhpCsFixer\Fixer\Operator\NewWithBracesFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer: - tags: - - method - - param - - property - - return - - throws - - type - - var - PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer: - align_double_arrow: true - PhpCsFixer\Fixer\Operator\IncrementStyleFixer: - style: post - PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~ - PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer: ~ - PhpCsFixer\Fixer\CastNotation\CastSpacesFixer: ~ - PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer: ~ - PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer: ~ - PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer: - comment_types: - - hash - PhpCsFixer\Fixer\ControlStructure\IncludeFixer: ~ - PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer: ~ - PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: - elements: - - method - PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer: ~ - PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer: ~ - PhpCsFixer\Fixer\Phpdoc\NoBlankLinesAfterPhpdocFixer: ~ - PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer: ~ - PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer: ~ - PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer: ~ - PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer: ~ - PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer: - tokens: - - curly_brace_block - - extra - - parenthesis_brace_block - - square_brace_block - - throw - - use - PhpCsFixer\Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer: ~ - PhpCsFixer\Fixer\CastNotation\NoShortBoolCastFixer: ~ - PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer: ~ - PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer: ~ - PhpCsFixer\Fixer\ControlStructure\NoTrailingCommaInListCallFixer: ~ - PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer: ~ - PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer: ~ - PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoPackageFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer: ~ - PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer: ~ - PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer: ~ - PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer: ~ - PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer: ~ - PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer: ~ - PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer: ~ - PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer: ~ - PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer: - singleLine: true - PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer: ~ - PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer: ~ - PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer: - use: echo - PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer: ~ - PhpCsFixer\Fixer\Import\NoUnusedImportsFixer: ~ - PhpCsFixer\Fixer\PhpUnit\PhpUnitFqcnAnnotationFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoAliasTagFixer: ~ - PhpCsFixer\Fixer\ClassNotation\ProtectedToPrivateFixer: ~ - PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer: ~ - PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer: ~ - - # new since PHP-CS-Fixer 2.6 - PhpCsFixer\Fixer\ControlStructure\NoUnneededCurlyBracesFixer: ~ - PhpCsFixer\Fixer\ClassNotation\NoUnneededFinalMethodFixer: ~ - PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer: ~ - - # new since 2.11 - PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer: ~ From e55000fa33476dbafb32ec5f45864a8ac0b781e3 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Thu, 14 Oct 2021 17:26:30 +0200 Subject: [PATCH 7/7] add return types to configuration, add migration paths --- src/SeoBundle/DependencyInjection/Configuration.php | 12 +++++------- src/SeoBundle/Resources/config/pimcore/config.yml | 4 ++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/SeoBundle/DependencyInjection/Configuration.php b/src/SeoBundle/DependencyInjection/Configuration.php index efe9bb1..68bffd1 100644 --- a/src/SeoBundle/DependencyInjection/Configuration.php +++ b/src/SeoBundle/DependencyInjection/Configuration.php @@ -2,15 +2,13 @@ namespace SeoBundle\DependencyInjection; +use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { - /** - * @return TreeBuilder - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('seo'); $rootNode = $treeBuilder->getRootNode(); @@ -22,7 +20,7 @@ public function getConfigTreeBuilder() return $treeBuilder; } - private function createIndexProviderConfigurationNode() + private function createIndexProviderConfigurationNode(): NodeDefinition { $treeBuilder = new TreeBuilder('index_provider_configuration'); $node = $treeBuilder->getRootNode(); @@ -49,7 +47,7 @@ private function createIndexProviderConfigurationNode() return $node; } - private function createMetaDataConfigurationNode() + private function createMetaDataConfigurationNode(): NodeDefinition { $treeBuilder = new TreeBuilder('meta_data_configuration'); $node = $treeBuilder->getRootNode(); @@ -115,7 +113,7 @@ private function createMetaDataConfigurationNode() return $node; } - private function createPersistenceNode() + private function createPersistenceNode(): NodeDefinition { $treeBuilder = new TreeBuilder('persistence'); $node = $treeBuilder->getRootNode(); diff --git a/src/SeoBundle/Resources/config/pimcore/config.yml b/src/SeoBundle/Resources/config/pimcore/config.yml index aa0213c..702424f 100644 --- a/src/SeoBundle/Resources/config/pimcore/config.yml +++ b/src/SeoBundle/Resources/config/pimcore/config.yml @@ -4,3 +4,7 @@ doctrine: entity_managers: default: auto_mapping: true + +doctrine_migrations: + migrations_paths: + 'SeoBundle\Migrations': '@SeoBundle/Migrations' \ No newline at end of file