Skip to content

Commit

Permalink
Update coding standards
Browse files Browse the repository at this point in the history
This change will bring many breaking changes. The good thing is that we
can finally use more modern resources available in PHP.

I can imagine that's not a popular change since it will bring many
breaking changes to users, but we shouldn't be stuck in time because of
that. Using some of those features will make it easier to contribute to
the project. At least, I hope so.

There are still some useless doc-blocks, and we're not using "readonly"
properties when we could. I aim to send those changes soon.

Signed-off-by: Henrique Moody <[email protected]>
  • Loading branch information
henriquemoody committed Jan 27, 2024
1 parent d98d010 commit 9a13c9f
Show file tree
Hide file tree
Showing 531 changed files with 1,003 additions and 5,387 deletions.
24 changes: 5 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@ declare(strict_types=1);

namespace Respect\Validation\Rules;

/**
* Explain in one sentence what this rule does.
*
* @author Your Name <youremail@yourdomain.tld>
*/
final class HelloWorld extends AbstractRule
{
/**
* {@inheritDoc}
*/
public function validate($input): bool
public function validate(mixed $input): bool
{
return $input === 'Hello World';
}
Expand All @@ -98,15 +90,12 @@ declare(strict_types=1);

namespace Respect\Validation\Exceptions;

/**
* @author Your Name <youremail@yourdomain.tld>
*/
final class HelloWorldException extends ValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a Hello World',
],
Expand Down Expand Up @@ -147,15 +136,12 @@ use Respect\Validation\Test\RuleTestCase;

/**
* @group rule
*
* @covers \Respect\Validation\Rules\HelloWorld
*
* @author Your Name <youremail@yourdomain.tld>
*/
final class HelloWorldTest extends RuleTestCase
{
/**
* {@inheritDoc}
* @return array<array{HelloWorld, mixed}>
*/
public static function providerForValidInput(): array
{
Expand All @@ -167,7 +153,7 @@ final class HelloWorldTest extends RuleTestCase
}

/**
* {@inheritDoc}
* @return array<array{HelloWorld, mixed}>
*/
public static function providerForInvalidInput(): array
{
Expand Down
5 changes: 4 additions & 1 deletion docs/custom-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use Respect\Validation\Exceptions\ValidationException;

final class SomethingException extends ValidationException
{
protected $defaultTemplates = [
/**
* @var array<string, array<string, string>>
*/
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'Validation message if Something fails validation.',
],
Expand Down
63 changes: 13 additions & 50 deletions library/ChainedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public function base(int $base, ?string $chars = null): ChainedValidator;

public function base64(): ChainedValidator;

/**
* @param mixed $minimum
* @param mixed $maximum
*/
public function between($minimum, $maximum): ChainedValidator;
public function between(mixed $minimum, mixed $maximum): ChainedValidator;

public function boolType(): ChainedValidator;

Expand All @@ -68,10 +64,7 @@ public function control(string ...$additionalChars): ChainedValidator;

public function consonant(string ...$additionalChars): ChainedValidator;

/**
* @param mixed $containsValue
*/
public function contains($containsValue, bool $identical = false): ChainedValidator;
public function contains(mixed $containsValue, bool $identical = false): ChainedValidator;

/**
* @param mixed[] $needles
Expand Down Expand Up @@ -104,20 +97,11 @@ public function each(Validatable $rule): ChainedValidator;

public function email(): ChainedValidator;

/**
* @param mixed $endValue
*/
public function endsWith($endValue, bool $identical = false): ChainedValidator;
public function endsWith(mixed $endValue, bool $identical = false): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function equals($compareTo): ChainedValidator;
public function equals(mixed $compareTo): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function equivalent($compareTo): ChainedValidator;
public function equivalent(mixed $compareTo): ChainedValidator;

public function even(): ChainedValidator;

Expand All @@ -138,7 +122,7 @@ public function file(): ChainedValidator;
/**
* @param mixed[]|int $options
*/
public function filterVar(int $filter, $options = null): ChainedValidator;
public function filterVar(int $filter, array|int|null $options = null): ChainedValidator;

public function finite(): ChainedValidator;

Expand All @@ -148,28 +132,19 @@ public function floatType(): ChainedValidator;

public function graph(string ...$additionalChars): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function greaterThan($compareTo): ChainedValidator;
public function greaterThan(mixed $compareTo): ChainedValidator;

public function hexRgbColor(): ChainedValidator;

public function iban(): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function identical($compareTo): ChainedValidator;
public function identical(mixed $compareTo): ChainedValidator;

public function image(?finfo $fileInfo = null): ChainedValidator;

public function imei(): ChainedValidator;

/**
* @param mixed[]|mixed $haystack
*/
public function in($haystack, bool $compareIdentical = false): ChainedValidator;
public function in(mixed $haystack, bool $compareIdentical = false): ChainedValidator;

public function infinite(): ChainedValidator;

Expand Down Expand Up @@ -213,28 +188,19 @@ public function length(?int $min = null, ?int $max = null, bool $inclusive = tru

public function lowercase(): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function lessThan($compareTo): ChainedValidator;
public function lessThan(mixed $compareTo): ChainedValidator;

public function luhn(): ChainedValidator;

public function macAddress(): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function max($compareTo): ChainedValidator;
public function max(mixed $compareTo): ChainedValidator;

public function maxAge(int $age, ?string $format = null): ChainedValidator;

public function mimetype(string $mimetype): ChainedValidator;

/**
* @param mixed $compareTo
*/
public function min($compareTo): ChainedValidator;
public function min(mixed $compareTo): ChainedValidator;

public function minAge(int $age, ?string $format = null): ChainedValidator;

Expand Down Expand Up @@ -324,10 +290,7 @@ public function sorted(string $direction): ChainedValidator;

public function space(string ...$additionalChars): ChainedValidator;

/**
* @param mixed $startValue
*/
public function startsWith($startValue, bool $identical = false): ChainedValidator;
public function startsWith(mixed $startValue, bool $identical = false): ChainedValidator;

public function stringType(): ChainedValidator;

Expand Down
8 changes: 2 additions & 6 deletions library/Exceptions/AllOfException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
*/
class AllOfException extends GroupedValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::NONE => 'All of the required rules must pass for {{name}}',
self::SOME => 'These rules must pass for {{name}}',
Expand Down
8 changes: 2 additions & 6 deletions library/Exceptions/AlnumException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class AlnumException extends FilteredValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only letters (a-z) and digits (0-9)',
self::EXTRA => '{{name}} must contain only letters (a-z), digits (0-9) and {{additionalChars}}',
Expand Down
8 changes: 2 additions & 6 deletions library/Exceptions/AlphaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class AlphaException extends FilteredValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only letters (a-z)',
self::EXTRA => '{{name}} must contain only letters (a-z) and {{additionalChars}}',
Expand Down
9 changes: 2 additions & 7 deletions library/Exceptions/AlwaysInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class AlwaysInvalidException extends ValidationException
{
public const SIMPLE = 'simple';

/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} is always invalid',
self::SIMPLE => '{{name}} is not valid',
Expand Down
9 changes: 2 additions & 7 deletions library/Exceptions/AlwaysValidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
* @author William Espindola <[email protected]>
*/
final class AlwaysValidException extends ValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} is always valid',
],
Expand Down
8 changes: 2 additions & 6 deletions library/Exceptions/AnyOfException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class AnyOfException extends NestedValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => 'At least one of these rules must pass for {{name}}',
],
Expand Down
10 changes: 2 additions & 8 deletions library/Exceptions/ArrayTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Emmerson Siqueira <[email protected]>
* @author Henrique Moody <[email protected]>
* @author João Torquato <[email protected]>
*/
final class ArrayTypeException extends ValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be of type array',
],
Expand Down
9 changes: 2 additions & 7 deletions library/Exceptions/ArrayValException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@

namespace Respect\Validation\Exceptions;

/**
* @author Alexandre Gomes Gaigalas <[email protected]>
* @author Emmerson Siqueira <[email protected]>
* @author Henrique Moody <[email protected]>
*/
final class ArrayValException extends ValidationException
{
/**
* {@inheritDoc}
* @var array<string, array<string, string>>
*/
protected $defaultTemplates = [
protected array $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be an array value',
],
Expand Down
Loading

0 comments on commit 9a13c9f

Please sign in to comment.