This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | use Jitamin\Foundation\Security\Role; |
||
16 | |||
17 | /** |
||
18 | * Project Duplication. |
||
19 | */ |
||
20 | class ProjectDuplicationModel extends Model |
||
21 | { |
||
22 | /** |
||
23 | * Get list of optional models to duplicate. |
||
24 | * |
||
25 | * @return string[] |
||
26 | */ |
||
27 | View Code Duplication | public function getOptionalSelection() |
|
0 ignored issues
–
show
|
|||
28 | { |
||
29 | return [ |
||
30 | 'categoryModel', |
||
31 | 'projectPermissionModel', |
||
32 | 'actionModel', |
||
33 | 'swimlaneModel', |
||
34 | 'tagDuplicationModel', |
||
35 | 'projectMetadataModel', |
||
36 | 'projectTaskDuplicationModel', |
||
37 | ]; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Get list of all possible models to duplicate. |
||
42 | * |
||
43 | * @return string[] |
||
44 | */ |
||
45 | View Code Duplication | public function getPossibleSelection() |
|
0 ignored issues
–
show
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. ![]() |
|||
46 | { |
||
47 | return [ |
||
48 | 'boardModel', |
||
49 | 'categoryModel', |
||
50 | 'projectPermissionModel', |
||
51 | 'actionModel', |
||
52 | 'swimlaneModel', |
||
53 | 'tagDuplicationModel', |
||
54 | 'projectMetadataModel', |
||
55 | 'projectTaskDuplicationModel', |
||
56 | ]; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Get a valid project name for the duplication. |
||
61 | * |
||
62 | * @param string $name Project name |
||
63 | * @param int $max_length Max length allowed |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | public function getClonedProjectName($name, $max_length = 50) |
||
68 | { |
||
69 | $suffix = ' ('.t('Clone').')'; |
||
70 | |||
71 | if (strlen($name.$suffix) > $max_length) { |
||
72 | $name = substr($name, 0, $max_length - strlen($suffix)); |
||
73 | } |
||
74 | |||
75 | return $name.$suffix; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Clone a project with all settings. |
||
80 | * |
||
81 | * @param int $src_project_id Project Id |
||
82 | * @param array $selection Selection of optional project parts to duplicate |
||
83 | * @param int $owner_id Owner of the project |
||
84 | * @param string $name Name of the project |
||
85 | * @param bool $private Force the project to be private |
||
86 | * |
||
87 | * @return int Cloned Project Id |
||
88 | */ |
||
89 | public function duplicate($src_project_id, $selection = ['projectPermissionModel', 'categoryModel', 'actionModel'], $owner_id = 0, $name = null, $private = null) |
||
90 | { |
||
91 | $this->db->startTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
92 | |||
93 | // Get the cloned project Id |
||
94 | $dst_project_id = $this->copy($src_project_id, $owner_id, $name, $private); |
||
95 | |||
96 | if ($dst_project_id === false) { |
||
97 | $this->db->cancelTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
98 | |||
99 | return false; |
||
100 | } |
||
101 | |||
102 | // Clone Columns, Categories, Permissions and Actions |
||
103 | foreach ($this->getPossibleSelection() as $model) { |
||
104 | |||
105 | // Skip if optional part has not been selected |
||
106 | if (in_array($model, $this->getOptionalSelection()) && !in_array($model, $selection)) { |
||
107 | continue; |
||
108 | } |
||
109 | |||
110 | // Skip permissions for private projects |
||
111 | if ($private && $model === 'projectPermissionModel') { |
||
112 | continue; |
||
113 | } |
||
114 | |||
115 | if (!$this->$model->duplicate($src_project_id, $dst_project_id)) { |
||
116 | $this->db->cancelTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
117 | |||
118 | return false; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | if (!$this->makeOwnerManager($dst_project_id, $owner_id)) { |
||
123 | $this->db->cancelTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
124 | |||
125 | return false; |
||
126 | } |
||
127 | |||
128 | $this->db->closeTransaction(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
129 | |||
130 | return (int) $dst_project_id; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * Create a project from another one. |
||
135 | * |
||
136 | * @param int $src_project_id |
||
137 | * @param int $owner_id |
||
138 | * @param string $name |
||
139 | * @param bool $private |
||
140 | * |
||
141 | * @return int |
||
142 | */ |
||
143 | private function copy($src_project_id, $owner_id = 0, $name = null, $private = null) |
||
144 | { |
||
145 | $project = $this->projectModel->getById($src_project_id); |
||
0 ignored issues
–
show
The property
projectModel does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
146 | $is_private = empty($project['is_private']) ? 0 : 1; |
||
147 | |||
148 | $values = [ |
||
149 | 'name' => $name ?: $this->getClonedProjectName($project['name']), |
||
150 | 'is_active' => 1, |
||
151 | 'last_modified' => time(), |
||
152 | 'token' => '', |
||
153 | 'is_public' => 0, |
||
154 | 'is_private' => $private ? 1 : $is_private, |
||
155 | 'owner_id' => $owner_id, |
||
156 | 'priority_default' => $project['priority_default'], |
||
157 | 'priority_start' => $project['priority_start'], |
||
158 | 'priority_end' => $project['priority_end'], |
||
159 | ]; |
||
160 | |||
161 | if (!$this->db->table(ProjectModel::TABLE)->save($values)) { |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
162 | return false; |
||
0 ignored issues
–
show
The return type of
return false; (false ) is incompatible with the return type documented by Jitamin\Model\ProjectDuplicationModel::copy of type integer .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
163 | } |
||
164 | |||
165 | return $this->db->getLastId(); |
||
0 ignored issues
–
show
The property
db does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Make sure that the creator of the duplicated project is also owner. |
||
170 | * |
||
171 | * @param int $dst_project_id |
||
172 | * @param int $owner_id |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | private function makeOwnerManager($dst_project_id, $owner_id) |
||
177 | { |
||
178 | if ($owner_id > 0) { |
||
179 | $this->projectUserRoleModel->removeUser($dst_project_id, $owner_id); |
||
0 ignored issues
–
show
The property
projectUserRoleModel does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
180 | |||
181 | if (!$this->projectUserRoleModel->addUser($dst_project_id, $owner_id, Role::PROJECT_MANAGER)) { |
||
0 ignored issues
–
show
The property
projectUserRoleModel does not exist on object<Jitamin\Model\ProjectDuplicationModel> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
182 | return false; |
||
183 | } |
||
184 | } |
||
185 | |||
186 | return true; |
||
187 | } |
||
188 | } |
||
189 |
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.