Skip to content

Commit

Permalink
chores: style fixes for php 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
courtney-miles committed Jan 25, 2023
1 parent f6fece0 commit cc8765e
Show file tree
Hide file tree
Showing 50 changed files with 243 additions and 326 deletions.
14 changes: 6 additions & 8 deletions PHPUnit/MySQLTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

namespace MilesAsylum\Slurp\PHPUnit;

use PDO;

class MySQLTestHelper
{
/**
* @var PDO
* @var \PDO
*/
private $pdo;

Expand All @@ -25,7 +23,7 @@ public function __construct()
$this->pdo = $this->connect($this->makeDsn());
}

public function getConnection(): PDO
public function getConnection(): \PDO
{
return $this->pdo;
}
Expand Down Expand Up @@ -77,7 +75,7 @@ public function selectAllFromTable(string $table): array
return $this->pdo->query(<<<SQL
SELECT * FROM `$table`
SQL
)->fetchAll(PDO::FETCH_ASSOC);
)->fetchAll(\PDO::FETCH_ASSOC);
}

public function truncateTable(string $table): void
Expand All @@ -96,10 +94,10 @@ private function makeDsn(): string
return $dsn;
}

private function connect(string $dsn): PDO
private function connect(string $dsn): \PDO
{
$pdo = new PDO($dsn, $this->getDatabaseUser(), $this->getDatabasePassword());
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo = new \PDO($dsn, $this->getDatabaseUser(), $this->getDatabasePassword());
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

return $pdo;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/UnknownFieldException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

namespace MilesAsylum\Slurp\Exception;

use Throwable;

class UnknownFieldException extends \InvalidArgumentException implements ExceptionInterface
{
/**
* @var string
*/
protected $field;

public function __construct(string $field, string $message = '', int $code = 0, Throwable $previous = null)
public function __construct(string $field, string $message = '', int $code = 0, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->field = $field;
Expand Down
8 changes: 3 additions & 5 deletions src/Extract/CsvFileExtractor/CsvFileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace MilesAsylum\Slurp\Extract\CsvFileExtractor;

use CallbackFilterIterator;
use Iterator;
use League\Csv\Exception;
use League\Csv\Reader;
use MilesAsylum\Slurp\SlurpFactory;
Expand Down Expand Up @@ -87,15 +85,15 @@ public function setHeaders(array $headers): void
$this->headers = $headers;
}

public function getIterator(): Iterator
public function getIterator(): \Iterator
{
return $this->prepareRecords($this->csvReader->getRecords(), $this->headers);
}

protected function prepareRecords(Iterator $records, array $headers): Iterator
protected function prepareRecords(\Iterator $records, array $headers): \Iterator
{
if (null !== $this->headerOffset) {
$records = new CallbackFilterIterator($records, function (array $record, int $offset): bool {
$records = new \CallbackFilterIterator($records, function (array $record, int $offset): bool {
return $offset !== $this->headerOffset;
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/Extract/CsvFileExtractor/EnforcePrimaryKeyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace MilesAsylum\Slurp\Extract\CsvFileExtractor;

use IteratorIterator;
use MilesAsylum\Slurp\Extract\Exception\DuplicatePrimaryKeyValueException;

class EnforcePrimaryKeyIterator extends IteratorIterator
class EnforcePrimaryKeyIterator extends \IteratorIterator
{
private $primaryKeyFieldsValues = [];

Expand Down
6 changes: 2 additions & 4 deletions src/Extract/CsvFileExtractor/EnforceUniqueFieldIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

namespace MilesAsylum\Slurp\Extract\CsvFileExtractor;

use IteratorIterator;
use MilesAsylum\Slurp\Extract\Exception\DuplicateFieldValueException;
use Traversable;

class EnforceUniqueFieldIterator extends IteratorIterator
class EnforceUniqueFieldIterator extends \IteratorIterator
{
/**
* @var array<string, array>
*/
private $uniqueFieldValues;

public function __construct(Traversable $iterator, array $uniqueFields)
public function __construct(\Traversable $iterator, array $uniqueFields)
{
parent::__construct($iterator);

Expand Down
7 changes: 2 additions & 5 deletions src/Extract/CsvFileExtractor/MapIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@

namespace MilesAsylum\Slurp\Extract\CsvFileExtractor;

use IteratorIterator;
use Traversable;

class MapIterator extends IteratorIterator
class MapIterator extends \IteratorIterator
{
/**
* @var array
*/
private $headers;

public function __construct(Traversable $iterator, array $headers)
public function __construct(\Traversable $iterator, array $headers)
{
parent::__construct($iterator);
$this->headers = $headers;
Expand Down
6 changes: 2 additions & 4 deletions src/Extract/CsvFileExtractor/VerifyValueCountIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

namespace MilesAsylum\Slurp\Extract\CsvFileExtractor;

use IteratorIterator;
use MilesAsylum\Slurp\Extract\Exception\ValueCountMismatchException;
use Traversable;

class VerifyValueCountIterator extends IteratorIterator
class VerifyValueCountIterator extends \IteratorIterator
{
private $expectedValueCount;

public function __construct(Traversable $iterator, int $expectedValueCount)
public function __construct(\Traversable $iterator, int $expectedValueCount)
{
parent::__construct($iterator);
$this->expectedValueCount = $expectedValueCount;
Expand Down
3 changes: 1 addition & 2 deletions src/Extract/Exception/ExtractionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

namespace MilesAsylum\Slurp\Extract\Exception;

use Exception;
use MilesAsylum\Slurp\Exception\ExceptionInterface;

class ExtractionException extends Exception implements ExceptionInterface
class ExtractionException extends \Exception implements ExceptionInterface
{
}
4 changes: 1 addition & 3 deletions src/Extract/ExtractorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace MilesAsylum\Slurp\Extract;

use IteratorAggregate;

interface ExtractorInterface extends IteratorAggregate
interface ExtractorInterface extends \IteratorAggregate
{
}
13 changes: 5 additions & 8 deletions src/Load/DatabaseLoader/BatchInsertManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

use MilesAsylum\Slurp\Load\Exception\LoadRuntimeException;
use MilesAsylum\Slurp\Load\Exception\MissingValueException;
use PDO;
use PDOException;
use PDOStatement;

class BatchInsertManager implements BatchManagerInterface
{
/**
* @var PDO
* @var \PDO
*/
protected $pdo;

Expand All @@ -43,7 +40,7 @@ class BatchInsertManager implements BatchManagerInterface
private $queryFactory;

/**
* @var PDOStatement[]
* @var \PDOStatement[]
*/
private $preparedBatchStmts = [];

Expand All @@ -53,7 +50,7 @@ class BatchInsertManager implements BatchManagerInterface
private $database;

public function __construct(
PDO $pdo,
\PDO $pdo,
string $table,
array $columns,
QueryFactory $queryFactory,
Expand All @@ -76,13 +73,13 @@ public function write(array $rows): void

try {
$stmt->execute($this->convertRowCollectionToParams($rows));
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new LoadRuntimeException('PDO exception thrown when inserting batch of records into staging table.', 0, $e);
}
}
}

protected function getPreparedBatchStmt($count): PDOStatement
protected function getPreparedBatchStmt($count): \PDOStatement
{
if (!isset($this->preparedBatchStmts[$count])) {
$this->preparedBatchStmts[$count] = $this->pdo->prepare(
Expand Down
6 changes: 2 additions & 4 deletions src/Load/DatabaseLoader/LoaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

namespace MilesAsylum\Slurp\Load\DatabaseLoader;

use PDO;

class LoaderFactory
{
/**
* @var PDO
* @var \PDO
*/
private $pdo;

public function __construct(PDO $pdo)
public function __construct(\PDO $pdo)
{
$this->pdo = $pdo;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Load/DatabaseLoader/QueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace MilesAsylum\Slurp\Load\DatabaseLoader;

use InvalidArgumentException;

class QueryFactory
{
public function createInsertQuery(
Expand All @@ -24,11 +22,11 @@ public function createInsertQuery(
string $database = null
): string {
if (empty($columns)) {
throw new InvalidArgumentException('One or more columns must be supplied.');
throw new \InvalidArgumentException('One or more columns must be supplied.');
}

if ($batchSize < 1) {
throw new InvalidArgumentException('The batch size cannot be less than 1.');
throw new \InvalidArgumentException('The batch size cannot be less than 1.');
}

$tableRefTicked = "`{$table}`";
Expand Down
5 changes: 2 additions & 3 deletions src/Load/DatabaseLoader/SimpleDeleteStmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
namespace MilesAsylum\Slurp\Load\DatabaseLoader;

use MilesAsylum\Slurp\Load\Exception\LoadRuntimeException;
use PDO;

class SimpleDeleteStmt implements DmlStmtInterface
{
/**
* @var PDO
* @var \PDO
*/
private $pdo;

Expand All @@ -39,7 +38,7 @@ class SimpleDeleteStmt implements DmlStmtInterface
*/
private $database;

public function __construct(PDO $pdo, string $table, array $conditions = [], string $database = null)
public function __construct(\PDO $pdo, string $table, array $conditions = [], string $database = null)
{
$this->pdo = $pdo;
$this->table = $table;
Expand Down
8 changes: 3 additions & 5 deletions src/Load/DatabaseLoader/StagedLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

use MilesAsylum\Slurp\Exception\LogicException;
use MilesAsylum\Slurp\Load\Exception\LoadRuntimeException;
use PDO;
use PDOException;

class StagedLoad
{
/**
* @var PDO
* @var \PDO
*/
private $pdo;

Expand All @@ -48,7 +46,7 @@ class StagedLoad
*/
private $database;

public function __construct(PDO $pdo, string $table, array $columns, string $database = null)
public function __construct(\PDO $pdo, string $table, array $columns, string $database = null)
{
$this->pdo = $pdo;
$this->table = $table;
Expand Down Expand Up @@ -116,7 +114,7 @@ public function commit(): void
ON DUPLICATE KEY UPDATE {$updateValuesStr}
SQL
);
} catch (PDOException $e) {
} catch (\PDOException $e) {
throw new LoadRuntimeException('PDO exception thrown when copying rows from the staging table to the destination table.', 0, $e);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Load/Exception/MissingValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@

namespace MilesAsylum\Slurp\Load\Exception;

use InvalidArgumentException;
use MilesAsylum\Slurp\Exception\ExceptionInterface;

class MissingValueException extends InvalidArgumentException implements ExceptionInterface
class MissingValueException extends \InvalidArgumentException implements ExceptionInterface
{
public static function createMissing(int $recordId, array $missingFields): self
{
Expand Down
6 changes: 1 addition & 5 deletions src/SlurpBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use MilesAsylum\Slurp\Transform\SlurpTransformer\Transformer;
use MilesAsylum\Slurp\Validate\ConstraintValidation\ConstraintValidator;
use MilesAsylum\Slurp\Validate\SchemaValidation\SchemaValidator;
use PDO;
use Symfony\Component\Validator\Constraint;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -140,9 +139,6 @@ public static function create(): self
);
}

/**
* @return SlurpBuilder
*/
public function setTableSchema(Schema $tableSchema, bool $validateOnly = false): self
{
$this->tableSchema = $tableSchema;
Expand Down Expand Up @@ -215,7 +211,7 @@ public function addLoader(LoaderInterface $loader): self
* @param array $fieldMappings array key is the destination column and the array value is the source column
*/
public function createDatabaseLoader(
PDO $pdo,
\PDO $pdo,
string $table,
array $fieldMappings,
int $batchSize = 100,
Expand Down

0 comments on commit cc8765e

Please sign in to comment.