Completed
Push — extensions-support ( bcc5d6...dc7c75 )
by Patrick
03:13
created

SortablePosition   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getExtensionName() 0 4 1
A enable() 0 6 1
A build() 8 8 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\Sortable;
4
5
use Gedmo\Sortable\Mapping\Driver\Fluent as FluentDriver;
6
use LaravelDoctrine\Fluent\Buildable;
7
use LaravelDoctrine\Fluent\Builders\Field;
8
use LaravelDoctrine\Fluent\Extensions\ExtensibleClassMetadata;
9
10
class SortablePosition implements Buildable
11
{
12
    const MACRO_METHOD = 'sortablePosition';
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
     * Return the name of the actual extension.
36
     *
37
     * @return string
38
     */
39 1
    public function getExtensionName()
40
    {
41 1
        return FluentDriver::EXTENSION_NAME;
42
    }
43
44
    /**
45
     * @return void
46
     */
47
    public static function enable()
48
    {
49 2
        Field::macro(self::MACRO_METHOD, function (Field $builder) {
50 1
            return new static($builder->getClassMetadata(), $builder->getName());
51 2
        });
52 2
    }
53
54
    /**
55
     * Execute the build process
56
     */
57 1 View Code Duplication
    public function build()
0 ignored issues
show
Duplication introduced by
This method 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...
58
    {
59 1
        $extension = $this->classMetadata->getExtension($this->getExtensionName());
60
61 1
        $extension['position'] = $this->fieldName;
62
63 1
        $this->classMetadata->addExtension($this->getExtensionName(), $extension);
64 1
    }
65
}
66