Support-Groups/admin/helpers/negativefinder.php

68 lines
1.0 KiB
PHP
Raw Permalink Normal View History

<?php
/**
*
* @version 1.0.0
* @package Detecting negative numbers
* @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
*
**/
// No direct access.
defined('_JEXEC') or die;
/**
* Detecting negative numbers
**/
2019-04-04 11:53:29 +00:00
class SupportgroupsExpression
{
2019-04-04 11:53:29 +00:00
protected $expression;
protected $result;
2019-04-04 11:53:29 +00:00
public function __construct($expression)
{
2019-04-04 11:53:29 +00:00
$this->expression = $expression;
}
2019-04-04 11:53:29 +00:00
public function evaluate()
{
2019-04-04 11:53:29 +00:00
$this->result = eval("return ".$this->expression.";");
return $this;
}
2019-04-04 11:53:29 +00:00
public function getResult()
{
2019-04-04 11:53:29 +00:00
return $this->result;
}
}
2019-04-04 11:53:29 +00:00
class SupportgroupsNegativeFinder
{
2019-04-04 11:53:29 +00:00
protected $expressionObj;
2019-04-04 11:53:29 +00:00
public function __construct(SupportgroupsExpression $expressionObj)
{
2019-04-04 11:53:29 +00:00
$this->expressionObj = $expressionObj;
}
2019-04-04 11:53:29 +00:00
public function isItNegative()
{
2019-04-04 11:53:29 +00:00
$result = $this->expressionObj->evaluate()->getResult();
if($this->hasMinusSign($result))
{
2019-04-04 11:53:29 +00:00
return true;
}
else
{
2019-04-04 11:53:29 +00:00
return false;
}
}
2019-04-04 11:53:29 +00:00
protected function hasMinusSign($value)
{
2019-04-04 11:53:29 +00:00
return (substr(strval($value), 0, 1) == "-");
}
}