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())
->setRules([
'@PER-CS' => true,
'@PHP82Migration' => true,
'@PHP74Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'braces_position' => [
'classes_opening_brace' => 'same_line',

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

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

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

@ -14,7 +14,7 @@ class Control {
/**
* 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 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.
* @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.
@ -38,7 +38,7 @@ class Control {
* 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, 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.
* @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.

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

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

@ -11,7 +11,7 @@ class Team {
private Color $secondColor;
/**
* @var array<int, Member> maps users with their role
* @var Member[] maps users with their role
*/
private array $members;
@ -20,7 +20,7 @@ class Team {
* @param Url $picture
* @param Color $mainColor
* @param Color $secondColor
* @param array<int, Member> $members
* @param Member[] $members
*/
public function __construct(string $name, Url $picture, Color $mainColor, Color $secondColor, array $members) {
$this->name = $name;
@ -59,7 +59,7 @@ class Team {
}
/**
* @return array<int, Member>
* @return Member[]
*/
public function listMembers(): array {
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.)
* @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, 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
*/
public static function from(array $request, array &$fails, array $schema): ?HttpRequest {
@ -65,7 +65,6 @@ class HttpRequest implements ArrayAccess {
/**
* @param $offset
* @param $value
* @return mixed
* @throws Exception
*/
public function offsetSet($offset, $value) {

@ -4,12 +4,12 @@ namespace App\Validation;
class FunctionValidator extends Validator {
/**
* @var callable
* @var callable(string, mixed): ValidationFail[]
*/
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) {
$this->validate_fn = $validate_fn;

@ -7,17 +7,17 @@ namespace App\Validation;
*/
class SimpleFunctionValidator extends Validator {
/**
* @var callable
* @var callable(mixed): bool
*/
private $predicate;
/**
* @var callable
* @var callable(string): ValidationFail[]
*/
private $errorFactory;
/**
* @param callable $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(mixed): bool $predicate a function predicate with signature: `(string) => bool`, to validate the given string
* @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) {
$this->predicate = $predicate;

@ -10,7 +10,7 @@ class Validation {
* Validate a value from validators, appending failures in the given errors array.
* @param mixed $val the value to validate
* @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
* @return bool true if any of the given validators did fail
*/

@ -7,7 +7,7 @@ abstract class Validator {
* validates a variable string
* @param string $name the name of the tested value
* @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;

@ -9,7 +9,7 @@ class Validators {
/**
* @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(
fn(string $str) => preg_match($regex, $str),
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 `_`.
*/
public static function name(string $msg = null): Validator {
public static function name(?string $msg = null): Validator {
return self::regex("/^[0-9a-zA-Zà-üÀ-Ü_-]*$/", $msg);
}

Loading…
Cancel
Save