GenerateCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Spatie\SchemaOrg\Generator\Console;
4
5
use Spatie\SchemaOrg\Generator\Definitions;
6
use Spatie\SchemaOrg\Generator\PackageGenerator;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class GenerateCommand extends Command
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('generate')
18
            ->setDescription('Generate the package code from the schema.org docs')
19
            ->addOption('local', 'l', InputOption::VALUE_NONE, 'Use a cached version of the source');
20
    }
21
22
    /**
23
     * @param \Symfony\Component\Console\Input\InputInterface $input
24
     * @param \Symfony\Component\Console\Output\OutputInterface $output
25
     *
26
     * @return int
27
     */
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $output->writeln('Generating package code...');
31
32
        $generator = new PackageGenerator();
33
34
        $definitions = new Definitions([
35
            'core' => 'https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/releases/7.04/schema.rdfa',
36
        ]);
37
38
        if (! $input->getOption('local')) {
39
            $definitions->preload();
40
        }
41
42
        $generator->generate($definitions);
43
44
        $output->writeln('Done!');
45
46
        return 0;
47
    }
48
}
49