CommentCreation   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 4 1
A getCompatibleEvents() 0 4 1
A getActionRequiredParameters() 0 4 1
A getEventRequiredParameters() 0 6 1
A doAction() 0 9 4
A hasRequiredCondition() 0 4 1
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\Action;
13
14
/**
15
 * Create automatically a comment from a webhook.
16
 */
17
class CommentCreation extends Base
18
{
19
    /**
20
     * Get automatic action description.
21
     *
22
     * @return string
23
     */
24
    public function getDescription()
25
    {
26
        return t('Create a comment from an external provider');
27
    }
28
29
    /**
30
     * Get the list of compatible events.
31
     *
32
     * @return string[]
33
     */
34
    public function getCompatibleEvents()
35
    {
36
        return [];
37
    }
38
39
    /**
40
     * Get the required parameter for the action (defined by the user).
41
     *
42
     * @return string[]
43
     */
44
    public function getActionRequiredParameters()
45
    {
46
        return [];
47
    }
48
49
    /**
50
     * Get the required parameter for the event.
51
     *
52
     * @return array
53
     */
54
    public function getEventRequiredParameters()
55
    {
56
        return [
57
            'task_id',
58
        ];
59
    }
60
61
    /**
62
     * Execute the action (create a new comment).
63
     *
64
     * @param array $data Event data dictionary
65
     *
66
     * @return bool True if the action was executed or false when not executed
67
     */
68
    public function doAction(array $data)
69
    {
70
        return (bool) $this->commentModel->create([
0 ignored issues
show
Documentation introduced by
The property commentModel does not exist on object<Jitamin\Action\CommentCreation>. 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...
71
            'reference' => isset($data['reference']) ? $data['reference'] : '',
72
            'comment'   => $data['comment'],
73
            'task_id'   => $data['task_id'],
74
            'user_id'   => isset($data['user_id']) && $this->projectPermissionModel->isAssignable($this->getProjectId(), $data['user_id']) ? $data['user_id'] : 0,
0 ignored issues
show
Documentation introduced by
The property projectPermissionModel does not exist on object<Jitamin\Action\CommentCreation>. 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...
75
        ]);
76
    }
77
78
    /**
79
     * Check if the event data meet the action condition.
80
     *
81
     * @param array $data Event data dictionary
82
     *
83
     * @return bool
84
     */
85
    public function hasRequiredCondition(array $data)
86
    {
87
        return !empty($data['comment']);
88
    }
89
}
90