Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 18 |
| UpdateParentProcess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 18 |
| handle | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 9 |
|||
| checkError | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 5 |
|||
| pass | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\CommandsLaravel\Middleware\Library\Monitoring; |
| 4 | |
| 5 | use Closure; |
| 6 | use Qmp\Laravel\CommandsLaravel\Middleware\Core\Middleware; |
| 7 | use Qmp\Laravel\CommandsLaravel\Models\CommandMonitoring; |
| 8 | |
| 9 | class UpdateParentProcess extends Middleware |
| 10 | { |
| 11 | /** |
| 12 | * Undocumented variable |
| 13 | * |
| 14 | * @var boolean |
| 15 | */ |
| 16 | protected $async = false; |
| 17 | |
| 18 | /** |
| 19 | * Undocumented variable |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | protected $errorMessage = [ 'message' => "Subprocess fail !" ]; |
| 24 | |
| 25 | /** |
| 26 | * Undocumented function |
| 27 | * |
| 28 | * @param Closure $next |
| 29 | * @return mixed |
| 30 | */ |
| 31 | public function handle($IOinterface, $next) |
| 32 | { |
| 33 | $this->setInterface($IOinterface); |
| 34 | |
| 35 | $next = $next($IOinterface); |
| 36 | |
| 37 | CommandMonitoring::where('_id', $this->getId())->update([ |
| 38 | 'log' => $this->getLog(), |
| 39 | 'error' => $this->checkError(), |
| 40 | 'warning' => $this->getWarning(), |
| 41 | 'pass' => $this->pass(), |
| 42 | 'running' => false |
| 43 | ]); |
| 44 | |
| 45 | $this->info("Update done !"); |
| 46 | |
| 47 | return $next; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Undocumented function |
| 52 | * |
| 53 | * @return mixed |
| 54 | */ |
| 55 | protected function checkError() { |
| 56 | if($this->getError()) { |
| 57 | return $this->getError(); |
| 58 | } |
| 59 | |
| 60 | if($this->async || $this->pass()) { |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | return $this->errorMessage; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Undocumented function |
| 69 | * |
| 70 | * @return boolean |
| 71 | */ |
| 72 | protected function pass(): bool |
| 73 | { |
| 74 | if ($this->getError()) { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | $command = CommandMonitoring::find($this->getId()); |
| 79 | return (bool) !collect($command->subProcess)->pluck('pass')->contains(false); |
| 80 | } |
| 81 | } |