Completed
Pull Request — master (#71)
by Mikael
04:28
created

ModifiedColumnEntityTrait::getModifiedColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the PommProject/ModelManager package.
4
 *
5
 * (c) 2014 - 2016 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\ModelManager\Model\FlexibleEntity;
11
12
/**
13
 * ModifiedColumnEntityTrait
14
 *
15
 * @package     ModelManager
16
 * @copyright   2014 - 2015 Grégoire HUBERT
17
 * @author      Mikael Paris
18
 * @license     X11 {@link http://opensource.org/licenses/mit-license.php}
19
 * @see         FlexibleEntityInterface
20
 */
21
trait ModifiedColumnEntityTrait
22
{
23
    private $modified_columns = [];
24
25
    abstract function touch();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
27
    /**
28
     * @return array
29
     */
30
    public function getModifiedColumns()
31
    {
32
        return $this->modified_columns;
33
    }
34
35
    /**
36
     * @param $column
37
     * @return FlexibleEntityInterface
38
     */
39
    public function addModifiedColumn($column)
40
    {
41
        if (!in_array($column, $this->modified_columns)) {
42
            $this->modified_columns[] = $column;
43
        }
44
45
        $this->touch();
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param $column
52
     * @return FlexibleEntityInterface
53
     */
54
    public function removeModifiedColumn($column)
55
    {
56
        $key = array_search($column, $this->modified_columns, true);
57
58
        if ($key !== FALSE) {
59
            unset($this->modified_columns[$key]);
60
        }
61
62
	$this->touch();
63
64
        return $this;
65
    }
66
}
67