Issues (117)

Command/GenerateGridSourceCommand.php (13 issues)

1
<?php
2
3
namespace Dtc\GridBundle\Command;
4
5
use Doctrine\Bundle\DoctrineBundle\Registry;
0 ignored issues
show
The type Doctrine\Bundle\DoctrineBundle\Registry 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
0 ignored issues
show
The type Doctrine\Bundle\MongoDBBundle\ManagerRegistry 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Doctrine\ODM\MongoDB\DocumentManager;
0 ignored issues
show
The type Doctrine\ODM\MongoDB\DocumentManager 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
The type Doctrine\ORM\EntityManagerInterface 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Dtc\GridBundle\Generator\GridSourceGenerator;
10
use Symfony\Bundle\FrameworkBundle\Console\Application;
0 ignored issues
show
The type Symfony\Bundle\FrameworkBundle\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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\Input\InputArgument;
0 ignored issues
show
The type Symfony\Component\Console\Input\InputArgument 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
/**
18
 * @deprecated
19
 *
20
 * Class GenerateGridSourceCommand
21
 */
22
class GenerateGridSourceCommand extends Command
23
{
24
    protected $registry;
25
    protected $mongodbRegistry;
26
    protected $entityManager;
27
    protected $documentManager;
28
29
    protected function configure()
30
    {
31
        $this
32
        ->setName('dtc:grid:source:generate')
33
            ->setDefinition([
34
                new InputArgument('entity_or_document', InputArgument::REQUIRED, 'The entity or document class name to initialize (shortcut notation)'),
35
                new InputArgument('class_name', InputArgument::OPTIONAL, 'Name of GridSource - camel case, no space.'),
36
                new InputOption('columns', null, InputOption::VALUE_NONE, 'Generate column files.'),
37
            ])
38
        ->setDescription('Generate a class for GridSource, GridColumn and template file')
39
        ;
40
    }
41
42
    public function setRegistry(Registry $registry)
43
    {
44
        $this->registry = $registry;
45
    }
46
47
    public function setEntityManager(EntityManagerInterface $entityManager)
48
    {
49
        $this->entityManager = $entityManager;
50
    }
51
52
    public function setDocumentManager(DocumentManager $documentManager)
53
    {
54
        $this->documentManager = $documentManager;
55
    }
56
57
    public function setMongoDBRegistry(ManagerRegistry $mongoDBRegistry)
58
    {
59
        $this->mongoDBRegistry = $mongoDBRegistry;
0 ignored issues
show
Bug Best Practice introduced by
The property mongoDBRegistry does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
60
    }
61
62
    protected function execute(InputInterface $input, OutputInterface $output)
63
    {
64
        // Taken from SensioGeneratorBundle: class Command\Validators (see LICENSE)
65
        if (!preg_match('{^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*:[a-zA-Z0-9_\x7f-\xff\\\/]+$}', $entity = $input->getArgument('entity_or_document'))) {
66
            throw new \InvalidArgumentException(sprintf('The entity name isn\'t valid ("%s" given, expecting something like AcmeBlogBundle:Blog/Post)', $entity));
67
        }
68
69
        list($bundle, $entity) = $this->parseShortcutNotation($entity);
70
71
        if ($this->registry) {
72
            $entityClass = $this->registry->getAliasNamespace($bundle).'\\'.$entity;
73
        }
74
        if ($this->mongodbRegistry) {
75
            $documentClass = $this->mongodbRegistry->getAliasNamespace($bundle).'\\'.$entity;
76
        }
77
78
        if (isset($entityClass) && $this->entityManager) {
79
            try {
80
                $metadata = $this->entityManager->getClassMetadata($entityClass);
81
            } catch (\Exception $exception) {
82
                if (!preg_match('/does not exist/', $exception->getMessage())) {
83
                    throw $exception;
84
                }
85
            }
86
        }
87
        if (!isset($metadata) && $this->documentManager) {
88
            if (!isset($documentClass)) {
89
                throw new \Exception("Could not get metadata for $entity");
90
            }
91
            $metadata = $this->documentManager->getClassMetadata($documentClass);
92
        }
93
94
        $application = $this->getApplication();
95
        if ($application instanceof Application) {
96
            $bundle = $application->getKernel()->getBundle($bundle);
97
        } else {
98
            throw new \Exception("Can't lookup bundle for $bundle");
99
        }
100
        $skeletonDir = __DIR__.'/../Resources/skeleton';
101
        $columnGenerator = new GridSourceGenerator($skeletonDir);
0 ignored issues
show
Deprecated Code introduced by
The class Dtc\GridBundle\Generator\GridSourceGenerator has been deprecated. ( Ignorable by Annotation )

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

101
        $columnGenerator = /** @scrutinizer ignore-deprecated */ new GridSourceGenerator($skeletonDir);
Loading history...
102
103
        $columnGenerator->generate($bundle, $entity, $metadata, $input->getOption('columns'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $metadata does not seem to be defined for all execution paths leading up to this point.
Loading history...
104
    }
105
106
    protected function parseShortcutNotation($shortcut)
107
    {
108
        $entity = str_replace('/', '\\', $shortcut);
109
110
        if (false === $pos = strpos($entity, ':')) {
111
            throw new \InvalidArgumentException(sprintf('The entity name must contain a : ("%s" given, expecting something like AcmeBlogBundle:Blog/Post)', $entity));
112
        }
113
114
        return [substr($entity, 0, $pos), substr($entity, $pos + 1)];
115
    }
116
}
117