@SuppressWarnings(PHPMD.CamelCaseMethodName)

{@inheritDoc}
339347
protected function _afterLoad(\Magento\Framework\Model\AbstractModel $object)
    {
        if ($object->getId()) {
            $searchContainers = $this->getSearchContainersFromOptimizerId($object->getId());
            $object->setSearchContainers($searchContainers);
        }

         /* Using getter to force unserialize*/
        $object->getConfig();
        $object->getRuleCondition();

        return parent::_afterLoad($object);
    }
94311
protected function camelCase($name, array $delimiters=['-','_'])
    {
        $spaceSeparated = str_replace($delimiters,' ', $name);
        return str_replace(' ', '', ucwords($spaceSeparated));
    }
1141681
public function when(/* see docblock */)
    {
        $arguments = func_get_args();
        if ($arguments[0] instanceof Antecedent) {
            $antecedent = $arguments[0];
        } elseif ($arguments[0] instanceof PHPUnit_Framework_Constraint) {
            $antecedent = Antecedent\IndependentConstraintsAntecedent::fromAll($arguments);
        } elseif ($arguments[0] instanceof Constraint) {
            $antecedent = Antecedent\IndependentConstraintsAntecedent::fromAll($arguments);
        } elseif ($arguments && count($arguments) == 1) {
            $antecedent = Antecedent\SingleCallbackAntecedent::from($arguments[0]);
        } else {
            throw new \InvalidArgumentException("Invalid call to when(): " . var_export($arguments, true));
        }
        $this->antecedents[] = $antecedent;
        return $this;
    }
297196
public function verifyConfig()
    {
        $keys = ['implementedFinders', 'implementedMethods'];
        foreach ($keys as $key) {
            if (!isset($this->_config[$key])) {
                continue;
            }

            foreach ($this->_config[$key] as $method) {
                if (!is_callable([$this, $method])) {
                    throw new Exception(sprintf('The method %s is not callable on class %s', $method, get_class($this)));
                }
            }
        }
    }
794279
public function executeMethod($class, $method, array $params = null, $model = null)
    {
        if (!method_exists($class, $method)) {
            throw new MethodNotExistsException(
                "Method '" . $method . "' does not exist in ". get_class($class)
            );
        }

        $params = $params ? $params : [];
        ! $model || $params[] = $model;

        return call_user_func_array([$class, $method], $params);
    }
1350050
protected function getApiMethod()
    {
        if (!isset($this->apiMethod)) {
            $words = explode('_', Str::snake(class_basename($this)), -1);
            $endpoint = strtolower(array_shift($words));
            $action = Str::camel(implode('_', $words)) ?: '*';
            $method = sprintf('%s.%s', $endpoint, $action);
            $this->apiMethod = $endpoint ? $method : 'undefined';
        }

        return $this->apiMethod;
    }
244178
private static function checkDefaultPattern(Dicionario $d, Meta $m)
    {
        if (preg_match('/{\$/', $m->getDefault())) {
            $newDefault = "";
            $error = false;
            foreach (explode('{$', $m->getDefault()) as $i => $expressao) {
                if ($i > 0) {
                    $variable = explode('}', $expressao);
                    $base = $variable[1];
                    $variable = trim(strtolower($variable[0]));
                    $mod = null;
                    $param = null;
                    if (preg_match('/\|/i', $variable)) {
                        $mod = explode('|', $variable);
                        $variable = $mod[0];
                        $mod = $mod[1];
                        if (preg_match('/\(/i', $mod) && preg_match('/\)/i', $mod)) {
                            $param = explode('(', $mod);
                            $mod = $param[0];
                            $param = explode(')', $param[1])[0];
                            if (preg_match('/,/i', $param))
                                $param = explode(',', $param);
                        }
                    }

                    if ($value = self::getValueFromVarible($d, $variable))
                        $newDefault .= ($mod ? self::proccessFunction($value, $mod, $param) : $value);

                    $newDefault .= $base;

                } else {
                    $newDefault .= $expressao;
                }
            }

            $m->setValue($newDefault);
        }

    }
494721
public function apply($dbDriver, $alias, $field, $exprValue, $namedParameter = null, &$value = null)
	{
		$matches = [];
		
		if (!preg_match(self::PATTERN, $exprValue, $matches)) {
			throw new BadQueryExprException(sprintf('The query expression converter "eq" does not support the following pattern "%s".', $exprValue));
		}
		
		$value = $matches[1];
		
		return $dbDriver === 'orm' ? 
				(new \Doctrine\ORM\Query\Expr())->eq($alias.'.'.$field, $namedParameter ?: ':'.$field) : 
				(new \Doctrine\MongoDB\Query\Expr())->field($field)->equals($value);
	}
279637
public function replaceReservedMethod($methodName, $context = null)
    {
        if ($this->getReservedMethodsInstance()->is($methodName)) {
            if ($context !== null) {
                $methodKey = $methodName . '_' . $context;
                if (!array_key_exists($methodKey, $this->replacedReservedMethods)) {
                    $this->replacedReservedMethods[$methodKey] = 0;
                } else {
                    $this->replacedReservedMethods[$methodKey]++;
                }
                return '_' . $methodName . ($this->replacedReservedMethods[$methodKey] ? '_' . $this->replacedReservedMethods[$methodKey] : '');
            } else {
                return '_' . $methodName;
            }
        } else {
            return $methodName;
        }
    }
971054
public function hydrate(array $data): void
    {
        if (!$data) {
            return;
        }

        if ($this->hydrationProperties === null || $this->hydrationSetters === null) {
            $reflection = new \ReflectionClass($this);
            $this->hydrationProperties = array_map(function ($v) {
                return $v->name;
            }, $reflection->getProperties(\ReflectionProperty::IS_PUBLIC));

            $this->hydrationSetters = array_filter(array_map(function ($v) {
                return strpos($v->name, 'set') === 0 ? $v->name : null;
            }, $reflection->getMethods(\ReflectionMethod::IS_PUBLIC)));
        }

        $camelCaseConvert = function ($v) {
            if (strpos($v, '_') === false) {
                return $v;
            }

            $v = explode('_', $v);

            $first = array_shift($v);
            $v = array_map('ucfirst', $v);

            return $first . implode('', $v);
        };

        foreach ($data as $key => $value) {
            if (in_array($key, $this->hydrationProperties, true)) {
                $this->{$key} = $value;
            } else {
                $camelCaseKey = $camelCaseConvert($key);
                $setter = 'set' . ucfirst($camelCaseKey);

                if ($camelCaseKey !== $key && in_array($camelCaseKey, $this->hydrationProperties, true)) {
                    $this->{$camelCaseKey} = $value;
                } elseif (in_array($setter, $this->hydrationSetters, true)) {
                    $this->$setter($value);
                } else {
                    throw new \OutOfBoundsException(sprintf(
                        'Invalid attribute provided "%s"',
                        $key
                    ));
                }
            }
        }
    }
1089527
public function camel() {
    if ($this->areTitleCase) {
      // If the pieces are already in title case, lower the case of the first
      // piece only, unless it's in uppercase.
      if (!preg_match('@^[[:upper:]]+$@', $this->pieces[0])) {
        $this->pieces[0] = lcfirst($this->pieces[0]);
      }
    }
    else {
      $first_piece = array_shift($this->pieces);

      $this->pieces = array_map('ucfirst', $this->pieces);

      array_unshift($this->pieces, $first_piece);
    }

    return implode('', $this->pieces);
  }
1366744
private function _filterScopes(): \Illuminate\Support\Collection
    {
        if (count($this->_request) > 0) {
            foreach ($this->_request as $scope => $value) {
                if (!empty($value) || $value === 0 || $value === '0') {
                    $value = (string)$value;
                    //checked scope method for model
                    if (method_exists($this->_model, 'scope' . \Illuminate\Support\Str::camel($scope))) {
                        $this->_query->{\Illuminate\Support\Str::camel($scope)}($value);
                    } else {
                        $this->_filterSearch($scope, $value, $this->filter['operator'], $this->filter['beforeValue'],
                            $this->filter['afterValue']);
                    }
                }
            }
            $this->_query->addSelect($this->_model->getTable() . '.*');
        }

        return $this->_request;
    }
345819
public function prepare()
    {    
        if (!empty($this->module->templateTransCat)) {
            $this->tcModule = $this->module->tcModule;
            $this->tcModels = $this->module->tcModels;
            
            $id = Inflector::camel2id(basename($this->className()));
            $this->tc = str_replace('*', "/model-{$id}", $this->module->templateTransCat);
        }
        if (!empty($this->module->params['pageSize'])) {
            $this->pageSize = $this->module->params['pageSize'];
        }
    }
1339350
public function run()
    {
        if(Schema::hasTable(strtolower($this->model)))
        {
            $tableName = strtolower($this->model);
        }elseif(Schema::hasTable(strtolower($this->model)."s")) {
            $tableName = strtolower($this->model."s");
        }else{
            $tableName = "";
        }

        $tableColumns = $tableName != "" ? Schema::getColumnListing($tableName) : [];

        $module  = camel_case($this->module);
        $model   = camel_case($this->model);

        if($this->output == "api")
        {
            $templatePath = $this->customTemplate ?: __DIR__."/template/api_controller.blade.php";
        }else{
            $templatePath = $this->customTemplate ?: __DIR__."/template/controller.blade.php";
        }

        $paramColumns = array_diff($tableColumns, ["id", "created_at", "updated_at"]);

        $paramStrings = collect($paramColumns)->map(function($item){
            return "$".lcfirst(camel_case($item));
        })->toArray();

        $data = [
            "group"         => $this->group,
            "module"        => $module,
            "model"         => $model,
            "paramStrings"  => $paramStrings,
            "tableColumns"  => $paramColumns
        ];

        $view =  View::file($templatePath, $data);

        $filePath = $this->customFile ?: ucfirst($this->group)."/".ucfirst($module)."Controller";
        $filePath = "Http/Controllers/".$filePath.".php";

        if(!is_dir(app_path("Http/Controllers/".ucfirst($this->group))))
        {
            mkdir(app_path("Http/Controllers/".ucfirst($this->group)));
        }

        if(!file_exists(app_path($filePath)))
        {
            file_put_contents(app_path($filePath), "<?php \n\n" . $view->render());
        }else{
            if($this->mode == "overwrite")
            {
                file_put_contents(app_path($filePath), "<?php \n\n" . $view->render());
            }

            if($this->mode == "append")
            {
                $this->append($filePath, $data);
            }
        }

        if(!file_exists(app_path("Http/Controllers/BaseController.php")))
        {
            $view = View::file(__DIR__."/template/base_controller.blade.php", []);
            file_put_contents(app_path("Http/Controllers/BaseController.php"), "<?php \n\n" . $view->render());
        }
    }
639342
public function generateScopePhp()
    {

        $methodSignature = '';
        $paramsDoc       = '';
        $buildScope      = '';
        $buildScopeVars  = '';

        if ($this->hasMultipleScopes()) {

            $methodSignature = [];
            $buildScope      = [];
            $buildScopeVars  = [];
            $paramsDoc       = [];

            foreach ($this->getScopes() as $idx => $scope) {

                $column = $this->table->getColumn($scope);
                $param  = '$scope'.$column->getPhpName();

                $buildScope[]     = "    \$scope[] = $param;\n";
                $buildScopeVars[] = "    $param = \$scope[$idx];\n";
                $paramsDoc[]      = " * @param     ".$column->getPhpType()." $param Scope value for column `".$column->getPhpName()."`";

                if (!$column->isNotNull()) {
                    $param .= ' = null';
                }
                $methodSignature[] = $param;
            }

            $methodSignature = implode(', ', $methodSignature);
            $paramsDoc       = implode("\n", $paramsDoc);
            $buildScope      = "\n".implode('', $buildScope)."\n";
            $buildScopeVars  = "\n".implode('', $buildScopeVars)."\n";

        } elseif ($this->useScope()) {
            $methodSignature = '$scope';
            $column = $this->table->getColumn($this->getParameter('scope_column'));
            if ($column) {
                if (!$column->isNotNull()) {
                    $methodSignature .= ' = null';
                }
                $paramsDoc .= ' * @param '.$column->getPhpType().' $scope Scope to determine which objects node to return';
            }
        }

        return [$methodSignature, $paramsDoc, $buildScope, $buildScopeVars];
    }
183327
private function validate()
    {
        if (null === $this->provider) {
            throw new MissingProviderException('A provider must be set for converting a currency');
        }

        if (null === $this->from || null === $this->to) {
            throw new \RuntimeException('from and to parameters must be provided');
        }
    }
1144939
protected function checkServiceEventMethodName($serviceEvent, $eventMethodName)
    {
        if (false === in_array($eventMethodName, self::$servicesChecked[$serviceEvent])) {
            $eventClassReflection = ReflectionService::get()->getClassReflection($serviceEvent);
            self::$servicesChecked[$serviceEvent][] = $eventMethodName;

            if (false === $eventClassReflection->hasMethod($eventMethodName)) {
                throw new MethodNotFoundException(
                    'The service event "' . $serviceEvent . '" does not have a method called "' . $eventMethodName . '".',
                    1456509926
                );
            }
        }
    }