Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
34 changes: 29 additions & 5 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
;
->in(__DIR__ . '/tests');

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'@PhpCsFixer' => true,
'array_syntax' => [
'syntax' => 'short',
],
'blank_line_after_opening_tag' => false,
'blank_line_before_statement' => [
'statements' => [],
],
'concat_space' => [
'spacing' => 'one',
],
'increment_style' => [
'style' => 'post',
],
'no_multiline_whitespace_before_semicolons' => true,
'no_superfluous_phpdoc_tags' => true,
'ordered_class_elements' => false,
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'phpdoc_align' => [
'align' => 'left',
],
'phpdoc_separation' => false,
'phpdoc_to_comment' => false,
'phpdoc_var_without_name' => false,
'single_blank_line_before_namespace' => false,
'yoda_style' => false,
])
->setFinder($finder)
;
->setFinder($finder);
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
"friendsofphp/php-cs-fixer": "^2.14"
},
"scripts": {
"tests": "phpunit tests --stop-on-failure && phpcs -n --standard=phpcs.xml src"
"test": "phpunit tests --stop-on-failure",
"cs": "phpcs -n --standard=phpcs.xml src",
"fix": "php-cs-fixer fix",
"tests": [
"@test",
"@cs",
"@fix"
]
}
}
1 change: 1 addition & 0 deletions src/Core/JVM/AccessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
interface AccessorInterface
{
public function getFields(): FieldInterface;

public function getMethods(): InvokerInterface;
}
4 changes: 1 addition & 3 deletions src/Core/JVM/ConstantPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class ConstantPool implements \ArrayAccess, \Countable, \IteratorAggregate
private $reader;

/**
* @param ReaderInterface $reader
* @param int $entries
* @throws ReadEntryException
*/
public function __construct(ReaderInterface $reader, int $entries)
Expand Down Expand Up @@ -98,7 +96,7 @@ private function read($entryTag): ?StructureInterface
}

/**
* @return boolean
* @return bool
*/
public function offsetExists($offset)
{
Expand Down
2 changes: 0 additions & 2 deletions src/Core/JVM/Field/FieldGettable.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php
namespace PHPJava\Core\JVM\Field;

use PHPJava\Core\JavaClassInvoker;
use PHPJava\Packages\java\lang\_String;
use PHPJava\Packages\java\lang\NoSuchFieldException;

trait FieldGettable
{
/**
* @param $name
* @return mixed
* @throws NoSuchFieldException
*/
public function get(string $name)
Expand Down
2 changes: 2 additions & 0 deletions src/Core/JVM/Field/FieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
interface FieldInterface
{
public function __construct(JavaClassInvoker $javaClassInvoker, array $fields);

public function get(string $name);

public function set(string $name, $value);
}
2 changes: 0 additions & 2 deletions src/Core/JVM/Field/FieldSettable.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace PHPJava\Core\JVM\Field;

use PHPJava\Core\JavaClassInvoker;

trait FieldSettable
{
public function set(string $name, $value)
Expand Down
1 change: 0 additions & 1 deletion src/Core/JVM/Field/StaticField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace PHPJava\Core\JVM\Field;

use PHPJava\Core\JavaClassInvoker;
use PHPJava\Packages\java\lang\_String;

class StaticField implements FieldInterface
{
Expand Down
1 change: 0 additions & 1 deletion src/Core/JVM/FieldPool.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace PHPJava\Core\JVM;

use PHPJava\Core\JavaClass;
use PHPJava\Core\Stream\Reader\ReaderInterface;
use PHPJava\Exceptions\ReadOnlyException;
use PHPJava\Kernel\Structures\_FieldInfo;
Expand Down
1 change: 0 additions & 1 deletion src/Core/JVM/InterfacePool.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace PHPJava\Core\JVM;

use PHPJava\Core\JavaClass;
use PHPJava\Core\Stream\Reader\ReaderInterface;
use PHPJava\Exceptions\ReadOnlyException;
use PHPJava\Utilities\DebugTool;
Expand Down
19 changes: 4 additions & 15 deletions src/Core/JVM/Invoker/Invokable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@
namespace PHPJava\Core\JVM\Invoker;

use ByteUnits\Metric;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPJava\Core\JavaClass;
use PHPJava\Core\JavaClassInvoker;
use PHPJava\Core\JVM\Cache\OperationCache;
use PHPJava\Core\JVM\FlexibleMethod;
use PHPJava\Core\JVM\Parameters\GlobalOptions;
use PHPJava\Core\JVM\Parameters\Runtime;
use PHPJava\Core\JVM\Stream\BinaryReader;
use PHPJava\Exceptions\IllegalJavaClassException;
use PHPJava\Exceptions\RuntimeException;
use PHPJava\Exceptions\UndefinedMethodException;
use PHPJava\Exceptions\UndefinedOpCodeException;
use PHPJava\Kernel\Provider\DependencyInjectionProvider;
use PHPJava\Packages\java\lang\NoSuchMethodException;
use PHPJava\Kernel\Attributes\AttributeInfo;
use PHPJava\Kernel\Attributes\AttributeInterface;
use PHPJava\Kernel\Attributes\CodeAttribute;
use PHPJava\Kernel\Core\Accumulator;
use PHPJava\Kernel\Core\ConstantPool;
use PHPJava\Kernel\Maps\OpCode;
use PHPJava\Kernel\Mnemonics\OperationInterface;
use PHPJava\Kernel\Provider\DependencyInjectionProvider;
use PHPJava\Kernel\Structures\_MethodInfo;
use PHPJava\Kernel\Types\_Char;
use PHPJava\Packages\java\lang\NoSuchMethodException;
use PHPJava\Utilities\AttributionResolver;
use PHPJava\Utilities\DebugTool;
use PHPJava\Utilities\Formatter;
use PHPJava\Utilities\SuperClassResolver;
use PHPJava\Utilities\TypeResolver;
use PHPJava\Core\JVM\Parameters\Runtime;

trait Invokable
{
Expand All @@ -39,7 +34,6 @@ trait Invokable
private $options = [];
private $debugTool;


public function __construct(JavaClassInvoker $javaClassInvoker, array $methods, array $options = [])
{
$this->javaClassInvoker = $javaClassInvoker;
Expand All @@ -51,11 +45,8 @@ public function __construct(JavaClassInvoker $javaClassInvoker, array $methods,
);
}


/**
* @param string $name
* @param mixed ...$arguments
* @return null
* @throws IllegalJavaClassException
* @throws RuntimeException
* @throws UndefinedOpCodeException
Expand Down Expand Up @@ -238,7 +229,7 @@ function ($item) {
}

/**
* @var OperationInterface|Accumulator|ConstantPool $executor
* @var Accumulator|ConstantPool|OperationInterface $executor
*/
$executor = $operationCache->fetchOrPush(
$fullName,
Expand Down Expand Up @@ -299,7 +290,6 @@ public function has(string $name): bool
/**
* @param $name
* @param mixed ...$arguments
* @return _MethodInfo
* @throws NoSuchMethodException
* @throws UndefinedMethodException
* @throws \PHPJava\Exceptions\TypeException
Expand Down Expand Up @@ -371,7 +361,6 @@ private function findMethod($name, ...$arguments): _MethodInfo

/**
* @param mixed ...$arguments
* @return string
*/
private function stringifyArguments(...$arguments): string
{
Expand Down
4 changes: 4 additions & 0 deletions src/Core/JVM/Invoker/InvokerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
interface InvokerInterface
{
public function __construct(JavaClassInvoker $javaClassInvoker, array $methods);

public function call(string $name, ...$arguments);

public function isDynamic(): bool;

public function getList(): array;

public function has(string $name): bool;
}
1 change: 0 additions & 1 deletion src/Core/JVM/Stream/BinaryReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace PHPJava\Core\JVM\Stream;

use PHPJava\Exceptions\BinaryReaderException;
use PHPJava\Utilities\BinaryTool;

class BinaryReader
{
Expand Down
4 changes: 0 additions & 4 deletions src/Core/JavaArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPJava\Exceptions\UndefinedEntrypointException;
use PHPJava\Kernel\Internal\JavaClassDeferredLoader;
use PHPJava\Packages\java\io\FileNotFoundException;
use PHPJava\Packages\java\lang\_Object;
use PHPJava\Packages\java\lang\ClassNotFoundException;
use PHPJava\Utilities\ClassResolver;
use PHPJava\Utilities\DebugTool;
Expand All @@ -31,8 +30,6 @@ class JavaArchive
private $startTime = 0.0;

/**
* @param string $jarFile
* @param array $options
* @throws FileNotFoundException
* @throws \PHPJava\Exceptions\ReadEntryException
* @throws \PHPJava\Exceptions\ValidatorException
Expand Down Expand Up @@ -158,7 +155,6 @@ public function __destruct()

/**
* @param mixed ...$arguments
* @return mixed
* @throws ClassNotFoundException
* @throws UndefinedEntrypointException
*/
Expand Down
40 changes: 16 additions & 24 deletions src/Core/JavaClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
namespace PHPJava\Core;

use PHPJava\Core\JVM\AttributePool;
use PHPJava\Core\JVM\ConstantPool;
use PHPJava\Core\JVM\FieldPool;
use PHPJava\Core\JVM\InterfacePool;
use PHPJava\Core\JVM\Intern\StringIntern;
use PHPJava\Core\JVM\MethodPool;
use PHPJava\Core\JVM\ConstantPool;
use PHPJava\Core\JVM\Parameters\GlobalOptions;
use PHPJava\Core\JVM\Parameters\Runtime;
use PHPJava\Core\JVM\Validations\MagicByte;
use PHPJava\Core\Stream\Reader\ReaderInterface;
use PHPJava\Exceptions\DebugTraceIsDisabledException;
use PHPJava\Exceptions\ValidatorException;
use PHPJava\Kernel\Attributes\AttributeInterface;
use PHPJava\Kernel\Attributes\InnerClassesAttribute;
use PHPJava\Kernel\Attributes\SourceFileAttribute;
use PHPJava\Kernel\Maps\FieldAccessFlag;
use PHPJava\Kernel\Provider\DependencyInjectionProvider;
use PHPJava\Kernel\Structures\_Utf8;
use PHPJava\Utilities\ClassResolver;
use PHPJava\Utilities\DebugTool;
Expand Down Expand Up @@ -63,9 +58,9 @@ class JavaClass implements JavaClassInterface
private $superClassIndex = 0;

/**
* @var _Utf8|null
* @var null|_Utf8
*/
private $className = null;
private $className;

private $debugTraces = [];

Expand All @@ -87,8 +82,6 @@ class JavaClass implements JavaClassInterface
private $startTime = 0.0;

/**
* @param ReaderInterface $reader
* @param array $options
* @throws ValidatorException
* @throws \PHPJava\Exceptions\ReadEntryException
* @throws \PHPJava\Exceptions\UnknownVersionException
Expand All @@ -113,7 +106,7 @@ public function __construct(ReaderInterface $reader, array $options = [])

$this->options['class_resolver']->add([
[ClassResolver::RESOURCE_TYPE_FILE, dirname($reader->getFileName())],
[ClassResolver::RESOURCE_TYPE_FILE, getcwd()]
[ClassResolver::RESOURCE_TYPE_FILE, getcwd()],
]);

// Debug tool
Expand Down Expand Up @@ -270,7 +263,6 @@ public function getClassName(bool $shortName = false): string
return $className;
}


public function getPackageName(): ?string
{
$className = dirname($this->className->getString());
Expand Down Expand Up @@ -337,7 +329,7 @@ public function debug(): void
$isEnabledTrace = $this->options['operations']['enable_trace'] ?? GlobalOptions::get('operations.enable_trace') ?? Runtime::OPERATIONS_ENABLE_TRACE;
if (!$isEnabledTrace) {
throw new DebugTraceIsDisabledException(
"Debug trace is disabled. If you want to show debug trace then enable to `enable_trace` option."
'Debug trace is disabled. If you want to show debug trace then enable to `enable_trace` option.'
);
}
$cpInfo = $this->getConstantPool();
Expand All @@ -360,7 +352,7 @@ function ($codes) use (&$codeCounter, &$debugTraces) {
function ($code) use (&$codeCounter, &$debugTraces) {
$isMnemonic = in_array($codeCounter, $debugTraces['mnemonic_indexes']);
$codeCounter++;
return ($isMnemonic ? "\e[1m\e[35m" : "") . "<0x{$code}>" . ($isMnemonic ? "\e[m" : "");
return ($isMnemonic ? "\e[1m\e[35m" : '') . "<0x{$code}>" . ($isMnemonic ? "\e[m" : '');
},
$codes
)
Expand All @@ -375,20 +367,20 @@ function ($code) use (&$codeCounter, &$debugTraces) {

printf(
"% 8s | %-6.6s | %-20.20s | %-10.10s | %-15.15s\n",
"PC",
"OPCODE",
"MNEMONIC",
"OPERANDS",
"LOCAL STORAGE"
'PC',
'OPCODE',
'MNEMONIC',
'OPERANDS',
'LOCAL STORAGE'
);

$line = sprintf(
"%8s+%8s+%22s+%12s+%17s\n",
"---------",
"--------",
"----------------------",
"------------",
"-----------------"
'---------',
'--------',
'----------------------',
'------------',
'-----------------'
);

printf($line);
Expand Down
Loading