From 42e1d596b52a6533bfe47b6a5ffb9d27f7dac583 Mon Sep 17 00:00:00 2001 From: Olivier Dolbeau Date: Sat, 7 Dec 2019 20:25:08 +0100 Subject: [PATCH] Allow sf5 + clean --- .github/workflows/static.yml | 21 +++++++++++++++++++ Makefile | 18 +++++++++++----- composer.json | 12 +++++------ phpstan.neon.dist | 1 + src/Api/HttpApi.php | 7 ------- src/Exception/Domain/BadRequestException.php | 2 +- .../Domain/UnknownErrorException.php | 2 +- src/Hydrator/ModelHydrator.php | 5 +---- src/Model/Conversation/Conversation.php | 2 +- src/TalkJSClient.php | 9 +------- tests/FunctionalTests/ConversationTest.php | 4 ++-- 11 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/static.yml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..de637af --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,21 @@ +on: [push, pull_request] +name: Static analysis +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: PHP-CS-Fixer + uses: docker://jakzal/phpqa:php7.3-alpine + with: + args: php-cs-fixer fix --dry-run --diff-format udiff -vvv + + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: PHPStan + uses: docker://oskarstark/phpstan-ga + with: + args: analyze --no-progress diff --git a/Makefile b/Makefile index 63fe58b..973f860 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ .PHONY: ${TARGETS} .DEFAULT_GOAL := help +DIR := ${CURDIR} +QA_IMAGE := jakzal/phpqa:php7.3-alpine + define say_red = echo "\033[31m$1\033[0m" endef @@ -25,11 +28,16 @@ install: ## Install all applications @$(call say_green,"Installing PHP dependencies") @composer install -test: ## Launch tests - @vendor/bin/phpunit - cs-lint: ## Verify check styles - -vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --verbose --diff + @docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff --dry-run -vvv cs-fix: ## Apply Check styles - -vendor/bin/php-cs-fixer fix --using-cache=no --verbose --diff + @docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) php-cs-fixer fix --diff-format udiff -vvv + +phpstan: ## Run PHPStan + @docker run --rm -v $(DIR):/project -w /project $(QA_IMAGE) phpstan analyse + +test: cs-lint phpstan ## Launch tests + @rm -rf ./tests/app/var ./tests/app/cache + @$(call say_green,"==\> Launch unit tests") + @vendor/bin/phpunit diff --git a/composer.json b/composer.json index cd00f17..fdcd206 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,13 @@ ], "require": { "php": "^7.3", - "symfony/config": "^4.2", - "symfony/http-client": "^4.3" + "symfony/config": "^4.3|^5.0", + "symfony/http-client": "^4.3|^5.0" }, "require-dev": { - "phpunit/phpunit": "^8.0", - "friendsofphp/php-cs-fixer": "^2.13", - "phpstan/phpstan": "^0.11.1", - "symfony/phpunit-bridge": "^4.2", - "symfony/var-dumper": "^4.2" + "phpunit/phpunit": "^8.5", + "symfony/phpunit-bridge": "^4.4|^5.0", + "symfony/var-dumper": "^4.3|^5.0" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index efe2c28..3862702 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,6 @@ parameters: level: 5 + inferPrivatePropertyTypeFromConstructor: true paths: - %currentWorkingDirectory%/src - %currentWorkingDirectory%/tests diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index daf7689..4ce1fb9 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -18,14 +18,7 @@ abstract class HttpApi { - /** - * @var HttpClient - */ protected $httpClient; - - /** - * @var Hydrator - */ protected $hydrator; public function __construct(HttpClientInterface $httpClient, Hydrator $hydrator) diff --git a/src/Exception/Domain/BadRequestException.php b/src/Exception/Domain/BadRequestException.php index 0de5755..17f6ab2 100644 --- a/src/Exception/Domain/BadRequestException.php +++ b/src/Exception/Domain/BadRequestException.php @@ -9,8 +9,8 @@ namespace Shapin\TalkJS\Exception\Domain; -use Symfony\Contracts\HttpClient\ResponseInterface; use Shapin\TalkJS\Exception\DomainException; +use Symfony\Contracts\HttpClient\ResponseInterface; class BadRequestException extends \Exception implements DomainException { diff --git a/src/Exception/Domain/UnknownErrorException.php b/src/Exception/Domain/UnknownErrorException.php index 7f70cfb..38d2bb3 100644 --- a/src/Exception/Domain/UnknownErrorException.php +++ b/src/Exception/Domain/UnknownErrorException.php @@ -9,8 +9,8 @@ namespace Shapin\TalkJS\Exception\Domain; -use Symfony\Contracts\HttpClient\ResponseInterface; use Shapin\TalkJS\Exception\DomainException; +use Symfony\Contracts\HttpClient\ResponseInterface; final class UnknownErrorException extends \Exception implements DomainException { diff --git a/src/Hydrator/ModelHydrator.php b/src/Hydrator/ModelHydrator.php index 9a30204..d50ed19 100644 --- a/src/Hydrator/ModelHydrator.php +++ b/src/Hydrator/ModelHydrator.php @@ -19,15 +19,12 @@ final class ModelHydrator implements Hydrator { /** - * @param ResponseInterface $response - * @param string $class - * * @return mixed */ public function hydrate(ResponseInterface $response, string $class) { if (!isset($response->getHeaders()['content-type'])) { - throw new HydrationException("The ModelHydrator cannot hydrate response with Content-Type: $contentType"); + throw new HydrationException('The ModelHydrator cannot hydrate response without Content-Type header.'); } $contentType = reset($response->getHeaders()['content-type']); diff --git a/src/Model/Conversation/Conversation.php b/src/Model/Conversation/Conversation.php index 2eddb41..0d4b0e4 100644 --- a/src/Model/Conversation/Conversation.php +++ b/src/Model/Conversation/Conversation.php @@ -29,7 +29,7 @@ class Conversation implements CreatableFromArray private $photoUrl; /** - * @var ?string + * @var array */ private $welcomeMessages; diff --git a/src/TalkJSClient.php b/src/TalkJSClient.php index 2bec71a..23ffc50 100644 --- a/src/TalkJSClient.php +++ b/src/TalkJSClient.php @@ -9,20 +9,13 @@ namespace Shapin\TalkJS; -use Shapin\TalkJS\Hydrator\ModelHydrator; use Shapin\TalkJS\Hydrator\Hydrator; +use Shapin\TalkJS\Hydrator\ModelHydrator; use Symfony\Contracts\HttpClient\HttpClientInterface; final class TalkJSClient { - /** - * @var HttpClient - */ private $httpClient; - - /** - * @var Hydrator - */ private $hydrator; public function __construct(HttpClientInterface $talkjsClient, Hydrator $hydrator = null) diff --git a/tests/FunctionalTests/ConversationTest.php b/tests/FunctionalTests/ConversationTest.php index 277bd6a..4ba131a 100644 --- a/tests/FunctionalTests/ConversationTest.php +++ b/tests/FunctionalTests/ConversationTest.php @@ -10,10 +10,10 @@ namespace Shapin\TalkJS\Tests\FunctionalTests; use Shapin\TalkJS\Model\Conversation\Conversation; -use Shapin\TalkJS\Model\Conversation\ConversationJoined; -use Shapin\TalkJS\Model\Conversation\ConversationLeft; use Shapin\TalkJS\Model\Conversation\ConversationCollection; use Shapin\TalkJS\Model\Conversation\ConversationCreatedOrUpdated; +use Shapin\TalkJS\Model\Conversation\ConversationJoined; +use Shapin\TalkJS\Model\Conversation\ConversationLeft; use Shapin\TalkJS\Model\Conversation\ParticipationUpdated; final class ConversationTest extends TestCase