Completed
Push — master ( 804cbb...e964af )
by Ryan
06:57
created

RestoreAssignmentData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
B handle() 28 28 4

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
use Illuminate\Contracts\Bus\SelfHandling;
7
8
/**
9
 * Class RestoreAssignmentData
10
 *
11
 * @link    http://anomaly.is/streams-platform
12
 * @author  AnomalyLabs, Inc. <[email protected]>
13
 * @author  Ryan Thompson <[email protected]>
14
 * @package Anomaly\Streams\Platform\Assignment\Command
15
 */
16 View Code Duplication
class RestoreAssignmentData implements SelfHandling
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...
17
{
18
19
    /**
20
     * The assignment interface.
21
     *
22
     * @var AssignmentInterface
23
     */
24
    protected $assignment;
25
26
    /**
27
     * Create a new RestoreAssignmentData instance.
28
     *
29
     * @param AssignmentInterface $assignment
30
     */
31
    public function __construct(AssignmentInterface $assignment)
32
    {
33
        $this->assignment = $assignment;
34
    }
35
36
    /**
37
     * Handle the command.
38
     *
39
     * @param AssignmentSchema $schema
40
     */
41
    public function handle(AssignmentSchema $schema, AssignmentRepositoryInterface $assignments)
42
    {
43
        $stream = $this->assignment->getStream();
44
45
        /* @var AssignmentInterface $assignment */
46
        $assignment = $assignments->find($this->assignment->getId());
47
48
        // If nothing is different then skip it.
49
        if ($assignment->isTranslatable() == $this->assignment->isTranslatable()) {
50
            return;
51
        }
52
53
        /**
54
         * If it's NOW translatable then
55
         * restore it to the main table.
56
         */
57
        if ($this->assignment->isTranslatable()) {
58
            $schema->restoreColumn($stream->getEntryTranslationsTableName(), $assignment->getFieldType(true));
59
        }
60
61
        /**
62
         * If it's NOT translatable then back
63
         * it up from the translations table.
64
         */
65
        if (!$this->assignment->isTranslatable()) {
66
            $schema->restoreColumn($stream->getEntryTableName(), $assignment->getFieldType(true));
67
        }
68
    }
69
}
70