PartitionItem::getItem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace drupol\phpartition;
4
5
/**
6
 * Class PartitionItem.
7
 *
8
 * @package drupol\phpartition
9
 */
10
class PartitionItem implements PartitionItemInterface
11
{
12
13
    protected $item;
14
    protected $valueOrCallable;
15
16
  /**
17
   * PartitionItem constructor.
18
   *
19
   * @param mixed $item
20
   *   The item.
21
   * @param float|callable $valueOrCallable
0 ignored issues
show
Documentation introduced by
Should the type for parameter $valueOrCallable not be double|callable|null? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
22
   *   A callable that will get it's value or a value.
23
   */
24 14
    public function __construct($item, $valueOrCallable = null)
25
    {
26 14
        $this->item = $item;
27 14
        $this->valueOrCallable = $valueOrCallable;
28 14
    }
29
30
  /**
31
   * {@inheritdoc}
32
   */
33 11
    public function getValue()
34
    {
35 11
        if (is_callable($this->valueOrCallable)) {
36 3
            return call_user_func($this->valueOrCallable, $this->item);
37
        }
38
39 8
        if (!is_null($this->valueOrCallable)) {
40 3
            return $this->valueOrCallable;
41
        }
42
43 8
        return is_numeric($this->item) ? $this->item : 0;
44
    }
45
46
  /**
47
   * {@inheritdoc}
48
   */
49 14
    public function getItem()
50
    {
51 14
        return $this->item;
52
    }
53
}
54