It seems like \Mcustiel\SimpleRequest\...n->getValue())->build() targeting Mcustiel\SimpleRequest\U...ntationBuilder::build() can also be of type object<Mcustiel\SimpleRe...ces\ValidatorInterface>; however, Mcustiel\SimpleRequest\S...serBuilder::addFilter() does only seem to accept object<Mcustiel\SimpleRe...rfaces\FilterInterface>, maybe add an additional type check?
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
It seems like you code against a specific sub-type and not the parent class Mcustiel\SimpleRequest\A...ation\RequestAnnotation as the method getAssociatedClass() does only exist in the following sub-classes of Mcustiel\SimpleRequest\A...ation\RequestAnnotation: Mcustiel\SimpleRequest\A...tionWithAssociatedClass, Mcustiel\SimpleRequest\Annotation\FilterAnnotation, Mcustiel\SimpleRequest\A...ation\Filter\Capitalize, Mcustiel\SimpleRequest\A...ion\Filter\CustomFilter, Mcustiel\SimpleRequest\A...ion\Filter\DefaultValue, Mcustiel\SimpleRequest\Annotation\Filter\LowerCase, Mcustiel\SimpleRequest\A...ion\Filter\RegexReplace, Mcustiel\SimpleRequest\A...ReplaceFilterAnnotation, Mcustiel\SimpleRequest\A...on\Filter\StringReplace, Mcustiel\SimpleRequest\Annotation\Filter\ToFloat, Mcustiel\SimpleRequest\Annotation\Filter\ToInteger, Mcustiel\SimpleRequest\Annotation\Filter\Trim, Mcustiel\SimpleRequest\Annotation\Filter\UpperCase, Mcustiel\SimpleRequest\A...ion\ValidatorAnnotation, Mcustiel\SimpleRequest\Annotation\Validator\AllOf, Mcustiel\SimpleRequest\Annotation\Validator\Alpha, Mcustiel\SimpleRequest\A...\Validator\AlphaNumeric, Mcustiel\SimpleRequest\Annotation\Validator\AnyOf, Mcustiel\SimpleRequest\A...lidator\CustomValidator, Mcustiel\SimpleRequest\A...tion\Validator\DateTime, Mcustiel\SimpleRequest\A...alidator\DateTimeFormat, Mcustiel\SimpleRequest\A...on\Validator\Definition, Mcustiel\SimpleRequest\Annotation\Validator\Email, Mcustiel\SimpleRequest\Annotation\Validator\Enum, Mcustiel\SimpleRequest\A...idator\ExclusiveMaximum, Mcustiel\SimpleRequest\A...idator\ExclusiveMinimum, Mcustiel\SimpleRequest\Annotation\Validator\Hexa, Mcustiel\SimpleRequest\A...tion\Validator\HostName, Mcustiel\SimpleRequest\Annotation\Validator\IPV4, Mcustiel\SimpleRequest\Annotation\Validator\IPV6, Mcustiel\SimpleRequest\Annotation\Validator\Items, Mcustiel\SimpleRequest\A...on\Validator\MacAddress, Mcustiel\SimpleRequest\A...tion\Validator\MaxItems, Mcustiel\SimpleRequest\A...ion\Validator\MaxLength, Mcustiel\SimpleRequest\A...Validator\MaxProperties, Mcustiel\SimpleRequest\A...ation\Validator\Maximum, Mcustiel\SimpleRequest\A...tion\Validator\MinItems, Mcustiel\SimpleRequest\A...ion\Validator\MinLength, Mcustiel\SimpleRequest\A...Validator\MinProperties, Mcustiel\SimpleRequest\A...ation\Validator\Minimum, Mcustiel\SimpleRequest\A...on\Validator\MultipleOf, Mcustiel\SimpleRequest\Annotation\Validator\Not, Mcustiel\SimpleRequest\A...tion\Validator\NotEmpty, Mcustiel\SimpleRequest\A...ation\Validator\NotNull, Mcustiel\SimpleRequest\Annotation\Validator\OneOf, Mcustiel\SimpleRequest\A...ation\Validator\Pattern, Mcustiel\SimpleRequest\A...on\Validator\Properties, Mcustiel\SimpleRequest\Annotation\Validator\RegExp, Mcustiel\SimpleRequest\A...tion\Validator\Required, Mcustiel\SimpleRequest\A...alidator\TwitterAccount, Mcustiel\SimpleRequest\Annotation\Validator\Type, Mcustiel\SimpleRequest\A...ion\Validator\TypeFloat, Mcustiel\SimpleRequest\A...n\Validator\TypeInteger, Mcustiel\SimpleRequest\A...n\Validator\UniqueItems, Mcustiel\SimpleRequest\Annotation\Validator\Uri. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example:
abstractclassUser{/** @return string */abstractpublicfunctiongetPassword();}classMyUserextendsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different sub-classes
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.