Skip to content

Commit 5264969

Browse files
committed
Can't compose constants in PHP 5.5
1 parent c6f9b72 commit 5264969

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/ReCaptcha/RequestMethod/SocketPost.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@
3737
*/
3838
class SocketPost implements RequestMethod
3939
{
40-
/**
41-
* @const string Bad request error
42-
*/
43-
const BAD_CONNECTION = '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_CONNECTION.'"]}';
44-
45-
/**
46-
* @const string Bad response error
47-
*/
48-
const BAD_RESPONSE = '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_RESPONSE.'"]}';
49-
5040
/**
5141
* Socket to the reCAPTCHA service
5242
* @var Socket
@@ -78,7 +68,7 @@ public function submit(RequestParameters $params)
7868
$urlParsed = parse_url($this->siteVerifyUrl);
7969

8070
if (false === $this->socket->fsockopen('ssl://' . $urlParsed['host'], 443, $errno, $errstr, 30)) {
81-
return self::BAD_CONNECTION;
71+
return '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_CONNECTION.'"]}';
8272
}
8373

8474
$content = $params->toQueryString();
@@ -100,7 +90,7 @@ public function submit(RequestParameters $params)
10090
$this->socket->fclose();
10191

10292
if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
103-
return self::BAD_RESPONSE;
93+
return '{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_RESPONSE.'"]}';
10494
}
10595

10696
$parts = preg_split("#\n\s*\n#Uis", $response);

tests/ReCaptcha/RequestMethod/SocketPostTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace ReCaptcha\RequestMethod;
2828

29+
use ReCaptcha\ReCaptcha;
2930
use ReCaptcha\RequestParameters;
3031
use PHPUnit\Framework\TestCase;
3132

@@ -108,7 +109,7 @@ public function testSubmitBadResponse()
108109

109110
$ps = new SocketPost($socket);
110111
$response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version"));
111-
$this->assertEquals(SocketPost::BAD_RESPONSE, $response);
112+
$this->assertEquals('{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_RESPONSE.'"]}', $response);
112113
}
113114

114115
public function testSubmitBadRequest()
@@ -122,6 +123,6 @@ public function testSubmitBadRequest()
122123
->willReturn(false);
123124
$ps = new SocketPost($socket);
124125
$response = $ps->submit(new RequestParameters("secret", "response", "remoteip", "version"));
125-
$this->assertEquals(SocketPost::BAD_CONNECTION, $response);
126+
$this->assertEquals('{"success": false, "error-codes": ["'.ReCaptcha::E_BAD_CONNECTION.'"]}', $response);
126127
}
127128
}

0 commit comments

Comments
 (0)