Skip to content

Commit 2bd4b7d

Browse files
Move several extensions to WP stubs (#235)
* remove get_posts extension * remove get_approved_comments extension * remove get_sites extension * remove get_terms extension * ignore phpcs warning about mkdir * sync with master * remove get_post extension * add error identifiers * add see tags * remove unnecessary in_array() * sort use statements * use ::class * register HookDocBlock as service * Upgrade ruleset (#230) * fix * fix cs * update CI * fix/update extension for wp_parse_url * rename variables with reserved names * remove else statement * fix TravisCI badge * raise phpstan constraint * remove echo key extension * remove obsolete redirect_canonical extension * remove wp_die extension * remove _get_list_table extension * Remove WP_Theme magic properties extension * Update required php-stubs/wordpress-stubs --------- Co-authored-by: Viktor Szépe <[email protected]>
1 parent 585c2c6 commit 2bd4b7d

36 files changed

+174
-1827
lines changed

.travis.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@ os:
88
dist: "bionic"
99

1010
php:
11+
- "8.3"
12+
- "8.2"
13+
- "8.1"
1114
- "8.0"
1215
- "7.4"
13-
- "7.2"
1416

1517
env:
16-
- TYPOS_VERSION="1.16.22"
18+
- TYPOS_VERSION="1.22.9"
1719

1820
jobs:
1921
include:
20-
-
21-
php: "8.1"
22-
script:
23-
- "composer test:syntax -- --no-progress"
24-
- "composer test:phpunit -- --verbose"
25-
# - "composer test:cs -- -s"
26-
- "composer test:phpstan -- --ansi --no-progress"
2722
-
2823
name: "With lowest deps"
2924
php: "7.4"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Thank you!
1212
[![Packagist stats](https://img.shields.io/packagist/dt/szepeviktor/phpstan-wordpress.svg)](https://packagist.org/packages/szepeviktor/phpstan-wordpress/stats)
1313
[![Packagist](https://img.shields.io/packagist/v/szepeviktor/phpstan-wordpress.svg?color=239922&style=popout)](https://packagist.org/packages/szepeviktor/phpstan-wordpress)
1414
[![Tweet](https://img.shields.io/badge/Tweet-share-d5d5d5?style=social&logo=twitter)](https://twitter.com/intent/tweet?text=Static%20analysis%20for%20WordPress&url=https%3A%2F%2Fgithub.com%2Fszepeviktor%2Fphpstan-wordpress)
15-
[![Build Status](https://travis-ci.com/szepeviktor/phpstan-wordpress.svg?branch=master)](https://travis-ci.com/github/szepeviktor/phpstan-wordpress)
15+
[![Build Status](https://app.travis-ci.com/szepeviktor/phpstan-wordpress.svg?token=CgYVxsSdNVnRNCDNV3qG&branch=master)](https://app.travis-ci.com/szepeviktor/phpstan-wordpress)
1616
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-239922)](https://github.com/phpstan/phpstan)
1717

1818
Static analysis for the WordPress ecosystem.

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
],
1313
"require": {
1414
"php": "^7.2 || ^8.0",
15-
"php-stubs/wordpress-stubs": "^6.2.1",
16-
"phpstan/phpstan": "^1.10.31",
15+
"php-stubs/wordpress-stubs": "^6.6.2",
16+
"phpstan/phpstan": "^1.11.0",
1717
"symfony/polyfill-php73": "^1.12.0"
1818
},
1919
"require-dev": {
@@ -22,7 +22,8 @@
2222
"php-parallel-lint/php-parallel-lint": "^1.1",
2323
"phpstan/phpstan-strict-rules": "^1.2",
2424
"phpunit/phpunit": "^8.0 || ^9.0",
25-
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.11"
25+
"szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.0",
26+
"wp-coding-standards/wpcs": "3.1.0 as 2.3.0"
2627
},
2728
"suggest": {
2829
"swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods"

extension.neon

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,10 @@
11
services:
22
-
3-
class: SzepeViktor\PHPStan\WordPress\WpThemeMagicPropertiesClassReflectionExtension
4-
tags:
5-
- phpstan.broker.propertiesClassReflectionExtension
6-
-
7-
class: SzepeViktor\PHPStan\WordPress\EchoKeyDynamicFunctionReturnTypeExtension
8-
tags:
9-
- phpstan.broker.dynamicFunctionReturnTypeExtension
10-
-
11-
class: SzepeViktor\PHPStan\WordPress\GetApprovedCommentsDynamicFunctionReturnTypeExtension
12-
tags:
13-
- phpstan.broker.dynamicFunctionReturnTypeExtension
14-
-
15-
class: SzepeViktor\PHPStan\WordPress\GetListTableDynamicFunctionReturnTypeExtension
16-
tags:
17-
- phpstan.broker.dynamicFunctionReturnTypeExtension
18-
-
19-
class: SzepeViktor\PHPStan\WordPress\RedirectCanonicalDynamicFunctionReturnTypeExtension
20-
tags:
21-
- phpstan.broker.dynamicFunctionReturnTypeExtension
3+
class: SzepeViktor\PHPStan\WordPress\HookDocBlock
224
-
235
class: SzepeViktor\PHPStan\WordPress\EscSqlDynamicFunctionReturnTypeExtension
246
tags:
257
- phpstan.broker.dynamicFunctionReturnTypeExtension
26-
-
27-
class: SzepeViktor\PHPStan\WordPress\GetTermsDynamicFunctionReturnTypeExtension
28-
tags:
29-
- phpstan.broker.dynamicFunctionReturnTypeExtension
30-
-
31-
class: SzepeViktor\PHPStan\WordPress\GetPostDynamicFunctionReturnTypeExtension
32-
tags:
33-
- phpstan.broker.dynamicFunctionReturnTypeExtension
34-
-
35-
class: SzepeViktor\PHPStan\WordPress\GetPostsDynamicFunctionReturnTypeExtension
36-
tags:
37-
- phpstan.broker.dynamicFunctionReturnTypeExtension
38-
-
39-
class: SzepeViktor\PHPStan\WordPress\GetSitesDynamicFunctionReturnTypeExtension
40-
tags:
41-
- phpstan.broker.dynamicFunctionReturnTypeExtension
428
-
439
class: SzepeViktor\PHPStan\WordPress\ShortcodeAttsDynamicFunctionReturnTypeExtension
4410
tags:
@@ -51,10 +17,6 @@ services:
5117
class: SzepeViktor\PHPStan\WordPress\WpParseUrlFunctionDynamicReturnTypeExtension
5218
tags:
5319
- phpstan.broker.dynamicFunctionReturnTypeExtension
54-
-
55-
class: SzepeViktor\PHPStan\WordPress\WpDieDynamicFunctionReturnTypeExtension
56-
tags:
57-
- phpstan.broker.dynamicFunctionReturnTypeExtension
5820
-
5921
class: SzepeViktor\PHPStan\WordPress\HookDocsVisitor
6022
tags:

phpstan.neon.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ includes:
33
- vendor/phpstan/phpstan-strict-rules/rules.neon
44
parameters:
55
level: 9
6-
# WpThemeMagicPropertiesClassReflectionExtension needs WP_Theme
76
scanFiles:
7+
# AssertWpErrorTypeSpecifyingExtension needs WP_Error
8+
# AssertNotWpErrorTypeSpecifyingExtension needs WP_Error
89
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
910
paths:
1011
- bootstrap.php

src/ApplyFiltersDynamicFunctionReturnTypeExtension.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
use PhpParser\Node\Expr\FuncCall;
1212
use PHPStan\Analyser\Scope;
1313
use PHPStan\Reflection\FunctionReflection;
14-
use PHPStan\Type\FileTypeMapper;
15-
use PHPStan\Type\Type;
1614
use PHPStan\Type\MixedType;
15+
use PHPStan\Type\Type;
1716

1817
class ApplyFiltersDynamicFunctionReturnTypeExtension implements \PHPStan\Type\DynamicFunctionReturnTypeExtension
1918
{
2019
/** @var \SzepeViktor\PHPStan\WordPress\HookDocBlock */
2120
protected $hookDocBlock;
2221

23-
public function __construct(FileTypeMapper $fileTypeMapper)
22+
public function __construct(HookDocBlock $hookDocBlock)
2423
{
25-
$this->hookDocBlock = new HookDocBlock($fileTypeMapper);
24+
$this->hookDocBlock = $hookDocBlock;
2625
}
2726

2827
public function isFunctionSupported(FunctionReflection $functionReflection): bool
@@ -38,7 +37,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3837
);
3938
}
4039

41-
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter
40+
/**
41+
* @see https://developer.wordpress.org/reference/functions/apply_filters/
42+
* @see https://developer.wordpress.org/reference/functions/apply_filters_deprecated/
43+
* @see https://developer.wordpress.org/reference/functions/apply_filters_ref_array/
44+
*
45+
* @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter
46+
*/
4247
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
4348
{
4449
$default = new MixedType();

src/AssertNotWpErrorTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
3939
{
4040
$expr = $node->getArgs()[0]->value;
4141
$typeBefore = $scope->getType($expr);
42-
$type = TypeCombinator::remove($typeBefore, new ObjectType('WP_Error'));
42+
$type = TypeCombinator::remove($typeBefore, new ObjectType(\WP_Error::class));
4343

4444
return $this->typeSpecifier->create($expr, $type, TypeSpecifierContext::createTruthy());
4545
}

src/AssertWpErrorTypeSpecifyingExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
3838
{
3939
$args = $node->getArgs();
4040

41-
return $this->typeSpecifier->create($args[0]->value, new ObjectType('WP_Error'), TypeSpecifierContext::createTruthy());
41+
return $this->typeSpecifier->create(
42+
$args[0]->value,
43+
new ObjectType(\WP_Error::class),
44+
TypeSpecifierContext::createTruthy()
45+
);
4246
}
4347

4448
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void

src/EchoKeyDynamicFunctionReturnTypeExtension.php

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)