TopProcessParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 56
ccs 22
cts 22
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parse() 0 17 2
A getProcesses() 0 4 1
A getRaw() 0 4 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
}