Refactored \RTEX\Objects\Program\Instructions > Equals > eval()

This commit is contained in:
Netkas 2022-12-28 00:25:11 -05:00
parent cfb55fd7df
commit 172bc4866a

View file

@ -8,8 +8,8 @@
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\Interfaces\InstructionInterface; use RTEX\Interfaces\InstructionInterface;
class Equals implements InstructionInterface class Equals implements InstructionInterface
@ -38,7 +38,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 +52,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,18 +65,21 @@
/** /**
* @param Engine $engine * @param Engine $engine
* @return bool * @return bool
* @throws UnsupportedVariableType * @throws EvaluationException
* @throws EvaluationException
*/ */
public function eval(Engine $engine): bool public function eval(Engine $engine): bool
{ {
return (intval($engine->eval($this->A)) == intval($engine->eval($this->B))); $a = $engine->eval($this->A);
$b = $engine->eval($this->B);
return $a === $b;
} }
/** /**
* 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 +104,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 +125,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
{ {