Completed
Push — master ( 7e3540...47b2d2 )
by Ankit
03:55
created

TestProfile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 53.49 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 23
loc 43
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 12 12 1
A test_getProfile() 0 10 1
A tearDown() 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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 7.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace ChatApp\Tests;
3
4
use PHPUnit_Framework_TestCase;
5
use ChatApp\Profile;
6
use Dotenv\Dotenv;
7
$dotenv = new Dotenv(dirname(__DIR__));
8
$dotenv->load();
9
10
class TestProfile
11
    extends
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
12
        PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "PHPUnit_Framework_TestCase"; 8 found
Loading history...
13
{
14
    protected $userId;
15
16 View Code Duplication
    public function setUp()
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
        $connect = mysqli_connect(
19
            getenv('DB_HOST'),
20
            getenv('DB_USER'),
21
            getenv('DB_PASSWORD'),
22
            getenv('DB_NAME')
23
        );
24
        $this->userId = 1000;
25
        $query = "INSERT INTO profile VALUES('$this->userId', 'Joined OpenChat', 'Joined OpenChat', '')";
26
        $this->assertTrue($connect->query($query));
27
    }
28
29
30
    public function test_getProfile()
31
    {
32
        $output = Profile::getProfile($this->userId);
33
        $this->assertEquals([
34
            'login_id' => '1000',
35
            'status' => 'Joined OpenChat',
36
            'education' => 'Joined OpenChat',
37
            'gender' => ''
38
        ], $output);
39
    }
40
41 View Code Duplication
    public function tearDown()
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...
42
    {
43
        $connect = mysqli_connect(
44
            getenv('DB_HOST'),
45
            getenv('DB_USER'),
46
            getenv('DB_PASSWORD'),
47
            getenv('DB_NAME')
48
        );
49
        $query = "DELETE from profile where login_id = '$this->userId'";
50
        $this->assertTrue($connect->query($query));
51
    }
52
}
53
54