GenerateIndex::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chinstrap\Core\Console\Commands;
6
7
use Chinstrap\Core\Contracts\Sources\Source;
8
use League\Flysystem\FilesystemInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
final class GenerateIndex extends Command
14
{
15
    protected Source $source;
16
17
    protected FilesystemInterface $manager;
18
19
    public function __construct(Source $source, FilesystemInterface $manager)
20
    {
21
        parent::__construct();
22
        $this->source = $source;
23
        $this->manager = $manager;
24
    }
25
26
    protected function configure(): void
27
    {
28
        $this->setName('index:generate')
29
                ->setDescription('Generates the search index')
30
                ->setHelp('This command will generate the search index file');
31
    }
32
33
    protected function execute(InputInterface $input, OutputInterface $output): int
34
    {
35
        $searchable = $this->source->all();
36
        $this->manager->put('assets://index.json', json_encode($searchable->toArray()));
37
        return 1;
38
    }
39
}
40