Skip to content

Commit 739f907

Browse files
committed
Rework
- Drop unused DateTime - Small refactorings & improvements
1 parent 0935bad commit 739f907

11 files changed

Lines changed: 62 additions & 65 deletions

File tree

ci/qa/phpstan-baseline.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@
715715
'count' => 1,
716716
'path' => __DIR__ . '/../../src/Surfnet/StepupRa/RaBundle/Service/RaCandidateService.php',
717717
];
718+
$ignoreErrors[] = [
719+
'message' => '#^Left side of && is always true\\.$#',
720+
'identifier' => 'booleanAnd.leftAlwaysTrue',
721+
'count' => 2,
722+
'path' => __DIR__ . '/../../src/Surfnet/StepupRa/RaBundle/Service/RaListingService.php',
723+
];
718724
$ignoreErrors[] = [
719725
'message' => '#^Parameter \\#1 \\$raInstitution of method Surfnet\\\\StepupMiddlewareClient\\\\Identity\\\\Dto\\\\RaListingSearchQuery\\:\\:setRaInstitution\\(\\) expects string, string\\|null given\\.$#',
720726
'identifier' => 'argument.type',
@@ -847,6 +853,12 @@
847853
'count' => 1,
848854
'path' => __DIR__ . '/../../src/Surfnet/StepupRa/RaBundle/Twig/Extensions/Extension/SecondFactorType.php',
849855
];
856+
$ignoreErrors[] = [
857+
'message' => '#^Call to function is_int\\(\\) with int will always evaluate to true\\.$#',
858+
'identifier' => 'function.alreadyNarrowedType',
859+
'count' => 1,
860+
'path' => __DIR__ . '/../../src/Surfnet/StepupRa/RaBundle/Value/TimeFrame.php',
861+
];
850862
$ignoreErrors[] = [
851863
'message' => '#^Class Surfnet\\\\StepupRa\\\\RaBundle\\\\VettingProcedure has an uninitialized property \\$authorityId\\. Give it default value or assign it in the constructor\\.$#',
852864
'identifier' => 'property.uninitialized',

ci/qa/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ includes:
44
rules:
55

66
parameters:
7-
treatPhpDocTypesAsCertain: false
87
checkUninitializedProperties: true
98
level: 9
109
paths:

src/Surfnet/StepupRa/RaBundle/Controller/RaLocationController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct(
6666
#[IsGranted('ROLE_RA')]
6767
public function manage(Request $request): Response
6868
{
69-
$institutionParameter = $request->query->has('institution') ? $request->query->get('institution') : $request->request->get('institution');
69+
$institutionParameter = $request->query->get('institution') ?? $request->request->get('institution');
7070

7171
$identity = $this->getUser()->getIdentity();
7272
$this->logger->notice('Starting search for locations');
@@ -101,8 +101,8 @@ public function manage(Request $request): Response
101101

102102
$command = new SearchRaLocationsCommand();
103103
$command->institution = $institution;
104-
$command->orderBy = $this->getString($request, 'orderBy');
105-
$command->orderDirection = $this->getString($request, 'orderDirection');
104+
$command->orderBy = $this->getOrderBy($request);
105+
$command->orderDirection = $this->getOrderDirection($request);
106106

107107
$locations = $this->raLocationService->search($command);
108108

src/Surfnet/StepupRa/RaBundle/Controller/RaManagementController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function raCandidateSearch(Request $request): Response
135135
$command->actorInstitution = $institution;
136136
$command->raInstitution = null;
137137
$command->pageNumber = $request->query->has('p') ? $request->query->getInt('p') : $request->request->getInt('p', 1);
138-
$command->orderBy = $this->getString($request, 'orderBy');
139-
$command->orderDirection = $this->getString($request, 'orderDirection');
138+
$command->orderBy = $this->getOrderBy($request);
139+
$command->orderDirection = $this->getOrderDirection($request);
140140

141141
$raCandidateList = $this->raCandidateService->search($command);
142142

src/Surfnet/StepupRa/RaBundle/Controller/RecoveryTokenController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function search(Request $request): Response
5858
$command = new SearchRecoveryTokensCommand();
5959
$command->actorId = $identity->id;
6060
$command->pageNumber = $request->query->has('p') ? $request->query->getInt('p') : $request->request->getInt('p', 1);
61-
$command->orderBy = $this->getString($request, 'orderBy');
62-
$command->orderDirection = $this->getString($request, 'orderDirection');
61+
$command->orderBy = $this->getOrderBy($request);
62+
$command->orderDirection = $this->getOrderDirection($request);
6363

6464
// Huh, why do we load the recovery tokens at this point?
6565
// This is just to get the filter options for the available institutions of the search results.

src/Surfnet/StepupRa/RaBundle/Controller/SecondFactorController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function search(Request $request): Response
7373
$command = new SearchRaSecondFactorsCommand();
7474
$command->actorId = $identity->id;
7575
$command->pageNumber = $request->query->has('p') ? $request->query->getInt('p') : $request->request->getInt('p', 1);
76-
$command->orderBy = $this->getString($request, 'orderBy');
77-
$command->orderDirection = $this->getString($request, 'orderDirection');
76+
$command->orderBy = $this->getOrderBy($request);
77+
$command->orderDirection = $this->getOrderDirection($request);
7878

7979
$secondFactors = $this->secondFactorService->search($command);
8080

src/Surfnet/StepupRa/RaBundle/Controller/Traits/OrderFromRequest.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,32 @@ trait OrderFromRequest
2424
{
2525

2626
/**
27-
* Convenience method to read get / post params as string, with default null.
28-
* This is a commonly used pattern in the RA controllers
27+
* Convenience method to read orderBy from both get & post params as string, with default null.
2928
*/
30-
private function getString(Request $request, string $paramName): null|string
29+
public function getOrderBy(Request $request): null|string
3130
{
32-
if ($request->query->has($paramName)) {
33-
return $request->query->getString($paramName);
31+
if ($request->query->has('orderBy')) {
32+
return $request->query->getString('orderBy');
3433
}
3534

36-
if ($request->request->has($paramName)) {
37-
return $request->request->getString($paramName);
35+
if ($request->request->has('orderBy')) {
36+
return $request->request->getString('orderBy');
37+
}
38+
39+
return null;
40+
}
41+
42+
/**
43+
* Convenience method to read orderDirection from both get & post params as string, with default null.
44+
*/
45+
public function getOrderDirection(Request $request): null|string
46+
{
47+
if ($request->query->has('orderDirection')) {
48+
return $request->query->getString('orderDirection');
49+
}
50+
51+
if ($request->request->has('orderDirection')) {
52+
return $request->request->getString('orderDirection');
3853
}
3954

4055
return null;

src/Surfnet/StepupRa/RaBundle/DateTime/DateTime.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Surfnet/StepupRa/RaBundle/Security/AuthenticatedIdentity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getUserIdentifier(): string
113113
$parts = explode(':', $this->originalIdentity->nameId);
114114
$identifier = end($parts);
115115

116-
if ($identifier === false || $identifier === '') {
116+
if ($identifier === '') {
117117
throw new LogicException('Cannot determine user identifier from nameId');
118118
}
119119

src/Surfnet/StepupRa/RaBundle/Tests/Controller/Traits/OrderFromRequestTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,14 @@ protected function setUp(): void
3131
{
3232
$this->traitObject = new class {
3333
use OrderFromRequest;
34-
35-
public function getStringPublic(Request $request, string $paramName): null|string
36-
{
37-
return $this->getString($request, $paramName);
38-
}
3934
};
4035
}
4136

4237
#[Test]
4338
public function it_returns_value_from_query_parameter(): void
4439
{
4540
$request = new Request(['orderBy' => 'name']);
46-
$result = $this->traitObject->getStringPublic($request, 'orderBy');
41+
$result = $this->traitObject->getOrderBy($request);
4742

4843
$this->assertSame('name', $result);
4944
}
@@ -52,7 +47,7 @@ public function it_returns_value_from_query_parameter(): void
5247
public function it_returns_value_from_request_parameter(): void
5348
{
5449
$request = new Request([], ['orderBy' => 'date']);
55-
$result = $this->traitObject->getStringPublic($request, 'orderBy');
50+
$result = $this->traitObject->getOrderBy($request);
5651

5752
$this->assertSame('date', $result);
5853
}
@@ -61,7 +56,7 @@ public function it_returns_value_from_request_parameter(): void
6156
public function it_returns_null_when_parameter_not_found(): void
6257
{
6358
$request = new Request();
64-
$result = $this->traitObject->getStringPublic($request, 'orderBy');
59+
$result = $this->traitObject->getOrderBy($request);
6560

6661
$this->assertNull($result);
6762
}
@@ -71,7 +66,7 @@ public function it_prioritizes_query_parameter_over_request_parameter(): void
7166
{
7267
$request = new Request(['orderBy' => 'query_value'], ['orderBy' => 'request_value']);
7368

74-
$result = $this->traitObject->getStringPublic($request, 'orderBy');
69+
$result = $this->traitObject->getOrderBy($request);
7570

7671
$this->assertSame('query_value', $result);
7772
}
@@ -80,18 +75,26 @@ public function it_prioritizes_query_parameter_over_request_parameter(): void
8075
public function it_handles_empty_string_values(): void
8176
{
8277
$request = new Request(['orderBy' => '']);
83-
$result = $this->traitObject->getStringPublic($request, 'orderBy');
78+
$result = $this->traitObject->getOrderBy($request);
8479

8580
$this->assertSame('', $result);
8681
}
8782

8883
#[Test]
8984
public function it_handles_numeric_string_values(): void
9085
{
91-
$request = new Request(['page' => '42']);
92-
$result = $this->traitObject->getStringPublic($request, 'page');
86+
$request = new Request(['orderBy' => '42']);
87+
$result = $this->traitObject->getOrderBy($request);
9388

9489
$this->assertSame('42', $result);
9590
}
96-
}
9791

92+
#[Test]
93+
public function it_returns_order_direction_from_query_parameter(): void
94+
{
95+
$request = new Request(['orderDirection' => 'asc']);
96+
$result = $this->traitObject->getOrderDirection($request);
97+
98+
$this->assertSame('asc', $result);
99+
}
100+
}

0 commit comments

Comments
 (0)