Failed Conditions
Pull Request — 4.0 (#4528)
by Kentaro
07:39
created

TranslatorFacade   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 47
loc 47
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A init() 8 8 2
A create() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Eccube\DependencyInjection\Facade;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Symfony\Component\Translation\TranslatorInterface;
7
8
/**
9
 * XXX ContainerInterface は不要かも
10
 */
11 View Code Duplication
class TranslatorFacade
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /** @var self|null */
14
    private static $instance = null;
15
16
    /** @var ContainerInterface */
17
    private static $Container;
18
19
    /** @var TranslatorInterface */
20
    private static $Translator;
21
22
    /**
23
     * @param ContainerInterface $container
24
     */
25
    private function __construct(ContainerInterface $container, TranslatorInterface $Translator)
26
    {
27
        self::$Container = $container;
28
        self::$Translator = $Translator;
29
    }
30
31
    /**
32
     * @param ContainerInterface $container
33
     *
34
     * @return null|TranslatorFacade
35
     */
36
    public static function init(ContainerInterface $container, TranslatorInterface $Translator)
37
    {
38
        if (null === self::$instance) {
39
            self::$instance = new self($container, $Translator);
40
        }
41
42
        return self::$instance;
43
    }
44
45
    /**
46
     * @return TranslatorInterface
47
     * @throws \Exception
48
     */
49
    public static function create()
50
    {
51
        if (null === self::$instance) {
52
            throw new \Exception("Facade is not instantiated");
53
        }
54
55
        return self::$Translator;
56
    }
57
}
58