| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Code Lines | 54 |
| 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 |
||
| 73 | public function newEntitiesFoundThroughRelationshipsErrorMessages() : array |
||
| 74 | { |
||
| 75 | $stringEntity3 = uniqid('entity3', true); |
||
| 76 | $entity1 = new \stdClass(); |
||
| 77 | $entity2 = new \stdClass(); |
||
| 78 | $entity3 = $this->getMockBuilder(\stdClass::class)->setMethods(['__toString'])->getMock(); |
||
| 79 | $association1 = [ |
||
| 80 | 'sourceEntity' => 'foo1', |
||
| 81 | 'fieldName' => 'bar1', |
||
| 82 | 'targetEntity' => 'baz1', |
||
| 83 | ]; |
||
| 84 | $association2 = [ |
||
| 85 | 'sourceEntity' => 'foo2', |
||
| 86 | 'fieldName' => 'bar2', |
||
| 87 | 'targetEntity' => 'baz2', |
||
| 88 | ]; |
||
| 89 | $association3 = [ |
||
| 90 | 'sourceEntity' => 'foo3', |
||
| 91 | 'fieldName' => 'bar3', |
||
| 92 | 'targetEntity' => 'baz3', |
||
| 93 | ]; |
||
| 94 | |||
| 95 | $entity3->expects(self::any())->method('__toString')->willReturn($stringEntity3); |
||
| 96 | |||
| 97 | return [ |
||
| 98 | 'one entity found' => [ |
||
| 99 | [ |
||
| 100 | [ |
||
| 101 | $association1, |
||
| 102 | $entity1, |
||
| 103 | ], |
||
| 104 | ], |
||
| 105 | 'A new entity was found through the relationship \'foo1#bar1\' that was not configured to cascade ' |
||
| 106 | . 'persist operations for entity: stdClass@' . spl_object_hash($entity1) |
||
| 107 | . '. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity ' |
||
| 108 | . 'or configure cascade persist this association in the mapping for example ' |
||
| 109 | . '@ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem ' |
||
| 110 | . 'implement \'baz1#__toString()\' to get a clue.', |
||
| 111 | ], |
||
| 112 | 'two entities found' => [ |
||
| 113 | [ |
||
| 114 | [ |
||
| 115 | $association1, |
||
| 116 | $entity1, |
||
| 117 | ], |
||
| 118 | [ |
||
| 119 | $association2, |
||
| 120 | $entity2, |
||
| 121 | ], |
||
| 122 | ], |
||
| 123 | 'Multiple non-persisted new entities were found through the given association graph:' . "\n\n" |
||
| 124 | . ' * A new entity was found through the relationship \'foo1#bar1\' that was not configured to ' |
||
| 125 | . 'cascade persist operations for entity: stdClass@' . spl_object_hash($entity1) . '. ' |
||
| 126 | . 'To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity ' |
||
| 127 | . 'or configure cascade persist this association in the mapping for example ' |
||
| 128 | . '@ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem ' |
||
| 129 | . 'implement \'baz1#__toString()\' to get a clue.' . "\n" |
||
| 130 | . ' * A new entity was found through the relationship \'foo2#bar2\' that was not configured to ' |
||
| 131 | . 'cascade persist operations for entity: stdClass@' . spl_object_hash($entity2) . '. To solve ' |
||
| 132 | . 'this issue: Either explicitly call EntityManager#persist() on this unknown entity or ' |
||
| 133 | . 'configure cascade persist this association in the mapping for example ' |
||
| 134 | . '@ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem ' |
||
| 135 | . 'implement \'baz2#__toString()\' to get a clue.' |
||
| 136 | ], |
||
| 137 | 'two entities found, one is stringable' => [ |
||
| 138 | [ |
||
| 139 | [ |
||
| 140 | $association3, |
||
| 141 | $entity3, |
||
| 142 | ], |
||
| 143 | ], |
||
| 144 | 'A new entity was found through the relationship \'foo3#bar3\' that was not configured to cascade ' |
||
| 145 | . 'persist operations for entity: ' . $stringEntity3 |
||
| 146 | . '. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity ' |
||
| 147 | . 'or configure cascade persist this association in the mapping for example ' |
||
| 148 | . '@ManyToOne(..,cascade={"persist"}).', |
||
| 149 | ], |
||
| 150 | ]; |
||
| 151 | } |
||
| 152 | } |
||
| 153 |