minor #32047 [Validator] prevent double deprecation message (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Validator] prevent double deprecation message

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

ecded5ed03 prevent double deprecation message
This commit is contained in:
Tobias Schultze 2019-06-14 20:10:10 +02:00
commit 9f6cbaa6b9

View File

@ -27,15 +27,16 @@ class ExpressionValidator extends ConstraintValidator
public function __construct(/*ExpressionLanguage */$expressionLanguage = null)
{
if (!$expressionLanguage instanceof ExpressionLanguage) {
if (null !== $expressionLanguage) {
@trigger_error(sprintf('The "%s" first argument must be an instance of "%s" or null since 4.4. "%s" given', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)), E_USER_DEPRECATED);
}
if (\func_num_args() > 1) {
@trigger_error(sprintf('The "%s" instance should be passed as "%s" first argument instead of second argument since 4.4.', ExpressionLanguage::class, __METHOD__), E_USER_DEPRECATED);
if (\func_num_args() > 1 && func_get_arg(1) instanceof ExpressionLanguage) {
@trigger_error(sprintf('The "%s" instance should be passed as "%s" first argument instead of second argument since 4.4.', ExpressionLanguage::class, __METHOD__), E_USER_DEPRECATED);
$expressionLanguage = func_get_arg(1);
$expressionLanguage = func_get_arg(1);
if (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
throw new \TypeError(sprintf('Argument 2 passed to %s() must be an instance of %s or null, %s given. Since 4.4, passing it as the second argument is deprecated and will trigger a deprecation. Pass it as the first argument instead.', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)));
}
} elseif (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
@trigger_error(sprintf('The "%s" first argument must be an instance of "%s" or null since 4.4. "%s" given', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)), E_USER_DEPRECATED);
}
$this->expressionLanguage = $expressionLanguage;