Skip to content

Commit abac8b9

Browse files
authored
Merge branch '0.6.x' into fix/scalar-specification-parameters
2 parents debc55c + 20fb241 commit abac8b9

55 files changed

Lines changed: 1431 additions & 1519 deletions

Some content is hidden

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

‎analyzer-baseline.toml‎

Lines changed: 53 additions & 1049 deletions
Large diffs are not rendered by default.

‎lint-baseline.toml‎

Lines changed: 0 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -1,209 +1,11 @@
11
variant = "loose"
22

3-
[[issues]]
4-
file = "src/Adapter/Adapter.php"
5-
code = "prefer-first-class-callable"
6-
message = "Use first-class callable syntax `...` instead of a closure."
7-
count = 2
8-
9-
[[issues]]
10-
file = "src/Adapter/AdapterAwareInterface.php"
11-
code = "strict-types"
12-
message = "Missing `declare(strict_types=1);` statement at the beginning of the file."
13-
count = 1
14-
15-
[[issues]]
16-
file = "src/Adapter/AdapterAwareTrait.php"
17-
code = "strict-types"
18-
message = "Missing `declare(strict_types=1);` statement at the beginning of the file."
19-
count = 1
20-
21-
[[issues]]
22-
file = "src/Adapter/Driver/ConnectionInterface.php"
23-
code = "too-many-methods"
24-
message = "Interface has too many methods."
25-
count = 1
26-
27-
[[issues]]
28-
file = "src/Adapter/Driver/Pdo/AbstractPdo.php"
29-
code = "literal-named-argument"
30-
message = "Literal argument `':'` should be passed as a named argument for clarity."
31-
count = 1
32-
33-
[[issues]]
34-
file = "src/Adapter/Driver/Pdo/AbstractPdo.php"
35-
code = "no-else-clause"
36-
message = "Avoid `else` clauses."
37-
count = 1
38-
39-
[[issues]]
40-
file = "src/Adapter/Driver/Pdo/AbstractPdo.php"
41-
code = "tagged-todo"
42-
message = "TODO should be tagged with (@username) or (#issue)."
43-
count = 1
44-
45-
[[issues]]
46-
file = "src/Adapter/Driver/Pdo/Result.php"
47-
code = "halstead"
48-
message = "Method has a high halstead difficulty"
49-
count = 1
50-
51-
[[issues]]
52-
file = "src/Adapter/Driver/Pdo/Result.php"
53-
code = "literal-named-argument"
54-
message = "Literal argument `true` should be passed as a named argument for clarity."
55-
count = 2
56-
57-
[[issues]]
58-
file = "src/Adapter/Driver/Pdo/Result.php"
59-
code = "no-else-clause"
60-
message = "Avoid `else` clauses."
61-
count = 1
62-
63-
[[issues]]
64-
file = "src/Adapter/Driver/Pdo/Result.php"
65-
code = "too-many-methods"
66-
message = "Class has too many methods."
67-
count = 1
68-
69-
[[issues]]
70-
file = "src/Adapter/Driver/Pdo/Statement.php"
71-
code = "literal-named-argument"
72-
message = "Literal argument `':'` should be passed as a named argument for clarity."
73-
count = 1
74-
75-
[[issues]]
76-
file = "src/Adapter/Driver/Pdo/Statement.php"
77-
code = "no-else-clause"
78-
message = "Avoid `else` clauses."
79-
count = 2
80-
81-
[[issues]]
82-
file = "src/Adapter/Driver/Pdo/Statement.php"
83-
code = "no-isset"
84-
message = "Use of the `isset` construct."
85-
count = 1
86-
873
[[issues]]
884
file = "src/Adapter/ParameterContainer.php"
895
code = "cyclomatic-complexity"
906
message = "Class has high complexity."
917
count = 1
928

93-
[[issues]]
94-
file = "src/Adapter/ParameterContainer.php"
95-
code = "halstead"
96-
message = "Method has a high halstead difficulty"
97-
count = 1
98-
99-
[[issues]]
100-
file = "src/Adapter/ParameterContainer.php"
101-
code = "kan-defect"
102-
message = "Class has a high kan defect score."
103-
count = 1
104-
105-
[[issues]]
106-
file = "src/Adapter/ParameterContainer.php"
107-
code = "literal-named-argument"
108-
message = "Literal argument `':'` should be passed as a named argument for clarity."
109-
count = 1
110-
111-
[[issues]]
112-
file = "src/Adapter/ParameterContainer.php"
113-
code = "literal-named-argument"
114-
message = "Literal argument `1` should be passed as a named argument for clarity."
115-
count = 2
116-
117-
[[issues]]
118-
file = "src/Adapter/ParameterContainer.php"
119-
code = "no-else-clause"
120-
message = "Avoid `else` clauses."
121-
count = 2
122-
123-
[[issues]]
124-
file = "src/Adapter/ParameterContainer.php"
125-
code = "no-else-clause"
126-
message = "Avoid `elseif` clauses."
127-
count = 3
128-
129-
[[issues]]
130-
file = "src/Adapter/ParameterContainer.php"
131-
code = "no-isset"
132-
message = "Use of the `isset` construct."
133-
count = 11
134-
135-
[[issues]]
136-
file = "src/Adapter/ParameterContainer.php"
137-
code = "too-many-methods"
138-
message = "Class has too many methods."
139-
count = 1
140-
141-
[[issues]]
142-
file = "src/Adapter/Platform/AbstractPlatform.php"
143-
code = "literal-named-argument"
144-
message = '''Literal argument `"\x00\n\r\\'\"\x1a"` should be passed as a named argument for clarity.'''
145-
count = 2
146-
147-
[[issues]]
148-
file = "src/Adapter/Platform/AbstractPlatform.php"
149-
code = "literal-named-argument"
150-
message = '''Literal argument `'\\"'` should be passed as a named argument for clarity.'''
151-
count = 1
152-
153-
[[issues]]
154-
file = "src/Adapter/Platform/AbstractPlatform.php"
155-
code = "no-else-clause"
156-
message = "Avoid `else` clauses."
157-
count = 1
158-
159-
[[issues]]
160-
file = "src/Adapter/Platform/AbstractPlatform.php"
161-
code = "no-isset"
162-
message = "Use of the `isset` construct."
163-
count = 2
164-
165-
[[issues]]
166-
file = "src/Adapter/Platform/PlatformInterface.php"
167-
code = "too-many-methods"
168-
message = "Interface has too many methods."
169-
count = 1
170-
171-
[[issues]]
172-
file = "src/Adapter/Platform/Sql92.php"
173-
code = "literal-named-argument"
174-
message = '''Literal argument `"\x00\n\r\\'\"\x1a"` should be passed as a named argument for clarity.'''
175-
count = 1
176-
177-
[[issues]]
178-
file = "src/Adapter/Platform/Sql92.php"
179-
code = "no-isset"
180-
message = "Use of the `isset` construct."
181-
count = 1
182-
183-
[[issues]]
184-
file = "src/Adapter/Profiler/Profiler.php"
185-
code = "no-else-clause"
186-
message = "Avoid `else` clauses."
187-
count = 1
188-
189-
[[issues]]
190-
file = "src/Adapter/Profiler/Profiler.php"
191-
code = "no-isset"
192-
message = "Use of the `isset` construct."
193-
count = 1
194-
195-
[[issues]]
196-
file = "src/Adapter/SchemaAwareInterface.php"
197-
code = "tagged-todo"
198-
message = "TODO should be tagged with (@username) or (#issue)."
199-
count = 1
200-
201-
[[issues]]
202-
file = "src/Adapter/StatementContainer.php"
203-
code = "strict-types"
204-
message = "Missing `declare(strict_types=1);` statement at the beginning of the file."
205-
count = 1
206-
2079
[[issues]]
20810
file = "src/Container/AbstractAdapterInterfaceFactory.php"
20911
code = "no-empty"

‎mago.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ baseline = "lint-baseline.toml"
1818
# not apply. Predicate, AlterTable, CreateTable, Select, Insert and Update are fluent builders:
1919
# one public method per clause they can emit, so their method count is the size of their
2020
# public API. AbstractSql is their base and carries one protected hook per clause it renders.
21+
# ConnectionInterface and PlatformInterface are the contracts every driver and platform package
22+
# implements, so their method count is the size of that contract. Pdo\Result implements Iterator,
23+
# Countable and ResultInterface, and ParameterContainer implements Iterator, ArrayAccess and
24+
# Countable beside its errata and max-length accessors: in both, the count is fixed by the
25+
# interfaces and the public API.
2126
# "test/" repeats the phpdb-qa-tools default, which this key replaces.
2227
too-many-methods = { exclude = [
2328
"test/",
29+
"src/Adapter/Driver/ConnectionInterface.php",
30+
"src/Adapter/Driver/Pdo/Result.php",
31+
"src/Adapter/ParameterContainer.php",
32+
"src/Adapter/Platform/PlatformInterface.php",
2433
"src/Sql/Exception/",
2534
"src/Sql/Predicate/Exception/",
2635
"src/TableGateway/Exception/",
@@ -62,6 +71,8 @@ ignore = [
6271
{ code = "invalid-enum-case-value", in = ["src/Sql/ArgumentType.php"] },
6372
]
6473
class-initializers = [
74+
"PhpDb\\Adapter\\Driver\\Pdo\\Statement::initialize",
75+
"PhpDb\\Adapter\\Driver\\Pdo\\Statement::setDriver",
6576
"PhpDb\\ResultSet\\AbstractResultSet::initialize",
6677
"PhpDb\\TableGateway\\Feature\\AbstractFeature::setTableGateway",
6778
"PhpDb\\RowGateway\\Feature\\AbstractFeature::setRowGateway",

‎src/Adapter/Adapter.php‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use function is_array;
1313
use function strtolower;
1414

15+
/**
16+
* @api
17+
*/
1518
class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface, SchemaAwareInterface
1619
{
1720
/**
@@ -30,6 +33,8 @@ public function __construct(
3033

3134
/**
3235
* Create statement
36+
*
37+
* @param ParameterContainer|array<array-key, mixed> $initialParameters
3338
*/
3439
#[Override]
3540
public function createStatement(
@@ -83,24 +88,31 @@ public function getDriver(): Driver\DriverInterface
8388

8489
/**
8590
* {@inheritDoc}
91+
*
92+
* Each argument names a helper, and the match is strict, so an argument that is not one of
93+
* the FUNCTION_* names, whatever its type, adds no helper.
94+
*
95+
* Every helper names its parameter $value so callers can pass it by name, which is why
96+
* quoteIdentifier(), whose own parameter is $identifier, sits behind a forwarding closure.
97+
*
98+
* @mago-expect analysis:mixed-assignment
99+
* @mago-expect lint:prefer-first-class-callable
86100
*/
87101
#[Override]
88102
public function getHelpers()
89103
{
90104
$functions = [];
91105
$platform = $this->platform;
92106
foreach (func_get_args() as $arg) {
93-
switch ($arg) {
94-
case self::FUNCTION_QUOTE_IDENTIFIER:
95-
$functions[] = static function ($value) use ($platform) {
96-
return $platform->quoteIdentifier($value);
97-
};
98-
break;
99-
case self::FUNCTION_QUOTE_VALUE:
100-
$functions[] = static function ($value) use ($platform) {
101-
return $platform->quoteValue($value);
102-
};
103-
break;
107+
$function = match ($arg) {
108+
self::FUNCTION_QUOTE_IDENTIFIER => static fn(string $value): string => $platform->quoteIdentifier(
109+
$value,
110+
),
111+
self::FUNCTION_QUOTE_VALUE => $platform->quoteValue(...),
112+
default => null,
113+
};
114+
if (null !== $function) {
115+
$functions[] = $function;
104116
}
105117
}
106118
return $functions;
@@ -129,6 +141,8 @@ public function getQueryResultSetPrototype(): ResultSet\ResultSetInterface
129141
*
130142
* Always prepares the statement; never executes it. Use executeQuery()
131143
* to run the returned statement.
144+
*
145+
* @param ParameterContainer|array<array-key, mixed> $parameters
132146
*/
133147
#[Override]
134148
public function prepareQuery(
@@ -152,6 +166,8 @@ public function prepareQuery(
152166
*
153167
* @deprecated Use prepareQuery() and executeQuery() instead. query() will be removed in a future version.
154168
*
169+
* @param ParameterContainer|array<array-key, mixed>|string $parametersOrQueryMode
170+
*
155171
* @throws Exception\InvalidArgumentException
156172
* @throws Exception\RuntimeException When execution did not produce a result.
157173
* @throws PhpException

‎src/Adapter/AdapterAwareInterface.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PhpDb\Adapter;
46

7+
/**
8+
* @api
9+
*/
510
interface AdapterAwareInterface
611
{
712
/** Set db adapter */

‎src/Adapter/AdapterAwareTrait.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace PhpDb\Adapter;
46

7+
/**
8+
* @api
9+
*/
510
trait AdapterAwareTrait
611
{
712
protected AdapterInterface $adapter;

0 commit comments

Comments
 (0)