1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Validation\Blocks; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2020 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Validation\Contracts\Blocks\AndExpressionInterface; |
22
|
|
|
use Limoncello\Validation\Contracts\Blocks\ExecutionBlockInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @package Limoncello\Validation |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
final class AndBlock implements AndExpressionInterface |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var ExecutionBlockInterface |
31
|
|
|
*/ |
32
|
|
|
private $primary; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ExecutionBlockInterface |
36
|
|
|
*/ |
37
|
|
|
private $secondary; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private $properties; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ExecutionBlockInterface $primary |
47
|
|
|
* @param ExecutionBlockInterface $secondary |
48
|
|
|
* @param array $properties |
49
|
|
|
*/ |
50
|
14 |
|
public function __construct( |
51
|
|
|
ExecutionBlockInterface $primary, |
52
|
|
|
ExecutionBlockInterface $secondary, |
53
|
|
|
array $properties = [] |
54
|
|
|
) { |
55
|
14 |
|
$this->primary = $primary; |
56
|
14 |
|
$this->secondary = $secondary; |
57
|
14 |
|
$this->properties = $properties; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
12 |
|
public function getPrimary(): ExecutionBlockInterface |
64
|
|
|
{ |
65
|
12 |
|
return $this->primary; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritdoc |
70
|
|
|
*/ |
71
|
12 |
|
public function getSecondary(): ExecutionBlockInterface |
72
|
|
|
{ |
73
|
12 |
|
return $this->secondary; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
14 |
|
public function getProperties(): array |
80
|
|
|
{ |
81
|
14 |
|
return $this->properties; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.