| Conditions | 1 |
| Paths | 1 |
| Total Lines | 83 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 190 | public function testComplexDocumentStructure(): void |
||
| 191 | { |
||
| 192 | // Create a complex APL document with multiple components |
||
| 193 | $mainTemplate = new MainTemplate( |
||
| 194 | parameters: ['payload', 'datasource'], |
||
| 195 | items: [] |
||
| 196 | ); |
||
| 197 | |||
| 198 | $document = new APLDocument( |
||
| 199 | mainTemplate: $mainTemplate, |
||
| 200 | type: 'APL', |
||
| 201 | version: '2024.3', |
||
| 202 | description: 'Complex test document', |
||
| 203 | theme: 'dark' |
||
| 204 | ); |
||
| 205 | |||
| 206 | $complexSources = [ |
||
| 207 | 'headlineTemplate' => [ |
||
| 208 | 'type' => 'Link', |
||
| 209 | 'url' => 'doc://alexa/apl/documents/headline', |
||
| 210 | ], |
||
| 211 | 'listTemplate' => [ |
||
| 212 | 'type' => 'Link', |
||
| 213 | 'url' => 'doc://alexa/apl/documents/list', |
||
| 214 | ], |
||
| 215 | ]; |
||
| 216 | |||
| 217 | $complexDatasources = [ |
||
| 218 | 'listData' => [ |
||
| 219 | 'type' => 'dynamicIndexList', |
||
| 220 | 'listId' => 'vQdpOESlok', |
||
| 221 | 'startIndex' => 0, |
||
| 222 | 'minimumInclusiveIndex' => 0, |
||
| 223 | 'maximumExclusiveIndex' => 100, |
||
| 224 | 'items' => [ |
||
| 225 | [ |
||
| 226 | 'primaryText' => 'Item 1', |
||
| 227 | 'secondaryText' => 'Description 1', |
||
| 228 | ], |
||
| 229 | [ |
||
| 230 | 'primaryText' => 'Item 2', |
||
| 231 | 'secondaryText' => 'Description 2', |
||
| 232 | ], |
||
| 233 | ], |
||
| 234 | ], |
||
| 235 | 'headlineData' => [ |
||
| 236 | 'type' => 'object', |
||
| 237 | 'objectId' => 'headline1', |
||
| 238 | 'properties' => [ |
||
| 239 | 'backgroundImage' => [ |
||
| 240 | 'contentDescription' => null, |
||
| 241 | 'smallSourceUrl' => null, |
||
| 242 | 'largeSourceUrl' => null, |
||
| 243 | 'sources' => [ |
||
| 244 | [ |
||
| 245 | 'url' => 'https://example.com/image.jpg', |
||
| 246 | 'size' => 'large', |
||
| 247 | ], |
||
| 248 | ], |
||
| 249 | ], |
||
| 250 | 'title' => 'Welcome to APL', |
||
| 251 | 'subtitle' => 'Alexa Presentation Language', |
||
| 252 | ], |
||
| 253 | ], |
||
| 254 | ]; |
||
| 255 | |||
| 256 | $directive = new RenderDocumentDirective( |
||
| 257 | document: $document, |
||
| 258 | token: 'complex-document-token', |
||
| 259 | sources: $complexSources, |
||
| 260 | datasources: $complexDatasources |
||
| 261 | ); |
||
| 262 | |||
| 263 | $json = $directive->jsonSerialize(); |
||
| 264 | |||
| 265 | $this->assertEquals('complex-document-token', $json['token']); |
||
| 266 | $this->assertArrayHasKey('sources', $json); |
||
| 267 | $this->assertArrayHasKey('datasources', $json); |
||
| 268 | $this->assertCount(2, $json['sources']); |
||
| 269 | $this->assertCount(2, $json['datasources']); |
||
| 270 | $this->assertArrayHasKey('listData', $json['datasources']); |
||
| 271 | $this->assertArrayHasKey('headlineData', $json['datasources']); |
||
| 272 | $this->assertEquals('dynamicIndexList', $json['datasources']['listData']['type']); |
||
| 273 | } |
||
| 275 |