Skip to content

Commit 80c4b7f

Browse files
committed
codacy suggestions
1 parent f5dbbce commit 80c4b7f

File tree

7 files changed

+57
-60
lines changed

7 files changed

+57
-60
lines changed

.github/pull_request_template.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Hello!
22

33
* Type: bug fix | new feature | code quality | documentation
4-
* Link to issue:
4+
* Link to issue:
55

66
**In raising this pull request, I confirm the following:**
77

8-
- [ ] I have read and understood the [Contributing Guidelines](https://github.com/phalcon/cli-options-parser/blob/master/CONTRIBUTING.md)
9-
- [ ] I have checked that another pull request for this purpose does not exist
10-
- [ ] I wrote some tests for this PR
11-
- [ ] I have updated the relevant CHANGELOG
8+
- [ ] I have read and understood the [Contributing Guidelines](https://github.com/phalcon/cli-options-parser/blob/master/CONTRIBUTING.md)
9+
- [ ] I have checked that another pull request for this purpose does not exist
10+
- [ ] I wrote some tests for this PR
11+
- [ ] I have updated the relevant CHANGELOG
1212

1313
Small description of change:
1414

CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ information you seek. If your question remains unanswered, explore the
3131
additional options provided below._
3232

3333
* Questions should go to [GitHub Discussions](https://phalcon.io/discussions)
34-
* Another way is to ask a question on [Stack Overflow](https://stackoverflow.com/) and tag it with
35-
[`phalcon`](https://stackoverflow.com/questions/tagged/phalcon)
34+
* Another way is to ask a question on [Stack Overflow](https://stackoverflow.com/) and tag it with [`phalcon`](https://stackoverflow.com/questions/tagged/phalcon)
3635
* Come join the Phalcon [Discord](https://phalcon.io/discord)
3736
* Our social network accounts are:
3837
* [Telegram](https://phalcon.io/telegram)

docker/8.0/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:latest as composer
1+
FROM composer:2 as composer
22
FROM php:8.0-fpm
33

44
COPY ./extra.ini /usr/local/etc/php/conf.d/

docker/8.1/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:latest as composer
1+
FROM composer:2 as composer
22
FROM php:8.1-fpm
33

44
COPY ./extra.ini /usr/local/etc/php/conf.d/

docker/8.2/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM composer:latest as composer
1+
FROM composer:2 as composer
22
FROM php:8.2-fpm
33

44
COPY ./extra.ini /usr/local/etc/php/conf.d/

src/Parser.php

+13-29
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ public function getBoolean(string $key, bool $default = false): bool
6161
return (bool)$this->parsedCommands[$key];
6262
}
6363

64-
return $this->getCoalescingDefault(
65-
$this->parsedCommands[$key],
66-
$default
67-
);
64+
return match ($this->parsedCommands[$key]) {
65+
'y',
66+
'yes',
67+
'true',
68+
'1',
69+
'on' => true,
70+
'n',
71+
'no',
72+
'false',
73+
'0',
74+
'off' => false,
75+
default => $default,
76+
};
6877
}
6978

7079
/**
@@ -117,31 +126,6 @@ protected function getArgvFromServer(): array
117126
return empty($_SERVER['argv']) ? [] : $_SERVER['argv'];
118127
}
119128

120-
/**
121-
* Return either received parameter or default
122-
*
123-
* @param string $value The parameter passed
124-
* @param bool $default A default value if the parameter is not set
125-
*
126-
* @return bool
127-
*/
128-
protected function getCoalescingDefault(string $value, bool $default): bool
129-
{
130-
return match ($value) {
131-
'y',
132-
'yes',
133-
'true',
134-
'1',
135-
'on' => true,
136-
'n',
137-
'no',
138-
'false',
139-
'0',
140-
'off' => false,
141-
default => $default,
142-
};
143-
}
144-
145129
/**
146130
* @param string $arg The argument passed
147131
* @param int $eqPos The position of where the equals sign is located

tests/ParserTest.php

+35-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class ParserTest extends TestCase
2626
{
2727
/** @var Parser */
28-
protected $parser;
28+
protected Parser $parser;
2929

3030
/**
3131
* {@inheritdoc}
@@ -43,14 +43,20 @@ public function setUp(): void
4343
*
4444
* @param array $params
4545
* @param array $expected
46+
*
47+
* @return void
4648
*/
4749
public function shouldParseCliCommand(array $params, array $expected): void
4850
{
4951
$actual = $this->parser->parse($params['command']);
5052
$this->assertSame($expected, $actual);
5153
}
5254

53-
/** @test */
55+
/**
56+
* @test
57+
*
58+
* @return void
59+
*/
5460
public function shouldParseCommandFromTheServer(): void
5561
{
5662
$_SERVER['argv'] = ['script.php', 'arg1', 'arg2', 'arg3'];
@@ -66,6 +72,8 @@ public function shouldParseCommandFromTheServer(): void
6672
*
6773
* @param array $params
6874
* @param bool $expected
75+
*
76+
* @return void
6977
*/
7078
public function shouldTransformParamsToBool(array $params, bool $expected): void
7179
{
@@ -94,7 +102,9 @@ public function testGetParsedCommandsShouldReturnEmptyArrayOnNewObject(): void
94102
* @dataProvider parseProvider
95103
*
96104
* @param array $params
97-
* @param array $expect
105+
* @param array $expected
106+
*
107+
* @return void
98108
*/
99109
public function testGetParsedCommandsShouldReturnParsedCommand(
100110
array $params,
@@ -131,12 +141,11 @@ public function testGetParsedCommandsShouldReturnParsedCommand(
131141
* @dataProvider parseProvider
132142
*
133143
* @param array $params
134-
* @param array $expect
144+
*
145+
* @return void
135146
*/
136-
public function testGetReturnsBoundDefaultValueIfNotSet(
137-
array $params,
138-
array $expect
139-
): void {
147+
public function testGetReturnsBoundDefaultValueIfNotSet(array $params): void
148+
{
140149
$expectedDefaultValues = [
141150
123,
142151
"test",
@@ -145,12 +154,12 @@ public function testGetReturnsBoundDefaultValueIfNotSet(
145154
new stdClass(),
146155
];
147156

148-
$nonExistingParameterKey = "non-existing-parameter-key";
157+
$nonExistingKey = "non-existing-parameter-key";
149158

150-
foreach ($expectedDefaultValues as $expectedDefaultValue) {
151-
$actual = $this->parser->get($nonExistingParameterKey, $expectedDefaultValue);
159+
foreach ($expectedDefaultValues as $expected) {
160+
$actual = $this->parser->get($nonExistingKey, $expected);
152161
$this->assertSame(
153-
$expectedDefaultValue,
162+
$expected,
154163
$actual,
155164
"Should return the provided default value,
156165
if the queried parameter doesn't exist in an empty/fresh object."
@@ -159,10 +168,10 @@ public function testGetReturnsBoundDefaultValueIfNotSet(
159168

160169
$this->parser->parse($params["command"]);
161170

162-
foreach ($expectedDefaultValues as $expectedDefaultValue) {
163-
$actual = $this->parser->get($nonExistingParameterKey, $expectedDefaultValue);
171+
foreach ($expectedDefaultValues as $expected) {
172+
$actual = $this->parser->get($nonExistingKey, $expected);
164173
$this->assertSame(
165-
$expectedDefaultValue,
174+
$expected,
166175
$actual,
167176
"Should return null,
168177
if the queried parameter doesn't exist in a populated/parsed object."
@@ -175,20 +184,21 @@ public function testGetReturnsBoundDefaultValueIfNotSet(
175184
* @dataProvider parseProvider
176185
*
177186
* @param array $params
178-
* @param array $expect
187+
*
188+
* @return void
179189
*/
180190
public function testGetReturnsNullIfParamDoesNotExist(array $params): void
181191
{
182-
$nonExistingParameterKey = "non-existing-parameter-key";
183-
$actual = $this->parser->get($nonExistingParameterKey);
192+
$nonExistingKey = "non-existing-parameter-key";
193+
$actual = $this->parser->get($nonExistingKey);
184194
$this->assertNull(
185195
$actual,
186196
"Should return null,
187197
if the queried parameter doesn't exist in an empty/fresh object."
188198
);
189199

190200
$this->parser->parse($params["command"]);
191-
$actual = $this->parser->get($nonExistingParameterKey);
201+
$actual = $this->parser->get($nonExistingKey);
192202
$this->assertNull(
193203
$actual,
194204
"Should return null,
@@ -202,9 +212,13 @@ public function testGetReturnsNullIfParamDoesNotExist(array $params): void
202212
*
203213
* @param array $params
204214
* @param array $expected
215+
*
216+
* @return void
205217
*/
206-
public function testGetReturnsValueIfParamDoesExist(array $params, array $expected)
207-
{
218+
public function testGetReturnsValueIfParamDoesExist(
219+
array $params,
220+
array $expected
221+
): void {
208222
$this->parser->parse($params["command"]);
209223
foreach ($expected as $parameterKey => $expectedValue) {
210224
$actual = $this->parser->get($parameterKey);

0 commit comments

Comments
 (0)