Completed
Push — master ( 3393fb...c18aa3 )
by Tobias
03:09
created

ContainerAwareTrans   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 52
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A newAction() 0 19 1
A getLine() 0 4 1
A getTranslatorVariable() 0 5 1
A getPdfFilename() 0 4 1
A static() 0 4 1
1
<?php
2
3
namespace Translation\Extractor\Tests\Resources\Php\Symfony;
4
5
use Symfony\Component\Translation\TranslatorInterface;
6
7
class ContainerAwareTrans
8
{
9
    private $translator;
10
11
    public function __construct(TranslatorInterface $translator)
12
    {
13
        $this->translator = $translator;
14
    }
15
16
    /**
17
     * @return array
18
     */
19
    public function newAction()
20
    {
21
        // Using container
22
        $translated = $this->get('translator')->trans('trans0');
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Translation\Extra...ny\ContainerAwareTrans>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
$translated is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
23
24
        // As a parameter
25
        $model->setMessage(
0 ignored issues
show
Bug introduced by
The variable $model does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
26
            $this->get('translator')->trans(
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Translation\Extra...ny\ContainerAwareTrans>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
                'trans1',
28
                array(
29
                    'a' => 'x',
30
                    'b' => 'y',
31
                    'c' => 'z',
32
                )
33
            )
34
        );
35
36
        return array();
37
    }
38
39
    public function getLine()
40
    {
41
        return $this->translator->trans('trans_line');
42
    }
43
    public function getTranslatorVariable()
44
    {
45
        $translator = $this->get('translator');
0 ignored issues
show
Bug introduced by
The method get() does not seem to exist on object<Translation\Extra...ny\ContainerAwareTrans>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        $translator->trans('variable');
47
    }
48
49
    public function getPdfFilename(string $locale)
50
    {
51
        return $this->translator->trans('my.pdf', [], 'generic', $locale);
52
    }
53
54
    public function static()
55
    {
56
        $translator = static::$container->get('translator'); $foo = $translator->trans('bar');
0 ignored issues
show
Unused Code introduced by
$foo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
    }
58
}
59