public function __construct($symbol = null) { $this->symbol = $symbol; $this->environment = Environment::getInstance(); $this->traversable = null; $this->forAll = null; }
public function m($symbolOne, $symbolTwo) { $operandOne = Environment::getInstance()->resolve($symbolOne); if (is_int($symbolTwo) || is_float($symbolTwo)) { $operandTwo = $symbolTwo; } else { $operandTwo = Environment::getInstance()->resolve($symbolTwo); } // Make sure operandOne is an int or a float if (!is_int($operandOne) && !is_float($operandOne)) { throw new \InvalidArgumentException("The value for symbol '{$symbolOne}' is neither an int nor a float."); } // Make sure operandTwo is an int or a float if (!is_int($operandTwo) && !is_float($operandTwo)) { throw new \InvalidArgumentException("The value for symbol '{$symbolTwo}' is neither an int nor a float."); } $result = $operandOne - $operandTwo; $this->setOperand("__x__", $result); }
/** * Test the getInstance method * * This method must return the same instance of the Environment class */ public function testGetInstance() { $environmentTwo = Environment::getInstance(); $this->assertSame($this->environment, $environmentTwo, "Failed to assert that the getInstance method returns the same environment. The environment must be a singleton."); }
public function be($value) { Environment::getInstance()->attach($this->symbol, $value); }