Skip to content

Commit

Permalink
Reintroduce Psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Jun 9, 2024
1 parent 6da08c0 commit 5295974
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ jobs:

- name: Check code styles
run: composer cs

- name: Check Static Analysis
run: composer psalm
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.psalm
/.idea/
/.vscode/
/build/
Expand Down
13 changes: 13 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PHPSTORM_META {
override(
\Psr\Container\ContainerInterface::get(0),
map(
[
'' => '@',
\Inpsyde\Modularity\Package::PROPERTIES => \Inpsyde\Modularity\Properties\Properties::class,
]
)
);
}
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
6 changes: 5 additions & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__;

Expand All @@ -24,6 +27,7 @@ function autoload(string $projectRoot): void
if (!\is_readable($autoloadFile)) {
return;
}
/** @psalm-suppress UnresolvableInclude */
require_once $autoloadFile;
}

Expand Down
38 changes: 38 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="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"
findUnusedBaselineEntry="true"
findUnusedCode="true"
cacheDirectory="./.psalm"
>
<projectFiles>
<file name="plugin.php" />
<directory name="sources/server" />
<ignoreFiles>
<directory name="vendor" />
<directory name="tests" />
</ignoreFiles>
</projectFiles>

<!-- https://github.com/vimeo/psalm/issues/5791 -->
<!-- Do not stub noop.php -->
<stubs>
<file name="vendor/roots/wordpress-no-content/wp-includes/l10n.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/theme.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/formatting.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/kses.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/plugin.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/blocks.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/post.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/functions.wp-scripts.php"/>
<file name="vendor/roots/wordpress-no-content/wp-includes/functions.wp-styles.php"/>
</stubs>

<extraFiles>
<directory name="vendor/roots/wordpress-no-content"/>
</extraFiles>
</psalm>
2 changes: 1 addition & 1 deletion sources/server/src/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions sources/server/src/Modules/BlockEditor/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, 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',
Expand Down
3 changes: 1 addition & 2 deletions sources/server/src/Modules/E2e/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Psr\Container;

/**
* @internal
* @internal \Widoz\Wp\EntitiesSearch
*/
class Module implements Modularity\Module\ExecutableModule
{
Expand Down Expand Up @@ -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);
});
Expand Down
13 changes: 9 additions & 4 deletions sources/server/src/Modules/Logging/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>, 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
);
Expand Down

0 comments on commit 5295974

Please sign in to comment.