Option   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A find() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of Laravel Meetups.
5
 *
6
 * (c) Nuno Maduro <[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 LaravelMeetups\Providers\Catalog;
13
14
use LaravelMeetups\Contracts\Providers\Provider as Contract;
15
use PHPHtmlParser\Dom;
16
17
/**
18
 * Class Option.
19
 */
20
class Option implements Contract
21
{
22
    /**
23
     * Holds the current option number.
24
     *
25
     * @var int
26
     */
27
    private static $number = 1;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getName()
33
    {
34
        return '#';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function find(Dom $dom)
41
    {
42
        return '[<info>'.static::$number++.'</info>]';
0 ignored issues
show
Bug introduced by
Since $number is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $number to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
43
    }
44
}
45