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

Completion::check()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.6666
c 0
b 0
f 0
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