Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgarlag committed Apr 3, 2024
1 parent cf26092 commit bca2438
Show file tree
Hide file tree
Showing 20 changed files with 303 additions and 62 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,31 @@ jobs:
run: composer update --no-interaction --no-progress ${{ matrix.prefer }}
- name: PHPUnit
run: vendor/bin/phpunit
cs:
name: Coding standards
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1']
prefer: ['']
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2, cs2pr
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.prefer }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
- name: Install dependencies
run: composer update --no-interaction --no-progress ${{ matrix.prefer }}
- name: PHP CS Fixer
run: vendor/bin/php-cs-fixer fix -vvv --dry-run --format=checkstyle | cs2pr
27 changes: 27 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use PhpCsFixer\Config;
USE PhpCsFixer\Finder;

$header = <<<'EOF'
AJGL Doctrine DBAL Types
Copyright (C) Antonio J. García Lagar <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return (new Config())
->setRiskyAllowed(true)
->setRules(
[
'@PER-CS' => true,
'@PER-CS:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'header_comment' => ['header' => $header],
]
)
->setFinder(Finder::create()->in(__DIR__))
;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"doctrine/dbal": "^3.3 || ^4"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3.52"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 17 additions & 6 deletions src/ArrayTypeAbstract.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -35,7 +46,7 @@ public function canRequireSQLConversion(): bool

public function convertToDatabaseValue($value, AbstractPlatform $platform): string
{
array_walk_recursive($value, array($this, 'convertToDatabaseCallback'), $platform);
array_walk_recursive($value, [$this, 'convertToDatabaseCallback'], $platform);

return self::parseArrayToPg($value);
}
Expand All @@ -44,7 +55,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?array
{
if (null !== $value) {
$value = self::parsePgToArray($value);
array_walk_recursive($value, array($this, 'convertToPhpCallback'), $platform);
array_walk_recursive($value, [$this, 'convertToPhpCallback'], $platform);
}

return $value;
Expand All @@ -59,18 +70,18 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool
* @see https://web.archive.org/web/20120721205048/http://www.php.net/manual/es/ref.pgsql.php#89841
* @author [email protected]
*/
protected static function parsePgToArray(string $input, &$output=null, int $limit=null, int $offset=1)
protected static function parsePgToArray(string $input, &$output = null, int $limit = null, int $offset = 1)
{
if (null === $limit) {
$limit = strlen($input) - 1;
$output = array();
$output = [];
}
if ('{}' != $input) {
do {
if ('{' != $input[$offset]) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $input, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ( '"' != $match[1][0] ? $match[1] : stripcslashes(substr($match[1], 1, -1)) );
$output[] = ('"' != $match[1][0] ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3]) {
return $offset;
}
Expand Down Expand Up @@ -107,7 +118,7 @@ public function getInnerType(): Type
* @param mixed $v
* @return mixed
*/
protected function convertToPhpCallback(&$v, string $k, AbstractPlatform $platform)
protected function convertToPhpCallback(&$v, string $k, AbstractPlatform $platform)
{
$v = $this->getInnerType()->convertToPHPValue($v, $platform);
}
Expand Down
14 changes: 13 additions & 1 deletion src/BigIntArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class BigIntArrayType extends ArrayTypeAbstract
{
const BIGINTARRAY = 'bigint[]';
public const BIGINTARRAY = 'bigint[]';

protected string $name = self::BIGINTARRAY;

Expand Down
14 changes: 13 additions & 1 deletion src/BooleanArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class BooleanArrayType extends ArrayTypeAbstract
{
const BOOLEANARRAY = 'boolean[]';
public const BOOLEANARRAY = 'boolean[]';

protected string $name = self::BOOLEANARRAY;

Expand Down
14 changes: 13 additions & 1 deletion src/IntegerArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class IntegerArrayType extends ArrayTypeAbstract
{
const INTEGERARRAY = 'integer[]';
public const INTEGERARRAY = 'integer[]';

protected string $name = self::INTEGERARRAY;

Expand Down
14 changes: 13 additions & 1 deletion src/SmallIntArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class SmallIntArrayType extends ArrayTypeAbstract
{
const SMALLINTARRAY = 'smallint[]';
public const SMALLINTARRAY = 'smallint[]';

protected string $name = self::SMALLINTARRAY;

Expand Down
14 changes: 13 additions & 1 deletion src/StringArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class StringArrayType extends ArrayTypeAbstract
{
const STRINGARRAY = 'string[]';
public const STRINGARRAY = 'string[]';

protected string $name = self::STRINGARRAY;

Expand Down
14 changes: 13 additions & 1 deletion src/TextArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class TextArrayType extends ArrayTypeAbstract
{
const TEXTARRAY = 'text[]';
public const TEXTARRAY = 'text[]';

protected string $name = self::TEXTARRAY;

Expand Down
14 changes: 13 additions & 1 deletion src/XmlArrayType.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

final class XmlArrayType extends ArrayTypeAbstract
{
const XMLARRAY = 'xml[]';
public const XMLARRAY = 'xml[]';

protected string $name = self::XMLARRAY;

Expand Down
12 changes: 11 additions & 1 deletion src/XmlType.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

declare(strict_types=1);

/*
* AJGL Doctrine DBAL Types
*
* Copyright (C) Antonio J. García Lagar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Ajgl\Doctrine\DBAL\Types;

Expand All @@ -11,7 +21,7 @@

final class XmlType extends TextType
{
const XML = 'xml';
public const XML = 'xml';

public function getName(): string
{
Expand Down
Loading

0 comments on commit bca2438

Please sign in to comment.