Worker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A prependChars() 0 4 1
A appendChars() 0 4 1
A execute() 0 8 1
1
<?php
2
namespace Sandbox\Demos;
3
4
use Redbox\Hooks\Filters;
5
6
require 'autoload.php';
7
8
9
class Worker
10
{
11
12
    public function prependChars($text = '')
13
    {
14
        return '@@' . $text;
15
    }
16
17
    public function appendChars($text = '')
18
    {
19
        return $text . '@@';
20
    }
21
22
    public function execute()
23
    {
24
25
        Filters::addFilter('manipulate_string', [$this, 'prependChars']);
0 ignored issues
show
Documentation introduced by
array($this, 'prependChars') is of type array<integer,this<Sandb...Worker>","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...
26
        Filters::addFilter('manipulate_string', [$this, 'appendChars']);
0 ignored issues
show
Documentation introduced by
array($this, 'appendChars') is of type array<integer,this<Sandb...Worker>","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...
27
28
        return Filters::applyFilter('manipulate_string', 'This is a text');
29
    }
30
}
31
32
$worker = new Worker;
33
$out = $worker->execute();
34
35
/**
36
 * The result should be:
37
 *
38
 * Result: @@This is a text@@
39
 */
40
echo "Result: " . $out . "\n";
41
42
/**
43
 * This is not required in your code. I have to add this to reset my unit tests.
44
 */
45
Filters::removeAllFilters('manipulate_string');
46