Completed
Push — master ( a95c92...e40b6a )
by Beñat
04:36
created

MigrateTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 79
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setMigratedFrom() 0 6 1
A getMigratedFrom() 0 4 1
A setMigratedTo() 0 6 1
A getMigratedTo() 0 4 1
A loadMigration() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2015 Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace BenatEspina\StackExchangeApiClient\Model\Traits;
13
14
use BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface;
15
use BenatEspina\StackExchangeApiClient\Model\MigrationInfo;
16
use BenatEspina\StackExchangeApiClient\Util\Util;
17
18
/**
19
 * Trait MigrateTrait.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
trait MigrateTrait
24
{
25
    /**
26
     * Migrated from.
27
     *
28
     * @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface|null
29
     */
30
    protected $migratedFrom;
31
32
    /**
33
     * Migrated to.
34
     *
35
     * @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface|null
36
     */
37
    protected $migratedTo;
38
39
    /**
40
     * Sets migrated from.
41
     *
42
     * @param \BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface|null $migratedFrom The
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $migratedFrom a bit more specific; maybe use MigrationInfoInterface.
Loading history...
43
     *                                                                                                       migration
44
     *                                                                                                       info
45
     *
46
     * @return $this self Object
47
     */
48
    public function setMigratedFrom(MigrationInfoInterface $migratedFrom)
49
    {
50
        $this->migratedFrom = $migratedFrom;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Gets migrated from.
57
     *
58
     * @return \BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface|null
59
     */
60
    public function getMigratedFrom()
61
    {
62
        return $this->migratedFrom;
63
    }
64
65
    /**
66
     * Sets migrated to.
67
     *
68
     * @param \BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface|null $migratedTo The
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $migratedTo a bit more specific; maybe use MigrationInfoInterface.
Loading history...
69
     *                                                                                                     migration
70
     *                                                                                                     info
71
     *
72
     * @return $this self Object
73
     */
74
    public function setMigratedTo(MigrationInfoInterface $migratedTo)
75
    {
76
        $this->migratedTo = $migratedTo;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Gets migrated to.
83
     *
84
     * @return \BenatEspina\StackExchangeApiClient\Model\Interfaces\MigrationInfoInterface|null
85
     */
86
    public function getMigratedTo()
87
    {
88
        return $this->migratedTo;
89
    }
90
91
    /**
92
     * Loads the variables if the data exist into resource. It works like a constructor.
93
     *
94
     * @param null|mixed[] $resource The resource
95
     */
96
    protected function loadMigration($resource)
97
    {
98
        $this->migratedFrom = new MigrationInfo(Util::setIfArrayExists($resource, 'migrated_from'));
99
        $this->migratedTo = new MigrationInfo(Util::setIfArrayExists($resource, 'migrated_to'));
100
    }
101
}
102