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.

ProgressBar   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A getInstance() 0 9 2
A setMaxByte() 0 6 1
A setProgress() 0 7 1
A getProgress() 0 4 1
A calcule() 0 8 2
A finish() 0 9 3
A render() 0 17 4
A clear() 0 7 1
1
<?php
2
3
namespace Classes\Update;
4
5
class ProgressBar
6
{
7
8
    private static $finished = 0;
9
    private static $progressBar;
10
11
    private $max = 0;
12
13
    private $progress = 0;
14
15
    private $progresslength = 0;
16
17
    private function __construct (){ }
18
19
    /**
20
     * @return \Classes\Update\ProgressBar
21
     */
22
    public static function getInstance ()
23
    {
24
        if ( is_null ( self::$progressBar ) )
25
        {
26
            self::$progressBar = new ProgressBar();
27
        }
28
29
        return self::$progressBar;
30
    }
31
32
    public function setMaxByte ( $bytesMax )
33
    {
34
        $this->max = $bytesMax;
35
36
        return $this;
37
    }
38
39
    public function setProgress ( $progress )
40
    {
41
        $this->progress = $progress;
42
        $this->calcule ();
43
44
        return $this;
45
    }
46
47
    public function getProgress ()
48
    {
49
        return $this->progresslength;
50
    }
51
52
    public function calcule ()
53
    {
54
        if ( $this->progress > 0 )
55
        {
56
            $this->progresslength = round( $this->progress * 100 / $this->max );
0 ignored issues
show
Documentation Bug introduced by
The property $progresslength was declared of type integer, but round($this->progress * 100 / $this->max) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
57
            //$this->progresslength = (int) ( ( $this->progress / $this->max ) * 100 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
        }
59
    }
60
61
    public function finish ()
62
    {
63
        if ( $this->getProgress () >= 99 && !self::$finished)
64
        {
65
            echo "\n\033[1;32mDone!\033[0m\n";
66
            self::$finished = 1;
67
        }
68
69
    }
70
71
    public function render ()
72
    {
73
        if ( $this->progress > 0 && !self::$finished)
74
        {
75
            if ( ! isset( $this->max ) )
76
            {
77
                printf ( "\rUnknown filesize.. %2d kb done.." , $this->progress / 1024 );
78
            } else
79
            {
80
                $length = $this->getProgress ();
81
                printf ( "\r[%-100s] %d%%" , str_repeat ( "=" , $length )
82
                                             . ">" , $length );
83
            }
84
        }
85
86
        return $this;
87
    }
88
89
    public function clear ()
90
    {
91
        $this->max = 0;
92
        $this->progress = 0;
93
94
        return $this;
95
    }
96
}