PUnit::run()   F
last analyzed

Complexity

Conditions 17
Paths 500

Size

Total Lines 48
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 48
rs 1.7444
cc 17
nc 500
nop 1

How to fix   Complexity   

Long Method

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:

1
<?php
2
require_once "../core/Logger.php";
3
class PUnit{
4
	function assertEquals($value,$expected,$info = NULL){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5
		if($value != $expected){
6
			throw new Exception($info." expected ".$expected." but ".$value);
7
		}
8
	}
9
	function run($torun = NULL){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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;
0 ignored issues
show
Unused Code introduced by
The assignment to $after is dead and can be removed.
Loading history...
23
        foreach ($methods as $method) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $methods seems to be defined by a foreach iteration on line 11. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
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
58
	}
59
}
60
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...