| 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  | 
            ||
| 53 | public function execute()  | 
            ||
| 54 |     { | 
            ||
| 55 |         try { | 
            ||
| 56 | $response = array();  | 
            ||
| 57 |             $secretKey = $this->getRequest()->getParam('secret'); | 
            ||
| 58 | $privateKey = isset($this->config['pmt_private_key']) ? $this->config['pmt_private_key'] : null;  | 
            ||
| 59 | |||
| 60 |             if ($secretKey!='' && $privateKey!='') { | 
            ||
| 61 | $this->checkDbLogTable();  | 
            ||
| 62 | /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */  | 
            ||
| 63 | $dbConnection = $this->dbObject->getConnection();  | 
            ||
| 64 | $tableName = $this->dbObject->getTableName(self::LOGS_TABLE);  | 
            ||
| 65 | $sql = $dbConnection  | 
            ||
| 66 | ->select()  | 
            ||
| 67 |                     ->from($tableName, array('log', 'createdAt')); | 
            ||
| 68 | |||
| 69 |                 if ($dateFrom = $this->getRequest()->getParam('from')) { | 
            ||
| 70 |                     $sql->where('createdAt > ?', $dateFrom); | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 73 |                 if ($dateTo = $this->getRequest()->getParam('to')) { | 
            ||
| 74 |                     $sql->where('createdAt < ?', $dateTo); | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 |                 $limit = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 50; | 
            ||
| 78 | $sql->limit($limit);  | 
            ||
| 79 |                 $sql->order('createdAt', 'desc'); | 
            ||
| 80 | |||
| 81 | $results = $dbConnection->fetchAll($sql);  | 
            ||
| 82 |                 if (isset($results) && $privateKey == $secretKey) { | 
            ||
| 83 |                     foreach ($results as $key => $result) { | 
            ||
| 84 | $response[$key]['timestamp'] = $result['createdAt'];  | 
            ||
| 85 | $response[$key]['log'] = json_decode($result['log']);  | 
            ||
| 86 | }  | 
            ||
| 87 |                 } else { | 
            ||
| 88 | $response['result'] = 'Error';  | 
            ||
| 89 | }  | 
            ||
| 90 | |||
| 91 | $response = json_encode($response);  | 
            ||
| 92 |                 header("HTTP/1.1 200", true, 200); | 
            ||
| 93 |                 header('Content-Type: application/json', true); | 
            ||
| 94 |                 header('Content-Length: '.strlen($response)); | 
            ||
| 95 | echo($response);  | 
            ||
| 96 | exit();  | 
            ||
| 97 | }  | 
            ||
| 98 |         } catch (\Exception $e) { | 
            ||
| 99 | die($e->getMessage());  | 
            ||
| 100 | }  | 
            ||
| 154 |