Online   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 28
loc 56
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setOnlineStatus() 14 14 2
A removeOnlineStatus() 14 14 2

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
 * Online Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  OpenChat
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/openchat
12
 */
13
namespace ChatApp;
14
require_once dirname(__DIR__).'/vendor/autoload.php';
15
use mysqli;
16
use Dotenv\Dotenv;
17
$dotenv = new Dotenv(dirname(__DIR__));
18
$dotenv->load();
19
20
21
/**
22
 * For checking online status
23
 *
24
 * @category PHP
25
 * @package  OpenChat
26
 * @author   Ankit Jain <[email protected]>
27
 * @license  The MIT License (MIT)
28
 * @link     https://github.com/ankitjain28may/openchat
29
 */
30
class Online
31
{
32
33
    /*
34
    |--------------------------------------------------------------------------
35
    | Online Class
36
    |--------------------------------------------------------------------------
37
    |
38
    | For checking online status.
39
    |
40
    */
41
42
    /**
43
     * Set Online Status
44
     *
45
     * @param string $userId To store userId
46
     *
47
     * @return void
48
     */
49 View Code Duplication
    public static function setOnlineStatus($userId)
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...
50
    {
51
        $connect = new mysqli(
52
            getenv('DB_HOST'),
53
            getenv('DB_USER'),
54
            getenv('DB_PASSWORD'),
55
            getenv('DB_NAME')
56
        );
57
        $query = "Update login set login_status = 1 where login_id = '$userId'";
58
        if (!$connect->query($query)) {
59
            echo $connect->error;
60
        }
61
        $connect->close();
62
    }
63
64
    /**
65
     * Remove Online Status
66
     *
67
     * @param string $userId To store userId
68
     *
69
     * @return void
70
     */
71 View Code Duplication
    public static function removeOnlineStatus($userId)
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...
72
    {
73
        $connect = new mysqli(
74
            getenv('DB_HOST'),
75
            getenv('DB_USER'),
76
            getenv('DB_PASSWORD'),
77
            getenv('DB_NAME')
78
        );
79
        $query = "Update login set login_status = 0 where login_id = '$userId'";
80
        if (!$connect->query($query)) {
81
            echo $connect->error;
82
        }
83
        $connect->close();
84
    }
85
}
86