Conditions | 23 |
Paths | > 20000 |
Total Lines | 89 |
Code Lines | 48 |
Lines | 6 |
Ratio | 6.74 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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 |
||
64 | private function addService($id, $definition) |
||
65 | { |
||
66 | $code = " $id:\n"; |
||
67 | if ($definition->getClass()) { |
||
|
|||
68 | $code .= sprintf(" class: %s\n", $definition->getClass()); |
||
69 | } |
||
70 | |||
71 | if (!$definition->isPublic()) { |
||
72 | $code .= " public: false\n"; |
||
73 | } |
||
74 | |||
75 | $tagsCode = ''; |
||
76 | foreach ($definition->getTags() as $name => $tags) { |
||
77 | foreach ($tags as $attributes) { |
||
78 | $att = array(); |
||
79 | foreach ($attributes as $key => $value) { |
||
80 | $att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value)); |
||
81 | } |
||
82 | $att = $att ? ', '.implode(', ', $att) : ''; |
||
83 | |||
84 | $tagsCode .= sprintf(" - { name: %s%s }\n", $this->dumper->dump($name), $att); |
||
85 | } |
||
86 | } |
||
87 | if ($tagsCode) { |
||
88 | $code .= " tags:\n".$tagsCode; |
||
89 | } |
||
90 | |||
91 | if ($definition->getFile()) { |
||
92 | $code .= sprintf(" file: %s\n", $definition->getFile()); |
||
93 | } |
||
94 | |||
95 | if ($definition->isSynthetic()) { |
||
96 | $code .= sprintf(" synthetic: true\n"); |
||
97 | } |
||
98 | |||
99 | if ($definition->isSynchronized(false)) { |
||
100 | $code .= sprintf(" synchronized: true\n"); |
||
101 | } |
||
102 | |||
103 | if ($definition->getFactoryClass(false)) { |
||
104 | $code .= sprintf(" factory_class: %s\n", $definition->getFactoryClass(false)); |
||
105 | } |
||
106 | |||
107 | if ($definition->isLazy()) { |
||
108 | $code .= sprintf(" lazy: true\n"); |
||
109 | } |
||
110 | |||
111 | if ($definition->getFactoryMethod(false)) { |
||
112 | $code .= sprintf(" factory_method: %s\n", $definition->getFactoryMethod(false)); |
||
113 | } |
||
114 | |||
115 | if ($definition->getFactoryService(false)) { |
||
116 | $code .= sprintf(" factory_service: %s\n", $definition->getFactoryService(false)); |
||
117 | } |
||
118 | |||
119 | if ($definition->getArguments()) { |
||
120 | $code .= sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0)); |
||
121 | } |
||
122 | |||
123 | if ($definition->getProperties()) { |
||
124 | $code .= sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0)); |
||
125 | } |
||
126 | |||
127 | if ($definition->getMethodCalls()) { |
||
128 | $code .= sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12)); |
||
129 | } |
||
130 | |||
131 | if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope()) { |
||
132 | $code .= sprintf(" scope: %s\n", $scope); |
||
133 | } |
||
134 | |||
135 | if (null !== $decorated = $definition->getDecoratedService()) { |
||
136 | list($decorated, $renamedId) = $decorated; |
||
137 | $code .= sprintf(" decorates: %s\n", $decorated); |
||
138 | if (null !== $renamedId) { |
||
139 | $code .= sprintf(" decoration_inner_name: %s\n", $renamedId); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | View Code Duplication | if ($callable = $definition->getFactory()) { |
|
144 | $code .= sprintf(" factory: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0)); |
||
145 | } |
||
146 | |||
147 | View Code Duplication | if ($callable = $definition->getConfigurator()) { |
|
148 | $code .= sprintf(" configurator: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0)); |
||
149 | } |
||
150 | |||
151 | return $code; |
||
152 | } |
||
153 | |||
346 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: