From e57fcdbf49a22fe2232bfe33f53b010e0cd53701 Mon Sep 17 00:00:00 2001 From: samuelgfeller Date: Mon, 1 Apr 2024 10:41:55 +0200 Subject: [PATCH] Added scrutinizer [SLE-197] --- .github/workflows/build.yml | 8 ++-- .scrutinizer.yml | 46 +++++++++++++++++++ .../Action/User/UserCreateAction.php | 2 +- .../User/Repository/UserCreatorRepository.php | 6 +-- src/Domain/User/Service/UserCreator.php | 6 +-- src/Domain/User/Service/UserValidator.php | 9 ++-- .../Integration/User/UserCreateActionTest.php | 2 +- 7 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 .scrutinizer.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f73972..aed022f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,9 +7,6 @@ on: pull_request: types: [ opened, synchronize, reopened ] -env: - APP_ENV: github - jobs: run: runs-on: ${{ matrix.operating-system }} @@ -77,6 +74,7 @@ jobs: run: mysql -uroot -proot -D ${{ matrix.test-database }} -e "SHOW TABLES;" - name: Run test suite - run: composer test:coverage + run: composer test env: - PHP_CS_FIXER_IGNORE_ENV: 1 \ No newline at end of file + APP_ENV: github + PHP_CS_FIXER_IGNORE_ENV: 1 diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..28a4b08 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,46 @@ +filter: + paths: [ "src/*" ] + excluded_paths: [ "vendor/*", "tests/*", "resources/", "public/" ] + +checks: + php: + code_rating: true + duplication: true + +tools: + external_code_coverage: false + +build: + services: + mysql: 8.0.29 + environment: + php: + version: 8.2 + ini: + xdebug.mode: coverage + mysql: 5.7 + node: false + postgresql: false + mongodb: false + elasticsearch: false + redis: false + memcached: false + neo4j: false + rabbitmq: false + variables: + APP_ENV: 'github' + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + dependencies: + before: + - composer self-update + - mysql -u root -e "CREATE DATABASE IF NOT EXISTS slim_api_example_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" + tests: + before: + - command: composer test:coverage + coverage: + file: 'build/logs/clover.xml' + format: 'clover' diff --git a/src/Application/Action/User/UserCreateAction.php b/src/Application/Action/User/UserCreateAction.php index d0029f8..f3539b6 100644 --- a/src/Application/Action/User/UserCreateAction.php +++ b/src/Application/Action/User/UserCreateAction.php @@ -2,8 +2,8 @@ namespace App\Application\Action\User; -use Fig\Http\Message\StatusCodeInterface; use App\Domain\User\Service\UserCreator; +use Fig\Http\Message\StatusCodeInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; diff --git a/src/Domain/User/Repository/UserCreatorRepository.php b/src/Domain/User/Repository/UserCreatorRepository.php index 78dec0b..5db24f5 100644 --- a/src/Domain/User/Repository/UserCreatorRepository.php +++ b/src/Domain/User/Repository/UserCreatorRepository.php @@ -8,14 +8,14 @@ { public function __construct( private QueryFactory $queryFactory, - ) - { + ) { } /** * Insert user values into database. * * @param array $userValues + * * @return int */ public function insertUser(array $userValues): int @@ -23,4 +23,4 @@ public function insertUser(array $userValues): int // Insert user into database return (int)$this->queryFactory->insertQueryWithData($userValues)->into('user')->execute()->lastInsertId(); } -} \ No newline at end of file +} diff --git a/src/Domain/User/Service/UserCreator.php b/src/Domain/User/Service/UserCreator.php index 140ae96..531e915 100644 --- a/src/Domain/User/Service/UserCreator.php +++ b/src/Domain/User/Service/UserCreator.php @@ -2,9 +2,7 @@ namespace App\Domain\User\Service; -use App\Domain\User\Data\UserData; use App\Domain\User\Repository\UserCreatorRepository; -use App\Domain\User\Repository\UserFinderRepository; final readonly class UserCreator { @@ -15,7 +13,9 @@ public function __construct( } /** - * Create new user with given values + * Create new user with given values. + * + * @param array $userValues * * @return int user id */ diff --git a/src/Domain/User/Service/UserValidator.php b/src/Domain/User/Service/UserValidator.php index 726864d..15fac28 100644 --- a/src/Domain/User/Service/UserValidator.php +++ b/src/Domain/User/Service/UserValidator.php @@ -7,11 +7,10 @@ /** * User validation. - * Documentation: https://github.com/samuelgfeller/slim-example-project/wiki/Validation + * Documentation: https://github.com/samuelgfeller/slim-example-project/wiki/Validation. */ final readonly class UserValidator { - /** * Validate user values. * @@ -27,15 +26,15 @@ public function validateUserValues(array $userValues, bool $isCreateMode = true) $validator ->requirePresence('first_name', $isCreateMode, 'Field is required') - ->allowEmptyString('first_name',) // Not required field + ->allowEmptyString('first_name') // Not required field ->minLength('first_name', 2, 'Minimum length is 2') ->maxLength('first_name', 100, 'Maximum length is 100') ->requirePresence('last_name', $isCreateMode, 'Field is required') - ->allowEmptyString('last_name',) // Not required field + ->allowEmptyString('last_name') // Not required field ->minLength('last_name', 2, 'Minimum length is 2') ->maxLength('last_name', 100, 'Maximum length is 100') ->requirePresence('email', $isCreateMode, 'Field is required') - ->allowEmptyString('first_name',) // Not required field + ->allowEmptyString('first_name') // Not required field ->email('email', false, 'Invalid email') ; diff --git a/tests/Integration/User/UserCreateActionTest.php b/tests/Integration/User/UserCreateActionTest.php index 47c9e0b..2426381 100644 --- a/tests/Integration/User/UserCreateActionTest.php +++ b/tests/Integration/User/UserCreateActionTest.php @@ -36,4 +36,4 @@ public function testUserCreateAction(): void // Assert that the user was created in the database $this->assertTableRow($testUserData, 'user', $testUserData['id']); } -} \ No newline at end of file +}