Completed
Pull Request — master (#15)
by Gabriel
03:36
created

MigrationEvent   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 76
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A getOptions() 0 4 1
A getTarget() 0 4 1
A getContext() 0 4 1
A getAdditionalPayload() 0 8 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <https://github.com/baleen/migrations>.
18
 */
19
20
namespace Baleen\Migrations\Service\Runner\Event\Migration;
21
22
use Baleen\Migrations\Migration\OptionsInterface;
23
use Baleen\Migrations\Shared\Event\AbstractDomainEvent;
24
use Baleen\Migrations\Shared\Event\Context\CollectionContext;
25
use Baleen\Migrations\Shared\Event\Context\CollectionContextInterface;
26
use Baleen\Migrations\Shared\Event\Progress;
27
use Baleen\Migrations\Version\VersionInterface;
28
use DateTime;
29
30
/**
31
 * Class MigrationEvent.
32
 *
33
 * @author Gabriel Somoza <[email protected]>
34
 */
35
class MigrationEvent extends AbstractDomainEvent
36
{
37
    /** @var OptionsInterface */
38
    private $options;
39
40
    /** @var VersionInterface */
41
    private $target;
42
43
    /** @var CollectionContextInterface */
44
    private $context;
45
46
    /**
47
     * MigrationEvent constructor.
48
     *
49
     * @param VersionInterface $target
50
     * @param OptionsInterface $options
51
     * @param CollectionContextInterface $context
0 ignored issues
show
Documentation introduced by
Should the type for parameter $context not be null|CollectionContextInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
52
     * @param DateTime $occurredOn
0 ignored issues
show
Documentation introduced by
Should the type for parameter $occurredOn not be null|DateTime?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
53
     */
54 19
    public function __construct(
55
        VersionInterface $target,
56
        OptionsInterface $options,
57
        CollectionContextInterface $context = null,
58
        DateTime $occurredOn = null
59
    ) {
60 19
        if (null === $context) {
61 1
            $context = new CollectionContext(new Progress(1, 1));
62 1
        }
63 19
        $this->context = $context;
64
65 19
        $this->options = $options;
66 19
        $this->target = $target;
67
68 19
        parent::__construct($occurredOn);
69 19
    }
70
71
    /**
72
     * @return OptionsInterface
73
     */
74 2
    public function getOptions()
75
    {
76 2
        return $this->options;
77
    }
78
79
    /**
80
     * Returns the Version that's being migrated.
81
     *
82
     * NOTE: Do not confuse this method with version()
83
     *
84
     * @return VersionInterface
85
     */
86 2
    public function getTarget()
87
    {
88 2
        return $this->target;
89
    }
90
91
    /**
92
     * @return CollectionContextInterface
93
     */
94 15
    public function getContext()
95
    {
96 15
        return $this->context;
97
    }
98
99
    /**
100
     * @inheritdoc
101
     */
102 1
    protected function getAdditionalPayload()
103
    {
104
        return [
105 1
            'target' => $this->getTarget(),
106 1
            'options' => $this->getOptions(),
107 1
            'context' => $this->getContext(),
108 1
        ];
109
    }
110
}
111