| Conditions | 2 |
| Paths | 2 |
| Total Lines | 11 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php defined('BASEPATH') OR exit('No direct script access allowed'); |
||
| 9 | public function up() { |
||
| 10 | $sitesData = json_decode(file_get_contents(APPPATH.'migrations/data/tracker_sites.json'), TRUE)['sites']; |
||
| 11 | |||
| 12 | foreach ($sitesData as $siteData) { |
||
| 13 | $id = $siteData['id']; |
||
| 14 | array_walk($siteData, function(&$arr) { |
||
| 15 | $arr = array_intersect_key($arr, array_flip(['site', 'site_class', 'status', 'use_custom'])); |
||
| 16 | }); |
||
| 17 | $this->db->update('tracker_sites', $siteData, array('id' => $id)); |
||
| 18 | } |
||
| 19 | } |
||
| 20 | |||
| 23 |
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 sub-classes 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 parent class: