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.

Update   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 87
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A update() 0 17 4
B downloadVersion() 0 21 5
A modifyTempName() 0 17 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Created by PhpStorm.
4
 * User: pedro
5
 * Date: 29/11/16
6
 * Time: 14:11
7
 */
8
9
namespace Classes;
10
11
12
use Classes\Update\Content\GitHub;
13
use Classes\Update\Version;
14
15
require_once 'Update/Content/GitHub.php';
16
require_once 'Update/ProgressBar.php';
17
18
class Update
19
{
20
21
    private static $fileName  = "orm-generator";
22
    private static $separador = "-";
23
    private static $extencion = ".phar";
24
    private        $versionUpdate;
25
    private        $tempFileName;
26
    /**
27
     * @type GitHub
28
     */
29
    private $objGitHub;
30
31
    public function __construct ( $version = null )
32
    {
33
        $this->objGitHub = GitHub::getInstance ();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Classes\Update\Content\GitHub::getInstance() can also be of type object<Classes\Update\Content\Content>. However, the property $objGitHub is declared as type object<Classes\Update\Content\GitHub>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
34
        if ( is_null ( $version ) )
35
        {
36
            $version = $this->objGitHub->getLastVersion ();
37
        }
38
39
        $this->versionUpdate = $version;
40
        $this->tempFileName = self::$fileName
41
                              . self::$separador
42
                              . $this->versionUpdate
43
                              . self::$extencion;
44
45
    }
46
47
    public function update ()
48
    {
49
        if ( Version::HasNewVersion () && ! Version::equalVersion ( $this->versionUpdate )
50
        )
51
        {
52
            $content = $this->objGitHub->getContent ( $this->objGitHub->getLastPhar () , true );
53
            if ( $content )
54
            {
55
                $this->objGitHub->putContent ( $this->tempFileName , $content );
56
            }
57
        } else
58
        {
59
            throw new \Exception ( "\033[0;31mError: Esta versão é a atual\033[0m\n" );
60
        }
61
62
        return $this;
63
    }
64
65
    public function downloadVersion ( $version )
66
    {
67
        if ( Version::existVersion ( $version ) && ! Version::equalVersion ( $version ) )
68
        {
69
            $content = $this->objGitHub->getContent ( $this->objGitHub->getPharByVersion ( $version ) , true );
70
71
            if ( $content )
72
            {
73
                $this->objGitHub->putContent ( $this->tempFileName , $content );
74
            }
75
        } else
76
        {
77
            if ( ! Version::existVersion ( $version ) )
78
            {
79
                throw new \Exception ( "\033[0;31mError: Esta versão não existe\033[0m\n" );
80
            }
81
            throw new \Exception ( "\033[0;31mError: Esta versão é a atual\033[0m\n" );
82
        }
83
84
        return $this;
85
    }
86
87
    public function modifyTempName ()
88
    {
89
        if ( file_exists ( realpath ( $this->tempFileName ) ) )
90
        {
91
            $fileName = realpath ( self::$fileName . self::$extencion );
92
            if ( file_exists ( $fileName ) )
93
            {
94
                unlink ( $fileName );
95
            }
96
97
            chmod ( $this->tempFileName , 0777 );
98
            rename ( $this->tempFileName , self::$fileName . self::$extencion );
99
100
        }
101
102
        return $this;
103
    }
104
}