Skip to content

Commit 51f87a5

Browse files
committed
Code. PHPCS inspection implemented.
1 parent 4babef1 commit 51f87a5

16 files changed

+1674
-1415
lines changed

CleantalkValidate.php

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,72 @@
11
<?php
2-
//require_once "vendor/autoload.php"; -- Composer
2+
3+
namespace Cleantalk;
34

45
require_once "lib/Cleantalk.php";
56
require_once "lib/CleantalkRequest.php";
67
require_once "lib/CleantalkResponse.php";
78
require_once "lib/CleantalkHelper.php";
89

10+
/*
11+
CleanTalk's global vars
12+
*/
13+
session_start();
14+
15+
if ( ! count($_POST) ) {
16+
$_SESSION['ct_submit_time'] = time();
17+
}
18+
919
/**
10-
* CleanTalk anti-spam script for any web form
20+
* CleanTalk anti-spam script for any web form
1121
*
1222
* @version 1.1
1323
* @package CleanTalk
1424
* @subpackage Base
1525
* @author СleanTalk team ([email protected])
1626
* @copyright (C) 2014 СleanTalk team (http://cleantalk.org)
1727
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
18-
* @see https://github.com/CleanTalk/php-antispam
19-
*
28+
* @see https://github.com/CleanTalk/php-antispam
29+
* @phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace
2030
*/
21-
use Cleantalk\CleantalkRequest;
22-
use Cleantalk\Cleantalk;
23-
use Cleantalk\CleantalkHelper;
24-
/*
25-
CleanTalk's global vars
26-
*/
27-
session_start();
28-
29-
if (!count($_POST))
30-
$_SESSION['ct_submit_time'] = time();
31-
32-
class CleantalkValidate
31+
class CleantalkValidate
3332
{
3433
public static $server_url = 'https://moderate.cleantalk.org';
3534
public static $access_key = 'your access key';
3635

37-
public static function spamCheckUser($name = '', $email = '')
38-
{
39-
$ct_request = new CleantalkRequest();
40-
$ct_request->auth_key = self::$access_key;
41-
$ct_request->agent = 'php-api';
42-
$ct_request->sender_email = $email;
43-
$ct_request->sender_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
44-
$ct_request->sender_nickname = $name;
45-
$ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
46-
$ct_request->js_on = 1;
47-
$ct = new Cleantalk();
48-
$ct->server_url = self::$server_url;
49-
// Check
50-
$ct_result = $ct->isAllowUser($ct_request);
36+
public static function spamCheckUser($name = '', $email = '')
37+
{
38+
$ct_request = new CleantalkRequest();
39+
$ct_request->auth_key = self::$access_key;
40+
$ct_request->agent = 'php-api';
41+
$ct_request->sender_email = $email;
42+
$ct_request->sender_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
43+
$ct_request->sender_nickname = $name;
44+
$ct_request->submit_time = time() - (int)$_SESSION['ct_submit_time'];
45+
$ct_request->js_on = 1;
46+
$ct = new Cleantalk();
47+
$ct->server_url = self::$server_url;
48+
// Check
49+
$ct_result = $ct->isAllowUser($ct_request);
5150

52-
return $ct_result;
53-
}
54-
public static function spamCheckMessage($name = '', $email = '', $message = '')
55-
{
56-
$ct_request = new CleantalkRequest();
57-
$ct_request->auth_key = self::$access_key;
58-
$ct_request->agent = 'php-api';
59-
$ct_request->sender_email = $email;
60-
$ct_request->sender_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
61-
$ct_request->sender_nickname = $name;
62-
$ct_request->submit_time = time() - (int) $_SESSION['ct_submit_time'];
63-
$ct_request->message = $message;
64-
$ct_request->js_on = 1;
65-
$ct = new Cleantalk();
66-
$ct->server_url = self::$server_url;
67-
// Check
68-
$ct_result = $ct->isAllowMessage($ct_request);
51+
return $ct_result;
52+
}
6953

70-
return $ct_result;
71-
}
72-
}
54+
public static function spamCheckMessage($name = '', $email = '', $message = '')
55+
{
56+
$ct_request = new CleantalkRequest();
57+
$ct_request->auth_key = self::$access_key;
58+
$ct_request->agent = 'php-api';
59+
$ct_request->sender_email = $email;
60+
$ct_request->sender_ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
61+
$ct_request->sender_nickname = $name;
62+
$ct_request->submit_time = time() - (int)$_SESSION['ct_submit_time'];
63+
$ct_request->message = $message;
64+
$ct_request->js_on = 1;
65+
$ct = new Cleantalk();
66+
$ct->server_url = self::$server_url;
67+
// Check
68+
$ct_result = $ct->isAllowMessage($ct_request);
7369

70+
return $ct_result;
71+
}
72+
}

cleantalk-antispam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
require_once "lib/CleantalkHelper.php";
55
require_once "lib/CleantalkRequest.php";
66
require_once "lib/CleantalkResponse.php";
7-
require_once "lib/CleantalkAntispam.php";
7+
require_once "lib/CleantalkAntispam.php";

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,33 @@
1414
"files": [
1515
"lib/cleantalk-php-patch.php"
1616
]
17+
},
18+
"require-dev": {
19+
"vimeo/psalm": "^4.8",
20+
"phpunit/phpunit": "^7.5",
21+
"squizlabs/php_codesniffer": "3.*",
22+
"phpcompatibility/php-compatibility": "@dev",
23+
"yoast/phpunit-polyfills": "^1.0",
24+
"ext-dom": "*",
25+
"wp-cli/wp-cli-bundle": "*"
26+
},
27+
"scripts": {
28+
"test": [
29+
"vendor/bin/phpunit --configuration tests/phpunit.xml",
30+
"vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility",
31+
"vendor/bin/phpcs --standard=tests/.phpcs.xml",
32+
"vendor/bin/psalm --no-cache --config=psalm.xml"
33+
],
34+
"psalm_l1": [
35+
"vendor/bin/psalm --no-cache --config=psalm.xml"
36+
],
37+
"just_phpunit": [
38+
"vendor/bin/phpunit --configuration tests/phpunit.xml --debug"
39+
]
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"dealerdirect/phpcodesniffer-composer-installer": true
44+
}
1745
}
1846
}

example.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
//require_once "vendor/autoload.php"; -- Composer
32

43
require_once "lib/Cleantalk.php";
54
require_once "lib/CleantalkRequest.php";
@@ -16,40 +15,39 @@
1615
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
1716
* @see https://cleantalk.org/help/api-check-message
1817
*
19-
*/
18+
*/
2019

2120
use Cleantalk\CleantalkRequest;
2221
use Cleantalk\Cleantalk;
2322
use Cleantalk\CleantalkAPI;
2423

2524
// Take params from config
2625
$config_url = 'https://moderate.cleantalk.org';
27-
$auth_key = null; // Set Cleantalk auth key
26+
$auth_key = null; // Set Cleantalk auth key
2827

2928

3029
// The facility in which to store the query parameters
3130
$ct_request = new CleantalkRequest();
3231

33-
$ct_request->auth_key = $auth_key;
34-
$ct_request->message = 'stop_word';
35-
$ct_request->sender_email = '[email protected]';
32+
$ct_request->auth_key = $auth_key;
33+
$ct_request->message = 'stop_word';
34+
$ct_request->sender_email = '[email protected]';
3635
$ct_request->sender_nickname = 'John Dow';
37-
$ct_request->example = str_repeat('Just text ', 10);
38-
$ct_request->agent = 'php-api';
39-
$ct_request->sender_ip = '178.32.183.43';
40-
$ct_request->event_token = isset($_POST['ct_bot_detector_event_token']) ? $_POST['ct_bot_detector_event_token'] : null;
36+
$ct_request->example = str_repeat('Just text ', 10);
37+
$ct_request->agent = 'php-api';
38+
$ct_request->sender_ip = '178.32.183.43';
39+
$ct_request->event_token = isset($_POST['ct_bot_detector_event_token']) ? $_POST['ct_bot_detector_event_token'] : null;
4140

42-
$ct = new Cleantalk();
41+
$ct = new Cleantalk();
4342
$ct->server_url = $config_url;
4443

4544
// Check
4645
$ct_result = $ct->isAllowMessage($ct_request);
4746

48-
if ($ct_result->allow == 1) {
47+
if ( $ct_result->allow == 1 ) {
4948
echo 'Comment allowed. Reason ' . $ct_result->comment;
5049
} else {
5150
echo 'Comment blocked. Reason ' . $ct_result->comment;
5251
}
5352
echo "<br/>CleantalkAPI call example:<br/>";
54-
var_dump(CleantalkAPI::method__notice_validate_key('',''));
55-
?>
53+
var_dump(CleantalkAPI::method__notice_validate_key('', ''));

0 commit comments

Comments
 (0)