Code Duplication    Length = 80-80 lines in 2 locations

app/Services/Action/TaskCloseNoActivityColumn.php 1 location

@@ 19-98 (lines=80) @@
16
/**
17
 * Close automatically a task after inactive and in a defined column.
18
 */
19
class TaskCloseNoActivityColumn extends Base
20
{
21
    /**
22
     * Get automatic action description.
23
     *
24
     * @return string
25
     */
26
    public function getDescription()
27
    {
28
        return t('Close a task when there is no activity in an specific column');
29
    }
30
31
    /**
32
     * Get the list of compatible events.
33
     *
34
     * @return array
35
     */
36
    public function getCompatibleEvents()
37
    {
38
        return [TaskModel::EVENT_DAILY_CRONJOB];
39
    }
40
41
    /**
42
     * Get the required parameter for the action (defined by the user).
43
     *
44
     * @return array
45
     */
46
    public function getActionRequiredParameters()
47
    {
48
        return [
49
            'duration'  => t('Duration in days'),
50
            'column_id' => t('Column'),
51
        ];
52
    }
53
54
    /**
55
     * Get the required parameter for the event.
56
     *
57
     * @return string[]
58
     */
59
    public function getEventRequiredParameters()
60
    {
61
        return ['tasks'];
62
    }
63
64
    /**
65
     * Execute the action (close the task).
66
     *
67
     * @param array $data Event data dictionary
68
     *
69
     * @return bool True if the action was executed or false when not executed
70
     */
71
    public function doAction(array $data)
72
    {
73
        $results = [];
74
        $max = $this->getParam('duration') * 86400;
75
76
        foreach ($data['tasks'] as $task) {
77
            $duration = time() - $task['date_modification'];
78
79
            if ($duration > $max && $task['column_id'] == $this->getParam('column_id')) {
80
                $results[] = $this->taskStatusModel->close($task['id']);
81
            }
82
        }
83
84
        return in_array(true, $results, true);
85
    }
86
87
    /**
88
     * Check if the event data meet the action condition.
89
     *
90
     * @param array $data Event data dictionary
91
     *
92
     * @return bool
93
     */
94
    public function hasRequiredCondition(array $data)
95
    {
96
        return count($data['tasks']) > 0;
97
    }
98
}
99

app/Services/Action/TaskCloseNotMovedColumn.php 1 location

@@ 19-98 (lines=80) @@
16
/**
17
 * Close automatically in a defined column after a certain amount of time.
18
 */
19
class TaskCloseNotMovedColumn extends Base
20
{
21
    /**
22
     * Get automatic action description.
23
     *
24
     * @return string
25
     */
26
    public function getDescription()
27
    {
28
        return t('Close a task in a specific column when not moved during a given period');
29
    }
30
31
    /**
32
     * Get the list of compatible events.
33
     *
34
     * @return array
35
     */
36
    public function getCompatibleEvents()
37
    {
38
        return [TaskModel::EVENT_DAILY_CRONJOB];
39
    }
40
41
    /**
42
     * Get the required parameter for the action (defined by the user).
43
     *
44
     * @return array
45
     */
46
    public function getActionRequiredParameters()
47
    {
48
        return [
49
            'duration'  => t('Duration in days'),
50
            'column_id' => t('Column'),
51
        ];
52
    }
53
54
    /**
55
     * Get the required parameter for the event.
56
     *
57
     * @return string[]
58
     */
59
    public function getEventRequiredParameters()
60
    {
61
        return ['tasks'];
62
    }
63
64
    /**
65
     * Execute the action (close the task).
66
     *
67
     * @param array $data Event data dictionary
68
     *
69
     * @return bool True if the action was executed or false when not executed
70
     */
71
    public function doAction(array $data)
72
    {
73
        $results = [];
74
        $max = $this->getParam('duration') * 86400;
75
76
        foreach ($data['tasks'] as $task) {
77
            $duration = time() - $task['date_moved'];
78
79
            if ($duration > $max && $task['column_id'] == $this->getParam('column_id')) {
80
                $results[] = $this->taskStatusModel->close($task['id']);
81
            }
82
        }
83
84
        return in_array(true, $results, true);
85
    }
86
87
    /**
88
     * Check if the event data meet the action condition.
89
     *
90
     * @param array $data Event data dictionary
91
     *
92
     * @return bool
93
     */
94
    public function hasRequiredCondition(array $data)
95
    {
96
        return count($data['tasks']) > 0;
97
    }
98
}
99