| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 12 | class m170324_000003_fix_widget_options extends Migration |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Any migration code in here is wrapped inside of a transaction. |
||
| 16 | * |
||
| 17 | * @return bool |
||
| 18 | */ |
||
| 19 | public function safeUp() |
||
| 20 | { |
||
| 21 | $widgetResults = (new Query()) |
||
| 22 | ->select('*') |
||
| 23 | ->from(['{{%widgets}}']) |
||
| 24 | ->where(['type' => 'dukt\analytics\widgets\Realtime']) |
||
| 25 | ->orWhere(['type' => 'dukt\analytics\widgets\Report']) |
||
| 26 | ->all(); |
||
| 27 | |||
| 28 | if ($widgetResults) { |
||
|
|
|||
| 29 | foreach ($widgetResults as $result) { |
||
| 30 | $settings = Json::decode($result['settings']); |
||
| 31 | |||
| 32 | if (isset($settings['options']['metric'])) { |
||
| 33 | $settings['options'] = [ |
||
| 34 | $settings['chart'] => $settings['options'] |
||
| 35 | ]; |
||
| 36 | } |
||
| 37 | |||
| 38 | // Update row |
||
| 39 | |||
| 40 | $settings = Json::encode($settings); |
||
| 41 | |||
| 42 | $this->update('{{%widgets}}', ['settings' => $settings], ['id' => $result['id']]); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return true; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @inheritdoc |
||
| 51 | */ |
||
| 52 | public function safeDown() |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.