AbstractBeanCreator::getWriter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (c) Manero Contributors. All rights reserved.
4
 *
5
 * Licensed under the MIT License. See LICENSE.md file in the
6
 * project root for full license information.
7
 */
8
9
namespace Manero\Creator;
10
11
abstract class AbstractBeanCreator implements Createable
12
{
13
    private $class;
14
15
    private $aliases;
16
17
    private $writer;
18
19
    public function __construct(Writeable $writer, string $class)
20
    {
21
        $this->writer = $writer;
22
        $this->class = $class;
23
        $this->aliases = [];
24
        $this->addAlias($class);
25
    }
26
27
    public function getClass() : string
28
    {
29
        return $this->class;
30
    }
31
32
    public function addAlias(string $alias) : void
33
    {
34
        if (in_array($alias, $this->aliases)) {
35
            return;
36
        }
37
38
        $this->aliases[] = $alias;
39
    }
40
41
    protected function writeAliases() : void
42
    {
43
        $template = '
44
        %indent% *     @Alias({"name" = "%alias%"})';
45
        foreach ($this->aliases as $alias) {
46
            $content[] = str_Replace('%alias%', $alias, $template);
47
        }
48
        $this->getWriter()->write(implode(",", $content));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $content seems to be defined by a foreach iteration on line 45. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
49
    }
50
51
    public function getWriter() : Writeable
52
    {
53
        return $this->writer;
54
    }
55
}
56