Completed
Push — bug/accordion ( 6550f4...474aef )
by Grant
12:54 queued 07:32
created

PasswordFormatRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 21
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 3 1
A message() 0 2 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class PasswordFormatRule implements Rule
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PasswordFormatRule
Loading history...
9
{
10
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $attribute should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
11
     * This Password Validation rule should be referenced wherever we need the user input their password on the site.
12
     * The rules used on their passwords are;
13
     * 1) Password is required.
14
     * 2) Must be at least 8 characters
15
     * 3) The password must contain at least one character from the following categories:
16
     * lower-case characters (a-z), upper-case characters (A-Z),
17
     * digits (0-9), and non-alphanumeric symbols (%, $, !, etc.).
18
     * Guide used by Polivas Korop
19
     * https://laraveldaily.com/how-to-create-custom-validation-rules-laravel/
20
     */
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
Coding Style introduced by
Missing @return tag in function comment
Loading history...
21
22 10
    public function passes($attribute, $value) {
23 10
        $passwordPattern = "~^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[.!@#$%^&*]).*$~";
24 10
        return preg_match($passwordPattern, $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match($passwordPattern, $value) returns the type integer which is incompatible with the return type mandated by Illuminate\Contracts\Validation\Rule::passes() of boolean.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
25
    }
26
27 2
    public function message() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function message()
Loading history...
28 2
        return Lang::get('validation.custom.password');
29
    }
30
31
}
32