Conditions | 6 |
Paths | 4 |
Total Lines | 71 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
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 |
||
28 | public function saveAssociations( |
||
29 | EntityManagerInterface $entityManager, |
||
30 | string $entityName, |
||
31 | EntityInterface $entity, |
||
32 | array $saveOptions = [], |
||
33 | array $saveCollectionOptions = [] |
||
34 | ): void { |
||
35 | $saveOptions = array_replace_recursive($this->options, $saveOptions); |
||
36 | $saveCollectionOptions = array_replace_recursive($this->collectionOptions, $saveCollectionOptions); |
||
37 | |||
38 | $classMetadata = $this->getClassMetadata($entityManager, $entityName); |
||
39 | $mappings = $classMetadata->getAssociationMappings(); |
||
40 | |||
41 | $this->logger->info( |
||
42 | sprintf('Processing cascade save operations for for entity class \'%s\'', $entityName) |
||
43 | ); |
||
44 | |||
45 | foreach ($mappings as $mapping) { |
||
46 | if ( |
||
47 | !isset( |
||
48 | $mapping['targetEntity'], |
||
49 | $mapping['fieldName'], |
||
50 | $mapping['type'], |
||
51 | $mapping['isCascadePersist'] |
||
52 | ) |
||
53 | || true !== $mapping['isCascadePersist'] |
||
54 | ) { |
||
55 | // We only want to save associations that are configured to cascade persist |
||
56 | continue; |
||
57 | } |
||
58 | |||
59 | $this->logger->info( |
||
60 | sprintf( |
||
61 | 'The entity field \'%s::%s\' is configured for cascade operations for target entity \'%s\'', |
||
62 | $entityName, |
||
63 | $mapping['fieldName'], |
||
64 | $mapping['targetEntity'] |
||
65 | ) |
||
66 | ); |
||
67 | |||
68 | $targetEntityOrCollection = $this->resolveTargetEntityOrCollection( |
||
69 | $entity, |
||
70 | $mapping['fieldName'], |
||
71 | $classMetadata, |
||
72 | $this->getClassMetadata($entityManager, $mapping['targetEntity']) |
||
73 | ); |
||
74 | |||
75 | if (!$this->isValidAssociation($targetEntityOrCollection, $mapping)) { |
||
76 | $this->logger->info( |
||
77 | sprintf( |
||
78 | 'The entity field \'%s::%s\' value could not be resolved', |
||
79 | $entityName, |
||
80 | $mapping['fieldName'] |
||
81 | ) |
||
82 | ); |
||
83 | continue; |
||
84 | } |
||
85 | |||
86 | $this->logger->info( |
||
87 | sprintf( |
||
88 | 'Performing cascading save operations for field \'%s::%s\'', |
||
89 | $entityName, |
||
90 | $mapping['fieldName'] |
||
91 | ) |
||
92 | ); |
||
93 | |||
94 | $this->saveAssociation( |
||
95 | $entityManager, |
||
96 | $mapping['targetEntity'], |
||
97 | $targetEntityOrCollection, |
||
98 | (is_iterable($targetEntityOrCollection) ? $saveCollectionOptions : $saveOptions) |
||
99 | ); |
||
135 |