Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into master…
Browse files Browse the repository at this point in the history
…-built
  • Loading branch information
Chrico committed Jul 25, 2024
2 parents b85c8cb + 8c8456a commit b598265
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 74 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Chrico
11 changes: 10 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/frontend-qa.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,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')"
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,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.
Expand All @@ -48,8 +44,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 `<target>-built` branch and create the tag and the release.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 30 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<psalm
useDocblockPropertyTypes="true"
usePhpDocMethodsWithoutMagicCall="true"
strictBinaryOperands="true"
hideExternalErrors="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="./src"/>
<file name="./index.php" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<stubs>
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php" />
</stubs>

<issueHandlers>
<MixedAssignment errorLevel="suppress" />
<MissingClosureParamType errorLevel="suppress" />
<MissingClosureReturnType errorLevel="suppress" />
<UnresolvableInclude errorLevel="suppress" />
<UndefinedConstant errorLevel="suppress" />
</issueHandlers>
</psalm>
Binary file modified resources/svn-assets/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/svn-assets/banner-1880x609.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/svn-assets/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/svn-assets/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/svn-assets/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/DataLayer/DataLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/DataLayer/PostDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down
3 changes: 0 additions & 3 deletions src/DataLayer/UserDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public function description(): string
);
}

/**
* {@inheritdoc}
*/
public function data(array $settings): ?array
{
$isLoggedIn = is_user_logged_in();
Expand Down
3 changes: 3 additions & 0 deletions src/Provider/AssetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 4 additions & 20 deletions src/Provider/DataLayerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}

Expand Down
7 changes: 0 additions & 7 deletions src/Provider/SettingsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
},
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Renderer/DataLayerRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ 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;
}
$dataLayerJs .= "\n";
$dataLayerJs .= sprintf(
'%1$s.push(%2$s);',
esc_js($dataLayerName),
wp_json_encode($data)
(string) wp_json_encode($data)
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Rest/DataLayerEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()]);
Expand Down
21 changes: 0 additions & 21 deletions src/Service/DataCollectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 3 additions & 2 deletions src/Service/RestEndpointRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit b598265

Please sign in to comment.