Passed
Push — ft/sitemap ( 9924a4...f8fe52 )
by Ben
06:49
created

SitemapFiles::allWithin()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 1
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Thinktomorrow\Chief\System\Sitemap;
5
6
use Carbon\Carbon;
7
use Illuminate\Support\Str;
8
use Illuminate\Support\Collection;
9
use Illuminate\Filesystem\Filesystem;
10
use Symfony\Component\Finder\SplFileInfo;
11
12
class SitemapFiles
13
{
14
    /** @var Filesystem */
15
    private $filesystem;
16
17
    public function __construct(Filesystem $filesystem)
18
    {
19
        $this->filesystem = $filesystem;
20
    }
21
22
    /**
23
     * @param string $directory
24
     * @return Collection (SplFileInfo[])
25
     */
26
    public function allWithin(string $directory): Collection
27
    {
28
        $files = $this->filesystem->files($directory);
29
30
        return collect($files)->filter(function($file){
0 ignored issues
show
Bug Best Practice introduced by
The expression return collect($files)->...ion(...) { /* ... */ }) returns the type Tightenco\Collect\Support\Collection which is incompatible with the type-hinted return Illuminate\Support\Collection.
Loading history...
31
            return (Str::startsWith($file->getFileName(), 'sitemap-') && Str::endsWith($file->getFileName(), '.xml'));
32
        });
33
    }
34
}
35