Skip to content

Commit c603b8f

Browse files
authored
fix: Deprecation with PHP 8.1. Add git action check of PHP8.2 (#8)
* Fix php8.1 Deprecated * Fix Deprecated with php8.1 * Update README.md * Fix error of php8.2 * Add phpcs, and fix CS. * Update badge * Fix action checking * Fix action checking * Fix action checking * Fix action checking
1 parent a3462d9 commit c603b8f

Some content is hidden

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

67 files changed

+457
-355
lines changed

.github/workflows/tests.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
strategy:
2424
matrix:
25-
php: [ '7.3', '7.4', '8.0', '8.1' ]
25+
php: [ '7.3', '7.4', '8.0', '8.1', '8.2']
2626

2727
steps:
2828
- name: Checkout
@@ -39,6 +39,7 @@ jobs:
3939
uses: shivammathur/setup-php@v2
4040
with:
4141
php-version: ${{ matrix.php }}
42+
ini-values: error_reporting=E_ALL, display_errors=On
4243
coverage: xdebug
4344

4445
- name: Validate composer.json and composer.lock
@@ -59,3 +60,17 @@ jobs:
5960

6061
- name: Run tests
6162
run: vendor/bin/phpunit --coverage-text
63+
64+
- name: CS Check
65+
if: ${{ matrix.php == '8.2' }}
66+
run: ./vendor/bin/phpcs
67+
68+
- name: Upload coverage to coveralls.io
69+
if: ${{ matrix.php == '8.2' }}
70+
env:
71+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
run: |
73+
composer require "php-coveralls/php-coveralls:^2" --dev -W
74+
ls ./vendor/bin
75+
./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
76+
./vendor/bin/php-coveralls -v

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ php-mysql-replication
44
[![Latest Stable Version](https://poser.pugx.org/moln/php-mysql-replication/v/stable)](https://packagist.org/packages/moln/php-mysql-replication) [![Total Downloads](https://poser.pugx.org/moln/php-mysql-replication/downloads)](https://packagist.org/packages/moln/php-mysql-replication)
55
[![License](https://poser.pugx.org/moln/php-mysql-replication/license)](https://packagist.org/packages/moln/php-mysql-replication)
66
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/moln/php-mysql-replication/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/moln/php-mysql-replication/?branch=master)
7-
[![Code Coverage](https://scrutinizer-ci.com/g/Moln/php-mysql-replication/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Moln/php-mysql-replication/?branch=master)
7+
[![Coverage Status](https://coveralls.io/repos/github/Moln/php-mysql-replication/badge.svg?branch=master)](https://coveralls.io/github/Moln/php-mysql-replication?branch=master)
88

99
Pure PHP Implementation of MySQL replication protocol. This allow you to receive event like insert, update, delete with their data and raw SQL queries.
1010

@@ -23,6 +23,7 @@ Based on a great work of creators:https://github.com/noplay/python-mysql-repli
2323
->withRetry(0) // Disable retry feature. (Default)
2424
->withRetry(2) // Retry twice.
2525
```
26+
- PHP 8.1,8.2 supports.
2627
--------------------------------------------------
2728

2829

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"require-dev": {
2626
"monolog/monolog": "^2.8",
27-
"phpunit/phpunit": "^9.0"
27+
"phpunit/phpunit": "^9.0",
28+
"slevomat/coding-standard": "^7.0"
2829
},
2930
"license": "MIT",
3031
"authors": [
@@ -45,7 +46,10 @@
4546
},
4647
"minimum-stability": "stable",
4748
"config": {
48-
"sort-packages": true
49+
"sort-packages": true,
50+
"allow-plugins": {
51+
"dealerdirect/phpcodesniffer-composer-installer": true
52+
}
4953
},
5054
"conflict": {
5155
"krowinski/php-mysql-replication": "*"

phpcs.xml.dist

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Coding Standard">
3+
<!-- Paths to check -->
4+
<file>src</file>
5+
<file>tests</file>
6+
7+
<!-- display progress -->
8+
<arg value="p"/>
9+
<arg name="no-colors"/>
10+
11+
<!-- inherit rules from: -->
12+
<rule ref="PSR2"/>
13+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
14+
<rule ref="Generic.Formatting.SpaceAfterNot"/>
15+
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
16+
<properties>
17+
<property name="ignoreNewlines" value="true"/>
18+
</properties>
19+
</rule>
20+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
21+
<properties>
22+
<property name="ignoreBlankLines" value="false"/>
23+
</properties>
24+
</rule>
25+
<rule ref="Squiz.NamingConventions.ValidVariableName">
26+
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
27+
</rule>
28+
29+
<rule ref="Squiz.Strings.ConcatenationSpacing" >
30+
<properties>
31+
<property name="spacing" value="1" />
32+
<property name="ignoreNewlines" value="true" />
33+
</properties>
34+
</rule>
35+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing" />
36+
37+
<config name="installed_paths" value="vendor/slevomat/coding-standard/SlevomatCodingStandard"/>
38+
39+
<rule ref="Generic.Files.LineLength">
40+
<exclude name="Generic.Files.LineLength.TooLong"/>
41+
</rule>
42+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />-->
43+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing" />-->
44+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />-->
45+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing" />-->
46+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing" />-->
47+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint" >-->
48+
<!-- <exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification" />-->
49+
<!-- </rule>-->
50+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint" />-->
51+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">-->
52+
<!-- <exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification" />-->
53+
<!-- </rule>-->
54+
<!-- <rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint" >-->
55+
<!-- <exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification" />-->
56+
<!-- </rule>-->
57+
<!-- <rule ref="SlevomatCodingStandard.Namespaces.UnusedUses" />-->
58+
59+
</ruleset>

src/MySQLReplication/BinLog/BinLogCurrent.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public function setMariaDbGtid(string $mariaDbGtid): void
6464
$this->mariaDbGtid = $mariaDbGtid;
6565
}
6666

67+
#[\ReturnTypeWillChange]
6768
public function jsonSerialize()
6869
{
6970
return get_object_vars($this);
7071
}
71-
}
72+
}

src/MySQLReplication/BinLog/BinLogException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
class BinLogException extends MySQLReplicationException
99
{
10-
}
10+
}

src/MySQLReplication/BinLog/BinLogServerInfo.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,21 @@ public static function parsePackage(string $data, string $version): BinLogServer
6161
$i += 2;
6262

6363
//auth_plugin_data_len (1) -- length of the combined auth_plugin_data, if auth_plugin_data_len is > 0
64-
$salt_len = ord($data[$i]);
64+
$saltLen = ord($data[$i]);
6565
++$i;
6666

67-
$salt_len = max(12, $salt_len - 9);
67+
$saltLen = max(12, $saltLen - 9);
6868

6969
$i += 10;
7070

7171
//next salt
72-
if ($length >= $i + $salt_len) {
73-
for ($j = $i; $j < $i + $salt_len; ++$j) {
72+
if ($length >= $i + $saltLen) {
73+
for ($j = $i; $j < $i + $saltLen; ++$j) {
7474
$serverInfo['salt'] .= $data[$j];
7575
}
76-
7776
}
7877
$serverInfo['auth_plugin_name'] = '';
79-
$i += $salt_len + 1;
78+
$i += $saltLen + 1;
8079
for ($j = $i; $j < $length - 1; ++$j) {
8180
$serverInfo['auth_plugin_name'] .= $data[$j];
8281
}
@@ -143,4 +142,4 @@ private static function parseRevision(string $version): float
143142
{
144143
return (float)$version;
145144
}
146-
}
145+
}

src/MySQLReplication/BinLog/BinLogSocketConnect.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function __construct(
5151
$this->repository = $repository;
5252
$this->socket = $socket;
5353
$this->binLogCurrent = new BinLogCurrent();
54-
5554
}
5655

5756
public function isConnected(): bool
@@ -101,8 +100,8 @@ public function getResponse(bool $checkResponse = true): string
101100
}
102101
$dataLength = unpack('L', $header[0] . $header[1] . $header[2] . chr(0))[1];
103102
$isMaxDataLength = $dataLength === $this->binaryDataMaxLength;
104-
$next_result = $this->socket->readFromSocket($dataLength);
105-
$result .= $next_result;
103+
$nextResult = $this->socket->readFromSocket($dataLength);
104+
$result .= $nextResult;
106105
}
107106

108107
return $result;
@@ -114,7 +113,7 @@ public function getResponse(bool $checkResponse = true): string
114113
private function isWriteSuccessful(string $data): void
115114
{
116115
$head = ord($data[0]);
117-
if (!in_array($head, $this->packageOkHeader, true)) {
116+
if (! in_array($head, $this->packageOkHeader, true)) {
118117
$errorCode = unpack('v', $data[1] . $data[2])[1];
119118
$errorMessage = '';
120119
$packetLength = strlen($data);
@@ -140,8 +139,9 @@ private function authenticate(): void
140139
$data .= chr(0);
141140
}
142141
$result = sha1($this->config->getPassword(), true) ^ sha1(
143-
$this->binLogServerInfo->getSalt() . sha1(sha1($this->config->getPassword(), true), true), true
144-
);
142+
$this->binLogServerInfo->getSalt() . sha1(sha1($this->config->getPassword(), true), true),
143+
true
144+
);
145145

146146
$data = $data . $this->config->getUser() . chr(0) . chr(strlen($result)) . $result;
147147
$str = pack('L', strlen($data));

src/MySQLReplication/BinaryDataReader/BinaryDataReader.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ public function __construct(string $data)
3636
public static function pack64bit(int $value): string
3737
{
3838
return pack(
39-
'C8', ($value >> 0) & 0xFF, ($value >> 8) & 0xFF, ($value >> 16) & 0xFF, ($value >> 24) & 0xFF,
40-
($value >> 32) & 0xFF, ($value >> 40) & 0xFF, ($value >> 48) & 0xFF, ($value >> 56) & 0xFF
39+
'C8',
40+
($value >> 0) & 0xFF,
41+
($value >> 8) & 0xFF,
42+
($value >> 16) & 0xFF,
43+
($value >> 24) & 0xFF,
44+
($value >> 32) & 0xFF,
45+
($value >> 40) & 0xFF,
46+
($value >> 48) & 0xFF,
47+
($value >> 56) & 0xFF
4148
);
4249
}
4350

@@ -282,7 +289,7 @@ public function readTableId(): string
282289

283290
public function isComplete(int $size): bool
284291
{
285-
return !($this->readBytes - 20 < $size);
292+
return ! ($this->readBytes - 20 < $size);
286293
}
287294

288295
public function getBinaryDataLength(): int
@@ -307,4 +314,4 @@ public function getReadBytes(): int
307314
{
308315
return $this->readBytes;
309316
}
310-
}
317+
}

src/MySQLReplication/BinaryDataReader/BinaryDataReaderException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
class BinaryDataReaderException extends MySQLReplicationException
99
{
10-
}
10+
}

src/MySQLReplication/Cache/ArrayCache.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Composer\InstalledVersions;
77
use Psr\SimpleCache\CacheInterface;
88

9+
// phpcs:ignoreFile
910
if (class_exists(InstalledVersions::class) && version_compare(InstalledVersions::getVersion("psr/simple-cache"), '3.0.0', ">=")) {
1011
class ArrayCache implements CacheInterface
1112
{
@@ -64,7 +65,8 @@ public function getMultiple($keys, $default = null)
6465
}
6566
}
6667

67-
trait ArrayCacheTrait {
68+
trait ArrayCacheTrait
69+
{
6870
private $tableMapCache = [];
6971

7072
/**

src/MySQLReplication/Config/Config.php

+27-17
Original file line numberDiff line numberDiff line change
@@ -71,46 +71,55 @@ public function __construct(
7171
*/
7272
public function validate(): void
7373
{
74-
if (!empty($this->host)) {
74+
if (! empty($this->host)) {
7575
$ip = gethostbyname($this->host);
7676
if (false === filter_var($ip, FILTER_VALIDATE_IP)) {
7777
throw new ConfigException(ConfigException::IP_ERROR_MESSAGE, ConfigException::IP_ERROR_CODE);
7878
}
7979
}
80-
if (!empty($this->port) && false === filter_var(
81-
$this->port, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]
82-
)) {
80+
if (! empty($this->port) && false === filter_var(
81+
$this->port,
82+
FILTER_VALIDATE_INT,
83+
['options' => ['min_range' => 0]]
84+
)) {
8385
throw new ConfigException(ConfigException::PORT_ERROR_MESSAGE, ConfigException::PORT_ERROR_CODE);
8486
}
85-
if (!empty($this->gtid)) {
87+
if (! empty($this->gtid)) {
8688
foreach (explode(',', $this->gtid) as $gtid) {
87-
if (!(bool)preg_match(
88-
'/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/', $gtid, $matches
89+
if (! (bool)preg_match(
90+
'/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/',
91+
$gtid,
92+
$matches
8993
)) {
9094
throw new ConfigException(ConfigException::GTID_ERROR_MESSAGE, ConfigException::GTID_ERROR_CODE);
9195
}
9296
}
9397
}
94-
if (!empty($this->slaveId) && false === filter_var(
95-
$this->slaveId, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]]
96-
)) {
98+
if (! empty($this->slaveId) && false === filter_var(
99+
$this->slaveId,
100+
FILTER_VALIDATE_INT,
101+
['options' => ['min_range' => 0]]
102+
)) {
97103
throw new ConfigException(ConfigException::SLAVE_ID_ERROR_MESSAGE, ConfigException::SLAVE_ID_ERROR_CODE);
98104
}
99105
if (false === filter_var($this->binLogPosition, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
100106
throw new ConfigException(
101-
ConfigException::BIN_LOG_FILE_POSITION_ERROR_MESSAGE, ConfigException::BIN_LOG_FILE_POSITION_ERROR_CODE
107+
ConfigException::BIN_LOG_FILE_POSITION_ERROR_MESSAGE,
108+
ConfigException::BIN_LOG_FILE_POSITION_ERROR_CODE
102109
);
103110
}
104111
if (false === filter_var($this->tableCacheSize, FILTER_VALIDATE_INT, ['options' => ['min_range' => 0]])) {
105112
throw new ConfigException(
106-
ConfigException::TABLE_CACHE_SIZE_ERROR_MESSAGE, ConfigException::TABLE_CACHE_SIZE_ERROR_CODE
113+
ConfigException::TABLE_CACHE_SIZE_ERROR_MESSAGE,
114+
ConfigException::TABLE_CACHE_SIZE_ERROR_CODE
107115
);
108116
}
109117
if (0.0 !== $this->heartbeatPeriod && false === (
110118
$this->heartbeatPeriod >= 0.001 && $this->heartbeatPeriod <= 4294967.0
111119
)) {
112120
throw new ConfigException(
113-
ConfigException::HEARTBEAT_PERIOD_ERROR_MESSAGE, ConfigException::HEARTBEAT_PERIOD_ERROR_CODE
121+
ConfigException::HEARTBEAT_PERIOD_ERROR_MESSAGE,
122+
ConfigException::HEARTBEAT_PERIOD_ERROR_CODE
114123
);
115124
}
116125
}
@@ -177,7 +186,7 @@ public function getTableCacheSize(): int
177186

178187
public function checkDataBasesOnly(string $database): bool
179188
{
180-
return [] !== $this->getDatabasesOnly() && !self::matchNames($database, $this->getDatabasesOnly());
189+
return [] !== $this->getDatabasesOnly() && ! self::matchNames($database, $this->getDatabasesOnly());
181190
}
182191

183192
public function getDatabasesOnly(): array
@@ -187,7 +196,7 @@ public function getDatabasesOnly(): array
187196

188197
public function checkTablesOnly(string $table): bool
189198
{
190-
return [] !== $this->getTablesOnly() && !self::matchNames($table, $this->getTablesOnly());
199+
return [] !== $this->getTablesOnly() && ! self::matchNames($table, $this->getTablesOnly());
191200
}
192201

193202
private static function matchNames(string $subject, array $names): bool
@@ -208,7 +217,7 @@ public function getTablesOnly(): array
208217

209218
public function checkEvent(int $type): bool
210219
{
211-
if ([] !== $this->getEventsOnly() && !in_array($type, $this->getEventsOnly(), true)) {
220+
if ([] !== $this->getEventsOnly() && ! in_array($type, $this->getEventsOnly(), true)) {
212221
return false;
213222
}
214223

@@ -239,8 +248,9 @@ public function getRetry(): int
239248
return $this->retry;
240249
}
241250

251+
#[\ReturnTypeWillChange]
242252
public function jsonSerialize()
243253
{
244254
return get_object_vars($this);
245255
}
246-
}
256+
}

0 commit comments

Comments
 (0)