Test Failed
Pull Request — master (#29)
by Tom
04:40 queued 01:31
created

ExportFactory::addFeeds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Astrotomic\Stancy\Factories;
4
5
use Astrotomic\Stancy\Contracts\ExportFactory as ExportFactoryContract;
6
use Astrotomic\Stancy\Contracts\Page as PageContract;
7
use Astrotomic\Stancy\Contracts\PageFactory as PageFactoryContract;
8
use Astrotomic\Stancy\Traits\ConvertsSheetToPage;
9
use Illuminate\Contracts\Routing\UrlGenerator as UrlGeneratorContract;
10
use Illuminate\Support\Str;
11
use Spatie\Export\Exporter;
12
use Spatie\Sheets\Facades\Sheets;
13
14
class ExportFactory implements ExportFactoryContract
15
{
16
    use ConvertsSheetToPage;
17
18
    /** @var Exporter */
19
    protected $exporter;
20
21
    /** @var UrlGeneratorContract */
22
    protected $urlGenerator;
23
24 3
    public function __construct(PageFactoryContract $pageFactory, Exporter $exporter, UrlGeneratorContract $urlGenerator)
25
    {
26 3
        $this->pageFactory = $pageFactory;
27 3
        $this->exporter = $exporter;
28 3
        $this->urlGenerator = $urlGenerator;
29 3
    }
30
31
    /**
32
     * @param string[] $list
33
     *
34
     * @return void
35
     */
36 1
    public function addSheetList(array $list): void
37
    {
38 1
        foreach ($list as $entry) {
39 1
            if (Str::contains($entry, ':')) {
40 1
                [$collection, $path] = explode(':', $entry);
41
42 1
                $this->addPages([$this->sheetToPage(Sheets::collection($collection)->get($path))]);
0 ignored issues
show
Bug introduced by
It seems like Spatie\Sheets\Facades\Sh...collection)->get($path) can also be of type null; however, parameter $sheet of Astrotomic\Stancy\Factor...tFactory::sheetToPage() does only seem to accept Spatie\Sheets\Sheet, maybe add an additional type check? ( Ignorable by Annotation )

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

42
                $this->addPages([$this->sheetToPage(/** @scrutinizer ignore-type */ Sheets::collection($collection)->get($path))]);
Loading history...
43
44
                continue;
45
            }
46
47
            $this->addPages($this->sheetsToPages(Sheets::collection($entry)->all()->all()));
48
        }
49
    }
50
51
    public function addSheetCollectionName(string $name): void
52
    {
53
        $this->addSheetList([$name]);
54
    }
55
56
    public function addFeeds(array $except = []): void
0 ignored issues
show
introduced by
Method \Astrotomic\Stancy\Factories\ExportFactory::addFeeds() does not have @param annotation for its traversable parameter $except.
Loading history...
57
    {
58
        collect(config('feed.feeds'))->except($except)->each(function (array $config): void {
59
            $this->exporter->paths([$config['url']]);
60
        });
61
    }
62
63
    /**
64
     * @param PageContract[] $pages
65
     *
66
     * @return void
67
     */
68 1
    protected function addPages(array $pages): void
69
    {
70 1
        foreach ($pages as $page) {
71 1
            $this->exporter->paths([Str::replaceFirst($this->urlGenerator->to('/'), '', $page->getUrl())]);
0 ignored issues
show
Bug introduced by
The method getUrl() does not exist on Astrotomic\Stancy\Contracts\Page. Since it exists in all sub-types, consider adding an abstract or default implementation to Astrotomic\Stancy\Contracts\Page. ( Ignorable by Annotation )

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

71
            $this->exporter->paths([Str::replaceFirst($this->urlGenerator->to('/'), '', $page->/** @scrutinizer ignore-call */ getUrl())]);
Loading history...
72
        }
73
    }
74
}
75