Skip to content

Commit 4fe88f8

Browse files
authored
Merge pull request #47 from exussum12/v1-prep
Start of v1
2 parents 3623b9d + d86c446 commit 4fe88f8

Some content is hidden

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

83 files changed

+538
-525
lines changed

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ 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
14-
- php: nightly
15-
- php: hhvm
16-
allow_failures:
17-
- php: hhvm
12+
env: UPDATE_COVERAGE=1
13+
- php: 7.3
1814
- php: nightly
1915
fast_finish: true
2016
before_script:

GitHooks/pre-commit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -e
2+
3+
# This is a PSR-2 checking example for just the code about to be committed
4+
5+
# Get the changes
6+
files=$(mktemp)
7+
diff=$(mktemp)
8+
9+
git diff --cached --name-only --diff-filter=ACMR -- "*.php" > ${files}
10+
git diff --cached > ${diff}
11+
12+
# Run the phpcs report
13+
phpcs=$(mktemp)
14+
./vendor/bin/phpcs --file-list=${files} --parallel=2 --standard=psr2 --report=json > ${phpcs} || true
15+
16+
check for differences
17+
./vendor/bin/diffFilter --phpcs diff.txt phpcs.json

GitHooks/pre-receive

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# This is a PSR-2 checking example for just the code about to be committed
4+
5+
# Get the changes
6+
files=$(mktemp)
7+
diff=$(mktemp)
8+
9+
git diff --name-only --diff-filter=ACMR -- "*.php" $1...$2 > ${files}
10+
git diff $1...$2 > ${diff}
11+
12+
# Run the phpcs report
13+
phpcs=$(mktemp)
14+
./vendor/bin/phpcs --file-list=${files} --parallel=2 --standard=psr2 --report=json > ${phpcs} || true
15+
16+
check for differences
17+
./vendor/bin/diffFilter --phpcs diff.txt phpcs.json

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Coverage checker allows new standards to be implemented incrementally, by only e
99

1010
Tools like phpcs and phpmd are an all or nothing approach, coverage checker allows this to work with the diff i.e. enforce all of the pull request / change request.
1111

12+
This is sometimes called "Baselining"
13+
1214
Also working with PHPunit to allow, for example 90% of new/edited code to be covered. which will increase the overall coverage over time.
1315

1416
# Installing
@@ -54,6 +56,12 @@ diffFilter will exit with a `0` status if the changed code passes the minimum co
5456
## Extended guide
5557
A more in depth guide can be [found on the wiki](https://github.com/exussum12/coverageChecker/wiki) also some tips for speeding up the build.
5658

59+
## Installing as a git hook
60+
61+
There are 2 examples hooks in the GitHooks directory, if you symlink to these diffFilter will run locally.
62+
63+
pre-commit is before the commit happens
64+
pre-receive will prevent you pushing
5765

5866
# Full list of available diff filters
5967

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: 5 additions & 3 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": {
22-
"php": ">=5.5",
22+
"php": ">=7.0",
23+
"ext-xmlreader": "*",
24+
"ext-json": "*",
2325
"nikic/php-parser": "^3.1||^4.0"
2426
}
2527
}

examples/phpcsEnforce.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ set -e
66

77
# Get the diff (changes since the branch was created
88
git diff origin/master... > diff.txt
9-
git diff origin/master... --name-only -- '*.php' > files.txt
9+
git diff origin/master... --name-only --diff-filter=ACMR -- '*.php' > files.txt
1010

1111

1212
# Old versions of phpcs will need to use the syntax commented out.
1313
# Note the || true is important, Without this phpcs failing will fail the build!
14-
# ./vendor/bin/phpcs --standard=psr2 src > phpcs.json || true
1514

1615
./vendor/bin/phpcs --file-list=files.txt --parallel=2 --standard=psr2 --report=json > phpcs.json || true
1716

src/ArgParser.php

Lines changed: 15 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,27 +12,31 @@ 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)) {
21+
$name = (int) $name;
1622
return $this->numericArg($name);
1723
}
1824

1925
return $this->letterArg($name);
2026
}
2127

22-
protected function numericArg($position)
28+
protected function numericArg(int $position): string
2329
{
2430
foreach ($this->args as $arg) {
2531
if ($arg{0} != '-' && $position-- == 0) {
2632
return $arg;
2733
}
2834
}
2935

30-
return null;
36+
throw new ArgumentNotFound();
3137
}
3238

33-
protected function letterArg($name)
39+
protected function letterArg($name): string
3440
{
3541
$name = $this->getAdjustedArg($name);
3642
foreach ($this->args as $arg) {
@@ -41,24 +47,20 @@ protected function letterArg($name)
4147
}
4248
}
4349

44-
return false;
50+
throw new ArgumentNotFound();
4551
}
4652

47-
protected function splitArg($arg)
53+
protected function splitArg(string $arg): array
4854
{
49-
$value = true;
50-
if (strpos($arg, '=')) {
55+
$value = '1';
56+
if (strpos($arg, '=') > 0) {
5157
list($arg, $value) = explode('=', $arg, 2);
5258
}
5359

5460
return array($value, $arg);
5561
}
5662

57-
/**
58-
* @param string $name
59-
* @return string
60-
*/
61-
protected function getAdjustedArg($name)
63+
protected function getAdjustedArg(string $name): string
6264
{
6365
$name = strlen($name) == 1 ?
6466
'-' . $name :

0 commit comments

Comments
 (0)