mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 06:42:22 +02:00
Setup PHPStan (PHP Static Analysis Tool)
Require "phpstan/phpstan" for development and add to the Travis CI configuration file to execute the analysis when Travis executes the build with the version 7.2 of PHP. The level of the configuration is very week for now (just "1") and still quite some changes had to be made in order to make the analysis pass. I hope it does not take much time to increase the level of the strictness of the analyses. I tried to configure that before but because of dependencies with "symfony/validator" it was not possible. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
f5c167c411
commit
258a456eec
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,5 +2,6 @@
|
|||
.couscous/
|
||||
composer.lock
|
||||
Makefile
|
||||
phpstan.neon
|
||||
phpunit.xml
|
||||
vendor/
|
||||
|
|
|
@ -33,6 +33,10 @@ script:
|
|||
if [[ "${TRAVIS_PHP_VERSION}" == "7.2" ]]; then
|
||||
vendor/bin/php-cs-fixer --diff --dry-run --verbose fix
|
||||
fi
|
||||
- |
|
||||
if [[ "${TRAVIS_PHP_VERSION}" == "7.2" ]]; then
|
||||
vendor/bin/phpstan analyze
|
||||
fi
|
||||
|
||||
after_script:
|
||||
- |
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
"friendsofphp/php-cs-fixer": "^2.8",
|
||||
"malukenho/docheader": "^0.1.4",
|
||||
"mikey179/vfsStream": "^1.6",
|
||||
"phpstan/phpstan": "^0.10.3",
|
||||
"phpunit/phpunit": "^6.4",
|
||||
"symfony/validator": "^3.0||^4.0",
|
||||
"zendframework/zend-validator": "^2.0"
|
||||
|
@ -41,6 +42,7 @@
|
|||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Respect\\Validation\\": "tests/unit/",
|
||||
"Respect\\Validation\\Test\\": "tests/library/"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -80,7 +80,8 @@ class ValidationException extends InvalidArgumentException implements Exception
|
|||
$this->params = $params;
|
||||
$this->translator = $translator;
|
||||
$this->template = $this->chooseTemplate();
|
||||
$this->message = $this->createMessage();
|
||||
|
||||
parent::__construct($this->createMessage());
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
|
|
|
@ -38,6 +38,8 @@ class Domain extends AbstractComposite
|
|||
),
|
||||
new Not(new EndsWith('-'))
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function tldCheck($do = true)
|
||||
|
|
|
@ -27,11 +27,11 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|||
* @method static Validator alpha(string $additionalChars = null)
|
||||
* @method static Validator alwaysInvalid()
|
||||
* @method static Validator alwaysValid()
|
||||
* @method static Validator anyOf()
|
||||
* @method static Validator anyOf(Validatable ...$rule)
|
||||
* @method static Validator arrayType()
|
||||
* @method static Validator arrayVal()
|
||||
* @method static Validator attribute(string $reference, Validatable $validator = null, bool $mandatory = true)
|
||||
* @method static Validator base()
|
||||
* @method static Validator base(int $base, string $chars = null)
|
||||
* @method static Validator base64()
|
||||
* @method static Validator between($minimum, $maximum)
|
||||
* @method static Validator bic(string $countryCode)
|
||||
|
@ -92,7 +92,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|||
* @method static Validator keyNested(string $reference, Validatable $referenceValidator = null, bool $mandatory = true)
|
||||
* @method static Validator keySet(Key ...$rule)
|
||||
* @method static Validator keyValue(string $comparedKey, string $ruleName, string $baseKey)
|
||||
* @method static Validator languageCode(string $set)
|
||||
* @method static Validator languageCode(string $set = null)
|
||||
* @method static Validator leapDate(string $format)
|
||||
* @method static Validator leapYear()
|
||||
* @method static Validator length(int $min = null, int $max = null, bool $inclusive = true)
|
||||
|
|
11
phpstan.neon.dist
Normal file
11
phpstan.neon.dist
Normal file
|
@ -0,0 +1,11 @@
|
|||
parameters:
|
||||
fileExtensions:
|
||||
- php
|
||||
- phpt
|
||||
ignoreErrors:
|
||||
- '/Call to an undefined static method Respect\\Validation\\Validator::iDoNotExistSoIShouldThrowException/'
|
||||
- '/Function Respect\\Validation\\Rules\\is_(file|readable|link|writable) not found/'
|
||||
level: 1
|
||||
paths:
|
||||
- library/
|
||||
- tests/
|
|
@ -2,19 +2,19 @@
|
|||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\intValException;
|
||||
use Respect\Validation\Exceptions\IntValException;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::intVal()->check('42.33');
|
||||
} catch (intValException $exception) {
|
||||
} catch (IntValException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::intVal())->check(2);
|
||||
} catch (intValException $exception) {
|
||||
} catch (IntValException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,22 +4,15 @@
|
|||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Test\Stubs\CountableStub;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
class MyClass
|
||||
{
|
||||
public function parse($url)
|
||||
{
|
||||
return parse_url($url);
|
||||
}
|
||||
}
|
||||
|
||||
$input = 'http://www.google.com/search?q=respect.github.com';
|
||||
|
||||
try {
|
||||
v::create()
|
||||
->call(
|
||||
[new MyClass(), 'parse'],
|
||||
[new CountableStub(1), 'count'],
|
||||
v::arrayVal()->key('scheme', v::startsWith('https'))
|
||||
)
|
||||
->assert($input);
|
||||
|
|
|
@ -52,6 +52,6 @@ final class Stub extends AbstractRule
|
|||
{
|
||||
$this->inputs[] = $input;
|
||||
|
||||
return (bool) array_shift($validations);
|
||||
return (bool) array_shift($this->validations);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,9 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Test\Helpers;
|
||||
namespace Respect\Validation\Helpers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Respect\Validation\Helpers\DateTimeHelper;
|
||||
|
||||
/**
|
||||
* @group helper
|
||||
|
|
|
@ -11,10 +11,9 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Test\Helpers;
|
||||
namespace Respect\Validation\Helpers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Respect\Validation\Helpers\UndefinedHelper;
|
||||
use Respect\Validation\Test\DataProvider\UndefinedProvider;
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,7 +36,8 @@ final class CreditCardTest extends RuleTestCase
|
|||
$message = '"RespectCard" is not a valid credit card brand';
|
||||
$message .= ' (Available: Any, American Express, Diners Club, Discover, JCB, MasterCard, Visa)';
|
||||
|
||||
$this->expectException(ComponentException::class, $message);
|
||||
$this->expectException(ComponentException::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
|
||||
new CreditCard('RespectCard');
|
||||
}
|
||||
|
|
|
@ -47,10 +47,8 @@ class FactorTest extends TestCase
|
|||
*/
|
||||
public function invalidFactorShouldThrowFactorException($dividend, $input): void
|
||||
{
|
||||
$this->expectException(
|
||||
FactorException::class,
|
||||
stringify($input).' must be a factor of '.$dividend
|
||||
);
|
||||
$this->expectException(FactorException::class);
|
||||
$this->expectExceptionMessage(stringify($input).' must be a factor of '.$dividend);
|
||||
|
||||
$min = new Factor($dividend);
|
||||
self::assertFalse($min->__invoke($input));
|
||||
|
@ -64,10 +62,8 @@ class FactorTest extends TestCase
|
|||
*/
|
||||
public function invalidDividentShouldThrowComponentException($dividend, $input): void
|
||||
{
|
||||
$this->expectException(
|
||||
ComponentException::class,
|
||||
'Dividend '.stringify($dividend).' must be an integer'
|
||||
);
|
||||
$this->expectException(ComponentException::class);
|
||||
$this->expectExceptionMessage('Dividend '.stringify($dividend).' must be an integer');
|
||||
|
||||
// It is enough to simply create a new Factor to trigger the dividend
|
||||
// exceptions in __construct.
|
||||
|
@ -168,7 +164,7 @@ class FactorTest extends TestCase
|
|||
uniqid('a'),
|
||||
// Non-scalars.
|
||||
[],
|
||||
new \StdClass(),
|
||||
new \stdClass(),
|
||||
new \DateTime(),
|
||||
null,
|
||||
true,
|
||||
|
|
|
@ -71,7 +71,7 @@ class FileTest extends TestCase
|
|||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new File();
|
||||
$object = $this->createMock('SplFileInfo', ['isFile'], ['somefile.txt']);
|
||||
$object = $this->createMock('SplFileInfo');
|
||||
$object->expects(self::once())
|
||||
->method('isFile')
|
||||
->will(self::returnValue(true));
|
||||
|
|
|
@ -59,7 +59,7 @@ class PhpLabelTest extends RuleTestCase
|
|||
[$rule, 0],
|
||||
[$rule, 1],
|
||||
[$rule, []],
|
||||
[$rule, new \StdClass()],
|
||||
[$rule, new \stdClass()],
|
||||
[$rule, new \DateTime()],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ class ReadableTest extends TestCase
|
|||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new Readable();
|
||||
$object = $this->createMock('SplFileInfo', ['isReadable'], ['somefile.txt']);
|
||||
$object = $this->createMock('SplFileInfo');
|
||||
$object->expects(self::once())
|
||||
->method('isReadable')
|
||||
->will(self::returnValue(true));
|
||||
|
|
|
@ -71,7 +71,7 @@ class SymbolicLinkTest extends TestCase
|
|||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new SymbolicLink();
|
||||
$object = $this->createMock('SplFileInfo', ['isLink'], ['somelink.lnk']);
|
||||
$object = $this->createMock('SplFileInfo');
|
||||
$object->expects(self::once())
|
||||
->method('isLink')
|
||||
->will(self::returnValue(true));
|
||||
|
|
|
@ -71,7 +71,7 @@ class WritableTest extends TestCase
|
|||
public function shouldValidateObjects(): void
|
||||
{
|
||||
$rule = new Writable();
|
||||
$object = $this->createMock('SplFileInfo', ['isWritable'], ['somefile.txt']);
|
||||
$object = $this->createMock('SplFileInfo');
|
||||
$object->expects(self::once())
|
||||
->method('isWritable')
|
||||
->will(self::returnValue(true));
|
||||
|
|
Loading…
Reference in a new issue