Skip to content

Commit 9f022c4

Browse files
committed
Fix phpstan-issues
1 parent 471f03f commit 9f022c4

File tree

8 files changed

+161
-134
lines changed

8 files changed

+161
-134
lines changed

phpstan-baseline.neon

Lines changed: 132 additions & 106 deletions
Large diffs are not rendered by default.

phpstan-dev-baseline.neon

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Property SimpleSAML\\\\Module\\\\casserver\\\\Tests\\\\Controller\\\\Cas10ControllerTest\\:\\:\\$sessionMock is never read, only written\\.$#"
4+
message: '#^Property SimpleSAML\\Module\\casserver\\Tests\\Controller\\Cas10ControllerTest\:\:\$sessionMock is never read, only written\.$#'
5+
identifier: property.onlyWritten
56
count: 1
67
path: tests/src/Controller/Cas10ControllerTest.php
78

89
-
9-
message: "#^Property SimpleSAML\\\\Module\\\\casserver\\\\Tests\\\\Controller\\\\Cas20ControllerTest\\:\\:\\$sessionMock is never read, only written\\.$#"
10+
message: '#^Property SimpleSAML\\Module\\casserver\\Tests\\Controller\\Cas20ControllerTest\:\:\$sessionMock is never read, only written\.$#'
11+
identifier: property.onlyWritten
1012
count: 1
1113
path: tests/src/Controller/Cas20ControllerTest.php
1214

1315
-
14-
message: "#^Property SimpleSAML\\\\Module\\\\casserver\\\\Tests\\\\Controller\\\\Cas20ControllerTest\\:\\:\\$ticketValidatorMock is never read, only written\\.$#"
16+
message: '#^Property SimpleSAML\\Module\\casserver\\Tests\\Controller\\Cas20ControllerTest\:\:\$ticketValidatorMock is never read, only written\.$#'
17+
identifier: property.onlyWritten
1518
count: 1
1619
path: tests/src/Controller/Cas20ControllerTest.php
1720

1821
-
19-
message: "#^Call to an undefined method SimpleSAML\\\\Module\\\\casserver\\\\Cas\\\\TicketValidator\\:\\:expects\\(\\)\\.$#"
22+
message: '#^Call to an undefined method SimpleSAML\\Module\\casserver\\Cas\\TicketValidator\:\:expects\(\)\.$#'
23+
identifier: method.notFound
2024
count: 2
2125
path: tests/src/Controller/Cas30ControllerTest.php
2226

2327
-
24-
message: "#^Property SimpleSAML\\\\Module\\\\casserver\\\\Tests\\\\Controller\\\\Cas30ControllerTest\\:\\:\\$sessionMock is never read, only written\\.$#"
28+
message: '#^Property SimpleSAML\\Module\\casserver\\Tests\\Controller\\Cas30ControllerTest\:\:\$sessionMock is never read, only written\.$#'
29+
identifier: property.onlyWritten
2530
count: 1
2631
path: tests/src/Controller/Cas30ControllerTest.php
2732

2833
-
29-
message: "#^Parameter \\#2 \\$renew of method SimpleSAML\\\\Module\\\\casserver\\\\Controller\\\\LoginController\\:\\:login\\(\\) expects bool, string given\\.$#"
34+
message: '#^Parameter \#2 \$renew of method SimpleSAML\\Module\\casserver\\Controller\\LoginController\:\:login\(\) expects bool, string given\.$#'
35+
identifier: argument.type
3036
count: 1
3137
path: tests/src/Controller/LoginControllerTest.php
3238

3339
-
34-
message: "#^Property SimpleSAML\\\\Module\\\\casserver\\\\Tests\\\\Controller\\\\LoginControllerTest\\:\\:\\$sspContainer is never read, only written\\.$#"
40+
message: '#^Property SimpleSAML\\Module\\casserver\\Tests\\Controller\\LoginControllerTest\:\:\$sspContainer is never read, only written\.$#'
41+
identifier: property.onlyWritten
3542
count: 1
3643
path: tests/src/Controller/LoginControllerTest.php

src/Cas/Protocol/Cas20.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function getProxyGrantingTicketIOU(): ?string
123123

124124
/**
125125
* @param string $username
126-
* @return \SimpleSAML\CAS\XML\cas\ServiceResponse
126+
* @return \SimpleSAML\CAS\XML\ServiceResponse
127127
*/
128128
public function getValidateSuccessResponse(string $username): ServiceResponse
129129
{
@@ -175,7 +175,7 @@ public function getValidateSuccessResponse(string $username): ServiceResponse
175175
/**
176176
* @param string $errorCode
177177
* @param string $explanation
178-
* @return \SimpleSAML\CAS\XML\cas\ServiceResponse
178+
* @return \SimpleSAML\CAS\XML\ServiceResponse
179179
*/
180180
public function getValidateFailureResponse(string $errorCode, string $explanation): ServiceResponse
181181
{
@@ -191,7 +191,7 @@ public function getValidateFailureResponse(string $errorCode, string $explanatio
191191

192192
/**
193193
* @param string $proxyTicketId
194-
* @return \SimpleSAML\CAS\XML\cas\ServiceResponse
194+
* @return \SimpleSAML\CAS\XML\ServiceResponse
195195
*/
196196
public function getProxySuccessResponse(string $proxyTicketId): ServiceResponse
197197
{
@@ -206,7 +206,7 @@ public function getProxySuccessResponse(string $proxyTicketId): ServiceResponse
206206
/**
207207
* @param string $errorCode
208208
* @param string $explanation
209-
* @return \SimpleSAML\CAS\XML\cas\ServiceResponse
209+
* @return \SimpleSAML\CAS\XML\ServiceResponse
210210
*/
211211
public function getProxyFailureResponse(string $errorCode, string $explanation): ServiceResponse
212212
{

src/Cas/TicketValidator.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ public function __construct(Configuration $casconfig)
3838
);
3939
$ticketStoreClass = Module::resolveClass($ticketStoreConfig['class'], 'Cas\Ticket');
4040

41-
/** @var \SimpleSAML\Module\casserver\Cas\Ticket\TicketStore $this->ticketStore */
4241
$this->ticketStore = new $ticketStoreClass($casconfig);
4342
$ticketFactoryClass = Module::resolveClass('casserver:TicketFactory', 'Cas\Factories');
4443

45-
/** @var \SimpleSAML\Module\casserver\Cas\Factories\TicketFactory $this->ticketStore */
4644
$this->ticketFactory = new $ticketFactoryClass($casconfig);
4745
}
4846

src/Shib13/AuthnResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SimpleSAML\Module\casserver\Shib13;
66

77
use DOMDocument;
8+
use DOMElement;
89
use DOMNode;
910
use DOMNodeList;
1011
use DOMXPath;
@@ -215,6 +216,8 @@ public function getSessionIndex(): ?string
215216
$nodelist = $this->doXPathQuery($query);
216217

217218
if ($node = $nodelist->item(0)) {
219+
Assert::isInstanceOf($node, DOMElement::class);
220+
/** @var \DOMElement $node */
218221
return $node->getAttribute('SessionIndex');
219222
}
220223

@@ -241,12 +244,14 @@ public function getAttributes(): array
241244
$assertions = $this->doXPathQuery('/shibp:Response/shib:Assertion');
242245

243246
foreach ($assertions as $assertion) {
247+
/** @var \DOMElement $assertion */
244248
if (!$this->isNodeValidated($assertion)) {
245249
throw new Exception('Shib13 AuthnResponse contained an unsigned assertion.');
246250
}
247251

248252
$conditions = $this->doXPathQuery('shib:Conditions', $assertion);
249253
if ($conditions->length > 0) {
254+
/** @var \DOMElement $condition */
250255
$condition = $conditions->item(0);
251256

252257
$start = $condition->getAttribute('NotBefore');
@@ -312,6 +317,7 @@ public function getIssuer(): string
312317
$nodelist = $this->doXPathQuery($query);
313318

314319
if ($attr = $nodelist->item(0)) {
320+
/** @var \DOMAttr $attr */
315321
return $attr->value;
316322
} else {
317323
throw new Exception('Could not find Issuer field in Authentication response');
@@ -330,6 +336,7 @@ public function getNameID(): array
330336
$nodelist = $this->doXPathQuery($query);
331337

332338
if ($node = $nodelist->item(0)) {
339+
/** @var \DOMElement $node */
333340
$nameID["Value"] = $node->nodeValue;
334341
$nameID["Format"] = $node->getAttribute('Format');
335342
}

tests/src/Cas/Protocol/SamlValidateTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public function testSamlValidateXmlGeneration(): void
6565

6666
$asSoap = $samlValidate->wrapInSoap($xmlString);
6767

68-
$this->assertInstanceOf(Envelope::class, $asSoap);
6968
$this->assertNull($asSoap->getHeader());
70-
$this->assertNotEmpty($asSoap->getBody());
69+
$this->assertFalse($asSoap->getBody()->isEmptyElement());
7170
}
7271
}

tests/src/Controller/Cas20ControllerTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,14 @@ public function testProxyValidatePassesTheCorrectMethodToValidate(string $prefix
144144
parameters: $requestParameters,
145145
);
146146

147-
$expectedArguments = [
148-
'request' => $request,
149-
'method' => $method,
150-
'renew' => false,
151-
'target' => null,
152-
'ticket' => $prefix . $this->sessionId,
153-
'service' => 'https://myservice.com/abcd',
154-
'pgtUrl' => null,
155-
];
156-
157147
$controllerMock = $this->getMockBuilder(Cas20Controller::class)
158148
->setConstructorArgs([$this->sspConfig, $casconfig])
159149
->onlyMethods(['validate'])
160150
->getMock();
161151

162-
$controllerMock->expects($this->once())->method('validate')
163-
->with(...$expectedArguments);
152+
$controllerMock->expects($this->once())
153+
->method('validate')
154+
->with($request, $method, false, null, $prefix . $this->sessionId, 'https://myservice.com/abcd', null);
164155
$controllerMock->$method($request, ...$requestParameters);
165156
}
166157

tests/src/Controller/LogoutControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ public function testLogoutNoRedirectUrlOnNoSkipLogoutAuthenticated(): void
180180

181181
$response = $controller->logout($logoutRequest, ...$queryParameters);
182182

183-
$this->assertInstanceOf(RunnableResponse::class, $response);
184183
$callable = (array)$response->getCallable();
185184
$this->assertEquals('logout', $callable[1] ?? '');
186185
}

0 commit comments

Comments
 (0)