Completed
Push — master ( 016937...9e2a06 )
by Tom
03:53
created

SitemapFactory::makeFromSheetCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Astrotomic\Stancy\Factories;
4
5
use Astrotomic\Stancy\Contracts\SitemapFactory as SitemapFactoryContract;
0 ignored issues
show
introduced by
You should change the following
<fg=green>+use Astrotomic\Stancy\Contracts\PageFactory as PageFactoryContract;
</>
Loading history...
6
use Astrotomic\Stancy\Contracts\PageFactory as PageFactoryContract;
0 ignored issues
show
introduced by
You should change the following
<fg=red>-use Astrotomic\Stancy\Contracts\PageFactory as PageFactoryContract;
</>
Loading history...
7
use Spatie\Sheets\Facades\Sheets;
8
use Spatie\Sheets\Repository as SheetRepository;
9
use Spatie\Sheets\Sheet;
10
use Spatie\Sitemap\Sitemap;
11
12
class SitemapFactory implements SitemapFactoryContract
13
{
14
    /** @var PageFactoryContract */
15
    protected $pageFactory;
16
17 3
    public function __construct(PageFactoryContract $pageFactory)
18
    {
19 3
        $this->pageFactory = $pageFactory;
20 3
    }
21
22 1
    public function makeFromSheetCollection(SheetRepository $collection): Sitemap
23
    {
24 1
        $sitemap = Sitemap::create();
25
26
        $collection->all()->each(function(Sheet $sheet) use ($sitemap) {
0 ignored issues
show
introduced by
Closure does not have void return type hint.
Loading history...
introduced by
You should change the following
<fg=red>- $collection->all()->each(function(Sheet $sheet) use ($sitemap) {
</><fg=green>+ $collection->all()->each(function(Sheet $sheet) use ($sitemap): void {
</>
Loading history...
introduced by
You should change the following
<fg=red>- $collection->all()->each(function(Sheet $sheet) use ($sitemap) {
</><fg=green>+ $collection->all()->each(function (Sheet $sheet) use ($sitemap) {
</>
Loading history...
27 1
            $sitemap->add($this->pageFactory->makeFromSheet($sheet)->toSitemapItem());
28 1
        });
29
30 1
        return $sitemap;
31
    }
32
33 1
    public function makeFromSheetCollectionName(string $name): Sitemap
34
    {
35 1
        $collection = Sheets::collection($name);
36
37 1
        return $this->makeFromSheetCollection($collection);
38
    }
39
}
40