| Conditions | 1 |
| Paths | 1 |
| Total Lines | 87 |
| 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 |
||
| 92 | public function testMenuTree() { |
||
| 93 | |||
| 94 | $result = $this->executeQueryFile('menu.gql'); |
||
| 95 | |||
| 96 | $this->assertArrayHasKey('data', $result); |
||
| 97 | |||
| 98 | $this->assertArraySubset([ |
||
| 99 | 'menu' => [ |
||
| 100 | 'links' => [ |
||
| 101 | 0 => [ |
||
| 102 | 'label' => 'Accessible', |
||
| 103 | 'route' => [ |
||
| 104 | 'path' => '/graphql/test/accessible', |
||
| 105 | 'routed' => TRUE, |
||
| 106 | ], |
||
| 107 | ], |
||
| 108 | ], |
||
| 109 | ], |
||
| 110 | ], $result['data'], 'Accessible root item is returned.'); |
||
| 111 | |||
| 112 | $this->assertArraySubset([ |
||
| 113 | 'menu' => [ |
||
| 114 | 'links' => [ |
||
| 115 | 0 => [ |
||
| 116 | 'links' => [ |
||
| 117 | 0 => [ |
||
| 118 | 'label' => 'Nested A', |
||
| 119 | 'route' => [ |
||
| 120 | 'path' => '/graphql/test/accessible', |
||
| 121 | 'routed' => TRUE, |
||
| 122 | ], |
||
| 123 | ], |
||
| 124 | ], |
||
| 125 | ], |
||
| 126 | ], |
||
| 127 | ], |
||
| 128 | ], $result['data'], 'Accessible nested item A is returned.'); |
||
| 129 | |||
| 130 | $this->assertArraySubset([ |
||
| 131 | 'menu' => [ |
||
| 132 | 'links' => [ |
||
| 133 | 0 => [ |
||
| 134 | 'links' => [ |
||
| 135 | 1 => [ |
||
| 136 | 'label' => 'Nested B', |
||
| 137 | 'route' => [ |
||
| 138 | 'path' => '/graphql/test/accessible', |
||
| 139 | 'routed' => TRUE, |
||
| 140 | ], |
||
| 141 | ], |
||
| 142 | ], |
||
| 143 | ], |
||
| 144 | ], |
||
| 145 | ], |
||
| 146 | ], $result['data'], 'Accessible nested item B is returned.'); |
||
| 147 | |||
| 148 | $this->assertArraySubset([ |
||
| 149 | 'menu' => [ |
||
| 150 | 'links' => [ |
||
| 151 | 1 => [ |
||
| 152 | 'label' => 'Inaccessible', |
||
| 153 | 'route' => [ |
||
| 154 | 'path' => '/', |
||
| 155 | 'routed' => TRUE, |
||
| 156 | ], |
||
| 157 | ], |
||
| 158 | ], |
||
| 159 | ], |
||
| 160 | ], $result['data'], 'Inaccessible root item is obfuscated.'); |
||
| 161 | |||
| 162 | $inaccessibleChildren = $result['data']['menu']['links'][1]['links']; |
||
| 163 | $this->assertEmpty($inaccessibleChildren, 'Inaccessible items do not expose children.'); |
||
| 164 | |||
| 165 | $this->assertArraySubset([ |
||
| 166 | 'menu' => [ |
||
| 167 | 'links' => [ |
||
| 168 | 2 => [ |
||
| 169 | 'label' => 'Drupal', |
||
| 170 | 'route' => [ |
||
| 171 | 'path' => 'http://www.drupal.org', |
||
| 172 | 'routed' => FALSE, |
||
| 173 | ], |
||
| 174 | ], |
||
| 175 | ], |
||
| 176 | ], |
||
| 177 | ], $result['data'], 'External menu link is included properly.'); |
||
| 178 | } |
||
| 179 | |||
| 181 |