It seems like you code against a concrete implementation and not the interface Laminas\Diagnostics\Check\CheckInterface as the method setLabel() does only exist in the following implementations of said interface: Laminas\Diagnostics\Check\AbstractCheck, Laminas\Diagnostics\Check\AbstractFileCheck, Laminas\Diagnostics\Check\AbstractMemoryCheck, Laminas\Diagnostics\Check\ApcFragmentation, Laminas\Diagnostics\Check\ApcMemory, Laminas\Diagnostics\Check\Callback, Laminas\Diagnostics\Check\ClassExists, Laminas\Diagnostics\Check\CouchDBCheck, Laminas\Diagnostics\Check\CpuPerformance, Laminas\Diagnostics\Check\DirReadable, Laminas\Diagnostics\Check\DirWritable, Laminas\Diagnostics\Check\DiskFree, Laminas\Diagnostics\Check\DiskUsage, Laminas\Diagnostics\Check\DoctrineMigration, Laminas\Diagnostics\Check\ExtensionLoaded, Laminas\Diagnostics\Check\GuzzleHttpService, Laminas\Diagnostics\Check\HttpService, Laminas\Diagnostics\Check\IniFile, Laminas\Diagnostics\Check\JsonFile, Laminas\Diagnostics\Check\Memcache, Laminas\Diagnostics\Check\Memcached, Laminas\Diagnostics\Check\Mongo, Laminas\Diagnostics\Check\OpCacheMemory, Laminas\Diagnostics\Check\PhpFlag, Laminas\Diagnostics\Check\PhpVersion, Laminas\Diagnostics\Check\ProcessRunning, Laminas\Diagnostics\Check\RabbitMQ, Laminas\Diagnostics\Check\Redis, Laminas\Diagnostics\Check\SecurityAdvisory, Laminas\Diagnostics\Check\StreamWrapperExists, Laminas\Diagnostics\Check\XmlFile, Laminas\Diagnostics\Check\YamlFile, Liip\MonitorBundle\Check\ApcFragmentation, Liip\MonitorBundle\Check\ApcMemory, Liip\MonitorBundle\Check\ClassExists, Liip\MonitorBundle\Check\CpuPerformance, Liip\MonitorBundle\Check\DiskUsage, Liip\MonitorBundle\Check\DoctrineDbal, Liip\MonitorBundle\Check\DoctrineMongoDb, Liip\MonitorBundle\Check\IniFile, Liip\MonitorBundle\Check\JsonFile, Liip\MonitorBundle\Check\OpCacheMemory, Liip\MonitorBundle\Check\PhpExtension, Liip\MonitorBundle\Check\ReadableDirectory, Liip\MonitorBundle\Check\SecurityAdvisory, Liip\MonitorBundle\Check\StreamWrapperExists, Liip\MonitorBundle\Check\WritableDirectory, Liip\MonitorBundle\Check\XmlFile, Liip\MonitorBundle\Check\YamlFile.
Let’s take a look at an example:
interfaceUser{/** @return string */publicfunctiongetPassword();}classMyUserimplementsUser{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 implementation
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.
Let’s take a look at an example:
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 implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: