final class RowMatch

Finds a row among rows, by the columns that identify it.

Nothing here knows about foreign keys or about mutations. It answers the one question every part of the shadow keeps asking — is this the same row, and where is it — so that the answer is given the same way everywhere.

Type Aliases§

Row = import from TableDefinition
RowValue = import from TableDefinition

Methods§

public function valuesOf(Row $row, list<string> $columns): list<RowValue>|null

Reads the values a row carries in the named columns.

A row that does not carry one of them cannot be compared on them at all, which is different from carrying null there, so it answers nothing rather than a list with a hole in it.

Parameters

$rowRowRow to read
$columnslist<string>Columns to read, in order

Returns

list<RowValue>|null The values, or null when the row lacks one of the columns
Test cases 3
Called from 4
Calls 1
  • function-call array_key_exists line 37
public function carries(Row $row, list<string> $columns, list<RowValue> $values): bool

Reports whether a row carries exactly these values in these columns.

Parameters

$rowRowRow to test
$columnslist<string>Columns to test, in order
$valueslist<RowValue>Values they must carry, in the same order

Returns

bool True when every column carries the value paired with it
Test cases 3
Called from 3
Calls 1
  • function-call array_key_exists line 58
public function agreeOn(Row $left, Row $right, list<string> $keys): bool
public function sameRow(Row $left, Row $right): bool

Reports whether two rows carry the same columns with the same values.

Column order is not part of a row's identity: the same columns carrying the same values are the same row however the reader happened to order them.

Parameters

$leftRowOne row
$rightRowThe other

Returns

bool True when neither carries a column the other lacks, and both agree everywhere
Test cases 5
Called from 2
Calls 3
public function identifies(Row $left, Row $right, array<int, string> $keys): bool

Reports whether two rows are the same row of a table keyed like this.

A table with a key is identified by it, and two rows agreeing on it are the same row however else they differ. A table with no key has nothing to be identified by, so being the same row means carrying everything the same.

Parameters

$leftRowOne row
$rightRowThe other
$keysarray<int, string>Columns that identify a row, or none where the table declares none

Returns

bool True when the table cannot tell the two apart
Test cases 4
Called from 3
Calls 3
public function positionOfSameKey(
    array<int, Row> $rows,
    Row $candidate,
    list<string> $keys,
    list<int> $excluded,
): int|null

Answers where a row with the same key is, among rows not already taken.

Rows already paired off are excluded so that two rows sharing a key are paired one to one rather than both to the first match.

Parameters

$rowsarray<int, Row>Rows to search
$candidateRowRow to look for
$keyslist<string>Columns that identify a row
$excludedlist<int>Positions already paired off

Returns

int|null Position of the match, or null when there is none left
Test cases 3
Called from 4
Calls 2
public function positionOfIdentical(
    array<int, Row> $rows,
    Row $candidate,
    list<int> $excluded,
): int|null

Answers where an identical row is, among rows not already taken.

A table with no key has nothing to be identified by, so the whole row is what has to match.

Parameters

$rowsarray<int, Row>Rows to search
$candidateRowRow to look for
$excludedlist<int>Positions already paired off

Returns

int|null Position of the match, or null when there is none left
Test cases 3
Called from 1
Calls 1

Test cases 38§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 22
Other tests reaching this symbol 16

Relations§

Instantiated in 7
Method calls 16
Type declarations 7