Skip to content

Commit 16c9f1f

Browse files
committed
Fix several coding style issues; make phpcs/psalter mandatory to pass
1 parent 9b29986 commit 16c9f1f

5 files changed

Lines changed: 121 additions & 50 deletions

File tree

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ jobs:
194194
uses: codecov/codecov-action@v1
195195

196196
- name: PHP Code Sniffer
197-
continue-on-error: true
197+
continue-on-error: false
198198
run: php vendor/bin/phpcs
199199

200200
- name: Psalm
201201
continue-on-error: true
202202
run: php vendor/bin/psalm --show-info=true
203203

204204
- name: Psalter
205-
continue-on-error: true
205+
continue-on-error: false
206206
run: php vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run

lib/SimpleSAML/Locale/Localization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function addAttributeDomains(): void
269269
$this->addDomain($this->localeDir, 'attributes');
270270

271271
list($theme,) = explode(':', $this->configuration->getString('theme.use', 'default'));
272-
if($theme !== 'default') {
272+
if ($theme !== 'default') {
273273
$this->addModuleDomain($theme, null, 'attributes');
274274
}
275275
}

phpcs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
<file>src</file>
1515
<file>tests</file>
1616
<file>www</file>
17+
1718
<exclude-pattern>modules/adfs/*</exclude-pattern>
19+
<exclude-pattern>www/assets/css/stylesheet.css</exclude-pattern>
20+
<exclude-pattern>www/assets/js/bundle.js</exclude-pattern>
21+
<exclude-pattern>www/assets/js/logout.js</exclude-pattern>
22+
<exclude-pattern>www/assets/js/stylesheet.js</exclude-pattern>
1823

1924
<!-- This is the rule we inherit from. If you want to exlude some specific rules, see the docs on how to do that -->
2025
<rule ref="PSR12"/>

tests/lib/SimpleSAML/XHTML/TemplateTranslationTest.php

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Symfony\Bridge\Twig\Extension\TranslationExtension;
1414
use Symfony\Component\Finder\Finder;
1515
use Symfony\Component\Finder\SplFileInfo;
16+
use Twig\Environment;
17+
use Twig\Extra\Intl\IntlExtension;
18+
use Twig\Loader\FilesystemLoader;
1619
use Twig\TwigFilter;
1720
use Twig\TwigFunction;
1821

@@ -21,7 +24,8 @@
2124
*/
2225
class TemplateTranslationTest extends TestCase
2326
{
24-
public function testCoreCardinalityErrorTemplate(): void {
27+
public function testCoreCardinalityErrorTemplate(): void
28+
{
2529
$c = Configuration::loadFromArray([], '', 'simplesaml');
2630
$t = new Template($c, 'core:cardinality_error.twig');
2731

@@ -30,18 +34,18 @@ public function testCoreCardinalityErrorTemplate(): void {
3034
'test 2' => [1, 2],
3135
];
3236

33-
$getContent = function() {
34-
/** @var Template $this */
37+
$getContent = function () {
38+
/** @var \SimpleSAML\XHTML\Template $this */
3539
return $this->getContents();
3640
};
3741
$html = $getContent->call($t);
3842

3943
$this->assertStringContainsString('got 0 values, want 1', $html);
4044
$this->assertStringContainsString('got 1 values, want 2', $html);
41-
4245
}
4346

44-
public function testCoreLoginUserPassTemplate(): void {
47+
public function testCoreLoginUserPassTemplate(): void
48+
{
4549
$c = Configuration::loadFromArray([], '', 'simplesaml');
4650
$t = new Template($c, 'core:loginuserpass.twig');
4751

@@ -53,16 +57,17 @@ public function testCoreLoginUserPassTemplate(): void {
5357
$t->data['rememberMeEnabled'] = false;
5458
$t->data['stateparams'] = [];
5559

56-
$getContent = function() {
57-
/** @var Template $this */
60+
$getContent = function () {
61+
/** @var \SimpleSAML\XHTML\Template $this */
5862
return $this->getContents();
5963
};
6064
$html = $getContent->call($t);
6165

6266
$this->assertStringContainsString('value="h.c oersted"', $html);
6367
}
6468

65-
public function testCoreLogoutIframeTemplate(): void {
69+
public function testCoreLogoutIframeTemplate(): void
70+
{
6671
$c = Configuration::loadFromArray([], '', 'simplesaml');
6772
$t = new Template($c, 'core:logout-iframe.twig');
6873

@@ -86,8 +91,8 @@ public function testCoreLogoutIframeTemplate(): void {
8691
],
8792
];
8893

89-
$getContent = function() {
90-
/** @var Template $this */
94+
$getContent = function () {
95+
/** @var \SimpleSAML\XHTML\Template $this */
9196
return $this->getContents();
9297
};
9398
$html = $getContent->call($t);
@@ -96,7 +101,8 @@ public function testCoreLogoutIframeTemplate(): void {
96101
$this->assertStringContainsString('ze missing service', $html);
97102
}
98103

99-
public function testAuthStatusTemplate(): void {
104+
public function testAuthStatusTemplate(): void
105+
{
100106
$c = Configuration::loadFromArray([], '', 'simplesaml');
101107
$t = new Template($c, 'auth_status.twig');
102108

@@ -106,44 +112,78 @@ public function testAuthStatusTemplate(): void {
106112
$t->data['trackid'] = '';
107113
$t->data['authData'] = false;
108114

109-
$getContent = function() {
110-
/** @var Template $this */
115+
$getContent = function () {
116+
/** @var \SimpleSAML\XHTML\Template $this */
111117
return $this->getContents();
112118
};
113119
$html = $getContent->call($t);
114120

115-
$this->assertStringContainsString('Your session is valid for ' . $t->data['remaining'] . ' seconds from now.', $html);
121+
$this->assertStringContainsString(
122+
'Your session is valid for ' . $t->data['remaining'] . ' seconds from now.',
123+
$html
124+
);
116125
}
117126

118-
public function testValidateTwigFiles()
127+
public function testValidateTwigFiles(): void
119128
{
120129
$root = dirname(dirname((dirname(dirname(__DIR__)))));
121130

122131
// Setup basic twig environment
123-
$loader = new \Twig\Loader\FilesystemLoader(['templates', 'modules'], $root);
124-
$twig = new \Twig\Environment($loader, ['cache' => false]);
132+
$loader = new FilesystemLoader(['templates', 'modules'], $root);
133+
$twig = new Environment($loader, ['cache' => false]);
125134

126135
$twigTranslator = new TwigTranslator([Translate::class, 'translateSingularGettext']);
127136
$twig->addExtension(new TranslationExtension($twigTranslator));
128-
$twig->addExtension(new \Twig\Extra\Intl\IntlExtension());
137+
$twig->addExtension(new IntlExtension());
129138

130139
// Fake functions
131-
$twig->addFunction(new TwigFunction('asset', function() { return ''; }));
132-
$twig->addFunction(new TwigFunction('moduleURL', function() { return ''; }));
140+
$twig->addFunction(
141+
new TwigFunction(
142+
'asset',
143+
function () {
144+
return '';
145+
}
146+
)
147+
);
148+
$twig->addFunction(
149+
new TwigFunction(
150+
'moduleURL',
151+
function () {
152+
return '';
153+
}
154+
)
155+
);
133156

134157
// Fake filters
135-
$twig->addFilter(new TwigFilter('translateFromArray', function() { return ''; }, ['needs_context' => true]));
136-
$twig->addFilter(new TwigFilter('entityDisplayName', function() { return ''; }));
158+
$twig->addFilter(
159+
new TwigFilter(
160+
'translateFromArray',
161+
function () {
162+
return '';
163+
},
164+
['needs_context' => true]
165+
)
166+
);
167+
$twig->addFilter(
168+
new TwigFilter(
169+
'entityDisplayName',
170+
function () {
171+
return '';
172+
}
173+
)
174+
);
137175

138176
$files = Finder::create()
139177
->name('*.twig')
140-
->in([
141-
$root . '/templates',
142-
$root . '/modules'
143-
]);
178+
->in(
179+
[
180+
$root . '/templates',
181+
$root . '/modules'
182+
]
183+
);
144184

145185
foreach ($files as $file) {
146-
/** @var SplFileInfo $file */
186+
/** @var \Symfony\Component\Finder\SplFileInfo $file */
147187
$twig->load($file->getRelativePathname());
148188
}
149189

tests/modules/saml/lib/IdP/SAML2Test.php

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SimpleSAML\Test\Module\saml\IdP;
66

77
use InvalidArgumentException;
8+
use SAML2\XML\Chunk;
89
use SimpleSAML\Configuration;
910
use SimpleSAML\Error\Exception;
1011
use SimpleSAML\IdP;
@@ -288,8 +289,13 @@ public function testIdPGetHostedMetadataMinimal(): void
288289
$this->assertArrayHasKey('SingleLogoutService', $hostedMd);
289290
$this->assertIsArray($hostedMd['SingleLogoutService']);
290291
$this->assertCount(1, $hostedMd['SingleLogoutService']);
291-
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
292-
'Location' => 'http://localhost/simplesaml/saml2/idp/SingleLogoutService.php'], $hostedMd['SingleLogoutService'][0]);
292+
$this->assertEquals(
293+
[
294+
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
295+
'Location' => 'http://localhost/simplesaml/saml2/idp/SingleLogoutService.php'
296+
],
297+
$hostedMd['SingleLogoutService'][0]
298+
);
293299

294300
$this->assertArrayHasKey('keys', $hostedMd);
295301
$this->assertIsArray($hostedMd['keys']);
@@ -349,8 +355,14 @@ public function testIdPGetHostedMetadataArtifact(): void
349355
$this->assertArrayHasKey('ArtifactResolutionService', $hostedMd);
350356
$this->assertIsArray($hostedMd['ArtifactResolutionService']);
351357
$this->assertCount(1, $hostedMd['ArtifactResolutionService']);
352-
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP', 'index' => 0,
353-
'Location' => 'http://localhost/simplesaml/saml2/idp/ArtifactResolutionService.php'], $hostedMd['ArtifactResolutionService'][0]);
358+
$this->assertEquals(
359+
[
360+
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
361+
'index' => 0,
362+
'Location' => 'http://localhost/simplesaml/saml2/idp/ArtifactResolutionService.php'
363+
],
364+
$hostedMd['ArtifactResolutionService'][0]
365+
);
354366
}
355367

356368
public function testIdPGetHostedMetadataHolderOfKey(): void
@@ -361,9 +373,14 @@ public function testIdPGetHostedMetadataHolderOfKey(): void
361373
$this->assertArrayHasKey('SingleSignOnService', $hostedMd);
362374
$this->assertIsArray($hostedMd['SingleSignOnService']);
363375
$this->assertCount(2, $hostedMd['SingleSignOnService']);
364-
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser',
365-
'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php',
366-
'hoksso:ProtocolBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'], $hostedMd['SingleSignOnService'][0]);
376+
$this->assertEquals(
377+
[
378+
'Binding' => 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser',
379+
'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php',
380+
'hoksso:ProtocolBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
381+
],
382+
$hostedMd['SingleSignOnService'][0]
383+
);
367384
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
368385
'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php'], $hostedMd['SingleSignOnService'][1]);
369386
}
@@ -527,19 +544,26 @@ public function testMetadataHostedEntityExtensions(): void
527544
{
528545
$dom = \SAML2\DOMDocumentFactory::create();
529546
$republishRequest = $dom->createElementNS('http://eduid.cz/schema/metadata/1.0', 'eduidmd:RepublishRequest');
530-
$republishTarget = $dom->createElementNS('http://eduid.cz/schema/metadata/1.0', 'eduidmd:RepublishTarget', 'http://edugain.org/');
547+
$republishTarget = $dom->createElementNS(
548+
'http://eduid.cz/schema/metadata/1.0',
549+
'eduidmd:RepublishTarget',
550+
'http://edugain.org/'
551+
);
531552
$republishRequest->appendChild($republishTarget);
532-
$ext = [new \SAML2\XML\Chunk($republishRequest)];
553+
$ext = [new Chunk($republishRequest)];
533554

534555
$config = [
535556
'saml:Extensions' => $ext,
536-
];
557+
];
537558
$md = $this->idpMetadataHandlerHelper($config);
538559

539560
$this->assertArrayHasKey('saml:Extensions', $md);
540561
$this->assertCount(1, $md['saml:Extensions']);
541-
$this->assertInstanceOf(\SAML2\XML\Chunk::class, $md['saml:Extensions'][0]);
542-
$this->assertEquals('http://edugain.org/', $md['saml:Extensions'][0]->getXML()->firstChild->firstChild->textContent);
562+
$this->assertInstanceOf(Chunk::class, $md['saml:Extensions'][0]);
563+
$this->assertEquals(
564+
'http://edugain.org/',
565+
$md['saml:Extensions'][0]->getXML()->firstChild->firstChild->textContent
566+
);
543567
}
544568

545569
/**
@@ -723,15 +747,17 @@ public function testMetadataHostedContactsSkipsNAGlobalTechContact(): void
723747
$globalConfig = [
724748
'technicalcontact_email' => 'na@example.org',
725749
'technicalcontact_name' => 'Someone von Somewhere',
726-
];
750+
];
727751

728-
$config = ['contacts' => [
729-
[
730-
'contactType' => 'technical',
731-
'emailAddress' => 'j.doe@example.edu',
732-
'surName' => 'Doe',
733-
],
734-
]];
752+
$config = [
753+
'contacts' => [
754+
[
755+
'contactType' => 'technical',
756+
'emailAddress' => 'j.doe@example.edu',
757+
'surName' => 'Doe',
758+
],
759+
]
760+
];
735761
$md = $this->idpMetadataHandlerHelper($config, $globalConfig);
736762

737763
$this->assertCount(1, $md['contacts']);

0 commit comments

Comments
 (0)