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

Manager::score()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace DeGraciaMathieu\Riddler;
4
5
use DeGraciaMathieu\Riddler\Contracts;
6
7
class Manager {
8
9 12
    public function buildCriteria(Contracts\Dictionary $dictionary, Contracts\Occurrence $occurrence)
10
    {
11 12
        return new Criteria($dictionary, $occurrence);
12
    }
13
14 12
    public function generate(array $criteriaBuilderList)
15
    {
16 12
        $concretPassword = [];
17
18 12
        foreach ($criteriaBuilderList as $criteriaBuilder) {
19 11
            $concretPassword = array_merge($concretPassword, $criteriaBuilder->build());
20
        }
21
22 12
        shuffle($concretPassword);
23
24 12
        return implode($concretPassword);
25
    }
26
27
    /**
28
     * Pourcentage de critères vérifiés
29
     *
30
     * @param  string $password
31
     * @param  array  $criterias
32
     * @return integer
33
     */
34
    public function score($password, array $criterias)
35
    {
36 1
        $criteriasPassed = array_filter($criterias, function ($criteria) use ($password) {
37 1
            return $criteria->passes($password);
38 1
        });
39
40 1
        return (int) count($criteriasPassed) * 100 / count($criterias);
41
    }
42
}
43