Completed
Push — 2.0 ( 6cd6ae...d9081a )
by Rob
11s
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 bool
20
     */
21
    public static function hasDirectContainerBuilderLogging()
22
    {
23
        return method_exists('\Symfony\Component\DependencyInjection\ContainerBuilder', 'log');
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($major, $minor = null, $patch = null)
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($major, $minor = null, $patch = null)
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($operator, $major, $minor = null, $patch = null)
59
    {
60
        $vernum = $major;
61
        $kernel = Kernel::MAJOR_VERSION;
62
63
        if ($minor) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $minor of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
64
            $vernum .= '.'.$minor;
65
            $kernel .= '.'.Kernel::MINOR_VERSION;
66
67
            if ($patch) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $patch of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
68
                $vernum .= '.'.$patch;
69
                $kernel .= '.'.Kernel::RELEASE_VERSION;
70
            }
71
        }
72
73
        return version_compare($kernel, $vernum, $operator);
74
    }
75
}
76