Passed
Push — master ( e32a81...12baf4 )
by Antonio Carlos
02:26
created

src/Checkers/Composer.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 makeCommand()
48
    {
49 1
        return sprintf(
50 1
            '%s %s',
51 1
            $this->target->resource->binary,
52 1
            $this->target->resource->command
53
        );
54
    }
55
56
    /**
57
     * Execute the Composer command.
58
     *
59
     * @return \Illuminate\Support\Collection|mixed
60
     */
61 1
    protected function executeCommand()
62
    {
63 1
        $process = new SymfonyProcess(
64 1
            $this->makeCommand(),
65 1
            $this->target->workingDir
0 ignored issues
show
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...
66
        );
67
68 1
        $process->run();
69
70 1
        $output = $this->outputToCollection($process->getOutput());
71
72 1
        if ($output->count() == 0) {
73 1
            return $output;
74
        }
75
76
        if ($rootItem = $this->target->resource->rootItem) {
77
            return collect($output[$rootItem]);
78
        }
79
80
        return $output;
81
    }
82
}
83