Skip to content

Commit f86c9d3

Browse files
committed
General: Change method names to camelCase
1 parent f858de7 commit f86c9d3

11 files changed

+180
-134
lines changed

src/Lunr/Shadow/GetoptCliParser.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,27 @@ public function parse(): array
7474
return [];
7575
}
7676

77-
return array_map([ $this, 'wrap_argument' ], $raw);
77+
return array_map([ $this, 'wrapArgument' ], $raw);
7878
}
7979

8080
/**
8181
* Parse error information.
8282
*
83+
* @deprecated Use isInvalidCommandline() instead
84+
*
8385
* @return bool Whether there was a parse error or not
8486
*/
8587
public function is_invalid_commandline(): bool
88+
{
89+
return $this->isInvalidCommandline();
90+
}
91+
92+
/**
93+
* Parse error information.
94+
*
95+
* @return bool Whether there was a parse error or not
96+
*/
97+
public function isInvalidCommandline(): bool
8698
{
8799
return $this->error;
88100
}
@@ -94,7 +106,7 @@ public function is_invalid_commandline(): bool
94106
*
95107
* @return list<bool>|list<string> Wrapped argument
96108
*/
97-
protected function wrap_argument(bool|string|array $value): array
109+
protected function wrapArgument(bool|string|array $value): array
98110
{
99111
if ($value === FALSE)
100112
{

src/Lunr/Shadow/LunrCliParser.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function parse(): array
122122
{
123123
if (!in_array($arg, $this->checked) && $index != 0)
124124
{
125-
$this->is_opt($arg, $index, TRUE);
125+
$this->isOpt($arg, $index, TRUE);
126126
}
127127
}
128128

@@ -132,9 +132,21 @@ public function parse(): array
132132
/**
133133
* Check whether the parsed command line was valid or not.
134134
*
135+
* @deprecated Use isInvalidCommandline() instead
136+
*
135137
* @return bool TRUE if the command line was invalid, FALSE otherwise
136138
*/
137139
public function is_invalid_commandline(): bool
140+
{
141+
return $this->isInvalidCommandline();
142+
}
143+
144+
/**
145+
* Check whether the parsed command line was valid or not.
146+
*
147+
* @return bool TRUE if the command line was invalid, FALSE otherwise
148+
*/
149+
public function isInvalidCommandline(): bool
138150
{
139151
return $this->error;
140152
}
@@ -149,31 +161,31 @@ public function is_invalid_commandline(): bool
149161
*
150162
* @return bool Success or Failure
151163
*/
152-
private function is_opt(string $opt, int $index, bool $toplevel = FALSE): bool
164+
private function isOpt(string $opt, int $index, bool $toplevel = FALSE): bool
153165
{
154166
array_push($this->checked, $opt);
155167

156168
if (isset($opt[0]) && $opt[0] == '-')
157169
{
158170
if (strlen($opt) < 1)
159171
{
160-
return $this->is_valid_short($opt, $index);
172+
return $this->isValidShort($opt, $index);
161173
}
162174

163175
$param = substr($opt, 1);
164176

165177
if (isset($param[0]) && $param[0] != '-')
166178
{
167-
return $this->is_valid_short($param, $index);
179+
return $this->isValidShort($param, $index);
168180
}
169181

170182
if (strlen($param) > 1)
171183
{
172-
return $this->is_valid_long(substr($param, 1), $index);
184+
return $this->isValidLong(substr($param, 1), $index);
173185
}
174186
else
175187
{
176-
return $this->is_valid_long($opt, $index);
188+
return $this->isValidLong($opt, $index);
177189
}
178190
}
179191
elseif ($toplevel)
@@ -192,7 +204,7 @@ private function is_opt(string $opt, int $index, bool $toplevel = FALSE): bool
192204
*
193205
* @return bool Success or Failure
194206
*/
195-
private function is_valid_short(string $opt, int $index): bool
207+
private function isValidShort(string $opt, int $index): bool
196208
{
197209
$pos = strpos($this->short, $opt);
198210

@@ -205,7 +217,7 @@ private function is_valid_short(string $opt, int $index): bool
205217

206218
$this->ast[$opt] = [];
207219

208-
return $this->check_argument($opt, $index, $pos, $this->short);
220+
return $this->checkArgument($opt, $index, $pos, $this->short);
209221
}
210222

211223
/**
@@ -216,7 +228,7 @@ private function is_valid_short(string $opt, int $index): bool
216228
*
217229
* @return bool Success or Failure
218230
*/
219-
private function is_valid_long(string $opt, int $index): bool
231+
private function isValidLong(string $opt, int $index): bool
220232
{
221233
$match = FALSE;
222234
$args = '';
@@ -247,7 +259,7 @@ private function is_valid_long(string $opt, int $index): bool
247259

248260
$this->ast[$opt] = [];
249261

250-
return $this->check_argument($opt, $index, strlen($opt) - 1, $this->long[$args]);
262+
return $this->checkArgument($opt, $index, strlen($opt) - 1, $this->long[$args]);
251263
}
252264

253265
/**
@@ -261,7 +273,7 @@ private function is_valid_long(string $opt, int $index): bool
261273
*
262274
* @return bool Success or Failure
263275
*/
264-
private function check_argument(string $opt, int $index, int $pos, string $a): bool
276+
private function checkArgument(string $opt, int $index, int $pos, string $a): bool
265277
{
266278
$next = $index + 1;
267279

@@ -276,7 +288,7 @@ private function check_argument(string $opt, int $index, int $pos, string $a): b
276288

277289
if (count($this->args) > $next && strlen($this->args[$next]) != 0)
278290
{
279-
if (!$this->is_opt($this->args[$next], $next) && $this->args[$next][0] != '-')
291+
if (!$this->isOpt($this->args[$next], $next) && $this->args[$next][0] != '-')
280292
{
281293
array_push($this->ast[$opt], $this->args[$next]);
282294

@@ -287,7 +299,7 @@ private function check_argument(string $opt, int $index, int $pos, string $a): b
287299

288300
if (($type == ':' && $a[$pos + 2] == ':') || $a[$pos + 2] == ';')
289301
{
290-
return $this->check_argument($opt, $next, $pos + 1, $a);
302+
return $this->checkArgument($opt, $next, $pos + 1, $a);
291303
}
292304
else
293305
{

src/Lunr/Shadow/Tests/GetoptCliParserBaseTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,21 @@ public function testErrorIsFalseByDefault(): void
4747
*
4848
* @covers Lunr\Shadow\GetoptCliParser::is_invalid_commandline
4949
*/
50-
public function testIsInvalidCommandLineReturnsError(): void
50+
public function testDeprecatedIsInvalidCommandLineReturnsError(): void
5151
{
5252
$this->assertPropertyEquals('error', $this->class->is_invalid_commandline());
5353
}
5454

55+
/**
56+
* Test that isInvalidCommandline() returns the value of error.
57+
*
58+
* @covers Lunr\Shadow\GetoptCliParser::isInvalidCommandline
59+
*/
60+
public function testIsInvalidCommandLineReturnsError(): void
61+
{
62+
$this->assertPropertyEquals('error', $this->class->isInvalidCommandline());
63+
}
64+
5565
}
5666

5767
?>

src/Lunr/Shadow/Tests/GetoptCliParserParseTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,44 @@ class GetoptCliParserParseTest extends GetoptCliParserTestCase
1919
{
2020

2121
/**
22-
* Test that wrap_argument() replaces a FALSE value with an empty array.
22+
* Test that wrapArgument() replaces a FALSE value with an empty array.
2323
*
24-
* @covers Lunr\Shadow\GetoptCliParser::wrap_argument
24+
* @covers Lunr\Shadow\GetoptCliParser::wrapArgument
2525
*/
2626
public function testWrapArgumentReturnsEmptyArrayForFalse(): void
2727
{
28-
$method = $this->getReflectionMethod('wrap_argument');
28+
$method = $this->getReflectionMethod('wrapArgument');
2929

3030
$value = $method->invokeArgs($this->class, [ FALSE ]);
3131

3232
$this->assertArrayEmpty($value);
3333
}
3434

3535
/**
36-
* Test that wrap_argument() replaces a FALSE value with an empty array.
36+
* Test that wrapArgument() replaces a FALSE value with an empty array.
3737
*
3838
* @param mixed $cliValue Value to wrap
3939
*
4040
* @dataProvider valueProvider
41-
* @covers Lunr\Shadow\GetoptCliParser::wrap_argument
41+
* @covers Lunr\Shadow\GetoptCliParser::wrapArgument
4242
*/
4343
public function testWrapArgumentReturnsValueWrappedInArray($cliValue): void
4444
{
45-
$method = $this->getReflectionMethod('wrap_argument');
45+
$method = $this->getReflectionMethod('wrapArgument');
4646

4747
$value = $method->invokeArgs($this->class, [ $cliValue ]);
4848

4949
$this->assertEquals([ $cliValue ], $value);
5050
}
5151

5252
/**
53-
* Test that wrap_argument() does not re-wrap already wrapped arguments (like multiple parameters).
53+
* Test that wrapArgument() does not re-wrap already wrapped arguments (like multiple parameters).
5454
*
55-
* @covers Lunr\Shadow\GetoptCliParser::wrap_argument
55+
* @covers Lunr\Shadow\GetoptCliParser::wrapArgument
5656
*/
5757
public function testWrapArgumentDoesNotRewrapArguments(): void
5858
{
59-
$method = $this->getReflectionMethod('wrap_argument');
59+
$method = $this->getReflectionMethod('wrapArgument');
6060

6161
$value = $method->invokeArgs($this->class, [ [ 'param1', 'param2' ] ]);
6262

src/Lunr/Shadow/Tests/LunrCliParserBaseTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,25 @@ public function testErrorIsFalseByDefault(): void
7777
*
7878
* @covers Lunr\Shadow\LunrCliParser::is_invalid_commandline
7979
*/
80-
public function testIsInvalidCommandLineReturnsError(): void
80+
public function testDeprecatedIsInvalidCommandLineReturnsError(): void
8181
{
8282
$value = $this->getReflectionPropertyValue('error');
8383

8484
$this->assertEquals($value, $this->class->is_invalid_commandline());
8585
}
8686

87+
/**
88+
* Test that isInvalidCommandline() returns the value of error.
89+
*
90+
* @covers Lunr\Shadow\LunrCliParser::isInvalidCommandline
91+
*/
92+
public function testIsInvalidCommandLineReturnsError(): void
93+
{
94+
$value = $this->getReflectionPropertyValue('error');
95+
96+
$this->assertEquals($value, $this->class->isInvalidCommandline());
97+
}
98+
8799
}
88100

89101
?>

src/Lunr/Shadow/Tests/LunrCliParserCheckArgumentTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@
1111
namespace Lunr\Shadow\Tests;
1212

1313
/**
14-
* This class contains test methods for check_arguments() in the LunrCliParser class.
14+
* This class contains test methods for checkArguments() in the LunrCliParser class.
1515
*
1616
* @covers Lunr\Shadow\LunrCliParser
1717
*/
1818
class LunrCliParserCheckArgumentTest extends LunrCliParserTestCase
1919
{
2020

2121
/**
22-
* Test that check_argument() returns FALSE for a valid parameter without arguments.
22+
* Test that checkArgument() returns FALSE for a valid parameter without arguments.
2323
*
24-
* @covers Lunr\Shadow\LunrCliParser::check_argument
24+
* @covers Lunr\Shadow\LunrCliParser::checkArgument
2525
*/
2626
public function testCheckArgumentReturnsFalseForValidParameterWithoutArgs(): void
2727
{
28-
$method = $this->getReflectionMethod('check_argument');
28+
$method = $this->getReflectionMethod('checkArgument');
2929

3030
$value = $method->invokeArgs($this->class, [ 'a', 1, 0, 'a' ]);
3131

3232
$this->assertFalse($value);
3333
}
3434

3535
/**
36-
* Test that check_argument() returns TRUE for a superfluous argument.
36+
* Test that checkArgument() returns TRUE for a superfluous argument.
3737
*
38-
* @covers Lunr\Shadow\LunrCliParser::check_argument
38+
* @covers Lunr\Shadow\LunrCliParser::checkArgument
3939
*/
4040
public function testCheckArgumentReturnsTrueForSuperfluousArgument(): void
4141
{
4242
$this->setReflectionPropertyValue('args', [ 'test.php', '-a', 'arg' ]);
4343

44-
$method = $this->getReflectionMethod('check_argument');
44+
$method = $this->getReflectionMethod('checkArgument');
4545

4646
$this->expectUserNotice('Superfluous argument: arg');
4747

0 commit comments

Comments
 (0)