Completed
Pull Request — master (#7)
by Philippe
04:00
created

Completion   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 9 3
A asPercentage() 0 11 2
1
<?php
2
3
namespace Thinktomorrow\Squanto\Domain;
4
5
class Completion
6
{
7 4
    public static function check(Page $page)
8
    {
9 4
        foreach (config('squanto.locales') as $locale) {
10 4
            if ((Integer)self::asPercentage($page, $locale) != 100) {
11 4
                return false;
12
            }
13
        }
14 4
        return true;
15
    }
16
17 8
    public static function asPercentage(Page $page, $locale)
18
    {
19 8
        $total  = $page->lines->count();
20
21 8
        if ($total == 0) {
22 4
            return 100;
23
        }
24
25 4
        $translated = collect(Line::getValuesByLocaleAndPage($locale, $page->key))->count();
26 4
        return $translated / $total * 100;
27
    }
28
}
29