Passed
Pull Request — master (#10)
by Alejandro
02:42
created

InputFactoryTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 15
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createBooleanInput() 0 13 1
A createInput() 0 7 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