From 31b0bd419a9b1d4effdb74a3caa36bc23a22e551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 25 Jul 2024 08:46:45 +0000 Subject: [PATCH 1/6] Fix corrupted PNG images --- resources/svn-assets/banner-1544x500.png | Bin 71731 -> 71735 bytes resources/svn-assets/banner-1880x609.png | Bin 89753 -> 89754 bytes resources/svn-assets/banner-772x250.png | Bin 28203 -> 28206 bytes resources/svn-assets/icon-128x128.png | Bin 7666 -> 7667 bytes resources/svn-assets/icon-256x256.png | Bin 15165 -> 15166 bytes 5 files changed, 0 insertions(+), 0 deletions(-) diff --git a/resources/svn-assets/banner-1544x500.png b/resources/svn-assets/banner-1544x500.png index 5c5b7a4e4df09bfa30127f693519b3e3a028e95a..da31f8e8adcd58aa9e9479f5bb66ddd45c10c820 100644 GIT binary patch delta 37 rcmdnIfo1y!7S_%HKX=}ZEL&w6c{lHr{V55gHkq%Q0ip&9r+ovwKuAmvtZEIN6mx|OaK4? diff --git a/resources/svn-assets/banner-1880x609.png b/resources/svn-assets/banner-1880x609.png index c76bb4d4717b131e931246fc84c8788ae376bd1c..91ba085eafa6bd6b5a8d6ae8fd15c9c0b84a96b3 100644 GIT binary patch delta 19 acmbQamvz=&R@Tk{KX=|nmaQy|Q{wF= delta 18 ZcmbQWmv!b|R+i2HKlet~t*new;{ZZO23`OF diff --git a/resources/svn-assets/banner-772x250.png b/resources/svn-assets/banner-772x250.png index 3fcd36f886e3e067a5b7f56248fdb1b45c541a06..164cc4d55ab10f1c0e4ea9e62eb37c9842d06b5b 100644 GIT binary patch delta 29 lcmZ2|hjHBGr-S%Bdet~04YfY1ONa4 From c266b31bd130b37340fe79ba33366ce282af3e05 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Thu, 25 Jul 2024 12:35:17 +0200 Subject: [PATCH 2/6] workflows // update workflows to only run in specific branches. add CODEOWNERS file. --- .github/CODEOWNERS | 1 + .github/workflows/e2e.yml | 11 ++++++++++- .github/workflows/frontend-qa.yml | 13 +++++++++++-- .github/workflows/php-qa.yml | 13 ++++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..db0657a --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @Chrico \ No newline at end of file diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c730791..354cc7c 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -1,8 +1,17 @@ name: E2E Testing -on: +on: workflow_dispatch: push: + branches: + - master + - 1.x + - 2.x + pull_request: + branches: + - master + - 1.x + - 2.x # Cancels all previous workflow runs for pull requests that have not completed. concurrency: diff --git a/.github/workflows/frontend-qa.yml b/.github/workflows/frontend-qa.yml index 94de774..ca464a4 100644 --- a/.github/workflows/frontend-qa.yml +++ b/.github/workflows/frontend-qa.yml @@ -1,7 +1,16 @@ name: Static code analysis assets -on: - push: +on: workflow_dispatch: + push: + branches: + - master + - 1.x + - 2.x + pull_request: + branches: + - master + - 1.x + - 2.x jobs: wp-scripts-lint: uses: inpsyde/reusable-workflows/.github/workflows/wp-scripts-lint.yml@main diff --git a/.github/workflows/php-qa.yml b/.github/workflows/php-qa.yml index bbda3a1..0882ad2 100644 --- a/.github/workflows/php-qa.yml +++ b/.github/workflows/php-qa.yml @@ -1,5 +1,16 @@ name: PHP Quality Assurance -on: [ push ] +on: + workflow_dispatch: + push: + branches: + - master + - 1.x + - 2.x + pull_request: + branches: + - master + - 1.x + - 2.x jobs: lint-php: uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main From 4248493908a12891079af5f0538100ae947d8dea Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Thu, 25 Jul 2024 12:38:52 +0200 Subject: [PATCH 3/6] SettingsProvider // removed SettingsPage service. --- src/Provider/SettingsProvider.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Provider/SettingsProvider.php b/src/Provider/SettingsProvider.php index 446f619..ff7ef6c 100644 --- a/src/Provider/SettingsProvider.php +++ b/src/Provider/SettingsProvider.php @@ -4,7 +4,6 @@ namespace Inpsyde\GoogleTagManager\Provider; -use Inpsyde\GoogleTagManager\Settings\SettingsPage; use Inpsyde\GoogleTagManager\Settings\SettingsRepository; use Inpsyde\Modularity\Module\ExecutableModule; use Inpsyde\Modularity\Module\ModuleClassNameIdTrait; @@ -30,12 +29,6 @@ public function services(): array return SettingsRepository::new($properties->textDomain()); }, - SettingsPage::class => static function (ContainerInterface $container): SettingsPage { - /** @var PluginProperties $properties */ - $properties = $container->get(Package::PROPERTIES); - - return SettingsPage::new($properties); - }, ]; } From f7b0e082b3be01d8ed75f802d5574c1f439b8ca6 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Thu, 25 Jul 2024 12:56:44 +0200 Subject: [PATCH 4/6] Update README.md Signed-off-by: Christian Leucht --- README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f94e7fd..d6b7771 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,10 @@ ## Documentation -Documentation can be found in [readme.txt](readme.txt). - -## Requirements - -* WordPress >= 4.6. -* PHP 8.0 or higher. +1. [Intro](./docs/01-intro.md) +2. [Hooks](./docs/02-hooks.md) +3. [Collectors](./docs/03-collectors.md) +4. [FAQ](./docs/99-faq.md) ## How to start development @@ -48,8 +46,6 @@ vendor/bin/phpcs vendor/bin/phpunit ``` -This repository automatically generates a CodeCoverage-report into the `tmp/`-folder, which will not be committed. - ## How to create a release To create a release go to the `-built` branch and create the tag and the release. From ddf314c872b11d97f86e2218e8d0ba29b994c613 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Thu, 25 Jul 2024 15:34:03 +0200 Subject: [PATCH 5/6] Update README.md Signed-off-by: Christian Leucht --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index d6b7771..0928184 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,9 @@ This plugin does not include build assets and PHP-dependencies. Therefore, after **With Yarn:** ```shell -yarn install && yarn build:dev +yarn install && yarn build ``` -For more information, please refer to the [Symfony Encore docs](https://symfony.com/doc/current/frontend.html#webpack-encore) - ## Testing & Quality To run all tests you've to install composer dev-dependencies first. From 87f9fbde2967d303fa352b19233183a6575dbc94 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Thu, 25 Jul 2024 15:48:42 +0200 Subject: [PATCH 6/6] Add vimeo/psalm and php-stubs/wordpress-stubs. --- .github/workflows/php-qa.yml | 5 +++++ composer.json | 4 +++- psalm.xml | 30 +++++++++++++++++++++++++++ src/DataLayer/DataLayer.php | 7 +++++-- src/DataLayer/PostDataCollector.php | 4 ++-- src/DataLayer/UserDataCollector.php | 3 --- src/Provider/AssetProvider.php | 3 +++ src/Provider/DataLayerProvider.php | 24 ++++----------------- src/Renderer/DataLayerRenderer.php | 3 ++- src/Rest/DataLayerEndpoint.php | 2 ++ src/Service/DataCollectorRegistry.php | 21 ------------------- src/Service/RestEndpointRegistry.php | 5 +++-- 12 files changed, 59 insertions(+), 52 deletions(-) create mode 100644 psalm.xml diff --git a/.github/workflows/php-qa.yml b/.github/workflows/php-qa.yml index 0882ad2..9bd8d3d 100644 --- a/.github/workflows/php-qa.yml +++ b/.github/workflows/php-qa.yml @@ -23,6 +23,11 @@ jobs: uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main with: PHP_VERSION: '8.1' + static-code-analysis-php: + uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main + with: + PSALM_ARGS: '--threads=3' + PHP_VERSION: '8.1' tests-unit-php: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'ci skip')" diff --git a/composer.json b/composer.json index 52165b9..a92904b 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,9 @@ "require-dev": { "phpunit/phpunit": "~10", "inpsyde/php-coding-standards": "2.0.0-beta.4", - "brain/monkey": "^2" + "brain/monkey": "^2", + "vimeo/psalm": ">=4.8.1@stable", + "php-stubs/wordpress-stubs": ">=6.6@stable" }, "autoload": { "psr-4": { diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..24d209d --- /dev/null +++ b/psalm.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DataLayer/DataLayer.php b/src/DataLayer/DataLayer.php index 596773b..22a92c1 100644 --- a/src/DataLayer/DataLayer.php +++ b/src/DataLayer/DataLayer.php @@ -95,6 +95,7 @@ public function enabledCollectors(): array public function data(): array { $data = []; + /** @var DataCollector $collector */ foreach ($this->registry->all() as $collector) { if (!in_array($collector->id(), $this->enabledCollectors(), true)) { continue; @@ -106,7 +107,10 @@ public function data(): array $settings = $collector->sanitize($settings); } - $data[$collector->id()] = $collector->data($settings); + $collectorData = $collector->data($settings); + if ($collectorData !== null) { + $data[$collector->id()] = $collectorData; + } } return $data; @@ -176,7 +180,6 @@ public function specification(): array 'label' => __('Enable collectors', 'inpsyde-google-tag-manager'), 'name' => self::SETTING_ENABLED_COLLECTORS, 'type' => 'checkbox', - 'value' => $this->enabledCollectors(), 'choices' => (function (): array { $choices = []; foreach ($this->registry->all() as $data) { diff --git a/src/DataLayer/PostDataCollector.php b/src/DataLayer/PostDataCollector.php index 961c413..9c0a32c 100644 --- a/src/DataLayer/PostDataCollector.php +++ b/src/DataLayer/PostDataCollector.php @@ -58,6 +58,7 @@ public function data(array $settings): ?array // Post data $fields = []; foreach ($settings[self::SETTING__POST_FIELDS] as $field) { + /** @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType */ $fields[$field] = get_post_field($field) ?? ''; } $fields = array_filter($fields); @@ -67,6 +68,7 @@ public function data(array $settings): ?array // Author data $fields = []; foreach ($settings[self::SETTING__AUTHOR_FIELDS] as $field) { + /** @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType */ $fields[$field] = get_the_author_meta($field) ?? ''; } $fields = array_filter($fields); @@ -89,7 +91,6 @@ public function specification(): array 'label' => __('Post fields used in dataLayer', 'inpsyde-google-tag-manager'), 'name' => self::SETTING__POST_FIELDS, 'type' => 'checkbox', - 'value' => $this->settings[self::SETTING__POST_FIELDS], 'choices' => [ [ 'label' => __('ID', 'inpsyde-google-tag-manager'), @@ -166,7 +167,6 @@ public function specification(): array ), 'name' => self::SETTING__AUTHOR_FIELDS, 'type' => 'checkbox', - 'value' => $this->settings[self::SETTING__AUTHOR_FIELDS], 'choices' => [ [ 'label' => __('ID', 'inpsyde-google-tag-manager'), diff --git a/src/DataLayer/UserDataCollector.php b/src/DataLayer/UserDataCollector.php index 1364078..9a33002 100644 --- a/src/DataLayer/UserDataCollector.php +++ b/src/DataLayer/UserDataCollector.php @@ -51,9 +51,6 @@ public function description(): string ); } - /** - * {@inheritdoc} - */ public function data(array $settings): ?array { $isLoggedIn = is_user_logged_in(); diff --git a/src/Provider/AssetProvider.php b/src/Provider/AssetProvider.php index 778601a..a172a92 100644 --- a/src/Provider/AssetProvider.php +++ b/src/Provider/AssetProvider.php @@ -33,6 +33,9 @@ public function run(ContainerInterface $container): bool $properties = $container->get(Package::PROPERTIES); $screen = get_current_screen(); + if ($screen === null) { + return; + } if ($screen->base !== 'settings_page_' . $properties->baseName()) { return; } diff --git a/src/Provider/DataLayerProvider.php b/src/Provider/DataLayerProvider.php index f770d92..3c0ccf3 100644 --- a/src/Provider/DataLayerProvider.php +++ b/src/Provider/DataLayerProvider.php @@ -36,26 +36,10 @@ public function services(): array $container->get(DataCollectorRegistry::class), ); }, - UserDataCollector::class => static function (ContainerInterface $container): UserDataCollector { - $settingsRepository = $container->get(SettingsRepository::class); - - return UserDataCollector::new($settingsRepository->option(UserDataCollector::ID)); - }, - SiteInfoDataCollector::class => static function (ContainerInterface $container): SiteInfoDataCollector { - $settingsRepository = $container->get(SettingsRepository::class); - - return SiteInfoDataCollector::new($settingsRepository->option(SiteInfoDataCollector::ID)); - }, - PostDataCollector::class => static function (ContainerInterface $container): PostDataCollector { - $settingsRepository = $container->get(SettingsRepository::class); - - return PostDataCollector::new($settingsRepository->option(PostDataCollector::ID)); - }, - SearchDataCollector::class => static function (ContainerInterface $container): SearchDataCollector { - $settingsRepository = $container->get(SettingsRepository::class); - - return SearchDataCollector::new($settingsRepository->option(SearchDataCollector::ID)); - }, + UserDataCollector::class => [UserDataCollector::class, 'new'], + SiteInfoDataCollector::class => [SiteInfoDataCollector::class, 'new'], + PostDataCollector::class => [PostDataCollector::class, 'new'], + SearchDataCollector::class => [SearchDataCollector::class, 'new'], ]; } diff --git a/src/Renderer/DataLayerRenderer.php b/src/Renderer/DataLayerRenderer.php index 2b94813..a0769b0 100644 --- a/src/Renderer/DataLayerRenderer.php +++ b/src/Renderer/DataLayerRenderer.php @@ -36,6 +36,7 @@ public function render(): bool $dataLayerJs = sprintf('var %1$s = %1$s || [];', esc_js($dataLayerName)); foreach ($dataLayerPushData as $data) { + /** @psalm-suppress DocblockTypeContradiction */ if (!is_array($data) || count($data) < 1) { continue; } @@ -43,7 +44,7 @@ public function render(): bool $dataLayerJs .= sprintf( '%1$s.push(%2$s);', esc_js($dataLayerName), - wp_json_encode($data) + (string) wp_json_encode($data) ); } diff --git a/src/Rest/DataLayerEndpoint.php b/src/Rest/DataLayerEndpoint.php index 8fcb479..746fe5b 100644 --- a/src/Rest/DataLayerEndpoint.php +++ b/src/Rest/DataLayerEndpoint.php @@ -4,6 +4,7 @@ namespace Inpsyde\GoogleTagManager\Rest; +use Inpsyde\GoogleTagManager\DataLayer\DataCollector; use Inpsyde\GoogleTagManager\DataLayer\DataLayer; use Inpsyde\GoogleTagManager\Service\DataCollectorRegistry; use Inpsyde\GoogleTagManager\Settings\SettingsRepository; @@ -85,6 +86,7 @@ public function updateDataLayer(\WP_REST_Request $request): \WP_REST_Response $settings[$this->dataLayer->id()] = $dataLayerSettings; } + /** @var DataCollector $collector */ foreach ($this->registry->all() as $collector) { if (!$collector instanceof SettingsSpecification) { unset($settings[$collector->id()]); diff --git a/src/Service/DataCollectorRegistry.php b/src/Service/DataCollectorRegistry.php index 969c56a..eac2938 100644 --- a/src/Service/DataCollectorRegistry.php +++ b/src/Service/DataCollectorRegistry.php @@ -35,25 +35,4 @@ public function all(): array { return $this->collectors; } - - public function allFormFields(): array - { - $fields = []; - foreach ($this->all() as $collector) { - if (!$collector instanceof SettingsSpecification) { - continue; - } - $fields[] = [ - 'label' => $collector->name(), - 'description' => $collector->description(), - 'attributes' => [ - 'name' => $collector->id(), - 'type' => 'collection', - ], - 'elements' => $collector->settingsSpec(), - ]; - } - - return $fields; - } } diff --git a/src/Service/RestEndpointRegistry.php b/src/Service/RestEndpointRegistry.php index c1502b9..1c8abac 100644 --- a/src/Service/RestEndpointRegistry.php +++ b/src/Service/RestEndpointRegistry.php @@ -52,9 +52,10 @@ public function addEndpoint(RestEndpoint $endpoint): void foreach ($args as $arg) { $name = $arg['entityName'] ?? ''; $baseUrl = $arg['entityBaseUrl'] ?? ''; - if (!$name || !$baseUrl) { + if ($name === '' || $baseUrl === '') { continue; } + /** @psalm-suppress InvalidPropertyAssignmentValue */ $this->entities[$name] = [ 'label' => (string) $arg['label'], 'name' => (string) $name, @@ -74,7 +75,7 @@ public function addEndpoint(RestEndpoint $endpoint): void public function register(): bool { foreach ($this->endpoints as $base => $endpoint) { - if ($this->registered[$base] ?? false) { + if (isset($this->registered[$base])) { continue; } foreach ($endpoint->routes() as $route => $args) {