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 8f80607
Show file tree
Hide file tree
Showing 51 changed files with 482 additions and 596 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
19 changes: 10 additions & 9 deletions src/Bridges/Dibi/DibiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

namespace Nextras\Migrations\Bridges\Dibi;

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

Expand All @@ -21,7 +22,7 @@ class DibiAdapter implements IDbal
private $innerAdapter;


public function __construct($conn)
public function __construct(Connection $conn)
{
if (version_compare(dibi::VERSION, '3.0.0', '>=')) {
$this->innerAdapter = new Dibi3Adapter($conn);
Expand All @@ -32,43 +33,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
24 changes: 7 additions & 17 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 @@ -58,9 +48,9 @@ public function generateContent()


/**
* @return string[]
* @return list<string>
*/
protected function getUpdateQueries()
protected function getUpdateQueries(): array
{
$cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl();
if ($cache instanceof ClearableCache) {
Expand All @@ -76,9 +66,9 @@ protected function getUpdateQueries()


/**
* @return string[]
* @return list<string>
*/
protected function getIgnoredQueries()
protected function getIgnoredQueries(): array
{
if ($this->ignoredQueriesFile === null) {
return [];
Expand Down
Loading

0 comments on commit 8f80607

Please sign in to comment.