Skip to content

Commit

Permalink
use PHP 7.1 types
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Jan 20, 2024
1 parent b768b3e commit f0c350b
Show file tree
Hide file tree
Showing 34 changed files with 308 additions and 397 deletions.
23 changes: 12 additions & 11 deletions src/Bridges/Dibi/Dibi3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Nextras\Migrations\Bridges\Dibi;

use DateTime;
use DateTimeInterface;
use Dibi;
use Nextras\Migrations\IDbal;

Expand All @@ -26,45 +26,46 @@ public function __construct(Dibi\Connection $dibi)
}


public function query($sql)
public function query(string $sql): array
{
$result = $this->conn->nativeQuery($sql);
$result->setRowClass(null);
return $result->fetchAll();
}


public function exec($sql)
public function exec(string $sql): int
{
return $this->conn->nativeQuery($sql);
$this->conn->nativeQuery($sql);
return $this->conn->getAffectedRows();
}


public function escapeString($value)
public function escapeString(string $value): string
{
return $this->conn->getDriver()->escapeText($value);
}


public function escapeInt($value)
public function escapeInt(int $value): string
{
return (string) (int) $value;
return (string) $value;
}


public function escapeBool($value)
public function escapeBool(bool $value): string
{
return $this->conn->getDriver()->escapeBool($value);
return (string) $this->conn->getDriver()->escapeBool($value);
}


public function escapeDateTime(DateTime $value)
public function escapeDateTime(DateTimeInterface $value): string
{
return $this->conn->getDriver()->escapeDateTime($value);
}


public function escapeIdentifier($value)
public function escapeIdentifier(string $value): string
{
return $this->conn->getDriver()->escapeIdentifier($value);
}
Expand Down
18 changes: 10 additions & 8 deletions src/Bridges/Dibi/DibiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

namespace Nextras\Migrations\Bridges\Dibi;

use DateTime;
use DateTimeInterface;
use dibi;
use LogicException;
use Nextras\Migrations\IDbal;

use function version_compare;


class DibiAdapter implements IDbal
{
Expand All @@ -32,43 +34,43 @@ public function __construct($conn)
}


public function query($sql)
public function query(string $sql): array
{
return $this->innerAdapter->query($sql);
}


public function exec($sql)
public function exec(string $sql): int
{
return $this->innerAdapter->exec($sql);
}


public function escapeString($value)
public function escapeString(string $value): string
{
return $this->innerAdapter->escapeString($value);
}


public function escapeInt($value)
public function escapeInt(int $value): string
{
return $this->innerAdapter->escapeInt($value);
}


public function escapeBool($value)
public function escapeBool(bool $value): string
{
return $this->innerAdapter->escapeBool($value);
}


public function escapeDateTime(DateTime $value)
public function escapeDateTime(DateTimeInterface $value): string
{
return $this->innerAdapter->escapeDateTime($value);
}


public function escapeIdentifier($value)
public function escapeIdentifier(string $value): string
{
return $this->innerAdapter->escapeIdentifier($value);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Bridges/DoctrineDbal/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Nextras\Migrations\Bridges\DoctrineDbal;

use DateTime;
use DateTimeInterface;
use Doctrine;
use Nextras\Migrations\IDbal;

Expand All @@ -26,47 +26,47 @@ public function __construct(Doctrine\DBAL\Connection $conn)
}


public function query($sql)
public function query(string $sql): array
{
return method_exists($this->conn, 'fetchAllAssociative')
? $this->conn->fetchAllAssociative($sql)
: $this->conn->fetchAll($sql);
}


public function exec($sql)
public function exec(string $sql): int
{
return method_exists($this->conn, 'executeStatement')
? $this->conn->executeStatement($sql)
: $this->conn->exec($sql);
}


public function escapeString($value)
public function escapeString(string $value): string
{
return $this->conn->quote($value, 'string');
}


public function escapeInt($value)
public function escapeInt(int $value): string
{
return $this->conn->quote($value, 'integer');
}


public function escapeBool($value)
public function escapeBool(bool $value): string
{
return $this->conn->quote($value, 'boolean');
}


public function escapeDateTime(DateTime $value)
public function escapeDateTime(DateTimeInterface $value): string
{
return $this->conn->quote($value, 'datetime');
}


public function escapeIdentifier($value)
public function escapeIdentifier(string $value): string
{
return $this->conn->quoteIdentifier($value);
}
Expand Down
20 changes: 5 additions & 15 deletions src/Bridges/DoctrineOrm/StructureDiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,20 @@ class StructureDiffGenerator implements IDiffGenerator
private $ignoredQueriesFile;


/**
* @param EntityManagerInterface $entityManager
* @param string|NULL $ignoredQueriesFile
*/
public function __construct(EntityManagerInterface $entityManager, $ignoredQueriesFile = null)
public function __construct(EntityManagerInterface $entityManager, ?string $ignoredQueriesFile = null)
{
$this->entityManager = $entityManager;
$this->ignoredQueriesFile = $ignoredQueriesFile;
}


/**
* @return string
*/
public function getExtension()
public function getExtension(): string
{
return 'sql';
}


/**
* @return string
*/
public function generateContent()
public function generateContent(): string
{
$queries = array_diff($this->getUpdateQueries(), $this->getIgnoredQueries());
$content = $queries ? (implode(";\n", $queries) . ";\n") : '';
Expand All @@ -60,7 +50,7 @@ public function generateContent()
/**
* @return string[]
*/
protected function getUpdateQueries()
protected function getUpdateQueries(): array
{
$cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl();
if ($cache instanceof ClearableCache) {
Expand All @@ -78,7 +68,7 @@ protected function getUpdateQueries()
/**
* @return string[]
*/
protected function getIgnoredQueries()
protected function getIgnoredQueries(): array
{
if ($this->ignoredQueriesFile === null) {
return [];
Expand Down
12 changes: 6 additions & 6 deletions src/Bridges/NetteDI/MigrationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MigrationsExtension extends Nette\DI\CompilerExtension
/** attributes = ['for' => names of target migration extensions, 'extension' => name of handled file extension] */
const TAG_EXTENSION_HANDLER = 'nextras.migrations.extensionHandler';

/** @var array */
/** @var array<string, mixed> */
public $defaults = [
'dir' => null,
'phpParams' => [],
Expand All @@ -40,7 +40,7 @@ class MigrationsExtension extends Nette\DI\CompilerExtension
'ignoredQueriesFile' => null,
];

/** @var array */
/** @var array<string, class-string> */
protected $dbals = [
'dibi' => Nextras\Migrations\Bridges\Dibi\DibiAdapter::class,
'dibi3' => Nextras\Migrations\Bridges\Dibi\Dibi3Adapter::class,
Expand All @@ -50,20 +50,20 @@ class MigrationsExtension extends Nette\DI\CompilerExtension
'nextras' => Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter::class,
];

/** @var array */
/** @var array<string, class-string> */
protected $drivers = [
'mysql' => Nextras\Migrations\Drivers\MySqlDriver::class,
'pgsql' => Nextras\Migrations\Drivers\PgSqlDriver::class,
];

/** @var array */
/** @var array<string, class-string> */
protected $printers = [
'console' => Nextras\Migrations\Printers\Console::class,
'psrLog' => Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter::class,
];


public function loadConfiguration()
public function loadConfiguration(): void
{
$config = $this->validateConfig($this->defaults);

Expand Down Expand Up @@ -109,7 +109,7 @@ public function loadConfiguration()
}


public function beforeCompile()
public function beforeCompile(): void
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
Expand Down
16 changes: 8 additions & 8 deletions src/Bridges/NetteDatabase/NetteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Nextras\Migrations\Bridges\NetteDatabase;

use DateTime;
use DateTimeInterface;
use Nette;
use Nextras\Migrations\IDbal;
use PDO;
Expand All @@ -27,7 +27,7 @@ public function __construct(Nette\Database\Connection $ndb)
}


public function query($sql)
public function query(string $sql): array
{
return array_map(
function ($row) { return (array) $row; },
Expand All @@ -36,37 +36,37 @@ function ($row) { return (array) $row; },
}


public function exec($sql)
public function exec(string $sql): int
{
return $this->conn->query($sql)->getRowCount();
}


public function escapeString($value)
public function escapeString(string $value): string
{
return $this->conn->quote($value, PDO::PARAM_STR);
}


public function escapeInt($value)
public function escapeInt(int $value): string
{
return $this->conn->quote((string) $value, PDO::PARAM_INT);
}


public function escapeBool($value)
public function escapeBool(bool $value): string
{
return $this->escapeString((string) (int) $value);
}


public function escapeDateTime(DateTime $value)
public function escapeDateTime(DateTimeInterface $value): string
{
return $this->conn->getSupplementalDriver()->formatDateTime($value);
}


public function escapeIdentifier($value)
public function escapeIdentifier(string $value): string
{
return $this->conn->getSupplementalDriver()->delimite($value);
}
Expand Down
Loading

0 comments on commit f0c350b

Please sign in to comment.