Skip to content

Commit 372d1ec

Browse files
rubenvdlindeclaude
andcommitted
chore: Apply PHPCS coding standards to small/medium PHP files
Fixed PHPCS violations in 32 lib/ files (all at 0 errors). Changes include: - Added declare(strict_types=1) to all files missing it - Fixed property and method doc blocks (short descriptions, @param/@return order) - Replaced operator ! with === false/true explicit comparisons - Replaced implicit true comparisons with === true - Added named parameters to function calls - Expanded inline ternary IFs to if/else blocks - Fixed inline comments to end with periods - Added end-of-block comments (//end method()) - Fixed file doc comment formatting Large service classes intentionally skipped (too many violations for this pass): ArchiMateService (517), ArchiMateExportService (183), ArchiMateImportService (1174), SettingsService (527), SoftwareCatalogueService (319), OrganizationSyncService (291), ContactPersonHandler (252). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 567acf9 commit 372d1ec

32 files changed

Lines changed: 3461 additions & 2617 deletions

lib/AppInfo/Application.php

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

lib/BackgroundJob/CronjobContextTrait.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
/**
44
* Cronjob Context Trait
55
*
6-
* @deprecated Since all sync operations now use _rbac: false and _multitenancy: false,
7-
* this trait is no longer needed. Background jobs are system-level operations
8-
* that do not require user context. Will be removed in a future version.
9-
* See OrganizationContactSyncJob for the simplified approach.
6+
* Since all sync operations now use _rbac: false and _multitenancy: false,
7+
* this trait is no longer needed. Background jobs are system-level operations
8+
* that do not require user context. Will be removed in a future version.
9+
* See OrganizationContactSyncJob for the simplified approach.
1010
*
11-
* @category Trait
12-
* @package OCA\SoftwareCatalog\BackgroundJob
13-
* @author Conduction b.v. <info@conduction.nl>
14-
* @copyright 2024 Conduction B.V.
15-
* @license AGPL-3.0-or-later https://www.gnu.org/licenses/agpl-3.0.html
16-
* @version 1.0.0
17-
* @link https://github.com/ConductionNL/SoftwareCatalog
11+
* @category Trait
12+
* @package OCA\SoftwareCatalog\BackgroundJob
13+
* @author Conduction b.v. <info@conduction.nl>
14+
* @copyright 2024 Conduction B.V.
15+
* @license AGPL-3.0-or-later https://www.gnu.org/licenses/agpl-3.0.html
16+
* @version GIT: <git_id>
17+
* @link https://github.com/ConductionNL/SoftwareCatalog
18+
* @deprecated Will be removed in a future version.
1819
*/
1920

2021
declare(strict_types=1);
@@ -91,7 +92,7 @@ protected function setCronjobContext(string $jobId): bool
9192
}
9293

9394
// Check if job is enabled.
94-
if (!($context['enabled'] ?? true)) {
95+
if (($context['enabled'] ?? true) === false) {
9596
$this->getLogger()->info(
9697
'[CRONJOB] Cronjob is disabled',
9798
[
@@ -127,7 +128,7 @@ protected function setCronjobContext(string $jobId): bool
127128
$this->cronjobOrganisationUuid = $organisationUuid;
128129

129130
// Set the active organisation in OpenRegister if available.
130-
if (class_exists('\OCA\OpenRegister\Service\OrganisationService')) {
131+
if (class_exists(classname: '\OCA\OpenRegister\Service\OrganisationService') === true) {
131132
try {
132133
$config = \OC::$server->get(IConfig::class);
133134

@@ -186,7 +187,7 @@ protected function setCronjobContext(string $jobId): bool
186187
protected function clearCronjobContext(string $jobId): void
187188
{
188189
try {
189-
if (!$this->contextSet) {
190+
if ($this->contextSet === false) {
190191
return;
191192
}
192193

lib/Controller/AanbodController.php

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
declare(strict_types=1);
4-
5-
/*
6-
* Aanbod Controller for SoftwareCatalog
3+
/**
4+
* Aanbod Controller for SoftwareCatalog.
75
*
86
* Handles HTTP requests for aanbod (offers) operations including retrieving
97
* aanbod objects (gebruik, dienst, module, koppeling) and accepting or denying them.
@@ -13,10 +11,12 @@
1311
* @author Conduction b.v. <info@conduction.nl>
1412
* @copyright 2024 Conduction B.V.
1513
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
16-
* @version 1.0.0
14+
* @version GIT: <git_id>
1715
* @link https://github.com/ConductionNL/SoftwareCatalog
1816
*/
1917

18+
declare(strict_types=1);
19+
2020
namespace OCA\SoftwareCatalog\Controller;
2121

2222
use OCP\AppFramework\Controller;
@@ -27,7 +27,7 @@
2727
use Psr\Log\LoggerInterface;
2828

2929
/**
30-
* Controller for handling aanbod (offers) API operations
30+
* Controller for handling aanbod (offers) API operations.
3131
*
3232
* This controller provides REST API endpoints for managing aanbod objects where
3333
* the active organization is involved either as afnemer (consumer) or aanbieder
@@ -38,13 +38,13 @@
3838
* @author Conduction b.v. <info@conduction.nl>
3939
* @copyright 2024 Conduction B.V.
4040
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
41-
* @version 1.0.0
41+
* @version GIT: <git_id>
4242
* @link https://github.com/ConductionNL/SoftwareCatalog
4343
*/
4444
class AanbodController extends Controller
4545
{
4646
/**
47-
* Constructor for AanbodController
47+
* Constructor for AanbodController.
4848
*
4949
* @param string $appName The name of the app
5050
* @param IRequest $request The HTTP request object
@@ -63,7 +63,7 @@ public function __construct(
6363
}//end __construct()
6464

6565
/**
66-
* Get all aanbod objects (modules, diensten, koppelingen, gebruiks)
66+
* Get all aanbod objects (modules, diensten, koppelingen, gebruiks).
6767
*
6868
* API Endpoint: GET /api/aanbod
6969
*
@@ -77,11 +77,11 @@ public function __construct(
7777
* - offset (int): Number of results to skip for pagination
7878
* - page (int): Page number for pagination
7979
*
80+
* @return JSONResponse JSON response with aanbod objects array
81+
*
8082
* @NoAdminRequired
8183
* @NoCSRFRequired
8284
* @PublicPage
83-
*
84-
* @return JSONResponse JSON response with aanbod objects array
8585
*/
8686
public function getAanbod(): JSONResponse
8787
{
@@ -95,21 +95,25 @@ public function getAanbod(): JSONResponse
9595
);
9696

9797
try {
98-
// Parse query parameters for filtering options
98+
// Parse query parameters for filtering options.
9999
$options = $this->parseQueryOptions();
100100

101-
// Get aanbod objects from service
101+
// Get aanbod objects from service.
102102
$result = $this->aanbodService->getAanbod($options);
103103

104-
// Determine HTTP status code based on whether there's an error
105-
$statusCode = isset($result['error']) ? 500 : 200;
104+
// Determine HTTP status code based on whether there's an error.
105+
if (isset($result['error']) === true) {
106+
$statusCode = 500;
107+
} else {
108+
$statusCode = 200;
109+
}
106110

107111
$this->logger->info(
108112
'API: Aanbod request completed',
109113
[
110114
'total' => $result['total'] ?? 0,
111115
'results_count' => count($result['results'] ?? []),
112-
'has_error' => isset($result['error']),
116+
'has_error' => isset($result['error']) === true,
113117
]
114118
);
115119

@@ -139,20 +143,21 @@ public function getAanbod(): JSONResponse
139143
}//end getAanbod()
140144

141145
/**
142-
* Accept an aanbod object (set @self.organisation to current organisation)
146+
* Accept an aanbod object (set @self.organisation to current organisation).
143147
*
144148
* API Endpoint: PUT /api/aanbod/{uuid}/accept
145149
*
146150
* Sets the '@self.organisation' property of an aanbod object to the active
147151
* organization. This operation is only allowed if the active organization
148152
* is the afnemer (for gebruiks) or aanbieder (for modules, diensten, koppelingen).
149153
*
154+
* @param string $uuid The UUID of the aanbod object to accept
155+
*
156+
* @return JSONResponse JSON response with success status and updated object
157+
*
150158
* @NoAdminRequired
151159
* @NoCSRFRequired
152160
* @PublicPage
153-
*
154-
* @param string $uuid The UUID of the aanbod object to accept
155-
* @return JSONResponse JSON response with success status and updated object
156161
*/
157162
public function acceptAanbod(string $uuid): JSONResponse
158163
{
@@ -166,8 +171,8 @@ public function acceptAanbod(string $uuid): JSONResponse
166171
);
167172

168173
try {
169-
// Validate input
170-
if (empty($uuid)) {
174+
// Validate input.
175+
if (empty($uuid) === true) {
171176
return new JSONResponse(
172177
[
173178
'success' => false,
@@ -178,25 +183,33 @@ public function acceptAanbod(string $uuid): JSONResponse
178183
);
179184
}
180185

181-
// Parse any additional options from request body
186+
// Parse any additional options from request body.
182187
$options = [];
183188
$requestBody = $this->request->getParams();
184-
if (!empty($requestBody)) {
189+
if (empty($requestBody) === false) {
185190
$options = array_filter(
186191
$requestBody,
187192
function ($key) {
188-
return !in_array($key, ['uuid']);
189-
// Exclude path parameters
193+
// Exclude path parameters.
194+
return in_array(needle: $key, haystack: ['uuid']) === false;
190195
},
191196
ARRAY_FILTER_USE_KEY
192197
);
193198
}
194199

195-
// Accept aanbod object via service
196-
$result = $this->aanbodService->acceptAanbod($uuid, $options);
197-
198-
// Determine appropriate HTTP status code
199-
$statusCode = $result['success'] ? 200 : ($result['error'] === 'Aanbod object not found' ? 404 : (strpos($result['error'] ?? '', 'Operation not allowed') !== false ? 403 : 500));
200+
// Accept aanbod object via service.
201+
$result = $this->aanbodService->acceptAanbod(uuid: $uuid, options: $options);
202+
203+
// Determine appropriate HTTP status code.
204+
if ($result['success'] === true) {
205+
$statusCode = 200;
206+
} else if ($result['error'] === 'Aanbod object not found') {
207+
$statusCode = 404;
208+
} else if (strpos(haystack: ($result['error'] ?? ''), needle: 'Operation not allowed') !== false) {
209+
$statusCode = 403;
210+
} else {
211+
$statusCode = 500;
212+
}
200213

201214
$this->logger->info(
202215
'API: Accept aanbod request completed',
@@ -230,20 +243,21 @@ function ($key) {
230243
}//end acceptAanbod()
231244

232245
/**
233-
* Deny an aanbod object (delete it)
246+
* Deny an aanbod object (delete it).
234247
*
235248
* API Endpoint: DELETE /api/aanbod/{uuid}/deny
236249
*
237250
* Deletes an aanbod object. This operation is only allowed if the active
238251
* organization is the afnemer (for gebruiks) or aanbieder (for modules,
239252
* diensten, koppelingen).
240253
*
254+
* @param string $uuid The UUID of the aanbod object to deny
255+
*
256+
* @return JSONResponse JSON response with success status and deletion details
257+
*
241258
* @NoAdminRequired
242259
* @NoCSRFRequired
243260
* @PublicPage
244-
*
245-
* @param string $uuid The UUID of the aanbod object to deny
246-
* @return JSONResponse JSON response with success status and deletion details
247261
*/
248262
public function denyAanbod(string $uuid): JSONResponse
249263
{
@@ -257,8 +271,8 @@ public function denyAanbod(string $uuid): JSONResponse
257271
);
258272

259273
try {
260-
// Validate input
261-
if (empty($uuid)) {
274+
// Validate input.
275+
if (empty($uuid) === true) {
262276
return new JSONResponse(
263277
[
264278
'success' => false,
@@ -269,25 +283,33 @@ public function denyAanbod(string $uuid): JSONResponse
269283
);
270284
}
271285

272-
// Parse any additional options from request body
286+
// Parse any additional options from request body.
273287
$options = [];
274288
$requestBody = $this->request->getParams();
275-
if (!empty($requestBody)) {
289+
if (empty($requestBody) === false) {
276290
$options = array_filter(
277291
$requestBody,
278292
function ($key) {
279-
return !in_array($key, ['uuid']);
280-
// Exclude path parameters
293+
// Exclude path parameters.
294+
return in_array(needle: $key, haystack: ['uuid']) === false;
281295
},
282296
ARRAY_FILTER_USE_KEY
283297
);
284298
}
285299

286-
// Deny aanbod object via service
287-
$result = $this->aanbodService->denyAanbod($uuid, $options);
288-
289-
// Determine appropriate HTTP status code
290-
$statusCode = $result['success'] ? 200 : ($result['error'] === 'Aanbod object not found' ? 404 : (strpos($result['error'] ?? '', 'Operation not allowed') !== false ? 403 : 500));
300+
// Deny aanbod object via service.
301+
$result = $this->aanbodService->denyAanbod(uuid: $uuid, options: $options);
302+
303+
// Determine appropriate HTTP status code.
304+
if ($result['success'] === true) {
305+
$statusCode = 200;
306+
} else if ($result['error'] === 'Aanbod object not found') {
307+
$statusCode = 404;
308+
} else if (strpos(haystack: ($result['error'] ?? ''), needle: 'Operation not allowed') !== false) {
309+
$statusCode = 403;
310+
} else {
311+
$statusCode = 500;
312+
}
291313

292314
$this->logger->info(
293315
'API: Deny aanbod request completed',
@@ -322,35 +344,35 @@ function ($key) {
322344
}//end denyAanbod()
323345

324346
/**
325-
* Parse query parameters into options array
347+
* Parse query parameters into options array.
326348
*
327349
* @return array Parsed options array
328350
*/
329351
private function parseQueryOptions(): array
330352
{
331353
$options = [];
332354

333-
// Parse pagination parameters
355+
// Parse pagination parameters.
334356
$limit = $this->request->getParam('_limit') ?? $this->request->getParam('limit');
335-
if ($limit !== null && is_numeric($limit)) {
357+
if ($limit !== null && is_numeric($limit) === true) {
336358
$options['_limit'] = (int) $limit;
337-
$options['limit'] = (int) $limit;
338-
// Keep both for compatibility
359+
// Keep both for compatibility.
360+
$options['limit'] = (int) $limit;
339361
}
340362

341363
$offset = $this->request->getParam('_offset') ?? $this->request->getParam('offset');
342-
if ($offset !== null && is_numeric($offset)) {
364+
if ($offset !== null && is_numeric($offset) === true) {
343365
$options['_offset'] = (int) $offset;
344-
$options['offset'] = (int) $offset;
345-
// Keep both for compatibility
366+
// Keep both for compatibility.
367+
$options['offset'] = (int) $offset;
346368
}
347369

348370
$page = $this->request->getParam('_page') ?? $this->request->getParam('page');
349-
if ($page !== null && is_numeric($page)) {
371+
if ($page !== null && is_numeric($page) === true) {
350372
$options['_page'] = (int) $page;
351373
}
352374

353-
// Force database source for real-time data
375+
// Force database source for real-time data.
354376
$options['_source'] = 'database';
355377

356378
$this->logger->debug(

0 commit comments

Comments
 (0)