Issues (54)

src/Factories/PageFactory.php (2 issues)

1
<?php
2
3
namespace Astrotomic\Stancy\Factories;
4
5
use Astrotomic\Stancy\Contracts\Page as PageContract;
6
use Astrotomic\Stancy\Contracts\PageFactory as PageFactoryContract;
7
use Astrotomic\Stancy\Exceptions\SheetCollectionNotFoundException;
8
use Astrotomic\Stancy\Exceptions\SheetNotFoundException;
9
use RuntimeException;
10
use Spatie\Sheets\Facades\Sheets;
11
use Spatie\Sheets\Sheet;
12
13
class PageFactory implements PageFactoryContract
14
{
15 25
    public function make(array $data = [], ?string $page = null): PageContract
16
    {
17 25
        return app(PageContract::class, [
18 25
            'data' => $data,
19 25
            'page' => $page,
20
        ]);
21
    }
22
23 17
    public function makeFromSheet(Sheet $sheet, ?string $page = null): PageContract
24
    {
25 17
        return static::make($sheet->toArray(), $page);
0 ignored issues
show
Bug Best Practice introduced by Gummibeer
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

25
        return static::/** @scrutinizer ignore-call */ make($sheet->toArray(), $page);
Loading history...
26
    }
27
28 16
    public function makeFromSheetName(string $collection, string $name, ?string $page = null): PageContract
29
    {
30
        try {
31 16
            $sheet = Sheets::collection($collection)->get($name);
32 1
        } catch (RuntimeException $exception) {
33 1
            throw SheetCollectionNotFoundException::make($collection, $exception);
34
        }
35
36 15
        if ($sheet === null) {
37 1
            throw SheetNotFoundException::make($collection, $name);
38
        }
39
40 14
        return static::makeFromSheet($sheet, $page);
0 ignored issues
show
Bug Best Practice introduced by Gummibeer
The method Astrotomic\Stancy\Factor...actory::makeFromSheet() 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

40
        return static::/** @scrutinizer ignore-call */ makeFromSheet($sheet, $page);
Loading history...
41
    }
42
}
43