MongoInt32::toBSONType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
if (class_exists('MongoInt32', false)) {
17
    return;
18
}
19
20
use Alcaeus\MongoDbAdapter\TypeInterface;
21
22
class MongoInt32 implements TypeInterface
23
{
24
    /**
25
     * @link http://php.net/manual/en/class.mongoint32.php#mongoint32.props.value
26
     * @var string
27
     */
28
    public $value;
29
30
    /**
31
     * Creates a new 32-bit number with the given value.
32
     *
33
     * @link http://php.net/manual/en/mongoint32.construct.php
34
     * @param string $value A number
35
     */
36
    public function __construct($value)
37
    {
38
        $this->value = (string) $value;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function __toString()
45
    {
46
        return (string) $this->value;
47
    }
48
49
    /**
50
     * Converts this MongoInt32 to a native integer
51
     *
52
     * @return int
53
     * @internal This method is not part of the ext-mongo API
54
     */
55
    public function toBSONType()
56
    {
57
        return (int) $this->value;
58
    }
59
}
60