| Conditions | 6 |
| Paths | 33 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 51 | public function handle() |
||
| 52 | { |
||
| 53 | $all = $this->option('all'); |
||
| 54 | |||
| 55 | if ($all) { |
||
| 56 | $this->info("Trying to renew both your keys..."); |
||
| 57 | } else { |
||
| 58 | $key = $this->option('key') ?: 'primary'; |
||
| 59 | $this->info("Trying to renew your {$key} key..."); |
||
| 60 | } |
||
| 61 | |||
| 62 | try { |
||
| 63 | if ($all) { |
||
| 64 | $this->apiKey->renewPrimary(config('signere.primary_key')); |
||
| 65 | $this->apiKey->renewSecondary(config('signere.secondary_key')); |
||
| 66 | |||
| 67 | $this->info("Both your keys were renewed!"); |
||
| 68 | } else { |
||
| 69 | if ($this->option('key') === 'secondary') { |
||
| 70 | $this->apiKey->renewSecondary(config('signere.secondary_key')); |
||
| 71 | } else { |
||
| 72 | $this->apiKey->renewPrimary(config('signere.primary_key')); |
||
| 73 | } |
||
| 74 | |||
| 75 | $this->info("Your {$key} key was renewed!"); |
||
|
|
|||
| 76 | } |
||
| 77 | } catch (Exception $e) { |
||
| 78 | $this->error("Renewing failed because: {$e->getMessage()}."); |
||
| 79 | |||
| 80 | return -1; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: