GenerateIndex   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 5 1
A execute() 0 5 1
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