| Conditions | 1 |
| Paths | 1 |
| Total Lines | 70 |
| Code Lines | 41 |
| 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 |
||
| 55 | public function testItem() |
||
| 56 | { |
||
| 57 | $authorItem = new ApplicationItem( |
||
| 58 | Microformats::FORMAT, |
||
| 59 | (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-card'], |
||
| 60 | [ |
||
| 61 | (object)[ |
||
| 62 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 63 | 'name' => 'p-name', |
||
| 64 | 'values' => [ |
||
| 65 | new StringValue('John Doe') |
||
| 66 | ] |
||
| 67 | ], |
||
| 68 | (object)[ |
||
| 69 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 70 | 'name' => 'u-email', |
||
| 71 | 'values' => [ |
||
| 72 | new StringValue('[email protected]') |
||
| 73 | ] |
||
| 74 | ] |
||
| 75 | ] |
||
| 76 | ); |
||
| 77 | |||
| 78 | |||
| 79 | $entryItem = new ApplicationItem( |
||
| 80 | Microformats::FORMAT, |
||
| 81 | (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-entry'], |
||
| 82 | [ |
||
| 83 | (object)[ |
||
| 84 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 85 | 'name' => 'p-name', |
||
| 86 | 'values' => [ |
||
| 87 | new StringValue('Famous blog post') |
||
| 88 | ] |
||
| 89 | ], |
||
| 90 | (object)[ |
||
| 91 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 92 | 'name' => 'p-author', |
||
| 93 | 'values' => [ |
||
| 94 | $authorItem |
||
| 95 | ] |
||
| 96 | ] |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | |||
| 100 | |||
| 101 | $feedItem = new ApplicationItem( |
||
|
|
|||
| 102 | Microformats::FORMAT, |
||
| 103 | (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-feed'], |
||
| 104 | [ |
||
| 105 | (object)[ |
||
| 106 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 107 | 'name' => 'p-name', |
||
| 108 | 'values' => [ |
||
| 109 | new StringValue('John Doe\'s Blog') |
||
| 110 | ] |
||
| 111 | ], |
||
| 112 | (object)[ |
||
| 113 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 114 | 'name' => 'p-author', |
||
| 115 | 'values' => [ |
||
| 116 | $authorItem |
||
| 117 | ] |
||
| 118 | ] |
||
| 119 | ], |
||
| 120 | [$entryItem, $entryItem] |
||
| 121 | ); |
||
| 122 | |||
| 123 | // print_r($feedItem); |
||
| 124 | } |
||
| 125 | } |
||
| 126 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.