User   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 16.36 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 9
loc 55
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A userDetails() 0 15 3

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
 * User 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 retreiving User Information
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 User
31
{
32
    /*
33
    |--------------------------------------------------------------------------
34
    | User Class
35
    |--------------------------------------------------------------------------
36
    |
37
    | For retreiving User Information.
38
    |
39
    */
40
41
    protected $details;
42
    protected $query;
43
    protected $result;
44
    protected $connect;
45
46
    /**
47
     * Create a new class instance.
48
     *
49
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
50
     */
51 View Code Duplication
    public function __construct()
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...
52
    {
53
        $this->connect = new mysqli(
54
            getenv('DB_HOST'),
55
            getenv('DB_USER'),
56
            getenv('DB_PASSWORD'),
57
            getenv('DB_NAME')
58
        );
59
    }
60
61
    /**
62
     * Getting User details on the basis of uername or login Id
63
     *
64
     * @param string  $details To store loginid/username
65
     * @param boollen $para    To store True/False
66
     *
67
     * @return array or null
68
     */
69
    public function userDetails($details, $para)
70
    {
71
        if ($para == true) {
72
            $this->query = "SELECT * from login where login_id = '$details'";
73
        } else {
74
            $this->query = "SELECT * from login where username = '$details'";
75
        }
76
        $this->result = $this->connect->query($this->query);
77
        if ($this->result->num_rows > 0) {
78
            $this->details = $this->result->fetch_assoc();
79
            return $this->details;
80
        } else {
81
            return null;
82
        }
83
    }
84
}
85