Skip to content

Commit 75cdb6b

Browse files
author
Sanikovich Aleksey
authored
Merge pull request #48 from allok/8.0
PHP 8+ support
2 parents 820c38b + 21a0842 commit 75cdb6b

40 files changed

+224
-222
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
composer.lock
33
vendor/
44
phpunit.xml
5+
.phpunit.result.cache
56
Vagrantfile
67
puphpet/
78
.vagrant/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sudo: required
55
php:
66
- 7.1
77
- 7.2
8+
- 8.0
89
- nightly
910

1011
services:

composer.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@
1818
{
1919
"name": "Mitrofanov Nikolay",
2020
"email": "mitrofanovnk@yandex.ru"
21+
},
22+
{
23+
"name": "Sanikovich Aleksey",
24+
"email": "asanikovich@gmail.com"
2125
}
2226
],
2327
"require": {
24-
"php": "^7.1",
25-
"ext-PDO": "*",
28+
"php": "^7.1 || ^8.0",
29+
"ext-pdo": "*",
2630
"ext-pcre": "*",
2731
"doctrine/dbal": "^2.7",
28-
"smi2/phpClickHouse": "^1.0"
32+
"smi2/phpclickhouse": "^1.0"
2933
},
3034
"require-dev": {
31-
"doctrine/coding-standard": "^4.0",
32-
"phpunit/phpunit": "^7.0"
35+
"doctrine/coding-standard": "^4.0 || ^9.0",
36+
"phpunit/phpunit": "^7.0 || ^9.0"
3337
},
3438
"autoload": {
3539
"psr-4": {

src/ClickHouseConnection.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
1010
*
11-
* For the full copyright and license inflormation, please view the LICENSE
11+
* For the full copyright and license information, please view the LICENSE
1212
* file that was distributed with this source code.
1313
*/
1414

@@ -35,11 +35,6 @@ class ClickHouseConnection implements Connection, PingableConnection, ServerInfo
3535
/** @var AbstractPlatform */
3636
protected $platform;
3737

38-
/**
39-
* Connection constructor
40-
*
41-
* @param mixed[] $params
42-
*/
4338
public function __construct(
4439
array $params,
4540
string $username,
@@ -60,15 +55,15 @@ public function __construct(
6055
/**
6156
* {@inheritDoc}
6257
*/
63-
public function prepare($prepareString)
58+
public function prepare($prepareString) : ClickHouseStatement
6459
{
6560
return new ClickHouseStatement($this->smi2CHClient, $prepareString, $this->platform);
6661
}
6762

6863
/**
6964
* {@inheritDoc}
7065
*/
71-
public function query()
66+
public function query() : ClickHouseStatement
7267
{
7368
$args = func_get_args();
7469
$stmt = $this->prepare($args[0]);
@@ -105,73 +100,73 @@ public function exec($statement) : int
105100
*/
106101
public function lastInsertId($name = null)
107102
{
108-
throw new \LogicException('Unable to get last insert id in ClickHouse');
103+
throw ClickHouseException::notSupported('Unable to get last insert id in ClickHouse');
109104
}
110105

111106
/**
112107
* {@inheritDoc}
113108
*/
114-
public function beginTransaction()
109+
public function beginTransaction() : bool
115110
{
116-
throw new \LogicException('Transactions are not allowed in ClickHouse');
111+
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
117112
}
118113

119114
/**
120115
* {@inheritDoc}
121116
*/
122-
public function commit()
117+
public function commit() : bool
123118
{
124-
throw new \LogicException('Transactions are not allowed in ClickHouse');
119+
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
125120
}
126121

127122
/**
128123
* {@inheritDoc}
129124
*/
130-
public function rollBack()
125+
public function rollBack() : bool
131126
{
132-
throw new \LogicException('Transactions are not allowed in ClickHouse');
127+
throw ClickHouseException::notSupported('Transactions are not allowed in ClickHouse');
133128
}
134129

135130
/**
136131
* {@inheritDoc}
137132
*/
138-
public function errorCode()
133+
public function errorCode() : ?string
139134
{
140-
throw new \LogicException('You need to implement ClickHouseConnection::errorCode()');
135+
throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorCode()');
141136
}
142137

143138
/**
144139
* {@inheritDoc}
145140
*/
146-
public function errorInfo()
141+
public function errorInfo() : array
147142
{
148-
throw new \LogicException('You need to implement ClickHouseConnection::errorInfo()');
143+
throw ClickHouseException::notSupported('You need to implement ClickHouseConnection::errorInfo()');
149144
}
150145

151146
/**
152147
* {@inheritDoc}
153148
*/
154-
public function ping()
149+
public function ping() : bool
155150
{
156151
return $this->smi2CHClient->ping();
157152
}
158153

159154
/**
160155
* {@inheritDoc}
161156
*/
162-
public function getServerVersion()
157+
public function getServerVersion() : string
163158
{
164159
try {
165160
return $this->smi2CHClient->getServerVersion();
166-
} catch (TransportException $exception) {
161+
} catch (TransportException $e) {
167162
return '';
168163
}
169164
}
170165

171166
/**
172167
* {@inheritDoc}
173168
*/
174-
public function requiresQueryForServerVersion()
169+
public function requiresQueryForServerVersion() : bool
175170
{
176171
return true;
177172
}

src/ClickHouseException.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@
88
*
99
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
1010
*
11-
* For the full copyright and license inflormation, please view the LICENSE
11+
* For the full copyright and license information, please view the LICENSE
1212
* file that was distributed with this source code.
1313
*/
1414

1515
namespace FOD\DBALClickHouse;
1616

17+
use Doctrine\DBAL\Exception;
18+
1719
/**
1820
* Specific Exception for ClickHouse
1921
*/
20-
class ClickHouseException extends \Exception
22+
class ClickHouseException extends Exception
2123
{
24+
public static function notSupported($method) : ClickHouseException
25+
{
26+
return new self(sprintf("Operation '%s' is not supported by platform.", $method));
27+
}
2228
}

src/ClickHouseKeywords.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* (c) FriendsOfDoctrine <https://github.com/FriendsOfDoctrine/>.
1010
*
11-
* For the full copyright and license inflormation, please view the LICENSE
11+
* For the full copyright and license information, please view the LICENSE
1212
* file that was distributed with this source code.
1313
*/
1414

0 commit comments

Comments
 (0)