Passed
Push — master ( 60319d...b48e8d )
by Daniele
08:21
created

FluidRepeater   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __call() 0 16 3
1
<?php
2
3
namespace FluidXml;
4
5
class FluidRepeater
6
{
7
        private $document;
8
        private $handler;
9
        private $context;
10
        private $times;
11
12
        public function __construct($document, $handler, $context, $times)
13
        {
14
                $this->document = $document;
15
                $this->handler  = $handler;
16
                $this->context  = $context;
17
                $this->times    = $times;
18
        }
19
20
        public function __call($method, $arguments)
21
        {
22
                $nodes = [];
23
                $new_context = $this->context;
24
25
                for ($i = 0, $l = $this->times; $i < $l; ++$i) {
26
                        $new_context = $this->context->$method(...$arguments);
27
                        $nodes       = \array_merge($nodes, $new_context->array());
28
                }
29
30
                if ($new_context !== $this->context) {
31
                        return new FluidContext($this->document, $this->handler, $nodes);
32
                }
33
34
                return $this->context;
35
        }
36
}
37