Passed
Push — master ( 8b81ae...74fc3b )
by Alec
03:24
created

MoneyFunctions::lessThan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 26.11.18
5
 * Time: 14:35
6
 */
7
8
namespace AlecRabbit\Money;
9
10
11
trait MoneyFunctions
12
{
13
    /**
14
     * @param Money $first
15
     * @param Money ...$collection
16
     *
17
     * @return Money
18
     */
19 3
    public static function min(Money $first, Money ...$collection): Money
20
    {
21 3
        $min = $first;
22
23 3
        foreach ($collection as $money) {
24 2
            if ($money->lessThan($min)) {
25 2
                $min = $money;
26
            }
27
        }
28
29 3
        return $min;
30
    }
31
32
    /**
33
     * Checks whether the value represented by this object is less than the other.
34
     *
35
     * @param Money $other
36
     *
37
     * @return bool
38
     */
39 5
    public function lessThan(Money $other): bool
40
    {
41 5
        return $this->compare($other) === -1;
0 ignored issues
show
Bug introduced by
It seems like compare() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        return $this->/** @scrutinizer ignore-call */ compare($other) === -1;
Loading history...
42
    }
43
44
    /**
45
     * @param Money $first
46
     * @param Money ...$collection
47
     *
48
     * @return Money
49
     */
50 3
    public static function max(Money $first, Money ...$collection): Money
51
    {
52 3
        $max = $first;
53
54 3
        foreach ($collection as $money) {
55 2
            if ($money->greaterThan($max)) {
56 2
                $max = $money;
57
            }
58
        }
59
60 3
        return $max;
61
    }
62
63
    /**
64
     * Checks whether the value represented by this object is greater than the other.
65
     *
66
     * @param Money $other
67
     *
68
     * @return bool
69
     */
70 5
    public function greaterThan(Money $other): bool
71
    {
72 5
        return $this->compare($other) === 1;
73
    }
74
75
    /**
76
     * @param Money $first
77
     * @param Money ...$collection
78
     *
79
     * @return Money
80
     */
81 6
    public static function sum(Money $first, Money ...$collection): Money
82
    {
83 6
        return $first->add(...$collection);
84
    }
85
86
87
88
}