| Conditions | 6 |
| Paths | 10 |
| Total Lines | 63 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 66 | public function run() |
||
| 67 | { |
||
| 68 | if (!$_SERVER['REQUEST_URI']) |
||
| 69 | { |
||
| 70 | header('Content-Type: application/json; charset=UTF-8'); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($_SERVER['REQUEST_URI'] == '/comment/list') { |
||
| 74 | $post = json_decode(file_get_contents('php://input'),true); |
||
| 75 | $product_id = $post['product_id']; |
||
| 76 | $comments = $this->db->prepare('SELECT * FROM comments where product_id=:product_id'); |
||
| 77 | $comments->execute(['product_id'=>$product_id]); |
||
| 78 | echo json_encode($comments->fetchAll(PDO::FETCH_OBJ), JSON_UNESCAPED_UNICODE); |
||
| 79 | return; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($_SERVER['REQUEST_URI'] == '/comment/add') { |
||
| 83 | |||
| 84 | $token = $this->getToken(); |
||
| 85 | if(!$token) { |
||
| 86 | die(json_encode(['error'=>'authentication error!'])); |
||
| 87 | } |
||
| 88 | |||
| 89 | $client = new Client(); |
||
| 90 | $headers = [ |
||
| 91 | 'Authorization' => 'Bearer ' . $token, |
||
| 92 | 'Accept' => 'application/json', |
||
| 93 | ]; |
||
| 94 | $res = $client->request('GET', 'http://user_management_nginx_1/user/checkToken', |
||
| 95 | [ |
||
| 96 | 'headers' => $headers, |
||
| 97 | 'exceptions' => false |
||
| 98 | ] |
||
| 99 | ); |
||
| 100 | $httpCode = $res->getStatusCode(); |
||
| 101 | if($httpCode!=200) |
||
| 102 | { |
||
| 103 | die(json_encode(['error'=>'authentication error!'])); |
||
| 104 | } |
||
| 105 | |||
| 106 | $response = json_decode($res->getBody(),1); |
||
| 107 | |||
| 108 | |||
| 109 | |||
| 110 | $post = json_decode(file_get_contents('php://input'),true); |
||
| 111 | |||
| 112 | $data = [ |
||
| 113 | 'product_id' => $post['product_id'], |
||
| 114 | 'comment' => $post['comment'], |
||
| 115 | 'user_id' => $response['user']['id'], |
||
| 116 | 'user_name' => $response['user']['username'], |
||
| 117 | 'comment_date' => date('Y-m-d H:i:s') |
||
| 118 | ]; |
||
| 119 | $sql = "INSERT INTO comments (product_id, comment, user_id, user_name, comment_date) VALUES |
||
| 120 | (:product_id, :comment, :user_id, :user_name, :comment_date)"; |
||
| 121 | $stmt= $this->db->prepare($sql); |
||
| 122 | $stmt->execute($data); |
||
| 123 | |||
| 124 | die(json_encode(['id'=>$this->db->lastInsertId()], JSON_UNESCAPED_UNICODE)); |
||
| 125 | return; |
||
| 126 | } |
||
| 127 | |||
| 128 | die('<h2 style="text-align: center;">Comment Management</h2>'); |
||
| 129 | } |
||
| 147 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths