Passed
Pull Request — master (#10)
by Alejandro
02: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 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.9666
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