Passed
Push — master ( 99ef14...e2607e )
by Sébastien
27:25 queued 11s
created

WeakReference::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
if (!class_exists(WeakReference::class)) {
4
    /**
5
     * Pseudo polyfill for get the WeakReference API on PHP < 7.4
6
     *
7
     * https://www.php.net/manual/en/class.weakreference.php
8
     *
9
     * @template T as object
10
     */
11
    class WeakReference
12
    {
13
        /**
14
         * @var T
15
         */
16
        private $obj;
17
18
        /**
19
         * WeakReference constructor.
20
         *
21
         * @param T $obj
22
         */
23
        private function __construct($obj)
24
        {
25
            $this->obj = $obj;
26
        }
27
28
        /**
29
         * Get a weakly referenced Object
30
         *
31
         * @return T|null
32
         */
33
        public function get()
34
        {
35
            return $this->obj;
0 ignored issues
show
Bug Best Practice introduced by
The property obj does not exist on WeakReference. Did you maybe forget to declare it?
Loading history...
36
        }
37
38
        /**
39
         * Create a new weak reference
40
         *
41
         * @param T $obj
42
         *
43
         * @return WeakReference
44
         */
45
        public static function create($obj): WeakReference
46
        {
47
            return new self($obj);
0 ignored issues
show
Unused Code introduced by
The call to WeakReference::__construct() has too many arguments starting with $obj. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            return /** @scrutinizer ignore-call */ new self($obj);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
48
        }
49
    }
50
}
51