GenerateSitemap::printFinishMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Actions\PostBuildTasks;
6
7
use Hyde\Hyde;
8
use Hyde\Framework\Features\BuildTasks\PostBuildTask;
9
use Hyde\Framework\Concerns\InteractsWithDirectories;
10
use Hyde\Framework\Features\XmlGenerators\SitemapGenerator;
11
12
use function file_put_contents;
13
14
class GenerateSitemap extends PostBuildTask
15
{
16
    use InteractsWithDirectories;
17
18
    public static string $message = 'Generating sitemap';
19
20
    protected string $path;
21
22
    public function handle(): void
23
    {
24
        if (! Hyde::hasSiteUrl()) {
0 ignored issues
show
Bug introduced by
The method hasSiteUrl() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

24
        if (! Hyde::/** @scrutinizer ignore-call */ hasSiteUrl()) {
Loading history...
25
            $this->skip('Cannot generate sitemap without a valid base URL');
26
        }
27
28
        $this->path = Hyde::sitePath('sitemap.xml');
0 ignored issues
show
Bug introduced by
The method sitePath() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

28
        /** @scrutinizer ignore-call */ 
29
        $this->path = Hyde::sitePath('sitemap.xml');
Loading history...
29
30
        $this->needsParentDirectory($this->path);
31
32
        file_put_contents($this->path, SitemapGenerator::make());
33
    }
34
35
    public function printFinishMessage(): void
36
    {
37
        $this->createdSiteFile($this->path)->withExecutionTime();
38
    }
39
}
40