diff --git a/.github/workflows/php-qa.yml b/.github/workflows/php-qa.yml index a822a10..88d697e 100644 --- a/.github/workflows/php-qa.yml +++ b/.github/workflows/php-qa.yml @@ -32,3 +32,6 @@ jobs: - name: Check code styles run: composer cs + + - name: Check Static Analysis + run: composer psalm diff --git a/.gitignore b/.gitignore index fdd2dd2..4af5ac5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.psalm /.idea/ /.vscode/ /build/ diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 0000000..914608b --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,13 @@ + '@', + \Inpsyde\Modularity\Package::PROPERTIES => \Inpsyde\Modularity\Properties\Properties::class, + ] + ) + ); +} diff --git a/composer.json b/composer.json index e2bc079..9c4badf 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "require-dev": { "inpsyde/modularity": "^1.5", "inpsyde/php-coding-standards": "^1.0", - "roots/wordpress-no-content": "^6.3" + "roots/wordpress-no-content": "^6.3", + "vimeo/psalm": "^5.24" }, "config": { "platform": { @@ -33,6 +34,7 @@ }, "scripts": { "cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", - "cs:fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" + "cs:fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf", + "psalm": "@php ./vendor/bin/psalm" } } diff --git a/plugin.php b/plugin.php index 8535870..c118a73 100644 --- a/plugin.php +++ b/plugin.php @@ -9,12 +9,15 @@ declare(strict_types=1); +namespace Widoz\Wp\EntitiesSearch; + use Inpsyde\Modularity; use Widoz\Wp\EntitiesSearch; function package(): Modularity\Package { - static $package; + /** @var Modularity\Package|null $package */ + static $package = null; $projectRoot = __DIR__; @@ -24,6 +27,7 @@ function autoload(string $projectRoot): void if (!\is_readable($autoloadFile)) { return; } + /** @psalm-suppress UnresolvableInclude */ require_once $autoloadFile; } diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..2b76a7f --- /dev/null +++ b/psalm.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sources/server/src/Library.php b/sources/server/src/Library.php index 0d46660..20ac493 100644 --- a/sources/server/src/Library.php +++ b/sources/server/src/Library.php @@ -8,7 +8,7 @@ class Library { - public static function new(string $baseUrl = null): Library + public static function new(string $baseUrl): Library { return new self($baseUrl); } diff --git a/sources/server/src/Modules/BlockEditor/Module.php b/sources/server/src/Modules/BlockEditor/Module.php index 86fa957..46e8946 100644 --- a/sources/server/src/Modules/BlockEditor/Module.php +++ b/sources/server/src/Modules/BlockEditor/Module.php @@ -26,16 +26,19 @@ final private function __construct() public function run(Container\ContainerInterface $container): bool { \add_action('init', static function () use ($container) { - /** @var Modularity\Properties\Properties $properties */ $properties = $container->get(Modularity\Package::PROPERTIES); $baseDir = \untrailingslashit($properties->basePath()); $baseUrl = \untrailingslashit($properties->baseUrl()); - $asset = include "{$baseDir}/build/main.asset.php"; - $version = $properties->isDebug() ? $asset['version'] : $properties->version(); - $dependencies = $asset['dependencies']; + /** + * @var array{dependencies?: array, version?: string} $asset + * @psalm-suppress UnresolvableInclude + */ + $asset = (array)include "{$baseDir}/build/main.asset.php"; + $dependencies = (array)($asset['dependencies'] ?? null); self::isInDebugMode() and $dependencies[] = 'wp-entities-search-logging'; + $version = (string)($asset['version'] ?? null) ?: false; \wp_register_script( 'wp-entities-search', diff --git a/sources/server/src/Modules/E2e/Module.php b/sources/server/src/Modules/E2e/Module.php index 937b4eb..136bc4b 100644 --- a/sources/server/src/Modules/E2e/Module.php +++ b/sources/server/src/Modules/E2e/Module.php @@ -8,7 +8,7 @@ use Psr\Container; /** - * @internal + * @internal \Widoz\Wp\EntitiesSearch */ class Module implements Modularity\Module\ExecutableModule { @@ -52,7 +52,6 @@ public function run(Container\ContainerInterface $container): bool // TODO Add WpContext to avoid run if not the right context. \add_action('init', static function () use ($container) { - /** @var Modularity\Properties\Properties $properties */ $properties = $container->get(Modularity\Package::PROPERTIES); self::postTypesExample($properties); }); diff --git a/sources/server/src/Modules/Logging/Module.php b/sources/server/src/Modules/Logging/Module.php index 37249c0..af7b5bf 100644 --- a/sources/server/src/Modules/Logging/Module.php +++ b/sources/server/src/Modules/Logging/Module.php @@ -30,18 +30,23 @@ public function run(Container\ContainerInterface $container): bool } \add_action('init', static function () use ($container) { - /** @var Modularity\Properties\Properties $properties */ $properties = $container->get(Modularity\Package::PROPERTIES); $baseDir = \untrailingslashit($properties->basePath()); $baseUrl = \untrailingslashit($properties->baseUrl()); - $asset = include "{$baseDir}/build/logging.asset.php"; - $version = $properties->isDebug() ? $asset['version'] : $properties->version(); + + /** + * @var array{dependencies?: array, version?: string} $asset + * @psalm-suppress UnresolvableInclude + */ + $asset = (array)include "{$baseDir}/build/logging.asset.php"; + $dependencies = (array)($asset['dependencies'] ?? null); + $version = (string)($asset['version'] ?? null) ?: false; \wp_register_script( 'wp-entities-search-logging', "{$baseUrl}/build/logging.js", - $asset['dependencies'], + $dependencies, $version, true );