Completed
Push — develop ( 20327f...69b019 )
by Neomerx
10:22 queued 02:22
created

QueryValidatorFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
crap 1
1
<?php namespace Limoncello\Flute\Http\Query;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Container\Traits\HasContainerTrait;
20
use Limoncello\Flute\Contracts\Adapters\PaginationStrategyInterface;
21
use Limoncello\Flute\Contracts\Http\Query\QueryValidatorFactoryInterface;
22
use Limoncello\Flute\Contracts\Http\Query\QueryValidatorInterface;
23
use Psr\Container\ContainerInterface;
24
25
/**
26
 * @package Limoncello\Flute
27
 */
28
class QueryValidatorFactory implements QueryValidatorFactoryInterface
29
{
30
    use HasContainerTrait;
31
32
    /**
33
     * @var array
34
     */
35
    private $rulesData;
36
37
    /**
38
     * @var PaginationStrategyInterface
39
     */
40
    private $paginationStrategy;
41
42
    /**
43
     * @param ContainerInterface          $container
44
     * @param PaginationStrategyInterface $paginationStrategy
45
     * @param array                       $rulesData
46
     */
47 1
    public function __construct(
48
        ContainerInterface $container,
49
        PaginationStrategyInterface $paginationStrategy,
50
        array $rulesData
51
    ) {
52 1
        $this->setContainer($container)->setPaginationStrategy($paginationStrategy)->setRulesData($rulesData);
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 1
    public function createValidator(string $class): QueryValidatorInterface
59
    {
60 1
        return new QueryValidator($this->getRulesData(), $this->getContainer(), $this->getPaginationStrategy());
61
    }
62
63
    /**
64
     * @param PaginationStrategyInterface $paginationStrategy
65
     *
66
     * @return self
67
     */
68 1
    private function setPaginationStrategy(PaginationStrategyInterface $paginationStrategy): self
69
    {
70 1
        $this->paginationStrategy = $paginationStrategy;
71
72 1
        return $this;
73
    }
74
75
    /**
76
     * @return PaginationStrategyInterface
77
     */
78 1
    private function getPaginationStrategy(): PaginationStrategyInterface
79
    {
80 1
        return $this->paginationStrategy;
81
    }
82
83
    /**
84
     * @return array
85
     */
86 1
    private function getRulesData(): array
87
    {
88 1
        return $this->rulesData;
89
    }
90
91
    /**
92
     * @param array $rulesData
93
     *
94
     * @return self
95
     */
96 1
    private function setRulesData(array $rulesData): self
97
    {
98 1
        $this->rulesData = $rulesData;
99
100 1
        return $this;
101
    }
102
}
103