for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Desmond\functions\special;
use Desmond\functions\DesmondSpecialFunction;
use Desmond\ArgumentHelper;
use Desmond\exceptions\ArgumentException;
class Conditional implements DesmondSpecialFunction
{
use ArgumentHelper;
public function run(array $args)
if (!isset($args[0])) {
throw new ArgumentException('"if" expects first argument condition.');
} else if (!isset($args[1])) {
throw new ArgumentException('"if" expects second argument body.');
}
$condition = $this->eval->getReturn($args[0])->value();
eval
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
if ($condition !== null && $condition !== false) {
return $this->eval->getReturn($args[1]);
} else {
return isset($args[2]) ? $this->eval->getReturn($args[2]) : $this->newReturnType('Nil');
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: