Passed
Push — master ( 16044f...5a8824 )
by Robert
05:31
created
src/Commands/LiveEngageTestCoverage.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -10,124 +10,124 @@
 block discarded – undo
10 10
  */
11 11
 class LiveEngageTestCoverage extends Command
12 12
 {
13
-    /**
14
-     * The name and signature of the console command.
15
-     *
16
-     * @var string
17
-     */
18
-    protected $signature = 'liveperson:le:coverage {--lines}';
13
+	/**
14
+	 * The name and signature of the console command.
15
+	 *
16
+	 * @var string
17
+	 */
18
+	protected $signature = 'liveperson:le:coverage {--lines}';
19 19
 
20
-    /**
21
-     * The console command description.
22
-     *
23
-     * @var string
24
-     */
25
-    protected $description = 'Reports the test coverage of this package';
20
+	/**
21
+	 * The console command description.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	protected $description = 'Reports the test coverage of this package';
26 26
 
27
-    /**
28
-     * Create a new command instance.
29
-     *
30
-     * @return void
31
-     */
32
-    public function __construct()
33
-    {
34
-        parent::__construct();
35
-    }
27
+	/**
28
+	 * Create a new command instance.
29
+	 *
30
+	 * @return void
31
+	 */
32
+	public function __construct()
33
+	{
34
+		parent::__construct();
35
+	}
36 36
 
37
-    /**
38
-     * Execute the console command.
39
-     *
40
-     * @return mixed
41
-     */
42
-    public function handle()
43
-    {
44
-	    $path = __DIR__ . "/../../tests/coverage.xml";
45
-	    if (!file_exists($path)) {
46
-		    $this->error("Coverage file does not exist.");
47
-	    } else {
37
+	/**
38
+	 * Execute the console command.
39
+	 *
40
+	 * @return mixed
41
+	 */
42
+	public function handle()
43
+	{
44
+		$path = __DIR__ . "/../../tests/coverage.xml";
45
+		if (!file_exists($path)) {
46
+			$this->error("Coverage file does not exist.");
47
+		} else {
48 48
 		    
49
-		    $xml = Parser::xml(file_get_contents($path));
49
+			$xml = Parser::xml(file_get_contents($path));
50 50
 		    
51 51
 		    
52
-		    $elements = [
53
-			    'covered' => $xml['project']['metrics']['@coveredelements'],
52
+			$elements = [
53
+				'covered' => $xml['project']['metrics']['@coveredelements'],
54 54
 				'total' => $xml['project']['metrics']['@elements']
55
-		    ];
55
+			];
56 56
 		    
57
-		    $statements = [
58
-			    'covered' => $xml['project']['metrics']['@coveredstatements'],
57
+			$statements = [
58
+				'covered' => $xml['project']['metrics']['@coveredstatements'],
59 59
 				'total' => $xml['project']['metrics']['@statements']
60
-		    ];
60
+			];
61 61
 		    
62
-		    $methods = [
63
-			    'covered' => $xml['project']['metrics']['@coveredmethods'],
62
+			$methods = [
63
+				'covered' => $xml['project']['metrics']['@coveredmethods'],
64 64
 				'total' => $xml['project']['metrics']['@methods']
65
-		    ];
65
+			];
66 66
 		    
67
-		    $percentages = [
68
-			    'elements' => round(($elements['covered'] / $elements['total']) * 100),
69
-			    'statements' => round(($statements['covered'] / $statements['total']) * 100),
70
-			    'methods' => round(($methods['covered'] / $methods['total']) * 100),
71
-		    ];
67
+			$percentages = [
68
+				'elements' => round(($elements['covered'] / $elements['total']) * 100),
69
+				'statements' => round(($statements['covered'] / $statements['total']) * 100),
70
+				'methods' => round(($methods['covered'] / $methods['total']) * 100),
71
+			];
72 72
 		    
73
-		    $average = round(($percentages['elements'] + $percentages['statements'] + $percentages['methods']) / 3);
74
-		    $percentages['average'] = $average;
73
+			$average = round(($percentages['elements'] + $percentages['statements'] + $percentages['methods']) / 3);
74
+			$percentages['average'] = $average;
75 75
 		    
76
-		    $percentages = array_map(function($item) {
77
-			    return number_format($item) . '%';
76
+			$percentages = array_map(function($item) {
77
+				return number_format($item) . '%';
78 78
 			}, $percentages);
79 79
 			
80 80
 			$headers = ['Elements', 'Statements', 'Methods', 'Average'];
81
-		    $this->table($headers, [$percentages]);
81
+			$this->table($headers, [$percentages]);
82 82
 		    
83
-		    if ($this->option('lines')) {
83
+			if ($this->option('lines')) {
84 84
 		    
85
-			    $packages = $xml['project']['package'];
85
+				$packages = $xml['project']['package'];
86 86
 			    
87
-			    foreach ($packages as $namespace) {
88
-				    $name = $namespace['@name'];
89
-				    if (!$this->isAssoc($namespace['file'])) {
90
-					    foreach ($namespace['file'] as $file) {
91
-						    $this->processFile($file);
92
-					    }
87
+				foreach ($packages as $namespace) {
88
+					$name = $namespace['@name'];
89
+					if (!$this->isAssoc($namespace['file'])) {
90
+						foreach ($namespace['file'] as $file) {
91
+							$this->processFile($file);
92
+						}
93 93
 					} else {
94 94
 						$this->processFile($namespace['file']);
95 95
 					}
96
-			    }
96
+				}
97 97
 		    
98
-		    }
98
+			}
99 99
 		    		    
100
-	    }
100
+		}
101 101
         
102
-    }
102
+	}
103 103
     
104
-    private function processFile($file)
105
-    {
106
-	    $filename = $file['@name'];
107
-	    $name = basename($file['@name']);
108
-	    if (!isset($file['line'])) return;
109
-	    foreach ($file['line'] as $line) {
110
-		    if ($line['@count'] == 0 && $line['@type'] == 'stmt') {
111
-			    $text = file_get_contents($filename);
112
-			    $text = str_replace("\t", "  ", $text);
113
-			    $filecontents = explode("\n", $text);
114
-			    $number = $line['@num'];
115
-			    $this->warn($name);
104
+	private function processFile($file)
105
+	{
106
+		$filename = $file['@name'];
107
+		$name = basename($file['@name']);
108
+		if (!isset($file['line'])) return;
109
+		foreach ($file['line'] as $line) {
110
+			if ($line['@count'] == 0 && $line['@type'] == 'stmt') {
111
+				$text = file_get_contents($filename);
112
+				$text = str_replace("\t", "  ", $text);
113
+				$filecontents = explode("\n", $text);
114
+				$number = $line['@num'];
115
+				$this->warn($name);
116 116
 	    
117
-			    $this->line("+---------------------------------------------------------");
118
-			    $this->line("|");
119
-			    $this->line("|" . ($number - 1) . $filecontents[$number - 2]);
120
-			    $this->info("|" . $number . $filecontents[$number - 1]);
121
-			    $this->line("|" . ($number + 1) . $filecontents[$number]);
117
+				$this->line("+---------------------------------------------------------");
118
+				$this->line("|");
119
+				$this->line("|" . ($number - 1) . $filecontents[$number - 2]);
120
+				$this->info("|" . $number . $filecontents[$number - 1]);
121
+				$this->line("|" . ($number + 1) . $filecontents[$number]);
122 122
 			    
123
-			    $this->line("+---------------------------------------------------------");
124
-		    }
125
-	    }
126
-    }
123
+				$this->line("+---------------------------------------------------------");
124
+			}
125
+		}
126
+	}
127 127
     
128
-    private function isAssoc(array $arr)
128
+	private function isAssoc(array $arr)
129 129
 	{
130
-	    if (array() === $arr) return false;
131
-	    return array_keys($arr) !== range(0, count($arr) - 1);
130
+		if (array() === $arr) return false;
131
+		return array_keys($arr) !== range(0, count($arr) - 1);
132 132
 	}
133 133
 }
Please login to merge, or discard this patch.