Completed
Push — master ( f42a76...e2cf37 )
by Andreas
05:39
created

MongoBinData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 98
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A __toString() 0 4 1
A toBSONType() 0 4 1
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
use Alcaeus\MongoDbAdapter\TypeInterface;
17
use MongoDB\BSON\Binary;
18
use MongoDB\BSON\Type;
19
20
class MongoBinData implements TypeInterface
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
21
{
22
    /**
23
     * Generic binary data.
24
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.custom
25
     */
26
    const GENERIC = 0x0;
27
28
    /**
29
     * Function
30
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.func
31
     */
32
    const FUNC = 0x1;
33
34
    /**
35
     * Generic binary data (deprecated in favor of MongoBinData::GENERIC)
36
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.byte-array
37
     */
38
    const BYTE_ARRAY = 0x2;
39
40
    /**
41
     * Universally unique identifier (deprecated in favor of MongoBinData::UUID_RFC4122)
42
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.uuid
43
     */
44
    const UUID = 0x3;
45
46
    /**
47
     * Universally unique identifier (according to » RFC 4122)
48
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.custom
49
     */
50
    const UUID_RFC4122 = 0x4;
51
52
53
    /**
54
     * MD5
55
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.md5
56
     */
57
    const MD5 = 0x5;
58
59
    /**
60
     * User-defined type
61
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.constants.custom
62
     */
63
    const CUSTOM = 0x80;
64
65
66
    /**
67
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.props.bin
68
     * @var $bin
69
     */
70
    public $bin;
71
72
    /**
73
     * @link http://php.net/manual/en/class.mongobindata.php#mongobindata.props.type
74
     * @var $type
75
     */
76
    public $type;
77
78
    /**
79
     * Creates a new binary data object.
80
     *
81
     * @link http://php.net/manual/en/mongobindata.construct.php
82
     * @param string $data Binary data
83
     * @param int $type Data type
84
     * @return MongoBinData Returns a new binary data object
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
85
     */
86
    public function __construct($data, $type = 2)
87
    {
88
        if ($data instanceof Binary) {
1 ignored issue
show
Bug introduced by
The class MongoDB\BSON\Binary does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
89
            $this->bin = $data->getData();
90
            $this->type = $data->getType();
91
        } else {
92
            $this->bin = $data;
93
            $this->type = $type;
94
        }
95
    }
96
97
    /**
98
     * Returns the string "<Mongo Binary Data>". To access the contents of a MongoBinData, use the bin field.
99
     *
100
     * @return string
101
     */
102
    public function __toString()
103
    {
104
        return '<Mongo Binary Data>';
105
    }
106
107
    /**
108
     * Converts this MongoBinData to the new BSON Binary type
109
     *
110
     * @return Binary
111
     * @internal This method is not part of the ext-mongo API
112
     */
113
    public function toBSONType()
114
    {
115
        return new Binary($this->bin, $this->type);
116
    }
117
}
118