Completed
Push — Lonja/albertg ( 67863a...bda4e5 )
by Albert
07:39 queued 05:26
created

CalculateLoadBenefit::__invoke()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 4
nop 3
crap 5
1
<?php
2
3
namespace Kata\Lonja\Domain\Service;
4
5
use Kata\Lonja\Domain\Model\Destination;
6
use Kata\Lonja\Domain\Model\Load;
7
use Kata\Lonja\Domain\PriceRule;
8
9
final class CalculateLoadBenefit
10
{
11
    /**
12
     * @param Load        $a_load
13
     * @param Destination $a_destination
14
     * @param PriceRule[] $some_price_rules
15
     *
16
     * @return float
17
     */
18 4
    public function __invoke(Load $a_load, Destination $a_destination, array $some_price_rules): float
19
    {
20 4
        $load_lines = $a_load->lines();
21 4
        $benefits   = 0;
22
23 4
        foreach ($load_lines as $load_line)
24
        {
25 4
            foreach ($some_price_rules as $price_rule)
26
            {
27 4
                if ($load_line->product()->equals($price_rule->product()) && $a_destination->city() === $price_rule->city())
0 ignored issues
show
Documentation introduced by
$price_rule->product() is of type object<Kata\Lonja\Domain\Model\Product>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
                {
29 4
                    $benefits += $price_rule->price() * $load_line->kilograms();
30
                }
31
            }
32
        }
33
34 4
        return $benefits;
35
    }
36
}