TaskProjectDuplicationModel::duplicateToProject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 6
dl 0
loc 12
rs 9.4285
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
/**
15
 * Task Project Duplication.
16
 */
17
class TaskProjectDuplicationModel extends TaskDuplicationModel
18
{
19
    /**
20
     * Duplicate a task to another project.
21
     *
22
     * @param int $task_id
23
     * @param int $project_id
24
     * @param int $swimlane_id
25
     * @param int $column_id
26
     * @param int $category_id
27
     * @param int $owner_id
28
     *
29
     * @return bool|int
30
     */
31
    public function duplicateToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null)
32
    {
33
        $values = $this->prepare($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id);
34
        $this->checkDestinationProjectValues($values);
35
        $new_task_id = $this->save($task_id, $values);
36
37
        if ($new_task_id !== false) {
38
            $this->tagDuplicationModel->duplicateTaskTagsToAnotherProject($task_id, $new_task_id, $project_id);
0 ignored issues
show
Documentation introduced by
The property tagDuplicationModel does not exist on object<Jitamin\Model\TaskProjectDuplicationModel>. 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
        }
40
41
        return $new_task_id;
42
    }
43
44
    /**
45
     * Prepare values before duplication.
46
     *
47
     * @param int $task_id
48
     * @param int $project_id
49
     * @param int $swimlane_id
50
     * @param int $column_id
51
     * @param int $category_id
52
     * @param int $owner_id
53
     *
54
     * @return array
55
     */
56
    protected function prepare($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id)
57
    {
58
        $values = $this->copyFields($task_id);
59
        $values['project_id'] = $project_id;
60
        $values['column_id'] = $column_id !== null ? $column_id : $values['column_id'];
61
        $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id'];
62
        $values['category_id'] = $category_id !== null ? $category_id : $values['category_id'];
63
        $values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id'];
64
65
        return $values;
66
    }
67
}
68