Skip to content

Commit

Permalink
Add PHPStan to build, fix errors it revealed (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Jan 16, 2019
1 parent 06656dc commit 348140b
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 35 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: php
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
install:
- composer install --no-interaction --no-progress --no-suggest --prefer-dist
script: vendor/bin/phpunit --coverage-text --whitelist src/ tests/
script:
- vendor/bin/phpunit --coverage-text --whitelist src/ tests/
- composer phpstan
after_success:
- travis_retry vendor/bin/php-coveralls
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.3] - 2019-01-16
### Summary
- Fixes some erroneously defined PHPDoc type signatures
- Adds PHPStan to CI
- Stops testing against PHP 7.0, which is no longer maintained

## [2.1.2] - 2018-09-20
### Summary
- Fixes an issue where default values were erroneously returned where `null` was a valid value

## [2.1.1] - 2018-05-16
### Summary
- Fixes regression in 2.1.0 that created a breaking change without an appropriate SemVer bump

## [2.1.0] - 2018-03-18
### Summary
- Configures CI
- Adds support for default values on optional parameters
- Exposes additional information about validation errors

## [2.0.0] - 2015-10-21
### Summary
- PHP 7 Support
- Adds return types
- Adds scalar type hints

## [1.0.0] - 2015-10-21
### Summary
- First stable release (no major changes)

## [0.0.4: Add SafeInputTestTrait] - 2015-10-08
### Summary
- Adds SafeInputTestTrait

## [0.0.3] - 2015-09-19
### Summary
- Changes InputException to extend UnexpectedValueException

## [0.0.2] - 2015-09-17
### Summary
- Add ValidationInterface test trait
- Moved InputObjects to a separate repository

## [0.0.1] - 2015-09-01
### Summary
- Initial release
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ An input validation framework with a boring name

[![Build Status](https://travis-ci.org/Firehed/input.svg?branch=master)](https://travis-ci.org/Firehed/input)
[![Coverage Status](https://coveralls.io/repos/github/Firehed/input/badge.svg?branch=master)](https://coveralls.io/github/Firehed/input?branch=master)
[Changelog](CHANGELOG.md)

Concept
-----
Expand Down Expand Up @@ -116,7 +117,3 @@ try {
echo $e;
}
```

Development
-----
PHP7 support (STH, return types, etc) has been added in the 2.0 line. The 1.0 line will remain compatible with PHP5.
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@
"Firehed\\Input\\": ["src/", "tests/"]
}
},
"config": {
"sort-packages": true
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.0",
"phpunit/phpunit": "^6 || ^7"
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpunit/phpunit": "^7"
},
"scripts": {
"test": [
"@phpunit"
"@phpunit",
"@phpstan"
],
"phpstan": "phpstan analyse --no-progress .",
"phpunit": "phpunit --coverage-text"
}
}
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
excludes_analyse:
- %rootDir%/../../../vendor
level: 7
10 changes: 5 additions & 5 deletions src/Containers/ParsedInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
class ParsedInput extends RawInput implements \ArrayAccess {

public function __construct(array $data) {
$this->setData($data)
->setIsParsed(true);
parent::__construct($data);
$this->setIsParsed(true);
} // __construct

/**
* @param array data to add
* @return this
* @param ParsedInput $add data to add
* @return $this
* @throws BadMethodCallException
*/
public function addData(ParsedInput $add): self {
Expand All @@ -37,7 +37,7 @@ public function addData(ParsedInput $add): self {
} // addData

/**
* @param ValidationInterface Validation requirements
* @param ValidationInterface $validator Validation requirements
* @return SafeInput
* @throws InputException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Containers/SafeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(ParsedInput $valid) {
if (!$valid->isValidated()) {
throw new BadMethodCallException;
}
$this->setData($valid->getData());
parent::__construct($valid->getData());
} // __construct

}
6 changes: 4 additions & 2 deletions src/Interfaces/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace Firehed\Input\Interfaces;

use Firehed\Input\Exceptions\InputException;

interface ParserInterface {

/**
* @param string Unparsed, unvalidated input
* @param string $raw_input Unparsed, unvalidated input
* @return array Parsed, unvalidated input
* @throws \ApiException
* @throws InputException
*/
public function parse(string $raw_input): array;

Expand Down
6 changes: 4 additions & 2 deletions src/Interfaces/ValidationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

namespace Firehed\Input\Interfaces;

use Firehed\Input\Objects\InputObject;

interface ValidationInterface {

/**
* @return array<string, Objects\InputObject>
* @return array<string, InputObject>
*/
public function getRequiredInputs(): array;

/**
* @return array<string, Objects\InputObject>
* @return array<string, InputObject>
*/
public function getOptionalInputs(): array;

Expand Down
4 changes: 2 additions & 2 deletions src/Objects/InputObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ final protected function getValue() {
} // getValue

/**
* @param mixed value to validate
* @return self
* @param mixed $value value to validate
* @return $this
*/
final public function setValue($value): self {
$this->isValid = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/Containers/RawInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testConstruct() {
* @covers ::parse
*/
public function testParse() {
$raw_data = md5(rand());
$raw_data = md5((string)rand());
$mock = $this->createMock('Firehed\Input\Interfaces\ParserInterface');
$mock->expects($this->once())
->method('parse')
Expand Down
14 changes: 0 additions & 14 deletions tests/Exceptions/InputExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ public function testInvalidConstructWithInt()
}
} // testInvalidConstruct

/**
* @covers ::__construct
*/
public function testInvalidConstructWithString()
{
try {
new InputException('this is not a defined value');
} catch (TypeError $e) {
$this->assertTrue(true, 'test passed');
} catch (LogicException $e) {
$this->assertTrue(true, 'test passed');
}
} // testInvalidConstruct

/**
* @covers ::getInvalid
* @dataProvider constants
Expand Down

0 comments on commit 348140b

Please sign in to comment.