HeaderPagePartAdminTypeTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 5 5 1
A testBuildForm() 7 7 1
A testConfigureOptions() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kunstmaan\PagePartBundle\Tests\Form;
4
5
use Kunstmaan\PagePartBundle\Form\HeaderPagePartAdminType;
6
use Kunstmaan\PagePartBundle\Tests\unit\Form\PagePartAdminTypeTestCase;
7
use Symfony\Component\Form\FormBuilderInterface;
8
9
/**
10
 * Generated by PHPUnit_SkeletonGenerator on 2012-08-20 at 13:19:22.
11
 */
12 View Code Duplication
class HeaderPagePartAdminTypeTest extends PagePartAdminTypeTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * @var HeaderPagePartAdminType
16
     */
17
    protected $object;
18
19
    /**
20
     * Sets up the fixture, for example, opens a network connection.
21
     * This method is called before a test is executed.
22
     */
23
    protected function setUp(): void
24
    {
25
        parent::setUp();
26
        $this->object = new HeaderPagePartAdminType();
27
    }
28
29
    public function testBuildForm()
30
    {
31
        $builder = $this->createMock(FormBuilderInterface::class);
32
        $builder->expects($this->exactly(2))->method('add');
33
34
        $this->object->buildForm($builder, array());
0 ignored issues
show
Documentation introduced by
$builder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormBuilderInterface>.

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...
35
    }
36
37
    public function testConfigureOptions()
38
    {
39
        $this->object->configureOptions($this->resolver);
40
        $resolve = $this->resolver->resolve();
41
        $this->assertEquals('Kunstmaan\PagePartBundle\Entity\HeaderPagePart', $resolve['data_class']);
42
    }
43
}
44