Skip to content

Commit 65c1131

Browse files
committed
Coding standards improvements
1 parent df5b4e5 commit 65c1131

10 files changed

+66
-54
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ KnownUser API
4747
You can use the Known user setting to test if a specific user has arrived at your site via the queue,
4848
or if the user has tried to bypass the queue. The KnownUser validation must only be done on page requests.
4949

50+
Troubleshooting
51+
===============
52+
53+
> Error: Class KnownUser not found
54+
55+
When using _Composer Manager_, make sure you've rebuilded and updated `composer.json` correctly by:
56+
57+
drush composer-json-rebuild
58+
drush composer-manager update
59+
5060
Notes
5161
=====
5262

@@ -55,4 +65,4 @@ Notes
5565
- Older versions [API1](http://api.queue-it.net) has been deprecated now.
5666
- The service will accept both XML and JSON formatted data by setting the `Content-Type` HTTP header.
5767
- Source code and binaries are available at [Github](https://github.com/queueit).
58-
- For support of Queue-it Implementation, please contact Queue-itsupport at <[email protected]>.
68+
- For support of Queue-it Implementation, please contact Queue-it support at <[email protected]>.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "queueit/KnownUser.V3.PHP",
33
"type": "library",
44
"description": "The Queue-it Security Framework is used to ensure that end users cannot bypass the queue by adding a server-side integration to your server.",
5-
"homepage": "https://drupal.org/project/coder",
5+
"homepage": "https://github.com/drupal-modules/queueit",
66
"support": {
77
"issues": "https://github.com/queueit/KnownUser.V3.PHP/issues",
88
"source": "https://github.com/queueit/KnownUser.V3.PHP"

queueit.admin.inc

+12-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function queueit_settings_form($form, &$form_state) {
2323
'#options' => [
2424
'integration' => 'Integration config',
2525
'code' => 'Configuration in code',
26-
//'js' => 'JavaScript', // @todo
26+
// 'js' => 'JavaScript', // @todo
2727
],
2828
'#description' => t('Select the type of Queue-it implementation.<br>Select Integration Config to load the configuration from the Go Queue-it platform.<br>Select Configuration in code if your application server is not allowed to do external GET requests (this is without using the Trigger/Action paradigm).'),
2929
'#default_value' => variable_get('queueit_mode', 'code'),
@@ -78,22 +78,22 @@ function queueit_settings_form($form, &$form_state) {
7878
'#type' => 'textfield',
7979
'#title' => t('Culture of the queue ticket layout.'),
8080
'#description' => t('Culture of the queue ticket layout in the format specified <a href="!url">here</a>.',
81-
[ '!url' => 'https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx' ]
82-
),
81+
['!url' => 'https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx']
82+
),
8383
'#default_value' => variable_get('queueit_culture_of_layout'),
8484
);
8585
/* Validation parameters */
8686
$form['validate'] = array(
8787
'#title' => 'Validation logic',
8888
'#type' => 'fieldset',
8989
);
90-
// Exclude Queue-it on specific pages.
91-
$form['validate']['queueit_exclude_pages'] = array(
92-
'#type' => 'textarea',
93-
'#title' => t('Exclude Queue-it on specific pages.'),
94-
'#default_value' => variable_get('queueit_exclude_pages', QUEUEIT_EXCLUDE),
95-
'#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. It is recommended to exclude resources and AJAX calls."),
96-
);
90+
// Exclude Queue-it on specific pages.
91+
$form['validate']['queueit_exclude_pages'] = array(
92+
'#type' => 'textarea',
93+
'#title' => t('Exclude Queue-it on specific pages.'),
94+
'#default_value' => variable_get('queueit_exclude_pages', QUEUEIT_EXCLUDE),
95+
'#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. It is recommended to exclude resources and AJAX calls."),
96+
);
9797
$form['validate']['queueit_ignore_post'] = array(
9898
'#type' => 'checkbox',
9999
'#title' => t('Ignore queue validation for the POST requests.'),
@@ -144,14 +144,15 @@ function queueit_settings_form_validate($form, &$form_state) {
144144
module_load_include('php', 'queueit', 'src/classes/QueueitKnownUser');
145145
// Validate the configuration.
146146
try {
147-
$known_user = new QueueitKnownUser;
147+
$known_user = new QueueitKnownUser();
148148
if (!$known_user->validateConfig()) {
149149
drupal_set_message(t('Queue-it configuration is not valid.'), 'warning');
150150
}
151151
switch (variable_get('queueit_mode', 'code')) {
152152
case 'code':
153153
$result = $known_user->validateRequestByIntegrationConfig();
154154
break;
155+
155156
case 'integration':
156157
$config = $known_user->getIntegrationConfig();
157158
if (!$config) {

queueit.inc

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ function queueit_md2html($content) {
1212
// Convert new lines into <br>.
1313
$content = nl2br($content, FALSE);
1414
// Format code.
15-
$content = preg_replace( '/`(.*?)`/s', '<code>\1</code>', $content);
15+
$content = preg_replace('/`(.*?)`/s', '<code>\1</code>', $content);
1616
// Convert links.
1717
$content = preg_replace('/\[([^\[]+)\]\(([^\)]+)\)/', '<a href=\'\2\'>\1</a>', $content);
1818
// Convert headers.
1919
$content = preg_replace('/\n?(.*)\n=+/', '<h1>\1</h1>', $content);
2020
$content = preg_replace_callback('/\n(#+)(.*)/',
2121
function ($regs) {
22-
list($tmp, $chars, $header) = $regs;
22+
list(, $chars, $header) = $regs;
2323
return sprintf('<h%d>%s</h%d>', strlen($chars), trim($header), strlen($chars));
2424
},
2525
$content);
2626
// Remove not needed characters.
2727
$content = strtr($content, ['=' => '']);
28-
return $content;
28+
return $content;
2929
}

queueit.info

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name = Queue-it
22
description = Queue-it offers an API for programmatic access to configuring and controlling the queue.
3-
version = VERSION
43
core = 7.x
54
files[] = tests/queueit.test
65
configure = admin/config/services/queueit

queueit.install

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ function queueit_requirements($phase) {
1818
$requirements['queueit'] = array(
1919
'title' => $t('KnownUser.V3.PHP'),
2020
'severity' => $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
21-
'value' => t('%lib library %state.',
22-
['%lib' => 'KnownUser.V3.PHP',
23-
'%state' => $exists ? 'installed' : 'not installed']),
21+
'value' => $t('%lib library %state.',
22+
[
23+
'%lib' => 'KnownUser.V3.PHP',
24+
'%state' => $exists ? 'installed' : 'not installed',
25+
]),
2426
);
2527
module_load_include('php', 'queueit', 'src/classes/QueueitBase');
2628
if ($exists && class_exists('QueueitBase') && !((new QueueitBase)->validateConfig())) {
2729
$requirements['queueit']['value'] .= '&nbsp;' . $t("But not configured correctly.");
2830
$requirements['queueit']['severity'] = REQUIREMENT_WARNING;
29-
} else {
30-
$queueit = new QueueitBase;
31+
}
32+
else {
33+
$queueit = new QueueitBase();
3134
$config = $queueit->getIntegrationConfig();
3235
$requirements['queueit']['severity'] = $config ? REQUIREMENT_OK : REQUIREMENT_WARNING;
3336
$requirements['queueit']['description'] = json_encode(json_decode($config), TRUE);
@@ -36,4 +39,3 @@ function queueit_requirements($phase) {
3639

3740
return $requirements;
3841
}
39-

queueit.module

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Queue-it main module file.
66
*/
77

8-
define('QUEUEIT_EXCLUDE', "admin\nadmin/*\nsites/*\nsystem/ajax/*");
8+
define('QUEUEIT_EXCLUDE', "admin\nadmin/*\nsites/*\nsystem/ajax/*");
99

1010
/**
1111
* Implements hook_help().
@@ -16,7 +16,7 @@ function queueit_help($path, $arg) {
1616
$content .= file_get_contents(libraries_get_path('composer') . '/queueit/knownuserv3' . '/README.md');
1717
module_load_include('inc', 'queueit');
1818
switch ($path) {
19-
// Main module help for the queueit module
19+
// Main module help for the queueit module.
2020
case 'admin/help#queueit':
2121
return '<p>' . queueit_md2html($content) . '</p>';
2222
}
@@ -43,13 +43,13 @@ function queueit_init() {
4343
// Check for matching page path to exclude.
4444
$page_match = drupal_match_path($curr_path, drupal_strtolower($path));
4545
if ($curr_path != $_GET['q']) {
46-
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
46+
$page_match = $page_match || drupal_match_path($_GET['q'], drupal_strtolower($path));
4747
}
4848
if ($page_match) {
4949
return;
5050
}
5151
}
52-
$known_user = new QueueitKnownUser;
52+
$known_user = new QueueitKnownUser();
5353
// Ignore processing if the config is invalid.
5454
if (!$known_user->validateConfig()) {
5555
return;
@@ -67,6 +67,7 @@ function queueit_init() {
6767
case 'code':
6868
$result = $known_user->validateRequestByIntegrationConfig();
6969
break;
70+
7071
case 'integration':
7172
$result = $known_user->resolveRequestByLocalEventConfig();
7273
break;
@@ -106,16 +107,16 @@ function queueit_menu() {
106107
return $items;
107108
}
108109

109-
/**
110+
/**
110111
* Implements hook_library().
111112
*/
112113
function queueit_library() {
113114
// Register libraries available in the external directory.
114-
$path = libraries_get_path('composer') . '/queueit/knownuserv3';
115115
$libraries['queueit/KnownUser'] = array(
116116
'title' => 'KnownUser.V3.PHP',
117+
'website' => 'https://github.com/queueit/KnownUser.V3.PHP',
117118
'version' => '3',
118-
);
119+
);
119120
return $libraries;
120121
}
121122

src/classes/QueueitBase.php

+19-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
class QueueitBase {
99

10-
// Protected variables.
10+
/* Protected variables */
1111
protected $apiKey; // API Key.
1212
protected $customerID; // Customer ID.
1313
protected $secretKey; // Secret key.
@@ -20,15 +20,14 @@ class QueueitBase {
2020
protected $layoutName; // Name of the queue ticket layout.
2121
protected $cultureLayout; // Culture of the queue ticket layout.
2222
protected $isDebug; // Debug mode.
23-
24-
// Constants.
23+
/* Constants */
2524
const QI_API_DOMAIN = 'queue-it.net';
2625
const QI_CONFIG_URI = '/status/integrationconfig';
2726

2827
/**
2928
* Class constructor.
3029
*/
31-
function __construct($customer_id = '', $secret_key = '', $api_key = '') {
30+
public function __construct($customer_id = '', $secret_key = '', $api_key = '') {
3231
$this->apiKey = $api_key
3332
?: variable_get('queueit_api_key');
3433
$this->customerID = $customer_id
@@ -48,9 +47,9 @@ function __construct($customer_id = '', $secret_key = '', $api_key = '') {
4847
* Validate config.
4948
*
5049
* @return bools
51-
* Returns TRUE if config is valid (e.g. credentials aren't empty).
50+
* Returns TRUE if config is valid (e.g. credentials aren't empty).
5251
*/
53-
function validateConfig() {
52+
public function validateConfig() {
5453
return $this->getCustomerId() && $this->secretKey;
5554
}
5655

@@ -59,14 +58,14 @@ function validateConfig() {
5958
/**
6059
* Sets event config.
6160
*/
62-
function setEventConfig() {
63-
$eventConfig = new QueueEventConfig;
61+
public function setEventConfig() {
62+
$eventConfig = new QueueEventConfig();
6463

6564
// ID of the queue to use.
6665
$eventConfig->eventId = "";
6766

6867
// Domain name of the queue.
69-
// Usually in the format [CustomerId].queue-it.net
68+
// Usually in the format [CustomerId].queue-it.net.
7069
$eventConfig->queueDomain = $this->queueDomain;
7170

7271
// Domain name where the Queue-it session cookie should be saved.
@@ -75,14 +74,14 @@ function setEventConfig() {
7574

7675
// Validity of the Queue-it session cookie.
7776
// Optional. Default is 10 minutes.
78-
$eventConfig->cookieValidityMinute = $this->cookieValidity;
77+
$eventConfig->cookieValidityMinute = $this->cookieValidity;
7978

8079
// Should the Queue-it session cookie validity time be extended each time the validation runs?
8180
// Optional. Default is true.
8281
$eventConfig->extendCookieValidity = $this->extCookieTime;
8382

8483
// Name of the queue ticket layout - e.g. "Default layout by Queue-it".
85-
// Optional. Default is to take what is specified on the Event
84+
// Optional. Default is to take what is specified on the Event.
8685
$eventConfig->layoutName = $this->layoutName;
8786

8887
// Culture of the queue ticket layout in the format specified at:
@@ -99,9 +98,9 @@ function setEventConfig() {
9998
* Retrieve the integration config.
10099
*
101100
* @return string
102-
* Returns plain JSON content.
101+
* Returns plain JSON content.
103102
*/
104-
function getIntegrationConfig() {
103+
public function getIntegrationConfig() {
105104
// Ignore fetching on invalid configuration.
106105
if (!$this->validateConfig()) {
107106
return NULL;
@@ -116,7 +115,7 @@ function getIntegrationConfig() {
116115
/**
117116
* Get the integration config URL.
118117
*/
119-
function getIntegrationConfigPath() {
118+
public function getIntegrationConfigPath() {
120119
return sprintf("http://%s.%s%s/%s",
121120
$this->getCustomerId(),
122121
self::QI_API_DOMAIN,
@@ -128,42 +127,42 @@ function getIntegrationConfigPath() {
128127
/**
129128
* Get API Key.
130129
*/
131-
function getAPIKey() {
130+
public function getAPIKey() {
132131
return $this->apiKey;
133132
}
134133

135134
/**
136135
* Get customer ID.
137136
*/
138-
function getCustomerId() {
137+
public function getCustomerId() {
139138
return $this->customerID;
140139
}
141140

142141
/**
143142
* Get secret key.
144143
*/
145-
function getSecretKey() {
144+
public function getSecretKey() {
146145
return $this->secretKey;
147146
}
148147

149148
/**
150149
* Get a queue token.
151150
*/
152-
function getQueueToken() {
151+
public function getQueueToken() {
153152
return filter_input(INPUT_GET, 'queueittoken');
154153
}
155154

156155
/**
157156
* Helper method to get the current URL.
158157
*/
159-
function getFullRequestUri() {
158+
public function getFullRequestUri() {
160159
return file_create_url(current_path());
161160
}
162161

163162
/**
164163
* Gets event config.
165164
*/
166-
function getEventConfig() {
165+
public function getEventConfig() {
167166
return $this->eventConfig;
168167
}
169168

src/classes/QueueitKnownUser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class QueueitKnownUser extends QueueitBase {
1010
/**
1111
* Validate that the user has been through the queue.
1212
*/
13-
function validateRequestByIntegrationConfig() {
13+
public function validateRequestByIntegrationConfig() {
1414
/*
1515
* This call will validate the timestamp and hash
1616
* and if valid create a cookie with a TTL like:
@@ -31,7 +31,7 @@ function validateRequestByIntegrationConfig() {
3131
/**
3232
* Verify if the user has been through the queue.
3333
*/
34-
function resolveRequestByLocalEventConfig() {
34+
public function resolveRequestByLocalEventConfig() {
3535
$this->setEventConfig();
3636
return KnownUser::resolveRequestByLocalEventConfig(
3737
$this->getFullRequestUri(),

tests/queueit.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class QueueitTestCase extends DrupalWebTestCase {
2424
/**
2525
* Implements setUp().
2626
*/
27-
function setUp() {
27+
public function setUp() {
2828
// Call the parent with an array of modules to enable for the test.
2929
parent::setUp(array('queueit'));
3030

@@ -34,7 +34,7 @@ class QueueitTestCase extends DrupalWebTestCase {
3434
/**
3535
* Test the module's functionality.
3636
*/
37-
function testTodoChangeThisName() {
37+
public function testTodoChangeThisName() {
3838
// TODO: write test!
3939
}
4040

0 commit comments

Comments
 (0)