GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d5de79...8929ee )
by De
06:12 queued 02:29
created

TypeChecker::isRegex()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of the PHPMongo package.
5
 *
6
 * (c) Dmytro Sokil <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sokil\Mongo\Type;
13
use Sokil\Mongo\Expression;
14
15
/**
16
 * Internal helper class to check if value has some type
17
 */
18
class TypeChecker
19
{
20
    /**
21
     * Check if value belongs to internal Mongo type, converted by driver to scalars
22
     *
23
     * @param mixed $value
24
     * @return bool
25
     */
26
    public static function isInternalType($value)
27
    {
28
        if (!is_object($value)) {
29
            return false;
30
        }
31
32
        if (class_exists('\MongoDB\BSON\Type')) {
33
            // mongodb extension for PHP 7
34
            return $value instanceof \MongoDB\BSON\Type;
0 ignored issues
show
Bug introduced by
The class MongoDB\BSON\Type 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...
35
        } else {
36
            // legacy mongo extension for PHP 5
37
            $mongoTypes = array(
38
                'MongoId',
39
                'MongoCode',
40
                'MongoDate',
41
                'MongoRegex',
42
                'MongoBinData',
43
                'MongoInt32',
44
                'MongoInt64',
45
                'MongoDBRef',
46
                'MongoMinKey',
47
                'MongoMaxKey',
48
                'MongoTimestamp'
49
            );
50
51
            return in_array(
52
                get_class($value),
53
                $mongoTypes
54
            );
55
        }
56
    }
57
58
    /**
59
     * @param mixed $value
60
     * @return bool
61
     */
62
    public static function isRegex($value)
63
    {
64
        if (!is_object($value)) {
65
            return false;
66
        }
67
68
        if (class_exists('\MongoDB\BSON\Regex')) {
69
            return $value instanceof \MongoDB\BSON\Regex;
0 ignored issues
show
Bug introduced by
The class MongoDB\BSON\Regex 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...
70
        } else {
71
            return get_class($value) === 'MongoRegex';
72
        }
73
74
    }
75
76
    /**
77
     * @param mixed $value
78
     * @return bool
79
     */
80
    public static function isExpression($value)
81
    {
82
        return ($value instanceof Expression) || self::isHashMap($value);
83
    }
84
85
    /**
86
     * Check if php array is hash map
87
     *
88
     * @param mixed $value
89
     *
90
     * @return bool
91
     */
92
    public static function isHashMap($value)
93
    {
94
        return is_array($value) && is_string(key($value));
95
    }
96
}
97