Completed
Push — master ( 7960a5...1c5373 )
by Ross
04:38 queued 35s
created

UnknownMiddlewareException::completeHelpMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace League\Tactician\Bundle\DependencyInjection\Compiler;
4
5
class UnknownMiddlewareException extends \RuntimeException
6
{
7
    public static function withId($serviceId)
8
    {
9
        return new static(
10
            trim(sprintf('Unknown middleware with service id "%s". %s', $serviceId, static::completeHelpMessage($serviceId)))
0 ignored issues
show
Bug introduced by
Since completeHelpMessage() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of completeHelpMessage() to at least protected.

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

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

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 {
      private static function getTemperature() {
        return "-182 °C";
    }
}

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

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

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
11
        );
12
    }
13
14
    private static function completeHelpMessage($serviceId)
15
    {
16
        $helpMessages = [
17
            ValidatorMiddlewarePass::SERVICE_ID => 'You should have the symfony validator service enabled to use this middleware.',
18
            SecurityMiddlewarePass::SERVICE_ID => 'You should have the symfony security service enabled to use this middleware.',
19
        ];
20
21
        if (array_key_exists($serviceId, $helpMessages)) {
22
            return $helpMessages[$serviceId];
23
        }
24
    }
25
}
26