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

PageFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 11
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeFromSheet() 0 13 3
A make() 0 5 1
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