spl_object_id.php ➔ spl_object_id()   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 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * PHP Polyfill for spl_object_id() for PHP <= 7.1
5
 * This file will be included even in releases which will analyze PHP 7.2,
6
 * there aren't any major compatibilities preventing analysis of PHP 7.2 from running in PHP 7.1.
7
 */
8
if (!function_exists('spl_object_id')) {
9
    if (function_exists('runkit_object_id') &&
10
        !(new ReflectionFunction('runkit_object_id'))->isUserDefined()) {
11
        /**
12
         * See https://github.com/runkit7/runkit_object_id for a faster native version for php <= 7.1
13
         *
14
         * @param object $object
15
         * @return int The object id
16
         */
17
        function spl_object_id($object) : int
18
        {
19
            return runkit_object_id($object);
20
        }
21
    } elseif (PHP_INT_SIZE === 8) {
22
        /**
23
         * See https://github.com/runkit7/runkit_object_id for a faster native version for php <= 7.1
24
         *
25
         * @param object $object
26
         * @return int (The object id, XORed with a random number)
27
         */
28
        function spl_object_id($object) : int
0 ignored issues
show
Best Practice introduced by
The function spl_object_id() has been defined more than once; this definition is ignored, only the first definition in this file (L17-20) is considered.

This check looks for functions that have already been defined in the same file.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
29
        {
30
            $hash = spl_object_hash($object);
31
            // Fit this into a php long (32-bit or 64-bit signed int).
32
            // The first 16 hex digits (64 bytes) vary, the last 16 don't.
33
            // Values are usually padded with 0s at the front.
34
            return intval(substr($hash, 1, 15), 16);
35
        }
36
    } else {
37
        /**
38
         * See https://github.com/runkit7/runkit_object_id for a faster native version for php <= 7.1
39
         *
40
         * @param object $object
41
         * @return int (The object id, XORed with a random number)
42
         */
43
        function spl_object_id($object) : int
0 ignored issues
show
Best Practice introduced by
The function spl_object_id() has been defined more than once; this definition is ignored, only the first definition in this file (L17-20) is considered.

This check looks for functions that have already been defined in the same file.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
44
        {
45
            $hash = spl_object_hash($object);
46
            // Fit this into a php long (32-bit or 64-bit signed int).
47
            // The first 16 hex digits (64 bytes) vary, the last 16 don't.
48
            // Values are usually padded with 0s at the front.
49
            return intval(substr($hash, 9, 7), 16);
50
        }
51
    }
52
}
53