Conditions | 9 |
Paths | 5 |
Total Lines | 58 |
Code Lines | 29 |
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 |
||
89 | public function loadAssociatedUninitializedCollectionsAndProxies( |
||
90 | array $entities, |
||
91 | AssociationMetadataWrapper $associationMetadataWrapper |
||
92 | ) { |
||
93 | // If we have to-one association and we are on the owning side |
||
94 | // we can collect uninitialized proxies and bulk load them. |
||
95 | if ( |
||
96 | $associationMetadataWrapper->isManyToOne() |
||
97 | || ( |
||
98 | $associationMetadataWrapper->isOneToOne() |
||
99 | && $associationMetadataWrapper->isOwningSide() |
||
100 | ) |
||
101 | ) { |
||
102 | $associatedEntities = $this->associationCollectingStrategy->collect( |
||
103 | $entities, |
||
104 | $associationMetadataWrapper->getName() |
||
105 | ); |
||
106 | $this->loadUninitializedProxies( |
||
107 | $associatedEntities, |
||
108 | $associationMetadataWrapper->getTargetClassMetadataWrapper() |
||
109 | ); |
||
110 | |||
111 | return; |
||
112 | } |
||
113 | |||
114 | // Otherwise we have some objects with uninitialized persistent collections. |
||
115 | if ( |
||
116 | $associationMetadataWrapper->isOneToMany() |
||
117 | || $associationMetadataWrapper->isManyToMany() |
||
118 | ) { |
||
119 | $associatedCollections = $this->associationCollectingStrategy->collect( |
||
120 | $entities, |
||
121 | $associationMetadataWrapper->getName() |
||
122 | ); |
||
123 | $uninitializedSourceEntities = $this->getUninitializedCollectionOwnerEntities($associatedCollections); |
||
124 | |||
125 | foreach ($this->splitIntoChunks($uninitializedSourceEntities) as $uninitializedSourceEntitiesChunk) { |
||
126 | $this->nonProxiedAssociationQueryExecutor->execute( |
||
127 | $uninitializedSourceEntitiesChunk, |
||
128 | $associationMetadataWrapper |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | return; |
||
133 | } |
||
134 | |||
135 | // Or we have one-to-one association with source being the inverse side. |
||
136 | if ( |
||
137 | $associationMetadataWrapper->isOneToOne() |
||
138 | && $associationMetadataWrapper->isInverseSide() |
||
139 | ) { |
||
140 | // We don't have to do anything as these objects are automatically loaded by Doctrine with separate queries |
||
141 | // and there's no way to optimize this. |
||
142 | |||
143 | return; |
||
144 | } |
||
145 | |||
146 | throw new \Exception('Association not handled.'); |
||
147 | } |
||
200 |