Conditions | 10 |
Paths | 10 |
Total Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
33 | public function save(array $data) |
||
34 | { |
||
35 | $this->connection->beginTransaction(); |
||
36 | |||
37 | try { |
||
38 | $id = Xhgui_Util::getId($data); |
||
39 | |||
40 | $requestTime = \DateTime::createFromFormat('U u', $data['meta']['request_ts_micro']['sec'].' '.$data['meta']['request_ts_micro']['usec']); |
||
41 | |||
42 | $infoStatement = $this->connection->prepare(' |
||
43 | insert into profiles_info( |
||
44 | id, url, simple_url, request_time, method, main_ct, main_wt, main_cpu, main_mu, main_pmu, application, version, branch,controller, action, remote_addr, session_id |
||
45 | ) values ( |
||
46 | :id, :url, :simple_url, :request_time, :method, :main_ct, :main_wt, :main_cpu, :main_mu, :main_pmu, :application, :version, :branch, :controller, :action, :remote_addr, :session_id |
||
47 | )'); |
||
48 | |||
49 | // get some data from meta and save in separate column to make it easier to search/filter |
||
50 | $infoStatement->execute(array( |
||
51 | 'id' => $id, |
||
52 | 'url'=> $data['meta']['url'], |
||
53 | 'simple_url' => $data['meta']['simple_url'], |
||
54 | 'request_time' => $requestTime->format('Y-m-d H:i:s.u'), |
||
55 | 'main_ct'=> $data['profile']['main()']['ct'], |
||
56 | 'main_wt'=> $data['profile']['main()']['wt'], |
||
57 | 'main_cpu' => $data['profile']['main()']['cpu'], |
||
58 | 'main_mu'=> $data['profile']['main()']['mu'], |
||
59 | 'main_pmu' => $data['profile']['main()']['pmu'], |
||
60 | 'application'=> !empty($data['meta']['application']) ? $data['meta']['application'] : null, |
||
61 | 'version'=> !empty($data['meta']['version']) ? $data['meta']['version'] : null, |
||
62 | 'branch' => !empty($data['meta']['branch']) ? $data['meta']['branch'] : null, |
||
63 | 'controller' => !empty($data['meta']['controller']) ? $data['meta']['controller'] : null, |
||
64 | 'action' => !empty($data['meta']['action']) ? $data['meta']['action'] : null, |
||
65 | 'session_id' => !empty($data['meta']['session_id']) ? $data['meta']['action'] : null, |
||
66 | 'method' => !empty($data['meta']['method']) ? $data['meta']['method'] : Xhgui_Util::getMethod(), |
||
67 | 'remote_addr' => !empty($data['meta']['SERVER']['REMOTE_ADDR']) ? $data['meta']['SERVER']['REMOTE_ADDR'] : null, |
||
68 | )); |
||
69 | |||
70 | $profileStatement = $this->connection->prepare('insert into profiles(profile_id, profiles) VALUES(:id, :profiles)'); |
||
71 | $profileStatement->execute(array( |
||
72 | 'id' => $id, |
||
73 | 'profiles' => json_encode($data['profile']), |
||
74 | )); |
||
75 | |||
76 | $metaStatement = $this->connection->prepare('insert into profiles_meta(profile_id, meta) VALUES(:id, :meta)'); |
||
77 | $metaStatement->execute(array( |
||
78 | 'id' => $id, |
||
79 | 'meta' => json_encode($data['meta']), |
||
80 | )); |
||
81 | |||
82 | $this->connection->commit(); |
||
83 | |||
84 | return true; |
||
85 | } catch (\Exception $e) { |
||
86 | $this->connection->rollBack(); |
||
87 | error_log('xhgui - ' . $e->getMessage()); |
||
88 | } |
||
89 | return false; |
||
90 | } |
||
91 | } |
||
92 |