GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ProtocolFileContent   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 0
dl 0
loc 84
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getInstance() 0 9 2
A hasProtocol() 0 4 1
A getProtocol() 0 4 1
A parseContentProtocol() 0 13 4
B hasEnabled() 0 17 7
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: pedro
5
 * Date: 24/11/16
6
 * Time: 17:19
7
 */
8
9
namespace Classes\Update;
10
11
12
class ProtocolFileContent
13
{
14
    /**
15
     * @type string
16
     */
17
    protected $protocol;
18
    /**
19
     * @type Content
20
     */
21
    private static $objProtocol;
22
23
    private function __construct ()
24
    {
25
        $this->parseContentProtocol ();
26
    }
27
28
    /**
29
     * @return \Classes\Update\ProtocolFileContent
30
     */
31
    public static function getInstance ()
32
    {
33
        if ( empty( self::$objProtocol ) )
34
        {
35
            self::$objProtocol = new ProtocolFileContent();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Classes\Update\ProtocolFileContent() of type object<Classes\Update\ProtocolFileContent> is incompatible with the declared type object<Classes\Update\Content> of property $objProtocol.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
        }
37
38
        return self::$objProtocol;
0 ignored issues
show
Bug Compatibility introduced by
The expression self::$objProtocol; of type Classes\Update\ProtocolF...|Classes\Update\Content adds the type Classes\Update\Content to the return on line 38 which is incompatible with the return type documented by Classes\Update\ProtocolFileContent::getInstance of type Classes\Update\ProtocolFileContent.
Loading history...
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function hasProtocol ()
45
    {
46
        return ! empty( $this->protocol );
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getProtocol ()
53
    {
54
        return $this->protocol;
55
    }
56
57
    /**
58
     *
59
     */
60
    private function parseContentProtocol ()
61
    {
62
        if ( $this->hasEnabled ( 'file_content' ) )
63
        {
64
            $this->protocol = 'file_content';
65
        } elseif ( $this->hasEnabled ( 'steam_content' ) )
66
        {
67
            $this->protocol = 'steam_content';
68
        } elseif ( $this->hasEnabled ( 'curl' ) )
69
        {
70
            $this->protocol = 'curl';
71
        }
72
    }
73
74
    /**
75
     * @return bool
76
     */
77
    private function hasEnabled ( $type )
78
    {
79
        switch ( $type )
80
        {
81
            case 'curl':
82
                return function_exists ( 'fopen' ) && function_exists ( 'curl_exec' );
83
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
84
            case 'file_content':
85
                return function_exists ( 'file_get_contents' ) && function_exists ( 'stream_get_contents' );
86
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
87
            case 'steam_content':
88
                return function_exists ( 'fopen' ) && function_exists ( 'stream_get_contents' );
89
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
90
        }
91
92
        throw new \Exception("\033[0;31mError: enable in php.ini 'file_get_contents' and  'stream_get_contents' or  'fopen' and 'curl'. \033[0m\n");
93
    }
94
95
}