BooleanTypeTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testType() 0 16 1
A assertForm() 0 5 1
1
<?php declare(strict_types = 1);
2
3
namespace Bukashk0zzz\BooleanTypeBundle\Tests;
4
5
use Bukashk0zzz\BooleanTypeBundle\Form\Type\BooleanType;
6
use Symfony\Component\Form\FormInterface;
7
use Symfony\Component\Form\Test\TypeTestCase;
8
9
/**
10
 * @internal
11
 */
12
final class BooleanTypeTest extends TypeTestCase
13
{
14
    /**
15
     * @var int
16
     */
17
    protected $status;
18
19
    /**
20
     * Test type.
21
     */
22
    public function testType(): void
23
    {
24
        $this->status = true;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type integer, but true is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
25
        $form = $this->factory->create(BooleanType::class);
26
        $form->submit($this->status);
0 ignored issues
show
Documentation introduced by
$this->status is of type boolean, but the function expects a string|array|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...
27
        $this->assertForm($form);
28
29
        $this->status = false;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type integer, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
30
        $form = $this->factory->create(BooleanType::class);
31
        $form->submit($this->status);
0 ignored issues
show
Documentation introduced by
$this->status is of type boolean, but the function expects a string|array|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...
32
        $this->assertForm($form);
33
34
        $form = $this->factory->create(BooleanType::class);
35
        $form->submit('');
36
        self::assertSame('', $form->getViewData());
37
    }
38
39
    private function assertForm(FormInterface $form): void
40
    {
41
        self::assertTrue($form->isSynchronized());
42
        self::assertSame((string) $this->status, $form->getViewData());
43
    }
44
}
45