Validate   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 48.48 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 32
loc 66
rs 10
wmc 7
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A validateEmailInDb() 11 11 3
A validateUsernameInDb() 11 11 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
 * Validate 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 Validating User Data whether he is registered or not
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
31
class Validate
32
{
33
    /*
34
    |--------------------------------------------------------------------------
35
    | Validate Class
36
    |--------------------------------------------------------------------------
37
    |
38
    | For Validating User Data whether he is registered or not.
39
    |
40
    */
41
42
    protected $connect;
43
44
    /**
45
     * Create a new class instance.
46
     *
47
     * @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...
48
     */
49 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...
50
    {
51
        $this->connect = new mysqli(
52
            getenv('DB_HOST'),
53
            getenv('DB_USER'),
54
            getenv('DB_PASSWORD'),
55
            getenv('DB_NAME')
56
        );
57
    }
58
59
    /**
60
     * Validating Email in Database.
61
     *
62
     * @param string $email To store email id
63
     *
64
     * @return integer 0|1
65
     */
66 View Code Duplication
    public function validateEmailInDb($email)
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...
67
    {
68
        $query = "SELECT login_id FROM login WHERE email = '$email'";
69
        if ($result = $this->connect->query($query)) {
70
            if ($result->num_rows > 0) {
71
                return 1;
72
            } else {
73
                return 0;
74
            }
75
        }
76
    }
77
78
    /**
79
     * Validating Username in Database.
80
     *
81
     * @param string $username To store username
82
     *
83
     * @return integer 0|1
84
     */
85 View Code Duplication
    function validateUsernameInDb($username)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
86
    {
87
        $query = "SELECT login_id FROM login WHERE username = '$username'";
88
        if ($result = $this->connect->query($query)) {
89
            if ($result->num_rows > 0) {
90
                return 1;
91
            } else {
92
                return 0;
93
            }
94
        }
95
    }
96
}
97