Completed
Push — master ( 43695e...e3b460 )
by dotzero
27:31
created

Callbacks   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 10
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A event() 0 7 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 32 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
require_once __DIR__ . '/../vendor/autoload.php';
4
5
try {
6
    $listener = new \AmoCRM\Webhooks();
7
8
    // Добавление обработчка на уведомление contacts->add
9
    $listener->on('contacts-add', function ($domain, $id, $data) {
0 ignored issues
show
Unused Code introduced by
The parameter $domain is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
10
        // $domain Поддомен amoCRM
11
        // $id Id объекта связаного с уведомленим
12
        // $data Поля возвращаемые уведомлением
13
    });
14
15
    // Добавление обработчка на несколько уведомлений
16
    $listener->on(['contacts-update', 'company-update'], function ($domain, $id, $data) {
0 ignored issues
show
Documentation introduced by
array('contacts-update', 'company-update') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The parameter $domain is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
        // $domain Поддомен amoCRM
18
        // $id Id объекта связаного с уведомленим
19
        // $data Поля возвращаемые уведомлением
20
    });
21
22
    // Добавление обработчка как метод класса
23
    $listener->on('companies-delete', ['Callbacks', 'event']);
24
25
    // Вызов обработчика уведомлений
26
    $listener->listen();
27
28
} catch (\AmoCRM\Exception $e) {
29
    printf('Error (%d): %s' . PHP_EOL, $e->getCode(), $e->getMessage());
30
}
31
32
class Callbacks
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
33
{
34
    static public function event($domain, $id, $data)
0 ignored issues
show
Unused Code introduced by
The parameter $domain is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
35
    {
36
        echo 'Fired ' . __METHOD__;
37
        // $domain Поддомен amoCRM
38
        // $id Id объекта связаного с уведомленим
39
        // $data Поля возвращаемые уведомлением
40
    }
41
}
42