Code Duplication    Length = 31-53 lines in 5 locations

src/Eccube/DI/AutoWiring/EntityEventAutowiring.php 1 location

@@ 30-60 (lines=31) @@
27
use Eccube\Annotation\EntityEvent;
28
use Eccube\DI\ComponentDefinition;
29
30
class EntityEventAutowiring extends ComponentAutoWiring
31
{
32
    public function __construct($scanDirs)
33
    {
34
        parent::__construct($scanDirs);
35
    }
36
37
    public function getAnnotationClass()
38
    {
39
        return EntityEvent::class;
40
    }
41
42
    public function createComponentDefinition($anno, $refClass)
43
    {
44
        return new ComponentDefinition($refClass->getName(), $refClass);
45
    }
46
47
    public function generateExtend(\Twig_Environment $twig, array $components)
48
    {
49
        return $twig->createTemplate(
50
'$app->extend("eccube.entity.event.dispatcher", function ($eventDispatcher, $app) {
51
    {% for event in events -%}
52
    $eventDispatcher->addEventListener($app["{{ event.id }}"]);
53
    {% endfor %}
54
55
    return $eventDispatcher;
56
});')->render(['events' => $components]);
57
    }
58
59
60
}

src/Eccube/DI/AutoWiring/FormExtensionAutoWiring.php 1 location

@@ 30-75 (lines=46) @@
27
use Eccube\Annotation\FormExtension;
28
use Eccube\DI\ComponentDefinition;
29
30
class FormExtensionAutoWiring extends ComponentAutoWiring
31
{
32
    /**
33
     * FormExtensionAutoWiring constructor.
34
     * @param array|string[] $scanDirs
35
     */
36
    public function __construct($scanDirs)
37
    {
38
        parent::__construct($scanDirs);
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getAnnotationClass()
45
    {
46
        return FormExtension::class;
47
    }
48
49
    /**
50
     * @param \Eccube\Annotation\Component $anno
51
     * @param \ReflectionClass $refClass
52
     * @return ComponentDefinition
53
     */
54
    public function createComponentDefinition($anno, $refClass)
55
    {
56
        return new ComponentDefinition($refClass->getName(), $refClass);
57
    }
58
59
    /**
60
     * @param \Twig_Environment $twig
61
     * @param array $components
62
     * @return string
63
     */
64
    public function generateExtend(\Twig_Environment $twig, array $components)
65
    {
66
        return $twig->createTemplate(
67
'$app->extend("form.type.extensions", function ($extensions) {
68
    {% for extension in form_extensions -%}
69
    $extensions[] = "{{ extension.id }}";
70
    {% endfor %}
71
72
    return $extensions;
73
});')->render(['form_extensions' => $components]);
74
    }
75
}

src/Eccube/DI/AutoWiring/FormTypeAutoWiring.php 1 location

@@ 30-76 (lines=47) @@
27
use Eccube\Annotation\FormType;
28
use Eccube\DI\ComponentDefinition;
29
30
class FormTypeAutoWiring extends ComponentAutoWiring
31
{
32
    /**
33
     * FormTypeAutoWiring constructor.
34
     * @param array|string[] $scanDirs
35
     */
36
    public function __construct($scanDirs)
37
    {
38
        parent::__construct($scanDirs);
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getAnnotationClass()
45
    {
46
        return FormType::class;
47
    }
48
49
    /**
50
     * @param $anno FormType
51
     * @param $refClass \ReflectionClass
52
     * @return ComponentDefinition
53
     */
54
    public function createComponentDefinition($anno, $refClass)
55
    {
56
        return new ComponentDefinition($refClass->getName(), $refClass);
57
    }
58
59
    /**
60
     * @param \Twig_Environment $twig
61
     * @param array $components
62
     * @return string
63
     */
64
    public function generateExtend(\Twig_Environment $twig, array $components)
65
    {
66
        $template = $twig->createTemplate('$app->extend("form.types", function ($types) {
67
    {% for types in form_types -%}
68
    $types[] = "{{ types.id }}";
69
    {% endfor %}
70
71
    return $types;
72
});');
73
74
        return $template->render(['form_types' => $components]);
75
    }
76
}

src/Eccube/DI/AutoWiring/QueryExtensionAutoWiring.php 1 location

@@ 30-62 (lines=33) @@
27
use Eccube\Annotation\QueryExtension;
28
use Eccube\DI\ComponentDefinition;
29
30
class QueryExtensionAutoWiring extends ComponentAutoWiring
31
{
32
    /**
33
     * QueryExtensionScanner constructor.
34
     * @param array|string[] $scanDirs
35
     */
36
    public function __construct($scanDirs)
37
    {
38
        parent::__construct($scanDirs);
39
    }
40
41
    public function getAnnotationClass()
42
    {
43
        return QueryExtension::class;
44
    }
45
46
    public function createComponentDefinition($anno, $refClass)
47
    {
48
        return new ComponentDefinition($refClass->getName(), $refClass);
49
    }
50
51
    public function generateExtend(\Twig_Environment $twig, array $components)
52
    {
53
        return $twig->createTemplate(
54
'$app->extend("eccube.queries", function ($queries, $app) {
55
    {% for extension in extensions -%}
56
    $queries->addCustomizer($app["{{ extension.id }}"]);
57
    {% endfor %}
58
59
    return $queries;
60
});')->render(['extensions' => $components]);
61
    }
62
}

src/Eccube/DI/AutoWiring/RepositoryAutoWiring.php 1 location

@@ 29-81 (lines=53) @@
26
27
use Eccube\Annotation\Repository;
28
29
class RepositoryAutoWiring extends ComponentAutoWiring
30
{
31
    /**
32
     * RepositoryAutoWiring constructor.
33
     * @param array|string[] $scanDirs
34
     */
35
    public function __construct($scanDirs)
36
    {
37
        parent::__construct($scanDirs);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getAnnotationClass()
44
    {
45
        return Repository::class;
46
    }
47
48
    /**
49
     * @param \Eccube\Annotation\Component $anno
50
     * @param \ReflectionClass $refClass
51
     * @return RepositoryDefinition
52
     */
53
    public function createComponentDefinition($anno, $refClass)
54
    {
55
        return new RepositoryDefinition($refClass->getName(), $refClass);
56
    }
57
58
    /**
59
     * @param \Twig_Environment $twig
60
     * @param array $components
61
     * @return string
62
     */
63
    public function generate(\Twig_Environment $twig, array $components)
64
    {
65
        return $twig->createTemplate(
66
'{% for component in components -%}
67
$app["{{ component.id }}"] = function (\Pimple\Container $app) {
68
    $class = new \ReflectionClass(\{{ component.className }}::class);
69
    $instance = $app["orm.em"]->getRepository(\{{ component.entityName }}::class);
70
71
    {% for dependency in component.dependencies -%}
72
    $property = $class->getProperty("{{ dependency.propertyName }}");
73
    $property->setAccessible(true);
74
    $property->setValue($instance, {% if is_app(dependency.id) %}$app{% else %}$app["{{ dependency.id }}"]{% endif %});
75
    {% endfor %}
76
77
    return $instance;
78
};
79
{% endfor %}')->render(['components' => $components]);
80
    }
81
}