Completed
Push — master ( 119f8d...4ad486 )
by Paweł
10:35
created

TextareaAttributeType::getValidationErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Attribute\AttributeType;
13
14
use Sylius\Component\Attribute\Model\AttributeValueInterface;
15
use Symfony\Component\Validator\Constraints\NotBlank;
16
use Symfony\Component\Validator\ConstraintViolationListInterface;
17
use Symfony\Component\Validator\Context\ExecutionContextInterface;
18
19
/**
20
 * @author Mateusz Zalewski <[email protected]>
21
 */
22
final class TextareaAttributeType implements AttributeTypeInterface
23
{
24
    const TYPE = 'textarea';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getStorageType()
30
    {
31
        return AttributeValueInterface::STORAGE_TEXT;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getType()
38
    {
39
        return static::TYPE;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function validate(AttributeValueInterface $attributeValue, ExecutionContextInterface $context, array $configuration)
46
    {
47
        if (!isset($configuration['required'])) {
48
            return;
49
        }
50
51
        $value = $attributeValue->getValue();
52
53
        foreach ($this->getValidationErrors($context, $value, $configuration) as $error) {
0 ignored issues
show
Unused Code introduced by
The call to TextareaAttributeType::getValidationErrors() has too many arguments starting with $configuration.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
            $context
55
                ->buildViolation($error->getMessage())
56
                ->atPath('value')
57
                ->addViolation()
58
            ;
59
        }
60
    }
61
62
    /**
63
     * @param ExecutionContextInterface $context
64
     * @param string $value
65
     *
66
     * @return ConstraintViolationListInterface
67
     */
68
    private function getValidationErrors(ExecutionContextInterface $context, $value)
69
    {
70
        $validator = $context->getValidator();
71
72
        return $validator->validate(
73
            $value, [
74
                new NotBlank([])
75
            ]
76
        );
77
    }
78
}
79