Skip to content

Commit

Permalink
add config for the psalm to check unused variables and parameter
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
  • Loading branch information
nabim777 committed Jun 26, 2024
1 parent c83e5fc commit a460716
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private function setIntegrationConfig(array $values): array {
];
// if values contains a key that is not in the allowedKeys array,
// return a response with status code 400 and an error message
foreach ($values as $key => $value) {
foreach (array_keys($values) as $key) {
if (!in_array($key, $allowedKeys)) {
throw new InvalidArgumentException('Invalid key');
}
Expand Down
1 change: 0 additions & 1 deletion lib/Controller/DirectUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public function directUpload(string $token):DataResponse {
throw new NotFoundException('invalid token');
}
$tokenInfo = $this->directUploadService->getTokenInfo($token);
$fileId = null;
$directUploadFile = $this->request->getUploadedFile('file');
if (empty($directUploadFile)) {
throw new OpenprojectFileNotUploadedException(
Expand Down
5 changes: 2 additions & 3 deletions lib/Service/OpenProjectAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public function searchWorkPackage(
bool $onlyLinkableWorkPackages = true,
int $workPackageId = null
): array {
$resultsById = [];
$filters = [];

// search by description
Expand Down Expand Up @@ -567,7 +566,7 @@ public static function validateIntegrationSetupInformation(?array $values, bool
throw new InvalidArgumentException('invalid data');
}
} else {
foreach ($values as $key => $value) {
foreach (array_keys($values) as $key) {
if (!in_array($key, $opKeys)) {
throw new InvalidArgumentException('invalid key');
}
Expand Down Expand Up @@ -724,7 +723,7 @@ public function linkWorkPackageToFile(
'workpackageId',
'fileinfo'
];
foreach ($values as $key => $value) {
foreach (array_keys($values) as $key) {
if (!in_array($key, $allowedKeys)) {
throw new InvalidArgumentException('invalid key');
}
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config"
findUnusedBaselineEntry="false"
findUnusedCode="false"
findUnusedVariablesAndParams="true"
autoloader="bootstrap.php"
>
<projectFiles>
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ public function theDataOfTheOCSResponseShouldMatch(
PyStringNode $schemaString
): void {
$responseAsJson = json_decode($this->response->getBody()->getContents());
$responseAsJson = $responseAsJson->ocs->data;
$_responseAsJson = $responseAsJson->ocs->data;
JsonAssertions::assertJsonDocumentMatchesSchema(
$responseAsJson,
$_responseAsJson,
$this->getJSONSchema($schemaString)
);
}
Expand All @@ -564,9 +564,9 @@ public function theDataOfTheOCSResponseShouldMatch(
public function theDataOfTheResponseShouldMatch(
PyStringNode $schemaString
): void {
$responseAsJson = json_decode($this->response->getBody()->getContents());
$_responseAsJson = json_decode($this->response->getBody()->getContents());
JsonAssertions::assertJsonDocumentMatchesSchema(
$responseAsJson,
$_responseAsJson,
$this->getJSONSchema($schemaString)
);
}
Expand Down
6 changes: 2 additions & 4 deletions tests/lib/Controller/ConfigControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,7 @@ public function testOauthNoAccessTokenInResponse($oauthResponse, $expectedErrorM
['testUser', 'integration_openproject', 'oauth_connection_result', 'error'],
['testUser', 'integration_openproject', 'oauth_connection_error_message', $expectedErrorMessage],
);
/**
* @var ConfigController
*/

$configController = new ConfigController(
'integration_openproject',
$this->createMock(IRequest::class),
Expand Down Expand Up @@ -837,7 +835,7 @@ public function checkForUsersCountBeforeTest($expectedCount = 1): IUserManager {
$actualCount = 1;
$userManager = \OC::$server->getUserManager();
$count = 0;
$function = function (IUser $user) use (&$count) {
$function = function () use (&$count) {
$count++;
return null;
};
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2804,10 +2804,9 @@ public function testMarkAllNotificationsOfANotExistingWorkPackageAsReadPact(): v
->with($consumerRequest)
->willRespondWith($providerResponse);


$service = $this->getOpenProjectAPIService();
$this->expectException(OpenprojectErrorException::class);
$result = $service->markAllNotificationsOfWorkPackageAsRead(
$service->markAllNotificationsOfWorkPackageAsRead(
789,
'testUser'
);
Expand Down

0 comments on commit a460716

Please sign in to comment.