Skip to content

Commit 98924ec

Browse files
committed
Doctrine cs fix
1 parent 2f5f4e1 commit 98924ec

18 files changed

+146
-129
lines changed

src/Types/ArrayFloatType.php renamed to src/Types/AbstractArrayFloatType.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -15,23 +18,21 @@
1518

1619
/**
1720
* Array(Float*) Types basic class
18-
*
19-
* @author Mochalygin <[email protected]>
2021
*/
21-
abstract class ArrayFloatType extends ArrayNumType
22+
abstract class AbstractArrayFloatType extends AbstractArrayNumType
2223
{
2324
/**
2425
* {@inheritDoc}
2526
*/
26-
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
27+
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
2728
{
2829
return 'Array(Float' . $this->getBitness() . ')';
2930
}
3031

3132
/**
3233
* {@inheritDoc}
3334
*/
34-
public function getName()
35+
public function getName() : string
3536
{
3637
return 'array(float' . $this->getBitness() . ')';
3738
}

src/Types/ArrayIntType.php renamed to src/Types/AbstractArrayIntType.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -11,30 +14,27 @@
1114

1215
namespace FOD\DBALClickHouse\Types;
1316

14-
use Doctrine\DBAL\Types\Type;
1517
use Doctrine\DBAL\Platforms\AbstractPlatform;
1618

1719
/**
1820
* Array(Int*) Types basic class
19-
*
20-
* @author Mochalygin <[email protected]>
2121
*/
22-
abstract class ArrayIntType extends ArrayNumType
22+
abstract class AbstractArrayIntType extends AbstractArrayNumType
2323
{
24-
const UNSIGNED = false;
24+
public const UNSIGNED = false;
2525

2626
/**
2727
* {@inheritDoc}
2828
*/
29-
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
29+
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
3030
{
3131
return 'Array(' . (static::UNSIGNED ? 'U' : '') . 'Int' . $this->getBitness() . ')';
3232
}
3333

3434
/**
3535
* {@inheritDoc}
3636
*/
37-
public function getName()
37+
public function getName() : string
3838
{
3939
return 'array(' . (static::UNSIGNED ? 'u' : '') . 'int' . $this->getBitness() . ')';
4040
}

src/Types/ArrayNumType.php renamed to src/Types/AbstractArrayNumType.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -13,13 +16,11 @@
1316

1417
/**
1518
* Array(Numeric) Types basic class
16-
*
17-
* @author Mochalygin <[email protected]>
1819
*/
19-
abstract class ArrayNumType extends ArrayType
20+
abstract class AbstractArrayNumType extends AbstractArrayType
2021
{
2122
/**
2223
* @return int Bitness of integers or floats in Array (Array(Int{bitness}) or Array(Float{bitness}))
2324
*/
24-
abstract protected function getBitness(): int;
25+
abstract protected function getBitness() : int;
2526
}
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -11,17 +14,16 @@
1114

1215
namespace FOD\DBALClickHouse\Types;
1316

14-
use Doctrine\DBAL\Types\Type;
17+
use Doctrine\DBAL\DBALException;
1518
use Doctrine\DBAL\Platforms\AbstractPlatform;
19+
use Doctrine\DBAL\Types\Type;
1620

1721
/**
1822
* Array(*) Types basic class
19-
*
20-
* @author Mochalygin <[email protected]>
2123
*/
22-
abstract class ArrayType extends Type
24+
abstract class AbstractArrayType extends Type
2325
{
24-
const ARRAY_TYPES = [
26+
public const ARRAY_TYPES = [
2527
'array(int8)' => ArrayInt8Type::class,
2628
'array(int16)' => ArrayInt16Type::class,
2729
'array(int32)' => ArrayInt32Type::class,
@@ -40,27 +42,27 @@ abstract class ArrayType extends Type
4042
/**
4143
* Register Array types to the type map.
4244
*
43-
* @return void
45+
* @throws DBALException
4446
*/
45-
public static function registerArrayTypes(AbstractPlatform $platform)
47+
public static function registerArrayTypes(AbstractPlatform $platform) : void
4648
{
4749
foreach (self::ARRAY_TYPES as $typeName => $className) {
48-
if (!self::hasType($typeName)) {
49-
self::addType($typeName, $className);
50-
foreach (Type::getType($typeName)->getMappedDatabaseTypes($platform) as $dbType) {
51-
$platform->registerDoctrineTypeMapping($dbType, $typeName);
52-
}
50+
if (self::hasType($typeName)) {
51+
continue;
52+
}
53+
54+
self::addType($typeName, $className);
55+
foreach (Type::getType($typeName)->getMappedDatabaseTypes($platform) as $dbType) {
56+
$platform->registerDoctrineTypeMapping($dbType, $typeName);
5357
}
5458
}
5559
}
5660

5761
/**
5862
* {@inheritDoc}
5963
*/
60-
public function getMappedDatabaseTypes(AbstractPlatform $platform)
64+
public function getMappedDatabaseTypes(AbstractPlatform $platform) : array
6165
{
62-
return [
63-
$this->getName()
64-
];
66+
return [$this->getName()];
6567
}
6668
}

src/Types/ArrayDateTimeType.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -16,23 +19,21 @@
1619

1720
/**
1821
* Array(DateTime) Type class
19-
*
20-
* @author Mochalygin <[email protected]>
2122
*/
22-
class ArrayDateTimeType extends ArrayType
23+
class ArrayDateTimeType extends AbstractArrayType
2324
{
2425
/**
2526
* {@inheritDoc}
2627
*/
27-
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
28+
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
2829
{
2930
return 'Array(DateTime)';
3031
}
3132

3233
/**
3334
* {@inheritDoc}
3435
*/
35-
public function getName()
36+
public function getName() : string
3637
{
3738
return 'array(datetime)';
3839
}
@@ -42,31 +43,30 @@ public function getName()
4243
*/
4344
public function convertToPHPValue($value, AbstractPlatform $platform)
4445
{
45-
$datetimes = [];
46-
foreach ($value as $stringDatetime) {
47-
$datetimes[] = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $stringDatetime);
48-
}
49-
50-
return $datetimes;
46+
return array_map(function ($stringDatetime) use ($platform) {
47+
return \DateTime::createFromFormat($platform->getDateTimeFormatString(), $stringDatetime);
48+
}, (array) $value);
5149
}
5250

5351
/**
5452
* {@inheritDoc}
5553
*/
5654
public function convertToDatabaseValue($value, AbstractPlatform $platform)
5755
{
58-
$strings = [];
59-
foreach ($value as $datetime) {
60-
$strings[] = "'" . $datetime->format($platform->getDateTimeFormatString()) . "'";
61-
}
62-
63-
return '[' . implode(', ', $strings) . ']';
56+
return '[' . implode(
57+
', ',
58+
array_map(function (\DateTime $datetime) use ($platform) {
59+
return "'" . $datetime->format($platform->getDateTimeFormatString()) . "'";
60+
}, array_filter((array) $value, function ($datetime) {
61+
return $datetime instanceof \DateTime;
62+
}))
63+
) . ']';
6464
}
6565

6666
/**
6767
* {@inheritDoc}
6868
*/
69-
public function getBindingType()
69+
public function getBindingType() : int
7070
{
7171
return ParameterType::INTEGER;
7272
}

src/Types/ArrayDateType.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -16,23 +19,21 @@
1619

1720
/**
1821
* Array(Date) Type class
19-
*
20-
* @author Mochalygin <[email protected]>
2122
*/
22-
class ArrayDateType extends ArrayType
23+
class ArrayDateType extends AbstractArrayType
2324
{
2425
/**
2526
* {@inheritDoc}
2627
*/
27-
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
28+
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
2829
{
2930
return 'Array(Date)';
3031
}
3132

3233
/**
3334
* {@inheritDoc}
3435
*/
35-
public function getName()
36+
public function getName() : string
3637
{
3738
return 'array(date)';
3839
}
@@ -42,31 +43,30 @@ public function getName()
4243
*/
4344
public function convertToPHPValue($value, AbstractPlatform $platform)
4445
{
45-
$datetimes = [];
46-
foreach ($value as $stringDatetime) {
47-
$datetimes[] = \DateTime::createFromFormat($platform->getDateFormatString(), $stringDatetime);
48-
}
49-
50-
return $datetimes;
46+
return array_map(function ($stringDatetime) use ($platform) {
47+
return \DateTime::createFromFormat($platform->getDateFormatString(), $stringDatetime);
48+
}, (array) $value);
5149
}
5250

5351
/**
5452
* {@inheritDoc}
5553
*/
5654
public function convertToDatabaseValue($value, AbstractPlatform $platform)
5755
{
58-
$strings = [];
59-
foreach ($value as $datetime) {
60-
$strings[] = "'" . $datetime->format($platform->getDateFormatString()) . "'";
61-
}
62-
63-
return '[' . implode(', ', $strings) . ']';
56+
return '[' . implode(
57+
', ',
58+
array_map(function (\DateTime $datetime) use ($platform) {
59+
return "'" . $datetime->format($platform->getDateFormatString()) . "'";
60+
}, array_filter((array) $value, function ($datetime) {
61+
return $datetime instanceof \DateTime;
62+
}))
63+
) . ']';
6464
}
6565

6666
/**
6767
* {@inheritDoc}
6868
*/
69-
public function getBindingType()
69+
public function getBindingType() : int
7070
{
7171
return ParameterType::INTEGER;
7272
}

src/Types/ArrayFloat32Type.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -13,15 +16,13 @@
1316

1417
/**
1518
* Array(Float32) Type
16-
*
17-
* @author Mochalygin <[email protected]>
1819
*/
19-
class ArrayFloat32Type extends ArrayFloatType
20+
class ArrayFloat32Type extends AbstractArrayFloatType
2021
{
21-
const BITNESS = 32;
22+
public const BITNESS = 32;
2223

2324
/** {@inheritdoc} */
24-
protected function getBitness(): int
25+
protected function getBitness() : int
2526
{
2627
return self::BITNESS;
2728
}

src/Types/ArrayFloat64Type.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/*
36
* This file is part of the FODDBALClickHouse package -- Doctrine DBAL library
47
* for ClickHouse (a column-oriented DBMS for OLAP <https://clickhouse.yandex/>)
@@ -13,15 +16,13 @@
1316

1417
/**
1518
* Array(Float64) Type
16-
*
17-
* @author Mochalygin <[email protected]>
1819
*/
19-
class ArrayFloat64Type extends ArrayFloatType
20+
class ArrayFloat64Type extends AbstractArrayFloatType
2021
{
21-
const BITNESS = 64;
22+
public const BITNESS = 64;
2223

2324
/** {@inheritdoc} */
24-
protected function getBitness(): int
25+
protected function getBitness() : int
2526
{
2627
return self::BITNESS;
2728
}

0 commit comments

Comments
 (0)