Passed
Pull Request — master (#9)
by Mariusz
02:39
created

Baz   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getWords() 0 3 1
A getText() 0 3 1
A getTextStats() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
require_once __DIR__ . '/vendor/autoload.php';
4
5
class Foo
6
{
7
    /**
8
     * @var Bar|null
9
     */
10
    protected $bar;
11
12
    /**
13
     * @param Bar|null $bar
14
     */
15
    public function __construct(Bar $bar = null)
16
    {
17
        $this->bar = $bar;
18
    }
19
20
    /**
21
     * @return Bar|null
22
     */
23
    public function getBar()
24
    {
25
        return $this->bar;
26
    }
27
}
28
29
class Bar
30
{
31
    /**
32
     * @var Baz[]
33
     */
34
    public $bazs;
35
36
    /**
37
     * @param Baz[] $bazs
38
     */
39
    public function __construct(array $bazs)
40
    {
41
        $this->bazs = $bazs;
42
    }
43
}
44
45
class Baz
46
{
47
    /**
48
     * @var string
49
     */
50
    protected $text;
51
52
    /**
53
     * @param string $text
54
     */
55
    public function __construct(string $text)
56
    {
57
        $this->text = $text;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getText(): string
64
    {
65
        return $this->text;
66
    }
67
68
    /**
69
     * @return string[]
70
     */
71
    public function getWords(): array
72
    {
73
        return explode(' ', $this->text);
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function getTextStats(): array
80
    {
81
        return ['wordCount' => count($this->getWords())];
82
    }
83
}
84
85
$foos = [
86
    $foo1 = new Foo(
87
        $bar1 = new Bar([
88
            $baz1 = new Baz('lorem ipsum'),
89
            $baz2 = new Baz('dolor'),
90
        ])
91
    ),
92
    $foo2 = new Foo(
93
        $bar2 = new Bar([
94
            $baz1,
95
            $baz3 = new Baz('sit amet malef'),
96
            $baz4 = new Baz('dolor sit'),
97
        ])
98
    ),
99
    $foo3 = new Foo(),
100
];
101
102
$facade = new \Xsolve\Associate\Facade();
103
$basicCollector = $facade->getBasicCollector();
104
105
$bars = $basicCollector->collect($foos, ['bar']);
106
var_dump($bars);
107
die;
108
109
$bazs = $basicCollector->collect($foos, ['bar', 'bazs']);
110
var_dump($bazs);
111
112
$texts = $basicCollector->collect($foos, ['bar', 'bazs', 'text']);
113
var_dump($texts);
114
115
$words = $basicCollector->collect($foos, ['bar', 'bazs', 'words']);
116
var_dump($words);
117
118
$wordCounts = $basicCollector->collect($foos, ['bar', 'bazs', 'textStats', '[wordCount]']);
119
var_dump($wordCounts);
120