classUpsertNumber
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 TableDefinitionMethods§
public function of(mixed $value): int|floatReads 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
$value | mixed | Value to read |
Returns
int|float The number it stands forThrows
UnsupportedSqlException When the value is not written as a numberTest cases 16
UpsertNumberTest::testAddSumsBothSidescoversUpsertNumberTest::testDivideDividesTheLeftSideByTheRightcoversUpsertNumberTest::testDivideRefusesAZeroDivisorcoversUpsertNumberTest::testDivideRefusesAZeroDivisorWrittenAsAFloatcoversUpsertNumberTest::testModuloAnswersWhatIsLeftOvercoversUpsertNumberTest::testModuloRefusesADivisorThatIsZeroOnceItIsAWholeNumbercoversUpsertNumberTest::testModuloTakesBothSidesAsWholeNumbersFirstcoversUpsertNumberTest::testMultiplyMultipliesBothSidescoversUpsertNumberTest::testNegativeTurnsTheSignAroundcoversUpsertNumberTest::testOfKeepsANumberAsItIscovers and callsUpsertNumberTest::testOfReadsTextWrittenTheWayAFloatIsAsAFloatcovers and callsUpsertNumberTest::testOfReadsWholeTextAsAnIntegerRatherThanAFloatcovers and callsUpsertNumberTest::testOfRefusesABooleanBecauseArithmeticOnItIsNotSomethingSqlAgreesOncovers and callsUpsertNumberTest::testOfRefusesTextThatIsNotWrittenAsANumbercovers and callsUpsertNumberTest::testPositiveKeepsTheNumberAndItsSigncoversUpsertNumberTest::testSubtractTakesTheRightSideFromTheLeftcovers
Called from 11
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:52
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::positive() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:72
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::negative() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:86
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::add() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:105
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::subtract() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:124
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::multiply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:143
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::divide() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:161
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::divide() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:169
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::modulo() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:190
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertNumber::modulo() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertNumber.php:198
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertTruth::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertTruth.php:47
public function isNumeric(mixed $value): boolReports whether a value is one arithmetic can be done on.
Parameters
$value | mixed | Value to test |
Returns
bool True when it is a number or written as oneTest cases 1
Called from 3
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:44
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:45
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:54
public function positive(mixed $value): int|float|nullAnswers the value with its sign kept, as a number.
Parameters
$value | mixed | Value to read |
Returns
int|float|null The number, or null when the value is unknownThrows
UnsupportedSqlException When the value is not written as a numberTest cases 2
UpsertNumberTest::testPositiveIsUnknownForAnUnknownValuecovers and callsUpsertNumberTest::testPositiveKeepsTheNumberAndItsSigncovers and calls
Called from 1
Calls 1
- method-call UpsertNumber::of() line 72
public function negative(mixed $value): int|float|nullAnswers the value with its sign turned around.
Parameters
$value | mixed | Value to read |
Returns
int|float|null The number, or null when the value is unknownThrows
UnsupportedSqlException When the value is not written as a numberTest cases 2
UpsertNumberTest::testNegativeIsUnknownForAnUnknownValuecovers and callsUpsertNumberTest::testNegativeTurnsTheSignAroundcovers and calls
Called from 1
Calls 1
- method-call UpsertNumber::of() line 86
public function add(mixed $left, mixed $right): int|float|nullAdds two values.
Parameters
$left | mixed | Left operand |
$right | mixed | Right operand |
Returns
int|float|null The sum, or null when either is unknownThrows
UnsupportedSqlException When either is not written as a numberTest cases 2
UpsertNumberTest::testAddIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testAddSumsBothSidescovers and calls
Called from 1
Calls 1
- method-call UpsertNumber::of() line 105
public function subtract(mixed $left, mixed $right): int|float|nullSubtracts the right value from the left.
Parameters
$left | mixed | Left operand |
$right | mixed | Right operand |
Returns
int|float|null The difference, or null when either is unknownThrows
UnsupportedSqlException When either is not written as a numberTest cases 2
UpsertNumberTest::testSubtractIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testSubtractTakesTheRightSideFromTheLeftcovers and calls
Called from 1
Calls 1
- method-call UpsertNumber::of() line 124
public function multiply(mixed $left, mixed $right): int|float|nullMultiplies two values.
Parameters
$left | mixed | Left operand |
$right | mixed | Right operand |
Returns
int|float|null The product, or null when either is unknownThrows
UnsupportedSqlException When either is not written as a numberTest cases 2
UpsertNumberTest::testMultiplyIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testMultiplyMultipliesBothSidescovers and calls
Called from 1
Calls 1
- method-call UpsertNumber::of() line 143
public function divide(mixed $left, mixed $right): int|float|nullDivides the left value by the right.
Parameters
$left | mixed | Left operand |
$right | mixed | Right operand |
Returns
int|float|null The quotient, or null when either is unknownThrows
UnsupportedSqlException When either is not a number, or the divisor is zeroTest cases 4
UpsertNumberTest::testDivideDividesTheLeftSideByTheRightcovers and callsUpsertNumberTest::testDivideIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testDivideRefusesAZeroDivisorcovers and callsUpsertNumberTest::testDivideRefusesAZeroDivisorWrittenAsAFloatcovers and calls
Called from 1
Calls 2
- method-call UpsertNumber::of() line 161
- new UnsupportedSqlException line 163
public function modulo(mixed $left, mixed $right): int|nullAnswers 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
$left | mixed | Left operand |
$right | mixed | Right operand |
Returns
int|null The remainder, or null when either is unknownThrows
UnsupportedSqlException When either is not a number, or the divisor is zeroTest cases 4
UpsertNumberTest::testModuloAnswersWhatIsLeftOvercovers and callsUpsertNumberTest::testModuloIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testModuloRefusesADivisorThatIsZeroOnceItIsAWholeNumbercovers and callsUpsertNumberTest::testModuloTakesBothSidesAsWholeNumbersFirstcovers and calls
Called from 1
Calls 3
- function-call
intvalline 190 - method-call UpsertNumber::of() line 190
- new UnsupportedSqlException line 192
Test cases 33§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 24
UpsertNumberTest::testAddIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testAddSumsBothSidescovers and callsUpsertNumberTest::testDivideDividesTheLeftSideByTheRightcovers and callsUpsertNumberTest::testDivideIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testDivideRefusesAZeroDivisorcovers and callsUpsertNumberTest::testDivideRefusesAZeroDivisorWrittenAsAFloatcovers and callsUpsertNumberTest::testIsNumericAnswersForTheValuesArithmeticCanBeDoneOncovers and callsUpsertNumberTest::testModuloAnswersWhatIsLeftOvercovers and callsUpsertNumberTest::testModuloIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testModuloRefusesADivisorThatIsZeroOnceItIsAWholeNumbercovers and callsUpsertNumberTest::testModuloTakesBothSidesAsWholeNumbersFirstcovers and callsUpsertNumberTest::testMultiplyIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testMultiplyMultipliesBothSidescovers and callsUpsertNumberTest::testNegativeIsUnknownForAnUnknownValuecovers and callsUpsertNumberTest::testNegativeTurnsTheSignAroundcovers and callsUpsertNumberTest::testOfKeepsANumberAsItIscovers and callsUpsertNumberTest::testOfReadsTextWrittenTheWayAFloatIsAsAFloatcovers and callsUpsertNumberTest::testOfReadsWholeTextAsAnIntegerRatherThanAFloatcovers and callsUpsertNumberTest::testOfRefusesABooleanBecauseArithmeticOnItIsNotSomethingSqlAgreesOncovers and callsUpsertNumberTest::testOfRefusesTextThatIsNotWrittenAsANumbercovers and callsUpsertNumberTest::testPositiveIsUnknownForAnUnknownValuecovers and callsUpsertNumberTest::testPositiveKeepsTheNumberAndItsSigncovers and callsUpsertNumberTest::testSubtractIsUnknownWhenEitherSideIscovers and callsUpsertNumberTest::testSubtractTakesTheRightSideFromTheLeftcovers and calls
Other tests reaching this symbol 9
ConflictSearchTestcallsMutationImpactTestcallsInsertMutationTestcallsUpsertComparisonTestcallsUpsertOperatorTestcallsUpsertTruthTestcallsUpsertExpressionTestcallsUpsertMutationTestcallsUpsertUpdateTestcalls
Relations§
Instantiated in 3
- new ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::__construct() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:25
- new ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::__construct() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:30
- new ZtdQuery\Shadow\Mutation\Upsert\UpsertTruth::__construct() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertTruth.php:25
Method calls 12
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:44
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:45
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:52
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:54
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:58
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:59
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:61
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:62
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:63
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:64
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator::apply() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:65
- method-call ZtdQuery\Shadow\Mutation\Upsert\UpsertTruth::of() packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertTruth.php:47
Type declarations 3
- type ZtdQuery\Shadow\Mutation\Upsert\UpsertComparison packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertComparison.php:25
- type ZtdQuery\Shadow\Mutation\Upsert\UpsertOperator packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertOperator.php:30
- type ZtdQuery\Shadow\Mutation\Upsert\UpsertTruth packages/ztd-query-core/src/Shadow/Mutation/Upsert/UpsertTruth.php:25