use Maslosoft\Manganel\Interfaces\ScoreAwareInterface;
16
use UnexpectedValueException;
17
18
/**
19
* ScoreAwareTrait
20
*
21
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
*/
23
trait ScoreAwareTrait
24
{
25
26
private $score = 0.0;
27
28
public function getScore()
29
{
30
if (!$this instanceof ScoreAwareInterface)
31
{
32
throw new UnexpectedValueException(sprintf('Class `%s` using `%s` must implement `%s`', get_class($this), __CLASS__, ScoreAwareInterface::class)); // @codeCoverageIgnore
Accessing score on the interface Maslosoft\Manganel\Interfaces\ScoreAwareInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a
concrete implementation of the interface.
throw new UnexpectedValueException(sprintf('Class `%s` using `%s` must implement `%s`', get_class($this), __CLASS__, ScoreAwareInterface::class)); // @codeCoverageIgnore
Accessing score on the interface Maslosoft\Manganel\Interfaces\ScoreAwareInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a
concrete implementation of the interface.
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: