Skip to content

Commit 6c0d56f

Browse files
committed
chore: install rector and run it with empty ruleset
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 69ccc81 commit 6c0d56f

8 files changed

Lines changed: 661 additions & 18 deletions

File tree

lib/Controller/ApiController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public function updateForm(int $formId, array $keyValuePairs): DataResponse {
335335
}
336336

337337
// Process file unlinking
338-
if (key_exists('fileId', $keyValuePairs) && key_exists('fileFormat', $keyValuePairs) && !isset($keyValuePairs['fileFormat'])) {
338+
if (array_key_exists('fileId', $keyValuePairs) && array_key_exists('fileFormat', $keyValuePairs) && !isset($keyValuePairs['fileFormat'])) {
339339
$form->setFileId(null);
340340
$form->setFileFormat(null);
341341
}
@@ -673,24 +673,24 @@ public function updateQuestion(int $formId, int $questionId, array $keyValuePair
673673
}
674674

675675
// Don't allow empty array
676-
if (sizeof($keyValuePairs) === 0) {
676+
if (count($keyValuePairs) === 0) {
677677
$this->logger->info('Empty keyValuePairs, will not update.');
678678
throw new OCSBadRequestException('This form is archived and can not be modified');
679679
}
680680

681681
//Don't allow to change id or formId
682-
if (key_exists('id', $keyValuePairs) || key_exists('formId', $keyValuePairs)) {
682+
if (array_key_exists('id', $keyValuePairs) || array_key_exists('formId', $keyValuePairs)) {
683683
$this->logger->debug('Not allowed to update \'id\' or \'formId\'');
684684
throw new OCSForbiddenException('Not allowed to update \'id\' or \'formId\'');
685685
}
686686

687687
// Don't allow to reorder here
688-
if (key_exists('order', $keyValuePairs)) {
688+
if (array_key_exists('order', $keyValuePairs)) {
689689
$this->logger->debug('Key \'order\' is not allowed on updateQuestion. Please use reorderQuestions() to change order.');
690690
throw new OCSForbiddenException('Please use reorderQuestions() to change order');
691691
}
692692

693-
if (key_exists('extraSettings', $keyValuePairs) && !$this->formsService->areExtraSettingsValid($keyValuePairs['extraSettings'], $question->getType())) {
693+
if (array_key_exists('extraSettings', $keyValuePairs) && !$this->formsService->areExtraSettingsValid($keyValuePairs['extraSettings'], $question->getType())) {
694694
throw new OCSBadRequestException('Invalid extraSettings, will not update.');
695695
}
696696

@@ -829,7 +829,7 @@ public function reorderQuestions(int $formId, array $newOrder): DataResponse {
829829

830830
// Check if all questions are given in Array.
831831
$questions = $this->questionMapper->findByForm($formId);
832-
if (sizeof($questions) !== sizeof($newOrder)) {
832+
if (count($questions) !== count($newOrder)) {
833833
$this->logger->debug('The length of the given array does not match the number of stored questions');
834834
throw new OCSBadRequestException('The length of the given array does not match the number of stored questions');
835835
}
@@ -1023,13 +1023,13 @@ public function updateOption(int $formId, int $questionId, int $optionId, array
10231023
}
10241024

10251025
// Don't allow empty array
1026-
if (sizeof($keyValuePairs) === 0) {
1026+
if (count($keyValuePairs) === 0) {
10271027
$this->logger->info('Empty keyValuePairs, will not update');
10281028
throw new OCSForbiddenException('Empty keyValuePairs, will not update');
10291029
}
10301030

10311031
//Don't allow to change id or questionId
1032-
if (key_exists('id', $keyValuePairs) || key_exists('questionId', $keyValuePairs)) {
1032+
if (array_key_exists('id', $keyValuePairs) || array_key_exists('questionId', $keyValuePairs)) {
10331033
$this->logger->debug('Not allowed to update id or questionId');
10341034
throw new OCSForbiddenException('Not allowed to update id or questionId');
10351035
}
@@ -1157,7 +1157,7 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder, ?s
11571157

11581158
$options = $this->optionMapper->findByQuestion($questionId, $optionType);
11591159

1160-
if (sizeof($options) !== sizeof($newOrder)) {
1160+
if (count($options) !== count($newOrder)) {
11611161
$this->logger->debug('The length of the given array does not match the number of stored options');
11621162
throw new OCSBadRequestException('The length of the given array does not match the number of stored options');
11631163
}
@@ -1925,7 +1925,7 @@ private function checkArchivePermission(Form $form, string $currentUserId, array
19251925
$isOwner = $currentUserId === $form->getOwnerId();
19261926

19271927
// If the request contains 'state' it must be the only key
1928-
if (sizeof($keyValuePairs) !== 1) {
1928+
if (count($keyValuePairs) !== 1) {
19291929
$this->logger->debug('State may only be changed on its own');
19301930
throw new OCSForbiddenException('State may only be changed on its own');
19311931
}
@@ -1944,19 +1944,19 @@ private function checkArchivePermission(Form $form, string $currentUserId, array
19441944
}
19451945

19461946
private function isLockingRequest(array $keyValuePairs): bool {
1947-
return sizeof($keyValuePairs) === 1
1947+
return count($keyValuePairs) === 1
19481948
&& array_key_exists('lockedUntil', $keyValuePairs)
19491949
&& $keyValuePairs['lockedUntil'] === 0;
19501950
}
19511951

19521952
private function isUnlockingRequest(array $keyValuePairs): bool {
1953-
return sizeof($keyValuePairs) === 1
1953+
return count($keyValuePairs) === 1
19541954
&& array_key_exists('lockedUntil', $keyValuePairs)
19551955
&& is_null($keyValuePairs['lockedUntil']);
19561956
}
19571957

19581958
private function isOwnerTransferRequest(array $keyValuePairs): bool {
1959-
return sizeof($keyValuePairs) === 1 && key_exists('ownerId', $keyValuePairs);
1959+
return count($keyValuePairs) === 1 && array_key_exists('ownerId', $keyValuePairs);
19601960
}
19611961

19621962
/**

lib/Controller/ShareApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function updateShare(int $formId, int $shareId, array $keyValuePairs): Da
252252
}
253253

254254
// Don't allow empty array
255-
if (sizeof($keyValuePairs) === 0) {
255+
if (count($keyValuePairs) === 0) {
256256
$this->logger->info('Empty keyValuePairs, will not update.');
257257
throw new OCSForbiddenException('Empty keyValuePairs, will not update');
258258
}

lib/Service/ConfigService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function canCreateForms(): bool {
123123

124124
$userGroups = $this->groupManager->getUserGroupIds($this->currentUser);
125125
// If array intersection is not empty, user is member of any allowed group.
126-
if (sizeof(array_intersect($userGroups, $this->getUnformattedCreationAllowedGroups()))) {
126+
if (count(array_intersect($userGroups, $this->getUnformattedCreationAllowedGroups()))) {
127127
return true;
128128
}
129129

rector.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/lib',
10+
__DIR__ . '/tests',
11+
])
12+
// uncomment to reach your current PHP version
13+
// ->withPhpSets()
14+
->withTypeCoverageLevel(0)
15+
->withDeadCodeLevel(0)
16+
->withCodeQualityLevel(0);

tests/Integration/Api/ApiV3Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public function testCreateNewQuestion(array $expected): void {
827827
// Check formId & order
828828
$this->assertEquals($this->testForms[0]['id'], $data['formId']);
829829
unset($data['formId']);
830-
$this->assertEquals(sizeof($this->testForms[0]['questions']), $data['order']);
830+
$this->assertEquals(count($this->testForms[0]['questions']), $data['order']);
831831
unset($data['order']);
832832
unset($data['id']);
833833

@@ -1567,7 +1567,7 @@ public static function dataDeleteSingleSubmission() {
15671567
* @param array $submissionsExpected
15681568
*/
15691569
public function testDeleteSingleSubmission(array $submissionsExpected) {
1570-
$submissionsExpected['filteredSubmissionsCount'] = $submissionsExpected['filteredSubmissionsCount'] - 1;
1570+
$submissionsExpected['filteredSubmissionsCount'] -= 1;
15711571
$resp = $this->http->request('DELETE', "api/v3/forms/{$this->testForms[0]['id']}/submissions/{$this->testForms[0]['submissions'][0]['id']}");
15721572
$data = $this->OcsResponse2Data($resp);
15731573

tests/Unit/FormsMigratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function testExport(string $expectedJson) {
235235

236236
$exportDestination->expects($this->once())
237237
->method('addFileContents')
238-
->will($this->returnCallback(function ($path, $jsonData) use ($expectedJson) {
238+
->will($this->returnCallback(function ($path, $jsonData) use ($expectedJson): void {
239239
$this->assertJsonStringEqualsJsonString($expectedJson, $jsonData);
240240
}));
241241
$this->formsMigrator->export($user, $exportDestination, $output);

vendor-bin/rector/composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require-dev": {
3+
"rector/rector": "^2.4",
4+
"nextcloud/rector": "^0.5.1"
5+
}
6+
}

0 commit comments

Comments
 (0)