Test Failed
Push — main ( 082278...f3ede0 )
by Davide
16:15
created

GenerateSitemap::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Post;
6
use App\Services\PostService;
7
use Illuminate\Console\Command;
8
use Spatie\Sitemap\Sitemap;
9
use Spatie\Sitemap\Tags\Url;
10
11
class GenerateSitemap extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'sitemap:generate';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Generate the sitemap';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32
    private PostService $postService;
33
34
    public function __construct(
35
        PostService $postService
36
    ) {
37
        parent::__construct();
38
        $this->postService = $postService;
39
    }
40
41
    /**
42
     * Execute the console command.
43
     *
44
     * @return int
45
     */
46
    public function handle()
47
    {
48
        $sitemap = Sitemap::create()
49
        ->add(Url::create('/blog'))
50
        ->add(Url::create('/next_events'))
51
        ->add(Url::create('/treatments-ilan-lev-method'))
52
          ->add(Url::create('/contact-improvisation'))
53
          ->add(Url::create('/getATreatment'))
54
          ->add(Url::create('/aboutMe'))
55
          ->add(Url::create('/contact'));
56
57
        /*$posts = $this->postService->getPosts(null, ['status' => 'published']);
58
        foreach ($posts as $post) {
59
            $sitemap->add(Url::create("/posts/{$post->slug}"));
60
        }*/
61
        $sitemap->writeToFile(public_path('sitemap.xml'));
62
    }
63
}
64