Conditions | 4 |
Paths | 4 |
Total Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
55 | public function formatLogConfig($app) |
||
56 | { |
||
57 | if (empty($app['config']->get('log'))) { |
||
58 | return [ |
||
59 | 'log' => [ |
||
60 | 'cli_on' => false, |
||
61 | 'default' => 'errorlog', |
||
62 | 'channels' => [ |
||
63 | 'errorlog' => [ |
||
64 | 'driver' => 'errorlog', |
||
65 | 'level' => 'debug', |
||
66 | ], |
||
67 | ], |
||
68 | ], |
||
69 | ]; |
||
70 | } |
||
71 | // 4.0 version |
||
72 | if (empty($app['config']->get('log.driver'))) { |
||
73 | return [ |
||
74 | 'log' => [ |
||
75 | 'cli_on' => false, |
||
76 | 'default' => 'single', |
||
77 | 'channels' => [ |
||
78 | 'single' => [ |
||
79 | 'driver' => 'single', |
||
80 | 'path' => $app['config']->get('log.file') ?: \sys_get_temp_dir() . '/logs/tim-sdk.log', |
||
81 | 'level' => $app['config']->get('log.level', 'debug'), |
||
82 | ], |
||
83 | ], |
||
84 | ], |
||
85 | ]; |
||
86 | } |
||
87 | $name = $app['config']->get('log.driver'); |
||
88 | |||
89 | return [ |
||
90 | 'log' => [ |
||
91 | 'cli_on' => false, |
||
92 | 'default' => $name, |
||
93 | 'channels' => [ |
||
94 | $name => $app['config']->get('log'), |
||
95 | ], |
||
96 | ], |
||
97 | ]; |
||
98 | } |
||
99 | } |
||
100 |
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: