Completed
Push — master ( 00d60f...aabe5c )
by Dion
14s
created

EnsureCacheCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 3 1
A execute() 0 8 2
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Tardigrades\Command;
5
6
use Doctrine\DBAL\DBALException;
7
use Symfony\Component\Cache\Adapter\PdoAdapter;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class EnsureCacheCommand extends Command
13
{
14
    /** @var PdoAdapter */
15
    private $adapter;
16
17
    public function __construct(PdoAdapter $adapter)
18
    {
19
        parent::__construct('sf:ensure-cache');
20
        $this->adapter = $adapter;
21
    }
22
23
    protected function configure()
24
    {
25
        $this->setDescription("Create the caching table in the database, if it doesn't exist");
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        try {
31
            $this->adapter->createTable();
32
            $output->writeln("<info>Caching table created!</info>");
33
        } catch (\PDOException | DBALException $exception) {
34
            $output->writeln($exception->getMessage(), OutputInterface::VERBOSITY_VERBOSE);
35
            $output->writeln("<info>Got database error, assuming caching table already exists</info>");
36
        }
37
    }
38
}
39