Test Failed
Push — master ( f043ce...f1785b )
by Antonio Carlos
04:03
created

Composer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 70.83%

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 17
cts 24
cp 0.7083
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 2
A outputToCollection() 0 8 2
A getBinary() 0 4 1
A executeCommand() 0 21 3
1
<?php
2
3
namespace PragmaRX\Health\Checkers;
4
5
use PragmaRX\Health\Support\Result;
6
use Symfony\Component\Process\Process as SymfonyProcess;
7
8
class Composer extends Base
9
{
10
    /**
11
     * Check resource.
12
     *
13
     * @return Result
14
     */
15 1
    public function check()
16
    {
17 1
        $outdated = $this->executeCommand();
18
19 1
        if ($outdated->count() > $this->target->resource->shouldCountAtMost) {
20
            return $this->makeResult(
21
                false,
22
                sprintf($this->target->getErrorMessage(), $outdated->count())
23
            );
24
        }
25
26 1
        return $this->makeHealthyResult();
27
    }
28
29
    /**
30
     * Convert output to array.
31
     *
32
     * @param string $output
33
     * @return \Illuminate\Support\Collection|mixed
34
     */
35 1
    protected function outputToCollection(string $output)
36
    {
37 1
        if ($this->target->resource->jsonResult) {
38 1
            return collect(json_decode($output, true) ?? collect([]));
39
        }
40
41
        return $output;
42
    }
43
44
    /**
45
     * Get the ping binary.
46
     */
47 1
    protected function getBinary()
48
    {
49 1
        return $this->target->resource->binary;
50
    }
51
52
    /**
53
     * Execute the Composer command.
54
     *
55
     * @return \Illuminate\Support\Collection|mixed
56
     */
57 1
    protected function executeCommand()
58
    {
59 1
        $process = new SymfonyProcess(
60 1
            $this->getBinary(),
61 1
            $this->target->workingDir
0 ignored issues
show
Bug introduced by
The property workingDir does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
62
        );
63
64 1
        $process->run();
65
66 1
        $output = $this->outputToCollection($process->getOutput());
67
68 1
        if ($output->count() == 0) {
69 1
            return $output;
70
        }
71
72
        if ($rootItem = $this->target->resource->rootItem) {
73
            return collect($output[$rootItem]);
74
        }
75
76
        return $output;
77
    }
78
}
79