Skip to content

Commit bc8377f

Browse files
committed
Doc. BaseCall. Default params class. Docs added.
1 parent 2b141d8 commit bc8377f

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

lib/Cleantalk/ApbctWP/BaseCall/DefaultParams.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public function __construct($auth_key, $sender_info = [])
1818
$this->sender_info = $sender_info;
1919
}
2020

21+
/**
22+
* Get default params
23+
* @return array
24+
*/
2125
public function get()
2226
{
2327
return [
@@ -28,26 +32,42 @@ public function get()
2832
'x_real_ip' => $this->getXRealIP(),
2933
'js_on' => $this->getJsOn(),
3034
'agent' => $this->getAgent(),
31-
'submit_time' => $this->getSubmittime(),
35+
'submit_time' => $this->getSubmitTime(),
3236
];
3337
}
3438

39+
/**
40+
* Get sender IP
41+
* @return string|null
42+
*/
3543
public function getSenderIP()
3644
{
3745
$test_ip = $this->getTestIp();
3846
return $test_ip ?? $this->ipGet('remote_addr');
3947
}
4048

49+
/**
50+
* Get X-Forwarded-For
51+
* @return string|null
52+
*/
4153
public function getXForwardedForIP()
4254
{
4355
return $this->ipGet('x_forwarded_for');
4456
}
4557

58+
/**
59+
* Get X-Real-IP
60+
* @return string|null
61+
*/
4662
public function getXRealIP()
4763
{
4864
return $this->ipGet('x_real_ip');
4965
}
5066

67+
/**
68+
* Get JS on
69+
* @return int|null
70+
*/
5171
public function getJsOn()
5272
{
5373
$cookieValue = Sanitize::cleanTextField(
@@ -59,25 +79,40 @@ public function getJsOn()
5979
: apbct_js_test(Post::getString('ct_checkjs'));
6080
}
6181

62-
public function getSubmittime()
82+
/**
83+
* @return int|null
84+
*/
85+
public function getSubmitTime()
6386
{
6487
return SubmitTimeHandler::getFromRequest();
6588
}
6689

6790
/**
68-
* ---- Wrapper methods for testability ----
91+
* Retrieves the IP address based on the specified type.
92+
*
93+
* @param string $type The type or format of the IP address to retrieve.
94+
* @return string|null Returns the IP address as a string if available; otherwise, returns null.
6995
*/
70-
7196
public function ipGet($type)
7297
{
7398
return \Cleantalk\ApbctWP\Helper::ipGet($type, false);
7499
}
75100

101+
/**
102+
* Retrieves the value of the constant APBCT_AGENT.
103+
*
104+
* @return string Returns the value of APBCT_AGENT.
105+
*/
76106
public function getAgent()
77107
{
78108
return APBCT_AGENT;
79109
}
80110

111+
/**
112+
* Retrieves the value of the constant CT_TEST_IP if it is defined and not empty.
113+
*
114+
* @return string|null Returns the value of CT_TEST_IP if available; otherwise, returns null.
115+
*/
81116
public function getTestIp()
82117
{
83118
return defined('CT_TEST_IP') && !empty(CT_TEST_IP)

tests/ApbctWP/BaseCall/BaseCallDefaultParamsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private function createMockedInstance($authKey = 'test_key', $senderInfo = [])
1919
'getXForwardedForIP',
2020
'getXRealIP',
2121
'getJsOn',
22-
'getSubmittime',
22+
'getSubmitTime',
2323
'getAgent',
2424
'getTestIp',
2525
'ipGet',
@@ -128,11 +128,11 @@ public function testGetSubmittime()
128128
$obj = $this->getMockBuilder(DefaultParams::class)
129129
->setConstructorArgs(['test_key', []])
130130
->onlyMethods([
131-
'getSubmittime',
131+
'getSubmitTime',
132132
])
133133
->getMock();
134134

135-
$obj->method('getSubmittime')
135+
$obj->method('getSubmitTime')
136136
->willReturn(123);
137137

138138
$this->assertEquals(123, $obj->get()['submit_time']);
@@ -163,7 +163,7 @@ public function testGetFullData()
163163
'getXForwardedForIP',
164164
'getXRealIP',
165165
'getJsOn',
166-
'getSubmittime',
166+
'getSubmitTime',
167167
'getAgent',
168168
'getTestIp',
169169
'ipGet',
@@ -173,11 +173,11 @@ public function testGetFullData()
173173
$obj->method('getTestIp')->willReturn(null);
174174
$obj->method('getSenderIP')->willReturn('1.2.3.4');
175175
$obj->method('getAgent')->willReturn('test-agent');
176-
$obj->method('getSubmittime')->willReturn(999);
176+
$obj->method('getSubmitTime')->willReturn(999);
177177
$obj->method('getXRealIP')->willReturn('10.0.0.2');
178178
$obj->method('getXForwardedForIP')->willReturn('10.0.0.1');
179179
$obj->method('getJsOn')->willReturn(1);
180-
$obj->method('getSubmittime')->willReturn(true);
180+
$obj->method('getSubmitTime')->willReturn(true);
181181

182182
$result = $obj->get();
183183

0 commit comments

Comments
 (0)