Completed
Push — master ( 3f5d51...85b3b0 )
by Arjay
01:13
created

HasEvents   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 10 2
A on() 0 9 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Editor;
4
5
use Illuminate\Support\Str;
6
7
/**
8
 * @method Editor onClose($script)
9
 * @method Editor onCreate($script)
10
 * @method Editor onDisplayOrder($script)
11
 * @method Editor onEdit($script)
12
 * @method Editor onInitCreate($script)
13
 * @method Editor onInitEdit($script)
14
 * @method Editor onInitRemove($script)
15
 * @method Editor onInitSubmit($script)
16
 * @method Editor onOpen($script)
17
 * @method Editor onPostCreate($script)
18
 * @method Editor onPostEdit($script)
19
 * @method Editor onPostRemove($script)
20
 * @method Editor onPostSubmit($script)
21
 * @method Editor onPostUpload($script)
22
 * @method Editor onPreBlur($script)
23
 * @method Editor onPreBlurCancelled($script)
24
 * @method Editor onPreCreate($script)
25
 * @method Editor onPreEdit($script)
26
 * @method Editor onPreOpen($script)
27
 * @method Editor onPreOpenCancelled($script)
28
 * @method Editor onPreRemove($script)
29
 * @method Editor onPreSubmit($script)
30
 * @method Editor onPreSubmitCancelled($script)
31
 * @method Editor onPreUpload($script)
32
 * @method Editor onPreUploadCancelled($script)
33
 * @method Editor onProcessing($script)
34
 * @method Editor onRemove($script)
35
 * @method Editor onSetData($script)
36
 * @method Editor onSubmitComplete($script)
37
 * @method Editor onSubmitError($script)
38
 * @method Editor onSubmitSuccess($script)
39
 * @method Editor onSubmitUnsuccessful($script)
40
 * @method Editor onUploadXhrError($script)
41
 * @method Editor onUploadXhrSuccess($script)
42
 */
43
trait HasEvents
44
{
45
    /**
46
     * Magic method handler for editor events.
47
     *
48
     * @param string $name
49
     * @param mixed $arguments
50
     * @return Editor
51
     */
52
    public function __call($name, $arguments)
53
    {
54
        if (Str::startsWith($name, 'on')) {
55
            $event = Str::camel(substr($name, 2, strlen($name) - 2));
56
57
            return $this->on($event, $arguments[0]);
58
        }
59
60
        return parent::__call($name, $arguments);
61
    }
62
63
    /**
64
     * Add Editor event listener scripts.
65
     *
66
     * @param string $script
67
     * @return Editor
68
     * @see https://editor.datatables.net/reference/event
69
     */
70
    public function on($event, $script)
71
    {
72
        $this->attributes['events'][] = [
0 ignored issues
show
Bug introduced by
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
73
            'event' => $event,
74
            'script' => value($script),
75
        ];
76
77
        return $this;
78
    }
79
}
80