fucongcong/framework

View on GitHub
core/Group/Container/Container.php

Summary

Maintainability
A
2 hrs
Test Coverage
<?php
 
namespace Group\Container;
 
use ReflectionClass;
use App;
use Group\Exceptions\NotFoundException;
use Group\Contracts\Container\Container as ContainerContract;
use Group\Events\HttpEvent;
use Group\Events\KernalEvent;
 
`Container` has 21 functions (exceeds 20 allowed). Consider refactoring.
class Container implements ContainerContract
Opening class brace must be on a line by itself
Whitespace found at end of line
{
Spaces must be used to indent lines; tabs are not allowed
private static $instance;
 
protected $timezone;
 
protected $environment;
 
protected $appPath;
 
protected $locale;
 
/**
* Response object
*
* @var response
*/
protected $response;
 
/**
* Request object
*
* @var request
*/
protected $request;
 
protected $debug = false;
 
protected $context;
 
public function __construct()
{
$this->setTimezone();
 
$this->setEnvironment();
 
$this->setLocale();
 
$this->needDebug();
}
 
Spaces must be used to indent lines; tabs are not allowed
/**
Spaces must be used to indent lines; tabs are not allowed
* build a moudle class
Spaces must be used to indent lines; tabs are not allowed
*
Spaces must be used to indent lines; tabs are not allowed
* @param class
Spaces must be used to indent lines; tabs are not allowed
* @return ReflectionClass class
Spaces must be used to indent lines; tabs are not allowed
*/
Spaces must be used to indent lines; tabs are not allowed
public function buildMoudle($class)
Spaces must be used to indent lines; tabs are not allowed
{
Spaces must be used to indent lines; tabs are not allowed
if (!class_exists($class)) {
Spaces must be used to indent lines; tabs are not allowed
throw new NotFoundException("Class ".$class." not found !");
Spaces must be used to indent lines; tabs are not allowed
}
 
Spaces must be used to indent lines; tabs are not allowed
$reflector = new ReflectionClass($class);
 
Spaces must be used to indent lines; tabs are not allowed
return $reflector;
Spaces must be used to indent lines; tabs are not allowed
}
 
/**
* do the moudle class action
*
* @param class
* @param action
* @param array parameters
* @return string
*/
Function `doAction` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Spaces must be used to indent lines; tabs are not allowed
public function doAction($class, $action, array $parameters, \Request $request)
Spaces must be used to indent lines; tabs are not allowed
{
Spaces must be used to indent lines; tabs are not allowed
$reflector = $this->buildMoudle($class);
 
Spaces must be used to indent lines; tabs are not allowed
if (!$reflector->hasMethod($action)) {
Spaces must be used to indent lines; tabs are not allowed
throw new NotFoundException("Class ".$class." exist ,But the Action ".$action." not found");
Spaces must be used to indent lines; tabs are not allowed
}
 
Spaces must be used to indent lines; tabs are not allowed
$instanc = $reflector->newInstanceArgs(array(App::getInstance()));
Spaces must be used to indent lines; tabs are not allowed
$method = $reflector->getmethod($action);
$args = [];
foreach ($method->getParameters() as $arg) {
$paramName = $arg ->getName();
Inline control structures are not allowed
if (isset($parameters[$paramName])) $args[$paramName] = $parameters[$paramName];
Inline control structures are not allowed
Line exceeds 120 characters; contains 126 characters
if (!empty($arg->getClass()) && $arg->getClass()->getName() == 'Group\Http\Request') $args[$paramName] = $request;
}
 
Spaces must be used to indent lines; tabs are not allowed
return $method->invokeArgs($instanc, $args);
Spaces must be used to indent lines; tabs are not allowed
}
 
/**
* return single class
*
* @return Group\Container Container
*/
Spaces must be used to indent lines; tabs are not allowed
public static function getInstance()
{
Spaces must be used to indent lines; tabs are not allowed
Expected 1 space after closing parenthesis; found 0
if (!(self::$instance instanceof self)){
Spaces must be used to indent lines; tabs are not allowed
self::$instance = new self;
Spaces must be used to indent lines; tabs are not allowed
}
 
Spaces must be used to indent lines; tabs are not allowed
return self::$instance;
Spaces must be used to indent lines; tabs are not allowed
}
 
/**
* 设置时区
*
*/
public function setTimezone()
{
$this->timezone = \Config::get('app::timezone');
date_default_timezone_set($this->getTimezone());
}
 
 
/**
* 获取当前时区
*
*/
public function getTimezone()
{
return $this->timezone;
}
 
/**
* 获取当前环境
*
*@return string prod|dev
*/
public function getEnvironment()
{
return $this->environment;
}
 
/**
* 设置环境
*
*/
public function setEnvironment()
{
$this->environment = \Config::get('app::environment');
}
 
/**
* 设置系统根目录
*
*/
public function setAppPath($path)
{
$this->appPath = $path;
}
 
/**
* 获取系统根目录
*
*@return string
*/
public function getAppPath()
{
return $this->appPath;
}
 
/**
* 设置地区
*
*/
public function setLocale()
{
$this->locale = \Config::get('app::locale');
}
 
/**
* 获取设置的地区
*
*@return string
*/
public function getLocale()
{
return $this->locale;
}
 
/**
* 设置response
*
*/
public function setResponse($response)
{
$this->response = $response;
}
 
/**
* 获取设置的response
*
*@return string
*/
public function getResponse()
{
return $this->response;
}
 
/**
* 设置request
*
*/
public function setRequest(\Request $request)
Whitespace found at end of line
{
\EventDispatcher::dispatch(KernalEvent::REQUEST, new HttpEvent($request));
$this->request = $request;
}
 
/**
* 获取设置的request
*
*@return string
*/
public function getRequest()
{
return $this->request;
}
 
public function runningInConsole()
{
return php_sapi_name() == 'cli';
}
 
private function needDebug()
{
if (\Config::get('app::environment') == "dev" && \Config::get('app::debug')) {
$this->debug = true;
}
}
 
public function isDebug()
{
return $this->debug;
}
 
public function setContext($key, $val)
{
$this->context[$key] = $val;
}
 
public function getContext($key, $default = null)
{
if (isset($this->context[$key])) {
return $this->context[$key];
}
 
return $default;
}
}