-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNameValue.php
55 lines (49 loc) · 1.55 KB
/
NameValue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Omnipay\Vindicia;
use InvalidArgumentException;
/**
* Class to represent Vindicia's NameValue objects, which are used to build
* many requests.
*/
class NameValue
{
/**
* @var string
*/
public $name;
/**
* @var string|int|bool|null
*/
public $value;
/**
* Constructs NameValue. Values can be string, ints, bools, or null and will be converted
* to strings, as is required for Vindicia's API.
*
* @param string $name
* @param string|int|bool|float|null $value
* @psalm-suppress FailedTypeResolution Because we're making sure a non-string isn't passed at runtime
*/
public function __construct($name, $value)
{
if (!is_string($name)) {
throw new InvalidArgumentException('Parameter name must be type string, not ' . gettype($name));
}
$this->name = $name;
if ($value === null) {
$this->value = 'null';
} elseif (is_int($value) || is_float($value)) {
$this->value = strval($value);
} elseif (is_bool($value)) {
// this attribute name actually takes a boolean value for some reason
if ($name == 'vin_PaymentMethod_active') {
$this->value = $value;
} else {
$this->value = $value ? 'true' : 'false';
}
} elseif (is_string($value)) {
$this->value = $value;
} else {
throw new InvalidArgumentException('Invalid type ' . gettype($value) . ' for parameter value');
}
}
}