diff --git a/README.md b/README.md index 50f62da..97a354b 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ With composer simply then call the script you need ##Manually -Clone this repository somewhere your your build plan can be accessed, composer install (required for the class loader only) +Clone this repository somewhere your your build plan can be accessed, composer install is prefered but there is a non composer class loader which will be used if composer is not installed. Then call the script you need @@ -40,7 +40,7 @@ exit code 0 and no output indicates success php vendor/bin/phpunitDiffFilter /tmp/diff.txt report/coverage.xml 90 -Will fail (exit status 1) if less than 90% of the code committed is covered by a test. +Will fail (exit status 2) if less than 90% of the code committed is covered by a test. This requires phpunit to be run on the branch first! ##phpcs @@ -51,7 +51,7 @@ All of the commands can read from stdin with placeholder `-` phpcs can be run with any options you normally have for example `--standard=PSR2` -This will exit with code 1 if any of the new/edited code fails the code standards check. The output is kept so you can see what the offending lines are and what the error is. +This will exit with code 2 if any of the new/edited code fails the code standards check. The output is kept so you can see what the offending lines are and what the error is. ##phpmd @@ -62,4 +62,4 @@ All of the commands can read from stdin with placeholder `-` phpcs can be run with any options you normally have for example `cleancode,codesize,controversial` -This will exit with code 1 if any of the new/edited code fails the code standards check. The output is kept so you can see what the offending lines are and what the error is. +This will exit with code 2 if any of the new/edited code fails the code standards check. The output is kept so you can see what the offending lines are and what the error is. diff --git a/bin/phpcsDiffFilter b/bin/phpcsDiffFilter index 14d6106..9c94f4b 100755 --- a/bin/phpcsDiffFilter +++ b/bin/phpcsDiffFilter @@ -1,16 +1,34 @@ #!/usr/bin/env php fileLocation = $fileName; $this->diff = new DiffFileState(); + } public function getChangedLines() { - $handle = @fopen($this->fileLocation, "r"); - - if (!$handle) { + if (!is_readable($this->fileLocation)) { throw new InvalidArgumentException("Can't read file"); } + $handle = fopen($this->fileLocation, 'r'); + while (($line = fgets($handle)) !== false) { // process the line read. $lineHandle = $this->getLineHandle($line); diff --git a/tests/DiffFileLoadTest.php b/tests/DiffFileLoadTest.php index 8619c7d..cbfffbe 100644 --- a/tests/DiffFileLoadTest.php +++ b/tests/DiffFileLoadTest.php @@ -27,26 +27,26 @@ public function getResults() { return [ 'newFile' => [ - __DIR__ . "/fixtures/newFile.txt", + __DIR__ . '/fixtures/newFile.txt', [ 'changedFile.php' => [1,2,3] ] ], 'lineChange' => [ - __DIR__ . "/fixtures/change.txt", + __DIR__ . '/fixtures/change.txt', [ 'changedFile.php' => [3] ] ], 'multipleFiles' => [ - __DIR__ . "/fixtures/multiple.txt", + __DIR__ . '/fixtures/multiple.txt', [ 'changedFile.php' => [3], 'newFile.php' => [1,2,3] ] ], 'removeFile' => [ - __DIR__ . "/fixtures/removeFile.txt", + __DIR__ . '/fixtures/removeFile.txt', [] ], ];