Passed
Pull Request — master (#7)
by Philippe
11:28
created

Completion::getPageCompletion()   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 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.6666
1
<?php
2
3
namespace Thinktomorrow\Squanto\Domain;
4
5
class Completion
6
{
7 2
    public static function getPageCompletion($pageid)
8
    {
9 2
        foreach (config('squanto.locales') as $locale) {
10 2
            if ((Integer)self::getPageCompletionPercentage($pageid, $locale) != 100) {
11 2
                return false;
12
            }
13
        }
14 2
        return true;
15
    }
16
17 4
    public static function getPageCompletionPercentage($pageid, $locale)
18
    {
19 4
        $page   = Page::find($pageid);
20 4
        $total  = $page->lines->count();
21
22 4
        if ($total == 0) {
23 2
            return 100;
24
        }
25
26 2
        $translated = collect(Line::getValuesByLocaleAndPage($locale, $page->key))->count();
27 2
        return $translated / $total * 100;
28
    }
29
}
30