Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ jobs:

- name: Install dependencies
run: composer install --ansi --no-interaction --no-progress
env:
# humanmade/coding-standards requires wp-coding-standards/wpcs 2.3.0, which has a security advisory
COMPOSER_NO_SECURITY_BLOCKING: 1

- name: Run Tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
/stubs/wordpress/
/stubs/vendor/
/vendor/
/tools/phpcs/vendor/
321 changes: 159 additions & 162 deletions Plugin.php

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"require-dev": {
"dg/bypass-finals": "^1.5",
"humanmade/coding-standards": "^1.2",
"phpunit/phpunit": "^10.5 || ^11.5",
"psalm/plugin-phpunit": "^0.21"
},
Expand All @@ -49,9 +48,6 @@
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"preferred-install": {
"vimeo/psalm": "source"
},
Expand All @@ -64,8 +60,14 @@
"@analyze"
],
"analyze": "psalm",
"cs-check": "phpcs -ps --colors",
"cs-fix": "phpcbf",
"cs-check": [
"@composer --working-dir=tools/phpcs update --no-interaction --quiet",
"tools/phpcs/vendor/bin/phpcs -ps --colors"
],
"cs-fix": [
"@composer --working-dir=tools/phpcs update --no-interaction --quiet",
"tools/phpcs/vendor/bin/phpcbf"
],
"test": "codecept run",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"generate-wordpress-stubs": "cd wordpress ; composer init -n ; composer require "
Expand Down
3 changes: 2 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch" />
<exclude name="Squiz.Commenting.FunctionCommentThrowTag.Missing" />

<!-- Exclude multiple classes sniff -->
<!-- Exclude multiple classes sniffs (WPCS 3 adds the same check as Generic.Files.OneObjectStructurePerFile) -->
<exclude name="HM.Classes.OnlyClassInFile.FoundMultipleDeclarations" />
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
<exclude name="Generic.Files.OneObjectStructurePerFile.MultipleFound" />

<!-- Exclude snake_case property sniffs -->
<exclude name="WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase" />
Expand Down
22 changes: 12 additions & 10 deletions stubs/overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WP_CLI {
* } $args
* @return bool
*/
// phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames -- WP-CLI's parameter name, for named arguments.
public static function add_command( string $name, $callable, array $args = [] ) {}

/**
Expand All @@ -29,6 +30,7 @@ public static function add_command( string $name, $callable, array $args = [] )
* : null
* )
*/
// phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames -- WP-CLI's parameter name, for named arguments.
public static function error( $message, $exit = true ) {}
}

Expand All @@ -43,7 +45,7 @@ public function prepare( $query, $args ) {}
/**
* @template TObject of ARRAY_A|ARRAY_N|OBJECT|OBJECT_K
* @param string|null $query
* @psalm-param TObject $object
* @psalm-param TObject $output
* @return (
* TObject is OBJECT
* ? list<ArrayObject<string, string>>
Expand All @@ -56,7 +58,7 @@ public function prepare( $query, $args ) {}
* )
* )|null
*/
public function get_results( $query = null, $object = \OBJECT ) {}
public function get_results( $query = null, $output = \OBJECT ) {}
}

/**
Expand Down Expand Up @@ -117,10 +119,10 @@ function wp_parse_url( string $url, int $component = -1 ) {}

/**
* @param string $option
* @param mixed $default
* @param mixed $default_value
* @return mixed
*/
function get_option( string $option, $default = null ) {}
function get_option( string $option, $default_value = null ) {}

/**
* @return array[] {
Expand All @@ -144,14 +146,14 @@ function get_option( string $option, $default = null ) {}
* type: string,
* }>
*/
function get_settings_errors( $setting = '', $sanitize = false ) : array {}
function get_settings_errors( $setting = '', $sanitize = false ): array {}

/**
* @param string $path
* @param 'https'|'http'|'relative'|'rest' $scheme
* @return string
*/
function home_url( string $path = '', $scheme = null ) : string {}
function home_url( string $path = '', $scheme = null ): string {}

/**
* @template TArgs of array<array-key, mixed>
Expand All @@ -166,13 +168,13 @@ function wp_parse_args( $args, $defaults ) {}
* @param WP_Error|mixed $error
* @psalm-assert-if-true WP_Error $error
*/
function is_wp_error( $error ) : bool {}
function is_wp_error( $error ): bool {}

/**
* @template T
* @template K
* @param array<array-key, array<K, T>> $list
* @param K $column
* @param array<array-key, array<K, T>> $input_list
* @param K $field
* @return list<T>
*/
function wp_list_pluck( array $list, string $column, string $index_key = null ) : array {}
function wp_list_pluck( array $input_list, string $field, string $index_key = null ): array {}
4 changes: 2 additions & 2 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class PluginTest extends TestCase {
/**
* @return void
*/
public function setUp() : void {
public function setUp(): void {
$this->registration = $this->prophesize( RegistrationInterface::class );
}

/**
* @test
*/
public function hasEntryPoint() : void {
public function hasEntryPoint(): void {
$this->expectNotToPerformAssertions();
$plugin = new Plugin();
$plugin( $this->registration->reveal(), null );
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

require __DIR__ . '/../vendor/autoload.php';

// Psalm's test classes extend classes that are final outside of its test suite
// Psalm's test classes extend classes that are final outside of its test suite.
DG\BypassFinals::enable();
8 changes: 4 additions & 4 deletions tests/unit/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Psalm\Tests\Internal\Provider;

abstract class BaseTestCase extends Psalm\Tests\TestCase {
public function setUp() : void {
public function setUp(): void {
parent::setUp();
$this->project_analyzer->getConfig()->initializePlugins( $this->project_analyzer );
$this->project_analyzer->getConfig()->visitStubFiles( $this->project_analyzer->getCodebase() );
Expand All @@ -19,7 +19,7 @@ public function setUp() : void {
/**
* @return Config
*/
protected function makeConfig() : Config {
protected function makeConfig(): Config {
$config = new TestConfig();
$config->addPluginClass( 'PsalmWordPress\\Plugin' );
return $config;
Expand All @@ -30,7 +30,7 @@ public function analyzeFile(
\Psalm\Context $context,
bool $track_unused_suppressions = true,
bool $taint_flow_tracking = false
) : void {
): void {
$codebase = $this->project_analyzer->getCodebase();
$codebase->addFilesToAnalyze( [ $file_path => $file_path ] );

Expand All @@ -54,7 +54,7 @@ public function __construct() {
$this->setAdvancedErrorLevel( 'InvalidDocblock', [ [ 'type' => 'suppress', 'directory' => [ [ 'name' => 'vendor' ] ] ] ], 'error' );
}

protected function getContents() : string {
protected function getContents(): string {
return '<?xml version="1.0"?>
<projectFiles>
<directory name="./" />
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FiltersTest extends BaseTestCase {
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
*/
public static function providerValidCodeParse() : iterable {
public static function providerValidCodeParse(): iterable {
return [
'add_filter with docblock' => [
<<<'EOD'
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function providerValidCodeParse() : iterable {
/**
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
*/
public static function providerInvalidCodeParse() : iterable {
public static function providerInvalidCodeParse(): iterable {
return [
'add_filter fails wrong types' => [
<<<'EOD'
Expand Down
11 changes: 11 additions & 0 deletions tools/phpcs/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "Psalm plugin for WordPress - coding standards, which need a newer PHP than the plugin supports",
"require": {
"humanmade/coding-standards": "^2.5"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
Loading