diff --git a/.gitattributes b/.gitattributes index c211397..5e43a5e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,5 +9,6 @@ /.php-cs-fixer.dist.php export-ignore /.phpunit.result.cache export-ignore /composer.lock export-ignore +/phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore -rector.php export-ignore \ No newline at end of file +/rector.php export-ignore \ No newline at end of file diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 255163c..b45ad9c 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -6,24 +6,20 @@ We accept contributions via Pull Requests on Github. ## Pull Requests -- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - Fix the code style with `composer fix`. +- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - Fix the code's style with `composer fix`. -- **Add tests!** - Your patch won't be accepted if it doesn't have tests. +- **[PHPStan level 9](https://phpstan.org/user-guide/rule-levels)** - Check compliance with `composer type`. + +- **Add tests!** - Your contribution won't be accepted if it doesn't have tests – Run the test suite with `composer test`. - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. -- **Create feature branches** - Don't ask us to pull from your master branch. +- **Create feature branches** - Don't ask us to pull from your main branch. - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. -## Testing - -```bash -$ composer test -``` - **Happy coding**! diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f970c7b..904563c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Setup PHP + - name: Set up PHP uses: shivammathur/setup-php@v2 - name: Install composer dependencies @@ -25,6 +25,23 @@ jobs: - name: Check coding style run: vendor/bin/php-cs-fixer fix --dry-run + type: + name: Type + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + + - name: Install composer dependencies + uses: ramsey/composer-install@v2 + + - name: Check code typing + run: vendor/bin/phpstan + tests: name: Tests runs-on: ubuntu-latest @@ -55,5 +72,5 @@ jobs: with: dependency-versions: ${{ matrix.dependency-versions }} - - name: Run PHPUnit + - name: Run tests run: vendor/bin/phpunit tests diff --git a/composer.json b/composer.json index 04b3480..1094415 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.17", + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.6", "rector/rector": "^0.17.1" }, @@ -52,8 +53,10 @@ "scripts": { "fix": "php-cs-fixer fix -v", "test": "phpunit", + "type": "phpstan", "all": [ "@fix", + "@type", "@test" ], "refactor": "rector process" diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..0263f62 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +parameters: + level: 9 + + paths: + - src + + checkMissingCallableSignature: true \ No newline at end of file diff --git a/src/Adapters/HttpFoundationAdapter.php b/src/Adapters/HttpFoundationAdapter.php index c5e3c43..f003814 100644 --- a/src/Adapters/HttpFoundationAdapter.php +++ b/src/Adapters/HttpFoundationAdapter.php @@ -6,7 +6,6 @@ use InvalidArgumentException; use Nyholm\Psr7\Factory\Psr17Factory; -use Psr\Http\Message\MessageInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; @@ -20,7 +19,7 @@ final class HttpFoundationAdapter implements MessageAdapterInterface * * @param object $message the HTTP message to convert */ - public function convert(object $message): MessageInterface + public function convert(object $message): ResponseInterface|ServerRequestInterface { if ($message instanceof ResponseInterface || $message instanceof ServerRequestInterface) { return $message; diff --git a/src/Adapters/MessageAdapterInterface.php b/src/Adapters/MessageAdapterInterface.php index 4de8937..bd77e62 100644 --- a/src/Adapters/MessageAdapterInterface.php +++ b/src/Adapters/MessageAdapterInterface.php @@ -4,7 +4,8 @@ namespace Osteel\OpenApi\Testing\Adapters; -use Psr\Http\Message\MessageInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; interface MessageAdapterInterface { @@ -13,5 +14,5 @@ interface MessageAdapterInterface * * @param object $message the HTTP message to convert */ - public function convert(object $message): MessageInterface; + public function convert(object $message): ResponseInterface|ServerRequestInterface; } diff --git a/src/ValidatorBuilder.php b/src/ValidatorBuilder.php index 13ac1f6..dac8918 100644 --- a/src/ValidatorBuilder.php +++ b/src/ValidatorBuilder.php @@ -16,8 +16,10 @@ */ final class ValidatorBuilder implements ValidatorBuilderInterface { + /** @var class-string */ private string $adapter = HttpFoundationAdapter::class; + /** @var class-string */ private string $cacheAdapter = Psr16Adapter::class; public function __construct(private BaseValidatorBuilder $validatorBuilder)