ColumnMoveRestrictionModel::getById()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 2
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
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 Jitamin\Model;
13
14
use Jitamin\Foundation\Database\Model;
15
16
/**
17
 * Class ColumnMoveRestrictionModel.
18
 */
19
class ColumnMoveRestrictionModel extends Model
20
{
21
    /**
22
     * SQL table name.
23
     *
24
     * @var string
25
     */
26
    const TABLE = 'column_has_move_restrictions';
27
28
    /**
29
     * Fetch one restriction.
30
     *
31
     * @param int $project_id
32
     * @param int $restriction_id
33
     *
34
     * @return array|null
35
     */
36 View Code Duplication
    public function getById($project_id, $restriction_id)
0 ignored issues
show
Duplication introduced by
This method 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...
37
    {
38
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ColumnMoveRestrictionModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
39
            ->table(self::TABLE)
40
            ->columns(
41
                self::TABLE.'.restriction_id',
42
                self::TABLE.'.project_id',
43
                self::TABLE.'.role_id',
44
                self::TABLE.'.src_column_id',
45
                self::TABLE.'.dst_column_id',
46
                'pr.role',
47
                'sc.title as src_column_title',
48
                'dc.title as dst_column_title'
49
            )
50
            ->left(ColumnModel::TABLE, 'sc', 'id', self::TABLE, 'src_column_id')
51
            ->left(ColumnModel::TABLE, 'dc', 'id', self::TABLE, 'dst_column_id')
52
            ->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id')
53
            ->eq(self::TABLE.'.project_id', $project_id)
54
            ->eq(self::TABLE.'.restriction_id', $restriction_id)
55
            ->findOne();
56
    }
57
58
    /**
59
     * Get all project column restrictions.
60
     *
61
     * @param int $project_id
62
     *
63
     * @return array
64
     */
65 View Code Duplication
    public function getAll($project_id)
0 ignored issues
show
Duplication introduced by
This method 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...
66
    {
67
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ColumnMoveRestrictionModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
            ->table(self::TABLE)
69
            ->columns(
70
                self::TABLE.'.restriction_id',
71
                self::TABLE.'.project_id',
72
                self::TABLE.'.role_id',
73
                self::TABLE.'.src_column_id',
74
                self::TABLE.'.dst_column_id',
75
                'pr.role',
76
                'sc.title as src_column_title',
77
                'dc.title as dst_column_title'
78
            )
79
            ->left(ColumnModel::TABLE, 'sc', 'id', self::TABLE, 'src_column_id')
80
            ->left(ColumnModel::TABLE, 'dc', 'id', self::TABLE, 'dst_column_id')
81
            ->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id')
82
            ->eq(self::TABLE.'.project_id', $project_id)
83
            ->findAll();
84
    }
85
86
    /**
87
     * Get all sortable column Ids.
88
     *
89
     * @param int    $project_id
90
     * @param string $role
91
     *
92
     * @return array
93
     */
94
    public function getSortableColumns($project_id, $role)
95
    {
96
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ColumnMoveRestrictionModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
97
            ->table(self::TABLE)
98
            ->columns(self::TABLE.'.src_column_id', self::TABLE.'.dst_column_id')
99
            ->left(ProjectRoleModel::TABLE, 'pr', 'role_id', self::TABLE, 'role_id')
100
            ->eq(self::TABLE.'.project_id', $project_id)
101
            ->eq('pr.role', $role)
102
            ->findAll();
103
    }
104
105
    /**
106
     * Create a new column restriction.
107
     *
108
     * @param int $project_id
109
     * @param int $role_id
110
     * @param int $src_column_id
111
     * @param int $dst_column_id
112
     *
113
     * @return bool|int
114
     */
115
    public function create($project_id, $role_id, $src_column_id, $dst_column_id)
116
    {
117
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ColumnMoveRestrictionModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
118
            ->table(self::TABLE)
119
            ->persist([
120
                'project_id'    => $project_id,
121
                'role_id'       => $role_id,
122
                'src_column_id' => $src_column_id,
123
                'dst_column_id' => $dst_column_id,
124
            ]);
125
    }
126
127
    /**
128
     * Remove a permission.
129
     *
130
     * @param int $restriction_id
131
     *
132
     * @return bool
133
     */
134
    public function remove($restriction_id)
135
    {
136
        return $this->db->table(self::TABLE)->eq('restriction_id', $restriction_id)->remove();
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\ColumnMoveRestrictionModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
137
    }
138
}
139