Issues (54)

src/Factories/SitemapFactory.php (2 issues)

php.Return type hint

Major
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\Contracts\SitemapFactory as SitemapFactoryContract;
8
use Astrotomic\Stancy\Traits\ConvertsSheetToPage;
9
use Illuminate\Support\Str;
10
use Spatie\Sheets\Facades\Sheets;
11
use Spatie\Sitemap\Sitemap;
12
13
class SitemapFactory implements SitemapFactoryContract
14
{
15
    use ConvertsSheetToPage;
16
17 4
    public function __construct(PageFactoryContract $pageFactory)
18
    {
19 4
        $this->pageFactory = $pageFactory;
20 4
    }
21
22
    /**
23
     * @param string[] $list
24
     *
25
     * @return Sitemap
0 ignored issues
show
Method \Astrotomic\Stancy\Factories\SitemapFactory::makeFromSheetList() has useless @return annotation.
Loading history...
26
     */
27 2
    public function makeFromSheetList(array $list): Sitemap
28
    {
29 2
        $pages = [];
30
31 2
        foreach ($list as $entry) {
32 2
            if (Str::contains($entry, ':')) {
33 1
                [$collection, $path] = explode(':', $entry);
34
35 1
                $pages[] = $this->sheetToPage(Sheets::collection($collection)->get($path));
36
37 1
                continue;
38
            }
39
40 1
            $pages = array_merge($pages, $this->sheetsToPages(Sheets::collection($entry)->all()->all()));
41
        }
42
43 2
        return $this->makeFromPages($pages);
44
    }
45
46 1
    public function makeFromSheetCollectionName(string $name): Sitemap
47
    {
48 1
        return $this->makeFromSheetList([$name]);
49
    }
50
51
    /**
52
     * @param PageContract[] $pages
53
     *
54
     * @return Sitemap
0 ignored issues
show
Method \Astrotomic\Stancy\Factories\SitemapFactory::makeFromPages() has useless @return annotation.
Loading history...
55
     */
56 2
    protected function makeFromPages(array $pages): Sitemap
57
    {
58 2
        $sitemap = Sitemap::create();
59
60 2
        foreach ($pages as $page) {
61 2
            $sitemap->add($page->toSitemapItem());
62
        }
63
64 2
        return $sitemap;
65
    }
66
}
67