Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v2 #12

Merged
merged 17 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/build/
/vendor/
composer.lock
/composer.lock
/phpunit.xml
29 changes: 22 additions & 7 deletions .scrutinizer.yml
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
35 changes: 11 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

env:
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.7.*
- SYMFONY_VERSION=2.8.*
- SYMFONY_VERSION=3.0.*
- SYMFONY_VERSION=3.1.*

matrix:
exclude:
- php: 5.4
env: SYMFONY_VERSION=3.0.*
- php: 5.4
env: SYMFONY_VERSION=3.1.*

before_install:
- pear install pear/PHP_CodeSniffer
- phpenv rehash
- composer self-update
- SYMFONY_VERSION=4.0.*

sudo: false

cache:
directories:
- $HOME/.composer/cache

install:
- composer require symfony/symfony:${SYMFONY_VERSION}

script:
- phpunit --coverage-clover=coverage.clover --coverage-text
- phpcs --ignore=/vendor/* --extensions=php --encoding=utf-8 --standard=PSR2 -np .
- vendor/bin/phpunit --coverage-clover=build/coverage/clover.xml --coverage-text

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --access-token="b64151e5c9d22d8cae4165f73c8c90d4542f1bb03e8e424a6301c3cbbc24ce4b" --format=php-clover coverage.clover
- php ocular.phar code-coverage:upload --format=php-clover build/coverage/clover.xml

notifications:
email:
Expand Down
19 changes: 0 additions & 19 deletions Builder/BuilderInterface.php

This file was deleted.

65 changes: 0 additions & 65 deletions Builder/ConstraintBuilder.php

This file was deleted.

32 changes: 11 additions & 21 deletions Validator/Constraint.php → Constraint/Constraint.php
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 <bjouhaud@prestaconcept.net>
*/
abstract class Constraint implements NormalizableInterface
{
/**
Expand All @@ -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(),
Expand All @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions Constraint/Constraints/Email.php
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'];
}
}
51 changes: 51 additions & 0 deletions Constraint/Constraints/GreaterThan.php
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'])
;
}
}
58 changes: 58 additions & 0 deletions Constraint/Constraints/Length.php
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'])
;
}
}
Loading