Skip to content

Commit

Permalink
Dumped PHP dependency to 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
boekkooi committed Jan 13, 2016
1 parent 6aec450 commit 118d088
Show file tree
Hide file tree
Showing 68 changed files with 354 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
matrix:
include:
# [PHPUnit] Test symfony versions
- php: 5.3.3
- php: 5.5
env: |
COMPOSER_FLAGS='--prefer-stable --prefer-lowest'
PHPUNIT_COVERAGE='--coverage-text --coverage-clover=coverage.clover'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": [ "jquery", "form", "validation", "validator", "symfony", "twig"],
"description": "Jquery form validation bundle for symfony 2",
"require": {
"php": ">=5.3.3",
"php": ">=5.5",
"symfony/framework-bundle": "~2.3|~3.0",
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/form": "~2.3, >=2.3.5|~3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Extension/FormTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getExtendedType()
{
return FormHelper::isSymfony3Compatible() ? 'Symfony\Component\Form\Extension\Core\Type\FormType' : 'form';
return FormHelper::isSymfony3Compatible() ? FormType::class : 'form';
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Form/Rule/Mapping/CreditcardRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\CardScheme;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand All @@ -25,7 +26,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\CardScheme $constraint */
/** @var CardScheme $constraint */
// TODO support schemes
$collection->set(
self::RULE_NAME,
Expand All @@ -40,6 +41,6 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
return get_class($constraint) === 'Symfony\Component\Validator\Constraints\CardScheme';
return get_class($constraint) === CardScheme::class;
}
}
5 changes: 3 additions & 2 deletions src/Form/Rule/Mapping/EmailRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Email;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand All @@ -25,7 +26,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\Email $constraint */
/** @var Email $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
Expand All @@ -39,6 +40,6 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
return get_class($constraint) === 'Symfony\Component\Validator\Constraints\Email';
return get_class($constraint) === Email::class;
}
}
6 changes: 3 additions & 3 deletions src/Form/Rule/Mapping/FileRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintRule;
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintMapperInterface;
use Symfony\Component\Validator\Constraints\File;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand Down Expand Up @@ -35,7 +36,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\File $constraint */
/** @var File $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
Expand All @@ -51,9 +52,8 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
/** @var \Symfony\Component\Validator\Constraints\File $constraint */
return $this->active &&
get_class($constraint) === 'Symfony\Component\Validator\Constraints\File' &&
get_class($constraint) === File::class &&
!empty($constraint->mimeTypes);
}
}
5 changes: 3 additions & 2 deletions src/Form/Rule/Mapping/IbanRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Iban;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand Down Expand Up @@ -35,7 +36,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\Iban $constraint */
/** @var Iban $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
Expand All @@ -49,6 +50,6 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
return $this->active && get_class($constraint) === 'Symfony\Component\Validator\Constraints\Iban';
return $this->active && get_class($constraint) === Iban::class;
}
}
4 changes: 2 additions & 2 deletions src/Form/Rule/Mapping/IpRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\Ip $constraint */
/** @var Ip $constraint */
$ruleOptions = true;
switch ($constraint->version) {
case Ip::V4:
Expand Down Expand Up @@ -100,7 +100,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
return get_class($constraint) === 'Symfony\Component\Validator\Constraints\Ip' &&
return get_class($constraint) === Ip::class &&
($this->useIpv6 || $this->useIpv4);
}
}
7 changes: 4 additions & 3 deletions src/Form/Rule/Mapping/IsBooleanRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\IsFalse;
use Symfony\Component\Validator\Constraints\IsTrue;

/**
Expand Down Expand Up @@ -59,7 +60,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
return;
}

/** @var \Symfony\Component\Validator\Constraints\IsTrue | \Symfony\Component\Validator\Constraints\IsFalse $constraint */
/** @var IsTrue|IsFalse $constraint */
$collection->set(
'equals',
new ConstraintRule(
Expand All @@ -76,8 +77,8 @@ public function supports(Constraint $constraint, FormInterface $form)
return in_array(
get_class($constraint),
array(
'Symfony\Component\Validator\Constraints\IsTrue',
'Symfony\Component\Validator\Constraints\IsFalse',
IsTrue::class,
IsFalse::class,
),
true
);
Expand Down
5 changes: 3 additions & 2 deletions src/Form/Rule/Mapping/LuhnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Luhn;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand Down Expand Up @@ -35,7 +36,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\Luhn $constraint */
/** @var Luhn $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
Expand All @@ -49,6 +50,6 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
return $this->active && get_class($constraint) === 'Symfony\Component\Validator\Constraints\Luhn';
return $this->active && get_class($constraint) === Luhn::class;
}
}
11 changes: 7 additions & 4 deletions src/Form/Rule/Mapping/MaxLengthRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleCollection;
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Boekkooi\Bundle\JqueryValidationBundle\Form\Util\FormHelper;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Length;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand Down Expand Up @@ -40,18 +43,18 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
/** @var \Symfony\Component\Validator\Constraints\Choice|\Symfony\Component\Validator\Constraints\Length $constraint */
/** @var Choice|Length $constraint */
$constraintClass = get_class($constraint);
if (!in_array($constraintClass, array('Symfony\Component\Validator\Constraints\Choice', 'Symfony\Component\Validator\Constraints\Length'), true) ||
if (!in_array($constraintClass, array(Choice::class, Length::class), true) ||
$constraint->max === null ||
$constraint->min == $constraint->max) {
return false;
}

return !(
$constraintClass === 'Symfony\Component\Validator\Constraints\Length' &&
$constraintClass === Length::class &&
(FormHelper::isSymfony3Compatible() ?
$this->isType($form, 'Symfony\Component\Form\Extension\Core\Type\ChoiceType') :
$this->isType($form, ChoiceType::class) :
$this->isType($form, 'choice')
)
);
Expand Down
17 changes: 10 additions & 7 deletions src/Form/Rule/Mapping/MaxRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\LessThan;
use Symfony\Component\Validator\Constraints\LessThanOrEqual;
use Symfony\Component\Validator\Constraints\Range;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand All @@ -24,23 +27,23 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
{
/** @var \Symfony\Component\Validator\Constraints\AbstractComparison $constraint */
$constraintClass = get_class($constraint);
if ($constraintClass === 'Symfony\Component\Validator\Constraints\LessThan') {
if ($constraintClass === LessThan::class) {
$rule = new ConstraintRule(
self::RULE_NAME,
$constraint->value - 1, // TODO support floats
new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
$constraint->groups
);
} elseif ($constraintClass === 'Symfony\Component\Validator\Constraints\LessThanOrEqual') {
} elseif ($constraintClass === LessThanOrEqual::class) {
$rule = new ConstraintRule(
self::RULE_NAME,
$constraint->value,
new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
$constraint->groups
);
}
/** @var \Symfony\Component\Validator\Constraints\Range $constraint */
elseif ($constraintClass === 'Symfony\Component\Validator\Constraints\Range' && $constraint->max !== null) {
/** @var Range $constraint */
elseif ($constraintClass === Range::class && $constraint->max !== null) {
$rule = new ConstraintRule(
self::RULE_NAME,
$constraint->max,
Expand All @@ -63,10 +66,10 @@ public function supports(Constraint $constraint, FormInterface $form)

return
in_array($constraintClass, array(
'Symfony\Component\Validator\Constraints\LessThan',
'Symfony\Component\Validator\Constraints\LessThanOrEqual',
LessThan::class,
LessThanOrEqual::class,
), true) ||
$constraintClass === 'Symfony\Component\Validator\Constraints\Range' && $constraint->max !== null
$constraintClass === Range::class && $constraint->max !== null
;
}
}
10 changes: 5 additions & 5 deletions src/Form/Rule/Mapping/MinLengthRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
throw new LogicException();
}

/** @var \Symfony\Component\Validator\Constraints\Choice|\Symfony\Component\Validator\Constraints\Length $constraint */
/** @var Choice|Length $constraint */
$collection->set(
self::RULE_NAME,
new ConstraintRule(
Expand All @@ -43,18 +43,18 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
/** @var \Symfony\Component\Validator\Constraints\Choice|\Symfony\Component\Validator\Constraints\Length $constraint */
/** @var Choice|Length $constraint */
$constraintClass = get_class($constraint);
if (!in_array($constraintClass, array('Symfony\Component\Validator\Constraints\Choice', 'Symfony\Component\Validator\Constraints\Length'), true) ||
if (!in_array($constraintClass, array(Choice::class, Length::class), true) ||
$constraint->min === null ||
$constraint->min == $constraint->max) {
return false;
}

return !(
$constraintClass === 'Symfony\Component\Validator\Constraints\Length' &&
$constraintClass === Length::class &&
(FormHelper::isSymfony3Compatible() ?
$this->isType($form, 'Symfony\Component\Form\Extension\Core\Type\ChoiceType') :
$this->isType($form, ChoiceType::class) :
$this->isType($form, 'choice')
)
);
Expand Down
17 changes: 10 additions & 7 deletions src/Form/Rule/Mapping/MinRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\Range;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand All @@ -25,23 +28,23 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect
$constraintClass = get_class($constraint);

/** @var \Symfony\Component\Validator\Constraints\AbstractComparison $constraint */
if ($constraintClass === 'Symfony\Component\Validator\Constraints\GreaterThan') {
if ($constraintClass === GreaterThan::class) {
$rule = new ConstraintRule(
self::RULE_NAME,
$constraint->value + 1, // TODO support floats
new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
$constraint->groups
);
} elseif ($constraintClass === 'Symfony\Component\Validator\Constraints\GreaterThanOrEqual') {
} elseif ($constraintClass === GreaterThanOrEqual::class) {
$rule = new ConstraintRule(
self::RULE_NAME,
$constraint->value,
new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
$constraint->groups
);
}
/** @var \Symfony\Component\Validator\Constraints\Range $constraint */
elseif ($constraintClass === 'Symfony\Component\Validator\Constraints\Range' && $constraint->min !== null) {
/** @var Range $constraint */
elseif ($constraintClass === Range::class && $constraint->min !== null) {
$rule = new ConstraintRule(
self::RULE_NAME,
$constraint->min,
Expand All @@ -64,9 +67,9 @@ public function supports(Constraint $constraint, FormInterface $form)

return
in_array($constraintClass, array(
'Symfony\Component\Validator\Constraints\GreaterThan',
'Symfony\Component\Validator\Constraints\GreaterThanOrEqual',
GreaterThan::class,
GreaterThanOrEqual::class,
), true) ||
$constraintClass === 'Symfony\Component\Validator\Constraints\Range' && $constraint->min !== null;
$constraintClass === Range::class && $constraint->min !== null;
}
}
4 changes: 2 additions & 2 deletions src/Form/Rule/Mapping/NumberRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function supports(Constraint $constraint, FormInterface $form)
{
$class = get_class($constraint);

return $class === 'Symfony\Component\Validator\Constraints\Range' || (
$class === 'Symfony\Component\Validator\Constraints\Type' &&
return $class === Range::class || (
$class === Type::class &&
in_array(strtolower($constraint->type), array('int', 'integer', 'float', 'double'), true)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Form/Rule/Mapping/PatternRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Regex;

/**
* @author Warnar Boekkooi <warnar@boekkooi.net>
Expand Down Expand Up @@ -49,6 +50,6 @@ public function resolve(Constraint $constraint, FormInterface $form, RuleCollect

public function supports(Constraint $constraint, FormInterface $form)
{
return $this->enabled && get_class($constraint) === 'Symfony\Component\Validator\Constraints\Regex';
return $this->enabled && get_class($constraint) === Regex::class;
}
}
Loading

0 comments on commit 118d088

Please sign in to comment.