Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
33 | protected function getProvider() |
||
34 | { |
||
35 | if( !isset( $this->fs ) ) |
||
36 | { |
||
37 | $config = $this->getConfig(); |
||
38 | |||
39 | if( !isset( $config['source'] ) ) { |
||
40 | throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'source' ) ); |
||
41 | } |
||
42 | |||
43 | if( !isset( $config['replica'] ) ) { |
||
44 | throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'replica' ) ); |
||
45 | } |
||
46 | |||
47 | $source = Factory::create( (array) $config['source'] )->getAdapter(); |
||
|
|||
48 | $replica = Factory::create( (array) $config['replica'] )->getAdapter(); |
||
49 | $this->fs = new Filesystem( new ReplicateAdapter( $source, $replica ) ); |
||
50 | } |
||
51 | |||
52 | return $this->fs; |
||
53 | } |
||
54 | } |
||
55 |
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: