Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce conditionalTags #268

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,40 @@ PHPStan interprets `$title` as `string`.

For best results, ensure the first `@param` tag in these docblocks is accurate.

## Disabling Rules

You can disable rules using configuration parameters:

```neon
parameters:
phpstanWP:
checkHookCallback: false
checkHookDocBlock: false
```

## Enabling Rules One-by-one

If you want to use a selective set of rules, you can!

You can disable all rules with:

```neon
parameters:
phpstanWP:
allRules: false
```

Then you can re-enable individual rules:

```neon
parameters:
phpstanWP:
allRules: false
checkHookCallback: true
```

Even with `phpstanWP.allRules` set to `false`, part of this package is still in effect. That's because phpstan-wordpress also provides [dynamic return types](https://phpstan.org/developing-extensions/dynamic-return-type-extensions) and [type specifiers](https://phpstan.org/developing-extensions/type-specifying-extensions).

## Make Your Code Testable

- Write clean OOP code: 1 class per file, and no additional code outside `class Name { ... }`.
Expand Down
81 changes: 50 additions & 31 deletions extension.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
parameters:
bootstrapFiles:
- ../../php-stubs/wordpress-stubs/wordpress-stubs.php
- bootstrap.php
dynamicConstantNames:
- WP_DEBUG
- WP_DEBUG_LOG
- WP_DEBUG_DISPLAY
- EMPTY_TRASH_DAYS
- WP_CLI
- COOKIE_DOMAIN
- SAVEQUERIES
- SCRIPT_DEBUG
earlyTerminatingFunctionCalls:
- wp_send_json
- wp_nonce_ays
earlyTerminatingMethodCalls:
IXR_Server:
- output
WP_Ajax_Response:
- send
WP_CLI:
- error
- halt
phpstanWP:
allRules: true
checkHookCallback: %phpstanWP.allRules%
checkHookDocBlock: %phpstanWP.allRules%

parametersSchema:
phpstanWP: structure([
allRules: bool()
checkHookDocBlock: bool()
checkHookCallback: bool()
])

conditionalTags:
SzepeViktor\PHPStan\WordPress\HookCallbackRule:
phpstan.rules.rule: %phpstanWP.checkHookCallback%
SzepeViktor\PHPStan\WordPress\HookDocsRule:
phpstan.rules.rule: %phpstanWP.checkHookDocBlock%

services:
-
class: SzepeViktor\PHPStan\WordPress\HookDocBlock
-
class: SzepeViktor\PHPStan\WordPress\HookCallbackRule
-
class: SzepeViktor\PHPStan\WordPress\HookDocsRule
-
class: SzepeViktor\PHPStan\WordPress\HookDocsVisitor
tags:
- phpstan.parser.richParserNodeVisitor
-
class: SzepeViktor\PHPStan\WordPress\EscSqlDynamicFunctionReturnTypeExtension
tags:
Expand All @@ -17,10 +67,6 @@ services:
class: SzepeViktor\PHPStan\WordPress\WpParseUrlFunctionDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicFunctionReturnTypeExtension
-
class: SzepeViktor\PHPStan\WordPress\HookDocsVisitor
tags:
- phpstan.parser.richParserNodeVisitor
-
class: SzepeViktor\PHPStan\WordPress\AssertWpErrorTypeSpecifyingExtension
tags:
Expand All @@ -29,30 +75,3 @@ services:
class: SzepeViktor\PHPStan\WordPress\AssertNotWpErrorTypeSpecifyingExtension
tags:
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
rules:
- SzepeViktor\PHPStan\WordPress\HookCallbackRule
- SzepeViktor\PHPStan\WordPress\HookDocsRule
parameters:
bootstrapFiles:
- ../../php-stubs/wordpress-stubs/wordpress-stubs.php
- bootstrap.php
dynamicConstantNames:
- WP_DEBUG
- WP_DEBUG_LOG
- WP_DEBUG_DISPLAY
- EMPTY_TRASH_DAYS
- WP_CLI
- COOKIE_DOMAIN
- SAVEQUERIES
- SCRIPT_DEBUG
earlyTerminatingFunctionCalls:
- wp_send_json
- wp_nonce_ays
earlyTerminatingMethodCalls:
IXR_Server:
- output
WP_Ajax_Response:
- send
WP_CLI:
- error
- halt