Skip to content

Commit 85efd87

Browse files
committed
Type casting, documentation minor fixes
1 parent ef509e1 commit 85efd87

File tree

12 files changed

+29
-50
lines changed

12 files changed

+29
-50
lines changed

src/Adapter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ protected function createDriver(array $parameters): DriverInterface
7272

7373
protected function createPlatform(array $parameters): PlatformInterface
7474
{
75-
$platformName = $parameters['platform'] ?? $this->driver->getDatabasePlatformName();
7675
// currently only supported by the IbmDb2 & Oracle concrete implementations
7776
// todo: check recent versions of mysqli and pdo to see if they support this
7877
$options = $parameters['platform_options'] ?? [];

src/ConfigProvider.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
use Laminas\Db\Adapter\AdapterInterface;
66
use Laminas\Db\Adapter\AdapterAbstractServiceFactory;
77
use Laminas\Db\Adapter\AdapterServiceFactory;
8-
use Laminas\Db\Adapter\Driver\DriverInterface;
9-
use Laminas\Db\Adapter\Platform\PlatformInterface;
108
use Laminas\Db\Container\MetadataFactory;
119
use Laminas\Db\Metadata\MetadataInterface;
12-
use Laminas\ServiceManager\Factory\InvokableFactory;
13-
use PHPUnit\Metadata\Metadata;
1410

1511
readonly class ConfigProvider
1612
{

src/DatabasePlatformNameTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
namespace Laminas\Db\Adapter\Mysql;
66

7+
use Laminas\Db\Adapter\Driver\DriverInterface;
8+
79
trait DatabasePlatformNameTrait
810
{
911
/**
1012
* Get database platform name
1113
*
12-
* @param string $nameFormat
14+
* @param string $nameFormat
1315
* @return string
1416
*/
15-
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
17+
public function getDatabasePlatformName(string $nameFormat = DriverInterface::NAME_FORMAT_CAMELCASE): string
1618
{
17-
if ($nameFormat === self::NAME_FORMAT_CAMELCASE) {
19+
if ($nameFormat === DriverInterface::NAME_FORMAT_CAMELCASE) {
1820
return 'Mysql';
1921
}
2022

src/Driver/Mysqli/Connection.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ public function connect(): static
143143
$this->resource->ssl_set($clientKey, $clientCert, $caCert, $caPath, $cipher);
144144
//MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT is not valid option, needs to be set as flag
145145
if (
146-
isset($p['driver_options'])
147-
&& isset($p['driver_options'][MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT])
146+
isset($p['driver_options'][MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT])
148147
) {
149148
$flags |= MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
150149
}
@@ -154,7 +153,7 @@ public function connect(): static
154153
$flags === null
155154
? $this->resource->real_connect($hostname, $username, $password, $database, $port, $socket)
156155
: $this->resource->real_connect($hostname, $username, $password, $database, $port, $socket, $flags);
157-
} catch (GenericException $e) {
156+
} catch (GenericException) {
158157
throw new Exception\RuntimeException(
159158
'Connection error',
160159
$this->resource->connect_errno,
@@ -254,15 +253,11 @@ public function execute($sql): ResultInterface
254253
$this->connect();
255254
}
256255

257-
if ($this->profiler) {
258-
$this->profiler->profilerStart($sql);
259-
}
256+
$this->profiler?->profilerStart($sql);
260257

261258
$resultResource = $this->resource->query($sql);
262259

263-
if ($this->profiler) {
264-
$this->profiler->profilerFinish($sql);
265-
}
260+
$this->profiler?->profilerFinish($sql);
266261

267262
// if the returnValue is something other than a mysqli_result, bypass wrapping it
268263
if ($resultResource === false) {

src/Driver/Mysqli/Mysqli.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function getPrepareType()
226226
* @param mixed $type
227227
* @return string
228228
*/
229-
public function formatParameterName($name, $type = null)
229+
public function formatParameterName($name, $type = null): string
230230
{
231231
return '?';
232232
}

src/Driver/Mysqli/Statement.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function setResource(mysqli_stmt $mysqliStatement)
143143
/**
144144
* Get sql
145145
*
146-
* @return string
146+
* @return string|null
147147
*/
148148
public function getSql(): ?string
149149
{
@@ -173,10 +173,8 @@ public function isPrepared()
173173
/**
174174
* Prepare
175175
*
176-
* @param string $sql
177-
* @return $this Provides a fluent interface
178-
* @throws Exception\InvalidQueryException
179-
* @throws Exception\RuntimeException
176+
* @param string|null $sql
177+
* @return Statement|null Provides a fluent interface
180178
*/
181179
public function prepare(?string $sql = null): ?static
182180
{
@@ -231,15 +229,11 @@ public function execute($parameters = null)
231229
}
232230
/** END Standard ParameterContainer Merging Block */
233231

234-
if ($this->profiler) {
235-
$this->profiler->profilerStart($this);
236-
}
232+
$this->profiler?->profilerStart($this);
237233

238234
$return = $this->resource->execute();
239235

240-
if ($this->profiler) {
241-
$this->profiler->profilerFinish();
242-
}
236+
$this->profiler?->profilerFinish();
243237

244238
if ($return === false) {
245239
throw new Exception\RuntimeException($this->resource->error);

src/Driver/Pdo/Connection.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66

77
use Laminas\Db\Adapter\Driver\Pdo\AbstractPdoConnection;
88
use Laminas\Db\Adapter\Exception;
9-
use Laminas\Db\Adapter\Exception\RuntimeException;
109
use Override;
1110
use PDOException;
1211
use PDOStatement;
1312

1413
use function array_diff_key;
1514
use function implode;
16-
use function is_array;
1715
use function is_int;
1816
use function str_replace;
19-
use function strpos;
2017
use function strtolower;
2118
use function substr;
2219

@@ -63,7 +60,7 @@ public function connect(): static
6360
break;
6461
case 'driver':
6562
$value = strtolower((string) $value);
66-
if (strpos($value, 'pdo') === 0) {
63+
if (str_starts_with($value, 'pdo')) {
6764
$pdoDriver = str_replace(['-', '_', ' '], '', $value);
6865
$pdoDriver = substr($pdoDriver, 3) ?: '';
6966
}
@@ -187,7 +184,7 @@ public function getLastGeneratedValue($name = null): string|int|bool|null
187184
{
188185
try {
189186
return $this->resource->lastInsertId($name);
190-
} catch (\Exception $e) {
187+
} catch (\Exception) {
191188
// do nothing
192189
}
193190

src/Metadata/Source/MysqlMetadata.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
use function preg_match;
1515
use function preg_match_all;
1616
use function str_replace;
17-
use function strpos;
1817

1918
use const CASE_LOWER;
2019
use const PREG_PATTERN_ORDER;
2120

2221
class MysqlMetadata extends AbstractSource
2322
{
24-
protected function loadSchemaData()
23+
/**
24+
* @throws \Exception
25+
*/
26+
protected function loadSchemaData(): void
2527
{
2628
if (isset($this->data['schemas'])) {
2729
return;
@@ -49,7 +51,7 @@ protected function loadSchemaData()
4951
* @param string $schema
5052
* @return void
5153
*/
52-
protected function loadTableNameData($schema)
54+
protected function loadTableNameData($schema): void
5355
{
5456
if (isset($this->data['table_names'][$schema])) {
5557
return;
@@ -110,7 +112,7 @@ protected function loadTableNameData($schema)
110112
* @param string $schema
111113
* @return void
112114
*/
113-
protected function loadColumnData($table, $schema)
115+
protected function loadColumnData($table, $schema): void
114116
{
115117
if (isset($this->data['columns'][$schema][$table])) {
116118
return;
@@ -185,7 +187,7 @@ protected function loadColumnData($table, $schema)
185187
'character_octet_length' => $row['CHARACTER_OCTET_LENGTH'],
186188
'numeric_precision' => $row['NUMERIC_PRECISION'],
187189
'numeric_scale' => $row['NUMERIC_SCALE'],
188-
'numeric_unsigned' => false !== strpos($row['COLUMN_TYPE'], 'unsigned'),
190+
'numeric_unsigned' => str_contains($row['COLUMN_TYPE'], 'unsigned'),
189191
'erratas' => $erratas,
190192
];
191193
}

test/integration/Driver/Mysqli/TraitSetup.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
use Override;
88
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
99

10-
use function extension_loaded;
1110
use function getenv;
1211
use function is_string;
1312
use function sprintf;
14-
use function strtolower;
1513

1614
// phpcs:ignore WebimpressCodingStandard.NamingConventions.Trait.Suffix
1715
trait TraitSetup

test/integration/Driver/Pdo/Mysql/AdapterTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Override;
99

1010
use function getenv;
11-
use function is_string;
12-
use function strtolower;
1311

1412
trait AdapterTrait
1513
{

0 commit comments

Comments
 (0)