-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update composer requirements: php 7.1, symfony 4.0, phpunit 7.1 * Create constraints form and entity readers * Remove constraints builders, use factories instead * Move unit tests into Tests/ * Rename ParsleyAssert\Type => ParsleyAssert\Email * Move classes * Rework bundle configuration * Better support for Type constraints * Avoid skipped tests * Update ci config
- Loading branch information
Showing
110 changed files
with
3,618 additions
and
3,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/build/ | ||
/vendor/ | ||
composer.lock | ||
/composer.lock | ||
/phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
checks: | ||
php: true | ||
|
||
filter: | ||
excluded_paths: | ||
- vendor/* | ||
excluded_paths: | ||
- 'Resources/' | ||
- 'Tests/' | ||
dependency_paths: | ||
- 'vendor/' | ||
|
||
build: | ||
nodes: | ||
analysis: | ||
tests: | ||
override: | ||
- php-scrutinizer-run | ||
- phpcs-run --extensions=php --standard=PSR2 --ignore=Resources/*,vendor/* . | ||
|
||
build_failure_conditions: | ||
- 'project.metric("scrutinizer.quality", < 9)' | ||
- 'project.metric("scrutinizer.test_coverage", < 1)' | ||
|
||
checks: | ||
php: | ||
code_rating: true | ||
|
||
tools: | ||
external_code_coverage: | ||
timeout: 500 | ||
external_code_coverage: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
<?php | ||
|
||
namespace JBen87\ParsleyBundle\Validator; | ||
namespace JBen87\ParsleyBundle\Constraint; | ||
|
||
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; | ||
use JBen87\ParsleyBundle\Exception\ConstraintException; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Serializer\Normalizer\NormalizableInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Benoit Jouhaud <[email protected]> | ||
*/ | ||
abstract class Constraint implements NormalizableInterface | ||
{ | ||
/** | ||
|
@@ -24,15 +21,15 @@ public function __construct(array $options = []) | |
{ | ||
$options = $this->configure($options); | ||
|
||
if (isset($options['message'])) { | ||
if (array_key_exists('message', $options)) { | ||
$this->message = $options['message']; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @inheritdoc | ||
*/ | ||
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) | ||
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []): array | ||
{ | ||
return [ | ||
$this->getAttribute() => $this->getValue(), | ||
|
@@ -43,37 +40,30 @@ public function normalize(NormalizerInterface $normalizer, $format = null, array | |
/** | ||
* @return string | ||
*/ | ||
abstract protected function getAttribute(); | ||
abstract protected function getAttribute(): string; | ||
|
||
/** | ||
* @return string | ||
* @throws ConstraintException | ||
*/ | ||
abstract protected function getValue(); | ||
abstract protected function getValue(): string; | ||
|
||
/** | ||
* @param OptionsResolver $resolver | ||
*/ | ||
protected function configureOptions(OptionsResolver $resolver) | ||
protected function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
} | ||
|
||
/** | ||
* @param array $options | ||
* | ||
* @return array | ||
* | ||
* @throws MissingOptionsException | ||
*/ | ||
private function configure(array $options) | ||
private function configure(array $options): array | ||
{ | ||
$resolver = new OptionsResolver(); | ||
|
||
// handle symfony version <= 2.5 | ||
if (method_exists($resolver, 'setDefined')) { | ||
$resolver->setDefined('message'); | ||
} else { | ||
$resolver->setOptional(['message']); | ||
} | ||
$resolver->setDefined('message'); | ||
|
||
$this->configureOptions($resolver); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace JBen87\ParsleyBundle\Constraint\Constraints; | ||
|
||
class Email extends Type | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getType(): string | ||
{ | ||
return static::TYPES['email']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace JBen87\ParsleyBundle\Constraint\Constraints; | ||
|
||
use JBen87\ParsleyBundle\Constraint\Constraint; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class GreaterThan extends Constraint | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function __construct(array $options = []) | ||
{ | ||
parent::__construct($options); | ||
|
||
$this->value = $options['value']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getAttribute(): string | ||
{ | ||
return 'data-parsley-gt'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getValue(): string | ||
{ | ||
return (string) $this->value; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver | ||
->setRequired(['value']) | ||
->setAllowedTypes('value', ['int']) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace JBen87\ParsleyBundle\Constraint\Constraints; | ||
|
||
use JBen87\ParsleyBundle\Constraint\Constraint; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class Length extends Constraint | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $min; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $max; | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function __construct(array $options = []) | ||
{ | ||
parent::__construct($options); | ||
|
||
$this->min = $options['min']; | ||
$this->max = $options['max']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getAttribute(): string | ||
{ | ||
return 'data-parsley-length'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getValue(): string | ||
{ | ||
return sprintf('[%d, %d]', $this->min, $this->max); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver | ||
->setRequired(['min', 'max']) | ||
->setAllowedTypes('min', ['int']) | ||
->setAllowedTypes('max', ['int']) | ||
; | ||
} | ||
} |
Oops, something went wrong.