Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 42 |
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 |
||
96 | public function testNavAndForm(): void |
||
97 | { |
||
98 | NavBar::counter(0); |
||
99 | |||
100 | $html = NavBar::begin() |
||
101 | ->brandLabel('My Company') |
||
102 | ->brandUrl('/') |
||
103 | ->start(); |
||
104 | |||
105 | $html .= Nav::widget() |
||
106 | ->items([ |
||
107 | ['label' => 'Home', 'url' => '#'], |
||
108 | ['label' => 'Link', 'url' => '#'], |
||
109 | ['label' => 'Dropdown', 'items' => [ |
||
110 | ['label' => 'Action', 'url' => '#'], |
||
111 | ['label' => 'Another action', 'url' => '#'], |
||
112 | '-', |
||
113 | ['label' => 'Something else here', 'url' => '#'], |
||
114 | ] |
||
115 | ] |
||
116 | ]) |
||
117 | ->options(['class' => ['mr-auto']]) |
||
118 | ->render(); |
||
119 | |||
120 | $html .= <<<HTML |
||
121 | <form class="form-inline my-2 my-lg-0"> |
||
122 | <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"> |
||
123 | <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> |
||
124 | </form> |
||
125 | HTML; |
||
126 | |||
127 | $html .= NavBar::end(); |
||
128 | |||
129 | $expected = <<<EXPECTED |
||
130 | <nav id="w0-navbar" class="navbar navbar-expand-lg navbar-light bg-light"> |
||
131 | <div class="container"> |
||
132 | <a class="navbar-brand" href="/">My Company</a> |
||
133 | <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#w0-collapse" aria-controls="w0-collapse" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button> |
||
134 | <div id="w0-collapse" class="collapse navbar-collapse"> |
||
135 | <ul id="w1-nav" class="mr-auto nav"><li class="nav-item"><a class="nav-link" href="#">Home</a></li> |
||
136 | <li class="nav-item"><a class="nav-link" href="#">Link</a></li> |
||
137 | <li class="dropdown nav-item"><a class="dropdown-toggle nav-link" href="#" data-toggle="dropdown">Dropdown</a><div id="w2-dropdown" class="dropdown-menu"><a class="dropdown-item" href="#">Action</a> |
||
138 | <a class="dropdown-item" href="#">Another action</a> |
||
139 | <div class="dropdown-divider"></div> |
||
140 | <a class="dropdown-item" href="#">Something else here</a></div></li></ul><form class="form-inline my-2 my-lg-0"> |
||
141 | <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"> |
||
142 | <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> |
||
143 | </form></div> |
||
144 | </div> |
||
145 | </nav> |
||
146 | EXPECTED; |
||
147 | |||
148 | $this->assertEqualsWithoutLE($expected, $html); |
||
149 | } |
||
151 |