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

Criteria::passes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 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