| Total Complexity | 8 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class MultipleCondition implements ConditionInterface { |
||
| 12 | /** |
||
| 13 | * Array of conditions to check |
||
| 14 | * |
||
| 15 | * @var array<ConditionInterface> |
||
| 16 | */ |
||
| 17 | protected $conditions = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Constructor |
||
| 21 | * |
||
| 22 | * @param array $conditions |
||
| 23 | */ |
||
| 24 | public function __construct( $conditions ) { |
||
| 25 | 1 | $this->conditions = array_map( function ( $condition ) { |
|
| 26 | 1 | if ( $condition instanceof ConditionInterface ) { |
|
| 27 | 1 | return $condition; |
|
| 28 | } |
||
| 29 | 1 | return RouteCondition::make( $condition ); |
|
| 30 | 1 | }, $conditions ); |
|
| 31 | 1 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritDoc} |
||
| 35 | */ |
||
| 36 | 1 | public function isSatisfied( Request $request ) { |
|
| 37 | 1 | foreach ( $this->conditions as $condition ) { |
|
| 38 | 1 | if ( ! $condition->isSatisfied( $request ) ) { |
|
| 39 | 1 | return false; |
|
| 40 | } |
||
| 41 | 1 | } |
|
| 42 | 1 | return true; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritDoc} |
||
| 47 | */ |
||
| 48 | 1 | public function getArguments( Request $request ) { |
|
| 49 | 1 | $arguments = []; |
|
| 50 | 1 | foreach ( $this->conditions as $condition ) { |
|
| 51 | 1 | $arguments = array_merge( $arguments, $condition->getArguments( $request ) ); |
|
| 52 | 1 | } |
|
| 53 | 1 | return $arguments; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get all assigned conditions |
||
| 58 | * |
||
| 59 | * @return \WPEmerge\Routing\Conditions\ConditionInterface[] |
||
| 60 | */ |
||
| 61 | 1 | public function getConditions() { |
|
| 63 | } |
||
| 64 | } |
||
| 65 |