Skip to content

Commit

Permalink
Merge pull request #31 from martin-georgiev/develop
Browse files Browse the repository at this point in the history
Release v1.0
  • Loading branch information
martin-georgiev authored Sep 2, 2018
2 parents e8450fe + 788a8f4 commit b525d6b
Show file tree
Hide file tree
Showing 124 changed files with 1,022 additions and 1,112 deletions.
10 changes: 6 additions & 4 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ return PhpCsFixer\Config::create()
[
'@PSR2' => true,
'@PHP56Migration' => true,
'@PHP70Migration' => true,
'@PHP71Migration' => true,
'@DoctrineAnnotation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => true,
Expand All @@ -24,7 +26,7 @@ return PhpCsFixer\Config::create()
'declare_equal_normalize' => ['space' => 'none'],
'dir_constant' => true,
'ereg_to_preg' => true,
'final_internal_class' => false,
'final_internal_class' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
'include' => true,
Expand Down Expand Up @@ -91,13 +93,13 @@ return PhpCsFixer\Config::create()
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
// 'static_lambda' => false,
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => false,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'void_return' => false,
'void_return' => true,
'whitespace_after_comma_in_array' => true,
]
)
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ cache:
- $HOME/.composer/cache

php:
- 5.6
- 7.0
- 7.1
- 7.2
- nightly
Expand Down
26 changes: 20 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
{
"name": "martin-georgiev/postgresql-for-doctrine",
"type": "library",
"description": "PostgreSQL enhancements for Doctrine. Provides support for JSONB and array data types and operators and other specific functions.",
"keywords": ["martin georgiev", "doctrine", "postgresql", "postgres", "dbal", "jsonb", "array data types"],
"description": "Adds PostgreSQL 9 and 10 enhancements to Doctrine. Provides support for JSON, JSONB and some array data types. Provides functions, operators and common expressions used when working with JSON data, arrays and features related to text search.",
"keywords": [
"martin georgiev",
"doctrine",
"postgresql",
"postgres",
"dbal",
"json",
"jsonb",
"text search",
"tsvector",
"array data types"
],
"license": "MIT",
"authors": [
{
"name": "Martin Georgiev",
"email": "[email protected]"
"email": "[email protected]",
"role": "author"
}
],

Expand All @@ -23,8 +35,10 @@
},

"require": {
"php": "^5.6|^7.0",
"php": "^7.1",
"ext-ctype": "*",
"ext-json": "*",
"ext-mbstring": "*",
"doctrine/dbal": "~2.5",
"doctrine/orm": "~2.5"
},
Expand All @@ -34,7 +48,7 @@
"php-coveralls/php-coveralls": "^2.1",
"phpstan/phpstan": "^0.10.2",
"phpstan/phpstan-phpunit": "^0.10",
"phpunit/phpunit": "^5.7|^6.0|^7.0",
"phpunit/phpunit": "^7.0",
"sensiolabs/security-checker": "^4.1"
},

Expand All @@ -49,7 +63,7 @@
"bin/php-cs-fixer fix --config='./.php_cs' --show-progress=none --no-interaction --diff -v"
],
"run-static-analysis": [
"bin/phpstan analyse --level=5 src/"
"bin/phpstan analyse --level=7 src/"
],
"run-static-analysis-including-tests": [
"@run-static-analysis",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
Expand All @@ -12,18 +14,14 @@
* @since 0.1
* @author Martin Georgiev <[email protected]>
*/
abstract class AbstractTypeArray extends AbstractType
abstract class BaseArray extends BaseType
{
/**
* Converts a value from its PHP representation to its PostgreSql representation of the type.
*
* @param array|null $phpArray The value to convert.
* @param AbstractPlatform $platform The currently used database platform.
* @return string|null The database representation of the value.
*
* @throws ConversionException When passed argument is not PHP array OR When invalid array items are detected
*/
public function convertToDatabaseValue($phpArray, AbstractPlatform $platform)
public function convertToDatabaseValue($phpArray, AbstractPlatform $platform): ?string
{
if ($phpArray === null) {
return null;
Expand All @@ -49,18 +47,15 @@ public function convertToDatabaseValue($phpArray, AbstractPlatform $platform)

/**
* Tests if given PHP array item is from compatible type for PostgreSql
*
* @param mixed $item
* @return bool
*/
protected function isValidArrayItemForDatabase($item)
protected function isValidArrayItemForDatabase($item): bool
{
return true;
}

/**
* Transforms PHP array item to a PostgreSql compatible array item
*
* @param mixed $item
* @return mixed
*/
Expand All @@ -71,16 +66,19 @@ protected function transformArrayItemForPostgres($item)

/**
* Converts a value from its PostgreSql representation to its PHP representation of this type.
*
* @param mixed $postgresArray The value to convert.
* @param AbstractPlatform $platform The currently used database platform.
* @return array|null The PHP representation of the value.
* @param string|null $postgresArray The value to convert.
*/
public function convertToPHPValue($postgresArray, AbstractPlatform $platform)
public function convertToPHPValue($postgresArray, AbstractPlatform $platform): ?array
{
if ($postgresArray === null) {
return null;
}
if (!is_string($postgresArray)) {
$exceptionMessage = 'Given PostgreSql value content type is not PHP string. Instead it is "%s".';

throw new ConversionException(sprintf($exceptionMessage, gettype($postgresArray)));
}

$phpArray = $this->transformPostgresArrayToPHPArray($postgresArray);
foreach ($phpArray as &$item) {
$item = $this->transformArrayItemForPHP($item);
Expand All @@ -89,23 +87,9 @@ public function convertToPHPValue($postgresArray, AbstractPlatform $platform)
return $phpArray;
}

/**
* Transforms whole PostgreSql array to PHP array
*
* @param string $postgresArray
* @return array
*
* @throws ConversionException When passed argument is not PHP string
*/
protected function transformPostgresArrayToPHPArray($postgresArray)
protected function transformPostgresArrayToPHPArray(string $postgresArray): array
{
if (!is_string($postgresArray)) {
$exceptionMessage = 'Given PostgreSql value content type is not PHP string. Instead it is "%s".';

throw new ConversionException(sprintf($exceptionMessage, gettype($postgresArray)));
}

$trimmedPostgresArray = mb_substr($postgresArray, 1, -1);
$trimmedPostgresArray = \mb_substr($postgresArray, 1, -1);
if ($trimmedPostgresArray === '') {
return [];
}
Expand All @@ -116,7 +100,6 @@ protected function transformPostgresArrayToPHPArray($postgresArray)

/**
* Transforms PostgreSql array item to a PHP compatible array item
*
* @param mixed $item
* @return mixed
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Types\ConversionException;
Expand All @@ -10,22 +12,16 @@
* @since 0.11
* @author Martin Georgiev <[email protected]>
*/
abstract class AbstractIntegerArray extends AbstractTypeArray
abstract class BaseIntegerArray extends BaseArray
{
/**
* @return string
*/
abstract protected function getMinValue();
abstract protected function getMinValue(): string;

/**
* @return string
*/
abstract protected function getMaxValue();
abstract protected function getMaxValue(): string;

/**
* {@inheritDoc}
* @param mixed $item
*/
public function isValidArrayItemForDatabase($item)
public function isValidArrayItemForDatabase($item): bool
{
return (is_int($item) || is_string($item))
&& (bool) preg_match('/^-?[0-9]+$/', (string) $item)
Expand All @@ -34,9 +30,9 @@ public function isValidArrayItemForDatabase($item)
}

/**
* {@inheritDoc}
* @param int|string|null $item Whole number
*/
public function transformArrayItemForPHP($item)
public function transformArrayItemForPHP($item): ?int
{
if ($item === null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
Expand All @@ -11,32 +13,28 @@
* @since 0.1
* @author Martin Georgiev <[email protected]>
*/
abstract class AbstractType extends Type
abstract class BaseType extends Type
{
/**
* {@inheritDoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
protected const TYPE_NAME = null;

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
self::throwExceptionIfTypeNameNotConfigured();

return $platform->getDoctrineTypeMapping(constant('static::TYPE_NAME'));
return $platform->getDoctrineTypeMapping(static::TYPE_NAME);
}

/**
* {@inheritDoc}
*/
public function getName()
public function getName(): string
{
self::throwExceptionIfTypeNameNotConfigured();

return constant('static::TYPE_NAME');
return static::TYPE_NAME;
}

private static function throwExceptionIfTypeNameNotConfigured()
private static function throwExceptionIfTypeNameNotConfigured(): void
{
if (false === defined('static::TYPE_NAME')) {
throw new \LogicException(sprintf('Doctrine type defined in class %s is missing the TYPE_NAME constant', self::class));
if (null === static::TYPE_NAME) {
throw new \LogicException(sprintf('Doctrine type defined in class %s has no meaningful value for TYPE_NAME constant', self::class));
}
}
}
16 changes: 6 additions & 10 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArray.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\DBAL\Types;

/**
Expand All @@ -9,25 +11,19 @@
* @since 0.1
* @author Martin Georgiev <[email protected]>
*/
class BigIntArray extends AbstractIntegerArray
class BigIntArray extends BaseIntegerArray
{
/**
* @var string
*/
const TYPE_NAME = 'bigint[]';
protected const TYPE_NAME = 'bigint[]';

/**
* @return string
*/
protected function getMinValue()
protected function getMinValue(): string
{
return '-9223372036854775807';
}

/**
* @return string
*/
protected function getMaxValue()
protected function getMaxValue(): string
{
return '9223372036854775807';
}
Expand Down
16 changes: 6 additions & 10 deletions src/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArray.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\DBAL\Types;

/**
Expand All @@ -9,25 +11,19 @@
* @since 0.1
* @author Martin Georgiev <[email protected]>
*/
class IntegerArray extends AbstractIntegerArray
class IntegerArray extends BaseIntegerArray
{
/**
* @var string
*/
const TYPE_NAME = 'integer[]';
protected const TYPE_NAME = 'integer[]';

/**
* @return string
*/
protected function getMinValue()
protected function getMinValue(): string
{
return '-2147483648';
}

/**
* @return string
*/
protected function getMaxValue()
protected function getMaxValue(): string
{
return '2147483647';
}
Expand Down
Loading

0 comments on commit b525d6b

Please sign in to comment.