use Maslosoft\Manganel\Interfaces\ScoreAwareInterface;
16
use UnexpectedValueException;
17
18
/**
19
* ScoreAwareTrait
20
*
21
* @see ScoreAwareInterface
22
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
23
*/
24
trait ScoreAwareTrait
25
{
26
27
private $score = 0.0;
28
29
17
public function getScore()
30
{
31
17
if (!$this instanceof ScoreAwareInterface)
32
{
33
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
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: