gggeek /
db-3v4l
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace Db3v4l\Console; |
||
| 4 | |||
| 5 | use Symfony\Component\Console\Application as BaseApplication; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Application was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 6 | use Symfony\Component\Console\Command\Command; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 7 | use Symfony\Component\Console\Command\ListCommand; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Command\ListCommand was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 8 | use Symfony\Component\Console\Input\InputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 9 | use Symfony\Component\Console\Input\InputOption; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 10 | use Symfony\Component\Console\Output\ConsoleOutputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Consol...\ConsoleOutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Style\SymfonyStyle was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use Symfony\Component\Debug\Exception\FatalThrowableError; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Debug\...ion\FatalThrowableError was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Depend...ContainerAwareInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 15 | use Symfony\Component\HttpKernel\Bundle\Bundle; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpKernel\Bundle\Bundle was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 16 | use Symfony\Component\HttpKernel\Kernel; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpKernel\Kernel was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 17 | use Symfony\Component\HttpKernel\KernelInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpKernel\KernelInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 18 | |||
| 19 | /** |
||
| 20 | * An Application that only registers 'dbconsole' commands via a custom command loader |
||
| 21 | * Sadly we can not easily extend Symfony\Bundle\FrameworkBundle\Console\Application, as it has private members. |
||
| 22 | * So we reimplement it fully... |
||
| 23 | */ |
||
|
0 ignored issues
–
show
|
|||
| 24 | class Application extends BaseApplication |
||
| 25 | { |
||
| 26 | private $kernel; |
||
|
0 ignored issues
–
show
|
|||
| 27 | private $commandsRegistered = false; |
||
|
0 ignored issues
–
show
|
|||
| 28 | private $registrationErrors = []; |
||
|
0 ignored issues
–
show
|
|||
| 29 | |||
| 30 | public function __construct(KernelInterface $kernel) |
||
|
0 ignored issues
–
show
|
|||
| 31 | { |
||
| 32 | $this->kernel = $kernel; |
||
| 33 | |||
| 34 | parent::__construct('Symfony', Kernel::VERSION); |
||
| 35 | |||
| 36 | $inputDefinition = $this->getDefinition(); |
||
| 37 | $inputDefinition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment())); |
||
| 38 | $inputDefinition->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.')); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Gets the Kernel associated with this Console. |
||
| 43 | * |
||
| 44 | * @return KernelInterface A KernelInterface instance |
||
| 45 | */ |
||
| 46 | public function getKernel() |
||
| 47 | { |
||
| 48 | return $this->kernel; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
|
0 ignored issues
–
show
|
|||
| 54 | public function reset() |
||
| 55 | { |
||
| 56 | if ($this->kernel->getContainer()->has('services_resetter')) { |
||
| 57 | $this->kernel->getContainer()->get('services_resetter')->reset(); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
|
0 ignored issues
–
show
|
|||
| 62 | * Runs the current application. |
||
| 63 | * |
||
| 64 | * @return int 0 if everything went fine, or an error code |
||
| 65 | */ |
||
| 66 | public function doRun(InputInterface $input, OutputInterface $output) |
||
| 67 | { |
||
| 68 | $this->registerCommands(); |
||
| 69 | |||
| 70 | if ($this->registrationErrors) { |
||
|
0 ignored issues
–
show
The expression
$this->registrationErrors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 71 | $this->renderRegistrationErrors($input, $output); |
||
| 72 | } |
||
| 73 | |||
| 74 | $this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher')); |
||
| 75 | |||
| 76 | return parent::doRun($input, $output); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
|
0 ignored issues
–
show
|
|||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
|
0 ignored issues
–
show
|
|||
| 82 | protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) |
||
| 83 | { |
||
| 84 | if (!$command instanceof ListCommand) { |
||
| 85 | if ($this->registrationErrors) { |
||
|
0 ignored issues
–
show
The expression
$this->registrationErrors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 86 | $this->renderRegistrationErrors($input, $output); |
||
| 87 | $this->registrationErrors = []; |
||
| 88 | } |
||
| 89 | |||
| 90 | return parent::doRunCommand($command, $input, $output); |
||
| 91 | } |
||
| 92 | |||
| 93 | $returnCode = parent::doRunCommand($command, $input, $output); |
||
| 94 | |||
| 95 | if ($this->registrationErrors) { |
||
|
0 ignored issues
–
show
The expression
$this->registrationErrors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 96 | $this->renderRegistrationErrors($input, $output); |
||
| 97 | $this->registrationErrors = []; |
||
| 98 | } |
||
| 99 | |||
| 100 | return $returnCode; |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
|
0 ignored issues
–
show
|
|||
| 104 | * {@inheritdoc} |
||
| 105 | */ |
||
|
0 ignored issues
–
show
|
|||
| 106 | public function find($name) |
||
| 107 | { |
||
| 108 | $this->registerCommands(); |
||
| 109 | |||
| 110 | return parent::find($name); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
|
0 ignored issues
–
show
|
|||
| 114 | * {@inheritdoc} |
||
| 115 | */ |
||
|
0 ignored issues
–
show
|
|||
| 116 | public function get($name) |
||
| 117 | { |
||
| 118 | $this->registerCommands(); |
||
| 119 | |||
| 120 | $command = parent::get($name); |
||
| 121 | |||
| 122 | if ($command instanceof ContainerAwareInterface) { |
||
| 123 | $command->setContainer($this->kernel->getContainer()); |
||
| 124 | } |
||
| 125 | |||
| 126 | return $command; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
|
0 ignored issues
–
show
|
|||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
|
0 ignored issues
–
show
|
|||
| 132 | public function all($namespace = null) |
||
| 133 | { |
||
| 134 | $this->registerCommands(); |
||
| 135 | |||
| 136 | return parent::all($namespace); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * {@inheritdoc} |
||
| 141 | */ |
||
|
0 ignored issues
–
show
|
|||
| 142 | public function getLongVersion() |
||
| 143 | { |
||
| 144 | return parent::getLongVersion().sprintf(' (env: <comment>%s</>, debug: <comment>%s</>)', $this->kernel->getEnvironment(), $this->kernel->isDebug() ? 'true' : 'false'); |
||
| 145 | } |
||
| 146 | |||
| 147 | public function add(Command $command) |
||
|
0 ignored issues
–
show
|
|||
| 148 | { |
||
| 149 | $this->registerCommands(); |
||
| 150 | |||
| 151 | return parent::add($command); |
||
| 152 | } |
||
| 153 | |||
| 154 | protected function registerCommands() |
||
|
0 ignored issues
–
show
|
|||
| 155 | { |
||
| 156 | if ($this->commandsRegistered) { |
||
| 157 | return; |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->commandsRegistered = true; |
||
| 161 | |||
| 162 | $this->kernel->boot(); |
||
| 163 | |||
| 164 | $container = $this->kernel->getContainer(); |
||
| 165 | |||
| 166 | /// @todo throw if not |
||
| 167 | if ($container->has('dbconsole.command_loader')) { |
||
| 168 | $this->setCommandLoader($container->get('dbconsole.command_loader')); |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($container->hasParameter('dbconsole.command.ids')) { |
||
| 172 | $lazyCommandIds = $container->hasParameter('dbconsole.lazy_command.ids') ? $container->getParameter('dbconsole.lazy_command.ids') : []; |
||
| 173 | foreach ($container->getParameter('dbconsole.command.ids') as $id) { |
||
| 174 | if (!isset($lazyCommandIds[$id])) { |
||
| 175 | try { |
||
| 176 | $this->add($container->get($id)); |
||
| 177 | } catch (\Throwable $e) { |
||
| 178 | $this->registrationErrors[] = $e; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | private function renderRegistrationErrors(InputInterface $input, OutputInterface $output) |
||
|
0 ignored issues
–
show
|
|||
| 186 | { |
||
| 187 | if ($output instanceof ConsoleOutputInterface) { |
||
| 188 | $output = $output->getErrorOutput(); |
||
| 189 | } |
||
| 190 | |||
| 191 | (new SymfonyStyle($input, $output))->warning('Some commands could not be registered:'); |
||
| 192 | |||
| 193 | foreach ($this->registrationErrors as $error) { |
||
| 194 | if (method_exists($this, 'doRenderThrowable')) { |
||
| 195 | $this->doRenderThrowable($error, $output); |
||
| 196 | } else { |
||
| 197 | if (!$error instanceof \Exception) { |
||
| 198 | $error = new FatalThrowableError($error); |
||
| 199 | } |
||
| 200 | |||
| 201 | $this->doRenderException($error, $output); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | } |
||
| 206 |