DoctorDbCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace GGGGino\SkuskuCartBundle\Command;
4
5
use Doctrine\ORM\EntityManager;
6
use GGGGino\SkuskuCartBundle\Model\SkuskuCurrencyInterface;
7
use GGGGino\SkuskuCartBundle\Service\CartManager;
8
use GGGGino\SkuskuCartBundle\Service\SkuskuHelper;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Class DoctorDbCommand
15
 * @package GGGGino\SkuskuCartBundle\Command
16
 */
17
class DoctorDbCommand extends ContainerAwareCommand
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function configure()
23
    {
24
        $this
25
            ->setName('ggggino_skusku:doctor:db')
26
            ->setDescription('Check if this bundle is correctly installed on the db');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $currencyText = $this->checkCurrencyOnDb();
35
        $output->writeln($currencyText);
36
    }
37
38
    /**
39
     * Check if exists at least one currency
40
     * Tip: ggggino_skusku:currency:create
41
     *
42
     * @return string
43
     */
44
    private function checkCurrencyOnDb()
45
    {
46
        /** @var EntityManager $em */
47
        $em = $this->getContainer()->get('doctrine')->getManager();
48
49
        /** @var SkuskuCurrencyInterface[] $Currencies */
50
        $currencies = $em->getRepository(SkuskuCurrencyInterface::class)->findAll();
51
52
        if ( count($currencies) > 0 ) {
53
            return 'Currency: <info> correct</info>';
54
        } else {
55
            return 'Currency: <error>not correct</error>';
56
        }
57
    }
58
}