Completed
Push — 2.0 ( 1bc459...d65881 )
by Rob
10s
created

hasDirectContainerBuilderLogging()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Utility\Framework;
13
14
use Symfony\Component\HttpKernel\Kernel;
15
16
class SymfonyFramework
17
{
18
    /**
19
     * @return string
20
     */
21
    public static function getContainerResolvableRootWebPath(): string
22
    {
23
        return sprintf('%%kernel.project_dir%%/%s', self::isKernelLessThan(4) ? 'web' : 'public');
24
    }
25
26
    /**
27
     * @param int      $major
28
     * @param int|null $minor
29
     * @param int|null $patch
30
     *
31
     * @return bool
32
     */
33
    public static function isKernelGreaterThanOrEqualTo(int $major, int $minor = null, int $patch = null): bool
34
    {
35
        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...
36
    }
37
38
    /**
39
     * @param int      $major
40
     * @param int|null $minor
41
     * @param int|null $patch
42
     *
43
     * @return bool
44
     */
45
    public static function isKernelLessThan(int $major, int $minor = null, int $patch = null): bool
46
    {
47
        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...
48
    }
49
50
    /**
51
     * @param string   $operator
52
     * @param int      $major
53
     * @param int|null $minor
54
     * @param int|null $patch
55
     *
56
     * @return bool
57
     */
58
    private static function kernelVersionCompare(string $operator, int $major, int $minor = null, int $patch = null): bool
59
    {
60
        return version_compare(Kernel::VERSION_ID, sprintf("%d%'.02d%'.02d", $major, $minor ?: 0, $patch ?: 0), $operator);
61
    }
62
}
63