fucongcong/framework

View on GitHub
core/Group/SwooleKernal.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
 
namespace Group;
 
use Group\App\App;
use swoole_http_server;
 
class SwooleKernal
Opening class brace must be on a line by itself
Whitespace found at end of line
{
protected $http;
 
protected $path;
 
protected $loader;
 
protected $app;
 
public function init($path, $loader)
Whitespace found at end of line
{
define('SWOOLE_HTTP', true);
 
$this->path = $path;
$this->loader = $loader;
 
$host = \Group\Config\Config::get('app::swoole_host') ? : "127.0.0.1";
$port = \Group\Config\Config::get('app::swoole_port') ? : 9777;
$setting = \Group\Config\Config::get('app::swoole_setting');
 
$this->http = new swoole_http_server($host, $port);
$this->http->set($setting);
 
$this->http->on('Start', [$this, 'onStart']);
$this->http->on('WorkerStart', [$this, 'onWorkerStart']);
$this->http->on('Request', [$this, 'onRequest']);
 
$this->start();
}
 
Avoid unused parameters such as '$serv'.
public function onStart($serv)
{
if (PHP_OS !== 'Darwin') {
swoole_set_process_name("php http server: master");
}
}
 
Avoid unused parameters such as '$serv'.
Avoid unused parameters such as '$workerId'.
public function onWorkerStart($serv, $workerId)
Whitespace found at end of line
{
if (function_exists('opcache_reset')) {
opcache_reset();
}
 
$this->app = new App();
$this->app->initSwoole($this->path, $this->loader);
//设置不同进程名字,方便grep管理
if (PHP_OS !== 'Darwin') {
swoole_set_process_name("php http server: worker");
}
 
echo "HTTP Worker Start...".PHP_EOL;
}
 
The method onRequest() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
public function onRequest($request, $response)
{
$request->get = isset($request->get) ? $request->get : [];
$request->post = isset($request->post) ? $request->post : [];
$request->cookie = isset($request->cookie) ? $request->cookie : [];
$request->files = isset($request->files) ? $request->files : [];
$request->server = isset($request->server) ? $request->server : [];
$request->server['REQUEST_URI'] = isset($request->server['request_uri']) ? $request->server['request_uri'] : '';
preg_match_all("/^(.+\.php)(\/.*)$/", $request->server['REQUEST_URI'], $matches);
$request->server['REQUEST_URI'] = isset($matches[2]) ? $matches[2][0] : '';
if ($request->server['request_uri'] == '/favicon.ico') {
$response->end();
return;
}
$this->fix_gpc_magic($request);
$this->app->initSwooleRequest($request);
 
$data = $this->app->handleSwooleHttp();
$response->status($data->getStatusCode());
$response->end($data->getContent());
return;
}
 
public function start()
Whitespace found at end of line
{
echo "HTTP Server Start...".PHP_EOL;
$this->http->start();
}
 
Method name "SwooleKernal::fix_gpc_magic" is not in camel caps format
The method fix_gpc_magic is not named in camelCase.
public function fix_gpc_magic($request)
{
static $fixed = false;
Blank line found at start of control structure
if (!$fixed && ini_get('magic_quotes_gpc')) {
 
array_walk($request->get, '_fix_gpc_magic');
array_walk($request->post, '_fix_gpc_magic');
array_walk($request->cookie, '_fix_gpc_magic');
array_walk($request->files, '_fix_gpc_magic_files');
Blank line found at end of control structure
 
}
$fixed = true;
}
 
Avoid unused private methods such as '_fix_gpc_magic'.
Method name "SwooleKernal::_fix_gpc_magic" is not in camel caps format
Method name "_fix_gpc_magic" should not be prefixed with an underscore to indicate visibility
The method _fix_gpc_magic is not named in camelCase.
private static function _fix_gpc_magic(&$item)
{
if (is_array($item)) {
array_walk($item, '_fix_gpc_magic');
Expected 1 space after closing brace; newline found
}
The method _fix_gpc_magic uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
else {
$item = stripslashes($item);
}
}
 
Avoid unused private methods such as '_fix_gpc_magic_files'.
Method name "SwooleKernal::_fix_gpc_magic_files" is not in camel caps format
Method name "_fix_gpc_magic_files" should not be prefixed with an underscore to indicate visibility
The method _fix_gpc_magic_files is not named in camelCase.
private static function _fix_gpc_magic_files(&$item, $key)
{
Blank line found at start of control structure
if ($key != 'tmp_name') {
 
if (is_array($item)) {
Line indented incorrectly; expected at least 16 spaces, found 14
array_walk($item, '_fix_gpc_magic_files');
Expected 1 space after closing brace; newline found
}
The method _fix_gpc_magic_files uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
else {
Line indented incorrectly; expected at least 16 spaces, found 14
$item = stripslashes($item);
}
Blank line found at end of control structure
 
}
}
Expected 1 blank line at end of file; 2 found
}