Completed
Branch master (19b0aa)
by Nate
07:03 queued 04:40
created

QueryManipulator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boolToString() 0 14 4
B varToString() 0 16 5
1
<?php
2
/*
3
 * Copyright (c) 2015 Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Retrofit\Generation\Manipulator;
8
9
/**
10
 * Class QueryManipulator
11
 *
12
 * @author Nate Brunette <[email protected]>
13
 */
14
class QueryManipulator
15
{
16
    /**
17
     * Convert booleans to string so that they're not passed as 0 and 1
18
     *
19
     * @param array $elements
20
     * @return array
21
     */
22
    public static function boolToString(array $elements)
23
    {
24
        foreach ($elements as $key => $element) {
25
            if (is_array($element)) {
26
                $elements[$key] = self::boolToString($element);
27
            }
28
29
            if (is_bool($element)) {
30
                $elements[$key] = self::varToString($element);
31
            }
32
        }
33
34
        return $elements;
35
    }
36
37
    /**
38
     * Convert a value to its string representation
39
     *
40
     * @param mixed $variable
41
     * @return string
42
     */
43
    public static function varToString($variable)
44
    {
45
        if (null === $variable) {
46
            return 'null';
47
        }
48
49
        if (is_bool($variable)) {
50
            return (true === $variable) ? 'true' : 'false';
51
        }
52
53
        if (is_array($variable)) {
54
            return '[]';
55
        }
56
57
        return (string) $variable;
58
    }
59
}
60