NumericalComparisonsTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 45
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A min() 0 7 1
A max() 0 7 1
A range() 0 4 1
1
<?php
2
3
namespace Almendra\Validators\Traits;
4
5
/**
6
 * Comparisons common to all numeric types.
7
 */
8
trait NumericalComparisonsTrait
9
{
10
    /**
11
     * Sets the minimum limit.
12
     *
13
     * @param numerical $limit The limit
14
     *
15
     * @return $self
0 ignored issues
show
Documentation introduced by
The doc-type $self could not be parsed: Unknown type name "$self" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
16
     */
17
    public function min($limit)
18
    {
19
        $result = $this->compare($limit, '<');
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?

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...
20
        $this->setValid($result);
0 ignored issues
show
Bug introduced by
It seems like setValid() 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...
21
22
        return $this;
23
    }
24
25
    /**
26
     * Sets the maximum limit.
27
     *
28
     * @param numerical $limit The limit
29
     *
30
     * @return $self
0 ignored issues
show
Documentation introduced by
The doc-type $self could not be parsed: Unknown type name "$self" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
31
     */
32
    public function max($limit)
33
    {
34
        $result = $this->compare($limit, '>');
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?

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...
35
        $this->setValid($result);
0 ignored issues
show
Bug introduced by
It seems like setValid() 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...
36
37
        return $this;
38
    }
39
40
    /**
41
     * Sets the limits at once.
42
     *
43
     * @param numerical $left  The bottom limit
44
     * @param numerical $right The upper limit
45
     *
46
     * @return $self
0 ignored issues
show
Documentation introduced by
The doc-type $self could not be parsed: Unknown type name "$self" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
47
     */
48
    public function range($left, $right)
49
    {
50
        return $this->min($left)->max($right);
51
    }
52
}
53