Refactored GreaterThan, added documentation
This commit is contained in:
parent
876621f618
commit
5a6f406ec7
2 changed files with 50 additions and 11 deletions
34
docs/greater_than.md
Normal file
34
docs/greater_than.md
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# greater_than
|
||||||
|
|
||||||
|
Returns true if the first argument is greater than the second argument.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
* a (`integer`, `float`, `double`, `instruction`) - The first number.
|
||||||
|
* b (`integer`, `float`, `double`, `instruction`) - The second number.
|
||||||
|
|
||||||
|
## Return
|
||||||
|
|
||||||
|
(`boolean`) - True if the first argument is greater than the second argument.
|
||||||
|
|
||||||
|
## Exceptions
|
||||||
|
|
||||||
|
* `EvaluationException` - If there was an error while evaluating one or more parameters.
|
||||||
|
* `TypeException` - If one or more parameters are not of the expected type.
|
||||||
|
|
||||||
|
## Instruction Example
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "greater_than",
|
||||||
|
"_": {
|
||||||
|
"a": 10,
|
||||||
|
"b": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Last Updated
|
||||||
|
|
||||||
|
Monday, December 29th, 2022.
|
||||||
|
Written by [Netkas](https://git.n64.cc/netkas)
|
|
@ -8,8 +8,9 @@
|
||||||
use RTEX\Classes\InstructionBuilder;
|
use RTEX\Classes\InstructionBuilder;
|
||||||
use RTEX\Classes\Utilities;
|
use RTEX\Classes\Utilities;
|
||||||
use RTEX\Engine;
|
use RTEX\Engine;
|
||||||
use RTEX\Exceptions\Core\MalformedInstructionException;
|
use RTEX\Exceptions\EvaluationException;
|
||||||
use RTEX\Exceptions\Core\UnsupportedVariableType;
|
use RTEX\Exceptions\InstructionException;
|
||||||
|
use RTEX\Exceptions\Runtime\TypeException;
|
||||||
use RTEX\Interfaces\InstructionInterface;
|
use RTEX\Interfaces\InstructionInterface;
|
||||||
|
|
||||||
class GreaterThan implements InstructionInterface
|
class GreaterThan implements InstructionInterface
|
||||||
|
@ -38,7 +39,6 @@
|
||||||
* Returns an array representation of the instruction
|
* Returns an array representation of the instruction
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws UnsupportedVariableType
|
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
|
@ -53,8 +53,7 @@
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return InstructionInterface
|
* @return InstructionInterface
|
||||||
* @throws MalformedInstructionException
|
* @throws InstructionException
|
||||||
* @throws UnsupportedVariableType
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): InstructionInterface
|
public static function fromArray(array $data): InstructionInterface
|
||||||
{
|
{
|
||||||
|
@ -67,10 +66,19 @@
|
||||||
/**
|
/**
|
||||||
* @param Engine $engine
|
* @param Engine $engine
|
||||||
* @return int
|
* @return int
|
||||||
* @throws UnsupportedVariableType
|
* @throws EvaluationException
|
||||||
|
* @throws TypeException
|
||||||
*/
|
*/
|
||||||
public function eval(Engine $engine): int
|
public function eval(Engine $engine): int
|
||||||
{
|
{
|
||||||
|
$a = $engine->eval($this->A);
|
||||||
|
$b = $engine->eval($this->B);
|
||||||
|
|
||||||
|
if (!is_numeric($a))
|
||||||
|
throw new TypeException(sprintf('Parameter "a" must be numeric, %s given', Utilities::getType($a)));
|
||||||
|
if (!is_numeric($b))
|
||||||
|
throw new TypeException(sprintf('Parameter "b" must be numeric, %s given', Utilities::getType($b)));
|
||||||
|
|
||||||
return (intval($engine->eval($this->A)) > intval($engine->eval($this->B)));
|
return (intval($engine->eval($this->A)) > intval($engine->eval($this->B)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +86,6 @@
|
||||||
* Returns the string representation of the instruction
|
* Returns the string representation of the instruction
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws UnsupportedVariableType
|
|
||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
|
@ -103,8 +110,7 @@
|
||||||
* Sets the value of A
|
* Sets the value of A
|
||||||
*
|
*
|
||||||
* @param mixed $A
|
* @param mixed $A
|
||||||
* @throws UnsupportedVariableType
|
* @throws InstructionException
|
||||||
* @throws MalformedInstructionException
|
|
||||||
*/
|
*/
|
||||||
public function setA(mixed $A): void
|
public function setA(mixed $A): void
|
||||||
{
|
{
|
||||||
|
@ -125,8 +131,7 @@
|
||||||
* Sets the value of B
|
* Sets the value of B
|
||||||
*
|
*
|
||||||
* @param mixed $B
|
* @param mixed $B
|
||||||
* @throws MalformedInstructionException
|
* @throws InstructionException
|
||||||
* @throws UnsupportedVariableType
|
|
||||||
*/
|
*/
|
||||||
public function setB(mixed $B): void
|
public function setB(mixed $B): void
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue