Skip to content

Commit 7b5081a

Browse files
committed
PSR-2 fixups
1 parent 67270ac commit 7b5081a

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

lib/Auth/Process/Fticks.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Fticks extends \SimpleSAML\Auth\ProcessingFilter
1616
{
1717
/** @var string F-ticks version number */
18-
private static $_fticksVersion = '1.0';
18+
private static $fticksVersion = '1.0';
1919

2020
/** @var string F-ticks federation identifier */
2121
private $federation;
@@ -48,7 +48,7 @@ class Fticks extends \SimpleSAML\Auth\ProcessingFilter
4848
* @param string $msg message to log
4949
* @return void
5050
*/
51-
private function _log($msg)
51+
private function log($msg)
5252
{
5353
switch ($this->logdest) {
5454
/* local syslog call, avoiding SimpleSAMLphp's wrapping */
@@ -65,7 +65,11 @@ private function _log($msg)
6565
assert('array_key_exists("processname", $this->logconfig)');
6666
assert('array_key_exists("facility", $this->logconfig)');
6767
/* assemble a syslog message per RFC 5424 */
68-
$rfc5424_message = sprintf('<%d>', ((($this->logconfig['facility'] & 0x03f8) >> 3) * 8) + (array_key_exists('priority', $this->logconfig) ? $this->logconfig['priority'] : LOG_INFO)); // pri
68+
$rfc5424_message = sprintf(
69+
'<%d>',
70+
((($this->logconfig['facility'] & 0x03f8) >> 3) * 8) +
71+
(array_key_exists('priority', $this->logconfig) ? $this->logconfig['priority'] : LOG_INFO)
72+
); // pri
6973
$rfc5424_message .= '1 '; // ver
7074
$rfc5424_message .= gmdate('Y-m-d\TH:i:s.v\Z '); // timestamp
7175
$rfc5424_message .= gethostname() . ' '; // hostname
@@ -110,7 +114,8 @@ private function _log($msg)
110114
* @return string|false $hash
111115
* @throws \SimpleSAML\Error\Exception
112116
*/
113-
private function _generatePNhash(&$state) {
117+
private function generatePNhash(&$state)
118+
{
114119
/* get a user id */
115120
if ($this->userId !== false) {
116121
assert('array_key_exists("Attributes", $state)');
@@ -150,7 +155,7 @@ private function _generatePNhash(&$state) {
150155
* @param string $value
151156
* @return string $value
152157
*/
153-
private function _escapeFticks($value)
158+
private function escapeFticks($value)
154159
{
155160
return preg_replace('/[^A-Za-z0-9_\-:.,;\/]+/', '', $value);
156161
}
@@ -300,7 +305,7 @@ public function process(&$state)
300305
}
301306

302307
/* ePTID */
303-
$pn = $this->_generatePNhash($state);
308+
$pn = $this->generatePNhash($state);
304309
if ($pn !== false) {
305310
$fticks['PN'] = $pn;
306311
}
@@ -332,24 +337,24 @@ public function process(&$state)
332337
* @param string $k
333338
* @return bool
334339
*/
335-
function($k) {
340+
function ($k) {
336341
return !in_array($k, $this->exclude);
337342
},
338343
ARRAY_FILTER_USE_KEY
339344
);
340345
}
341346

342347
/* assemble an F-ticks log string */
343-
$this->_log(
344-
'F-TICKS/'.$this->federation.'/'.self::$_fticksVersion.'#' .
348+
$this->log(
349+
'F-TICKS/'.$this->federation.'/'.self::$fticksVersion.'#' .
345350
implode('#', array_map(
346351
/**
347352
* @param string $k
348353
* @param string $v
349354
* @return string
350355
*/
351-
function($k, $v) {
352-
return $k.'='.$this->_escapeFticks($v);
356+
function ($k, $v) {
357+
return $k.'='.$this->escapeFticks($v);
353358
},
354359
array_keys($fticks),
355360
$fticks

tests/lib/Auth/Process/FticksTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase', true);
1414
class FticksTest extends \PHPUnit_Framework_TestCase
1515
{
1616
/** @var array minimal request */
17-
private static $_minrequest = [
17+
private static $minRequest = [
1818
'Source' => [
1919
'entityid' => 'https://localhost/sp',
2020
],
@@ -24,7 +24,7 @@ class FticksTest extends \PHPUnit_Framework_TestCase
2424
];
2525

2626
/** @var array SP request */
27-
private static $_sprequest =[
27+
private static $spRequest =[
2828
'saml:sp:IdP' => 'https://localhost/saml:sp:IdP',
2929
'saml:sp:SessionIndex' => 'saml:sp:SessionIndex',
3030
'saml:sp:State' => [
@@ -34,7 +34,7 @@ class FticksTest extends \PHPUnit_Framework_TestCase
3434
];
3535

3636
/** @var array IdP request */
37-
private static $_idprequest = [
37+
private static $idpRequest = [
3838
'SimpleSAML_Auth_State.id' => 'SimpleSAML_Auth_State.id',
3939
'SimpleSAML_Auth_State.stage' => 'sspmod_core_Auth_UserPassBase.state',
4040
'UserID' => 'user1@example.org',
@@ -75,8 +75,8 @@ protected function setUp()
7575
public function testMinimal()
7676
{
7777
$config = ['federation' => 'ACME', 'logdest' => 'stdout'];
78-
$request = self::$_minrequest;
79-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL','/').'[^#]+#TS=\d+#$/');
78+
$request = self::$minRequest;
79+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL', '/').'[^#]+#TS=\d+#$/');
8080
$result = self::processFilter($config, $request);
8181
}
8282

@@ -86,8 +86,8 @@ public function testMinimal()
8686
public function testAsServiceProvider()
8787
{
8888
$config = ['federation' => 'ACME', 'logdest' => 'stdout',];
89-
$request = array_merge(self::$_minrequest, self::$_sprequest);
90-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL','/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified#TS=1000#','/').'$/');
89+
$request = array_merge(self::$minRequest, self::$spRequest);
90+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL', '/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified#TS=1000#', '/').'$/');
9191
$result = self::processFilter($config, $request);
9292
}
9393

@@ -97,12 +97,12 @@ public function testAsServiceProvider()
9797
public function testSPwithUserId()
9898
{
9999
$config = ['federation' => 'ACME', 'logdest' => 'stdout', 'userId' => 'eduPersonPrincipalName'];
100-
$request = array_merge(self::$_minrequest, self::$_sprequest, [
100+
$request = array_merge(self::$minRequest, self::$spRequest, [
101101
'Attributes' => [
102102
'eduPersonPrincipalName' => 'user2@example.net',
103103
],
104104
]);
105-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL','/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified#PN=e5d066a96d5809a21264e153013c3c793e6574cb77afdfa248ad2cefab9b0451#TS=1000#','/').'$/');
105+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/saml:sp:IdP#RP=https://localhost/idp#CSI=CL', '/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified#PN=e5d066a96d5809a21264e153013c3c793e6574cb77afdfa248ad2cefab9b0451#TS=1000#', '/').'$/');
106106
$result = self::processFilter($config, $request);
107107
}
108108

@@ -112,8 +112,8 @@ public function testSPwithUserId()
112112
public function testAsIdentityProvider()
113113
{
114114
$config = ['federation' => 'ACME', 'logdest' => 'stdout',];
115-
$request = array_merge(self::$_minrequest, self::$_idprequest);
116-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL','/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:Password#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc#TS=','/').'\d+#$/');
115+
$request = array_merge(self::$minRequest, self::$idpRequest);
116+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL', '/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:Password#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc#TS=', '/').'\d+#$/');
117117
$result = self::processFilter($config, $request);
118118
}
119119

@@ -131,13 +131,13 @@ public function testExample()
131131
'exclude' => ['PN'],
132132
'logdest' => 'stdout',
133133
];
134-
$request = array_merge(self::$_minrequest, self::$_idprequest, [
134+
$request = array_merge(self::$minRequest, self::$idpRequest, [
135135
'Attributes' => [
136136
'eduPersonPrincipalName' => 'user3@example.com',
137137
'schacHomeOrganization' => 'example.com',
138138
],
139139
]);
140-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL','/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:Password#TS=','/').'\d+#REALM=example.com#$/');
140+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL', '/').'[^#]+'.preg_quote('#AM=urn:oasis:names:tc:SAML:2.0:ac:classes:Password#TS=', '/').'\d+#REALM=example.com#$/');
141141
$result = self::processFilter($config, $request);
142142
}
143143

@@ -147,8 +147,8 @@ public function testExample()
147147
public function testFilteringArray()
148148
{
149149
$config = ['federation' => 'ACME', 'logdest' => 'stdout', 'exclude' => ['PN', 'AM']];
150-
$request = array_merge(self::$_minrequest, self::$_idprequest);
151-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL','/').'[^#]+#TS=\d+#$/');
150+
$request = array_merge(self::$minRequest, self::$idpRequest);
151+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL', '/').'[^#]+#TS=\d+#$/');
152152
$result = self::processFilter($config, $request);
153153
}
154154

@@ -158,8 +158,8 @@ public function testFilteringArray()
158158
public function testFilteringString()
159159
{
160160
$config = ['federation' => 'ACME', 'logdest' => 'stdout', 'exclude' => 'AM'];
161-
$request = array_merge(self::$_minrequest, self::$_idprequest);
162-
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL','/').'[^#]+'.preg_quote('#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc#TS=','/').'\d+#$/');
161+
$request = array_merge(self::$minRequest, self::$idpRequest);
162+
$this->expectOutputRegex('/^'.preg_quote('F-TICKS/ACME/1.0#RESULT=OK#AP=https://localhost/sp#RP=https://localhost/idp#CSI=CL', '/').'[^#]+'.preg_quote('#PN=d844a9a0666bb3990e88f72b8f5c20accbcfa46f7b8a7ab38593bfbbab6e9cbc#TS=', '/').'\d+#$/');
163163
$result = self::processFilter($config, $request);
164164
}
165165
}

0 commit comments

Comments
 (0)