FactoryBeanCreator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
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
class FactoryBeanCreator extends AbstractBeanCreator
12
{
13
    private $factory;
14
15
    public function __construct(Writeable $writer, string $class, string $factory)
16
    {
17
        parent::__construct($writer, $class);
18
        $this->factory = $factory;
19
    }
20
21
    public function create() : void
22
    {
23
        $preAliasTemplate = '
24
            %indent%/**
25
            %indent% * @Bean({"aliases" = {';
26
27
        $postAliasTemplate = '
28
            %indent% * }})
29
            %indent% */
30
            %indent%public function get%classWithoutBackslashes%() : \\%class%
31
            %indent%{
32
            %indent%    return (new \\%factory%())(BeanFactoryRegistry::getInstance());
33
            %indent%}';
34
35
        $this->getWriter()->write($preAliasTemplate);
36
        $this->writeAliases();
37
        $this->getWriter()->write(str_replace(
38
            [
39
                '%class%',
40
                '%factory%',
41
                '%classWithoutBackslashes%'
42
            ],
43
            [
44
                $this->getClass(),
45
                $this->factory,
46
                str_replace('\\', '', $this->getClass()),
47
            ],
48
            $postAliasTemplate
49
        ));
50
    }
51
}
52