diff --git a/README.md b/README.md index 286c7cb..9daed99 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,9 @@ What is the type coverage you ask? We have 4 type possible declarations in total ```php final class ConferenceFactory { + const SPEAKER_TAG = 'speaker'; + private $talkFactory; - public const SPEAKER_TAG = 'speaker'; public function createConference(array $data) { @@ -31,7 +32,9 @@ final class ConferenceFactory } ``` -The param type is defined, but property and return types are missing. +*Note: Class constant types require PHP 8.3 to run.* + +The param type is defined. But the property, return and constant types are missing. * 1 out of 4 = 25 % coverage @@ -40,12 +43,11 @@ Our code quality is only at one-quarter of its potential. Let's get to 100 %! ```diff final class ConferenceFactory { -- private $talkFactory; -+ private TalkFactory $talkFactory; - - public const SPEAKER_TAG = 'speaker'; + public const string SPEAKER_TAG = 'speaker'; +- private $talkFactory; ++ private TalkFactory $talkFactory; - public function createConference(array $data) + public function createConference(array $data): Conference diff --git a/src/Configuration.php b/src/Configuration.php index 9955268..77174e2 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -19,6 +19,15 @@ public function getRequiredPropertyTypeLevel(): float|int return $this->parameters['property'] ?? $this->parameters['property_type']; } + public function isConstantTypeCoverageEnabled(): bool + { + if (PHP_VERSION_ID < 80300) { + return false; + } + + return $this->getRequiredConstantTypeLevel() > 0; + } + public function getRequiredConstantTypeLevel(): float|int { return $this->parameters['constant'] ?? $this->parameters['constant_type']; diff --git a/src/Rules/ConstantTypeCoverageRule.php b/src/Rules/ConstantTypeCoverageRule.php index 05deb32..d5aae5c 100644 --- a/src/Rules/ConstantTypeCoverageRule.php +++ b/src/Rules/ConstantTypeCoverageRule.php @@ -59,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array ]; } - if ($this->configuration->getRequiredConstantTypeLevel() === 0) { + if (! $this->configuration->isConstantTypeCoverageEnabled()) { return []; }