core/Group/Controller/WebExtension.php
<?php namespace Group\Controller; use Twig_Extension;use Route;use Group\Routing\Router;use Group\Session\CsrfSessionService;use Qiniu\Auth; class WebExtension extends Twig_Extension{ /** * 重写Twig_Extension getFunctions方法 * * @return array */ public function getFunctions() { return array(Missing class import via use statement (line '21', column '29'). 'assets' => new \Twig_Function_Method($this, 'getAssets'),Missing class import via use statement (line '22', column '28'). 'dump' => new \Twig_Function_Method($this, 'dump'),Missing class import via use statement (line '23', column '30'). 'render' => new \Twig_Function_Method($this, 'render', array('is_safe' => array('html'))),Missing class import via use statement (line '24', column '34'). 'csrf_token' => new \Twig_Function_Method($this, 'getCsrfToken'),Missing class import via use statement (line '25', column '29'). 'debug' => new \Twig_Function_Method($this, 'debug', array('is_safe' => array('html'))),Missing class import via use statement (line '26', column '35'). 'debugHeader' => new \Twig_Function_Method($this, 'debugHeader', array('is_safe' => array('html'))), ); } public function getFilters() { return array(Missing class import via use statement (line '33', column '33'). 'smart_time' => new \Twig_Filter_Method($this, 'smarttimeFilter'),Missing class import via use statement (line '34', column '32'). 'get_short' => new \Twig_Filter_Method($this, 'getShort', ['is_safe' => ['html']]), ); } public function getShort($string, $len = 40) { return \Group\Common\StringToolkit::getShort($string, $len, "..."); } /** * 获取asset目录下得文件路径 * * @return string */ public function getAssets($path) { return "/assets/".$path; } /** * 获取路由 * * @return string */ public function getUrl($url, $params = []) { return Route::deParse($url, $params); } /** * 在模板调试使用 * * @param var * @return void */ public function dump($var) { return var_dump($var); } public function render($controller, $params)Whitespace found at end of line { Avoid using undefined variables such as '$config' which will lead to PHP notices. $config['controller'] = $controller;Avoid using undefined variables such as '$config' which will lead to PHP notices. $config['parameters'] = $params;Avoid using undefined variables such as '$config' which will lead to PHP notices. return app()->router->getTpl($config); } public function getCsrfToken() { $csrfProvider = new CsrfSessionService(); return $csrfProvider->generateCsrfToken(); } Function `smarttimeFilter` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Opening brace should be on a new line public function smarttimeFilter($time) { $diff = time() - $time; if ($diff < 0) { return '未来'; } if ($diff == 0) { return '刚刚'; } if ($diff < 60) { return $diff . '秒前'; } if ($diff < 3600) { return round($diff / 60) . '分钟前'; } if ($diff < 86400) {Avoid too many `return` statements within this method. return round($diff / 3600) . '小时前'; } if ($diff < 2592000) {Avoid too many `return` statements within this method. return round($diff / 86400) . '天前'; } if ($diff < 31536000) {Avoid too many `return` statements within this method. return date('m-d', $time); } Avoid too many `return` statements within this method. return date('Y-m-d', $time); } public function debug()Whitespace found at end of line { if (app('container')->isDebug()) { $debugbarRenderer = app('debugbar')->getJavascriptRenderer(); return $debugbarRenderer->render(); } } public function debugHeader()Whitespace found at end of line { if (app('container')->isDebug()) { $debugbarRenderer = app('debugbar')->getJavascriptRenderer(); return $debugbarRenderer->renderHead(); } } public function getName() { return 'group_twig'; }}