Skip to content

Commit a90a5cc

Browse files
committed
Add PHPCS and Fix for rules
1 parent 34cf92f commit a90a5cc

8 files changed

Lines changed: 34 additions & 12 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ composer.lock
77
.phpunit.result.cache
88
tests/caches/
99
!tests/caches/.gitkeep
10-
.php_cs.cache

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ public static void main(java.lang.String[])
294294
./vendor/bin/phpunit tests
295295
```
296296

297-
- PHPCS is below.
297+
- PHP Coding standards testing is below.
298+
299+
```
300+
./vendor/bin/phpcs --standard=phpcs.xml src
301+
```
298302

299303
## Reference
300304
- [Java Virtual Machine Specification](https://docs.oracle.com/javase/specs/jvms/se11/html/index.html)

phpcs.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<ruleset name="PHPJava Standards">
2+
<description>The PHPJava Coding Standards</description>
3+
4+
<exclude-pattern>./tests</exclude-pattern>
5+
6+
<rule ref="PSR2">
7+
<exclude name="Generic.Files.LineLength.TooLong"/>
8+
</rule>
9+
10+
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
11+
<exclude-pattern>./src/kernel/types</exclude-pattern>
12+
<exclude-pattern>./src/kernel/mnemonics</exclude-pattern>
13+
<exclude-pattern>./src/kernel/structures</exclude-pattern>
14+
<exclude-pattern>./src/imitation/java/lang/_Object.php</exclude-pattern>
15+
<exclude-pattern>./src/imitation/java/lang/_String.php</exclude-pattern>
16+
<exclude-pattern>./src/imitation/phpjava/extended/_Object</exclude-pattern>
17+
</rule>
18+
19+
<rule ref="Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase">
20+
<exclude-pattern>./src/kernel/maps</exclude-pattern>
21+
</rule>
22+
23+
<arg name="colors"/>
24+
<arg value="p"/>
25+
26+
<ini name="memory_limit" value="128M"/>
27+
</ruleset>

src/imitation/java/io/PrintStream.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public function println($arg)
1313
echo $arg->getString() . "\n";
1414
return;
1515
}
16-
if (
17-
is_string($arg) ||
16+
if (is_string($arg) ||
1817
is_int($arg) ||
1918
$arg instanceof Type ||
2019
$arg instanceof \PHPJava\Imitation\java\lang\_String
@@ -32,8 +31,7 @@ public function print($arg)
3231
echo $arg->getString();
3332
return;
3433
}
35-
if (
36-
is_string($arg) ||
34+
if (is_string($arg) ||
3735
is_int($arg) ||
3836
$arg instanceof Type ||
3937
$arg instanceof \PHPJava\Imitation\java\lang\_String

src/kernel/mnemonics/_getstatic.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public function execute(): void
2323
if ($cp instanceof _Fieldref) {
2424
foreach ($this->javaClass->getFields() as $field) {
2525
if ($cpInfo[$field->getNameIndex()]->getString() === $cpInfo[$cpInfo[$cp->getNameAndTypeIndex()]->getNameIndex()]->getString()) {
26-
2726
// push stack
2827
$fieldName = $cpInfo[$field->getNameIndex()]->getString();
2928
$this->pushStack($this->javaClassInvoker->getStaticFields()->get($fieldName));

src/kernel/mnemonics/_lookupswitch.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function execute(): void
2929
}
3030

3131
if (isset($offsets[$key])) {
32-
3332
// goto PC
3433
$this->setOffset($this->getProgramCounter() + $offsets[$key]);
3534
return;

src/kernel/mnemonics/_tableswitch.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ public function execute(): void
2828
}
2929

3030
if (isset($offsets[$key])) {
31-
3231
// goto PC
3332
$this->setOffset($this->getProgramCounter() + $offsets[$key]);
3433
return;
3534
}
3635

37-
3836
// goto default
3937
$this->setOffset($this->getProgramCounter() + $offsets['default']);
4038
}

src/utilities/BinaryTool.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ final public static function addOneBit($bits)
3333
$bitSize = strlen($bits);
3434

3535
for ($index = $bitSize - 1; $index >= 0 && $bits[$index] === '1'; $index--) {
36-
3736
// nop
3837
}
3938

@@ -70,7 +69,6 @@ final public static function negate($value, $bytes)
7069
$value = base_convert((string) $value, 10, 2);
7170

7271
if (sprintf('%0' . $bytes . 's', $value) === str_repeat('0', $bytes)) {
73-
7472
// zero number was overflow
7573
return '0';
7674
}

0 commit comments

Comments
 (0)