ArithmeticTrait::reversePolarity()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
crap 3
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Mathematical\Operator;
4
5
use BestServedCold\PhalueObjects\Contract\ValueObject as ValueObjectInterface;
6
7
/**
8
 * Class ArithmeticTrait
9
 *
10
 * @package   BestServedCold\PhalueObjects\Mathematical\Operator
11
 * @author    Adam Lewis <[email protected]>
12
 * @copyright Copyright (c) 2015 Best Served Cold Media Limited
13
 * @license   http://http://opensource.org/licenses/GPL-3.0 GPL License
14
 * @link      http://bestservedcold.com
15
 * @since     0.0.1-alpha
16
 * @version   0.0.2-alpha
17
 */
18
trait ArithmeticTrait
19
{
20
    /**
21
     * @return mixed
22
     */
23
    public abstract function getValue();
24
25
    /**
26
     * @return static
27
     */
28 7
    public function absolute()
29
    {
30 7
        return new static(abs($this->getValue()));
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with abs($this->getValue()).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
31
    }
32
33
    /**
34
     * @return static
35
     */
36 5
    public function makeNegative()
37
    {
38 5
        return new static(-$this->absolute()->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with -$this->absolute()->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
    }
40
41
    /**
42
     * @return static
43
     */
44 4
    public function makePositive()
45
    {
46 4
        return new static($this->absolute()->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->absolute()->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
47
    }
48
49
    /**
50
     * @return static
51
     */
52 2
    public function reversePolarity()
53
    {
54 2
        if ($this->isNegative() || $this->isZero()) {
0 ignored issues
show
Bug introduced by
It seems like isNegative() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like isZero() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
55 2
            return new static($this->makePositive()->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->makePositive()->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
56
        } else {
57 2
            return new static($this->makeNegative()->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->makeNegative()->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
58
        }
59
    }
60
61
    /**
62
     * @param  ValueObjectInterface $object
63
     * @return static
64
     */
65 18
    public function add(ValueObjectInterface $object)
66
    {
67 18
        return new static($this->getValue() + $object->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->getValue() + $object->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
    }
69
70
    /**
71
     * @param  ValueObjectInterface $object
72
     * @return static
73
     */
74 1
    public function subtract(ValueObjectInterface $object)
75
    {
76 1
        return new static($this->getValue() - $object->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->getValue() - $object->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
77
    }
78
79
    /**
80
     * @param  ValueObjectInterface $object
81
     * @return static
82
     */
83 18
    public function multiply(ValueObjectInterface $object)
84
    {
85 18
        return new static($this->getValue() * $object->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->getValue() * $object->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
86
    }
87
88
    /**
89
     * @param  ValueObjectInterface $object
90
     * @return static
91
     */
92 1
    public function divide(ValueObjectInterface $object)
93
    {
94 1
        return new static($this->getValue() / $object->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->getValue() / $object->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
95
    }
96
97
    /**
98
     * @param  ValueObjectInterface $object
99
     * @return static
100
     */
101 1
    public function modulus(ValueObjectInterface $object)
102
    {
103 1
        return new static($this->getValue() % $object->getValue());
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with $this->getValue() % $object->getValue().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
104
    }
105
106
    /**
107
     * @param  ValueObjectInterface $object
108
     * @return static
109
     */
110 1
    public function exponentiation(ValueObjectInterface $object)
111
    {
112 1
        return new static(pow($this->getValue(), $object->getValue()));
0 ignored issues
show
Unused Code introduced by
The call to ArithmeticTrait::__construct() has too many arguments starting with pow($this->getValue(), $object->getValue()).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
113
    }
114
}
115