| Conditions | 3 |
| Paths | 3 |
| Total Lines | 128 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 138 | public function registerDoctrineMapping(array $config) |
||
| 139 | { |
||
| 140 | $collector = DoctrineCollector::getInstance(); |
||
| 141 | |||
| 142 | foreach ($config['class'] as $type => $class) { |
||
| 143 | if (!class_exists($class)) { |
||
| 144 | /* |
||
| 145 | * NEXT_MAJOR: |
||
| 146 | * Throw an exception if the class is not defined |
||
| 147 | */ |
||
| 148 | @trigger_error(sprintf( |
||
|
|
|||
| 149 | 'The "%s" class is not defined or does not exist. This is tolerated now but will be forbidden in 4.0', |
||
| 150 | $class |
||
| 151 | ), E_USER_DEPRECATED); |
||
| 152 | |||
| 153 | return; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $collector->addAssociation($config['class']['post'], 'mapOneToMany', [ |
||
| 158 | 'fieldName' => 'comments', |
||
| 159 | 'targetEntity' => $config['class']['comment'], |
||
| 160 | 'cascade' => [ |
||
| 161 | 0 => 'remove', |
||
| 162 | 1 => 'persist', |
||
| 163 | ], |
||
| 164 | 'mappedBy' => 'post', |
||
| 165 | 'orphanRemoval' => true, |
||
| 166 | 'orderBy' => [ |
||
| 167 | 'createdAt' => 'DESC', |
||
| 168 | ], |
||
| 169 | ]); |
||
| 170 | |||
| 171 | $collector->addAssociation($config['class']['post'], 'mapManyToOne', [ |
||
| 172 | 'fieldName' => 'image', |
||
| 173 | 'targetEntity' => $config['class']['media'], |
||
| 174 | 'cascade' => [ |
||
| 175 | 0 => 'remove', |
||
| 176 | 1 => 'persist', |
||
| 177 | 2 => 'refresh', |
||
| 178 | 3 => 'merge', |
||
| 179 | 4 => 'detach', |
||
| 180 | ], |
||
| 181 | 'mappedBy' => null, |
||
| 182 | 'inversedBy' => null, |
||
| 183 | 'joinColumns' => [ |
||
| 184 | [ |
||
| 185 | 'name' => 'image_id', |
||
| 186 | 'referencedColumnName' => 'id', |
||
| 187 | ], |
||
| 188 | ], |
||
| 189 | 'orphanRemoval' => false, |
||
| 190 | ]); |
||
| 191 | |||
| 192 | $collector->addAssociation($config['class']['post'], 'mapManyToOne', [ |
||
| 193 | 'fieldName' => 'author', |
||
| 194 | 'targetEntity' => $config['class']['user'], |
||
| 195 | 'cascade' => [ |
||
| 196 | 1 => 'persist', |
||
| 197 | ], |
||
| 198 | 'mappedBy' => null, |
||
| 199 | 'inversedBy' => null, |
||
| 200 | 'joinColumns' => [ |
||
| 201 | [ |
||
| 202 | 'name' => 'author_id', |
||
| 203 | 'referencedColumnName' => 'id', |
||
| 204 | ], |
||
| 205 | ], |
||
| 206 | 'orphanRemoval' => false, |
||
| 207 | ]); |
||
| 208 | |||
| 209 | $collector->addAssociation($config['class']['post'], 'mapManyToOne', [ |
||
| 210 | 'fieldName' => 'collection', |
||
| 211 | 'targetEntity' => $config['class']['collection'], |
||
| 212 | 'cascade' => [ |
||
| 213 | 1 => 'persist', |
||
| 214 | ], |
||
| 215 | 'mappedBy' => null, |
||
| 216 | 'inversedBy' => null, |
||
| 217 | 'joinColumns' => [ |
||
| 218 | [ |
||
| 219 | 'name' => 'collection_id', |
||
| 220 | 'referencedColumnName' => 'id', |
||
| 221 | ], |
||
| 222 | ], |
||
| 223 | 'orphanRemoval' => false, |
||
| 224 | ]); |
||
| 225 | |||
| 226 | $collector->addAssociation($config['class']['post'], 'mapManyToMany', [ |
||
| 227 | 'fieldName' => 'tags', |
||
| 228 | 'targetEntity' => $config['class']['tag'], |
||
| 229 | 'cascade' => [ |
||
| 230 | 1 => 'persist', |
||
| 231 | ], |
||
| 232 | 'joinTable' => [ |
||
| 233 | 'name' => $config['table']['post_tag'], |
||
| 234 | 'joinColumns' => [ |
||
| 235 | [ |
||
| 236 | 'name' => 'post_id', |
||
| 237 | 'referencedColumnName' => 'id', |
||
| 238 | ], |
||
| 239 | ], |
||
| 240 | 'inverseJoinColumns' => [ |
||
| 241 | [ |
||
| 242 | 'name' => 'tag_id', |
||
| 243 | 'referencedColumnName' => 'id', |
||
| 244 | ], |
||
| 245 | ], |
||
| 246 | ], |
||
| 247 | ]); |
||
| 248 | |||
| 249 | $collector->addAssociation($config['class']['comment'], 'mapManyToOne', [ |
||
| 250 | 'fieldName' => 'post', |
||
| 251 | 'targetEntity' => $config['class']['post'], |
||
| 252 | 'cascade' => [ |
||
| 253 | ], |
||
| 254 | 'mappedBy' => null, |
||
| 255 | 'inversedBy' => 'comments', |
||
| 256 | 'joinColumns' => [ |
||
| 257 | [ |
||
| 258 | 'name' => 'post_id', |
||
| 259 | 'referencedColumnName' => 'id', |
||
| 260 | 'nullable' => false, |
||
| 261 | ], |
||
| 262 | ], |
||
| 263 | 'orphanRemoval' => false, |
||
| 264 | ]); |
||
| 265 | } |
||
| 266 | |||
| 277 |
If you suppress an error, we recommend checking for the error condition explicitly: