* To change this license header, choose License Headers in Project Properties.
5
* To change this template file, choose Tools | Templates
6
* and open the template in the editor.
7
*/
8
9
namespace Maslosoft\Manganel\Traits;
10
11
use Maslosoft\Manganel\Interfaces\ScoreAwareInterface;
12
use UnexpectedValueException;
13
14
/**
15
* ScoreAwareTrait
16
*
17
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
18
*/
19
trait ScoreAwareTrait
20
{
21
22
private $score = 0.0;
23
24
1
public function getScore()
25
{
26
1
if (!$this instanceof ScoreAwareInterface)
27
{
28
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: