use Maslosoft\Manganel\Interfaces\IndexAwareInterface;
16
use UnexpectedValueException;
17
18
/**
19
* IndexAwareTrait
20
*
21
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
22
*/
23
trait IndexAwareTrait
24
{
25
26
private $index = '';
27
28
/**
29
* Get currently used index
30
* @return string
31
*/
32
public function getIndex()
33
{
34
if (!$this instanceof IndexAwareInterface)
35
{
36
throw new UnexpectedValueException(sprintf('Class `%s` using `%s` must implement `%s`', get_class($this), __CLASS__, IndexAwareInterface::class)); // @codeCoverageIgnore
Accessing index on the interface Maslosoft\Manganel\Interfaces\IndexAwareInterface 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__, IndexAwareInterface::class)); // @codeCoverageIgnore
Accessing index on the interface Maslosoft\Manganel\Interfaces\IndexAwareInterface 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: