Manager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 51
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCriteria() 0 4 1
A generate() 0 12 2
A score() 0 8 1
A passed() 0 13 1
1
<?php
2
3
namespace DeGraciaMathieu\Riddler;
4
5
use DeGraciaMathieu\Riddler\Contracts;
6
7
class Manager
8
{
9
10 26
    public function buildCriteria($name, Contracts\Dictionary $dictionary, Contracts\Occurrence $occurrence)
11
    {
12 26
        return new Criteria($name, $dictionary, $occurrence);
13
    }
14
15 13
    public function generate(array $criteriaBuilderList)
16
    {
17 13
        $concretPassword = [];
18
19 13
        foreach ($criteriaBuilderList as $criteriaBuilder) {
20 12
            $concretPassword = array_merge($concretPassword, $criteriaBuilder->build());
21 13
        }
22
23 13
        shuffle($concretPassword);
24
25 13
        return implode($concretPassword);
26
    }
27
28
    /**
29
     * Pourcentage de critères vérifiés
30
     *
31
     * @param  string $password
32
     * @param  array  $criterias
33
     * @return integer
34
     */
35 10
    public function score($password, array $criterias)
36
    {
37
        $criteriasPassed = array_filter($criterias, function ($criteria) use ($password) {
38 10
            return $criteria->passes($password);
39 10
        });
40
41 10
        return (int) number_format(count($criteriasPassed) * 100 / count($criterias));
42
    }
43
44
    public function passed($password, array $criterias)
45
    {
46 4
        $criteriasPassed = array_map(function ($criteria) use ($password) {
47
48
            return [
49 4
                'name' => $criteria->getName(),
50 4
                'passed' => $criteria->passes($password)
51
52 4
            ];
53 4
        }, $criterias);
54
55 4
        return $criteriasPassed;
56
    }
57
}
58