Completed
Push — master ( b6e8a8...8fab1b )
by Alejandro
09:45 queued 06:47
created

InputFactoryTrait::createInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
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 4
    private function createInput(string $name, bool $required = true): Input
13
    {
14 4
        $input = new Input($name);
15 4
        $input->setRequired($required)
16 4
              ->getFilterChain()->attach(new Filter\StripTags())
17 4
                                ->attach(new Filter\StringTrim());
18 4
        return $input;
19
    }
20
21 2
    private function createBooleanInput(string $name, bool $required = true): Input
22
    {
23 2
        $input = $this->createInput($name, $required);
24 2
        $input->getFilterChain()->attach(new Filter\Boolean());
25 2
        $input->getValidatorChain()->attach(new Validator\NotEmpty(['type' => [
26 2
            Validator\NotEmpty::OBJECT,
27 2
            Validator\NotEmpty::SPACE,
28 2
            Validator\NotEmpty::NULL,
29 2
            Validator\NotEmpty::EMPTY_ARRAY,
30 2
            Validator\NotEmpty::STRING,
31
        ]]));
32
33 2
        return $input;
34
    }
35
}
36