Completed
Push — master ( c310a2...2d8cb6 )
by Kazi Mainuddin
07:28 queued 05:39
created

FormBuilderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 48.98 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 24
loc 49
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testItWillBuildWithCorrectCredentials() 0 9 1
A testWillFailWithWrongCredentials() 0 10 2
A getCredentials() 13 13 2
A getTransaction() 11 11 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 Tzsk\Payu\Tests\Helpers;
4
5
use Tzsk\Payu\Tests\TestCase;
6
use Tzsk\Payu\Helpers\FormBuilder;
7
use Illuminate\Support\Facades\Session;
8
9
class FormBuilderTest extends TestCase
10
{
11
    public function testItWillBuildWithCorrectCredentials()
12
    {
13
        $credentials = $this->getCredentials();
0 ignored issues
show
Unused Code introduced by
$credentials is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
14
15
        $builder = (new FormBuilder(request()))->build();
16
        $this->assertTrue(is_object($builder));
17
        $this->assertTrue(is_array($builder->fields));
18
        $this->assertNotEmpty($builder->url);
19
    }
20
21
    public function testWillFailWithWrongCredentials()
22
    {
23
        $credentials = $this->getCredentials(false);
0 ignored issues
show
Unused Code introduced by
$credentials is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
25
        try {
26
            $builder = (new FormBuilder(request()))->build();
0 ignored issues
show
Unused Code introduced by
$builder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
        } catch (\Exception $e) {
28
            $this->assertNotEmpty($e->getMessage());
29
        }
30
    }
31
32 View Code Duplication
    protected function getCredentials($transaction = true)
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...
33
    {
34
        $data = [
35
            'data' => $transaction ? $this->getTransaction() : [],
36
            'status_url' => 'foo',
37
            'account' => 'payubiz',
38
            'model' => ['id' => 1, 'class' => 'baz'],
39
        ];
40
41
        Session::put('tzsk_payu_data', $data);
42
43
        return $data;
44
    }
45
46 View Code Duplication
    protected function getTransaction()
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...
47
    {
48
        return [
49
            'txnid' => strtoupper(str_random(8)),
50
            'amount' => rand(100, 999),
51
            'productinfo' => 'Product Information',
52
            'firstname' => 'John',
53
            'email' => '[email protected]',
54
            'phone' => '9876543210',
55
        ];
56
    }
57
}
58