Conditions | 11 |
Paths | 365 |
Total Lines | 47 |
Code Lines | 33 |
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 |
||
40 | public function execute() |
||
41 | { |
||
42 | try { |
||
43 | $response = array(); |
||
44 | $secretKey = $this->getRequest()->getParam('secret'); |
||
45 | $privateKey = isset($this->config['secret_key']) ? $this->config['secret_key'] : null; |
||
46 | |||
47 | if ($secretKey!='' && $privateKey!='') { |
||
48 | $this->checkDbLogTable(); |
||
49 | /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
||
50 | $dbConnection = $this->dbObject->getConnection(); |
||
51 | $tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
||
52 | $sql = $dbConnection |
||
53 | ->select() |
||
54 | ->from($tableName, array('log', 'createdAt')); |
||
55 | |||
56 | if ($dateFrom = $this->getRequest()->getParam('from')) { |
||
57 | $sql->where('createdAt > ?', $dateFrom); |
||
58 | } |
||
59 | |||
60 | if ($dateTo = $this->getRequest()->getParam('to')) { |
||
61 | $sql->where('createdAt < ?', $dateTo); |
||
62 | } |
||
63 | |||
64 | $limit = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 50; |
||
65 | $sql->limit($limit); |
||
66 | $sql->order('createdAt', 'desc'); |
||
67 | |||
68 | $results = $dbConnection->fetchAll($sql); |
||
69 | if (isset($results) && $privateKey == $secretKey) { |
||
70 | foreach ($results as $key => $result) { |
||
71 | $response[$key]['timestamp'] = $result['createdAt']; |
||
72 | $response[$key]['log'] = json_decode($result['log']); |
||
73 | } |
||
74 | } else { |
||
75 | $response['result'] = 'Error'; |
||
76 | } |
||
77 | |||
78 | $response = json_encode($response); |
||
79 | header("HTTP/1.1 200", true, 200); |
||
80 | header('Content-Type: application/json', true); |
||
81 | header('Content-Length: '.strlen($response)); |
||
82 | echo($response); |
||
83 | exit(); |
||
84 | } |
||
85 | } catch (\Exception $e) { |
||
86 | die($e->getMessage()); |
||
87 | } |
||
111 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.