Skip to content

Commit fa183b6

Browse files
committed
PSR-12
1 parent 48a65d8 commit fa183b6

25 files changed

+166
-140
lines changed

config-templates/module_casserver.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<?php
2-
/*
2+
3+
/*
34
* Configuration for the module casserver.
4-
*
5+
*
56
*/
67

78
$config = [
89
'authsource' => 'casserver',
910

1011
/* Scopes are named sets of entityIDs to be used for scoping. If a named scope is provided during login, then the
1112
IdPs listed by the disco service will be restricted to entityIDs in the specified set. */
12-
'scopes' =>[
13+
'scopes' => [
1314
'mobile' => [
1415
'https://idp1.domain:1234/saml2/idp/metadata.php',
1516
'https://idp2.domain:5678/saml2/idp/metadata.php'
1617
],
1718
'desktop' => [
18-
'https://idp3.domain:1234/saml2/idp/metadata.php',
19+
'https://idp3.domain:1234/saml2/idp/metadata.php',
1920
'https://idp4.domain:5678/saml2/idp/metadata.php'
2021
]
2122
],
@@ -63,8 +64,11 @@
6364
'attributes' => true, // enable transfer of attributes, defaults to true
6465
'attributes_to_transfer' => ['eduPersonPrincipalName'], // set of attributes to transfer, defaults to all
6566

66-
/* Optional authproc filter. Only authproc filters that solely rely on attributes (such as core:AttributeMap and AttributeAlter)
67-
may be used. If your authsource supports authproc filters you are better off doing it there. */
67+
/**
68+
* Optional authproc filter. Only authproc filters that solely rely on attributes
69+
* (such as core:AttributeMap and AttributeAlter)
70+
* may be used. If your authsource supports authproc filters you are better off doing it there.
71+
*/
6872
'authproc' => [
6973
[
7074
'class' => 'core:AttributeMap',
@@ -75,18 +79,26 @@
7579
],
7680

7781
'base64attributes' => true, // base64 encode transferred attributes, defaults to false
78-
'base64_attributes_indicator_attribute' => 'base64Attributes', /*add an attribute with the value of the base64attributes
79-
configuration parameter to the set of transferred attributes.
80-
Defaults to not adding an indicator attribute. */
82+
83+
/**
84+
* add an attribute with the value of the base64attributes
85+
* configuration parameter to the set of transferred attributes.
86+
* Defaults to not adding an indicator attribute.
87+
*/
88+
'base64_attributes_indicator_attribute' => 'base64Attributes',
8189

8290
'enable_logout' => true, // enable CAS logout, defaults to false
8391
'skip_logout_page' => true, /*perform a redirect instead of showing a logout page with a link to the location
8492
given in the url parameter, defaults to false. Skipping the logout page makes the
8593
url query parameter to CAS logout mandatory for obvious reasons.*/
8694

87-
'service_ticket_expire_time' => 5, //how many seconds service tickets are valid for, defaults to 5
88-
'proxy_granting_ticket_expire_time' => 600, //how many seconds proxy granting tickets are valid for at most, defaults to 3600
89-
'proxy_ticket_expire_time' => 5, //how many seconds proxy tickets are valid for, defaults to 5
95+
// how many seconds service tickets are valid for, defaults to 5
96+
'service_ticket_expire_time' => 5,
97+
// how many seconds proxy granting tickets are valid for at most, defaults to 3600
98+
'proxy_granting_ticket_expire_time' => 600,
99+
//how many seconds proxy tickets are valid for, defaults to 5
100+
'proxy_ticket_expire_time' => 5,
90101

91-
'debugMode' => true, // If query param debugMode=true is sent to the login endpoint then print cas ticket xml. Default false
102+
// If query param debugMode=true is sent to the login endpoint then print cas ticket xml. Default false
103+
'debugMode' => true,
92104
];

lib/Cas/CasException.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
*/
99
class CasException extends \Exception
1010
{
11-
// For list of cas codes see https://apereo.github.io/cas/5.2.x/protocol/CAS-Protocol-Specification.html#253-error-codes
11+
// For list of cas codes see:
12+
// https://apereo.github.io/cas/5.2.x/protocol/CAS-Protocol-Specification.html#253-error-codes
1213
const INVALID_TICKET = 'INVALID_TICKET';
1314
const INVALID_SERVICE = 'INVALID_SERVICE';
1415

lib/Cas/Protocol/Cas10.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(Configuration $config)
4141
*/
4242
public function getValidateSuccessResponse($username)
4343
{
44-
return "yes\n".$username."\n";
44+
return "yes\n" . $username . "\n";
4545
}
4646

4747

lib/Cas/Protocol/Cas20.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function getProxyFailureResponse($errorCode, $explanation)
244244
private function workAroundForBuggyJasigXmlParser($xmlString)
245245
{
246246
// when will people stop hand coding xml handling....?
247-
return str_replace('><', '>'.PHP_EOL.'<', str_replace(PHP_EOL, '', $xmlString));
247+
return str_replace('><', '>' . PHP_EOL . '<', str_replace(PHP_EOL, '', $xmlString));
248248
}
249249

250250

@@ -259,7 +259,7 @@ private function generateCas20Attribute($xmlDocument, $attributeName, $attribute
259259
$attributeValueNode = $xmlDocument->createTextNode($this->base64EncodeAttributes ?
260260
base64_encode($attributeValue) : $attributeValue);
261261

262-
$attributeElement = $xmlDocument->createElement('cas:'.$attributeName);
262+
$attributeElement = $xmlDocument->createElement('cas:' . $attributeName);
263263

264264
$attributeElement->appendChild($attributeValueNode);
265265

lib/Cas/ServiceValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function checkServiceURL($service)
5555
$isValidService = true;
5656
break;
5757
} elseif ($result === false) {
58-
Logger::warning("Invalid CAS legal service url '$legalUrl'. Error ".preg_last_error());
58+
Logger::warning("Invalid CAS legal service url '$legalUrl'. Error " . preg_last_error());
5959
}
6060
} elseif (strpos($service, $legalUrl) === 0) {
6161
$isValidService = true;

lib/Cas/Ticket/FileSystemTicketStore.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public function __construct(Configuration $config)
4848
$path = $config->resolvePath($storeConfig['directory']);
4949

5050
if (is_null($path) || !is_dir($path)) {
51-
throw new Exception('Directory for CAS Server ticket storage ['.strval($path).'] does not exists.');
51+
throw new Exception('Directory for CAS Server ticket storage [' . strval($path) . '] does not exists.');
5252
}
5353

5454
if (!is_writable($path)) {
55-
throw new Exception('Directory for CAS Server ticket storage ['.$path.'] is not writable.');
55+
throw new Exception('Directory for CAS Server ticket storage [' . $path . '] is not writable.');
5656
}
5757

5858
$this->pathToTicketDirectory = preg_replace('/\/$/', '', $path);
@@ -65,7 +65,7 @@ public function __construct(Configuration $config)
6565
*/
6666
public function getTicket($ticketId)
6767
{
68-
$filename = $this->pathToTicketDirectory.'/'.$ticketId;
68+
$filename = $this->pathToTicketDirectory . '/' . $ticketId;
6969

7070
if (file_exists($filename)) {
7171
$content = file_get_contents($filename);
@@ -83,7 +83,7 @@ public function getTicket($ticketId)
8383
*/
8484
public function addTicket(array $ticket)
8585
{
86-
$filename = $this->pathToTicketDirectory.'/'.$ticket['id'];
86+
$filename = $this->pathToTicketDirectory . '/' . $ticket['id'];
8787
file_put_contents($filename, serialize($ticket));
8888
}
8989

@@ -94,7 +94,7 @@ public function addTicket(array $ticket)
9494
*/
9595
public function deleteTicket($ticketId)
9696
{
97-
$filename = $this->pathToTicketDirectory.'/'.$ticketId;
97+
$filename = $this->pathToTicketDirectory . '/' . $ticketId;
9898

9999
if (file_exists($filename)) {
100100
unlink($filename);

lib/Cas/Ticket/MemCacheTicketStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ public function deleteTicket($ticketId)
8989
*/
9090
private function scopeTicketId($ticketId)
9191
{
92-
return $this->prefix.'.'.$ticketId;
92+
return $this->prefix . '.' . $ticketId;
9393
}
9494
}

lib/Cas/Ticket/SQLTicketStore.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function deleteTicket($ticketId)
117117
*/
118118
private function scopeTicketId($ticketId)
119119
{
120-
return $this->prefix.'.'.$ticketId;
120+
return $this->prefix . '.' . $ticketId;
121121
}
122122

123123

@@ -130,9 +130,9 @@ private function initTableVersionTable()
130130
$this->tableVersions = [];
131131

132132
try {
133-
$fetchTableVersion = $this->pdo->query('SELECT _name, _version FROM '.$this->prefix.'_tableVersion');
133+
$fetchTableVersion = $this->pdo->query('SELECT _name, _version FROM ' . $this->prefix . '_tableVersion');
134134
} catch (PDOException $e) {
135-
$this->pdo->exec('CREATE TABLE '.$this->prefix.
135+
$this->pdo->exec('CREATE TABLE ' . $this->prefix .
136136
'_tableVersion (_name VARCHAR(30) NOT NULL UNIQUE, _version INTEGER NOT NULL)');
137137
return;
138138
}
@@ -153,11 +153,11 @@ private function initKVTable()
153153
return;
154154
}
155155

156-
$query = 'CREATE TABLE '.$this->prefix.
156+
$query = 'CREATE TABLE ' . $this->prefix .
157157
'_kvstore (_key VARCHAR(50) NOT NULL, _value TEXT NOT NULL, _expire TIMESTAMP, PRIMARY KEY (_key))';
158158
$this->pdo->exec($query);
159159

160-
$query = 'CREATE INDEX '.$this->prefix.'_kvstore_expire ON '.$this->prefix.'_kvstore (_expire)';
160+
$query = 'CREATE INDEX ' . $this->prefix . '_kvstore_expire ON ' . $this->prefix . '_kvstore (_expire)';
161161
$this->pdo->exec($query);
162162

163163
$this->setTableVersion('kvstore', 1);
@@ -191,7 +191,7 @@ private function setTableVersion($name, $version)
191191
Assert::integer($version);
192192

193193
$this->insertOrUpdate(
194-
$this->prefix.'_tableVersion',
194+
$this->prefix . '_tableVersion',
195195
['_name'],
196196
[
197197
'_name' => $name,
@@ -212,24 +212,24 @@ private function insertOrUpdate($table, array $keys, array $data)
212212
{
213213
Assert::string($table);
214214

215-
$colNames = '('.implode(', ', array_keys($data)).')';
216-
$values = 'VALUES(:'.implode(', :', array_keys($data)).')';
215+
$colNames = '(' . implode(', ', array_keys($data)) . ')';
216+
$values = 'VALUES(:' . implode(', :', array_keys($data)) . ')';
217217

218218
switch ($this->driver) {
219219
case 'mysql':
220-
$query = 'REPLACE INTO '.$table.' '.$colNames.' '.$values;
220+
$query = 'REPLACE INTO ' . $table . ' ' . $colNames . ' ' . $values;
221221
$query = $this->pdo->prepare($query);
222222
$query->execute($data);
223223
return;
224224
case 'sqlite':
225-
$query = 'INSERT OR REPLACE INTO '.$table.' '.$colNames.' '.$values;
225+
$query = 'INSERT OR REPLACE INTO ' . $table . ' ' . $colNames . ' ' . $values;
226226
$query = $this->pdo->prepare($query);
227227
$query->execute($data);
228228
return;
229229
default:
230230
/* Default implementation. Try INSERT, and UPDATE if that fails. */
231231

232-
$insertQuery = 'INSERT INTO '.$table.' '.$colNames.' '.$values;
232+
$insertQuery = 'INSERT INTO ' . $table . ' ' . $colNames . ' ' . $values;
233233
/** @var \PDOStatement|false $insertQuery */
234234
$insertQuery = $this->pdo->prepare($insertQuery);
235235

@@ -260,7 +260,7 @@ private function insertOrUpdateFallback($table, array $keys, array $data, PDOSta
260260
case '23505': /* PostgreSQL */
261261
break;
262262
default:
263-
Logger::error('casserver: Error while saving data: '.$e->getMessage());
263+
Logger::error('casserver: Error while saving data: ' . $e->getMessage());
264264
throw $e;
265265
}
266266
}
@@ -269,7 +269,7 @@ private function insertOrUpdateFallback($table, array $keys, array $data, PDOSta
269269
$condCols = [];
270270

271271
foreach ($data as $col => $value) {
272-
$tmp = $col.' = :'.$col;
272+
$tmp = $col . ' = :' . $col;
273273

274274
if (in_array($col, $keys, true)) {
275275
$condCols[] = $tmp;
@@ -278,7 +278,7 @@ private function insertOrUpdateFallback($table, array $keys, array $data, PDOSta
278278
}
279279
}
280280

281-
$updateQuery = 'UPDATE '.$table.' SET '.implode(',', $updateCols).' WHERE '.implode(' AND ', $condCols);
281+
$updateQuery = 'UPDATE ' . $table . ' SET ' . implode(',', $updateCols) . ' WHERE ' . implode(' AND ', $condCols);
282282
$updateQuery = $this->pdo->prepare($updateQuery);
283283
$updateQuery->execute($data);
284284
}
@@ -289,7 +289,7 @@ private function insertOrUpdateFallback($table, array $keys, array $data, PDOSta
289289
*/
290290
private function cleanKVStore()
291291
{
292-
$query = 'DELETE FROM '.$this->prefix.'_kvstore WHERE _expire < :now';
292+
$query = 'DELETE FROM ' . $this->prefix . '_kvstore WHERE _expire < :now';
293293
$params = ['now' => gmdate('Y-m-d H:i:s')];
294294

295295
$query = $this->pdo->prepare($query);
@@ -309,7 +309,7 @@ private function get($key)
309309
$key = sha1($key);
310310
}
311311

312-
$query = 'SELECT _value FROM '.$this->prefix.
312+
$query = 'SELECT _value FROM ' . $this->prefix .
313313
'_kvstore WHERE _key = :key AND (_expire IS NULL OR _expire > :now)';
314314
$params = ['key' => $key, 'now' => gmdate('Y-m-d H:i:s')];
315315

@@ -369,7 +369,7 @@ private function set($key, $value, $expire = null)
369369
'_expire' => $expire,
370370
];
371371

372-
$this->insertOrUpdate($this->prefix.'_kvstore', ['_key'], $data);
372+
$this->insertOrUpdate($this->prefix . '_kvstore', ['_key'], $data);
373373
}
374374

375375

@@ -390,7 +390,7 @@ private function delete($key)
390390

391391
];
392392

393-
$query = 'DELETE FROM '.$this->prefix.'_kvstore WHERE _key=:_key';
393+
$query = 'DELETE FROM ' . $this->prefix . '_kvstore WHERE _key=:_key';
394394
$query = $this->pdo->prepare($query);
395395
$query->execute($data);
396396
}

lib/Cas/TicketValidator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,26 @@ public function validateAndDeleteTicket($ticket, $service)
6363

6464
$serviceTicket = $this->ticketStore->getTicket($ticket);
6565
if ($serviceTicket == null) {
66-
$message = 'Ticket '.var_export($ticket, true).' not recognized';
67-
Logger::debug('casserver:'.$message);
66+
$message = 'Ticket ' . var_export($ticket, true) . ' not recognized';
67+
Logger::debug('casserver:' . $message);
6868
throw new CasException(CasException::INVALID_TICKET, $message);
6969
}
7070

7171
// TODO: do proxy vs non proxy ticket check
7272
$this->ticketStore->deleteTicket($ticket);
7373

7474
if ($this->ticketFactory->isExpired($serviceTicket)) {
75-
$message = 'Ticket '.var_export($ticket, true).' has expired';
76-
Logger::debug('casserver:'.$message);
75+
$message = 'Ticket ' . var_export($ticket, true) . ' has expired';
76+
Logger::debug('casserver:' . $message);
7777
throw new CasException(CasException::INVALID_TICKET, $message);
7878
}
7979

8080
if (self::sanitize($serviceTicket['service']) !== self::sanitize($service)) {
81-
$message = 'Mismatching service parameters: expected '.
82-
var_export($serviceTicket['service'], true).
83-
' but was: '.var_export($service, true);
81+
$message = 'Mismatching service parameters: expected ' .
82+
var_export($serviceTicket['service'], true) .
83+
' but was: ' . var_export($service, true);
8484

85-
Logger::debug('casserver:'.$message);
85+
Logger::debug('casserver:' . $message);
8686
throw new CasException(CasException::INVALID_SERVICE, $message);
8787
}
8888

templates/loggedIn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
$this->includeAtTemplateBase('includes/footer.php');
3737

3838
if (isset($this->data['autofocus'])) {
39-
echo '<script type="text/javascript">window.onload = function() {document.getElementById(\''.$this->data['autofocus'].'\').focus();}</script>';
39+
echo '<script type="text/javascript">window.onload = function() {document.getElementById(\'' . $this->data['autofocus'] . '\').focus();}</script>';
4040
}

0 commit comments

Comments
 (0)