SluggableTraitTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSetterDoesntCastNullToEmptyString() 0 13 1
1
<?php
2
/**
3
 * @author Stefano Torresi (http://stefanotorresi.it)
4
 * @license See the file LICENSE.txt for copying permission.
5
 * ************************************************
6
 */
7
8
namespace Thorr\Persistence\Test\Entity;
9
10
use PHPUnit_Framework_MockObject_MockObject as MockObject;
11
use PHPUnit_Framework_TestCase as TestCase;
12
use Thorr\Persistence\Entity\SluggableTrait;
13
14
class SluggableTraitTest extends TestCase
15
{
16
    public function testSetterDoesntCastNullToEmptyString()
17
    {
18
        /** @var SluggableTrait|MockObject $sluggable */
19
        $sluggable = $this->getMockForTrait(SluggableTrait::class);
20
21
        $this->assertNull($sluggable->getSlug());
22
23
        $sluggable->setSlug(false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|null.

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...
24
        $this->assertSame('', $sluggable->getSlug());
25
26
        $sluggable->setSlug(null);
27
        $this->assertNull($sluggable->getSlug());
28
    }
29
}
30