apply suggestions
continuous-integration/drone/push Build is passing Details

pull/13/head
maxime.batista 1 year ago
parent 185a4d19bb
commit bb53114d78

@ -5,7 +5,7 @@ $finder = (new PhpCsFixer\Finder())->in(__DIR__);
return (new PhpCsFixer\Config()) return (new PhpCsFixer\Config())
->setRules([ ->setRules([
'@PER-CS' => true, '@PER-CS' => true,
'@PHP82Migration' => true, '@PHP74Migration' => true,
'array_syntax' => ['syntax' => 'short'], 'array_syntax' => ['syntax' => 'short'],
'braces_position' => [ 'braces_position' => [
'classes_opening_brace' => 'same_line', 'classes_opening_brace' => 'same_line',

@ -21,7 +21,7 @@ steps:
- image: composer:latest - image: composer:latest
name: "php CI" name: "php CI"
commands: commands:
- composer install && composer update - composer install
- vendor/bin/phpstan analyze - vendor/bin/phpstan analyze
- image: node:latest - image: node:latest

@ -22,7 +22,7 @@
"build": "vite build", "build": "vite build",
"test": "vite test", "test": "vite test",
"format": "prettier --config .prettierrc 'front' --write", "format": "prettier --config .prettierrc 'front' --write",
"tsc": "node_modules/.bin/tsc" "tsc": "tsc"
}, },
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [

@ -4,12 +4,10 @@ parameters:
paths: paths:
- src - src
- public - public
- sql scanFiles:
ignoreErrors: - config.php
- - sql/database.php
message: '#.*#' - profiles/dev-config-profile.php
path: sql/database.php - profiles/prod-config-profile.php
- excludePaths:
message: '#.*#' - src/react-display-file.php
path: src/react-display-file.php

@ -14,7 +14,7 @@ class Control {
/** /**
* Runs given callback, if the request's json validates the given schema. * Runs given callback, if the request's json validates the given schema.
* @param array<string, Validator[]> $schema an array of `fieldName => Validators` which represents the request object schema * @param array<string, Validator[]> $schema an array of `fieldName => Validators` which represents the request object schema
* @param callable $run the callback to run if the request is valid according to the given schema. * @param callable(HttpRequest): HttpResponse $run the callback to run if the request is valid according to the given schema.
* THe callback must accept an HttpRequest, and return an HttpResponse object. * THe callback must accept an HttpRequest, and return an HttpResponse object.
* @param bool $errorInJson if set to true, the returned response, in case of errors, will be a JsonHttpResponse, instead * @param bool $errorInJson if set to true, the returned response, in case of errors, will be a JsonHttpResponse, instead
* of the ViewHttpResponse for an error view. * of the ViewHttpResponse for an error view.
@ -38,7 +38,7 @@ class Control {
* Runs given callback, if the given request data array validates the given schema. * Runs given callback, if the given request data array validates the given schema.
* @param array<string, mixed> $data the request's data array. * @param array<string, mixed> $data the request's data array.
* @param array<string, Validator[]> $schema an array of `fieldName => Validators` which represents the request object schema * @param array<string, Validator[]> $schema an array of `fieldName => Validators` which represents the request object schema
* @param callable $run the callback to run if the request is valid according to the given schema. * @param callable(HttpRequest): HttpResponse $run the callback to run if the request is valid according to the given schema.
* THe callback must accept an HttpRequest, and return an HttpResponse object. * THe callback must accept an HttpRequest, and return an HttpResponse object.
* @param bool $errorInJson if set to true, the returned response, in case of errors, will be a JsonHttpResponse, instead * @param bool $errorInJson if set to true, the returned response, in case of errors, will be a JsonHttpResponse, instead
* of the ViewHttpResponse for an error view. * of the ViewHttpResponse for an error view.

@ -31,7 +31,7 @@ class SampleFormController {
/** /**
* @param array<string, mixed> $form * @param array<string, mixed> $form
* @param callable $response * @param callable(array<array<string, string>>): ViewHttpResponse $response
* @return HttpResponse * @return HttpResponse
*/ */
private function submitForm(array $form, callable $response): HttpResponse { private function submitForm(array $form, callable $response): HttpResponse {

@ -29,7 +29,7 @@ class Account {
private AccountUser $user; private AccountUser $user;
/** /**
* @var array<int, Team> account's teams * @var Team[] account's teams
*/ */
private array $teams; private array $teams;
@ -43,7 +43,7 @@ class Account {
* @param string $email * @param string $email
* @param string $phoneNumber * @param string $phoneNumber
* @param AccountUser $user * @param AccountUser $user
* @param array<int, Team> $teams * @param Team[] $teams
* @param int $id * @param int $id
*/ */
public function __construct(string $email, string $phoneNumber, AccountUser $user, array $teams, int $id) { public function __construct(string $email, string $phoneNumber, AccountUser $user, array $teams, int $id) {

@ -11,7 +11,7 @@ class Team {
private Color $secondColor; private Color $secondColor;
/** /**
* @var array<int, Member> maps users with their role * @var Member[] maps users with their role
*/ */
private array $members; private array $members;
@ -20,7 +20,7 @@ class Team {
* @param Url $picture * @param Url $picture
* @param Color $mainColor * @param Color $mainColor
* @param Color $secondColor * @param Color $secondColor
* @param array<int, Member> $members * @param Member[] $members
*/ */
public function __construct(string $name, Url $picture, Color $mainColor, Color $secondColor, array $members) { public function __construct(string $name, Url $picture, Color $mainColor, Color $secondColor, array $members) {
$this->name = $name; $this->name = $name;
@ -59,7 +59,7 @@ class Team {
} }
/** /**
* @return array<int, Member> * @return Member[]
*/ */
public function listMembers(): array { public function listMembers(): array {
return $this->members; return $this->members;

@ -30,7 +30,7 @@ class HttpRequest implements ArrayAccess {
* This is a simple function that only supports flat schemas (non-composed, the data must only be a k/v array pair.) * This is a simple function that only supports flat schemas (non-composed, the data must only be a k/v array pair.)
* @param array<string, mixed> $request the request's data * @param array<string, mixed> $request the request's data
* @param array<string, ValidationFail> $fails a reference to a failure array, that will contain the reported validation failures. * @param array<string, ValidationFail> $fails a reference to a failure array, that will contain the reported validation failures.
* @param array<string, array<int, Validator>> $schema the schema to satisfy. a schema is a simple array with a string key (which is the top-level field name), and a set of validators * @param array<string, Validator[]> $schema the schema to satisfy. a schema is a simple array with a string key (which is the top-level field name), and a set of validators
* @return HttpRequest|null the built HttpRequest instance, or null if a field is missing, or if any of the schema validator failed * @return HttpRequest|null the built HttpRequest instance, or null if a field is missing, or if any of the schema validator failed
*/ */
public static function from(array $request, array &$fails, array $schema): ?HttpRequest { public static function from(array $request, array &$fails, array $schema): ?HttpRequest {
@ -65,7 +65,6 @@ class HttpRequest implements ArrayAccess {
/** /**
* @param $offset * @param $offset
* @param $value * @param $value
* @return mixed
* @throws Exception * @throws Exception
*/ */
public function offsetSet($offset, $value) { public function offsetSet($offset, $value) {

@ -4,12 +4,12 @@ namespace App\Validation;
class FunctionValidator extends Validator { class FunctionValidator extends Validator {
/** /**
* @var callable * @var callable(string, mixed): ValidationFail[]
*/ */
private $validate_fn; private $validate_fn;
/** /**
* @param callable $validate_fn the validate function. Must have the same signature as the {@link Validator::validate()} method. * @param callable(string, mixed): ValidationFail[] $validate_fn the validate function. Must have the same signature as the {@link Validator::validate()} method.
*/ */
public function __construct(callable $validate_fn) { public function __construct(callable $validate_fn) {
$this->validate_fn = $validate_fn; $this->validate_fn = $validate_fn;

@ -7,17 +7,17 @@ namespace App\Validation;
*/ */
class SimpleFunctionValidator extends Validator { class SimpleFunctionValidator extends Validator {
/** /**
* @var callable * @var callable(mixed): bool
*/ */
private $predicate; private $predicate;
/** /**
* @var callable * @var callable(string): ValidationFail[]
*/ */
private $errorFactory; private $errorFactory;
/** /**
* @param callable $predicate a function predicate with signature: `(string) => bool`, to validate the given string * @param callable(mixed): bool $predicate a function predicate with signature: `(string) => bool`, to validate the given string
* @param callable $errorsFactory a factory function with signature `(string) => array` to emit failures when the predicate fails * @param callable(string): ValidationFail[] $errorsFactory a factory function with signature `(string) => array` to emit failures when the predicate fails
*/ */
public function __construct(callable $predicate, callable $errorsFactory) { public function __construct(callable $predicate, callable $errorsFactory) {
$this->predicate = $predicate; $this->predicate = $predicate;

@ -10,7 +10,7 @@ class Validation {
* Validate a value from validators, appending failures in the given errors array. * Validate a value from validators, appending failures in the given errors array.
* @param mixed $val the value to validate * @param mixed $val the value to validate
* @param string $valName the name of the value * @param string $valName the name of the value
* @param array<int, ValidationFail> $failures array to push when a validator fails * @param ValidationFail[] $failures array to push when a validator fails
* @param Validator ...$validators given validators * @param Validator ...$validators given validators
* @return bool true if any of the given validators did fail * @return bool true if any of the given validators did fail
*/ */

@ -7,7 +7,7 @@ abstract class Validator {
* validates a variable string * validates a variable string
* @param string $name the name of the tested value * @param string $name the name of the tested value
* @param mixed $val the value to validate * @param mixed $val the value to validate
* @return array<int, ValidationFail> the errors the validator has reported * @return ValidationFail[] the errors the validator has reported
*/ */
abstract public function validate(string $name, $val): array; abstract public function validate(string $name, $val): array;

@ -9,7 +9,7 @@ class Validators {
/** /**
* @return Validator a validator that validates a given regex * @return Validator a validator that validates a given regex
*/ */
public static function regex(string $regex, string $msg = null): Validator { public static function regex(string $regex, ?string $msg = null): Validator {
return new SimpleFunctionValidator( return new SimpleFunctionValidator(
fn(string $str) => preg_match($regex, $str), fn(string $str) => preg_match($regex, $str),
fn(string $name) => [new FieldValidationFail($name, $msg == null ? "field does not validates pattern $regex" : $msg)] fn(string $name) => [new FieldValidationFail($name, $msg == null ? "field does not validates pattern $regex" : $msg)]
@ -19,7 +19,7 @@ class Validators {
/** /**
* @return Validator a validator that validates strings that only contains numbers, letters, accents letters, `-` and `_`. * @return Validator a validator that validates strings that only contains numbers, letters, accents letters, `-` and `_`.
*/ */
public static function name(string $msg = null): Validator { public static function name(?string $msg = null): Validator {
return self::regex("/^[0-9a-zA-Zà-üÀ-Ü_-]*$/", $msg); return self::regex("/^[0-9a-zA-Zà-üÀ-Ü_-]*$/", $msg);
} }

Loading…
Cancel
Save