Passed
Push — master ( 342193...f80fe6 )
by Andrea Marco
03:14 queued 11s
created

OutOfAttemptsException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Cerbero\LazyJsonPages\Exceptions;
4
5
use Cerbero\LazyJsonPages\Outcome;
6
use Illuminate\Support\LazyCollection;
7
use Throwable;
8
9
/**
10
 * The out of attempts exception.
11
 *
12
 */
13
class OutOfAttemptsException extends LazyJsonPagesException
14
{
15
    /**
16
     * The original exception.
17
     *
18
     * @var Throwable
19
     */
20
    public $original;
21
22
    /**
23
     * The pages that caused the failure.
24
     *
25
     * @var array
26
     */
27
    public $failedPages;
28
29
    /**
30
     * The paginated items loaded before the failure.
31
     *
32
     * @var LazyCollection
33
     */
34
    public $items;
35
36
    /**
37
     * Instantiate the class.
38
     *
39
     * @param Throwable $original
40
     * @param Outcome $outcome
41
     */
42 2
    public function __construct(Throwable $original, Outcome $outcome)
43
    {
44 2
        $this->message = $original->getMessage();
45 2
        $this->original = $original;
46 2
        $this->failedPages = $outcome->pullFailedPages();
47 2
        $this->items = new LazyCollection(function () use ($outcome) {
48 2
            yield from $outcome->pullItems();
49 2
        });
50 2
    }
51
}
52