Skip to content

Commit 25b7415

Browse files
committed
PHPStan : upgrade version to 2.1 for php8.4 compatible + upgrading source code #21
1 parent 3e21c6b commit 25b7415

File tree

4 files changed

+59
-53
lines changed

4 files changed

+59
-53
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require-dev": {
1616
"phpunit/phpunit": "^11.0",
17-
"phpstan/phpstan": "^1.9",
17+
"phpstan/phpstan": "^2.1",
1818
"squizlabs/php_codesniffer": "^3.7"
1919
},
2020
"autoload": {

composer.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Arguments/Argument.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ class Argument
3131
* @throws \RayanLevert\Cli\Arguments\ParseException If the parsed value is not of casted type
3232
*/
3333
set {
34+
$this->hasBeenHandled = true;
35+
3436
if ($this->noValue) {
35-
$this->value = $this->hasBeenHandled = true;
37+
$this->value = true;
3638

3739
return;
3840
} elseif ($this->castTo === 'string') {
39-
$this->value = $value;
40-
$this->hasBeenHandled = true;
41+
$this->value = $value;
4142

4243
return;
4344
}
@@ -49,6 +50,8 @@ class Argument
4950
}
5051

5152
$this->value = intval($value);
53+
54+
return;
5255
} elseif ($this->castTo === 'double') {
5356
if (!is_numeric($value)) {
5457
throw new ParseException(
@@ -57,9 +60,11 @@ class Argument
5760
}
5861

5962
$this->value = floatval($value);
63+
64+
return;
6065
}
6166

62-
$this->hasBeenHandled = true;
67+
$this->value = $value;
6368
}
6469
}
6570

src/ProgressBar.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,28 @@ class ProgressBar
2222
public const string RIGHT = "\e[%dC";
2323
public const string LEFT = "\e[%dD";
2424

25-
/** Number of required iterations to add a character */
26-
public int $numberOfEachIterations {
27-
get => intval(ceil($this->max / $this->numberOfSymbols));
25+
public int $max {
26+
set {
27+
if ($value <= 0) {
28+
throw new UnexpectedValueException('The max value must be positive');
29+
}
30+
31+
$this->max = $value;
32+
}
33+
get => $this->max;
34+
}
35+
36+
public int $numberOfSymbols {
37+
set {
38+
if ($value <= 0) {
39+
throw new UnexpectedValueException('The number of symbols must be positive');
40+
}
41+
42+
$this->numberOfSymbols = $value;
43+
}
44+
get {
45+
return $this->max <= $this->numberOfSymbols ? $this->max : $this->numberOfSymbols;
46+
}
2847
}
2948

3049
/** Current iteration */
@@ -84,29 +103,11 @@ public static function getFormattedTime(float $time): string
84103
*
85104
* @throws UnexpectedValueException If `$max` or `$numberOfSymbols` are negative values
86105
*/
87-
public function __construct(
88-
public int $max {
89-
set {
90-
if ($value <= 0) {
91-
throw new UnexpectedValueException('The max value must be positive');
92-
}
93-
94-
$this->max = $value;
95-
}
96-
},
97-
public int $numberOfSymbols = 50 {
98-
set {
99-
if ($value <= 0) {
100-
throw new UnexpectedValueException('The number of symbols must be positive');
101-
}
102-
103-
$this->numberOfSymbols = $value;
104-
}
105-
get {
106-
return $this->max <= $this->numberOfSymbols ? $this->max : $this->numberOfSymbols;
107-
}
108-
}
109-
) {}
106+
public function __construct(int $max, int $numberOfSymbols = 50)
107+
{
108+
$this->max = $max;
109+
$this->numberOfSymbols = $numberOfSymbols;
110+
}
110111

111112
/**
112113
* Starts the progress bar (or restarts it, if not breaks two lines)
@@ -168,7 +169,7 @@ public function advance(int $toAdvance = 1): void
168169
} elseif ($this->max === $this->numberOfSymbols) {
169170
print str_repeat('#', $this->iteration) . str_repeat(' ', $this->max - $this->iteration);
170171
} else {
171-
$actualDiezes = intval(floor($this->iteration / $this->numberOfEachIterations));
172+
$actualDiezes = intval(floor($this->iteration / intval(ceil($this->max / $this->numberOfSymbols))));
172173

173174
print str_repeat('#', $actualDiezes) . str_repeat(' ', ($this->numberOfSymbols - $actualDiezes));
174175
}

0 commit comments

Comments
 (0)