| Conditions | 14 |
| Paths | 90 |
| Total Lines | 68 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 19 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 8 | public function __construct(){ |
||
| 9 | |||
| 10 | $config = (new Config)->get(); |
||
| 11 | |||
| 12 | if(!isset($_SERVER['HTTP_ACCEPT'])) $_SERVER['HTTP_ACCEPT'] = '*/*'; |
||
| 13 | $acceptSrc = explode(',',$_SERVER['HTTP_ACCEPT']); |
||
| 14 | foreach($acceptSrc as $key=>$value){ |
||
| 15 | $value = explode('/',$value); |
||
| 16 | $value[1] = explode(';',$value[1]); |
||
| 17 | $name = array_shift($value[1]); |
||
| 18 | $data = []; |
||
| 19 | foreach($value[1] as $k=>$v){ |
||
| 20 | $v = explode('=',$v); |
||
| 21 | $data[$v[0]] = $v[1]; |
||
| 22 | } |
||
| 23 | $accept[$value[0]][$name] = $data; |
||
| 24 | } |
||
| 25 | |||
| 26 | unset($acceptSrc,$key,$value,$name,$data,$k,$v); |
||
| 27 | |||
| 28 | $requestUri = parse_url($_SERVER['REQUEST_URI']); |
||
| 29 | if($requestUri['path'] == '/javascript.js'){ |
||
| 30 | header('Content-Type: application/javascript'); |
||
| 31 | if(isset($requestUri['query'])){ |
||
| 32 | $query = explode(':',$requestUri['query']); |
||
| 33 | (new Content)->js($query); |
||
| 34 | } |
||
| 35 | exit; |
||
| 36 | } |
||
| 37 | |||
| 38 | header('Access-Control-Allow-Origin: *'); |
||
| 39 | header('Access-Control-Max-Age: 31556926'); |
||
| 40 | header('Access-Control-Allow-Credentials: true'); |
||
| 41 | header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT'); |
||
| 42 | |||
| 43 | if(isset($accept['application']['view'])){ |
||
| 44 | header('Content-Type: text/html'); |
||
| 45 | (new RestApi)->view(); |
||
| 46 | } else if(isset($accept['application']['widget'])){ |
||
| 47 | header('Content-Type: text/html'); |
||
| 48 | (new RestApi)->widget(); |
||
| 49 | } else if(isset($accept['application']['apps'])){ |
||
| 50 | header('Content-Type: application/json'); |
||
| 51 | $query = json_decode(file_get_contents('php://input'),1); |
||
| 52 | $result = []; |
||
| 53 | foreach($query as $method=>$params){ |
||
| 54 | $stableParams = []; |
||
| 55 | $file = $config['core']['apps'].'/'.$method.'.php'; |
||
| 56 | $func = require_once($file); |
||
| 57 | $reflection = new \ReflectionFunction($func); |
||
| 58 | foreach($reflection->getParameters() as $key=>$value){ |
||
| 59 | if(isset($params[$value->name])) $stableParams[$value->name] = $params[$value->name]; |
||
| 60 | else $stableParams[$value->name] = null; |
||
| 61 | } |
||
| 62 | $name = explode('/',$method); |
||
| 63 | $count = count($name)-1; |
||
| 64 | $app = new Application; |
||
| 65 | foreach($name as $key=>$var){ |
||
| 66 | if($count == $key) $app = call_user_method_array($var,$app,$stableParams); |
||
| 67 | else $app = $app->{$var}; |
||
| 68 | } |
||
| 69 | $result[$method] = $app; |
||
| 70 | } |
||
| 71 | die(json_encode($result)); |
||
| 72 | } else { |
||
| 73 | (new Content)->page(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 79 |
This check marks private properties in classes that are never used. Those properties can be removed.