1 | <?php |
||||||
2 | namespace Pagantis\Pagantis\Controller\Payment; |
||||||
3 | |||||||
4 | use Magento\Framework\App\Action\Action; |
||||||
5 | use Magento\Framework\App\Action\Context; |
||||||
6 | use Magento\Framework\App\ResourceConnection; |
||||||
7 | use Magento\Framework\DB\Ddl\Table; |
||||||
8 | use Magento\Framework\App\RequestInterface; |
||||||
9 | use Magento\Framework\App\Request\InvalidRequestException; |
||||||
10 | use \Pagantis\Pagantis\Helper\Config; |
||||||
0 ignored issues
–
show
|
|||||||
11 | |||||||
12 | class LogV2 extends Action |
||||||
13 | { |
||||||
14 | /** Concurrency tablename */ |
||||||
15 | const LOGS_TABLE = 'Pagantis_logs'; |
||||||
16 | |||||||
17 | /** @var mixed $config */ |
||||||
18 | protected $config; |
||||||
19 | |||||||
20 | /** @var ResourceConnection $dbObject */ |
||||||
21 | protected $dbObject; |
||||||
22 | |||||||
23 | /** |
||||||
24 | * LogV2 constructor. |
||||||
25 | * |
||||||
26 | * @param Context $context |
||||||
27 | * @param Config $pagantisConfig |
||||||
28 | * @param ResourceConnection $dbObject |
||||||
29 | * @param RequestInterface $request |
||||||
30 | */ |
||||||
31 | public function __construct( |
||||||
32 | Context $context, |
||||||
33 | Config $pagantisConfig, |
||||||
34 | ResourceConnection $dbObject, |
||||||
35 | RequestInterface $request |
||||||
36 | ) { |
||||||
37 | $this->config = $pagantisConfig->getConfig(); |
||||||
38 | $this->dbObject = $dbObject; |
||||||
39 | |||||||
40 | // CsrfAwareAction Magento2.3 compatibility |
||||||
41 | if (interface_exists("\Magento\Framework\App\CsrfAwareActionInterface")) { |
||||||
42 | if (isset($request) && $request->isPost() && empty($request->getParam('form_key'))) { |
||||||
0 ignored issues
–
show
The method
isPost() does not exist on Magento\Framework\App\RequestInterface . It seems like you code against a sub-type of Magento\Framework\App\RequestInterface such as Magento\Framework\Webapi\Request or Magento\Framework\App\Request\Http .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
43 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); |
||||||
44 | $formKey = $objectManager->get(\Magento\Framework\Data\Form\FormKey::class); |
||||||
45 | $request->setParam('form_key', $formKey->getFormKey()); |
||||||
0 ignored issues
–
show
The method
setParam() does not exist on Magento\Framework\App\RequestInterface . Did you maybe mean setParams() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
46 | } |
||||||
47 | } |
||||||
48 | |||||||
49 | return parent::__construct($context); |
||||||
0 ignored issues
–
show
Are you sure the usage of
parent::__construct($context) targeting Magento\Framework\App\Action\Action::__construct() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||||||
50 | } |
||||||
51 | |||||||
52 | /** |
||||||
53 | * Main function |
||||||
54 | * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
||||||
55 | */ |
||||||
56 | public function execute() |
||||||
57 | { |
||||||
58 | try { |
||||||
59 | $response = array(); |
||||||
60 | $secretKey = $this->getRequest()->getParam('secret'); |
||||||
61 | $privateKey = isset($this->config['pagantis_private_key']) ? $this->config['pagantis_private_key'] : null; |
||||||
62 | |||||||
63 | if ($secretKey!='' && $privateKey!='') { |
||||||
64 | $this->checkDbLogTable(); |
||||||
65 | /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
||||||
66 | $dbConnection = $this->dbObject->getConnection(); |
||||||
67 | $tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
||||||
68 | $sql = $dbConnection |
||||||
69 | ->select() |
||||||
70 | ->from($tableName, array('log', 'createdAt')); |
||||||
0 ignored issues
–
show
The call to
Magento\Framework\DB\Select::from() has too many arguments starting with $tableName .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.
Loading history...
|
|||||||
71 | |||||||
72 | if ($dateFrom = $this->getRequest()->getParam('from')) { |
||||||
73 | $sql->where('createdAt > ?', $dateFrom); |
||||||
74 | } |
||||||
75 | |||||||
76 | if ($dateTo = $this->getRequest()->getParam('to')) { |
||||||
77 | $sql->where('createdAt < ?', $dateTo); |
||||||
78 | } |
||||||
79 | |||||||
80 | $limit = ($this->getRequest()->getParam('limit')) ? $this->getRequest()->getParam('limit') : 50; |
||||||
81 | $sql->limit($limit); |
||||||
82 | $sql->order('createdAt', 'desc'); |
||||||
0 ignored issues
–
show
The call to
Magento\Framework\DB\Select::order() has too many arguments starting with 'desc' .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.
Loading history...
|
|||||||
83 | |||||||
84 | $results = $dbConnection->fetchAll($sql); |
||||||
85 | if (isset($results) && $privateKey == $secretKey) { |
||||||
86 | foreach ($results as $key => $result) { |
||||||
87 | $response[$key]['timestamp'] = $result['createdAt']; |
||||||
88 | $response[$key]['log'] = json_decode($result['log']); |
||||||
89 | } |
||||||
90 | } else { |
||||||
91 | $response['result'] = 'Error'; |
||||||
92 | } |
||||||
93 | |||||||
94 | $response = json_encode($response); |
||||||
95 | header("HTTP/1.1 200", true, 200); |
||||||
96 | header('Content-Type: application/json', true); |
||||||
97 | header('Content-Length: '.strlen($response)); |
||||||
98 | echo($response); |
||||||
99 | exit(); |
||||||
0 ignored issues
–
show
|
|||||||
100 | } |
||||||
101 | } catch (\Exception $e) { |
||||||
102 | die($e->getMessage()); |
||||||
0 ignored issues
–
show
|
|||||||
103 | } |
||||||
104 | } |
||||||
105 | |||||||
106 | /** |
||||||
107 | * @return void|\Zend_Db_Statement_Interface |
||||||
108 | * @throws \Zend_Db_Exception |
||||||
109 | */ |
||||||
110 | private function checkDbLogTable() |
||||||
111 | { |
||||||
112 | /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
||||||
113 | $dbConnection = $this->dbObject->getConnection(); |
||||||
114 | $tableName = $this->dbObject->getTableName(self::LOGS_TABLE); |
||||||
115 | if (!$dbConnection->isTableExists($tableName)) { |
||||||
116 | $table = $dbConnection |
||||||
117 | ->newTable($tableName) |
||||||
118 | ->addColumn( |
||||||
119 | 'id', |
||||||
120 | Table::TYPE_SMALLINT, |
||||||
121 | null, |
||||||
122 | array('nullable'=>false, 'auto_increment'=>true, 'primary'=>true) |
||||||
123 | ) |
||||||
124 | ->addColumn('log', Table::TYPE_TEXT, null, array('nullable'=>false)) |
||||||
125 | ->addColumn( |
||||||
126 | 'createdAt', |
||||||
127 | Table::TYPE_TIMESTAMP, |
||||||
128 | null, |
||||||
129 | array('nullable'=>false, |
||||||
130 | 'default'=>Table::TIMESTAMP_INIT) |
||||||
131 | ); |
||||||
132 | return $dbConnection->createTable($table); |
||||||
133 | } |
||||||
134 | return; |
||||||
135 | } |
||||||
136 | |||||||
137 | /** |
||||||
138 | * @param RequestInterface $request |
||||||
139 | * |
||||||
140 | * @return InvalidRequestException|null |
||||||
141 | */ |
||||||
142 | public function createCsrfValidationException(RequestInterface $request) |
||||||
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||
143 | { |
||||||
144 | return null; |
||||||
145 | } |
||||||
146 | |||||||
147 | /** |
||||||
148 | * @param RequestInterface $request |
||||||
149 | * |
||||||
150 | * @return bool|null |
||||||
151 | */ |
||||||
152 | public function validateForCsrf(RequestInterface $request) |
||||||
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||
153 | { |
||||||
154 | return true; |
||||||
155 | } |
||||||
156 | } |
||||||
157 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: