Passed
Push — master ( 8e7179...83cd22 )
by Php Easy Api
02:35
created

UrlVersionIdentifier::getConsoleVersion()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Url;
4
5
use Resta\Support\Utils;
6
7
class UrlVersionIdentifier
8
{
9
    /**
10
     * list supported version numbers
11
     *
12
     * @var array
13
     */
14
    private static $supportedVersions = ['V1'];
15
16
    /**
17
     * get client version
18
     *
19
     * @return null|string
20
     */
21
    public static function clientVersion()
22
    {
23
        if(defined('version')){
24
            return version;
25
        }
26
27
        return null;
28
    }
29
30
    /**
31
     * check path url version
32
     *
33
     * @return bool
34
     */
35
    public static function checkPathUrlVersion()
36
    {
37
        return (file_exists(path()->version())) ? true : false;
38
    }
39
40
    /**
41
     * console version
42
     *
43
     * @return null
44
     */
45
    private static function consoleVersion()
46
    {
47
        return null;
48
    }
49
50
    /**
51
     * get application console version
52
     *
53
     * @return mixed
54
     */
55
    public static function getConsoleVersion()
56
    {
57
        if(Utils::isNamespaceExists(self::versionNamespace()) && method_exists(self::versionNamespace(),'consoleVersion')){
58
            return self::versionNamespace()::consoleVersion();
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::versionNamespace()::consoleVersion() targeting Resta\Url\UrlVersionIdentifier::consoleVersion() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
59
        }
60
61
        return null;
62
    }
63
64
    /**
65
     * @param array $versions
66
     * @return array
67
     */
68
    private static function getSupportedVersions($versions=array())
69
    {
70
        if(count($versions)){
71
            return $versions;
72
        }
73
        return self::$supportedVersions;
74
    }
75
76
    /**
77
     * get supported versions
78
     *
79
     * @param array $versions
80
     * @return mixed
81
     */
82
    public static function supportedVersions($versions=array())
83
    {
84
        return self::versionNamespace()::getSupportedVersions($versions);
85
    }
86
87
    /**
88
     * get version
89
     *
90
     * @return mixed|string|null
91
     */
92
    public static function version()
93
    {
94
        if(self::clientVersion()!==null){
95
            return self::clientVersion();
96
        }
97
98
        if(app()->console() && self::getConsoleVersion()!==null){
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::getConsoleVersion() targeting Resta\Url\UrlVersionIden...er::getConsoleVersion() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
introduced by
The condition self::getConsoleVersion() !== null is always false.
Loading history...
99
            return self::getConsoleVersion();
100
        }
101
102
        return 'V1';
103
    }
104
105
    /**
106
     * get version namespace
107
     *
108
     * @return UrlVersionIdentifier|string
109
     */
110
    public static function versionNamespace()
111
    {
112
        if(file_exists(app()->path()->kernel())){
113
            return app()->namespace()->kernel().'\Version';
114
        }
115
116
        return new static();
117
118
    }
119
}