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

Pair::getScalar()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 7
nc 4
nop 1
crap 6
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
}