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

Completion   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPageCompletion() 0 9 3
A getPageCompletionPercentage() 0 12 2
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