Skip to content

Commit 5774dce

Browse files
committed
private and internal constants are PascalCase
1 parent 60a38ca commit 5774dce

File tree

9 files changed

+68
-68
lines changed

9 files changed

+68
-68
lines changed

src/CodeCoverage/Generators/HtmlGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class HtmlGenerator extends AbstractGenerator
1919
{
20-
private const CLASSES = [
20+
private const Classes = [
2121
self::CODE_TESTED => 't', // tested
2222
self::CODE_UNTESTED => 'u', // untested
2323
self::CODE_DEAD => 'dead', // dead code
@@ -47,7 +47,7 @@ protected function renderSelf(): void
4747
$this->parse();
4848

4949
$title = $this->title;
50-
$classes = self::CLASSES;
50+
$classes = self::Classes;
5151
$files = $this->files;
5252
$coveredPercent = $this->getCoveredPercent();
5353

src/Framework/Assert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Assert
1717
{
1818
/** used by equal() for comparing floats */
19-
private const EPSILON = 1e-10;
19+
private const Epsilon = 1e-10;
2020

2121
/** used by match(); in values, each $ followed by number is backreference */
2222
public static $patterns = [
@@ -652,7 +652,7 @@ private static function isEqual($expected, $actual, int $level = 0, $objects = n
652652

653653
case is_float($expected) && is_float($actual) && is_finite($expected) && is_finite($actual):
654654
$diff = abs($expected - $actual);
655-
return ($diff < self::EPSILON) || ($diff / max(abs($expected), abs($actual)) < self::EPSILON);
655+
return ($diff < self::Epsilon) || ($diff / max(abs($expected), abs($actual)) < self::Epsilon);
656656

657657
case is_object($expected) && is_object($actual) && get_class($expected) === get_class($actual):
658658
$objects = $objects ? clone $objects : new \SplObjectStorage;

src/Framework/FileMock.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class FileMock
1717
{
18-
private const PROTOCOL = 'mock';
18+
private const Protocol = 'mock';
1919

2020
/** @var string[] */
2121
public static $files = [];
@@ -47,16 +47,16 @@ public static function create(string $content = '', ?string $extension = null):
4747
self::register();
4848

4949
static $id;
50-
$name = self::PROTOCOL . '://' . (++$id) . '.' . $extension;
50+
$name = self::Protocol . '://' . (++$id) . '.' . $extension;
5151
self::$files[$name] = $content;
5252
return $name;
5353
}
5454

5555

5656
public static function register(): void
5757
{
58-
if (!in_array(self::PROTOCOL, stream_get_wrappers(), true)) {
59-
stream_wrapper_register(self::PROTOCOL, self::class);
58+
if (!in_array(self::Protocol, stream_get_wrappers(), true)) {
59+
stream_wrapper_register(self::Protocol, self::class);
6060
}
6161
}
6262

src/Framework/FileMutator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class FileMutator
1818
{
19-
private const PROTOCOL = 'file';
19+
private const Protocol = 'file';
2020

2121
/** @var resource|null */
2222
public $context;
@@ -31,8 +31,8 @@ class FileMutator
3131
public static function addMutator(callable $mutator): void
3232
{
3333
self::$mutators[] = $mutator;
34-
stream_wrapper_unregister(self::PROTOCOL);
35-
stream_wrapper_register(self::PROTOCOL, self::class);
34+
stream_wrapper_unregister(self::Protocol);
35+
stream_wrapper_register(self::Protocol, self::class);
3636
}
3737

3838

@@ -224,12 +224,12 @@ public function url_stat(string $path, int $flags)
224224

225225
private function native(string $func)
226226
{
227-
stream_wrapper_restore(self::PROTOCOL);
227+
stream_wrapper_restore(self::Protocol);
228228
try {
229229
return $func(...array_slice(func_get_args(), 1));
230230
} finally {
231-
stream_wrapper_unregister(self::PROTOCOL);
232-
stream_wrapper_register(self::PROTOCOL, self::class);
231+
stream_wrapper_unregister(self::Protocol);
232+
stream_wrapper_register(self::Protocol, self::class);
233233
}
234234
}
235235
}

src/Framework/TestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class TestCase
1717
{
1818
/** @internal */
1919
public const
20-
LIST_METHODS = 'nette-tester-list-methods',
21-
METHOD_PATTERN = '#^test[A-Z0-9_]#';
20+
ListMethods = 'nette-tester-list-methods',
21+
MethodPattern = '#^test[A-Z0-9_]#';
2222

2323
/** @var bool */
2424
private $handleErrors = false;
@@ -36,13 +36,13 @@ public function run(): void
3636
throw new \LogicException('Calling TestCase::run($method) is deprecated. Use TestCase::runTest($method) instead.');
3737
}
3838

39-
$methods = array_values(preg_grep(self::METHOD_PATTERN, array_map(function (\ReflectionMethod $rm): string {
39+
$methods = array_values(preg_grep(self::MethodPattern, array_map(function (\ReflectionMethod $rm): string {
4040
return $rm->getName();
4141
}, (new \ReflectionObject($this))->getMethods())));
4242

4343
if (isset($_SERVER['argv']) && ($tmp = preg_filter('#--method=([\w-]+)$#Ai', '$1', $_SERVER['argv']))) {
4444
$method = reset($tmp);
45-
if ($method === self::LIST_METHODS) {
45+
if ($method === self::ListMethods) {
4646
$this->sendMethodList($methods);
4747
return;
4848
}
@@ -72,7 +72,7 @@ public function runTest(string $method, ?array $args = null): void
7272
{
7373
if (!method_exists($this, $method)) {
7474
throw new TestCaseException("Method '$method' does not exist.");
75-
} elseif (!preg_match(self::METHOD_PATTERN, $method)) {
75+
} elseif (!preg_match(self::MethodPattern, $method)) {
7676
throw new TestCaseException("Method '$method' is not a testing method.");
7777
}
7878

src/Runner/CliTester.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ private function loadOptions(): CommandLine
130130

131131
XX
132132
, [
133-
'-c' => [CommandLine::REALPATH => true],
134-
'--watch' => [CommandLine::REPEATABLE => true, CommandLine::REALPATH => true],
135-
'--setup' => [CommandLine::REALPATH => true],
136-
'--temp' => [CommandLine::REALPATH => true],
137-
'paths' => [CommandLine::REPEATABLE => true, CommandLine::VALUE => getcwd()],
133+
'-c' => [CommandLine::Realpath => true],
134+
'--watch' => [CommandLine::Repeatable => true, CommandLine::Realpath => true],
135+
'--setup' => [CommandLine::Realpath => true],
136+
'--temp' => [CommandLine::Realpath => true],
137+
'paths' => [CommandLine::Repeatable => true, CommandLine::Value => getcwd()],
138138
'--debug' => [],
139139
'--cider' => [],
140-
'--coverage-src' => [CommandLine::REALPATH => true, CommandLine::REPEATABLE => true],
141-
'-o' => [CommandLine::REPEATABLE => true, CommandLine::NORMALIZER => function ($arg) use (&$outputFiles) {
140+
'--coverage-src' => [CommandLine::Realpath => true, CommandLine::Repeatable => true],
141+
'-o' => [CommandLine::Repeatable => true, CommandLine::Normalizer => function ($arg) use (&$outputFiles) {
142142
[$format, $file] = explode(':', $arg, 2) + [1 => null];
143143

144144
if (isset($outputFiles[$file])) {

src/Runner/CommandLine.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
class CommandLine
1717
{
1818
public const
19-
ARGUMENT = 'argument',
20-
OPTIONAL = 'optional',
21-
REPEATABLE = 'repeatable',
22-
ENUM = 'enum',
23-
REALPATH = 'realpath',
24-
NORMALIZER = 'normalizer',
25-
VALUE = 'default';
19+
Argument = 'argument',
20+
Optional = 'optional',
21+
Repeatable = 'repeatable',
22+
Enum = 'enum',
23+
Realpath = 'realpath',
24+
Normalizer = 'normalizer',
25+
Value = 'default';
2626

2727
/** @var array[] */
2828
private $options = [];
@@ -52,11 +52,11 @@ public function __construct(string $help, array $defaults = [])
5252
$name = end($m[1]);
5353
$opts = $this->options[$name] ?? [];
5454
$this->options[$name] = $opts + [
55-
self::ARGUMENT => (bool) end($m[2]),
56-
self::OPTIONAL => isset($line[2]) || (substr(end($m[2]), 0, 1) === '[') || isset($opts[self::VALUE]),
57-
self::REPEATABLE => (bool) end($m[3]),
58-
self::ENUM => count($enums = explode('|', trim(end($m[2]), '<[]>'))) > 1 ? $enums : null,
59-
self::VALUE => $line[2] ?? null,
55+
self::Argument => (bool) end($m[2]),
56+
self::Optional => isset($line[2]) || (substr(end($m[2]), 0, 1) === '[') || isset($opts[self::Value]),
57+
self::Repeatable => (bool) end($m[3]),
58+
self::Enum => count($enums = explode('|', trim(end($m[2]), '<[]>'))) > 1 ? $enums : null,
59+
self::Value => $line[2] ?? null,
6060
];
6161
if ($name !== $m[1][0]) {
6262
$this->aliases[$m[1][0]] = $name;
@@ -89,7 +89,7 @@ public function parse(?array $args = null): array
8989

9090
$name = current($this->positional);
9191
$this->checkArg($this->options[$name], $arg);
92-
if (empty($this->options[$name][self::REPEATABLE])) {
92+
if (empty($this->options[$name][self::Repeatable])) {
9393
$params[$name] = $arg;
9494
next($this->positional);
9595
} else {
@@ -110,31 +110,31 @@ public function parse(?array $args = null): array
110110

111111
$opt = $this->options[$name];
112112

113-
if ($arg !== true && empty($opt[self::ARGUMENT])) {
113+
if ($arg !== true && empty($opt[self::Argument])) {
114114
throw new \Exception("Option $name has not argument.");
115115

116-
} elseif ($arg === true && !empty($opt[self::ARGUMENT])) {
116+
} elseif ($arg === true && !empty($opt[self::Argument])) {
117117
if (isset($args[$i]) && $args[$i][0] !== '-') {
118118
$arg = $args[$i++];
119-
} elseif (empty($opt[self::OPTIONAL])) {
119+
} elseif (empty($opt[self::Optional])) {
120120
throw new \Exception("Option $name requires argument.");
121121
}
122122
}
123123

124124
$this->checkArg($opt, $arg);
125125

126126
if (
127-
!empty($opt[self::ENUM])
128-
&& !in_array(is_array($arg) ? reset($arg) : $arg, $opt[self::ENUM], true)
127+
!empty($opt[self::Enum])
128+
&& !in_array(is_array($arg) ? reset($arg) : $arg, $opt[self::Enum], true)
129129
&& !(
130-
$opt[self::OPTIONAL]
130+
$opt[self::Optional]
131131
&& $arg === true
132132
)
133133
) {
134-
throw new \Exception("Value of option $name must be " . implode(', or ', $opt[self::ENUM]) . '.');
134+
throw new \Exception("Value of option $name must be " . implode(', or ', $opt[self::Enum]) . '.');
135135
}
136136

137-
if (empty($opt[self::REPEATABLE])) {
137+
if (empty($opt[self::Repeatable])) {
138138
$params[$name] = $arg;
139139
} else {
140140
$params[$name][] = $arg;
@@ -144,15 +144,15 @@ public function parse(?array $args = null): array
144144
foreach ($this->options as $name => $opt) {
145145
if (isset($params[$name])) {
146146
continue;
147-
} elseif (isset($opt[self::VALUE])) {
148-
$params[$name] = $opt[self::VALUE];
149-
} elseif ($name[0] !== '-' && empty($opt[self::OPTIONAL])) {
147+
} elseif (isset($opt[self::Value])) {
148+
$params[$name] = $opt[self::Value];
149+
} elseif ($name[0] !== '-' && empty($opt[self::Optional])) {
150150
throw new \Exception("Missing required argument <$name>.");
151151
} else {
152152
$params[$name] = null;
153153
}
154154

155-
if (!empty($opt[self::REPEATABLE])) {
155+
if (!empty($opt[self::Repeatable])) {
156156
$params[$name] = (array) $params[$name];
157157
}
158158
}
@@ -169,11 +169,11 @@ public function help(): void
169169

170170
public function checkArg(array $opt, &$arg): void
171171
{
172-
if (!empty($opt[self::NORMALIZER])) {
173-
$arg = call_user_func($opt[self::NORMALIZER], $arg);
172+
if (!empty($opt[self::Normalizer])) {
173+
$arg = call_user_func($opt[self::Normalizer], $arg);
174174
}
175175

176-
if (!empty($opt[self::REALPATH])) {
176+
if (!empty($opt[self::Realpath])) {
177177
$path = realpath($arg);
178178
if ($path === false) {
179179
throw new \Exception("File path '$arg' not found.");

src/Runner/TestHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class TestHandler
2222
{
23-
private const HTTP_OK = 200;
23+
private const HttpOk = 200;
2424

2525
/** @var Runner */
2626
private $runner;
@@ -88,7 +88,7 @@ public function assess(Job $job): void
8888
$test = $job->getTest();
8989
$annotations = $this->getAnnotations($test->getFile())[0] += [
9090
'exitcode' => Job::CODE_OK,
91-
'httpcode' => self::HTTP_OK,
91+
'httpcode' => self::HttpOk,
9292
];
9393

9494
foreach (get_class_methods($this) as $method) {
@@ -195,7 +195,7 @@ private function initiateTestCase(Test $test, $foo, PhpInterpreter $interpreter)
195195
}
196196

197197
if ($methods === null) {
198-
$job = new Job($test->withArguments(['method' => TestCase::LIST_METHODS]), $interpreter, $this->runner->getEnvironmentVariables());
198+
$job = new Job($test->withArguments(['method' => TestCase::ListMethods]), $interpreter, $this->runner->getEnvironmentVariables());
199199
$job->run();
200200

201201
if (in_array($job->getExitCode(), [Job::CODE_ERROR, Job::CODE_FAIL, Job::CODE_SKIP], true)) {
@@ -259,7 +259,7 @@ private function assessHttpCode(Job $job, $code): ?Test
259259
}
260260

261261
$headers = $job->getHeaders();
262-
$actual = (int) ($headers['Status'] ?? self::HTTP_OK);
262+
$actual = (int) ($headers['Status'] ?? self::HttpOk);
263263
$code = (int) $code;
264264
return $code && $code !== $actual
265265
? $job->getTest()->withResult(Test::FAILED, "Exited with HTTP code $actual (expected $code)")

0 commit comments

Comments
 (0)