diff --git a/composer.lock b/composer.lock index 034ce0501..f4d2b049a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "081cc25b52dc5280fc49116979b18323", + "content-hash": "b739e3ef69933bcc04ff49d0025ea2ad", "packages": [ { "name": "composer/installers", @@ -2032,112 +2032,6 @@ ], "time": "2024-05-20T13:34:27+00:00" }, - { - "name": "phpstan/extension-installer", - "version": "1.4.3", - "source": { - "type": "git", - "url": "https://github.com/phpstan/extension-installer.git", - "reference": "85e90b3942d06b2326fba0403ec24fe912372936" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", - "reference": "85e90b3942d06b2326fba0403ec24fe912372936", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^2.0", - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.9.0 || ^2.0" - }, - "require-dev": { - "composer/composer": "^2.0", - "php-parallel-lint/php-parallel-lint": "^1.2.0", - "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" - }, - "type": "composer-plugin", - "extra": { - "class": "PHPStan\\ExtensionInstaller\\Plugin" - }, - "autoload": { - "psr-4": { - "PHPStan\\ExtensionInstaller\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Composer plugin for automatic installation of PHPStan extensions", - "keywords": [ - "dev", - "static analysis" - ], - "support": { - "issues": "https://github.com/phpstan/extension-installer/issues", - "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" - }, - "time": "2024-09-04T20:21:43+00:00" - }, - { - "name": "phpstan/phpstan", - "version": "2.1.6", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c", - "reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c", - "shasum": "" - }, - "require": { - "php": "^7.4|^8.0" - }, - "conflict": { - "phpstan/phpstan-shim": "*" - }, - "bin": [ - "phpstan", - "phpstan.phar" - ], - "type": "library", - "autoload": { - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPStan - PHP Static Analysis Tool", - "keywords": [ - "dev", - "static analysis" - ], - "support": { - "docs": "https://phpstan.org/user-guide/getting-started", - "forum": "https://github.com/phpstan/phpstan/discussions", - "issues": "https://github.com/phpstan/phpstan/issues", - "security": "https://github.com/phpstan/phpstan/security/policy", - "source": "https://github.com/phpstan/phpstan-src" - }, - "funding": [ - { - "url": "https://github.com/ondrejmirtes", - "type": "github" - }, - { - "url": "https://github.com/phpstan", - "type": "github" - } - ], - "time": "2025-02-19T15:46:42+00:00" - }, { "name": "phpunit/php-code-coverage", "version": "9.2.32", @@ -3523,75 +3417,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "shipmonk/dead-code-detector", - "version": "0.8.1", - "source": { - "type": "git", - "url": "https://github.com/shipmonk-rnd/dead-code-detector.git", - "reference": "1935d9b58b92ce8d2522d8c72ef310de4d0c3508" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/shipmonk-rnd/dead-code-detector/zipball/1935d9b58b92ce8d2522d8c72ef310de4d0c3508", - "reference": "1935d9b58b92ce8d2522d8c72ef310de4d0c3508", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0", - "phpstan/phpstan": "^2.0" - }, - "require-dev": { - "doctrine/orm": "^2.19 || ^3.0", - "editorconfig-checker/editorconfig-checker": "^10.3.0", - "ergebnis/composer-normalize": "^2.28", - "nette/application": "^3.1", - "nette/component-model": "^3.0", - "nette/utils": "^3.0 || ^4.0", - "nikic/php-parser": "^5.3.1", - "phpstan/phpstan-phpunit": "^2.0.0", - "phpstan/phpstan-strict-rules": "^2.0.0", - "phpstan/phpstan-symfony": "^2.0.0", - "phpunit/phpunit": "^9.6.21", - "shipmonk/composer-dependency-analyser": "^1.8.1", - "shipmonk/name-collision-detector": "^2.0.0", - "shipmonk/phpstan-rules": "^4.0.0", - "slevomat/coding-standard": "^8.15.0", - "symfony/contracts": "^2.5 || ^3.0", - "symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0", - "symfony/http-kernel": "^5.4 || ^6.0 || ^7.0", - "symfony/routing": "^5.4 || ^6.0 || ^7.0" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "rules.neon" - ] - } - }, - "autoload": { - "psr-4": { - "ShipMonk\\PHPStan\\DeadCode\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles.", - "keywords": [ - "PHPStan", - "dead code", - "static analysis", - "unused code" - ], - "support": { - "issues": "https://github.com/shipmonk-rnd/dead-code-detector/issues", - "source": "https://github.com/shipmonk-rnd/dead-code-detector/tree/0.8.1" - }, - "time": "2025-01-22T10:23:04+00:00" - }, { "name": "squizlabs/php_codesniffer", "version": "3.11.3", @@ -3676,68 +3501,6 @@ ], "time": "2025-01-23T17:04:15+00:00" }, - { - "name": "szepeviktor/phpstan-wordpress", - "version": "v2.0.1", - "source": { - "type": "git", - "url": "https://github.com/szepeviktor/phpstan-wordpress.git", - "reference": "f7beb13cd22998e3d913fdb897a1e2553ccd637e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/f7beb13cd22998e3d913fdb897a1e2553ccd637e", - "reference": "f7beb13cd22998e3d913fdb897a1e2553ccd637e", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0", - "php-stubs/wordpress-stubs": "^6.6.2", - "phpstan/phpstan": "^2.0" - }, - "require-dev": { - "composer/composer": "^2.1.14", - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "php-parallel-lint/php-parallel-lint": "^1.1", - "phpstan/phpstan-strict-rules": "^2.0", - "phpunit/phpunit": "^9.0", - "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.0", - "wp-coding-standards/wpcs": "3.1.0 as 2.3.0" - }, - "suggest": { - "swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods" - }, - "type": "phpstan-extension", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - } - }, - "autoload": { - "psr-4": { - "SzepeViktor\\PHPStan\\WordPress\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "WordPress extensions for PHPStan", - "keywords": [ - "PHPStan", - "code analyse", - "code analysis", - "static analysis", - "wordpress" - ], - "support": { - "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", - "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v2.0.1" - }, - "time": "2024-12-01T02:13:05+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.3", diff --git a/library/App.php b/library/App.php index c7b170409..a7cc3d2b1 100644 --- a/library/App.php +++ b/library/App.php @@ -926,6 +926,7 @@ private function setupExternalContent(): void * Sync external content. */ $this->wpService->addAction('Municipio/ExternalContent/Sync', function (string $postType, ?int $postId = null) use ($sourceConfigs) { + $sourceConfig = reset(array_filter($sourceConfigs, fn($config) => $config->getPostType() === $postType)); $sourceReader = (new \Municipio\ExternalContent\SourceReaders\Factories\SourceReaderFromConfig())->create($sourceConfig); $schemaObjectToPost = (new \Municipio\ExternalContent\WpPostArgsFromSchemaObject\Factory\Factory($sourceConfig))->create(); diff --git a/library/ExternalContent/Config/SourceConfig.php b/library/ExternalContent/Config/SourceConfig.php index 1def5b75a..6ee7b6cb9 100644 --- a/library/ExternalContent/Config/SourceConfig.php +++ b/library/ExternalContent/Config/SourceConfig.php @@ -2,6 +2,8 @@ namespace Municipio\ExternalContent\Config; +use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition; + /** * Class SourceConfig * @@ -25,17 +27,18 @@ class SourceConfig implements SourceConfigInterface * @param string $sourceTypesenseCollection */ public function __construct( - private string $postType = '', - private string $automaticImportSchedule = '', - private string $schemaType = '', - private string $sourceType = '', - private array $taxonomies = [], - private string $sourceJsonFilePath = '', - private string $sourceTypesenseApiKey = '', - private string $sourceTypesenseProtocol = '', - private string $sourceTypesenseHost = '', - private string $sourceTypesensePort = '', - private string $sourceTypesenseCollection = '' + private string $postType, + private string $automaticImportSchedule, + private string $schemaType, + private string $sourceType, + private array $taxonomies, + private string $sourceJsonFilePath, + private string $sourceTypesenseApiKey, + private string $sourceTypesenseProtocol, + private string $sourceTypesenseHost, + private string $sourceTypesensePort, + private string $sourceTypesenseCollection, + private FilterDefinition $filterDefinition ) { } @@ -134,4 +137,12 @@ public function getId(): string { return $this->postType; } + + /** + * @inheritDoc + */ + public function getFilterDefinition(): FilterDefinition + { + return $this->filterDefinition; + } } diff --git a/library/ExternalContent/Config/SourceConfigFactory.php b/library/ExternalContent/Config/SourceConfigFactory.php index 0a473f026..60bcc0691 100644 --- a/library/ExternalContent/Config/SourceConfigFactory.php +++ b/library/ExternalContent/Config/SourceConfigFactory.php @@ -3,6 +3,7 @@ namespace Municipio\ExternalContent\Config; use Municipio\Config\Features\SchemaData\SchemaDataConfigInterface; +use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\FilterDefinition; use WpService\Contracts\GetOption; use WpService\Contracts\GetOptions; @@ -77,7 +78,8 @@ private function createSourceConfigsFromNamedSettings(array $namedSettings): Sou $namedSettings['source_typesense_protocol'] ?? '', $namedSettings['source_typesense_host'] ?? '', $namedSettings['source_typesense_port'] ?? '', - $namedSettings['source_typesense_collection'] ?? '' + $namedSettings['source_typesense_collection'] ?? '', + new FilterDefinition([]) ); } diff --git a/library/ExternalContent/Config/SourceConfigInterface.php b/library/ExternalContent/Config/SourceConfigInterface.php index 8c235b735..0c5201714 100644 --- a/library/ExternalContent/Config/SourceConfigInterface.php +++ b/library/ExternalContent/Config/SourceConfigInterface.php @@ -2,6 +2,8 @@ namespace Municipio\ExternalContent\Config; +use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition; + interface SourceConfigInterface { /** @@ -85,4 +87,11 @@ public function getSourceTypesenseCollection(): string; * Get the source unique ID */ public function getId(): string; + + /** + * Retrieves the filter definition. + * + * @return FilterDefinition The filter definition. + */ + public function getFilterDefinition(): FilterDefinition; } diff --git a/library/ExternalContent/Config/SourceConfigWithUniqueId.php b/library/ExternalContent/Config/SourceConfigWithUniqueId.php index 013425f57..7e327e5d5 100644 --- a/library/ExternalContent/Config/SourceConfigWithUniqueId.php +++ b/library/ExternalContent/Config/SourceConfigWithUniqueId.php @@ -2,6 +2,8 @@ namespace Municipio\ExternalContent\Config; +use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition; + /** * Class SourceConfig * @@ -103,6 +105,14 @@ public function getSourceTypesenseCollection(): string return $this->inner->getSourceTypesenseCollection(); } + /** + * @inheritDoc + */ + public function getFilterDefinition(): FilterDefinition + { + return $this->inner->getFilterDefinition(); + } + /** * @inheritDoc */ diff --git a/library/ExternalContent/Cron/WpCronJobFromPostTypeSettings/WpCronJobFromPostTypeSettings.test.php b/library/ExternalContent/Cron/WpCronJobFromPostTypeSettings/WpCronJobFromPostTypeSettings.test.php index 8cf74a0e5..81ec4e144 100644 --- a/library/ExternalContent/Cron/WpCronJobFromPostTypeSettings/WpCronJobFromPostTypeSettings.test.php +++ b/library/ExternalContent/Cron/WpCronJobFromPostTypeSettings/WpCronJobFromPostTypeSettings.test.php @@ -6,6 +6,7 @@ use Municipio\Config\Features\ExternalContent\SourceConfig\TypesenseSourceConfigInterface; use Municipio\Config\Features\ExternalContent\SourceConfig\JsonSourceConfigInterface; use Municipio\ExternalContent\Config\SourceConfigInterface; +use Municipio\ExternalContent\PropertyPathFilter\FilterDefinition\Contracts\FilterDefinition; use PHPUnit\Framework\TestCase; use WpService\Implementations\FakeWpService; @@ -101,6 +102,10 @@ public function getId(): string { return 'test-id'; } + public function getFilterDefinition(): FilterDefinition + { + return new FilterDefinition([]); + } }; } } diff --git a/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.php b/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.php index a16c512df..af3c80f31 100644 --- a/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.php +++ b/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.php @@ -19,9 +19,6 @@ class FilterDefinition implements FilterDefinitionInterface */ public function __construct(private array $ruleSets) { - if (empty($ruleSets)) { - throw new \InvalidArgumentException('No rulesets provided.'); - } } /** diff --git a/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.test.php b/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.test.php index b0d2b44eb..420f5e966 100644 --- a/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.test.php +++ b/library/ExternalContent/PropertyPathFilter/FilterDefinition/FilterDefinition.test.php @@ -16,15 +16,6 @@ public function testCanBeInstantiated() $this->assertInstanceOf(FilterDefinition::class, $filterDefinition); } - /** - * @testdox class can not be instantiated with empty ruleSets - */ - public function testCanBeInstantiatedWithEmptyRuleSets() - { - $this->expectException(\InvalidArgumentException::class); - new FilterDefinition([]); - } - /** * @testdox getRuleSets() returns provided ruleSets */