1 | <?php |
||
23 | class Runtime |
||
24 | { |
||
25 | /** |
||
26 | * @var string[]|StateInterface[] |
||
27 | */ |
||
28 | private const RESOLVERS = [ |
||
29 | OpcodeInterface::RL_OPEN => OpenState::class, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $result = []; |
||
36 | |||
37 | /** |
||
38 | * @var Readable |
||
39 | */ |
||
40 | private $input; |
||
41 | |||
42 | /** |
||
43 | * @var Reflection |
||
44 | */ |
||
45 | private $root; |
||
46 | |||
47 | /** |
||
48 | * Runtime constructor. |
||
49 | * @param Reflection $root |
||
50 | * @param Readable $input |
||
51 | */ |
||
52 | public function __construct(Reflection $root, Readable $input) |
||
57 | |||
58 | /** |
||
59 | * @return Readable |
||
60 | */ |
||
61 | public function getInput(): Readable |
||
65 | |||
66 | /** |
||
67 | * @param int $id |
||
68 | * @return mixed|null |
||
69 | */ |
||
70 | public function get(int $id) |
||
74 | |||
75 | /** |
||
76 | * @return Reflection |
||
77 | */ |
||
78 | public function getReflection(): Reflection |
||
82 | |||
83 | /** |
||
84 | * @param iterable|OpcodeInterface[]|JoinedOpcode[] $opcodes |
||
85 | * @return iterable |
||
86 | * @throws \Railt\Io\Exception\ExternalFileException |
||
87 | */ |
||
88 | public function execute(iterable $opcodes): iterable |
||
94 | |||
95 | /** |
||
96 | * @param OpcodeInterface|JoinedOpcode $opcode |
||
97 | * @return StateInterface |
||
98 | * @throws \Railt\Io\Exception\ExternalFileException |
||
99 | */ |
||
100 | private function getState(OpcodeInterface $opcode): StateInterface |
||
111 | } |
||
112 |
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: