Skip to content

Commit 29f31e5

Browse files
Fix CS/WS issues
1 parent 699b15e commit 29f31e5

File tree

13 files changed

+96
-60
lines changed

13 files changed

+96
-60
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"phpunit/phpunit": "^7.0"
4242
},
4343
"suggest": {
44-
"ext-xdebug": "^2.5.5"
44+
"ext-xdebug": "^2.6.0"
4545
},
4646
"autoload": {
4747
"classmap": [

src/CodeCoverage.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use PHPUnit\Framework\TestCase;
1414
use PHPUnit\Runner\PhptTestCase;
15+
use PHPUnit\Util\Test;
1516
use SebastianBergmann\CodeCoverage\Driver\Driver;
1617
use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
1718
use SebastianBergmann\CodeCoverage\Driver\Xdebug;
@@ -364,11 +365,11 @@ public function append(array $data, $id = null, $append = true, $linesToBeCovere
364365
if ($id instanceof TestCase) {
365366
$_size = $id->getSize();
366367

367-
if ($_size === \PHPUnit\Util\Test::SMALL) {
368+
if ($_size === Test::SMALL) {
368369
$size = 'small';
369-
} elseif ($_size === \PHPUnit\Util\Test::MEDIUM) {
370+
} elseif ($_size === Test::MEDIUM) {
370371
$size = 'medium';
371-
} elseif ($_size === \PHPUnit\Util\Test::LARGE) {
372+
} elseif ($_size === Test::LARGE) {
372373
$size = 'large';
373374
}
374375

@@ -1113,7 +1114,7 @@ private function initializeData()
11131114

11141115
foreach ($this->filter->getWhitelist() as $file) {
11151116
if ($this->filter->isFile($file)) {
1116-
include_once($file);
1117+
include_once $file;
11171118
}
11181119
}
11191120

src/Driver/Driver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ interface Driver
2020
*
2121
* @see http://xdebug.org/docs/code_coverage
2222
*/
23-
const LINE_EXECUTED = 1;
23+
public const LINE_EXECUTED = 1;
2424

2525
/**
2626
* @var int
2727
*
2828
* @see http://xdebug.org/docs/code_coverage
2929
*/
30-
const LINE_NOT_EXECUTED = -1;
30+
public const LINE_NOT_EXECUTED = -1;
3131

3232
/**
3333
* @var int
3434
*
3535
* @see http://xdebug.org/docs/code_coverage
3636
*/
37-
const LINE_NOT_EXECUTABLE = -2;
37+
public const LINE_NOT_EXECUTABLE = -2;
3838

3939
/**
4040
* Start collection of code coverage information.

src/Driver/PHPDBG.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public function stop()
6666
\array_keys($fetchedLines)
6767
);
6868

69+
$sourceLines = [];
70+
6971
if ($newFiles) {
7072
$sourceLines = phpdbg_get_executable(
7173
['files' => $newFiles]
7274
);
73-
} else {
74-
$sourceLines = [];
7575
}
7676
}
7777

src/Driver/Xdebug.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@ final class Xdebug implements Driver
2727
private $cacheNumLines = [];
2828

2929
/**
30-
* Constructor.
30+
* @throws RuntimeException
3131
*/
3232
public function __construct()
3333
{
3434
if (!\extension_loaded('xdebug')) {
3535
throw new RuntimeException('This driver requires Xdebug');
3636
}
3737

38-
if (\version_compare(\phpversion('xdebug'), '2.2.1', '>=') &&
39-
!\ini_get('xdebug.coverage_enable')) {
40-
throw new RuntimeException(
41-
'xdebug.coverage_enable=On has to be set in php.ini'
42-
);
38+
if (!\ini_get('xdebug.coverage_enable')) {
39+
throw new RuntimeException('xdebug.coverage_enable=On has to be set in php.ini');
4340
}
4441
}
4542

@@ -65,6 +62,7 @@ public function start($determineUnusedAndDead = true)
6562
public function stop()
6663
{
6764
$data = \xdebug_get_code_coverage();
65+
6866
\xdebug_stop_code_coverage();
6967

7068
return $this->cleanup($data);

src/Node/Builder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ private function buildDirectoryStructure($files)
114114
$max = \count($path);
115115

116116
for ($i = 0; $i < $max; $i++) {
117+
$type = '';
118+
117119
if ($i == ($max - 1)) {
118120
$type = '/f';
119-
} else {
120-
$type = '';
121121
}
122122

123123
$pointer = &$pointer[$path[$i] . $type];
@@ -194,7 +194,7 @@ private function reducePaths(&$files)
194194
// strip phar:// prefixes
195195
if (\strpos($paths[$i], 'phar://') === 0) {
196196
$paths[$i] = \substr($paths[$i], 7);
197-
$paths[$i] = \strtr($paths[$i], '/', DIRECTORY_SEPARATOR);
197+
$paths[$i] = \str_replace('/', DIRECTORY_SEPARATOR, $paths[$i]);
198198
}
199199
$paths[$i] = \explode(DIRECTORY_SEPARATOR, $paths[$i]);
200200

src/Report/Clover.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
4545

4646
$packages = [];
4747
$report = $coverage->getReport();
48-
unset($coverage);
4948

5049
foreach ($report as $item) {
5150
if (!$item instanceof File) {
@@ -57,10 +56,10 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
5756
$xmlFile = $xmlDocument->createElement('file');
5857
$xmlFile->setAttribute('name', $item->getPath());
5958

60-
$classes = $item->getClassesAndTraits();
61-
$coverage = $item->getCoverageData();
62-
$lines = [];
63-
$namespace = 'global';
59+
$classes = $item->getClassesAndTraits();
60+
$coverageData = $item->getCoverageData();
61+
$lines = [];
62+
$namespace = 'global';
6463

6564
foreach ($classes as $className => $class) {
6665
$classStatements = 0;
@@ -84,8 +83,8 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
8483
$methodCount = 0;
8584

8685
foreach (\range($method['startLine'], $method['endLine']) as $line) {
87-
if (isset($coverage[$line]) && ($coverage[$line] !== null)) {
88-
$methodCount = \max($methodCount, \count($coverage[$line]));
86+
if (isset($coverageData[$line]) && ($coverageData[$line] !== null)) {
87+
$methodCount = \max($methodCount, \count($coverageData[$line]));
8988
}
9089
}
9190

@@ -150,7 +149,7 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
150149
$xmlClass->appendChild($xmlMetrics);
151150
}
152151

153-
foreach ($coverage as $line => $data) {
152+
foreach ($coverageData as $line => $data) {
154153
if ($data === null || isset($lines[$line])) {
155154
continue;
156155
}

src/Report/Crap4j.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
117117
$stats->appendChild($document->createElement('crapLoad', \round($fullCrapLoad)));
118118
$stats->appendChild($document->createElement('totalCrap', $fullCrap));
119119

120+
$crapMethodPercent = 0;
121+
120122
if ($fullMethodCount > 0) {
121123
$crapMethodPercent = $this->roundValue((100 * $fullCrapMethodCount) / $fullMethodCount);
122-
} else {
123-
$crapMethodPercent = 0;
124124
}
125125

126126
$stats->appendChild($document->createElement('crapMethodPercent', $crapMethodPercent));
@@ -131,8 +131,8 @@ public function process(CodeCoverage $coverage, $target = null, $name = null)
131131
$buffer = $document->saveXML();
132132

133133
if ($target !== null) {
134-
if (!\is_dir(\dirname($target))) {
135-
\mkdir(\dirname($target), 0777, true);
134+
if (!\mkdir(\dirname($target)) && !\is_dir(\dirname($target))) {
135+
throw new \RuntimeException(\sprintf('Directory "%s" was not created', \dirname($target)));
136136
}
137137

138138
\file_put_contents($target, $buffer);

src/Report/Html/Renderer/Dashboard.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,11 @@ protected function projectRisks(array $classes, $baseLink)
248248

249249
foreach ($classes as $className => $class) {
250250
foreach ($class['methods'] as $methodName => $method) {
251-
if ($method['coverage'] < $this->highLowerBound &&
252-
$method['ccn'] > 1) {
251+
if ($method['coverage'] < $this->highLowerBound && $method['ccn'] > 1) {
252+
$key = $methodName;
253+
253254
if ($className !== '*') {
254255
$key = $className . '::' . $methodName;
255-
} else {
256-
$key = $methodName;
257256
}
258257

259258
$methodRisks[$key] = $method['crap'];

src/Report/Html/Renderer/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,14 @@ protected function renderSource(FileNode $node)
394394
}
395395
}
396396

397+
$popover = '';
398+
397399
if (!empty($popoverTitle)) {
398400
$popover = \sprintf(
399401
' data-title="%s" data-content="%s" data-placement="bottom" data-html="true"',
400402
$popoverTitle,
401403
\htmlspecialchars($popoverContent)
402404
);
403-
} else {
404-
$popover = '';
405405
}
406406

407407
$lines .= \sprintf(

0 commit comments

Comments
 (0)