GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( f7060e...00f73a )
by Brent
10s
created

ParallelProcess   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 20
lcom 1
cbo 4

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 4 1
A start() 0 10 1
A stop() 0 6 1
A isRunning() 0 4 1
A isSuccessful() 0 4 1
A isTerminated() 0 4 1
A getOutput() 0 14 3
A getErrorOutput() 0 14 3
A getProcess() 0 4 1
A getId() 0 4 1
A getPid() 0 4 1
A getCurrentExecutionTime() 0 4 1
A resolveErrorOutput() 0 14 3
1
<?php
2
3
namespace Spatie\Async\Process;
4
5
use Throwable;
6
use Spatie\Async\Output\ParallelError;
7
use Symfony\Component\Process\Process;
8
use Spatie\Async\Output\SerializableException;
9
10
class ParallelProcess implements Runnable
11
{
12
    protected $process;
13
    protected $id;
14
    protected $pid;
15
16
    protected $output;
17
    protected $errorOutput;
18
19
    protected $startTime;
20
21
    use ProcessCallbacks;
22
23
    public function __construct(Process $process, int $id)
24
    {
25
        $this->process = $process;
26
        $this->id = $id;
27
    }
28
29
    public static function create(Process $process, int $id): self
30
    {
31
        return new self($process, $id);
32
    }
33
34
    public function start(): self
35
    {
36
        $this->startTime = microtime(true);
37
38
        $this->process->start();
39
40
        $this->pid = $this->process->getPid();
41
42
        return $this;
43
    }
44
45
    public function stop(): self
46
    {
47
        $this->process->stop(10, SIGKILL);
48
49
        return $this;
50
    }
51
52
    public function isRunning(): bool
53
    {
54
        return $this->process->isRunning();
55
    }
56
57
    public function isSuccessful(): bool
58
    {
59
        return $this->process->isSuccessful();
60
    }
61
62
    public function isTerminated(): bool
63
    {
64
        return $this->process->isTerminated();
65
    }
66
67
    public function getOutput()
68
    {
69
        if (! $this->output) {
70
            $processOutput = $this->process->getOutput();
71
72
            $this->output = @unserialize(base64_decode($processOutput));
73
74
            if (! $this->output) {
75
                $this->errorOutput = $processOutput;
76
            }
77
        }
78
79
        return $this->output;
80
    }
81
82
    public function getErrorOutput()
83
    {
84
        if (! $this->errorOutput) {
85
            $processOutput = $this->process->getErrorOutput();
86
87
            $this->errorOutput = @unserialize(base64_decode($processOutput));
88
89
            if (! $this->errorOutput) {
90
                $this->errorOutput = $processOutput;
91
            }
92
        }
93
94
        return $this->errorOutput;
95
    }
96
97
    public function getProcess(): Process
98
    {
99
        return $this->process;
100
    }
101
102
    public function getId(): int
103
    {
104
        return $this->id;
105
    }
106
107
    public function getPid(): ?int
108
    {
109
        return $this->pid;
110
    }
111
112
    public function getCurrentExecutionTime(): float
113
    {
114
        return microtime(true) - $this->startTime;
115
    }
116
117
    protected function resolveErrorOutput(): Throwable
118
    {
119
        $exception = $this->getErrorOutput();
120
121
        if ($exception instanceof SerializableException) {
122
            $exception = $exception->asThrowable();
123
        }
124
125
        if (! $exception instanceof Throwable) {
126
            $exception = ParallelError::fromException($exception);
127
        }
128
129
        return $exception;
130
    }
131
}
132