Completed
Push — develop ( e1ba06...9ac8df )
by
unknown
14:59 queued 06:41
created

ApiController::list_ports()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace App\Api\Controllers;
4
5
use DB;
6
use App\User;
7
use App\Device;
8
use App\Port;
9
use Illuminate\Http\Request;
10
11
class ApiController extends Controller
12
{
13
    public function __construct() {
14
15
    }
16
17
    /**
18
    * Get info about the install
19
    */
20
    public function get_info() {
21
        $versions['git'] = `git rev-parse --short HEAD`;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$versions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $versions = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
22
        $versions['db_schema'] = DB::select('SELECT `version` FROM `dbSchema` LIMIT 1')[0]->version;
23
        return $versions;
24
    }
25
26
}
27