Completed
Pull Request — master (#17)
by Andreas
15:20 queued 06:48
created

MongoCode::toBSONType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
class MongoCode implements \Alcaeus\MongoDbAdapter\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...
17
{
18
    /**
19
     * @var string
20
     */
21
    private $code;
22
23
    /**
24
     * @var array
25
     */
26
    private $scope;
27
28
    /**
29
     * @link http://php.net/manual/en/mongocode.construct.php
30
     * @param string $code A string of code
31
     * @param array $scope The scope to use for the code
32
     */
33
    public function __construct($code, array $scope = [])
34
    {
35
        if ($code instanceof \MongoDB\BSON\Javascript) {
1 ignored issue
show
Bug introduced by
The class MongoDB\BSON\Javascript 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...
36
            // @todo Use properties from object once they are accessible
37
            $code = '';
38
        }
39
40
        $this->code = $code;
41
        $this->scope = $scope;
42
    }
43
44
    /**
45
     * Returns this code as a string
46
     * @return string
47
     */
48
    public function __toString()
49
    {
50
        return $this->code;
51
    }
52
53
    /**
54
     * Converts this MongoCode to the new BSON JavaScript type
55
     *
56
     * @return \MongoDB\BSON\Javascript
57
     * @internal This method is not part of the ext-mongo API
58
     */
59
    public function toBSONType()
60
    {
61
        return new \MongoDB\BSON\Javascript($this->code, $this->scope);
62
    }
63
}
64