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