Skip to content

Commit

Permalink
Structure: removed unused parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 12, 2025
1 parent d71cf33 commit 6850508
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/Database/IStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function getPrimaryKeySequence(string $table): ?string;
* Returns hasMany reference.
* If a targetTable is not provided, returns references for all tables.
*/
function getHasManyReference(string $table, ?string $targetTable = null): ?array;
function getHasManyReference(string $table): ?array;

/**
* Returns belongsTo reference.
* If a column is not provided, returns references for all columns.
*/
function getBelongsToReference(string $table, ?string $column = null): ?array;
function getBelongsToReference(string $table): ?array;

/**
* Rebuilds database structure cache.
Expand Down
30 changes: 4 additions & 26 deletions src/Database/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,41 +114,19 @@ public function getPrimaryKeySequence(string $table): ?string
}


public function getHasManyReference(string $table, ?string $targetTable = null): ?array
public function getHasManyReference(string $table): array
{
$this->needStructure();
$table = $this->resolveFQTableName($table);

if ($targetTable) {
$targetTable = $this->resolveFQTableName($targetTable);
foreach ($this->structure['hasMany'][$table] as $key => $value) {
if (strtolower($key) === $targetTable) {
return $this->structure['hasMany'][$table][$key];
}
}

return null;

} else {
return $this->structure['hasMany'][$table] ?? [];
}
return $this->structure['hasMany'][$table] ?? [];
}


public function getBelongsToReference(string $table, ?string $column = null): ?array
public function getBelongsToReference(string $table): array
{
$this->needStructure();
$table = $this->resolveFQTableName($table);

if ($column) {
$column = strtolower($column);
return isset($this->structure['belongsTo'][$table][$column])
? [$this->structure['belongsTo'][$table][$column], $column]
: null;

} else {
return $this->structure['belongsTo'][$table] ?? [];
}
return $this->structure['belongsTo'][$table] ?? [];
}


Expand Down
12 changes: 0 additions & 12 deletions tests/Database/Structure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ class StructureTestCase extends TestCase
Assert::same([
'Books' => ['author_id', 'translator_id'],
], $this->structure->getHasManyReference('authors'));

Assert::same(
['author_id', 'translator_id'],
$this->structure->getHasManyReference('authors', 'books'),
);
}


Expand All @@ -169,13 +164,6 @@ class StructureTestCase extends TestCase
'tag_id' => 'tags',
'book_id' => 'Books',
], $this->structure->getBelongsToReference('books_x_tags'));

Assert::same(
['Books', 'book_id'],
$this->structure->getBelongsToReference('books_x_tags', 'book_id'),
);

Assert::null($this->structure->getBelongsToReference('books_x_tags', 'non_exist'));
}


Expand Down

0 comments on commit 6850508

Please sign in to comment.