-
Notifications
You must be signed in to change notification settings - Fork 24
Add initial PHPStan config #212
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| parameters: | ||
| level: 6 | ||
| paths: | ||
| - src | ||
| - doctor-command.php | ||
| scanDirectories: | ||
| - vendor/wp-cli/wp-cli/php | ||
| scanFiles: | ||
| - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php | ||
| - tests/phpstan/scan-files.php | ||
| treatPhpDocTypesAsCertain: false | ||
| ignoreErrors: | ||
| - '#Call to deprecated method setAccessible\(\) of class ReflectionProperty\.#' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,9 +26,9 @@ class Constant_Definition extends Check { | |
| /** | ||
| * Whether or not the constant is expected to be a falsy value. | ||
| * | ||
| * @var bool | ||
| * @var bool|null | ||
| */ | ||
| protected $falsy; | ||
| protected $falsy = null; | ||
|
|
||
| /** | ||
| * Expected value of the constant. | ||
|
|
@@ -39,6 +39,8 @@ class Constant_Definition extends Check { | |
|
|
||
| /** | ||
| * Initialize the constant check | ||
| * | ||
| * @param array<string, mixed> $options | ||
| */ | ||
| public function __construct( $options = array() ) { | ||
| parent::__construct( $options ); | ||
|
|
@@ -47,6 +49,9 @@ public function __construct( $options = array() ) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function run() { | ||
|
|
||
| if ( isset( $this->falsy ) ) { | ||
|
|
@@ -99,7 +104,7 @@ public function run() { | |
| return; | ||
| } | ||
|
|
||
| if ( $this->defined && ! isset( $this->value ) ) { | ||
| if ( ! isset( $this->value ) ) { | ||
| $this->set_status( 'success' ); | ||
| $this->set_message( "Constant '{$this->constant}' is defined." ); | ||
| return; | ||
|
|
@@ -118,12 +123,18 @@ public function run() { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $value | ||
| * @return string | ||
| */ | ||
| private static function human_value( $value ) { | ||
| if ( true === $value ) { | ||
| $value = 'true'; | ||
| return 'true'; | ||
| } elseif ( false === $value ) { | ||
| $value = 'false'; | ||
| return 'false'; | ||
| } elseif ( is_null( $value ) ) { | ||
| return 'null'; | ||
| } | ||
| return $value; | ||
| return (string) $value; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Casting return is_scalar( $value ) ? (string) $value : json_encode( $value ); |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ abstract class File extends Check { | |
| /** | ||
| * File checks are run as their own group. | ||
| */ | ||
| protected $_when = false; | ||
| protected $_when = 'manual'; // Run manually via group | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing protected $_when = false; |
||
|
|
||
| /** | ||
| * File extension to check. | ||
|
|
@@ -42,14 +42,14 @@ abstract class File extends Check { | |
| /** | ||
| * Any files matching the check. | ||
| * | ||
| * @var array | ||
| * @var array<string|\SplFileInfo> | ||
| */ | ||
| protected $_matches = array(); | ||
|
|
||
| /** | ||
| * Get the options for this check | ||
| * | ||
| * @return string | ||
| * @return array<string, bool|string> | ||
| */ | ||
| public function get_options() { | ||
| return array( | ||
|
|
@@ -58,4 +58,12 @@ public function get_options() { | |
| 'path' => $this->path, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Check a specific file. | ||
| * | ||
| * @param \SplFileInfo $file File to check. | ||
| * @return void | ||
| */ | ||
| abstract public function check_file( \SplFileInfo $file ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing
$this->definedfrom this condition changes the behavior of the check. Previously, this block only executed if the configuration explicitly requested a definition check (e.g.,defined: truein YAML). Now, it will execute for any constant check where avalueis not specified, potentially leading to incorrect success reports if the constant is not actually defined. If PHPStan is flagging$this->definedas an undefined property, it should be explicitly declared in the class rather than removed from the logic.