Passed
Push — master ( 89de50...6aa9d5 )
by DeGracia
46s
created

Criteria   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 4 1
A passes() 0 12 1
1
<?php
2
3
namespace DeGraciaMathieu\Riddler;
4
5
class Criteria {
6
7
	protected $dictionary;
8
	protected $occurrence;
9
10 12
    public function __construct($dictionary, $occurrence)
11
    {
12 12
        $this->dictionary = $dictionary;
13 12
        $this->occurrence = $occurrence;
14 12
    }
15
16 11
    public function build()
17
    {
18 11
        return $this->occurrence->parse($this->dictionary->handle());
19
    }
20
21
    /**
22
     * Détermine si le mot de passe vérifie le critère
23
     *
24
     * @param string $password
25
     * @return boolean
26
     */
27 1
    public function passes($password)
28
    {
29 1
        $size = $this->occurrence->size();
30
31 1
        $regex = preg_quote(implode($this->dictionary->handle()), '/');
32
33 1
        $regex = array_fill(0, $size, '[' . $regex . ']');
34
35 1
        $regex = '/(?=.*' . implode('.*', $regex) . ')/';
36
37 1
        return preg_match($regex, $password);
38
    }
39
}
40