Skip to content

Commit 586fea1

Browse files
committed
feat: apply laminas-coding-standard 2.2 ruleset
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 21cf3dd commit 586fea1

File tree

327 files changed

+5599
-5146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

327 files changed

+5599
-5146
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.phpcs-cache
12
/.phpunit.result.cache
23
/.vagrant/
34
/clover.xml

src/Adapter/Adapter.php

+63-65
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
namespace Laminas\Db\Adapter;
44

5+
use InvalidArgumentException;
56
use Laminas\Db\ResultSet;
67

8+
use function func_get_args;
9+
use function in_array;
10+
use function is_array;
11+
use function is_bool;
12+
use function is_string;
13+
use function strpos;
14+
use function strtolower;
15+
716
/**
817
* @property Driver\DriverInterface $driver
918
* @property Platform\PlatformInterface $platform
@@ -13,58 +22,45 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface
1322
/**
1423
* Query Mode Constants
1524
*/
16-
const QUERY_MODE_EXECUTE = 'execute';
17-
const QUERY_MODE_PREPARE = 'prepare';
25+
public const QUERY_MODE_EXECUTE = 'execute';
26+
public const QUERY_MODE_PREPARE = 'prepare';
1827

1928
/**
2029
* Prepare Type Constants
2130
*/
22-
const PREPARE_TYPE_POSITIONAL = 'positional';
23-
const PREPARE_TYPE_NAMED = 'named';
31+
public const PREPARE_TYPE_POSITIONAL = 'positional';
32+
public const PREPARE_TYPE_NAMED = 'named';
2433

25-
const FUNCTION_FORMAT_PARAMETER_NAME = 'formatParameterName';
26-
const FUNCTION_QUOTE_IDENTIFIER = 'quoteIdentifier';
27-
const FUNCTION_QUOTE_VALUE = 'quoteValue';
34+
public const FUNCTION_FORMAT_PARAMETER_NAME = 'formatParameterName';
35+
public const FUNCTION_QUOTE_IDENTIFIER = 'quoteIdentifier';
36+
public const FUNCTION_QUOTE_VALUE = 'quoteValue';
2837

29-
const VALUE_QUOTE_SEPARATOR = 'quoteSeparator';
38+
public const VALUE_QUOTE_SEPARATOR = 'quoteSeparator';
3039

31-
/**
32-
* @var Driver\DriverInterface
33-
*/
34-
protected $driver = null;
40+
/** @var Driver\DriverInterface */
41+
protected $driver;
3542

36-
/**
37-
* @var Platform\PlatformInterface
38-
*/
39-
protected $platform = null;
43+
/** @var Platform\PlatformInterface */
44+
protected $platform;
4045

41-
/**
42-
* @var Profiler\ProfilerInterface
43-
*/
44-
protected $profiler = null;
46+
/** @var Profiler\ProfilerInterface */
47+
protected $profiler;
4548

46-
/**
47-
* @var ResultSet\ResultSetInterface
48-
*/
49-
protected $queryResultSetPrototype = null;
49+
/** @var ResultSet\ResultSetInterface */
50+
protected $queryResultSetPrototype;
5051

51-
/**
52-
* @var Driver\StatementInterface
53-
*/
54-
protected $lastPreparedStatement = null;
52+
/** @var Driver\StatementInterface */
53+
protected $lastPreparedStatement;
5554

5655
/**
5756
* @param Driver\DriverInterface|array $driver
58-
* @param Platform\PlatformInterface $platform
59-
* @param ResultSet\ResultSetInterface $queryResultPrototype
60-
* @param Profiler\ProfilerInterface $profiler
6157
* @throws Exception\InvalidArgumentException
6258
*/
6359
public function __construct(
6460
$driver,
65-
Platform\PlatformInterface $platform = null,
66-
ResultSet\ResultSetInterface $queryResultPrototype = null,
67-
Profiler\ProfilerInterface $profiler = null
61+
?Platform\PlatformInterface $platform = null,
62+
?ResultSet\ResultSetInterface $queryResultPrototype = null,
63+
?Profiler\ProfilerInterface $profiler = null
6864
) {
6965
// first argument can be an array of parameters
7066
$parameters = [];
@@ -88,16 +84,15 @@ public function __construct(
8884
$platform = $this->createPlatform($parameters);
8985
}
9086

91-
$this->platform = $platform;
92-
$this->queryResultSetPrototype = ($queryResultPrototype) ?: new ResultSet\ResultSet();
87+
$this->platform = $platform;
88+
$this->queryResultSetPrototype = $queryResultPrototype ?: new ResultSet\ResultSet();
9389

9490
if ($profiler) {
9591
$this->setProfiler($profiler);
9692
}
9793
}
9894

9995
/**
100-
* @param Profiler\ProfilerInterface $profiler
10196
* @return self Provides a fluent interface
10297
*/
10398
public function setProfiler(Profiler\ProfilerInterface $profiler)
@@ -147,6 +142,7 @@ public function getQueryResultSetPrototype()
147142
return $this->queryResultSetPrototype;
148143
}
149144

145+
/** @return string */
150146
public function getCurrentSchema()
151147
{
152148
return $this->driver->getConnection()->getCurrentSchema();
@@ -157,30 +153,30 @@ public function getCurrentSchema()
157153
*
158154
* @param string $sql
159155
* @param string|array|ParameterContainer $parametersOrQueryMode
160-
* @param \Laminas\Db\ResultSet\ResultSetInterface $resultPrototype
161156
* @throws Exception\InvalidArgumentException
162157
* @return Driver\StatementInterface|ResultSet\ResultSet
163158
*/
164159
public function query(
165160
$sql,
166161
$parametersOrQueryMode = self::QUERY_MODE_PREPARE,
167-
ResultSet\ResultSetInterface $resultPrototype = null
162+
?ResultSet\ResultSetInterface $resultPrototype = null
168163
) {
169-
if (is_string($parametersOrQueryMode)
164+
if (
165+
is_string($parametersOrQueryMode)
170166
&& in_array($parametersOrQueryMode, [self::QUERY_MODE_PREPARE, self::QUERY_MODE_EXECUTE])
171167
) {
172-
$mode = $parametersOrQueryMode;
168+
$mode = $parametersOrQueryMode;
173169
$parameters = null;
174170
} elseif (is_array($parametersOrQueryMode) || $parametersOrQueryMode instanceof ParameterContainer) {
175-
$mode = self::QUERY_MODE_PREPARE;
171+
$mode = self::QUERY_MODE_PREPARE;
176172
$parameters = $parametersOrQueryMode;
177173
} else {
178174
throw new Exception\InvalidArgumentException(
179175
'Parameter 2 to this method must be a flag, an array, or ParameterContainer'
180176
);
181177
}
182178

183-
if ($mode == self::QUERY_MODE_PREPARE) {
179+
if ($mode === self::QUERY_MODE_PREPARE) {
184180
$this->lastPreparedStatement = null;
185181
$this->lastPreparedStatement = $this->driver->createStatement($sql);
186182
$this->lastPreparedStatement->prepare();
@@ -199,7 +195,7 @@ public function query(
199195
}
200196

201197
if ($result instanceof Driver\ResultInterface && $result->isQueryResult()) {
202-
$resultSet = clone ($resultPrototype ?: $this->queryResultSetPrototype);
198+
$resultSet = $resultPrototype !== null ? clone $resultPrototype : $this->queryResultSetPrototype;
203199
$resultSet->initialize($result);
204200
return $resultSet;
205201
}
@@ -217,11 +213,12 @@ public function query(
217213
public function createStatement($initialSql = null, $initialParameters = null)
218214
{
219215
$statement = $this->driver->createStatement($initialSql);
220-
if ($initialParameters === null
216+
if (
217+
$initialParameters === null
221218
|| ! $initialParameters instanceof ParameterContainer
222219
&& is_array($initialParameters)
223220
) {
224-
$initialParameters = new ParameterContainer((is_array($initialParameters) ? $initialParameters : []));
221+
$initialParameters = new ParameterContainer(is_array($initialParameters) ? $initialParameters : []);
225222
}
226223
$statement->setParameterContainer($initialParameters);
227224
return $statement;
@@ -230,7 +227,7 @@ public function createStatement($initialSql = null, $initialParameters = null)
230227
public function getHelpers()
231228
{
232229
$functions = [];
233-
$platform = $this->platform;
230+
$platform = $this->platform;
234231
foreach (func_get_args() as $arg) {
235232
switch ($arg) {
236233
case self::FUNCTION_QUOTE_IDENTIFIER:
@@ -248,7 +245,7 @@ public function getHelpers()
248245
}
249246

250247
/**
251-
* @param $name
248+
* @param string $name
252249
* @throws Exception\InvalidArgumentException
253250
* @return Driver\DriverInterface|Platform\PlatformInterface
254251
*/
@@ -267,7 +264,7 @@ public function __get($name)
267264
/**
268265
* @param array $parameters
269266
* @return Driver\DriverInterface
270-
* @throws \InvalidArgumentException
267+
* @throws InvalidArgumentException
271268
* @throws Exception\InvalidArgumentException
272269
*/
273270
protected function createDriver($parameters)
@@ -313,7 +310,7 @@ protected function createDriver($parameters)
313310
break;
314311
case 'pdo':
315312
default:
316-
if ($driverName == 'pdo' || strpos($driverName, 'pdo') === 0) {
313+
if ($driverName === 'pdo' || strpos($driverName, 'pdo') === 0) {
317314
$driver = new Driver\Pdo\Pdo($parameters);
318315
}
319316
}
@@ -342,7 +339,7 @@ protected function createPlatform(array $parameters)
342339
}
343340

344341
// currently only supported by the IbmDb2 & Oracle concrete implementations
345-
$options = (isset($parameters['platform_options'])) ? $parameters['platform_options'] : [];
342+
$options = $parameters['platform_options'] ?? [];
346343

347344
switch ($platformName) {
348345
case 'Mysql':
@@ -355,7 +352,7 @@ protected function createPlatform(array $parameters)
355352
return new Platform\Mysql($driver);
356353
case 'SqlServer':
357354
// PDO is only supported driver for quoting values in this platform
358-
return new Platform\SqlServer(($this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null);
355+
return new Platform\SqlServer($this->driver instanceof Driver\Pdo\Pdo ? $this->driver : null);
359356
case 'Oracle':
360357
if ($this->driver instanceof Driver\Oci8\Oci8 || $this->driver instanceof Driver\Pdo\Pdo) {
361358
$driver = $this->driver;
@@ -386,41 +383,42 @@ protected function createPlatform(array $parameters)
386383
}
387384

388385
/**
389-
*
390386
* @param array $parameters
391387
* @return Profiler\ProfilerInterface
392388
* @throws Exception\InvalidArgumentException
393389
*/
394390
protected function createProfiler($parameters)
395391
{
396392
if ($parameters['profiler'] instanceof Profiler\ProfilerInterface) {
397-
$profiler = $parameters['profiler'];
398-
} elseif (is_bool($parameters['profiler'])) {
399-
$profiler = ($parameters['profiler'] == true) ? new Profiler\Profiler : null;
400-
} else {
401-
throw new Exception\InvalidArgumentException(
402-
'"profiler" parameter must be an instance of ProfilerInterface or a boolean'
403-
);
393+
return $parameters['profiler'];
404394
}
405-
return $profiler;
395+
396+
if (is_bool($parameters['profiler'])) {
397+
return $parameters['profiler'] === true ? new Profiler\Profiler() : null;
398+
}
399+
400+
throw new Exception\InvalidArgumentException(
401+
'"profiler" parameter must be an instance of ProfilerInterface or a boolean'
402+
);
406403
}
407404

408405
/**
406+
* @deprecated
407+
*
409408
* @param array $parameters
410409
* @return Driver\DriverInterface
411-
* @throws \InvalidArgumentException
410+
* @throws InvalidArgumentException
412411
* @throws Exception\InvalidArgumentException
413-
* @deprecated
414412
*/
415413
protected function createDriverFromParameters(array $parameters)
416414
{
417415
return $this->createDriver($parameters);
418416
}
419417

420418
/**
421-
* @param Driver\DriverInterface $driver
422-
* @return Platform\PlatformInterface
423419
* @deprecated
420+
*
421+
* @return Platform\PlatformInterface
424422
*/
425423
protected function createPlatformFromDriver(Driver\DriverInterface $driver)
426424
{

src/Adapter/AdapterAbstractServiceFactory.php

+10-15
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
use Laminas\ServiceManager\AbstractFactoryInterface;
77
use Laminas\ServiceManager\ServiceLocatorInterface;
88

9+
use function is_array;
10+
911
/**
1012
* Database adapter abstract service factory.
1113
*
1214
* Allows configuring several database instances (such as writer and reader).
1315
*/
1416
class AdapterAbstractServiceFactory implements AbstractFactoryInterface
1517
{
16-
/**
17-
* @var array
18-
*/
18+
/** @var array */
1919
protected $config;
2020

2121
/**
2222
* Can we create an adapter by the requested name?
2323
*
24-
* @param ContainerInterface $container
2524
* @param string $requestedName
2625
* @return bool
2726
*/
@@ -32,17 +31,14 @@ public function canCreate(ContainerInterface $container, $requestedName)
3231
return false;
3332
}
3433

35-
return (
36-
isset($config[$requestedName])
34+
return isset($config[$requestedName])
3735
&& is_array($config[$requestedName])
38-
&& ! empty($config[$requestedName])
39-
);
36+
&& ! empty($config[$requestedName]);
4037
}
4138

4239
/**
4340
* Determine if we can create a service with name (SM v2 compatibility)
4441
*
45-
* @param ServiceLocatorInterface $serviceLocator
4642
* @param string $name
4743
* @param string $requestedName
4844
* @return bool
@@ -55,12 +51,11 @@ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator
5551
/**
5652
* Create a DB adapter
5753
*
58-
* @param ContainerInterface $container
5954
* @param string $requestedName
6055
* @param array $options
6156
* @return Adapter
6257
*/
63-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
58+
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
6459
{
6560
$config = $this->getConfig($container);
6661
return new Adapter($config[$requestedName]);
@@ -69,7 +64,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
6964
/**
7065
* Create service with name
7166
*
72-
* @param ServiceLocatorInterface $serviceLocator
7367
* @param string $name
7468
* @param string $requestedName
7569
* @return Adapter
@@ -82,7 +76,6 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
8276
/**
8377
* Get db configuration, if any
8478
*
85-
* @param ContainerInterface $container
8679
* @return array
8780
*/
8881
protected function getConfig(ContainerInterface $container)
@@ -97,15 +90,17 @@ protected function getConfig(ContainerInterface $container)
9790
}
9891

9992
$config = $container->get('config');
100-
if (! isset($config['db'])
93+
if (
94+
! isset($config['db'])
10195
|| ! is_array($config['db'])
10296
) {
10397
$this->config = [];
10498
return $this->config;
10599
}
106100

107101
$config = $config['db'];
108-
if (! isset($config['adapters'])
102+
if (
103+
! isset($config['adapters'])
109104
|| ! is_array($config['adapters'])
110105
) {
111106
$this->config = [];

0 commit comments

Comments
 (0)