Skip to content

Commit

Permalink
private and internal constants are PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 24, 2022
1 parent 60a38ca commit 5774dce
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions src/CodeCoverage/Generators/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class HtmlGenerator extends AbstractGenerator
{
private const CLASSES = [
private const Classes = [
self::CODE_TESTED => 't', // tested
self::CODE_UNTESTED => 'u', // untested
self::CODE_DEAD => 'dead', // dead code
Expand Down Expand Up @@ -47,7 +47,7 @@ protected function renderSelf(): void
$this->parse();

$title = $this->title;
$classes = self::CLASSES;
$classes = self::Classes;
$files = $this->files;
$coveredPercent = $this->getCoveredPercent();

Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Assert
{
/** used by equal() for comparing floats */
private const EPSILON = 1e-10;
private const Epsilon = 1e-10;

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

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

case is_object($expected) && is_object($actual) && get_class($expected) === get_class($actual):
$objects = $objects ? clone $objects : new \SplObjectStorage;
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/FileMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class FileMock
{
private const PROTOCOL = 'mock';
private const Protocol = 'mock';

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

static $id;
$name = self::PROTOCOL . '://' . (++$id) . '.' . $extension;
$name = self::Protocol . '://' . (++$id) . '.' . $extension;
self::$files[$name] = $content;
return $name;
}


public static function register(): void
{
if (!in_array(self::PROTOCOL, stream_get_wrappers(), true)) {
stream_wrapper_register(self::PROTOCOL, self::class);
if (!in_array(self::Protocol, stream_get_wrappers(), true)) {
stream_wrapper_register(self::Protocol, self::class);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Framework/FileMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class FileMutator
{
private const PROTOCOL = 'file';
private const Protocol = 'file';

/** @var resource|null */
public $context;
Expand All @@ -31,8 +31,8 @@ class FileMutator
public static function addMutator(callable $mutator): void
{
self::$mutators[] = $mutator;
stream_wrapper_unregister(self::PROTOCOL);
stream_wrapper_register(self::PROTOCOL, self::class);
stream_wrapper_unregister(self::Protocol);
stream_wrapper_register(self::Protocol, self::class);
}


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

private function native(string $func)
{
stream_wrapper_restore(self::PROTOCOL);
stream_wrapper_restore(self::Protocol);
try {
return $func(...array_slice(func_get_args(), 1));
} finally {
stream_wrapper_unregister(self::PROTOCOL);
stream_wrapper_register(self::PROTOCOL, self::class);
stream_wrapper_unregister(self::Protocol);
stream_wrapper_register(self::Protocol, self::class);
}
}
}
10 changes: 5 additions & 5 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class TestCase
{
/** @internal */
public const
LIST_METHODS = 'nette-tester-list-methods',
METHOD_PATTERN = '#^test[A-Z0-9_]#';
ListMethods = 'nette-tester-list-methods',
MethodPattern = '#^test[A-Z0-9_]#';

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

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

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

Expand Down
14 changes: 7 additions & 7 deletions src/Runner/CliTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ private function loadOptions(): CommandLine

XX
, [
'-c' => [CommandLine::REALPATH => true],
'--watch' => [CommandLine::REPEATABLE => true, CommandLine::REALPATH => true],
'--setup' => [CommandLine::REALPATH => true],
'--temp' => [CommandLine::REALPATH => true],
'paths' => [CommandLine::REPEATABLE => true, CommandLine::VALUE => getcwd()],
'-c' => [CommandLine::Realpath => true],
'--watch' => [CommandLine::Repeatable => true, CommandLine::Realpath => true],
'--setup' => [CommandLine::Realpath => true],
'--temp' => [CommandLine::Realpath => true],
'paths' => [CommandLine::Repeatable => true, CommandLine::Value => getcwd()],
'--debug' => [],
'--cider' => [],
'--coverage-src' => [CommandLine::REALPATH => true, CommandLine::REPEATABLE => true],
'-o' => [CommandLine::REPEATABLE => true, CommandLine::NORMALIZER => function ($arg) use (&$outputFiles) {
'--coverage-src' => [CommandLine::Realpath => true, CommandLine::Repeatable => true],
'-o' => [CommandLine::Repeatable => true, CommandLine::Normalizer => function ($arg) use (&$outputFiles) {
[$format, $file] = explode(':', $arg, 2) + [1 => null];

if (isset($outputFiles[$file])) {
Expand Down
56 changes: 28 additions & 28 deletions src/Runner/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
class CommandLine
{
public const
ARGUMENT = 'argument',
OPTIONAL = 'optional',
REPEATABLE = 'repeatable',
ENUM = 'enum',
REALPATH = 'realpath',
NORMALIZER = 'normalizer',
VALUE = 'default';
Argument = 'argument',
Optional = 'optional',
Repeatable = 'repeatable',
Enum = 'enum',
Realpath = 'realpath',
Normalizer = 'normalizer',
Value = 'default';

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

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

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

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

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

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

if (
!empty($opt[self::ENUM])
&& !in_array(is_array($arg) ? reset($arg) : $arg, $opt[self::ENUM], true)
!empty($opt[self::Enum])
&& !in_array(is_array($arg) ? reset($arg) : $arg, $opt[self::Enum], true)
&& !(
$opt[self::OPTIONAL]
$opt[self::Optional]
&& $arg === true
)
) {
throw new \Exception("Value of option $name must be " . implode(', or ', $opt[self::ENUM]) . '.');
throw new \Exception("Value of option $name must be " . implode(', or ', $opt[self::Enum]) . '.');
}

if (empty($opt[self::REPEATABLE])) {
if (empty($opt[self::Repeatable])) {
$params[$name] = $arg;
} else {
$params[$name][] = $arg;
Expand All @@ -144,15 +144,15 @@ public function parse(?array $args = null): array
foreach ($this->options as $name => $opt) {
if (isset($params[$name])) {
continue;
} elseif (isset($opt[self::VALUE])) {
$params[$name] = $opt[self::VALUE];
} elseif ($name[0] !== '-' && empty($opt[self::OPTIONAL])) {
} elseif (isset($opt[self::Value])) {
$params[$name] = $opt[self::Value];
} elseif ($name[0] !== '-' && empty($opt[self::Optional])) {
throw new \Exception("Missing required argument <$name>.");
} else {
$params[$name] = null;
}

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

public function checkArg(array $opt, &$arg): void
{
if (!empty($opt[self::NORMALIZER])) {
$arg = call_user_func($opt[self::NORMALIZER], $arg);
if (!empty($opt[self::Normalizer])) {
$arg = call_user_func($opt[self::Normalizer], $arg);
}

if (!empty($opt[self::REALPATH])) {
if (!empty($opt[self::Realpath])) {
$path = realpath($arg);
if ($path === false) {
throw new \Exception("File path '$arg' not found.");
Expand Down
8 changes: 4 additions & 4 deletions src/Runner/TestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class TestHandler
{
private const HTTP_OK = 200;
private const HttpOk = 200;

/** @var Runner */
private $runner;
Expand Down Expand Up @@ -88,7 +88,7 @@ public function assess(Job $job): void
$test = $job->getTest();
$annotations = $this->getAnnotations($test->getFile())[0] += [
'exitcode' => Job::CODE_OK,
'httpcode' => self::HTTP_OK,
'httpcode' => self::HttpOk,
];

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

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

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

$headers = $job->getHeaders();
$actual = (int) ($headers['Status'] ?? self::HTTP_OK);
$actual = (int) ($headers['Status'] ?? self::HttpOk);
$code = (int) $code;
return $code && $code !== $actual
? $job->getTest()->withResult(Test::FAILED, "Exited with HTTP code $actual (expected $code)")
Expand Down
Loading

0 comments on commit 5774dce

Please sign in to comment.