Completed
Push — master ( 89612e...daf835 )
by Axel
02:08
created

PlusForTrelloHelper::extractEstimations()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 16
ccs 11
cts 12
cp 0.9167
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0052
1
<?php
2
3
namespace Scrumban\Utils;
4
5
class PlusForTrelloHelper
6
{
7
    const PREFIX = 'plus!';
8
    
9 2
    public static function extractEstimations(array $comments): array
10
    {
11 2
        $estimated = 0;
12 2
        $spent = 0;
13 2
        foreach ($comments as $comment) {
14 2
            $text = $comment['data']['text'];
15 2
            if (strpos($text, static::PREFIX) === false) {
16
                continue;
17
            }
18 2
            $parts = explode('/', $text);
19 2
            $spent += (float) array_reverse(explode(' ', $parts[0]))[0];
20 2
            $estimated += (float) $parts[1];
21
        }
22
        return [
23 2
            'estimated' => $estimated,
24 2
            'spent' => $spent
25
        ];
26
    }
27
}