Completed
Push — extensions-support ( 74d037...c14d66 )
by Patrick
03:15
created

TreeLockTime   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 54
loc 54
rs 10
ccs 15
cts 15
cp 1

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\Tree\Mapping\Driver\Fluent as FluentDriver;
6
use LaravelDoctrine\Fluent\Buildable;
7
use LaravelDoctrine\Fluent\Builders\Field;
8
use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata;
9
10 View Code Duplication
class TreeLockTime 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 = 'treeLockTime';
13
14
    /**
15
     * @var ExtensibleClassMetadata
16
     */
17
    protected $classMetadata;
18
19
    /**
20
     * @var string
21
     */
22
    protected $fieldName;
23
24
    /**
25
     * @param ExtensibleClassMetadata $classMetadata
26
     * @param string                  $fieldName
27
     */
28 2
    public function __construct(ExtensibleClassMetadata $classMetadata, $fieldName)
29
    {
30 2
        $this->classMetadata = $classMetadata;
31 2
        $this->fieldName     = $fieldName;
32 2
    }
33
34
    /**
35
     * Enable TreeLockTime
36
     */
37
    public static function enable()
38
    {
39 2
        Field::macro(self::MACRO_METHOD, function (Field $field) {
40 1
            return new static($field->getClassMetadata(), $field->getName());
0 ignored issues
show
Compatibility introduced by
$field->getClassMetadata() of type object<Doctrine\ORM\Mapping\ClassMetadataInfo> is not a sub-type of object<LaravelDoctrine\F...xtensibleClassMetadata>. It seems like you assume a child class of the class Doctrine\ORM\Mapping\ClassMetadataInfo 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...
41 2
        });
42 2
    }
43
44
    /**
45
     * Execute the build process
46
     */
47 1
    public function build()
48
    {
49 1
        $this->classMetadata->appendExtension($this->getExtensionName(), [
50 1
            'lock_time' => $this->fieldName
51 1
        ]);
52 1
    }
53
54
    /**
55
     * Return the name of the actual extension.
56
     *
57
     * @return string
58
     */
59 1
    public function getExtensionName()
60
    {
61 1
        return FluentDriver::EXTENSION_NAME;
62
    }
63
}
64