Completed
Pull Request — develop (#7)
by
unknown
03:21
created

ValueDriver::generator()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 6.9811
cc 7
eloc 13
nc 16
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
10
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
11
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
12
 * THE SOFTWARE.
13
 */
14
15
namespace Ytake\Lom\Factory;
16
17
use PhpParser\Node\Stmt\Class_;
18
19
/**
20
 * Class ValueDriver.
21
 *
22
 * @author  yuuki.takezawa<[email protected]>
23
 * @license http://opensource.org/licenses/MIT MIT
24
 */
25
class ValueDriver extends AbstractDriver implements FactoryInterface
26
{
27
    // getter generator
28
    use GetterTrait, ToStringTrait;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function generator(): ?array
34
    {
35
        foreach ($this->reflector->getProperties() as $property) {
36
            $name = $property->getName();
37
            $this->createGetter($name);
38
        }
39
        foreach ($this->parsed as $part) {
40
            if ($part instanceof Class_) {
41
                foreach ($this->getGetters() as $getter) {
42
                    if ($this->reflector->hasMethod($getter['method'])) {
43
                        continue;
44
                    }
45
                    $part->stmts[] = $this->createGetterMethod($getter);
46
                }
47
                if (!$this->reflector->hasMethod('__toString')) {
48
                    $part->stmts[] = $this->createToString($this->getGetters());
49
                }
50
            }
51
        }
52
53
        return $this->parsed;
54
    }
55
}
56