Completed
Push — master ( b0612a...e62e65 )
by Pol
06:37
created

PartitionItem::getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
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
  protected $item;
13
  protected $valueCallable;
14
15
  /**
16
   * PartitionItem constructor.
17
   *
18
   * @param mixed $item
19
   *   The item.
20
   * @param callable $valueCallable
0 ignored issues
show
Documentation introduced by
Should the type for parameter $valueCallable not be null|callable? 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...
21
   *   The callable that will get it's value.
22
   */
23 10
  public function __construct($item, callable $valueCallable = NULL) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
24 10
    $this->item = $item;
25 10
    $this->valueCallable = $valueCallable;
26 10
  }
27
28
  /**
29
   * {@inheritdoc}
30
   */
31 8
  public function getValue() {
32 8
    if (!is_null($this->valueCallable)) {
33 3
      return call_user_func($this->valueCallable, $this->item);
34
    }
35
36 5
    return $this->item;
37
  }
38
39
  /**
40
   * {@inheritdoc}
41
   */
42 10
  public function getItem() {
43 10
    return $this->item;
44
  }
45
46
}
47