CreateSchemaCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 2
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the InMemoryList package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 */
10
11
namespace InMemoryList\Command;
12
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
class CreateSchemaCommand extends BaseCommand
17
{
18
    /**
19
     * CreateSchemaCommand constructor.
20
     *
21
     * @param array $parameters
22
     */
23
    public function __construct(array $parameters)
24
    {
25
        parent::__construct(
26
            'iml_cache_create_schema',
27
            'pdo',
28
            $parameters
29
        );
30
    }
31
32
    protected function configure()
33
    {
34
        $this
35
            ->setName('iml:cache:schema:create')
36
            ->setDescription('Create database schema.')
37
            ->setHelp('This command creates the database schema (only with PDO driver).')
38
        ;
39
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        if($this->driver !== 'pdo'){
44
            throw new \Exception('This command is avaliable only with PDO driver');
45
        }
46
47
        $cache = $this->createClient($this->driver, $this->parameters);
48
49
        try {
50
            $cache->getRepository()->createSchema();
0 ignored issues
show
Bug introduced by
The method createSchema() does not exist on InMemoryList\Domain\Mode...ListRepositoryInterface. Did you maybe mean create()? ( Ignorable by Annotation )

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

50
            $cache->getRepository()->/** @scrutinizer ignore-call */ createSchema();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
52
            $output->writeln('<fg=red>['.$this->driver.'] Schema was successful created.</>');
53
        } catch (\Exception $e) {
54
            $output->writeln('<fg=red>['.$this->driver.'] Error in schema creation: '.$e->getMessage().' .</>');
55
        }
56
    }
57
}
58