ValidooException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Validoo;
4
5
class ValidooException extends \Exception
6
{
7
8
    const NO_ERROR_TEXT = 1;
9
    const STATIC_METHOD = 2;
10
    const UNKNOWN_RULE = 3;
11
    const ARRAY_EXPECTED = 4;
12
13
    private static $error_messages;
14
15
    public function __construct($code, $param)
16
    {
17
        static::$error_messages = [
0 ignored issues
show
Bug introduced by
Since $error_messages is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $error_messages 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...
18
            static::NO_ERROR_TEXT => "Error text could not found for ':param', or Error file could not found",
19
            static::STATIC_METHOD => "The method :param should be static",
20
            static::UNKNOWN_RULE => "Unknown Rule: :param",
21
            static::ARRAY_EXPECTED => "Rules are expected to Array. Input Name: :param"
22
        ];
23
        parent::__construct(str_replace(":param", $param, static::$error_messages[$code]), $code);
0 ignored issues
show
Bug introduced by
Since $error_messages is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $error_messages 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...
24
    }
25
26
}
27