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.

PoolStatus::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Async;
4
5
use Spatie\Async\Output\SerializableException;
6
use Spatie\Async\Process\ParallelProcess;
7
8
class PoolStatus
9
{
10
    protected $pool;
11
12
    public function __construct(Pool $pool)
13
    {
14
        $this->pool = $pool;
15
    }
16
17
    public function __toString(): string
18
    {
19
        return $this->lines(
20
            $this->summaryToString(),
21
            $this->failedToString()
22
        );
23
    }
24
25
    protected function lines(string ...$lines): string
26
    {
27
        return implode(PHP_EOL, $lines);
28
    }
29
30
    protected function summaryToString(): string
31
    {
32
        $queue = $this->pool->getQueue();
33
        $finished = $this->pool->getFinished();
34
        $failed = $this->pool->getFailed();
35
        $timeouts = $this->pool->getTimeouts();
36
37
        return
38
            'queue: '.count($queue)
39
            .' - finished: '.count($finished)
40
            .' - failed: '.count($failed)
41
            .' - timeout: '.count($timeouts);
42
    }
43
44
    protected function failedToString(): string
45
    {
46
        return (string) array_reduce($this->pool->getFailed(), function ($currentStatus, ParallelProcess $process) {
47
            $output = $process->getErrorOutput();
48
49
            if ($output instanceof SerializableException) {
50
                $output = get_class($output->asThrowable()).': '.$output->asThrowable()->getMessage();
51
            }
52
53
            return $this->lines((string) $currentStatus, "{$process->getPid()} failed with {$output}");
54
        });
55
    }
56
}
57