SimpleArrayTypeTest::testSubmitValidData()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace EmanueleMinotto\SimpleArrayBundle\Tests\Form\Type;
4
5
use EmanueleMinotto\SimpleArrayBundle\Form\Type\SimpleArrayType;
6
use Symfony\Component\Form\Test\TypeTestCase;
7
8
class SimpleArrayTypeTest extends TypeTestCase
9
{
10
    public function testSubmitValidData()
11
    {
12
        $formData = [
13
            'test' => 'test',
14
            'test2' => 'test2',
15
        ];
16
17
        $type = new SimpleArrayType();
18
        $form = $this->factory->create(
19
            method_exists($type, 'getBlockPrefix') ? get_class($type) : $type
0 ignored issues
show
Bug introduced by
It seems like method_exists($type, 'ge...et_class($type) : $type can also be of type object<EmanueleMinotto\S...m\Type\SimpleArrayType>; however, Symfony\Component\Form\F...toryInterface::create() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
20
        );
21
22
        // submit the data to the form directly
23
        $form->submit($formData);
24
25
        $this->assertTrue($form->isSynchronized());
26
        $this->assertEquals($formData, $form->getData());
27
    }
28
}
29