| Conditions | 17 |
| Paths | 500 |
| Total Lines | 48 |
| Code Lines | 38 |
| 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 |
||
| 9 | function run($torun = NULL){ |
||
| 10 | $r = new ReflectionClass($this); |
||
| 11 | foreach($r->getMethods() as $key=>$methodObj){ |
||
| 12 | if($methodObj->isPrivate()) |
||
| 13 | $methods[$key]['type'] = 'private'; |
||
| 14 | elseif($methodObj->isProtected()) |
||
| 15 | $methods[$key]['type'] = 'protected'; |
||
| 16 | else |
||
| 17 | $methods[$key]['type'] = 'public'; |
||
| 18 | $methods[$key]['name'] = $methodObj->name; |
||
| 19 | $methods[$key]['class'] = $methodObj->class; |
||
| 20 | } |
||
| 21 | $before = NULL; |
||
| 22 | $after = NULL; |
||
| 23 | foreach ($methods as $method) { |
||
| 24 | if($method["class"] != "PUnit"&&$method["name"] == "before"){ |
||
| 25 | $before = $method; |
||
| 26 | } |
||
| 27 | if($method["class"] != "PUnit"&&$method["name"] == "after"){ |
||
| 28 | $after = $method; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | $error = array(); |
||
| 32 | $success = array(); |
||
| 33 | foreach ($methods as $method) { |
||
| 34 | if($method["class"] != "PUnit"&&substr($method["name"],0,4) == "test"){ |
||
| 35 | if($torun !== NULL){ |
||
| 36 | if(!in_array($method["name"],$torun)) |
||
| 37 | continue; |
||
| 38 | } |
||
| 39 | try{ |
||
| 40 | if($method["type"] == "public"){ |
||
| 41 | $log = new Logger(); |
||
| 42 | $log->info("Run unit --->".$method["name"]); |
||
| 43 | if($before!=NULL) |
||
| 44 | $this->$before["name"](); |
||
| 45 | $this->$method["name"](); |
||
| 46 | array_push($success,$method["name"]); |
||
| 47 | } |
||
| 48 | }catch(Exception $e){ |
||
| 49 | $error[$method["name"]]="".$e; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | echo "\r\nPHP Unit-----------error"."\r\n"; |
||
| 54 | print_r($error); |
||
| 55 | echo "PHP Unit-----------result"."\r\n"; |
||
| 56 | echo "total:".(count($success)+count($error)).",success:".count($success).",error:".count($error)."\r\n"; |
||
| 57 | |||
| 60 | ?> |
||
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.