| Conditions | 4 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 36 |
| 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 |
||
| 27 | public function testRetrievingCacheShouldNotThrowUndefinedIndexException() |
||
| 28 | { |
||
| 29 | for ($i = 1; $i < 3; $i++) { |
||
| 30 | $user = new GH6217User(); |
||
| 31 | $user->id = $i; |
||
| 32 | $user->username = "user$i"; |
||
| 33 | $profile = new GH6217Profile(); |
||
| 34 | $profile->id = $i; |
||
| 35 | $category = new GH6217Category(); |
||
| 36 | $category->id = $i; |
||
| 37 | $category->title = "category$i"; |
||
| 38 | $this->_em->persist($user); |
||
| 39 | $this->_em->persist($profile); |
||
| 40 | $this->_em->persist($category); |
||
| 41 | $this->_em->flush(); |
||
| 42 | } |
||
| 43 | for ($i = 1; $i < 3; $i++) { |
||
| 44 | $category = $this->_em->getRepository(GH6217Category::class)->find($i); |
||
| 45 | $user = $this->_em->getRepository(GH6217User::class)->find($i); |
||
| 46 | for ($x = 1; $x < 3; $x++) { |
||
| 47 | $profile = $this->_em->getRepository(GH6217Profile::class)->find($x); |
||
| 48 | $userProfile = new GH6217UserProfile(); |
||
| 49 | $userProfile->profile = $profile; |
||
| 50 | $userProfile->category = $category; |
||
| 51 | $userProfile->user = $user; |
||
| 52 | $this->_em->persist($userProfile); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | $this->_em->flush(); |
||
| 56 | $this->_em->clear(); |
||
| 57 | |||
| 58 | $id = 2; |
||
| 59 | /** @var GH6217UserProfile[] $userProfiles */ |
||
| 60 | $userProfiles = $this->_em->getRepository(GH6217UserProfile::class)->findBy( |
||
| 61 | [ |
||
| 62 | 'user' => $id, |
||
| 63 | 'category' => $id, |
||
| 64 | ] |
||
| 65 | ); |
||
| 66 | $queryCount = $this->getCurrentQueryCount(); |
||
| 67 | $this->_em->clear(); |
||
| 68 | |||
| 69 | $this->_em->getRepository(GH6217UserProfile::class)->findBy( |
||
| 70 | [ |
||
| 71 | 'user' => $id, |
||
| 72 | 'category' => $id, |
||
| 73 | ] |
||
| 74 | ); |
||
| 75 | $this->assertEquals($queryCount, $this->getCurrentQueryCount()); |
||
| 76 | |||
| 77 | } |
||
| 78 | } |
||
| 195 |