Skip to content

Commit 134dbcf

Browse files
committed
Start of v1
This will disable php 5.5 support Moves the loaders to their own namespace to clean up removed legacy command adding real type hints to most arguments Still a WIP This will be v1.0.0 when released
1 parent 50e3d05 commit 134dbcf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+448
-443
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ cache:
66
- $HOME/.cache/composer/files
77
matrix:
88
include:
9-
- php: 5.6
109
- php: 7.0
1110
- php: 7.1
12-
env: UPDATE_COVERAGE=1
1311
- php: 7.2
12+
env: UPDATE_COVERAGE=1
13+
- php: 7.3
1414
- php: nightly
15-
- php: hhvm
16-
allow_failures:
17-
- php: hhvm
1815
fast_finish: true
1916
before_script:
2017
- composer global require squizlabs/php_codesniffer

bin/phpcsDiffFilter

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/phpmdDiffFilter

Lines changed: 0 additions & 6 deletions
This file was deleted.

bin/phpunitDiffFilter

Lines changed: 0 additions & 6 deletions
This file was deleted.

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "exussum12/coverage-checker",
33
"description": "Allows checking the code coverage of a single pull request",
44
"require-dev": {
5-
"phpunit/phpunit": "^5.7"
5+
"phpunit/phpunit": "^6.5"
66
},
77
"license": "MIT",
88
"authors": [
@@ -17,9 +17,11 @@
1717
"exussum12\\CoverageChecker\\tests\\": "tests/"
1818
}
1919
},
20-
"bin": ["bin/phpunitDiffFilter","bin/phpcsDiffFilter", "bin/phpmdDiffFilter", "bin/diffFilter"],
20+
"bin": ["bin/diffFilter"],
2121
"require": {
2222
"php": ">=5.5",
23+
"ext-xmlreader": "*",
24+
"ext-json": "*",
2325
"nikic/php-parser": "^3.1||^4.0"
2426
}
2527
}

src/ArgParser.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace exussum12\CoverageChecker;
33

4+
use exussum12\CoverageChecker\Exceptions\ArgumentNotFound;
5+
46
class ArgParser
57
{
68
protected $args;
@@ -10,7 +12,10 @@ public function __construct(array $args)
1012
$this->args = $args;
1113
}
1214

13-
public function getArg($name)
15+
/**
16+
* @throws ArgumentNotFound
17+
*/
18+
public function getArg(string $name): string
1419
{
1520
if (is_numeric($name)) {
1621
return $this->numericArg($name);
@@ -19,18 +24,18 @@ public function getArg($name)
1924
return $this->letterArg($name);
2025
}
2126

22-
protected function numericArg($position)
27+
protected function numericArg(int $position): string
2328
{
2429
foreach ($this->args as $arg) {
2530
if ($arg{0} != '-' && $position-- == 0) {
2631
return $arg;
2732
}
2833
}
2934

30-
return null;
35+
throw new ArgumentNotFound();
3136
}
3237

33-
protected function letterArg($name)
38+
protected function letterArg($name): string
3439
{
3540
$name = $this->getAdjustedArg($name);
3641
foreach ($this->args as $arg) {
@@ -41,24 +46,20 @@ protected function letterArg($name)
4146
}
4247
}
4348

44-
return false;
49+
throw new ArgumentNotFound();
4550
}
4651

47-
protected function splitArg($arg)
52+
protected function splitArg(string $arg): array
4853
{
49-
$value = true;
50-
if (strpos($arg, '=')) {
54+
$value = '1';
55+
if (strpos($arg, '=') > 0) {
5156
list($arg, $value) = explode('=', $arg, 2);
5257
}
5358

5459
return array($value, $arg);
5560
}
5661

57-
/**
58-
* @param string $name
59-
* @return string
60-
*/
61-
protected function getAdjustedArg($name)
62+
protected function getAdjustedArg(string $name): string
6263
{
6364
$name = strlen($name) == 1 ?
6465
'-' . $name :

src/CodeLimits.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ class CodeLimits
66
protected $startLine;
77
protected $endLine;
88

9-
public function __construct($startLine, $endLine)
9+
public function __construct(int $startLine, int $endLine)
1010
{
1111
$this->startLine = $startLine;
1212
$this->endLine = $endLine;
1313
}
1414

15-
public function getStartLine()
15+
public function getStartLine(): int
1616
{
1717
return $this->startLine;
1818
}
1919

20-
public function getEndLine()
20+
public function getEndLine(): int
2121
{
2222
return $this->endLine;
2323
}

src/CoverageCheck.php

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class CoverageCheck
4545
* For example if the checker is phpunit, this class filters the phpunit
4646
* output by the diff of the pull request. giving only the common lines in
4747
* each
48-
*
49-
* @param DiffFileLoader $diff
50-
* @param FileChecker $fileChecker
51-
* @param FileMatcher $matcher
5248
*/
5349
public function __construct(
5450
DiffFileLoader $diff,
@@ -63,9 +59,8 @@ public function __construct(
6359

6460
/**
6561
* array of uncoveredLines and coveredLines
66-
* @return array
6762
*/
68-
public function getCoveredLines()
63+
public function getCoveredLines(): array
6964
{
7065
$this->getDiff();
7166

@@ -76,7 +71,7 @@ public function getCoveredLines()
7671
$diffFiles = array_keys($this->cache->diff);
7772
foreach ($diffFiles as $file) {
7873
$matchedFile = $this->findFile($file, $coveredFiles);
79-
if ($matchedFile !== false) {
74+
if ($matchedFile !== '') {
8075
$this->matchLines($file, $matchedFile);
8176
}
8277
}
@@ -87,12 +82,7 @@ public function getCoveredLines()
8782
];
8883
}
8984

90-
/**
91-
* @param string $file the filename containing the uncovered line
92-
* @param int $line the number of the uncovered line
93-
* @param array $message a list of messages showing why its uncovered
94-
*/
95-
protected function addUnCoveredLine($file, $line, $message)
85+
protected function addUnCoveredLine(string $file, int $line, array $message)
9686
{
9787
if (!isset($this->uncoveredLines[$file])) {
9888
$this->uncoveredLines[$file] = [];
@@ -101,11 +91,7 @@ protected function addUnCoveredLine($file, $line, $message)
10191
$this->uncoveredLines[$file][$line] = $message;
10292
}
10393

104-
/**
105-
* @param string $file the filename containing the covered line
106-
* @param int $line the number of the covered line
107-
*/
108-
protected function addCoveredLine($file, $line)
94+
protected function addCoveredLine(string $file, int $line)
10995
{
11096
if (!isset($this->coveredLines[$file])) {
11197
$this->coveredLines[$file] = [];
@@ -114,11 +100,7 @@ protected function addCoveredLine($file, $line)
114100
$this->coveredLines[$file][] = $line;
115101
}
116102

117-
/**
118-
* @param string $fileName the file name in the diff
119-
* @param string $matchedFile the file name of the matched file
120-
*/
121-
protected function matchLines($fileName, $matchedFile)
103+
protected function matchLines(string $fileName, string $matchedFile)
122104
{
123105
foreach ($this->cache->diff[$fileName] as $line) {
124106
$messages = $this->fileChecker->getErrorsOnLine($matchedFile, $line);
@@ -141,21 +123,21 @@ protected function matchLines($fileName, $matchedFile)
141123
}
142124
}
143125

144-
protected function addCoveredFile($file)
126+
protected function addCoveredFile(string $file)
145127
{
146128
foreach ($this->cache->diff[$file] as $line) {
147129
$this->addCoveredLine($file, $line);
148130
}
149131
}
150132

151-
protected function addUnCoveredFile($file)
133+
protected function addUnCoveredFile(string $file)
152134
{
153135
foreach ($this->cache->diff[$file] as $line) {
154136
$this->addUnCoveredLine($file, $line, ['No Cover']);
155137
}
156138
}
157139

158-
protected function getDiff()
140+
protected function getDiff(): array
159141
{
160142
if (empty($this->cache->diff)) {
161143
$this->cache->diff = $this->diff->getChangedLines();
@@ -164,7 +146,7 @@ protected function getDiff()
164146
return $this->cache->diff;
165147
}
166148

167-
protected function handleFileNotFound($file)
149+
protected function handleFileNotFound(string $file)
168150
{
169151
$unMatchedFile = $this->fileChecker->handleNotFoundFile();
170152

@@ -177,13 +159,13 @@ protected function handleFileNotFound($file)
177159
}
178160
}
179161

180-
protected function findFile($file, $coveredFiles)
162+
protected function findFile(string $file, array $coveredFiles): string
181163
{
182164
try {
183165
return $this->matcher->match($file, $coveredFiles);
184166
} catch (Exceptions\FileNotFound $e) {
185167
$this->handleFileNotFound($file);
186-
return false;
168+
return '';
187169
}
188170
}
189171
}

src/DiffFileLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct($fileName)
2222
$this->diff = new DiffFileState();
2323
}
2424

25-
public function getChangedLines()
25+
public function getChangedLines(): array
2626
{
2727
if ((
2828
!is_readable($this->fileLocation) &&
@@ -45,19 +45,19 @@ public function getChangedLines()
4545
return $this->diff->getChangedLines();
4646
}
4747

48-
private function getLineHandle($line)
48+
private function getLineHandle(string $line): DiffLineHandle
4949
{
5050
foreach ($this->diffLines as $lineType) {
5151
$lineType = $this->getClass($lineType);
5252
if ($lineType->isValid($line)) {
5353
return $lineType;
5454
}
5555
}
56-
//not found, Class it as context
56+
// the line doesn't have a special meaning, its probably context
5757
return $this->getClass(DiffLineHandle\ContextLine::class);
5858
}
5959

60-
private function getClass($className)
60+
private function getClass(string $className): DiffLineHandle
6161
{
6262
if (!isset($this->handles[$this->getFileHandleName($className)])) {
6363
$this->handles[
@@ -68,7 +68,7 @@ private function getClass($className)
6868
return $this->handles[$this->getFileHandleName($className)];
6969
}
7070

71-
private function getFileHandleName($namespace)
71+
private function getFileHandleName(string $namespace): string
7272
{
7373
$namespace = explode('\\', $namespace);
7474
return end($namespace);

src/DiffFileLoaderOldVersion.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
namespace exussum12\CoverageChecker;
33

4+
/**
5+
* This file gets the file context before the file was changed.
6+
* ie old -> new, this returns what used to be there
7+
*/
48
class DiffFileLoaderOldVersion extends DiffFileLoader
59
{
610
protected $diffLines = [

0 commit comments

Comments
 (0)