Passed
Push — master ( a9840c...5ab0c2 )
by Todd
03:34
created

Pair   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 28
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B getScalar() 0 11 6
A getKey() 0 2 1
A __construct() 0 3 1
A getValue() 0 2 1
1
<?php
2
3
namespace Logikos\Util;
4
5
class Pair {
6
  private $key;
7
  private $value;
8
9 8
  public function __construct($key, $value) {
10 8
    $this->key = $this->getScalar($key);
11 6
    $this->value = $value;
12 6
  }
13
14 4
  public function getKey() {
15 4
    return $this->key;
16
  }
17
18 2
  public function getValue() {
19 2
    return $this->value;
20
  }
21
22 8
  private function getScalar($key) {
23 8
    if (is_null($key))
24 1
      throw new InvalidTypeException('Can not use null for a key');
25
26 7
    if (is_object($key) && !method_exists($key, '__toString'))
27 1
      throw new InvalidTypeException('Object keys must implement __toString');
28
29 6
    if (is_numeric($key) || is_string($key))
30 5
      return $key;
31
32 1
    return (string) $key;
33
  }
34
}