Skip to content

Commit

Permalink
Integrate rector and upgrade codebase to php 82 (#1339)
Browse files Browse the repository at this point in the history
* Configure rector for src and tests

* Upgraded codebase to php 8.2
  • Loading branch information
norberttech authored Jan 7, 2025
1 parent 68e22ad commit 7fbaff9
Show file tree
Hide file tree
Showing 253 changed files with 777 additions and 649 deletions.
2 changes: 1 addition & 1 deletion bin/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int
$normalizedFunctions[] = $function->normalize();
}

\file_put_contents(__DIR__ . '/../' . \ltrim($input->getArgument('output'), '/'), \json_encode($normalizedFunctions));
\file_put_contents(__DIR__ . '/../' . \ltrim((string) $input->getArgument('output'), '/'), \json_encode($normalizedFunctions));

return Command::SUCCESS;
}
Expand Down
18 changes: 18 additions & 0 deletions rector.src.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/bin',
__DIR__ . '/examples',
__DIR__ . '/src/core/etl/src',
__DIR__ . '/src/cli/src',
__DIR__ . '/src/adapter/*/src',
__DIR__ . '/src/bridge/*/*/src',
__DIR__ . '/src/tools/*/*/src',
])
->withSets([
LevelSetList::UP_TO_PHP_82
]);
20 changes: 20 additions & 0 deletions rector.tests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Set\ValueObject\LevelSetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src/core/etl/tests',
__DIR__ . '/src/cli/tests',
__DIR__ . '/src/adapter/*/tests',
__DIR__ . '/src/bridge/*/*/tests',
__DIR__ . '/src/tools/*/*/tests',
])
->withSets([
LevelSetList::UP_TO_PHP_82
])
->withSkip([
RemoveParentCallWithoutParentRector::class
]);
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
use Flow\ETL\{Exception\RuntimeException, FlowContext, Loader, Rows};
use Flow\Filesystem\Path;

final class AvroLoader implements Closure, Loader, Loader\FileLoader
final readonly class AvroLoader implements Closure, Loader, Loader\FileLoader
{
public function __construct(
private readonly Path $path,
private readonly ?Schema $schema = null,
private Path $path,
private ?Schema $schema = null,
) {
throw new RuntimeException('Avro integration was abandoned due to lack of availability of good Avro libraries.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

final class CSVDetector
{
private ?Option $fallback;

private Options $options;

private SourceStream $stream;

public function __construct(SourceStream $stream, ?Option $fallback = new Option(',', '"', '\\'), ?Options $options = null)
public function __construct(private readonly SourceStream $stream, private readonly ?Option $fallback = new Option(',', '"', '\\'), ?Options $options = null)
{
$this->stream = $stream;
$this->options = $options ?? Options::all();
$this->fallback = $fallback;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@

use Flow\ETL\Adapter\CSV\Exception\CantDetectCSVOptions;

final class Options
final readonly class Options
{
/**
* @var array<Option>
*/
private array $options;

/**
* @param array<Option> $options
*/
public function __construct(array $options)
public function __construct(private array $options)
{
$this->options = $options;
}

public static function all() : self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Flow\ETL\Adapter\CSV\RowsNormalizer\EntryNormalizer;
use Flow\ETL\Rows;

final class RowsNormalizer
final readonly class RowsNormalizer
{
public function __construct(private readonly EntryNormalizer $entryNormalizer)
public function __construct(private EntryNormalizer $entryNormalizer)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use Flow\ETL\PHP\Type\Caster;
use Flow\ETL\Row\Entry;

final class EntryNormalizer
final readonly class EntryNormalizer
{
public function __construct(
private readonly Caster $caster,
private readonly string $dateTimeFormat = \DateTimeInterface::ATOM,
private Caster $caster,
private string $dateTimeFormat = \DateTimeInterface::ATOM,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use PhpBench\Attributes\Groups;

#[Groups(['extractor'])]
final class CSVExtractorBench
final readonly class CSVExtractorBench
{
private readonly FlowContext $context;
private FlowContext $context;

public function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class DbalDataFrameFactory implements DataFrameFactory
/**
* @var array<QueryParameter>
*/
private array $parameters;
private readonly array $parameters;

private ?Schema $schema = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class DbalLoader implements Loader
* @param array<string, mixed> $connectionParams
*/
public function __construct(
private string $tableName,
private readonly string $tableName,
private readonly array $connectionParams,
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Doctrine\DBAL\ArrayParameterType;
use Flow\ETL\Rows;

final class LiteralParameter implements QueryParameter
final readonly class LiteralParameter implements QueryParameter
{
public function __construct(
private readonly string $queryParamName,
private readonly mixed $value,
private readonly int|ArrayParameterType|null $type = null,
private string $queryParamName,
private mixed $value,
private int|ArrayParameterType|null $type = null,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Flow\ETL\Adapter\Doctrine;

final class OrderBy
final readonly class OrderBy
{
public function __construct(
public readonly string $column,
public readonly Order $order = Order::ASC,
public string $column,
public Order $order = Order::ASC,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Flow\ETL\Adapter\Doctrine;

final class Pages
final readonly class Pages
{
public function __construct(readonly public int $total, readonly public int $pageSize)
public function __construct(public int $total, public int $pageSize)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use Flow\ETL\Row\EntryReference;
use Flow\ETL\Rows;

final class Parameter implements QueryParameter
final readonly class Parameter implements QueryParameter
{
public function __construct(
private readonly string $queryParamName,
private readonly EntryReference $ref,
private readonly int|ArrayParameterType $type = ArrayParameterType::STRING,
private string $queryParamName,
private EntryReference $ref,
private int|ArrayParameterType $type = ArrayParameterType::STRING,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Flow\ETL\Adapter\Doctrine;

final class ParametersSet
final readonly class ParametersSet
{
/**
* @var array<array<string, mixed>>|array<list<mixed>>
*/
private readonly array $parameters;
private array $parameters;

/**
* @param array<string, mixed>|list<mixed> ...$parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Flow\ETL\Adapter\Doctrine;

final class Table
final readonly class Table
{
/**
* @param string $name
* @param null|array<string> $columns
*/
public function __construct(
public readonly string $name,
public readonly ?array $columns = [],
public string $name,
public ?array $columns = [],
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Table;

final class DatabaseContext
final readonly class DatabaseContext
{
public function __construct(
private readonly Connection $connection,
private readonly InsertQueryCounter $logger,
private Connection $connection,
private InsertQueryCounter $logger,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function log($level, $message, array $context = []) : void
return;
}

if (\str_starts_with(\trim($context['sql']), 'INSERT')) {
if (\str_starts_with(\trim((string) $context['sql']), 'INSERT')) {
$this->count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ final class ElasticsearchLoader implements Loader
* @param array{hosts?: array<string>, connectionParams?: array<mixed>, retries?: int, sniffOnStart?: bool, sslCert?: array<string>, sslKey?: array<string>, sslVerification?: (bool|string), elasticMetaHeader?: bool, includePortInHostHeader?: bool} $config
*/
public function __construct(
private array $config,
private string $index,
private IdFactory $idFactory,
private readonly array $config,
private readonly string $index,
private readonly IdFactory $idFactory,
) {
$this->client = null;
$this->method = 'index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Flow\ETL\{FlowContext, Row, Rows, Transformer};

final class HitsIntoRowsTransformer implements Transformer
final readonly class HitsIntoRowsTransformer implements Transformer
{
public function __construct(
private readonly DocumentDataSource $source = DocumentDataSource::source,
private DocumentDataSource $source = DocumentDataSource::source,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Flow\ETL\Adapter\Elasticsearch\ElasticsearchPHP;

final class SearchParams
final readonly class SearchParams
{
/**
* @param array<mixed> $params - https://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html
*/
public function __construct(private readonly array $params)
public function __construct(private array $params)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use Flow\ETL\Row\EntryFactory;
use Flow\ETL\{Row, Rows};

final class SearchResults
final readonly class SearchResults
{
/**
* @var array<mixed>
*/
private readonly array $results;
private array $results;

/**
* @param array<mixed>|Elasticsearch $results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Flow\ETL\Row;
use Flow\ETL\Row\Entry;

final class EntryIdFactory implements IdFactory
final readonly class EntryIdFactory implements IdFactory
{
public function __construct(private string $entryName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class HashIdFactory implements IdFactory
/**
* @var string[]
*/
private array $entryNames;
private readonly array $entryNames;

private Algorithm $hashAlgorithm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ protected function setUp() : void

protected function tearDown() : void
{
parent::tearDown();

$this->elasticsearchContext->deleteIndex(self::SOURCE_INDEX);
$this->elasticsearchContext->deleteIndex(self::DESTINATION_INDEX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ protected function setUp() : void

protected function tearDown() : void
{
parent::tearDown();

$this->elasticsearchContext->deleteIndex(self::INDEX_NAME);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ protected function setUp() : void

protected function tearDown() : void
{
parent::tearDown();

$this->elasticsearchContext->deleteIndex(self::INDEX_NAME);
}

Expand Down
Loading

0 comments on commit 7fbaff9

Please sign in to comment.