Skip to content

Commit 92f94c9

Browse files
committed
Remove magics
1 parent 1f0c1d0 commit 92f94c9

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/Core/JVM/Invoker/Invokable.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPJava\Utilities\Formatter;
2222
use PHPJava\Utilities\SuperClassResolver;
2323
use PHPJava\Utilities\TypeResolver;
24+
use PHPJava\Core\JVM\Parameters\Settings;
2425

2526
trait Invokable
2627
{
@@ -111,7 +112,7 @@ function ($argument) {
111112
)['arguments'];
112113

113114
// does not strict mode can be PHP types
114-
if (!($this->options['strict'] ?? true)) {
115+
if (!($this->options['strict'] ?? Settings::STRICT)) {
115116
$formattedArguments = Formatter::signatureConvertToAmbiguousForPHP($formattedArguments);
116117
}
117118

@@ -120,13 +121,13 @@ function ($argument) {
120121
*/
121122
$methodSignature = Formatter::buildArgumentsSignature($formattedArguments);
122123

123-
if (!($this->options['validation']['method']['arguments_count_only'] ?? false)) {
124+
if (!($this->options['validation']['method']['arguments_count_only'] ?? Settings::VALIDATION_METHOD_ARGUMENTS_COUNT_ONLY)) {
124125
if ($methodSignature === $convertedPassedArguments) {
125126
$method = $methodReference;
126127
break;
127128
}
128129
}
129-
if (($this->options['validation']['method']['arguments_count_only'] ?? false) === true) {
130+
if (($this->options['validation']['method']['arguments_count_only'] ?? Settings::VALIDATION_METHOD_ARGUMENTS_COUNT_ONLY) === true) {
130131
$size = count($formattedArguments);
131132
$passedArgumentsSize = count(
132133
$arguments
@@ -180,7 +181,7 @@ function ($argument) {
180181
$mnemonicMap = new OpCode();
181182
$executedCounter = 0;
182183
while ($reader->getOffset() < $codeAttribute->getOpCodeLength()) {
183-
if (++$executedCounter > ($this->options['max_stack_exceeded'] ?? \PHPJava\Core\JVM\Parameters\Invoker::MAX_STACK_EXCEEDED)) {
184+
if (++$executedCounter > ($this->options['max_stack_exceeded'] ?? Settings::MAX_STACK_EXCEEDED)) {
184185
throw new RuntimeException(
185186
'Max stack exceeded. PHPJava has been stopped by safety guard.' .
186187
' Maybe Java class has illegal program counter, stacks, or OpCode.'

src/Core/JVM/Parameters/Invoker.php

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace PHPJava\Core\JVM\Parameters;
3+
4+
final class Settings
5+
{
6+
const MAX_STACK_EXCEEDED = 9999;
7+
const STRICT = true;
8+
9+
const VALIDATION_METHOD_ARGUMENTS_COUNT_ONLY = false;
10+
}

0 commit comments

Comments
 (0)