Skip to content

Commit 0e5d1a8

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
Conflicts: system/Database/BaseConnection.php
2 parents 32df1ab + d7449f6 commit 0e5d1a8

19 files changed

+971
-82
lines changed

.php-cs-fixer.dist.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,35 @@
4343
__DIR__ . '/spark',
4444
]);
4545

46-
$overrides = [];
46+
$overrides = [
47+
'phpdoc_no_alias_tag' => [
48+
'replacements' => [
49+
'type' => 'var',
50+
'link' => 'see',
51+
],
52+
],
53+
'phpdoc_align' => [
54+
'align' => 'vertical',
55+
'spacing' => 1,
56+
'tags' => [
57+
'method',
58+
'param',
59+
'phpstan-assert',
60+
'phpstan-assert-if-true',
61+
'phpstan-assert-if-false',
62+
'phpstan-param',
63+
'phpstan-property',
64+
'phpstan-return',
65+
'property',
66+
'property-read',
67+
'property-write',
68+
'return',
69+
'throws',
70+
'type',
71+
'var',
72+
],
73+
],
74+
];
4775

4876
$options = [
4977
'cacheFile' => 'build/.php-cs-fixer.cache',

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"phpunit/phpcov": "^8.2",
3333
"phpunit/phpunit": "^9.1",
3434
"predis/predis": "^1.1 || ^2.0",
35-
"rector/rector": "0.19.8",
35+
"rector/rector": "1.0.0",
3636
"vimeo/psalm": "^5.0"
3737
},
3838
"replace": {

phpstan-baseline.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,6 @@
556556
'count' => 1,
557557
'path' => __DIR__ . '/system/Database/Config.php',
558558
];
559-
$ignoreErrors[] = [
560-
'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\ConnectionInterface\\:\\:\\$DBDriver\\.$#',
561-
'count' => 2,
562-
'path' => __DIR__ . '/system/Database/Database.php',
563-
];
564-
$ignoreErrors[] = [
565-
'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\ConnectionInterface\\:\\:\\$connID\\.$#',
566-
'count' => 2,
567-
'path' => __DIR__ . '/system/Database/Database.php',
568-
];
569559
$ignoreErrors[] = [
570560
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
571561
'count' => 2,

system/Database/BaseConnection.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@
2020
use Throwable;
2121

2222
/**
23-
* @property array $aliasedTables
24-
* @property string $charset
25-
* @property bool $compress
26-
* @property float $connectDuration
27-
* @property float $connectTime
28-
* @property string $database
29-
* @property string $DBCollat
30-
* @property bool $DBDebug
31-
* @property string $DBDriver
32-
* @property string $DBPrefix
33-
* @property string $DSN
34-
* @property array|bool $encrypt
35-
* @property array $failover
36-
* @property string $hostname
37-
* @property Query $lastQuery
38-
* @property string $password
39-
* @property bool $pConnect
40-
* @property int|string $port
41-
* @property bool $pretend
42-
* @property string $queryClass
43-
* @property array $reservedIdentifiers
44-
* @property bool $strictOn
45-
* @property string $subdriver
46-
* @property string $swapPre
47-
* @property int $transDepth
48-
* @property bool $transFailure
49-
* @property bool $transStatus
50-
* @property string $username
23+
* @property-read array $aliasedTables
24+
* @property-read string $charset
25+
* @property-read bool $compress
26+
* @property-read float $connectDuration
27+
* @property-read float $connectTime
28+
* @property-read string $database
29+
* @property-read string $DBCollat
30+
* @property-read bool $DBDebug
31+
* @property-read string $DBDriver
32+
* @property-read string $DBPrefix
33+
* @property-read string $DSN
34+
* @property-read array|bool $encrypt
35+
* @property-read array $failover
36+
* @property-read string $hostname
37+
* @property-read Query $lastQuery
38+
* @property-read string $password
39+
* @property-read bool $pConnect
40+
* @property-read int|string $port
41+
* @property-read bool $pretend
42+
* @property-read string $queryClass
43+
* @property-read array $reservedIdentifiers
44+
* @property-read bool $strictOn
45+
* @property-read string $subdriver
46+
* @property-read string $swapPre
47+
* @property-read int $transDepth
48+
* @property-read bool $transFailure
49+
* @property-read bool $transStatus
50+
* @property-read string $username
5151
*
5252
* @template TConnection
5353
* @template TResult

system/Database/ConnectionInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
/**
1717
* @template TConnection
1818
* @template TResult
19+
*
20+
* @property false|object|resource $connID
21+
* @property-read string $DBDriver
1922
*/
2023
interface ConnectionInterface
2124
{

system/Database/Postgre/Builder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,16 @@ private function getFieldType(string $table, string $fieldName): ?string
433433
$this->QBOptions['fieldTypes'][$table] = [];
434434

435435
foreach ($this->db->getFieldData($table) as $field) {
436-
$this->QBOptions['fieldTypes'][$table][$field->name] = $field->type;
436+
$type = $field->type;
437+
438+
// If `character` (or `char`) lacks a specifier, it is equivalent
439+
// to `character(1)`.
440+
// See https://www.postgresql.org/docs/current/datatype-character.html
441+
if ($field->type === 'character') {
442+
$type = $field->type . '(' . $field->max_length . ')';
443+
}
444+
445+
$this->QBOptions['fieldTypes'][$table][$field->name] = $type;
437446
}
438447
}
439448

system/View/Parser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ public function renderString(string $template, ?array $options = null, ?bool $sa
190190
* so that the variable is correctly handled within the
191191
* parsing itself, and contexts (including raw) are respected.
192192
*
193-
* @param non-empty-string|null $context The context to escape it for: html, css, js, url, raw
194-
* If 'raw', no escaping will happen
193+
* @param non-empty-string|null $context The context to escape it for.
194+
* If 'raw', no escaping will happen.
195+
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
195196
*/
196197
public function setData(array $data = [], ?string $context = null): RendererInterface
197198
{

system/View/RendererInterface.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ interface RendererInterface
2424
* Builds the output based upon a file name and any
2525
* data that has already been set.
2626
*
27-
* @param array $options Reserved for 3rd-party uses since
28-
* it might be needed to pass additional info
29-
* to other template engines.
30-
* @param bool $saveData Whether to save data for subsequent calls
27+
* @param array|null $options Reserved for 3rd-party uses since
28+
* it might be needed to pass additional info
29+
* to other template engines.
30+
* @param bool $saveData Whether to save data for subsequent calls
3131
*/
3232
public function render(string $view, ?array $options = null, bool $saveData = false): string;
3333

3434
/**
3535
* Builds the output based upon a string and any
3636
* data that has already been set.
3737
*
38-
* @param string $view The view contents
39-
* @param array $options Reserved for 3rd-party uses since
40-
* it might be needed to pass additional info
41-
* to other template engines.
42-
* @param bool $saveData Whether to save data for subsequent calls
38+
* @param string $view The view contents
39+
* @param array|null $options Reserved for 3rd-party uses since
40+
* it might be needed to pass additional info
41+
* to other template engines.
42+
* @param bool $saveData Whether to save data for subsequent calls
4343
*/
4444
public function renderString(string $view, ?array $options = null, bool $saveData = false): string;
4545

4646
/**
4747
* Sets several pieces of view data at once.
4848
*
49-
* @param string $context The context to escape it for: html, css, js, url
50-
* If 'raw', no escaping will happen
49+
* @param non-empty-string|null $context The context to escape it for.
50+
* If 'raw', no escaping will happen.
5151
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
5252
*
5353
* @return RendererInterface
@@ -58,8 +58,8 @@ public function setData(array $data = [], ?string $context = null);
5858
* Sets a single piece of view data.
5959
*
6060
* @param mixed $value
61-
* @param string $context The context to escape it for: html, css, js, url
62-
* If 'raw' no escaping will happen
61+
* @param non-empty-string|null $context The context to escape it for.
62+
* If 'raw', no escaping will happen.
6363
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
6464
*
6565
* @return RendererInterface

system/View/View.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ public function excerpt(string $string, int $length = 20): string
346346
/**
347347
* Sets several pieces of view data at once.
348348
*
349-
* @param string|null $context The context to escape it for: html, css, js, url
350-
* If null, no escaping will happen
349+
* @param non-empty-string|null $context The context to escape it for.
350+
* If 'raw', no escaping will happen.
351351
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
352352
*/
353353
public function setData(array $data = [], ?string $context = null): RendererInterface
@@ -366,8 +366,8 @@ public function setData(array $data = [], ?string $context = null): RendererInte
366366
* Sets a single piece of view data.
367367
*
368368
* @param mixed $value
369-
* @param string|null $context The context to escape it for: html, css, js, url
370-
* If null, no escaping will happen
369+
* @param non-empty-string|null $context The context to escape it for.
370+
* If 'raw', no escaping will happen.
371371
* @phpstan-param null|'html'|'js'|'css'|'url'|'attr'|'raw' $context
372372
*/
373373
public function setVar(string $name, $value = null, ?string $context = null): RendererInterface

tests/system/Database/Live/AbstractGetFieldDataTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,64 @@ protected function createTableForDefault()
9898
$this->forge->createTable($this->table);
9999
}
100100

101+
protected function createTableForType()
102+
{
103+
$this->forge->dropTable($this->table, true);
104+
105+
// missing types:
106+
// TINYINT,MEDIUMINT,BIT,YEAR,BINARY,VARBINARY,TINYTEXT,LONGTEXT,
107+
// JSON,Spatial data types
108+
// `id` must be INTEGER else SQLite3 error on not null for autoincrement field.
109+
$fields = [
110+
'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true],
111+
'type_varchar' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
112+
'type_char' => ['type' => 'CHAR', 'constraint' => 10, 'null' => true],
113+
// TEXT should not be used on SQLSRV. It is deprecated.
114+
'type_text' => ['type' => 'TEXT', 'null' => true],
115+
'type_smallint' => ['type' => 'SMALLINT', 'null' => true],
116+
'type_integer' => ['type' => 'INTEGER', 'null' => true],
117+
'type_float' => ['type' => 'FLOAT', 'null' => true],
118+
'type_numeric' => ['type' => 'NUMERIC', 'constraint' => '18,2', 'null' => true],
119+
'type_date' => ['type' => 'DATE', 'null' => true],
120+
'type_time' => ['type' => 'TIME', 'null' => true],
121+
// On SQLSRV `datetime2` is recommended.
122+
'type_datetime' => ['type' => 'DATETIME', 'null' => true],
123+
'type_timestamp' => ['type' => 'TIMESTAMP', 'null' => true],
124+
'type_bigint' => ['type' => 'BIGINT', 'null' => true],
125+
'type_real' => ['type' => 'REAL', 'null' => true],
126+
'type_enum' => ['type' => 'ENUM', 'constraint' => ['appel', 'pears'], 'null' => true],
127+
'type_set' => ['type' => 'SET', 'constraint' => ['one', 'two'], 'null' => true],
128+
'type_mediumtext' => ['type' => 'MEDIUMTEXT', 'null' => true],
129+
'type_double' => ['type' => 'DOUBLE', 'null' => true],
130+
'type_decimal' => ['type' => 'DECIMAL', 'constraint' => '18,4', 'null' => true],
131+
'type_blob' => ['type' => 'BLOB', 'null' => true],
132+
'type_boolean' => ['type' => 'BOOLEAN', 'null' => true],
133+
];
134+
135+
if ($this->db->DBDriver === 'Postgre') {
136+
unset(
137+
$fields['type_enum'],
138+
$fields['type_set'],
139+
$fields['type_mediumtext'],
140+
$fields['type_double'],
141+
$fields['type_blob']
142+
);
143+
}
144+
145+
if ($this->db->DBDriver === 'SQLSRV') {
146+
unset(
147+
$fields['type_set'],
148+
$fields['type_mediumtext'],
149+
$fields['type_double'],
150+
$fields['type_blob']
151+
);
152+
}
153+
154+
$this->forge->addField($fields);
155+
$this->forge->addKey('id', true);
156+
$this->forge->createTable($this->table);
157+
}
158+
101159
abstract public function testGetFieldDataDefault(): void;
102160

103161
protected function assertSameFieldData(array $expected, array $actual)

0 commit comments

Comments
 (0)