Skip to content

Commit

Permalink
Added scrutinizer [SLE-197]
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgfeller committed Apr 1, 2024
1 parent c22da9c commit e57fcdb
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 18 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
pull_request:
types: [ opened, synchronize, reopened ]

env:
APP_ENV: github

jobs:
run:
runs-on: ${{ matrix.operating-system }}
Expand Down Expand Up @@ -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
APP_ENV: github
PHP_CS_FIXER_IGNORE_ENV: 1
46 changes: 46 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion src/Application/Action/User/UserCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Domain/User/Repository/UserCreatorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
{
public function __construct(
private QueryFactory $queryFactory,
)
{
) {
}

/**
* Insert user values into database.
*
* @param array $userValues
*
* @return int
*/
public function insertUser(array $userValues): int
{
// Insert user into database
return (int)$this->queryFactory->insertQueryWithData($userValues)->into('user')->execute()->lastInsertId();
}
}
}
6 changes: 3 additions & 3 deletions src/Domain/User/Service/UserCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
*/
Expand Down
9 changes: 4 additions & 5 deletions src/Domain/User/Service/UserValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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')
;

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/User/UserCreateActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public function testUserCreateAction(): void
// Assert that the user was created in the database
$this->assertTableRow($testUserData, 'user', $testUserData['id']);
}
}
}

0 comments on commit e57fcdb

Please sign in to comment.