Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
31 | public function renderWithStdWrap(): void |
||
32 | { |
||
33 | $view = new StandaloneView(); |
||
34 | $view->assign( |
||
35 | 'metadataWrap', |
||
36 | [ |
||
37 | 'key' => ['wrap' => '<label>|</label>'], |
||
38 | 'value' => ['required' => 1, 'wrap' => '<li>|</li>'], |
||
39 | 'all' => ['wrap' => '<article class="shlb-metadata-text-item metadata-title">|</article>'] |
||
40 | ] |
||
41 | ); |
||
42 | |||
43 | // A fully filled array with correct values does not make any difference. The rendering result |
||
44 | // is not been influenced by the viewhelpers data parameter. |
||
45 | $view->assign('metaSectionCObj', [0 => ['tilte' => 'A test title']]); |
||
46 | |||
47 | $view->setTemplateSource( |
||
48 | '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> |
||
49 | <kitodo:stdWrap wrap="{metadataWrap.all}" data="{metaConfigObjectData.0}"> |
||
50 | <kitodo:stdWrap wrap="{metadataWrap.key}" data="{metaConfigObjectData.0}">Label</kitodo:stdWrap> |
||
51 | <h2>Title</h2><p>Text</p> |
||
52 | </kitodo:stdWrap> |
||
53 | </html>' |
||
54 | ); |
||
55 | |||
56 | self::assertXmlStringEqualsXmlString( |
||
57 | '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> |
||
58 | <article class="shlb-metadata-text-item metadata-title"> |
||
59 | <label>Label</label> |
||
60 | <h2>Title</h2><p>Text</p> |
||
61 | </article> |
||
62 | </html>', |
||
63 | $view->render() |
||
64 | ); |
||
65 | |||
66 | // Without using the data parameter the rendering result is the same as above. |
||
67 | $view->setTemplateSource( |
||
68 | '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> |
||
69 | <kitodo:stdWrap wrap="{metadataWrap.all}"> |
||
70 | <kitodo:stdWrap wrap="{metadataWrap.key}">Label</kitodo:stdWrap> |
||
71 | <h2>Title</h2><p>Text</p> |
||
72 | </kitodo:stdWrap> |
||
73 | </html>' |
||
74 | ); |
||
75 | |||
76 | self::assertXmlStringEqualsXmlString( |
||
77 | '<html xmlns:kitodo="http://typo3.org/ns/Kitodo/Dlf/ViewHelpers"> |
||
78 | <article class="shlb-metadata-text-item metadata-title"> |
||
79 | <label>Label</label> |
||
80 | <h2>Title</h2><p>Text</p> |
||
81 | </article> |
||
82 | </html>', |
||
83 | $view->render() |
||
84 | ); |
||
87 |