| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 78 |
| 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 |
||
| 106 | public function testGetHostedFieldConfig() |
||
| 107 | { |
||
| 108 | $aHostedConfig = [ |
||
| 109 | "Number_type" => "tel", |
||
| 110 | "Number_count" => "30", |
||
| 111 | "Number_max" => "16", |
||
| 112 | "Number_iframe" => "standard", |
||
| 113 | "Number_style" => "custom", |
||
| 114 | "Number_css" => "", |
||
| 115 | "CVC_type" => "tel", |
||
| 116 | "CVC_count" => "30", |
||
| 117 | "CVC_max" => "4", |
||
| 118 | "CVC_iframe" => "standard", |
||
| 119 | "CVC_style" => "custom", |
||
| 120 | "CVC_css" => "", |
||
| 121 | "Month_type" => "select", |
||
| 122 | "Month_count" => "3", |
||
| 123 | "Month_max" => "2", |
||
| 124 | "Month_iframe" => "custom", |
||
| 125 | "Month_width" => "120px", |
||
| 126 | "Month_height" => "20px", |
||
| 127 | "Month_style" => "standard", |
||
| 128 | "Year_type" => "select", |
||
| 129 | "Year_count" => "5", |
||
| 130 | "Year_max" => "4", |
||
| 131 | "Year_iframe" => "custom", |
||
| 132 | "Year_width" => "120px", |
||
| 133 | "Year_height" => "20px", |
||
| 134 | "Year_style" => "standard", |
||
| 135 | "Standard_input" => "", |
||
| 136 | "Standard_selection" => "width:100px;", |
||
| 137 | "Iframe_width" => "365px", |
||
| 138 | "Iframe_height" => "30px", |
||
| 139 | "Errors_active" => "true", |
||
| 140 | "Errors_lang" => "de" |
||
| 141 | ]; |
||
| 142 | |||
| 143 | $this->scopeConfig->expects($this->any()) |
||
| 144 | ->method('getValue') |
||
| 145 | ->willReturnMap( |
||
| 146 | [ |
||
| 147 | ['payone_general/creditcard/cc_template', ScopeInterface::SCOPE_STORE, null, $this->toolkitHelper->serialize($aHostedConfig)] |
||
| 148 | ] |
||
| 149 | ); |
||
| 150 | $result = $this->hostedIframe->getHostedFieldConfig(); |
||
| 151 | $expected = [ |
||
| 152 | 'fields' => [ |
||
| 153 | 'cardpan' => [ |
||
| 154 | 'selector' => 'cardpan', |
||
| 155 | 'type' => 'tel', |
||
| 156 | 'size' => '30', |
||
| 157 | 'maxlength' => '16', |
||
| 158 | 'style' => '' |
||
| 159 | ], |
||
| 160 | 'cardcvc2' => [ |
||
| 161 | 'selector' => 'cardcvc2', |
||
| 162 | 'type' => 'tel', |
||
| 163 | 'size' => '30', |
||
| 164 | 'maxlength' => '4', |
||
| 165 | 'style' => '' |
||
| 166 | ], |
||
| 167 | 'cardexpiremonth' => [ |
||
| 168 | 'selector' => 'cardexpiremonth', |
||
| 169 | 'type' => 'select', |
||
| 170 | 'size' => '3', |
||
| 171 | 'maxlength' => '2', |
||
| 172 | 'iframe' => [ |
||
| 173 | 'width' => '120px', |
||
| 174 | 'height' => '20px' |
||
| 175 | ] |
||
| 176 | ], |
||
| 177 | 'cardexpireyear' => [ |
||
| 178 | 'selector' => 'cardexpireyear', |
||
| 179 | 'type' => 'select', |
||
| 180 | 'size' => '5', |
||
| 181 | 'maxlength' => '4', |
||
| 182 | 'iframe' => [ |
||
| 183 | 'width' => '120px', |
||
| 184 | 'height' => '20px' |
||
| 185 | ] |
||
| 186 | ] |
||
| 187 | ], |
||
| 188 | 'defaultStyle' => [ |
||
| 189 | 'input' => '', |
||
| 190 | 'select' => 'width:100px;', |
||
| 191 | 'iframe' => [ |
||
| 192 | 'width' => '365px', |
||
| 193 | 'height' => '30px' |
||
| 194 | ] |
||
| 195 | ], |
||
| 196 | 'error' => 'errorOutput', |
||
| 197 | 'language' => 'de' |
||
| 198 | ]; |
||
| 199 | $this->assertEquals($expected, $result); |
||
| 200 | } |
||
| 201 | } |
||
| 202 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: