Types::guessType()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Db
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Db;
16
17
use Phossa2\Shared\Base\StaticAbstract;
18
19
/**
20
 * Types
21
 *
22
 * @package Phossa2\Db
23
 * @author  Hong Zhang <[email protected]>
24
 * @see     StaticAbstract
25
 * @version 2.0.0
26
 * @since   2.0.0 added
27
 */
28
class Types extends StaticAbstract
29
{
30
    /**#@+
31
     * Parameter types
32
     *
33
     * @var   int
34
     */
35
36
    /**
37
     * null
38
     */
39
    const PARAM_NULL = \PDO::PARAM_NULL;
40
41
    /**
42
     * integer
43
     */
44
    const PARAM_INT = \PDO::PARAM_INT;
45
46
    /**
47
     * string
48
     */
49
    const PARAM_STR = \PDO::PARAM_STR;
50
51
    /**
52
     * lob
53
     */
54
    const PARAM_LOB = \PDO::PARAM_LOB;
55
56
    /**
57
     * statement
58
     */
59
    const PARAM_STMT = \PDO::PARAM_STMT;
60
61
    /**
62
     * boolean
63
     */
64
    const PARAM_BOOL = \PDO::PARAM_BOOL;
65
66
    /**#@-*/
67
68
    /**
69
     * bind parameters
70
     *
71
     * @param  mixed value
72
     * @param  int $suggestType suggested type
73
     * @return int
74
     * @access public
75
     * @static
76
     */
77
    public static function guessType(
78
        $value,
79
        /*# int */ $suggestType = self::PARAM_STR
80
    )/*# : int */ {
81
        if (is_null($value)) {
82
            return self::PARAM_NULL;
83
        } elseif (is_int($value)) {
84
            return self::PARAM_INT;
85
        } elseif (is_bool($value)) {
86
            return self::PARAM_BOOL;
87
        } else {
88
            return $suggestType;
89
        }
90
    }
91
}
92