Skip to content

Commit aa2b625

Browse files
committed
Fix: lint-errors & moduleName fetching
1 parent 9c2277f commit aa2b625

File tree

12 files changed

+37
-29
lines changed

12 files changed

+37
-29
lines changed

application/controllers/ApiController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function indexAction(): never
3333
{
3434
$this->assertPermission('notifications/api/v1');
3535
$request = $this->getRequest();
36-
if (!$request->isApiRequest() && strtolower($request->getParam('endpoint')) !== ApiCore::OPENAPI_ENDPOINT) {
36+
if (! $request->isApiRequest() && strtolower($request->getParam('endpoint')) !== ApiCore::OPENAPI_ENDPOINT) {
3737
$this->httpBadRequest('No API request');
3838
}
3939

@@ -69,14 +69,14 @@ private function dispatchEndpoint(Request $request, Response $response): void
6969
$className = sprintf('Icinga\\%sApi\\%s\\%s', $module, $version, $endpoint);
7070

7171
// Check if the required class and method are available and valid
72-
if (!class_exists($className) || (new ReflectionClass($className))->isAbstract()) {
72+
if (! class_exists($className) || (new ReflectionClass($className))->isAbstract()) {
7373
$this->httpNotFound(404, "Endpoint $endpoint does not exist.");
7474
}
7575

7676
// TODO: move this to an api core or version class?
7777
$parsedMethodName = ($method === 'GET' && empty($identifier)) ? $methodName . 'Any' : $methodName;
7878

79-
if (!in_array($parsedMethodName, get_class_methods($className))) {
79+
if (! in_array($parsedMethodName, get_class_methods($className))) {
8080
if ($method === 'GET' && in_array($methodName, get_class_methods($className))) {
8181
$parsedMethodName = $methodName;
8282
} else {
@@ -105,7 +105,7 @@ private function getValidatedJsonContent(Request $request): array
105105
$msgPrefix = 'Invalid request body: ';
106106

107107
if (
108-
!preg_match('/([^;]*);?/', $request->getHeader('Content-Type'), $matches)
108+
! preg_match('/([^;]*);?/', $request->getHeader('Content-Type'), $matches)
109109
|| $matches[1] !== 'application/json'
110110
) {
111111
$this->httpBadRequest($msgPrefix . 'Content-Type must be application/json');

application/controllers/ApiV1ContactgroupsController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ function (Filter\Condition $condition) {
214214
$contactgroupId = $this->getContactgroupId($identifier);
215215
if ($contactgroupId !== null) {
216216
$db->update('contactgroup', ['name' => $data['name']], ['id = ?' => $contactgroupId]);
217-
$db->update('contactgroup_member', ['deleted' => 'y'], ['contactgroup_id = ?' => $contactgroupId, 'deleted = ?' => 'n']);
217+
$db->update(
218+
'contactgroup_member',
219+
['deleted' => 'y'],
220+
['contactgroup_id = ?' => $contactgroupId, 'deleted = ?' => 'n']
221+
);
218222

219223
if (! empty($data['users'])) {
220224
$this->addUsers($contactgroupId, $data['users']);

application/controllers/ApiV1ContactsController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,16 @@ function (Filter\Condition $condition) {
231231
], ['id = ?' => $contactId]);
232232

233233
$markAsDeleted = ['deleted' => 'y'];
234-
$db->update('contact_address', $markAsDeleted, ['contact_id = ?' => $contactId, 'deleted = ?' => 'n']);
235-
$db->update('contactgroup_member', $markAsDeleted, ['contact_id = ?' => $contactId, 'deleted = ?' => 'n']);
234+
$db->update(
235+
'contact_address',
236+
$markAsDeleted,
237+
['contact_id = ?' => $contactId, 'deleted = ?' => 'n']
238+
);
239+
$db->update(
240+
'contactgroup_member',
241+
$markAsDeleted,
242+
['contact_id = ?' => $contactId, 'deleted = ?' => 'n']
243+
);
236244

237245
if (! empty($data['addresses'])) {
238246
$this->addAddresses($contactId, $data['addresses']);

application/forms/ContactGroupForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public function addGroup(): int
188188
'name' => trim($data['group_name']),
189189
'changed_at' => $changedAt,
190190
'external_uuid' => Uuid::uuid4()->toString()
191-
]);
191+
]
192+
);
192193

193194
$groupIdentifier = $this->db->lastInsertId();
194195

library/Notifications/Api/ApiCore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function getFilesIncludingDocs(string $fileFilter = '*'): array
8080
{
8181
$apiCoreDir = __DIR__ . '/ApiCore.php';
8282
// check if the extended object of this class has a attribute 'moduleName'
83-
$moduleName = property_exists($this, 'moduleName') ? $this->moduleName : 'default;';
83+
$moduleName = $this->getRequest()->getModuleName() ?: 'default;';
8484
if ($moduleName === 'default' || $moduleName === '') {
8585
$dir = Icinga::app()->getLibraryDir('Icinga/Application/Api/' . ucfirst($this->version) . '/');
8686
} else {
@@ -89,10 +89,10 @@ protected function getFilesIncludingDocs(string $fileFilter = '*'): array
8989
}
9090

9191
$dir = rtrim($dir, '/') . '/';
92-
if (!is_dir($dir)) {
92+
if (! is_dir($dir)) {
9393
throw new \RuntimeException("Directory $dir does not exist");
9494
}
95-
if (!is_readable($dir)) {
95+
if (! is_readable($dir)) {
9696
throw new \RuntimeException("Directory $dir is not readable");
9797
}
9898

library/Notifications/Api/V1/ApiV1.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
abstract class ApiV1 extends ApiCore
6060
{
6161
protected string $identifier;
62+
6263
/**
6364
* Initialize the API
6465
*
@@ -73,11 +74,11 @@ protected function init(): void
7374
$filterStr = Url::fromRequest()->getQueryString();
7475

7576
// Validate that Method with parameters or identifier is allowed
76-
if ($method !== 'GET' && !empty($filterStr)) {
77+
if ($method !== 'GET' && ! empty($filterStr)) {
7778
$this->httpBadRequest(
7879
"Invalid request: $method with query parameters, only GET is allowed with query parameters."
7980
);
80-
} elseif ($method === 'GET' && !empty($this->identifier) && !empty($filterStr)) {
81+
} elseif ($method === 'GET' && ! empty($this->identifier) && ! empty($filterStr)) {
8182
$this->httpBadRequest(
8283
"Invalid request: $method with identifier and query parameters, it's not allowed to use both together."
8384
);
@@ -95,7 +96,7 @@ protected function init(): void
9596
protected function validateIdentifier(): void
9697
{
9798
if ($identifier = $this->getRequest()->getParams()['identifier'] ?? null) {
98-
if (!Uuid::isValid($identifier)) {
99+
if (! Uuid::isValid($identifier)) {
99100
$this->httpBadRequest('The given identifier is not a valid UUID');
100101
}
101102
$this->identifier = $identifier;
@@ -114,7 +115,7 @@ protected function validateIdentifier(): void
114115
*/
115116
protected function createFilterFromFilterStr(callable $listener): array|bool
116117
{
117-
if (!empty($filterStr = Url::fromRequest()->getQueryString())) {
118+
if (! empty($filterStr = Url::fromRequest()->getQueryString())) {
118119
try {
119120
$filterRule = QueryString::fromString($filterStr)
120121
->on(

library/Notifications/Api/V1/Channels.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,4 @@ enum: ['email', 'webhook', 'rocketchat'],
127127
)]
128128
class Channels extends ApiV1
129129
{
130-
131130
}

library/Notifications/Api/V1/ContactGroups.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
)]
4141
class ContactGroups extends ApiV1
4242
{
43-
44-
4543
/**
4644
* Fetch the group identifiers of the contact with the given id
4745
*

library/Notifications/Api/V1/Contacts.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ public function get(): void
179179

180180
$this->sendJsonResponse(
181181
/** @throws JsonEncodeException */
182-
function () {
183-
echo Json::sanitize($this->results[0]);
184-
});
185-
182+
function () {
183+
echo Json::sanitize($this->results[0]);
184+
}
185+
);
186186
}
187187

188188
/**
@@ -251,7 +251,7 @@ public function getAny(): void
251251
$filter = $this->createFilterFromFilterStr(
252252
function (Condition $condition) {
253253
$column = $condition->getColumn();
254-
if (!in_array($column, ['id', 'full_name', 'username'])) {
254+
if (! in_array($column, ['id', 'full_name', 'username'])) {
255255
$this->httpBadRequest(
256256
sprintf(
257257
'Invalid filter column %s given, only id, full_name and username are allowed',
@@ -261,7 +261,7 @@ function (Condition $condition) {
261261
}
262262

263263
if ($column === 'id') {
264-
if (!Uuid::isValid($condition->getValue())) {
264+
if (! Uuid::isValid($condition->getValue())) {
265265
$this->httpBadRequest('The given filter id is not a valid UUID');
266266
}
267267

library/Notifications/Common/PsrLogger.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
class PsrLogger implements LoggerInterface
1919
{
20-
2120
use LoggerTrait;
2221

2322
/**

0 commit comments

Comments
 (0)