SimpleArrayTypeTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSubmitValidData() 0 18 2
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