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 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
|
|||
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 |
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.