Completed
Push — master ( 867576...44cf56 )
by Sander
15:38
created

SymfonyVersion   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRootWebPath() 0 4 2
A isKernelLessThan() 0 4 1
A kernelVersionCompare() 0 4 3
1
<?php
2
3
namespace Kunstmaan\MediaBundle\Utils;
4
5
use Symfony\Component\HttpKernel\Kernel;
6
7
/**
8
 * @internal
9
 */
10
class SymfonyVersion
11
{
12
    /**
13
     * @return string
14
     */
15
    public static function getRootWebPath()
16
    {
17
        return sprintf('%%kernel.project_dir%%/%s', self::isKernelLessThan(4) ? 'web' : 'public');
18
    }
19
20
    /**
21
     * @return bool
22
     */
23
    public static function isKernelLessThan($major, $minor = null, $patch = null)
24
    {
25
        return static::kernelVersionCompare('<', $major, $minor, $patch);
0 ignored issues
show
Bug introduced by
Since kernelVersionCompare() 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 kernelVersionCompare() 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...
26
    }
27
28
    /**
29
     * @return bool
30
     */
31
    private static function kernelVersionCompare($operator, $major, $minor = null, $patch = null)
32
    {
33
        return version_compare(Kernel::VERSION_ID, sprintf("%d%'.02d%'.02d", $major, $minor ?: 0, $patch ?: 0), $operator);
34
    }
35
}
36