Skip to content

Commit 065861e

Browse files
committed
Update code linting
1 parent 108471d commit 065861e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+242
-229
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v3
1111
- uses: php-actions/composer@v6
12-
12+
13+
- name: Lint
14+
run: composer run lint
15+
1316
- name: Phpstan
1417
run: composer run phpstan
1518

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ composer.lock
55
phpunit-report
66
phpDocumentor.phar
77
.phpdoc
8+
.php-cs-fixer.cache

.php-cs-fixer.php

+38-53
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,82 @@
11
<?php
22

3-
return (new PhpCsFixer\Config())->setRules([
3+
declare(strict_types=1);
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in(__DIR__)
7+
->name('*.php')
8+
->notPath('/^vendor\//')
9+
;
10+
11+
$config = new PhpCsFixer\Config();
12+
13+
return $config->setRules([
414
'@PSR2' => false,
15+
'declare_strict_types' => true,
516
'array_indentation' => true,
617
'array_syntax' => [
7-
'syntax' => 'short',
18+
'syntax' => 'short', // short array() => [] , long [] => array()
819
],
920
'blank_line_after_namespace' => true,
1021
'blank_line_after_opening_tag' => true,
11-
'blank_line_before_statement' => [
12-
'statements' => [
13-
'declare',
14-
'default',
15-
'exit',
16-
'goto',
17-
'include',
18-
'include_once',
19-
'phpdoc',
20-
'require',
21-
'require_once',
22-
'return',
23-
'switch',
24-
'try',
25-
'yield',
26-
'yield_from',
27-
],
28-
],
29-
'braces' => [
30-
'allow_single_line_closure' => true,
31-
'position_after_functions_and_oop_constructs' => 'same',
22+
'blank_line_before_statement' => true, // blank before return, try, break, continue
23+
'single_space_around_construct' => true,
24+
'control_structure_braces' => true,
25+
'control_structure_continuation_position' => true,
26+
'declare_parentheses' => true,
27+
'no_multiple_statements_per_line' => true,
28+
'braces_position' => [
29+
'functions_opening_brace' => 'same_line',
30+
'classes_opening_brace' => 'same_line',
3231
],
32+
'statement_indentation' => true,
33+
'no_extra_blank_lines' => true,
3334
'cast_spaces' => true,
3435
'class_definition' => [
3536
'single_line' => false,
3637
],
3738
'clean_namespace' => true,
3839
'combine_consecutive_issets' => false,
39-
'combine_consecutive_unsets' => false,
40-
'concat_space' => ['spacing' => 'one'],
41-
'constant_case' => true,
40+
'combine_consecutive_unsets' => false, // unset($a); unset($b); => unset($a, $b);
41+
'concat_space' => ['spacing' => 'one'], // $foo = 'bar' . 3 . 'baz' . 'qux';
42+
'constant_case' => true, // nuLL, FALSE, True => null, false, true
4243
'elseif' => true,
4344
'encoding' => true,
44-
'function_typehint_space' => true,
45-
'include' => true,
45+
'type_declaration_spaces' => ['elements' => ['function', 'property']],
46+
'include' => true, // include("sample.php"); => include_once "sample.php"
4647
'indentation_type' => true,
4748
'linebreak_after_opening_tag' => true,
4849
'list_syntax' => ['syntax' => 'short'],
49-
'lowercase_cast' => true,
50-
'lowercase_keywords' => true,
50+
'lowercase_cast' => true, // (InTegEr),(BOOLEAN), => (integer),(boolean)
51+
'lowercase_keywords' => true, // WHILE, FOREACH => while, foreach
5152
'lowercase_static_reference' => true,
5253
'magic_constant_casing' => true,
5354
'magic_method_casing' => true,
5455
'native_function_casing' => true,
55-
'native_function_type_declaration_casing' => true,
56+
'native_type_declaration_casing' => true,
5657
'no_blank_lines_after_class_opening' => true,
5758
'no_empty_statement' => true,
5859
'no_leading_import_slash' => true,
5960
'no_mixed_echo_print' => ['use' => 'echo'],
6061
'no_spaces_after_function_name' => true,
6162
'no_spaces_around_offset' => true,
62-
'no_spaces_inside_parenthesis' => true,
63+
'spaces_inside_parentheses' => ['space' => 'none'],
6364
'no_trailing_whitespace' => true,
6465
'no_whitespace_in_blank_line' => true,
6566
'operator_linebreak' => ['only_booleans' => true],
66-
'ordered_class_elements' => [
67-
'order' => [
68-
'use_trait',
69-
'case',
70-
'constant_public',
71-
'constant_protected',
72-
'constant_private',
73-
'property_public',
74-
'property_protected',
75-
'property_private',
76-
'construct',
77-
'destruct',
78-
'magic',
79-
'phpunit',
80-
'method_abstract',
81-
'method_public',
82-
'method_protected',
83-
'method_private',
84-
],
85-
'sort_algorithm' => 'alpha',
86-
],
67+
'ordered_class_elements' => ['sort_algorithm' => 'alpha'],
8768
'short_scalar_cast' => true,
8869
'single_blank_line_at_eof' => true,
8970
'single_class_element_per_statement' => ['elements' => ['const', 'property']],
9071
'single_quote' => true,
9172
'ternary_operator_spaces' => true,
9273
'trailing_comma_in_multiline' => true,
9374
'whitespace_after_comma_in_array' => true,
75+
'visibility_required' => true,
76+
'return_type_declaration'=> ['space_before' => 'none'],
9477
])
9578
->setIndent(' ')
9679
->setLineEnding("\n")
80+
->setFinder($finder)
81+
->setRiskyAllowed(true)
9782
;

composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"vimeo/psalm": "^5.24.0"
4444
},
4545
"scripts": {
46+
"lint": "vendor/bin/php-cs-fixer check",
47+
"lint-fix": "vendor/bin/php-cs-fixer fix",
4648
"phpstan": "vendor/bin/phpstan analyse",
4749
"psalm": "vendor/bin/psalm --no-cache",
4850
"phpunit": "XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite php-cassandra $@"

debug/debug-db.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Cassandra\Connection;
46
use Cassandra\Type;
57

@@ -66,7 +68,6 @@
6668
#var_dump(Type\Duration::parse(Type\Duration::binary(['months' => 1, 'days' => 2, 'nanoseconds'=> 3])));
6769
#var_dump(Type\Duration::parse(Type\Duration::binary(['months' => 223231, 'days' => 277756, 'nanoseconds'=> 320688000000000])));
6870

69-
7071
#var_dump(Type\Duration::parse(Type\Duration::binary(['months' => 2147483647, 'days' => 2147483647, 'nanoseconds'=> PHP_INT_MAX])));
7172
#var_dump(Type\Duration::parse(Type\Duration::binary(['months' => -2147483648, 'days' => -2147483648, 'nanoseconds'=> PHP_INT_MIN])));
7273

@@ -163,7 +164,6 @@
163164
var_dump(Type\Varint::fromBinary((new Type\Varint($varInt))->getBinary())->__toString());
164165
#var_dump(binaryToString(stringToBinary($varInt)));
165166

166-
167167
$varInt = (string) PHP_INT_MAX . (string) PHP_INT_MAX;
168168

169169
var_dump(Type\Varint::fromBinary((new Type\Varint($varInt))->getBinary())->__toString());

debug/debug-db2.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
require __DIR__ . '/../php-cassandra.php';
46

57
use Cassandra\Connection;
@@ -104,7 +106,6 @@
104106
*/
105107
// SELECT * FROM test.test2;
106108

107-
108109
$result1 = $connection->querySync('SELECT * FROM test.test1');
109110
$data1 = $result1->fetchAll();
110111

debug/debug-events.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
require __DIR__ . '/../php-cassandra.php';
46

57
$nodes =[
@@ -19,7 +21,6 @@
1921
$connection = new \Cassandra\Connection($nodes, $keyspace, ['COMPRESSION' => 'lz4']);
2022
$connection->connect();
2123

22-
2324
$connection->addEventListener(new class() implements \Cassandra\EventListener {
2425
public function onEvent(\Cassandra\Response\Event $event): void {
2526
var_dump($event->getData());

debug/debug-lz4.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
require __DIR__ . '/../php-cassandra.php';
46

57
$lz4d = new \Cassandra\Compression\Lz4Decompressor(file_get_contents('lz4-1.bin'));

src/Connection/FrameCodec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use Cassandra\Request\Request;
99

1010
class FrameCodec implements Node {
11-
public final const CRC24_INIT = 0x875060;
12-
public final const CRC24_POLYNOMIAL = 0x1974F0B;
13-
public final const PAYLOAD_MAX_SIZE = 131071;
11+
final public const CRC24_INIT = 0x875060;
12+
final public const CRC24_POLYNOMIAL = 0x1974F0B;
13+
final public const PAYLOAD_MAX_SIZE = 131071;
1414

1515
protected string $compression;
1616

src/Connection/Socket.php

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ protected function connect(): PhpSocket {
219219
$result = socket_connect($this->socket, $this->options['host'] ?? 'localhost', $this->options['port']);
220220
if ($result === false) {
221221
$errorCode = socket_last_error($this->socket);
222+
222223
//Unable to connect to Cassandra node: {$this->options['host']}:{$this->options['port']}
223224
throw new SocketException(socket_strerror($errorCode), $errorCode);
224225
}

src/Connection/Stream.php

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function __construct(array $options) {
6868
throw new StreamException('persistent must be a bool value');
6969
}
7070

71-
7271
if (!isset($options['ssl']) || !is_array($options['ssl'])) {
7372
$options['ssl'] = [];
7473
} else {

src/Exception.php

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Exception extends PhpException {
1313
*/
1414
protected array $context;
1515

16-
1716
/**
1817
* @param array<string, string|int|array<int|string, int|string>> $context
1918
*/

src/Protocol/Flag.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Cassandra\Protocol;
66

77
interface Flag {
8-
public final const COMPRESSION = 0x01; // deprecated in v5
9-
public final const CUSTOM_PAYLOAD = 0x04;
10-
public final const TRACING = 0x02;
11-
public final const USE_BETA = 0x10;
12-
public final const WARNING = 0x08;
8+
final public const COMPRESSION = 0x01; // deprecated in v5
9+
final public const CUSTOM_PAYLOAD = 0x04;
10+
final public const TRACING = 0x02;
11+
final public const USE_BETA = 0x10;
12+
final public const WARNING = 0x08;
1313
}

src/Protocol/Opcode.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
namespace Cassandra\Protocol;
66

77
interface Opcode {
8-
public final const REQUEST_AUTH_RESPONSE = 0x0F;
9-
public final const REQUEST_BATCH = 0x0D;
10-
public final const REQUEST_EXECUTE = 0x0A;
11-
public final const REQUEST_OPTIONS = 0x05;
12-
public final const REQUEST_PREPARE = 0x09;
13-
public final const REQUEST_QUERY = 0x07;
14-
public final const REQUEST_REGISTER = 0x0B;
15-
public final const REQUEST_STARTUP = 0x01;
8+
final public const REQUEST_AUTH_RESPONSE = 0x0F;
9+
final public const REQUEST_BATCH = 0x0D;
10+
final public const REQUEST_EXECUTE = 0x0A;
11+
final public const REQUEST_OPTIONS = 0x05;
12+
final public const REQUEST_PREPARE = 0x09;
13+
final public const REQUEST_QUERY = 0x07;
14+
final public const REQUEST_REGISTER = 0x0B;
15+
final public const REQUEST_STARTUP = 0x01;
1616

17-
public final const RESPONSE_AUTH_CHALLENGE = 0x0E;
18-
public final const RESPONSE_AUTH_SUCCESS = 0x10;
19-
public final const RESPONSE_AUTHENTICATE = 0x03;
20-
public final const RESPONSE_CREDENTIALS = 0x04;
21-
public final const RESPONSE_ERROR = 0x00;
22-
public final const RESPONSE_EVENT = 0x0C;
23-
public final const RESPONSE_READY = 0x02;
24-
public final const RESPONSE_RESULT = 0x08;
25-
public final const RESPONSE_SUPPORTED = 0x06;
17+
final public const RESPONSE_AUTH_CHALLENGE = 0x0E;
18+
final public const RESPONSE_AUTH_SUCCESS = 0x10;
19+
final public const RESPONSE_AUTHENTICATE = 0x03;
20+
final public const RESPONSE_CREDENTIALS = 0x04;
21+
final public const RESPONSE_ERROR = 0x00;
22+
final public const RESPONSE_EVENT = 0x0C;
23+
final public const RESPONSE_READY = 0x02;
24+
final public const RESPONSE_RESULT = 0x08;
25+
final public const RESPONSE_SUPPORTED = 0x06;
2626
}

src/Request/Batch.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use Cassandra\Response\Result;
1111

1212
class Batch extends Request {
13-
public final const TYPE_COUNTER = 2;
14-
public final const TYPE_LOGGED = 0;
15-
public final const TYPE_UNLOGGED = 1;
13+
final public const TYPE_COUNTER = 2;
14+
final public const TYPE_LOGGED = 0;
15+
final public const TYPE_UNLOGGED = 1;
1616

1717
protected int $batchType;
1818

src/Request/Prepare.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Cassandra\Protocol\Opcode;
88

99
class Prepare extends Request {
10-
public final const FLAG_WITH_KEYSPACE = 0x01;
10+
final public const FLAG_WITH_KEYSPACE = 0x01;
1111

1212
protected string $cql;
1313

src/Request/Query.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
use Cassandra\Protocol\Opcode;
88

99
class Query extends Request {
10-
public final const FLAG_PAGE_SIZE = 0x04;
11-
public final const FLAG_SKIP_METADATA = 0x02;
12-
public final const FLAG_VALUES = 0x01;
13-
public final const FLAG_WITH_DEFAULT_TIMESTAMP = 0x20;
14-
public final const FLAG_WITH_KEYSPACE = 0x80;
15-
public final const FLAG_WITH_NAMES_FOR_VALUES = 0x40;
16-
public final const FLAG_WITH_NOW_IN_SECONDS = 0x0100;
17-
public final const FLAG_WITH_PAGING_STATE = 0x08;
18-
public final const FLAG_WITH_SERIAL_CONSISTENCY = 0x10;
10+
final public const FLAG_PAGE_SIZE = 0x04;
11+
final public const FLAG_SKIP_METADATA = 0x02;
12+
final public const FLAG_VALUES = 0x01;
13+
final public const FLAG_WITH_DEFAULT_TIMESTAMP = 0x20;
14+
final public const FLAG_WITH_KEYSPACE = 0x80;
15+
final public const FLAG_WITH_NAMES_FOR_VALUES = 0x40;
16+
final public const FLAG_WITH_NOW_IN_SECONDS = 0x0100;
17+
final public const FLAG_WITH_PAGING_STATE = 0x08;
18+
final public const FLAG_WITH_SERIAL_CONSISTENCY = 0x10;
1919

2020
protected int $consistency;
2121

0 commit comments

Comments
 (0)