Completed
Push — fix-2494 ( 3153ee...40d9bb )
by Sam
13:43 queued 06:38
created

FormRequestHandlerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 87.5 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
dl 28
loc 32
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCallsActionOnFormHandler() 14 14 1
A testCallsActionOnForm() 14 14 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 SilverStripe\Forms\Tests;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\FormAction;
10
use SilverStripe\Forms\FormRequestHandler;
11
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestForm;
12
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestFormRequestHandler;
13
14
class FormRequestHandlerTest extends SapphireTest
15
{
16 View Code Duplication
    public function testCallsActionOnFormHandler()
0 ignored issues
show
Duplication introduced by
This method 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...
17
    {
18
        $form = new TestForm(
19
            new Controller(),
20
            'Form',
21
            new FieldList(),
22
            new FieldList(new FormAction('mySubmitOnFormHandler'))
23
        );
24
        $form->disableSecurityToken();
25
        $handler = new TestFormRequestHandler($form);
26
        $request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnFormHandler' => 1]);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

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
        $response = $handler->httpSubmission($request);
28
        $this->assertFalse($response->isError());
29
    }
30
31 View Code Duplication
    public function testCallsActionOnForm()
0 ignored issues
show
Duplication introduced by
This method 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...
32
    {
33
        $form = new TestForm(
34
            new Controller(),
35
            'Form',
36
            new FieldList(),
37
            new FieldList(new FormAction('mySubmitOnForm'))
38
        );
39
        $form->disableSecurityToken();
40
        $handler = new FormRequestHandler($form);
41
        $request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnForm' => 1]);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

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...
42
        $response = $handler->httpSubmission($request);
43
        $this->assertFalse($response->isError());
44
    }
45
}
46