| Conditions | 6 |
| Paths | 33 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 51 | 5 | public function handle() |
|
| 52 | { |
||
| 53 | 5 | $all = $this->option('all'); |
|
| 54 | |||
| 55 | 5 | if ($all) { |
|
| 56 | 2 | $this->info('Trying to renew both your keys...'); |
|
| 57 | } else { |
||
| 58 | 3 | $key = $this->option('key') ?: 'primary'; |
|
| 59 | 3 | $this->info("Trying to renew your {$key} key..."); |
|
| 60 | } |
||
| 61 | |||
| 62 | try { |
||
| 63 | 5 | if ($all) { |
|
| 64 | 2 | $this->apiKey->renewPrimary(config('signere.primary_key')); |
|
| 65 | 1 | $this->apiKey->renewSecondary(config('signere.secondary_key')); |
|
| 66 | |||
| 67 | 1 | $this->info('Both your keys were renewed!'); |
|
| 68 | } else { |
||
| 69 | 3 | if ($this->option('key') === 'secondary') { |
|
| 70 | 1 | $this->apiKey->renewSecondary(config('signere.secondary_key')); |
|
| 71 | } else { |
||
| 72 | 2 | $this->apiKey->renewPrimary(config('signere.primary_key')); |
|
| 73 | } |
||
| 74 | |||
| 75 | 4 | $this->info("Your {$key} key was renewed!"); |
|
|
|
|||
| 76 | } |
||
| 77 | 1 | } catch (Exception $e) { |
|
| 78 | 1 | $this->error("Renewing failed because: {$e->getMessage()}."); |
|
| 79 | |||
| 80 | 1 | return -1; |
|
| 81 | } |
||
| 82 | 4 | } |
|
| 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: