Conditions | 6 |
Paths | 7 |
Total Lines | 53 |
Code Lines | 33 |
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 |
||
39 | public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void |
||
40 | { |
||
41 | /** @var ClassMetadataInfo $mediaObjectClassMetadata */ |
||
42 | $mediaObjectClassMetadata = $eventArgs->getClassMetadata(); |
||
43 | if (!$this->mediaObjectHelper->isConfigured($mediaObjectClassMetadata->getName())) { |
||
44 | return; |
||
45 | } |
||
46 | |||
47 | $mediaObjectConfiguration = $this->mediaObjectHelper->getConfiguration($mediaObjectClassMetadata->getName()); |
||
48 | if (!$this->uploadsHelper->isConfigured($mediaObjectConfiguration->uploadsEntityClass)) { |
||
49 | throw new OutOfBoundsException('The value of uploadsEntityClass on your MediaObject is not configured as an Uploads resource'); |
||
50 | } |
||
51 | |||
52 | $uploadsConfiguration = $this->uploadsHelper->getConfiguration($mediaObjectConfiguration->uploadsEntityClass); |
||
53 | |||
54 | $em = $eventArgs->getObjectManager(); |
||
55 | if (!$em instanceof EntityManagerInterface) { |
||
56 | return; |
||
57 | } |
||
58 | /** @var ClassMetadataInfo $mediaObjectClassMetadata */ |
||
59 | $uploadsClassMetadata = $em->getClassMetadata($mediaObjectConfiguration->uploadsEntityClass); |
||
60 | $namingStrategy = $em->getConfiguration()->getNamingStrategy(); |
||
61 | |||
62 | if (!$mediaObjectClassMetadata->hasAssociation($mediaObjectConfiguration->uploadsEntityClass)) { |
||
63 | $mediaObjectClassMetadata->mapField([ |
||
64 | 'fieldName' => $mediaObjectConfiguration->filePathFieldName, |
||
65 | 'nullable' => false, |
||
66 | ]); |
||
67 | $mediaObjectClassMetadata->mapField([ |
||
68 | 'fieldName' => $mediaObjectConfiguration->temporaryFieldName, |
||
69 | 'type' => 'boolean', |
||
70 | 'nullable' => false, |
||
71 | ]); |
||
72 | |||
73 | $mediaObjectClassMetadata->mapManyToOne([ |
||
74 | 'fieldName' => $mediaObjectConfiguration->uploadsFieldName, |
||
75 | 'targetEntity' => $mediaObjectConfiguration->uploadsEntityClass, |
||
76 | 'joinColumns' => [ |
||
77 | [ |
||
78 | 'name' => $namingStrategy->joinKeyColumnName($uploadsClassMetadata->getName()), |
||
79 | 'referencedColumnName' => $namingStrategy->referenceColumnName(), |
||
80 | 'onDelete' => 'SET NULL', |
||
81 | ], |
||
82 | ], |
||
83 | 'inversedBy' => $uploadsConfiguration->fieldName, |
||
84 | ]); |
||
85 | } |
||
86 | |||
87 | if (!$mediaObjectClassMetadata->hasAssociation($uploadsConfiguration->fieldName)) { |
||
88 | $mediaObjectClassMetadata->mapOneToMany([ |
||
89 | 'fieldName' => $uploadsConfiguration->fieldName, |
||
90 | 'targetEntity' => $mediaObjectClassMetadata->getName(), |
||
91 | 'mappedBy' => $mediaObjectConfiguration->uploadsEntityClass, |
||
92 | ]); |
||
96 |