IcecastReader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
namespace WITR\Services;
4
5
use stdClass;
6
use Illuminate\Support\Collection;
7
use GuzzleHttp\Client;
8
9
class IcecastReader
10
{
11
12
    protected $hostname;
13
    protected $credentials;
14
    protected $mounts;
15
16
    public function __construct($hostname, $credentials, $mounts)
17
    {
18
        $this->hostname = $hostname;
19
        $this->credentials = $credentials;
20
        $this->mounts = $mounts;
21
    }
22
23
    public function getMounts()
24
    {
25
        return $this->mounts;
26
    }
27
28
    public function get($studio)
29
    {
30
        $results = new Collection;
0 ignored issues
show
Unused Code introduced by
$results is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
32
        $client = new Client();
33
        
34
        $listeners = IcecastListeners::forMounts($this->mounts[$studio]);
35
        foreach ($this->mounts[$studio] as $mount)
36
        {
37
            $response = $client->get($this->hostname . '/admin/listclients?mount=/'. $mount, [
38
                'auth' => $this->credentials
39
            ]);
40
            $xml = simplexml_load_string($response->getBody())->source->listener;
41
            foreach ($xml as $node)
42
            {
43
                $listener = new stdClass;
44
                $listener->hostname = gethostbyaddr($node->IP);
45
                $listener->minutesConnected = round($node->Connected / 60);
46
                $listener->userAgent = $node->UserAgent;
47
                $listener->mount = $mount;
48
                $listeners->push($listener);
49
            }
50
        }
51
52
        return $listeners;
53
    }
54
}
55