Skip to content

Commit 18cebb9

Browse files
committed
update dependency of phpClickHouse to ^0.18. cs fix
1 parent 6765448 commit 18cebb9

19 files changed

+267
-185
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
composer.lock
33
vendor/
44
phpunit.xml
5+
Vagrantfile
6+
puphpet/
7+
.vagrant/

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sudo: required
44

55
php:
66
- 7.1
7+
- 7.2
78
- nightly
89

910
services:

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
],
1515
"require": {
1616
"php": "^7.1",
17-
"smi2/phpClickHouse": "^0.17",
17+
"smi2/phpClickHouse": "^0.18",
1818
"doctrine/dbal": ">=2.6"
1919
},
2020
"autoload": {
@@ -24,6 +24,6 @@
2424
"psr-4": { "FOD\\DBALClickHouse\\Tests\\": "tests/" }
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^6.1"
27+
"phpunit/phpunit": "^7.0"
2828
}
2929
}

src/ClickHouseConnection.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ class ClickHouseConnection implements \Doctrine\DBAL\Driver\Connection
3535
/**
3636
* Connection constructor
3737
*
38-
* @param string $username The username to use when connecting.
39-
* @param string $password The password to use when connecting.
38+
* @param string $username The username to use when connecting.
39+
* @param string $password The password to use when connecting.
4040
* @param string $host
4141
* @param int $port
4242
* @param string $database
43+
* @param AbstractPlatform $platform
4344
*/
44-
public function __construct($username = 'default', $password = '', $host = 'localhost', $port = 8123, $database = 'default', AbstractPlatform $platform = null)
45-
{
45+
public function __construct(
46+
$username = 'default',
47+
$password = '',
48+
$host = 'localhost',
49+
$port = 8123,
50+
$database = 'default',
51+
AbstractPlatform $platform
52+
) {
4653
$this->smi2CHClient = new Smi2CHClient([
4754
'host' => $host,
4855
'port' => $port,
@@ -59,7 +66,7 @@ public function __construct($username = 'default', $password = '', $host = 'loca
5966
*/
6067
public function prepare($prepareString)
6168
{
62-
if (! $this->smi2CHClient) {
69+
if (!$this->smi2CHClient) {
6370
throw new \Exception('ClickHouse\Client was not initialized');
6471
}
6572

@@ -71,7 +78,7 @@ public function prepare($prepareString)
7178
*/
7279
public function query()
7380
{
74-
$args = func_get_args();
81+
$args = \func_get_args();
7582
$stmt = $this->prepare($args[0]);
7683
$stmt->execute();
7784

@@ -83,7 +90,7 @@ public function query()
8390
*/
8491
public function quote($input, $type = \PDO::PARAM_STR)
8592
{
86-
if (\PDO::PARAM_INT == $type) {
93+
if (\PDO::PARAM_INT === $type) {
8794
return $input;
8895
}
8996

@@ -148,5 +155,4 @@ public function errorInfo()
148155
{
149156
throw new \LogicException('You need to implement ClickHouseConnection::errorInfo()');
150157
}
151-
152-
}
158+
}

src/ClickHouseException.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
*
1717
* @author Mochalygin <[email protected]>
1818
*/
19-
class ClickHouseException extends \Exception {}
19+
class ClickHouseException extends \Exception
20+
{
21+
}

src/ClickHousePlatform.php

+64-39
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\DBALException;
1515

16+
use Doctrine\DBAL\Types\BlobType;
1617
use Doctrine\DBAL\Types\DecimalType;
1718
use Doctrine\DBAL\Types\FloatType;
1819
use Doctrine\DBAL\Types\StringType;
@@ -72,8 +73,9 @@ public function getSmallIntTypeDeclarationSQL(array $columnDef)
7273
*/
7374
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
7475
{
75-
if (! empty($columnDef['autoincrement']))
76+
if (!empty($columnDef['autoincrement'])) {
7677
throw new \Exception('Clickhouse do not support AUTO_INCREMENT fields');
78+
}
7779

7880
return empty($columnDef['unsigned']) ? '' : 'U';
7981
}
@@ -126,8 +128,8 @@ protected function initializeDoctrineTypeMappings()
126128
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
127129
{
128130
return $fixed
129-
? 'FixedString(' . $length . ')'
130-
: 'String';
131+
? 'FixedString(' . $length . ')'
132+
: 'String';
131133
}
132134

133135
/**
@@ -289,7 +291,7 @@ public function getNowExpression()
289291
*/
290292
public function getSubstringExpression($value, $from, $length = null)
291293
{
292-
if ( null === $length ) {
294+
if (null === $length) {
293295
throw new \InvalidArgumentException("'length' argument must be a constant");
294296
}
295297

@@ -528,18 +530,22 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
528530
$engine = !empty($options['engine']) ? $options['engine'] : 'ReplacingMergeTree';
529531
$engineOptions = '';
530532

531-
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
533+
if (isset($options['uniqueConstraints']) && !empty($options['uniqueConstraints'])) {
532534
throw DBALException::notSupported('uniqueConstraints');
533535
}
534536

535-
if (isset($options['indexes']) && ! empty($options['indexes'])) {
537+
if (isset($options['indexes']) && !empty($options['indexes'])) {
536538
throw DBALException::notSupported('uniqueConstraints');
537539
}
538540

539541
/**
540542
* MergeTree* specific section
541543
*/
542-
if ( in_array($engine, ['MergeTree', 'CollapsingMergeTree', 'SummingMergeTree', 'AggregatingMergeTree', 'ReplacingMergeTree'], true) ) {
544+
if (in_array(
545+
$engine,
546+
['MergeTree', 'CollapsingMergeTree', 'SummingMergeTree', 'AggregatingMergeTree', 'ReplacingMergeTree'],
547+
true
548+
)) {
543549
$indexGranularity = !empty($options['indexGranularity']) ? $options['indexGranularity'] : 8192;
544550

545551
/**
@@ -549,9 +555,9 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
549555
'type' => Type::getType('date'),
550556
'default' => 'today()',
551557
];
552-
if (! empty($options['eventDateProviderColumn']) ) {
558+
if (!empty($options['eventDateProviderColumn'])) {
553559
$options['eventDateProviderColumn'] = trim($options['eventDateProviderColumn']);
554-
if (! isset($columns[$options['eventDateProviderColumn']]) ) {
560+
if (!isset($columns[$options['eventDateProviderColumn']])) {
555561
throw new \Exception('Table `' . $tableName . '` has not column with name: `' . $options['eventDateProviderColumn']);
556562
}
557563

@@ -566,7 +572,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
566572
$columns[$options['eventDateProviderColumn']]['type'] instanceof DecimalType ||
567573
(
568574
$columns[$options['eventDateProviderColumn']]['type'] instanceof StringType &&
569-
! $columns[$options['eventDateProviderColumn']]['fixed']
575+
!$columns[$options['eventDateProviderColumn']]['fixed']
570576
)
571577
) {
572578
$dateColumnParams['default'] =
@@ -576,21 +582,24 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
576582
('toDate(toDateTime(' . $options['eventDateProviderColumn'] . '))') :
577583
('toDate(' . $options['eventDateProviderColumn'] . ')');
578584
} else {
579-
throw new \Exception('Column `' . $options['eventDateProviderColumn'] . '` with type `'.$columns[$options['eventDateProviderColumn']]['type']->getName().'`, defined in `eventDateProviderColumn` option, has not valid DBAL Type');
585+
throw new \Exception('Column `' . $options['eventDateProviderColumn'] . '` with type `' . $columns[$options['eventDateProviderColumn']]['type']->getName() . '`, defined in `eventDateProviderColumn` option, has not valid DBAL Type');
580586
}
581587
}
582-
if ( empty($options['eventDateColumn']) ) {
583-
$dateColumns = array_filter($columns, function($column) {
588+
if (empty($options['eventDateColumn'])) {
589+
$dateColumns = array_filter($columns, function ($column) {
584590
return $column['type'] instanceof DateType;
585591
});
586592

587593
if ($dateColumns) {
588-
throw new \Exception('Table `' . $tableName . '` has DateType columns: `' . implode('`, `', array_keys($dateColumns)) . '`, but no one of them is setted as `eventDateColumn` with $table->addOption("eventDateColumn", "%eventDateColumnName%")');
594+
throw new \Exception('Table `' . $tableName . '` has DateType columns: `' . implode(
595+
'`, `',
596+
array_keys($dateColumns)
597+
) . '`, but no one of them is setted as `eventDateColumn` with $table->addOption("eventDateColumn", "%eventDateColumnName%")');
589598
}
590599

591600
$eventDateColumnName = 'EventDate';
592601
} else {
593-
if ( isset($columns[$options['eventDateColumn']]) ) {
602+
if (isset($columns[$options['eventDateColumn']])) {
594603
if ($columns[$options['eventDateColumn']]['type'] instanceof DateType) {
595604
$eventDateColumnName = $options['eventDateColumn'];
596605
unset($columns[$options['eventDateColumn']]);
@@ -607,27 +616,30 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
607616
/**
608617
* Primary key section
609618
*/
610-
if ( empty($options['primary']) ) {
619+
if (empty($options['primary'])) {
611620
throw new \Exception('You need specify PrimaryKey for MergeTree* tables');
612621
}
613622

614-
$engineOptions = '(' . $eventDateColumnName . ', (' . implode(', ', array_unique(array_values($options['primary']))) . '), ' . $indexGranularity;
623+
$engineOptions = '(' . $eventDateColumnName . ', (' . implode(
624+
', ',
625+
array_unique(array_values($options['primary']))
626+
) . '), ' . $indexGranularity;
615627

616628
/**
617629
* any specific MergeTree* table parameters
618630
*/
619631
if ('ReplacingMergeTree' === $engine) {
620-
if (! empty($options['versionColumn'])) {
621-
if (! isset($columns[$options['versionColumn']]) ) {
632+
if (!empty($options['versionColumn'])) {
633+
if (!isset($columns[$options['versionColumn']])) {
622634
throw new \Exception('If you specify `versionColumn` for ReplacingMergeTree table -- you must add this column manually (any of UInt*, Date or DateTime types)');
623635
}
624636

625637
if (
626-
! $columns[$options['versionColumn']]['type'] instanceof IntegerType &&
627-
! $columns[$options['versionColumn']]['type'] instanceof BigIntType &&
628-
! $columns[$options['versionColumn']]['type'] instanceof SmallIntType &&
629-
! $columns[$options['versionColumn']]['type'] instanceof DateType &&
630-
! $columns[$options['versionColumn']]['type'] instanceof DateTimeType
638+
!$columns[$options['versionColumn']]['type'] instanceof IntegerType &&
639+
!$columns[$options['versionColumn']]['type'] instanceof BigIntType &&
640+
!$columns[$options['versionColumn']]['type'] instanceof SmallIntType &&
641+
!$columns[$options['versionColumn']]['type'] instanceof DateType &&
642+
!$columns[$options['versionColumn']]['type'] instanceof DateTimeType
631643
) {
632644
throw new \Exception('For ReplacingMergeTree tables `versionColumn` must be any of UInt* family, or Date, or DateTime types. ' . get_class($columns[$options['versionColumn']]['type']) . ' given.');
633645
}
@@ -680,7 +692,7 @@ public function getAlterTableSQL(TableDiff $diff)
680692
continue;
681693
}
682694

683-
$queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this);
695+
$queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this);
684696
}
685697

686698
foreach ($diff->changedColumns as $columnDiff) {
@@ -694,13 +706,16 @@ public function getAlterTableSQL(TableDiff $diff)
694706

695707
// Don't propagate default value changes for unsupported column types.
696708
if ($columnDiff->hasChanged('default') &&
697-
count($columnDiff->changedProperties) === 1 &&
709+
\count($columnDiff->changedProperties) === 1 &&
698710
($columnArray['type'] instanceof TextType || $columnArray['type'] instanceof BlobType)
699711
) {
700712
continue;
701713
}
702714

703-
$queryParts[] = 'MODIFY COLUMN ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
715+
$queryParts[] = 'MODIFY COLUMN ' . $this->getColumnDeclarationSQL(
716+
$column->getQuotedName($this),
717+
$columnArray
718+
);
704719
}
705720

706721
foreach ($diff->renamedColumns as $oldColumnName => $column) {
@@ -710,9 +725,12 @@ public function getAlterTableSQL(TableDiff $diff)
710725
$sql = [];
711726
$tableSql = [];
712727

713-
if ( ! $this->onSchemaAlterTable($diff, $tableSql)) {
728+
if (!$this->onSchemaAlterTable($diff, $tableSql)) {
714729
if (count($queryParts) > 0) {
715-
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(', ', $queryParts);
730+
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(
731+
', ',
732+
$queryParts
733+
);
716734
}
717735
}
718736

@@ -871,15 +889,15 @@ public function getCurrentTimestampSQL()
871889
*/
872890
public function getListDatabasesSQL()
873891
{
874-
return 'SHOW DATABASES FORMAT JSON';
892+
return 'SHOW DATABASES';
875893
}
876894

877895
/**
878896
* {@inheritDoc}
879897
*/
880898
public function getListTableColumnsSQL($table, $database = null)
881899
{
882-
return 'DESCRIBE TABLE ' . ($database ? $this->quoteSingleIdentifier($database) . '.' : '') . $this->quoteSingleIdentifier($table) . ' FORMAT JSON';
900+
return 'DESCRIBE TABLE ' . ($database ? $this->quoteSingleIdentifier($database) . '.' : '') . $this->quoteSingleIdentifier($table);
883901
}
884902

885903
/**
@@ -1014,11 +1032,12 @@ public function supportsGettingAffectedRows()
10141032
*/
10151033
protected function doModifyLimitQuery($query, $limit, $offset)
10161034
{
1017-
if ( is_null($limit) )
1035+
if (is_null($limit)) {
10181036
return $query;
1037+
}
10191038

10201039
$query .= ' LIMIT ';
1021-
if (! is_null($offset)) {
1040+
if (!is_null($offset)) {
10221041
$query .= $offset . ', ';
10231042
}
10241043

@@ -1086,17 +1105,24 @@ protected function getReservedKeywordsClass()
10861105
*/
10871106
public function getDefaultValueDeclarationSQL($field)
10881107
{
1089-
if (! isset($field['default'])) {
1108+
if (!isset($field['default'])) {
10901109
return '';
10911110
}
10921111

10931112
$default = " DEFAULT '" . $field['default'] . "'";
1094-
if ( isset($field['type']) ) {
1095-
if (in_array((string)$field['type'], ['Integer', 'SmallInt', 'Float']) || ('BigInt' === $field['type'] && \PDO::PARAM_INT === Type::getType('BigInt')->getBindingType())) {
1113+
if (isset($field['type'])) {
1114+
if (in_array((string)$field['type'], [
1115+
'Integer',
1116+
'SmallInt',
1117+
'Float'
1118+
]) || ('BigInt' === $field['type'] && \PDO::PARAM_INT === Type::getType('BigInt')->getBindingType())) {
10961119
$default = ' DEFAULT ' . $field['default'];
1097-
} else if (in_array((string)$field['type'], ['DateTime']) && $field['default'] == $this->getCurrentTimestampSQL()) {
1120+
} elseif (in_array(
1121+
(string)$field['type'],
1122+
['DateTime']
1123+
) && $field['default'] === $this->getCurrentTimestampSQL()) {
10981124
$default = ' DEFAULT ' . $this->getCurrentTimestampSQL();
1099-
} else if ('Date' == (string)$field['type']) { // TODO check if string matches constant date like 'dddd-yy-mm' and quote it
1125+
} elseif ('Date' === (string)$field['type']) { // TODO check if string matches constant date like 'dddd-yy-mm' and quote it
11001126
$default = ' DEFAULT ' . $field['default'];
11011127
}
11021128
}
@@ -1145,5 +1171,4 @@ public function quoteSingleIdentifier($str)
11451171

11461172
return $c . addslashes($str) . $c;
11471173
}
1148-
11491174
}

0 commit comments

Comments
 (0)