Completed
Push — master ( 98a062...441031 )
by Ryan
10:10
created

ChangeAssignmentColumn   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 45
loc 45
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 18 18 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 namespace Anomaly\Streams\Platform\Assignment\Command;
2
3
use Anomaly\Streams\Platform\Assignment\AssignmentSchema;
4
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentInterface;
5
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface;
6
7
/**
8
 * Class ChangeAssignmentColumn
9
 *
10
 * @link    http://pyrocms.com/
11
 * @author  PyroCMS, Inc. <[email protected]>
12
 * @author  Ryan Thompson <[email protected]>
13
 */
14 View Code Duplication
class ChangeAssignmentColumn
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...
15
{
16
17
    /**
18
     * The assignment interface.
19
     *
20
     * @var AssignmentInterface
21
     */
22
    protected $assignment;
23
24
    /**
25
     * Create a new ChangeAssignmentColumn instance.
26
     *
27
     * @param AssignmentInterface $assignment
28
     */
29
    public function __construct(AssignmentInterface $assignment)
30
    {
31
        $this->assignment = $assignment;
32
    }
33
34
    /**
35
     * Handle the command.
36
     *
37
     * @param AssignmentSchema              $schema
38
     * @param AssignmentRepositoryInterface $assignments
39
     */
40
    public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments)
41
    {
42
        $stream = $this->assignment->getStream();
43
        $type   = $this->assignment->getFieldType(true);
44
45
        if (!$this->assignment->isTranslatable()) {
46
            $table = $stream->getEntryTableName();
47
        } else {
48
            $table = $stream->getEntryTranslationsTableName();
49
        }
50
51
        /* @var AssignmentInterface $assignment */
52
        $assignment = $assignments->find($this->assignment->getId());
53
54
        $assignment = clone($assignment);
55
56
        $schema->renameColumn($table, $type, $assignment);
57
    }
58
}
59