GetripayVerifyFakeEmails   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 2
A searchFileForDomain() 0 17 2
1
<?php
2
3
namespace Getripay\GetripayVerifyFakeEmails;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Facades\Storage;
7
use Illuminate\Support\LazyCollection;
8
9
class GetripayVerifyFakeEmails
10
{
11
    public $path_to_file = '/vendor/wesbos/burner-email-providers/emails.txt';
12
    // Build your next great package.
13
    public function validate ($attribute, $value, $parameters, $validator) {
0 ignored issues
show
Unused Code introduced by
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
        $email_domain = explode('@', $value)[1];
15
        logger("Email Domain => ".$email_domain);
16
        $collection = $this->searchFileForDomain($email_domain);
17
        $validator->setCustomMessages(['email.not_fake_email' => config('getripay_verify_fake_emails.validation_message')]);
18
        return !empty($collection) ? false : true;
19
    }
20
21
    protected function searchFileForDomain($searchfor){
22
        // get the file contents, assuming the file to be readable (and exist)
23
        $contents = file_get_contents(base_path().$this->path_to_file);
24
        // escape special characters in the query
25
        $pattern = preg_quote($searchfor, '/');
26
        // finalise the regular expression, matching the whole line
27
        $pattern = "/^.*$pattern.*\$/m";
28
        // search, and store all matching occurences in $matches
29
        if(preg_match_all($pattern, $contents, $matches)){
30
            //logger("Found matches:\n". implode("\n", $matches[0]));
31
            return $matches;
32
        }
33
        else{
34
            //echo "No matches found";
35
            return false;
36
        }
37
    }
38
}
39