Action   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A firstFunc() 0 4 1
A secondFunc() 0 4 1
A execute() 0 6 1
1
<?php
2
namespace Sandbox\Demos;
3
4
require 'autoload.php';
5
6
use Redbox\Hooks\Actions;
7
8
class Action
9
{
10
11
12
    /**
13
     */
14
    public function firstFunc()
15
    {
16
        echo "Called first\n";
17
    }
18
19
    /**
20
     */
21
    public function secondFunc()
22
    {
23
        echo "Called second\n";
24
    }
25
26
    /**
27
     * Register and call the actions.
28
     *
29
     * @return string
30
     */
31
    public function execute()
32
    {
33
        Actions::addAction('say_hello', [$this, 'firstFunc'], 0);
0 ignored issues
show
Documentation introduced by
array($this, 'firstFunc') is of type array<integer,this<Sandb...Action>","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...
34
        Actions::addAction('say_hello', [$this, 'secondFunc'], 1);
0 ignored issues
show
Documentation introduced by
array($this, 'secondFunc') is of type array<integer,this<Sandb...Action>","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...
35
        return Actions::doAction('say_hello');
36
    }
37
}
38
39
$instance = new Action;
40
/**
41
 * Result should be:
42
 *
43
 * Called first
44
 * Called second
45
 *
46
 */
47
$instance->execute();
48
49
/**
50
 * This is not required in your code. I have to add this to reset my unit tests.
51
 */
52
Actions::removeAllActions('say_hello');
53