| Conditions | 1 |
| Paths | 1 |
| Total Lines | 112 |
| Code Lines | 84 |
| 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 |
||
| 98 | public function testGetDefaultOptions() |
||
| 99 | { |
||
| 100 | $expectedOptions = array ( |
||
| 101 | 'base' => array( |
||
| 102 | 'default' => 'http://linkeddata.center/botk/resource/', |
||
| 103 | 'filter' => FILTER_SANITIZE_URL, |
||
| 104 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 105 | ), |
||
| 106 | 'uri' => array( |
||
| 107 | 'filter' => FILTER_SANITIZE_URL, |
||
| 108 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 109 | ), |
||
| 110 | 'lang' => array( |
||
| 111 | 'default' => 'it', |
||
| 112 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 113 | 'options' => array('regexp'=>'/^[a-z]{2}$/'), |
||
| 114 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 115 | ), |
||
| 116 | 'id' => array( |
||
| 117 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 118 | 'options' => array('regexp'=>'/^\w+$/'), |
||
| 119 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 120 | ), |
||
| 121 | 'businessType' => array( |
||
| 122 | // additional types as extension of schema:LocalBusiness |
||
| 123 | 'filter' => FILTER_DEFAULT, |
||
| 124 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 125 | ), |
||
| 126 | 'taxID' => array( |
||
| 127 | 'filter' => FILTER_CALLBACK, |
||
| 128 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
||
| 129 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 130 | ), |
||
| 131 | 'vatID' => array( // italian rules |
||
| 132 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 133 | 'options' => array('regexp'=>'/^[0-9]{11}$/'), |
||
| 134 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 135 | ), |
||
| 136 | 'legalName' => array( |
||
| 137 | 'filter' => FILTER_CALLBACK, |
||
| 138 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
||
| 139 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 140 | ), |
||
| 141 | 'businessName' => array( |
||
| 142 | // a schema:alternateName for schema:PostalAddress |
||
| 143 | 'filter' => FILTER_DEFAULT, |
||
| 144 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 145 | ), |
||
| 146 | 'addressCountry' => array( |
||
| 147 | 'default' => 'IT', |
||
| 148 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 149 | 'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
||
| 150 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 151 | ), |
||
| 152 | 'addressLocality' => array( |
||
| 153 | 'filter' => FILTER_CALLBACK, |
||
| 154 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
||
| 155 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 156 | ), |
||
| 157 | 'addressRegion' => array( |
||
| 158 | 'filter' => FILTER_CALLBACK, |
||
| 159 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
||
| 160 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 161 | ), |
||
| 162 | 'streetAddress' => array( |
||
| 163 | 'filter' => FILTER_CALLBACK, |
||
| 164 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
||
| 165 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 166 | ), |
||
| 167 | 'postalCode' => array( // italian rules |
||
| 168 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 169 | 'options' => array('regexp'=>'/^[0-9]{5}$/'), |
||
| 170 | 'flags' => FILTER_REQUIRE_SCALAR, |
||
| 171 | ), |
||
| 172 | 'page' => array( |
||
| 173 | 'filter' => FILTER_SANITIZE_URL, |
||
| 174 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 175 | ), |
||
| 176 | 'telephone' => array( |
||
| 177 | 'filter' => FILTER_CALLBACK, |
||
| 178 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
||
| 179 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 180 | ), |
||
| 181 | 'faxNumber' => array( |
||
| 182 | 'filter' => FILTER_CALLBACK, |
||
| 183 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
||
| 184 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 185 | ), |
||
| 186 | 'email' => array( |
||
| 187 | 'filter' => FILTER_CALLBACK, |
||
| 188 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
||
| 189 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 190 | ), |
||
| 191 | 'geoDescription' => array( |
||
| 192 | // a schema:alternateName for schema:GeoCoordinates |
||
| 193 | 'filter' => FILTER_CALLBACK, |
||
| 194 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
||
| 195 | 'flags' => FILTER_FORCE_ARRAY, |
||
| 196 | ), |
||
| 197 | 'lat' => array( |
||
| 198 | 'filter' => FILTER_CALLBACK, |
||
| 199 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
||
| 200 | ), |
||
| 201 | 'long' => array( |
||
| 202 | 'filter' => FILTER_CALLBACK, |
||
| 203 | 'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
||
| 204 | ), |
||
| 205 | ); |
||
| 206 | |||
| 207 | $localBusiness = new BOTK\Model\LocalBusiness(array()); |
||
| 208 | $this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
||
| 209 | } |
||
| 210 | |||
| 369 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.