TopProcessParser::getProcesses()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Petrica
5
 * Date: 5/29/2016
6
 * Time: 13:47
7
 */
8
namespace Petrica\StatsdSystem\Model\Process;
9
10
/**
11
 * Class TopProcessParser
12
 *
13
 * Takes out put from top command and parse it into separate process objects
14
 *
15
 * @package Petrica\StatsdSystem\Model\Process
16
 */
17
class TopProcessParser
18
{
19
    private $raw;
20
21
    private $processes;
22
23
    /**
24
     * TopProcessParser constructor.
25
     *
26
     * @param $raw
27
     */
28 1
    public function __construct($raw)
29
    {
30 1
        $this->raw = $raw;
31 1
        $this->processes = array();
32 1
    }
33
34
    /**
35
     * Run the parsing process
36
     */
37 1
    public function parse()
38
    {
39 1
        $raw = $this->getRaw();
40 1
        $count = count($raw);
41 1
        for ($i = 7; $i < $count; $i++) {
42 1
            $line = $raw[$i];
43
44 1
            $process = new Process(
45 1
                $line[11],
46 1
                $line[0],
47 1
                floatval($line[8]),
48 1
                floatval($line[9])
49 1
            );
50
51 1
            $this->processes[] = $process;
52 1
        }
53 1
    }
54
55
    /**
56
     * Parsed processes
57
     *
58
     * @return Process[]
59
     */
60 1
    public function getProcesses()
61
    {
62 1
        return $this->processes;
63
    }
64
65
    /**
66
     * @return mixed
67
     */
68 1
    public function getRaw()
69
    {
70 1
        return $this->raw;
71
    }
72
}