Validate   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 35.59 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validateEmailInDb() 10 10 3
A validateUsernameInDb() 10 10 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
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 25 and the first side effect is on line 14.

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
/**
3
 * Validate Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  Registration-Module
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/registration-module
12
 */
13
namespace AnkitJain\RegistrationModule;
14
require_once dirname(__DIR__) . '/config/database.php';
15
16
/**
17
 * For validation the Email and Username in DB.
18
 *
19
 * @category PHP
20
 * @package  Registration-Module
21
 * @author   Ankit Jain <[email protected]>
22
 * @license  The MIT License (MIT)
23
 * @link     https://github.com/ankitjain28may/registration-module
24
 */
25
class Validate
26
{
27
    /*
28
    |--------------------------------------------------------------------------
29
    | Validate Class
30
    |--------------------------------------------------------------------------
31
    |
32
    | For validation the Email and Username in DB.
33
    |
34
    */
35
36
    protected $connect;
37
38
    /**
39
     * Create a new controller instance.
40
     *
41
     * @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...
42
     */
43
    public function __construct()
44
    {
45
        $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
46
    }
47
48
    /**
49
     * For checking whether the credentials are empty or not
50
     *
51
     * @param string $email Contains the email for checking
52
     *
53
     * @return 0 | 1
0 ignored issues
show
Documentation introduced by
The doc-type 0 could not be parsed: Unknown type name "0" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
54
     */
55 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...
56
    {
57
        $query = "SELECT login_id FROM login WHERE email = '$email'";
58
        if ($result = $this->connect->query($query)) {
59
            if ($result->num_rows > 0) {
60
                return 1;
61
            }
62
            return 0;
63
        }
64
    }
65
66
    /**
67
     * For checking whether the credentials are empty or not
68
     *
69
     * @param string $username Contains the username for checking
70
     *
71
     * @return 0 | 1
0 ignored issues
show
Documentation introduced by
The doc-type 0 could not be parsed: Unknown type name "0" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
72
     */
73 View Code Duplication
    public function validateUsernameInDb($username)
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...
74
    {
75
        $query = "SELECT login_id FROM login WHERE username = '$username'";
76
        if ($result = $this->connect->query($query)) {
77
            if ($result->num_rows > 0) {
78
                return 1;
79
            }
80
            return 0;
81
        }
82
    }
83
}
84