Skip to content

Commit fdebf73

Browse files
committed
Structure: removed unused parameter
1 parent a5d594a commit fdebf73

7 files changed

+16
-50
lines changed

Diff for: src/Database/IStructure.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ function getPrimaryKeySequence(string $table): ?string;
5858
* Returns hasMany reference.
5959
* If a targetTable is not provided, returns references for all tables.
6060
*/
61-
function getHasManyReference(string $table, ?string $targetTable = null): ?array;
61+
function getHasManyReference(string $table): ?array;
6262

6363
/**
6464
* Returns belongsTo reference.
6565
* If a column is not provided, returns references for all columns.
6666
*/
67-
function getBelongsToReference(string $table, ?string $column = null): ?array;
67+
function getBelongsToReference(string $table): ?array;
6868

6969
/**
7070
* Rebuilds database structure cache.

Diff for: src/Database/Structure.php

+4-26
Original file line numberDiff line numberDiff line change
@@ -114,41 +114,19 @@ public function getPrimaryKeySequence(string $table): ?string
114114
}
115115

116116

117-
public function getHasManyReference(string $table, ?string $targetTable = null): ?array
117+
public function getHasManyReference(string $table): array
118118
{
119119
$this->needStructure();
120120
$table = $this->resolveFQTableName($table);
121-
122-
if ($targetTable) {
123-
$targetTable = $this->resolveFQTableName($targetTable);
124-
foreach ($this->structure['hasMany'][$table] as $key => $value) {
125-
if (strtolower($key) === $targetTable) {
126-
return $this->structure['hasMany'][$table][$key];
127-
}
128-
}
129-
130-
return null;
131-
132-
} else {
133-
return $this->structure['hasMany'][$table] ?? [];
134-
}
121+
return $this->structure['hasMany'][$table] ?? [];
135122
}
136123

137124

138-
public function getBelongsToReference(string $table, ?string $column = null): ?array
125+
public function getBelongsToReference(string $table): array
139126
{
140127
$this->needStructure();
141128
$table = $this->resolveFQTableName($table);
142-
143-
if ($column) {
144-
$column = strtolower($column);
145-
return isset($this->structure['belongsTo'][$table][$column])
146-
? [$this->structure['belongsTo'][$table][$column], $column]
147-
: null;
148-
149-
} else {
150-
return $this->structure['belongsTo'][$table] ?? [];
151-
}
129+
return $this->structure['belongsTo'][$table] ?? [];
152130
}
153131

154132

Diff for: tests/Database/Helpers.parseColumnType.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ Assert::same(['type' => 'DECIMAL', 'length' => 10, 'scale' => 2, 'parameters' =>
2929
$result = Helpers::parseColumnType("ENUM('value1','value2')");
3030
Assert::same(['type' => 'ENUM', 'length' => null, 'scale' => null, 'parameters' => "'value1','value2'"], $result);
3131

32-
// Test omitted typ
32+
// Test omitted type
3333
$result = Helpers::parseColumnType('');
3434
Assert::same(['type' => null, 'length' => null, 'scale' => null, 'parameters' => null], $result);

Diff for: tests/Database/Reflection.columns.sqlite.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ $expectedColumns = [
289289
'autoIncrement' => false,
290290
'primary' => false,
291291
],
292-
'empty' => [
293-
'name' => 'empty',
292+
'omitted' => [
293+
'name' => 'omitted',
294294
'table' => 'types',
295295
'nativeType' => 'BLOB',
296296
'size' => null,

Diff for: tests/Database/ResultSet.normalizeRow.sqlite.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Assert::equal([
4646
'boolean' => true,
4747
'date' => new DateTime('2012-10-13'),
4848
'datetime' => new DateTime('2012-10-13 10:10:10'),
49-
'empty' => 'a',
49+
'omitted' => 'a',
5050
], (array) $res->fetch());
5151

5252
Assert::equal([
@@ -77,7 +77,7 @@ Assert::equal([
7777
'boolean' => false,
7878
'date' => new DateTime('1970-01-01'),
7979
'datetime' => new DateTime('1970-01-01 00:00:00'),
80-
'empty' => '',
80+
'omitted' => '',
8181
], (array) $res->fetch());
8282

8383
Assert::same([
@@ -108,7 +108,7 @@ Assert::same([
108108
'boolean' => null,
109109
'date' => null,
110110
'datetime' => null,
111-
'empty' => null,
111+
'omitted' => null,
112112
], (array) $res->fetch());
113113

114114

Diff for: tests/Database/Structure.phpt

-12
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ class StructureTestCase extends TestCase
148148
Assert::same([
149149
'Books' => ['author_id', 'translator_id'],
150150
], $this->structure->getHasManyReference('authors'));
151-
152-
Assert::same(
153-
['author_id', 'translator_id'],
154-
$this->structure->getHasManyReference('authors', 'books'),
155-
);
156151
}
157152

158153

@@ -169,13 +164,6 @@ class StructureTestCase extends TestCase
169164
'tag_id' => 'tags',
170165
'book_id' => 'Books',
171166
], $this->structure->getBelongsToReference('books_x_tags'));
172-
173-
Assert::same(
174-
['Books', 'book_id'],
175-
$this->structure->getBelongsToReference('books_x_tags', 'book_id'),
176-
);
177-
178-
Assert::null($this->structure->getBelongsToReference('books_x_tags', 'non_exist'));
179167
}
180168

181169

Diff for: tests/Database/files/sqlite-nette_test3.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ CREATE TEMPORARY TABLE types (
2626
[boolean] BOOLEAN,
2727
[date] DATE,
2828
[datetime] DATETIME,
29-
[empty]
29+
[omitted]
3030
);
3131

3232

@@ -59,7 +59,7 @@ INSERT INTO types VALUES
5959
1, --boolean
6060
1350079200, --date
6161
1350115810, --datetime
62-
'a' --empty
62+
'a' --omitted
6363
);
6464

6565

@@ -91,7 +91,7 @@ INSERT INTO types VALUES (
9191
0, --boolean
9292
-3600, --date
9393
-3600, --datetime
94-
'' --empty
94+
'' --omitted
9595
);
9696

9797

@@ -123,5 +123,5 @@ INSERT INTO types VALUES (
123123
NULL, --boolean
124124
NULL, --date
125125
NULL, --datetime
126-
NULL --empty
126+
NULL --omitted
127127
);

0 commit comments

Comments
 (0)