final class UpsertNumber

Does arithmetic the way a database does it, over the values a row carries.

Two things separate this from PHP's own operators. A row value arrives as text however it was declared, so '12' is a number here; and null is unknown rather than zero, so anything touching it is unknown too.

Type Aliases§

RowValue = import from TableDefinition

Methods§

public function of(mixed $value): int|float

Reads a value as the number it stands for.

A string is read as an integer unless it is written the way a float is, which keeps whole numbers exact however the driver handed them over.

Parameters

$valuemixedValue to read

Returns

int|float The number it stands for

Throws

UnsupportedSqlException When the value is not written as a number
Test cases 16
Called from 11
Calls 6
public function isNumeric(mixed $value): bool

Reports whether a value is one arithmetic can be done on.

Parameters

$valuemixedValue to test

Returns

bool True when it is a number or written as one
Test cases 1
Called from 3
Calls 4
public function positive(mixed $value): int|float|null

Answers the value with its sign kept, as a number.

Parameters

$valuemixedValue to read

Returns

int|float|null The number, or null when the value is unknown

Throws

UnsupportedSqlException When the value is not written as a number
Test cases 2
Called from 1
Calls 1
public function negative(mixed $value): int|float|null

Answers the value with its sign turned around.

Parameters

$valuemixedValue to read

Returns

int|float|null The number, or null when the value is unknown

Throws

UnsupportedSqlException When the value is not written as a number
Test cases 2
Called from 1
Calls 1
public function add(mixed $left, mixed $right): int|float|null

Adds two values.

Parameters

$leftmixedLeft operand
$rightmixedRight operand

Returns

int|float|null The sum, or null when either is unknown

Throws

UnsupportedSqlException When either is not written as a number
Test cases 2
Called from 1
Calls 1
public function subtract(mixed $left, mixed $right): int|float|null

Subtracts the right value from the left.

Parameters

$leftmixedLeft operand
$rightmixedRight operand

Returns

int|float|null The difference, or null when either is unknown

Throws

UnsupportedSqlException When either is not written as a number
Test cases 2
Called from 1
Calls 1
public function multiply(mixed $left, mixed $right): int|float|null

Multiplies two values.

Parameters

$leftmixedLeft operand
$rightmixedRight operand

Returns

int|float|null The product, or null when either is unknown

Throws

UnsupportedSqlException When either is not written as a number
Test cases 2
Called from 1
Calls 1
public function divide(mixed $left, mixed $right): int|float|null

Divides the left value by the right.

Parameters

$leftmixedLeft operand
$rightmixedRight operand

Returns

int|float|null The quotient, or null when either is unknown

Throws

UnsupportedSqlException When either is not a number, or the divisor is zero
Test cases 4
Called from 1
Calls 2
public function modulo(mixed $left, mixed $right): int|null

Answers what is left over when the left value is divided by the right.

Both sides are taken as whole numbers first, which is what SQL's own modulo does with a fractional operand.

Parameters

$leftmixedLeft operand
$rightmixedRight operand

Returns

int|null The remainder, or null when either is unknown

Throws

UnsupportedSqlException When either is not a number, or the divisor is zero
Test cases 4
Called from 1
Calls 3

Test cases 33§

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

Dedicated tests 24
Other tests reaching this symbol 9

Relations§

Instantiated in 3
Method calls 12
Type declarations 3