for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Lampager\Idiorm\Concerns;
/**
* Trait HasSnakeAliases
*/
trait HasSnakeAliases
{
* @param string $name
* @return bool
protected function hasSnakeMethod($name)
return $this->performOnSnakeMethod(
$name,
static function () {
return true;
},
return false;
}
);
* @param array $args
* @return mixed
protected function callSnakeMethod($name, array $args)
function (\ReflectionMethod $method) use ($args) {
return $method->invokeArgs($this, $args);
function ($name) {
throw new \BadMethodCallException('Call to undefined method ' . static::class . '::' . $name . '()');
* @param callable $handleInvoke
* @param callable $handleError
protected function performOnSnakeMethod($name, callable $handleInvoke, callable $handleError)
static $class;
if (!$class) {
$class = new \ReflectionClass(static::class);
$camel = str_replace('_', '', ucwords($name, '_'));
if ($class->hasMethod($camel)) {
$method = $class->getMethod($camel);
if ($method->isPublic()) {
return $handleInvoke($method);
return $handleError($name);
public function __call($name, array $args)
return $this->callSnakeMethod($name, $args);