| Conditions | 1 |
| Paths | 1 |
| Total Lines | 91 |
| Code Lines | 66 |
| 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 |
||
| 100 | public function testGetDefaultOptions() |
||
| 101 | { |
||
| 102 | $options = array ( |
||
| 103 | 'base' => array(), |
||
| 104 | 'lang' => array( |
||
| 105 | 'default' => 'en', |
||
| 106 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 107 | 'options' => array('regexp'=>'/^[a-z]{2}$/') |
||
| 108 | ), |
||
| 109 | ); |
||
| 110 | |||
| 111 | $expectedOptions =array ( |
||
| 112 | 'base' => array(), |
||
| 113 | 'uri' => array( |
||
| 114 | 'filter' => FILTER_SANITIZE_URL, |
||
| 115 | ), |
||
| 116 | 'lang' => array( |
||
| 117 | 'default' => 'en', |
||
| 118 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 119 | 'options' => array('regexp'=>'/^[a-z]{2}$/') |
||
| 120 | ), |
||
| 121 | 'id' => array( |
||
| 122 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 123 | 'options' => array('regexp'=>'/^[\w]+$/') |
||
| 124 | ), |
||
| 125 | 'taxID' => array( |
||
| 126 | 'filter' => FILTER_CALLBACK, |
||
| 127 | 'options' => '\BOTK\Filters::normalizeToken' |
||
| 128 | ), |
||
| 129 | 'vatID' => array( // italian rules |
||
| 130 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 131 | 'options' => array('regexp'=>'/^[0-9]{11}$/') |
||
| 132 | ), |
||
| 133 | 'legalName' => array( |
||
| 134 | 'filter' => FILTER_CALLBACK, |
||
| 135 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
| 136 | ), |
||
| 137 | 'alternateName' => array(), |
||
| 138 | 'addressCountry' => array( |
||
| 139 | 'default' => 'IT', |
||
| 140 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 141 | 'options' => array('regexp'=>'/^[A-Z]{2}$/') |
||
| 142 | ), |
||
| 143 | 'addressLocality' => array( |
||
| 144 | 'filter' => FILTER_CALLBACK, |
||
| 145 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
| 146 | ), |
||
| 147 | 'addressRegion' => array( |
||
| 148 | 'filter' => FILTER_CALLBACK, |
||
| 149 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
| 150 | ), |
||
| 151 | 'streetAddress' => array( |
||
| 152 | 'filter' => FILTER_CALLBACK, |
||
| 153 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
| 154 | ), |
||
| 155 | 'postalCode' => array( // italian rules |
||
| 156 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 157 | 'options' => array('regexp'=>'/^[0-9]{5}$/') |
||
| 158 | ), |
||
| 159 | 'page' => array( |
||
| 160 | 'filter' => FILTER_SANITIZE_URL |
||
| 161 | ), |
||
| 162 | 'telephone' => array( |
||
| 163 | 'filter' => FILTER_CALLBACK, |
||
| 164 | 'options' => '\BOTK\Filters::normalizeItTelephone' |
||
| 165 | ), |
||
| 166 | 'faxNumber' => array( |
||
| 167 | 'filter' => FILTER_CALLBACK, |
||
| 168 | 'options' => '\BOTK\Filters::normalizeItTelephone' |
||
| 169 | ), |
||
| 170 | 'email' => array( |
||
| 171 | 'filter' => FILTER_CALLBACK, |
||
| 172 | 'options' => '\BOTK\Filters::normalizeEmail' |
||
| 173 | ), |
||
| 174 | 'geoDescription' => array( |
||
| 175 | 'filter' => FILTER_CALLBACK, |
||
| 176 | 'options' => '\BOTK\Filters::normalizeAddress' |
||
| 177 | ), |
||
| 178 | 'lat' => array( // http://www.regexlib.com/REDetails.aspx?regexp_id=2728 |
||
| 179 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 180 | 'options' => array('regexp'=>'/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/') |
||
| 181 | ), |
||
| 182 | 'long' => array( // http://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates |
||
| 183 | 'filter' => FILTER_VALIDATE_REGEXP, |
||
| 184 | 'options' => array('regexp'=>'/-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/') |
||
| 185 | ), |
||
| 186 | ); |
||
| 187 | |||
| 188 | $localBusiness = new BOTK\Model\LocalBusiness(array(),$options); |
||
| 189 | $this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
||
| 190 | } |
||
| 191 | |||
| 246 |
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.