Completed
Push — master ( 34d315...a20938 )
by Garrett
09:58
created

HTMLString::nl2br()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace StringObject\Decorator;
4
5
use StringObject\AnyString;
6
7
class HTMLString extends TextString
8
{
9
    public function nl2br()
10
    {
11
        return new self(\nl2br($this->raw, false));
0 ignored issues
show
Bug introduced by
The property raw 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...
Documentation introduced by
\nl2br($this->raw, false) is of type string, but the function expects a object<StringObject\AnyString>.

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...
12
    }
13
14
    public function nl2brX()
15
    {
16
        return new self(\nl2br($this->raw, true));
0 ignored issues
show
Documentation introduced by
\nl2br($this->raw, true) is of type string, but the function expects a object<StringObject\AnyString>.

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...
17
    }
18
}
19