Skip to content

Commit

Permalink
PHP_CodeSniffer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zoilomora committed Nov 23, 2020
1 parent 95492eb commit 1d31983
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ There are some functionalities that are not supported by Microsoft Access in a P

## OS Requirements
- Microsoft Access Database Engine Redistributable ([2010](https://www.microsoft.com/download/details.aspx?id=13255) or [2016](https://www.microsoft.com/download/details.aspx?id=54920)).
- Register a **DSN** in **ODBC Data Source Administrator** (odbcad32.exe).
- Register a **DSN** in **ODBC Data Source Administrator** `odbcad32.exe`.

## Installation

Expand Down
34 changes: 5 additions & 29 deletions src/Doctrine/DBAL/Driver/MicrosoftAccess/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function connect(
$password = null,
array $driverOptions = []
): \Doctrine\DBAL\Driver\Connection {
$this->assertRequiredParameters($driverOptions);
$this->assertRequiredDriverOptions($driverOptions);

try {
$conn = new PDOConnection(
Expand Down Expand Up @@ -62,49 +62,25 @@ public function getSchemaManager(Connection $conn): AbstractSchemaManager
return new MicrosoftAccessSchemaManager($conn, $this->odbcConnection);
}

/**
* @param array $driverOptions
* @throws \Exception
*/
private function assertRequiredParameters(array $driverOptions): void
private function assertRequiredDriverOptions(array $driverOptions): void
{
$dsn = $this->getDsn($driverOptions);

if ($dsn === null) {
if (false === \array_key_exists('dsn', $driverOptions)) {
throw new Exception\InvalidArgumentException("The driver option 'dsn' is mandatory");
}
}

/**
* Get the DSN for the PDO connection.
*
* @param array $driverOptions
* @return string
*/
protected function constructPdoDsn(array $driverOptions): string
{
return 'odbc:' . $this->getDsn($driverOptions);
}

/**
* Get the DSN for the ODBC connection.
*
* @param array $driverOptions
* @return string
*/
protected function constructOdbcDsn(array $driverOptions): string
{
return $this->getDsn($driverOptions);
}

/**
* Get the DSN by the driver's parameters and options
*
* @param array $driverOptions
* @return string|null
*/
private function getDsn(array $driverOptions): ?string
private function getDsn(array $driverOptions): string
{
return $driverOptions['dsn'] ?? null;
return $driverOptions['dsn'];
}
}
66 changes: 38 additions & 28 deletions src/Doctrine/DBAL/Platforms/MicrosoftAccessPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,30 @@

final class MicrosoftAccessPlatform extends SQLServer2012Platform
{
/** @link \Doctrine\DBAL\Platforms\AbstractPlatform::getName */
/**
* {@inheritDoc}
*/
public function getName(): string
{
return 'msaccess';
}

/** @link \Doctrine\DBAL\Platforms\AbstractPlatform::supportsForeignKeyConstraints */
/**
* {@inheritDoc}
*/
public function supportsForeignKeyConstraints()
{
return false;
}

/** @link \Doctrine\DBAL\Platforms\SQLServer2005Platform::supportsLimitOffset */
/**
* {@inheritDoc}
*/
public function supportsLimitOffset()
{
return false;
}

/** @link \Doctrine\DBAL\Platforms\AbstractPlatform::initializeDoctrineTypeMappings */
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = [
'bit' => 'boolean',
'byte' => 'boolean',
'counter' => 'bigint',
'currency' => 'decimal',
'datetime' => 'datetime',
'double' => 'float',
'integer' => 'integer',
'longbinary' => 'binary',
'longchar' => 'text',
'real' => 'float',
'smallint' => 'smallint',
'varchar' => 'string',
];
}

/** @link \Doctrine\DBAL\Platforms\AbstractPlatform::getReservedKeywordsClass */
protected function getReservedKeywordsClass(): string
{
return MicrosoftAccessKeywords::class;
}

/**
* {@inheritDoc}
*/
Expand All @@ -74,4 +55,33 @@ public function getTimeFormatString()
{
return 'H:i:s';
}

/**
* {@inheritDoc}
*/
protected function initializeDoctrineTypeMappings()
{
$this->doctrineTypeMapping = [
'bit' => 'boolean',
'byte' => 'boolean',
'counter' => 'bigint',
'currency' => 'decimal',
'datetime' => 'datetime',
'double' => 'float',
'integer' => 'integer',
'longbinary' => 'binary',
'longchar' => 'text',
'real' => 'float',
'smallint' => 'smallint',
'varchar' => 'string',
];
}

/**
* {@inheritDoc}
*/
protected function getReservedKeywordsClass(): string
{
return MicrosoftAccessKeywords::class;
}
}
5 changes: 3 additions & 2 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function connections(): \Iterator

$params = [
'driverClass' => Driver::class,
'dsn' => $this->dsn(),
'driverOptions' => $this->driverOptions(),
];

Expand Down Expand Up @@ -52,7 +51,9 @@ protected function dsn(): string

protected function driverOptions(): array
{
return [];
return [
'dsn' => $this->dsn(),
];
}

private function isMicrosoftWindows(): bool
Expand Down
9 changes: 6 additions & 3 deletions tests/Doctrine/DBAL/Driver/MicrosoftAccess/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ protected function dsn(): string

protected function driverOptions(): array
{
return [
'charset' => 'UTF-8',
];
return \array_merge(
parent::driverOptions(),
[
'charset' => 'UTF-8',
],
);
}
}

0 comments on commit 1d31983

Please sign in to comment.