| Conditions | 7 |
| Paths | 12 |
| Total Lines | 60 |
| Code Lines | 34 |
| 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 |
||
| 65 | public function run() |
||
| 66 | { |
||
| 67 | if (!$_SERVER['REQUEST_URI']) |
||
| 68 | { |
||
| 69 | header('Content-Type: application/json; charset=UTF-8'); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($_SERVER['REQUEST_URI'] == '/category/list') { |
||
| 73 | $categories = $this->db->prepare('SELECT * FROM categories'); |
||
| 74 | $categories->execute(); |
||
| 75 | echo json_encode($categories->fetchAll(PDO::FETCH_OBJ), JSON_UNESCAPED_UNICODE); |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($_SERVER['REQUEST_URI'] == '/category/add') { |
||
| 80 | |||
| 81 | $token = $this->getToken(); |
||
| 82 | if(!$token) { |
||
| 83 | die(json_encode(['error'=>'authentication error!'])); |
||
| 84 | } |
||
| 85 | |||
| 86 | $client = new Client(); |
||
| 87 | $headers = [ |
||
| 88 | 'Authorization' => 'Bearer ' . $token, |
||
| 89 | 'Accept' => 'application/json', |
||
| 90 | ]; |
||
| 91 | $res = $client->request('GET', 'http://user_management_nginx_1/user/checkToken', |
||
| 92 | [ |
||
| 93 | 'headers' => $headers, |
||
| 94 | 'exceptions' => false |
||
| 95 | ] |
||
| 96 | ); |
||
| 97 | $httpCode = $res->getStatusCode(); |
||
| 98 | if($httpCode!=200) |
||
| 99 | { |
||
| 100 | die(json_encode(['error'=>'authentication error!'])); |
||
| 101 | } |
||
| 102 | |||
| 103 | |||
| 104 | $response = json_decode($res->getBody(),1); |
||
| 105 | $isAdmin = $response['user']['is_admin']; |
||
| 106 | |||
| 107 | if(!$isAdmin) { |
||
| 108 | die(json_encode(['error'=>'admin only!'])); |
||
| 109 | } |
||
| 110 | |||
| 111 | $post = json_decode(file_get_contents('php://input'),true); |
||
| 112 | |||
| 113 | $data = [ |
||
| 114 | 'category_name' => $post['category_name'] |
||
| 115 | ]; |
||
| 116 | $sql = "INSERT INTO categories (category_name) VALUES (:category_name)"; |
||
| 117 | $stmt= $this->db->prepare($sql); |
||
| 118 | $stmt->execute($data); |
||
| 119 | |||
| 120 | die(json_encode(['id'=>$this->db->lastInsertId()])); |
||
| 121 | return; |
||
| 122 | } |
||
| 123 | |||
| 124 | die('<h2 style="text-align: center;">Category Management</h2>'); |
||
| 125 | } |
||
| 145 | } |
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