Completed
Push — 1.1 ( d166b0...e7f438 )
by Patrick
11:31 queued 07:46
created

TranslationClass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 55
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A enable() 6 6 1
A build() 6 6 1
A getExtensionName() 4 4 1

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 LaravelDoctrine\Fluent\Extensions\Gedmo;
4
5
use Gedmo\Translatable\Mapping\Driver\Fluent as FluentDriver;
6
use LaravelDoctrine\Fluent\Buildable;
7
use LaravelDoctrine\Fluent\Builders\Builder;
8
use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata;
9
10 View Code Duplication
class TranslationClass implements Buildable
0 ignored issues
show
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...
11
{
12
    const MACRO_METHOD = 'translationClass';
13
14
    /**
15
     * @var ExtensibleClassMetadata
16
     */
17
    private $classMetadata;
18
19
    /**
20
     * @var string
21
     */
22
    private $class;
23
24
    /**
25
     * Locale constructor.
26
     * @param ExtensibleClassMetadata $classMetadata
27
     * @param string                  $class
28
     */
29
    public function __construct(ExtensibleClassMetadata $classMetadata, $class)
30
    {
31
        $this->classMetadata = $classMetadata;
32
        $this->class         = $class;
33
    }
34
35
    /**
36
     * @return void
37
     */
38
    public static function enable()
39
    {
40
        Builder::macro(self::MACRO_METHOD, function (Builder $builder, $class) {
41
            return new static($builder->getClassMetadata(), $class);
0 ignored issues
show
Compatibility introduced by
$builder->getClassMetadata() of type object<Doctrine\ORM\Mapping\ClassMetadata> is not a sub-type of object<LaravelDoctrine\F...xtensibleClassMetadata>. It seems like you assume a child class of the class Doctrine\ORM\Mapping\ClassMetadata to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
42
        });
43
    }
44
45
    /**
46
     * Execute the build process
47
     */
48
    public function build()
49
    {
50
        $this->classMetadata->appendExtension($this->getExtensionName(), [
51
            'translationClass' => $this->class
52
        ]);
53
    }
54
55
    /**
56
     * Return the name of the actual extension.
57
     *
58
     * @return string
59
     */
60
    public function getExtensionName()
61
    {
62
        return FluentDriver::EXTENSION_NAME;
63
    }
64
}
65