Passed
Pull Request — master (#116)
by David
06:24
created

onBaseDaoSetDefaultSortGenerated()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 4
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils;
5
6
7
use Doctrine\DBAL\Schema\Index;
8
use TheCodingMachine\TDBM\ConfigurationInterface;
9
use Zend\Code\Generator\ClassGenerator;
10
use Zend\Code\Generator\FileGenerator;
11
use Zend\Code\Generator\MethodGenerator;
12
13
class CodeGeneratorEventDispatcher implements CodeGeneratorListenerInterface
14
{
15
    /**
16
     * @var CodeGeneratorListenerInterface[]
17
     */
18
    private $listeners;
19
20
    /**
21
     * @param CodeGeneratorListenerInterface[] $listeners
22
     */
23
    public function __construct(array $listeners)
24
    {
25
        $this->listeners = $listeners;
26
    }
27
28
    public function onBaseBeanGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator
29
    {
30
        foreach ($this->listeners as $listener) {
31
            $fileGenerator = $listener->onBaseBeanGenerated($fileGenerator, $beanDescriptor, $configuration);
32
            if ($fileGenerator === null) {
33
                break;
34
            }
35
        }
36
        return $fileGenerator;
37
    }
38
39
    public function onBaseBeanConstructorGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
40
    {
41
        foreach ($this->listeners as $listener) {
42
            $methodGenerator = $listener->onBaseBeanConstructorGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
43
            if ($methodGenerator === null) {
44
                break;
45
            }
46
        }
47
        return $methodGenerator;
48
    }
49
50
    /**
51
     * Called when a column is turned into a getter/setter.
52
     *
53
     * @return array<int, ?MethodGenerator> Returns an array of 2 methods to be generated for this property. You MUST return the getter (first argument) and setter (second argument) as part of these methods (if you want them to appear in the bean). Return null if you want to delete them.
54
     */
55
    public function onBaseBeanPropertyGenerated(?MethodGenerator $getter, ?MethodGenerator $setter, AbstractBeanPropertyDescriptor $propertyDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): array
56
    {
57
        foreach ($this->listeners as $listener) {
58
            [$getter, $setter] = $listener->onBaseBeanPropertyGenerated($getter, $setter, $propertyDescriptor, $beanDescriptor, $configuration, $classGenerator);
59
            if ($getter === null && $setter === null) {
60
                break;
61
            }
62
        }
63
        return [$getter, $setter];
64
    }
65
66
    /**
67
     * Called when a foreign key from another table is turned into a "get many objects" method.
68
     *
69
     * @param MethodGenerator $getter
70
     * @param DirectForeignKeyMethodDescriptor $directForeignKeyMethodDescriptor
71
     * @param BeanDescriptor $beanDescriptor
72
     * @param ConfigurationInterface $configuration
73
     * @param ClassGenerator $classGenerator
74
     * @return MethodGenerator|null
75
     */
76
    public function onBaseBeanOneToManyGenerated(MethodGenerator $getter, DirectForeignKeyMethodDescriptor $directForeignKeyMethodDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
77
    {
78
        foreach ($this->listeners as $listener) {
79
            $getter = $listener->onBaseBeanOneToManyGenerated($getter, $directForeignKeyMethodDescriptor, $beanDescriptor, $configuration, $classGenerator);
80
            if ($getter === null) {
81
                break;
82
            }
83
        }
84
        return $getter;
85
    }
86
87
    /**
88
     * Called when a pivot table is turned into get/has/add/set/remove methods.
89
     *
90
     * @return array<int, ?MethodGenerator> Returns an array of methods to be generated for this property. You MUST return the get/has/add/set/remove methods as part of these methods (if you want them to appear in the bean).
91
     */
92
    public function onBaseBeanManyToManyGenerated(?MethodGenerator $getter, ?MethodGenerator $adder, ?MethodGenerator $remover, ?MethodGenerator $hasser, ?MethodGenerator $setter, PivotTableMethodsDescriptor $pivotTableMethodsDescriptor, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): array
93
    {
94
        foreach ($this->listeners as $listener) {
95
            [$getter, $adder, $remover, $hasser, $setter] = $listener->onBaseBeanManyToManyGenerated($getter, $adder, $remover, $hasser, $setter, $pivotTableMethodsDescriptor, $beanDescriptor, $configuration, $classGenerator);
96
            if ($getter === null && $adder === null && $remover === null && $hasser === null && $setter === null) {
97
                break;
98
            }
99
        }
100
        return [$getter, $adder, $remover, $hasser, $setter];
101
    }
102
103
    public function onBaseBeanJsonSerializeGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
104
    {
105
        foreach ($this->listeners as $listener) {
106
            $methodGenerator = $listener->onBaseBeanJsonSerializeGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
107
            if ($methodGenerator === null) {
108
                break;
109
            }
110
        }
111
        return $methodGenerator;
112
    }
113
114
    public function onBaseBeanCloneGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
115
    {
116
        foreach ($this->listeners as $listener) {
117
            $methodGenerator = $listener->onBaseBeanCloneGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
118
            if ($methodGenerator === null) {
119
                break;
120
            }
121
        }
122
        return $methodGenerator;
123
    }
124
125
    public function onBaseDaoGenerated(FileGenerator $fileGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration): ?FileGenerator
126
    {
127
        foreach ($this->listeners as $listener) {
128
            $fileGenerator = $listener->onBaseDaoGenerated($fileGenerator, $beanDescriptor, $configuration);
129
            if ($fileGenerator === null) {
130
                break;
131
            }
132
        }
133
        return $fileGenerator;
134
    }
135
136
    public function onBaseDaoConstructorGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
137
    {
138
        foreach ($this->listeners as $listener) {
139
            $methodGenerator = $listener->onBaseDaoConstructorGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
140
            if ($methodGenerator === null) {
141
                break;
142
            }
143
        }
144
        return $methodGenerator;
145
    }
146
147
    public function onBaseDaoSaveGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
148
    {
149
        foreach ($this->listeners as $listener) {
150
            $methodGenerator = $listener->onBaseDaoSaveGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
151
            if ($methodGenerator === null) {
152
                break;
153
            }
154
        }
155
        return $methodGenerator;
156
    }
157
158
    public function onBaseDaoFindAllGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
159
    {
160
        foreach ($this->listeners as $listener) {
161
            $methodGenerator = $listener->onBaseDaoFindAllGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
162
            if ($methodGenerator === null) {
163
                break;
164
            }
165
        }
166
        return $methodGenerator;
167
    }
168
169
    public function onBaseDaoGetByIdGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
170
    {
171
        foreach ($this->listeners as $listener) {
172
            $methodGenerator = $listener->onBaseDaoGetByIdGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
173
            if ($methodGenerator === null) {
174
                break;
175
            }
176
        }
177
        return $methodGenerator;
178
    }
179
180
    public function onBaseDaoDeleteGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
181
    {
182
        foreach ($this->listeners as $listener) {
183
            $methodGenerator = $listener->onBaseDaoDeleteGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
184
            if ($methodGenerator === null) {
185
                break;
186
            }
187
        }
188
        return $methodGenerator;
189
    }
190
191
    public function onBaseDaoFindGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
192
    {
193
        foreach ($this->listeners as $listener) {
194
            $methodGenerator = $listener->onBaseDaoFindGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
195
            if ($methodGenerator === null) {
196
                break;
197
            }
198
        }
199
        return $methodGenerator;
200
    }
201
202
    public function onBaseDaoFindFromSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
203
    {
204
        foreach ($this->listeners as $listener) {
205
            $methodGenerator = $listener->onBaseDaoFindFromSqlGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
206
            if ($methodGenerator === null) {
207
                break;
208
            }
209
        }
210
        return $methodGenerator;
211
    }
212
213
    public function onBaseDaoFindFromRawSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
214
    {
215
        foreach ($this->listeners as $listener) {
216
            $methodGenerator = $listener->onBaseDaoFindFromRawSqlGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
217
            if ($methodGenerator === null) {
218
                break;
219
            }
220
        }
221
        return $methodGenerator;
222
    }
223
224
    public function onBaseDaoFindOneGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
225
    {
226
        foreach ($this->listeners as $listener) {
227
            $methodGenerator = $listener->onBaseDaoFindOneGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
228
            if ($methodGenerator === null) {
229
                break;
230
            }
231
        }
232
        return $methodGenerator;
233
    }
234
235
    public function onBaseDaoFindOneFromSqlGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
236
    {
237
        foreach ($this->listeners as $listener) {
238
            $methodGenerator = $listener->onBaseDaoFindOneFromSqlGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
239
            if ($methodGenerator === null) {
240
                break;
241
            }
242
        }
243
        return $methodGenerator;
244
    }
245
246
    public function onBaseDaoSetDefaultSortGenerated(MethodGenerator $methodGenerator, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
247
    {
248
        foreach ($this->listeners as $listener) {
249
            $methodGenerator = $listener->onBaseDaoSetDefaultSortGenerated($methodGenerator, $beanDescriptor, $configuration, $classGenerator);
250
            if ($methodGenerator === null) {
251
                break;
252
            }
253
        }
254
        return $methodGenerator;
255
    }
256
257
    public function onBaseDaoFindByIndexGenerated(MethodGenerator $methodGenerator, Index $index, BeanDescriptor $beanDescriptor, ConfigurationInterface $configuration, ClassGenerator $classGenerator): ?MethodGenerator
258
    {
259
        foreach ($this->listeners as $listener) {
260
            $methodGenerator = $listener->onBaseDaoFindByIndexGenerated($methodGenerator, $index, $beanDescriptor, $configuration, $classGenerator);
261
            if ($methodGenerator === null) {
262
                break;
263
            }
264
        }
265
        return $methodGenerator;
266
    }
267
}
268