GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#249)
by Théo
34:54
created

LoadDataFixturesCommand::execute()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 34
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.439
c 0
b 0
f 0
cc 5
eloc 20
nc 5
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Hautelook\AliceBundle package.
5
 *
6
 * (c) Baldur Rensch <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Hautelook\AliceBundle\Console\Command;
13
14
use Doctrine\Common\Persistence\ManagerRegistry;
15
use Hautelook\AliceBundle\Doctrine\DataFixtures\Executor\FixturesExecutorInterface;
16
use Hautelook\AliceBundle\Doctrine\Finder\FixturesFinder;
17
use Hautelook\AliceBundle\Doctrine\Generator\LoaderGeneratorInterface;
18
use Hautelook\AliceBundle\Finder\FixturesFinderInterface;
19
use Hautelook\AliceBundle\BundleResolverInterface;
20
use Hautelook\AliceBundle\LoaderInterface as AliceBundleLoaderInterface;
21
use Symfony\Bundle\FrameworkBundle\Console\Application;
22
use Symfony\Component\Console\Command\Command;
23
use Symfony\Component\Console\Helper\QuestionHelper;
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Input\InputOption;
26
use Symfony\Component\Console\Output\OutputInterface;
27
use Symfony\Component\Console\Question\ConfirmationQuestion;
28
29
/**
30
 * Command used to load the fixtures.
31
 *
32
 * @author Théo FIDRY <[email protected]>
33
 */
34
class LoadDataFixturesCommand extends Command
35
{
36
    /**
37
     * @var BundleResolverInterface
38
     */
39
    private $bundlesResolver;
0 ignored issues
show
Unused Code introduced by
The property $bundlesResolver is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
41
    /**
42
     * @var ManagerRegistry
43
     */
44
    private $doctrine;
45
46
    /**
47
     * @var FixturesExecutorInterface
48
     */
49
    private $fixturesExecutor;
0 ignored issues
show
Unused Code introduced by
The property $fixturesExecutor is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
50
51
    /**
52
     * @var FixturesFinderInterface|FixturesFinder
53
     */
54
    private $fixturesFinder;
0 ignored issues
show
Unused Code introduced by
The property $fixturesFinder is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
55
56
    /**
57
     * @var FixturesLoaderInterface
58
     */
59
    private $fixturesLoader;
0 ignored issues
show
Unused Code introduced by
The property $fixturesLoader is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
60
61
    /**
62
     * @var LoaderInterface
63
     */
64
    private $loader;
65
66
    /**
67
     * @var LoaderGeneratorInterface
68
     */
69
    private $loaderGenerator;
0 ignored issues
show
Unused Code introduced by
The property $loaderGenerator is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
70
71
    /**
72
     * @param string                    $name             Command name
73
     * @param ManagerRegistry           $doctrine
0 ignored issues
show
Bug introduced by
There is no parameter named $doctrine. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
     * @param LoaderInterface           $loader
75
     * @param FixturesLoaderInterface   $fixturesLoader
0 ignored issues
show
Documentation introduced by
There is no parameter named $fixturesLoader. Did you maybe mean $loader?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
76
     * @param FixturesFinderInterface   $fixturesFinder
0 ignored issues
show
Bug introduced by
There is no parameter named $fixturesFinder. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
     * @param BundleResolverInterface   $bundlesResolver
0 ignored issues
show
Bug introduced by
There is no parameter named $bundlesResolver. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
78
     * @param LoaderGeneratorInterface  $loaderGenerator
0 ignored issues
show
Documentation introduced by
There is no parameter named $loaderGenerator. Did you maybe mean $loader?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
79
     * @param FixturesExecutorInterface $fixturesExecutor
0 ignored issues
show
Bug introduced by
There is no parameter named $fixturesExecutor. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
80
     */
81
    public function __construct($name, AliceBundleLoaderInterface $loader)
82
    {
83
        parent::__construct($name);
84
85
        $this->loader = $loader;
0 ignored issues
show
Documentation Bug introduced by
It seems like $loader of type object<Hautelook\AliceBundle\LoaderInterface> is incompatible with the declared type object<Hautelook\AliceBu...ommand\LoaderInterface> of property $loader.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    protected function configure()
92
    {
93
        $this
94
            ->setAliases(['fixtures:load'])
95
            ->setDescription('Load data fixtures to your database.')
96
            ->addOption(
97
                'bundle',
98
                'b',
99
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
100
                'Bundles where fixtures should be loaded.'
101
            )
102
            ->addOption(
103
                'manager',
104
                'em',
105
                InputOption::VALUE_REQUIRED,
106
                'The entity manager to use for this command.'
107
            )
108
            ->addOption(
109
                'append',
110
                null,
111
                InputOption::VALUE_NONE,
112
                'Append the data fixtures instead of deleting all data from the database first.'
113
            )
114
            ->addOption(
115
                'shard',
116
                null,
117
                InputOption::VALUE_REQUIRED,
118
                'The shard database id to use for this command.'
119
            )
120
            ->addOption('purge-with-truncate',
121
                null,
122
                InputOption::VALUE_NONE,
123
                'Purge data by using a database-level TRUNCATE statement when using Doctrine ORM.'
124
            )
125
        ;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     *
131
     * \RuntimeException Unsupported Application type
132
     */
133
    protected function execute(InputInterface $input, OutputInterface $output)
134
    {
135
        // Warn the user that the database will be purged
136
        // Ask him to confirm his choice
137
        if ($input->isInteractive() && !$input->getOption('append')) {
138
            if (false === $this->askConfirmation(
139
                    $input,
140
                    $output,
141
                    '<question>Careful, database will be purged. Do you want to continue y/N ?</question>',
142
                    false
143
                )
144
            ) {
145
                return;
146
            }
147
        }
148
149
        $manager = $this->doctrine->getManager($input->getOption('manager'));
0 ignored issues
show
Unused Code introduced by
$manager is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
150
        $environment = $input->getOption('env');
151
        $bundles = $input->getOption('bundle');
152
        $shard = $input->getOption('shard');
153
        $append = $input->getOption('append');
154
        $truncate = $input->getOption('purge-with-truncate');
155
156
        /** @var Application $application */
157
        $application = $this->getApplication();
158
        if (false === $application instanceof Application) {
159
            throw new \RuntimeException(
160
                'Expected application to be an instance of "%s".',
161
                Application::class
162
            );
163
        }
164
165
        return $this->loader->load($application, $bundles, $environment, $shard, $append, $truncate);
166
    }
167
168
    /**
169
     * Prompts to the user a message to ask him a confirmation.
170
     *
171
     * @param InputInterface  $input
172
     * @param OutputInterface $output
173
     * @param string          $question
174
     * @param bool            $default
175
     *
176
     * @return bool User choice
177
     */
178
    private function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default)
179
    {
180
        /** @var QuestionHelper $questionHelper */
181
        $questionHelper = $this->getHelperSet()->get('question');
182
        $question = new ConfirmationQuestion($question, $default);
183
184
        return (bool) $questionHelper->ask($input, $output, $question);
185
    }
186
}
187