Completed
Push — master ( 2b6f23...9d72ed )
by Tom
03:44
created

PageFactory::makeFromSheet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 1
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Astrotomic\Stancy\Factories;
4
5
use Astrotomic\Stancy\Exceptions\SheetCollectionNotFoundException;
6
use Astrotomic\Stancy\Exceptions\SheetNotFoundException;
7
use Astrotomic\Stancy\Models\Page;
8
use RuntimeException;
9
use Spatie\Sheets\Facades\Sheets;
10
11
class PageFactory
12
{
13 17
    public function make(array $data = [], ?string $page = null): Page
0 ignored issues
show
introduced by
Method \Astrotomic\Stancy\Factories\PageFactory::make() does not have @param annotation for its traversable parameter $data.
Loading history...
14
    {
15 17
        return app(Page::class, [
16 17
            'data' => $data,
17 17
            'page' => $page,
18
        ]);
19
    }
20
21 12
    public function makeFromSheet(string $collection, string $name, ?string $page = null): Page
22
    {
23
        try {
24 12
            $sheet = Sheets::collection($collection)->get($name);
25 1
        } catch (RuntimeException $exception) {
26 1
            throw SheetCollectionNotFoundException::make($collection, $exception);
27
        }
28
29 11
        if ($sheet === null) {
30 1
            throw SheetNotFoundException::make($collection, $name);
31
        }
32
33 10
        return static::make($sheet->toArray(), $page);
0 ignored issues
show
Bug Best Practice introduced by
The method Astrotomic\Stancy\Factories\PageFactory::make() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        return static::/** @scrutinizer ignore-call */ make($sheet->toArray(), $page);
Loading history...
34
    }
35
}
36