Passed
Pull Request — master (#343)
by Alejandro
05:42
created

InputFactoryTrait::createBooleanInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
ccs 10
cts 10
cp 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Validation;
5
6
use Zend\Filter;
7
use Zend\InputFilter\Input;
8
use Zend\Validator;
9
10
trait InputFactoryTrait
11
{
12 15
    private function createInput($name, $required = true): Input
13
    {
14 15
        $input = new Input($name);
15 15
        $input->setRequired($required)
16 15
              ->getFilterChain()->attach(new Filter\StripTags())
17 15
                                ->attach(new Filter\StringTrim());
18 15
        return $input;
19
    }
20
21 15
    private function createBooleanInput(string $name, bool $required = true): Input
22
    {
23 15
        $input = $this->createInput($name, $required);
24 15
        $input->getFilterChain()->attach(new Filter\Boolean());
25 15
        $input->getValidatorChain()->attach(new Validator\NotEmpty(['type' => [
26 15
            Validator\NotEmpty::OBJECT,
27 15
            Validator\NotEmpty::SPACE,
28 15
            Validator\NotEmpty::NULL,
29 15
            Validator\NotEmpty::EMPTY_ARRAY,
30 15
            Validator\NotEmpty::STRING,
31
        ]]));
32
33 15
        return $input;
34
    }
35
}
36