Conditions | 6 |
Paths | 30 |
Total Lines | 78 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 19 | ||
Bugs | 2 | Features | 9 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
15 | public function load(array $configs, ContainerBuilder $container) |
||
16 | { |
||
17 | foreach ($configs as $config) { |
||
18 | if ($this->isConnectionConfig($config)) { |
||
19 | $connectionConfig = $config; |
||
20 | } |
||
21 | } |
||
22 | if ($container->hasParameter('connection_config')) { |
||
23 | $connectionConfig = $container->getParameter('connection_config'); |
||
24 | } |
||
25 | |||
26 | $this->defineParameters($container); |
||
27 | |||
28 | $definition = new Definition('Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher'); |
||
29 | $definition->setArguments(array(new Reference('service_container'))); |
||
30 | $container->setDefinition('event_dispatcher', $definition); |
||
31 | |||
32 | $definition = new Definition('Rentgen\Schema\Manipulation'); |
||
33 | $definition->setArguments(array(new Reference('service_container'))); |
||
34 | $container->setDefinition('rentgen.schema.manipulation', $definition); |
||
35 | |||
36 | $definition = new Definition('Rentgen\Schema\Info'); |
||
37 | $definition->setArguments(array(new Reference('service_container'))); |
||
38 | $container->setDefinition('rentgen.schema.info', $definition); |
||
39 | |||
40 | if (!isset($connectionConfig)) { |
||
41 | $fileLocator = new FileLocator(getcwd()); |
||
42 | try { |
||
43 | $configFile = $fileLocator->locate('rentgen.yml'); |
||
|
|||
44 | $content = file_get_contents('rentgen.yml'); |
||
45 | $config = Yaml::parse($content); |
||
46 | $connectionConfig = $config; |
||
47 | } catch (\InvalidArgumentException $e) { |
||
48 | $connectionConfig['environments']['dev'] = array( |
||
49 | 'adapter' => 'pgsql', |
||
50 | 'host' => 'localhost', |
||
51 | 'database' => null, |
||
52 | 'username' => 'postgres', |
||
53 | 'password' => '', |
||
54 | 'port' => 5432, |
||
55 | ); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | $definition = new Definition('Rentgen\Database\Connection\ConnectionConfig'); |
||
60 | $definition->setArguments(array($connectionConfig['environments'])); |
||
61 | $container->setDefinition('connection_config', $definition); |
||
62 | |||
63 | $definition = new Definition('Rentgen\Database\Connection\Connection'); |
||
64 | $definition->setArguments(array(new Reference('connection_config'))); |
||
65 | $container->setDefinition('connection', $definition); |
||
66 | |||
67 | $this->connection = $container->getDefinition('connection'); |
||
68 | $this->eventDispatcher = $container->getDefinition('event_dispatcher'); |
||
69 | |||
70 | $this->setDefinition('rentgen.create_table', 'rentgen.command.manipulation.create_table.class', $container); |
||
71 | $this->setDefinition('rentgen.drop_table', 'rentgen.command.manipulation.drop_table.class', $container); |
||
72 | $this->setDefinition('rentgen.add_column', 'rentgen.command.manipulation.add_column.class', $container); |
||
73 | $this->setDefinition('rentgen.drop_column', 'rentgen.command.manipulation.drop_column.class', $container); |
||
74 | $this->setDefinition('rentgen.add_constraint', 'rentgen.command.manipulation.add_constraint.class', $container); |
||
75 | $this->setDefinition('rentgen.drop_constraint', 'rentgen.command.manipulation.drop_constraint.class', $container); |
||
76 | $this->setDefinition('rentgen.create_index', 'rentgen.command.manipulation.create_index.class', $container); |
||
77 | $this->setDefinition('rentgen.create_schema', 'rentgen.command.manipulation.create_schema.class', $container); |
||
78 | $this->setDefinition('rentgen.drop_schema', 'rentgen.command.manipulation.drop_schema.class', $container); |
||
79 | $this->setDefinition('rentgen.drop_index', 'rentgen.command.manipulation.drop_index.class', $container); |
||
80 | |||
81 | $this->setDefinition('rentgen.table_exists', 'rentgen.command.info.table_exists.class', $container); |
||
82 | $this->setDefinition('rentgen.get_table', 'rentgen.command.info.get_table.class', $container); |
||
83 | $this->setDefinition('rentgen.get_tables', 'rentgen.command.info.get_tables.class', $container); |
||
84 | $this->setDefinition('rentgen.get_schemas', 'rentgen.command.info.get_schemas.class', $container); |
||
85 | $this->setDefinition('rentgen.schema_exists', 'rentgen.command.info.schema_exists.class', $container); |
||
86 | |||
87 | $definition = new Definition($container->getParameter('rentgen.command.manipulation.clear_database.class'), |
||
88 | array(new Reference('rentgen.get_schemas'))); |
||
89 | $definition->addMethodCall('setConnection', array(new Reference('connection'))); |
||
90 | $definition->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher'))); |
||
91 | $container->setDefinition('rentgen.clear_database', $definition); |
||
92 | } |
||
93 | |||
147 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.