chore: Import all names and increase type coverage with rector

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2024-09-19 10:17:16 +02:00
Родитель b652dbdecd
Коммит cf0a1c6037
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A3E2F658B28C760A
6 изменённых файлов: 31 добавлений и 27 удалений

Просмотреть файл

@ -144,7 +144,7 @@ class Add extends Base {
$helper = $this->getHelper('question');
$q = new Question('Address book display name: ');
$q->setNormalizer(fn (string $input) => $this->stringNormalizer($input));
$q->setNormalizer(fn (string $input): string => $this->stringNormalizer($input));
$input->setArgument('addressBookName', $helper->ask($input, $output, $q));
}
@ -343,7 +343,7 @@ class Add extends Base {
$helper = $this->getHelper('question');
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$input->setOption($subject, $helper->ask($input, $output, $q));
}
@ -353,7 +353,7 @@ class Add extends Base {
$helper = $this->getHelper('question');
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$values = array_map('trim', explode(',', $helper->ask($input, $output, $q)));
$input->setOption($subject, $values);
@ -374,7 +374,7 @@ class Add extends Base {
$helper = $this->getHelper('question');
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->posNumberNormalizer($input));
$q->setNormalizer(fn ($input): ?int => $this->posNumberNormalizer($input));
$input->setOption($subject, $helper->ask($input, $output, $q));
}
@ -391,13 +391,13 @@ class Add extends Base {
$isFollowUp = false;
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
while (($value = $helper->ask($input, $output, $q)) !== '') {
$values[] = $value;
if (!$isFollowUp) {
$q = new Question($followUpLabel);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$isFollowUp = true;
}
}

Просмотреть файл

@ -70,21 +70,21 @@ class Edit extends Base {
'type' => 'string',
'currentLabel' => sprintf('Address book display name: %s.', $model->getAddressBookDisplayName()),
'newLabel' => ' New address book display name: ',
'setter' => fn ($v) => $model->setAddressBookDisplayName($v),
'setter' => fn ($v): ConfigurationModel => $model->setAddressBookDisplayName($v),
];
yield [
'key' => 'host',
'type' => 'string',
'currentLabel' => sprintf('LDAP hostname: %s.', $model->getHost()),
'newLabel' => ' New LDAP hostname: ',
'setter' => fn ($v) => $model->setHost($v),
'setter' => fn ($v): ConfigurationModel => $model->setHost($v),
];
yield [
'key' => 'port',
'type' => 'uint',
'currentLabel' => sprintf('LDAP port: %u.', $model->getPort()),
'newLabel' => ' New LDAP port: ',
'setter' => fn ($v) => $model->setPort($v),
'setter' => fn ($v): ConfigurationModel => $model->setPort($v),
];
yield [
'key' => 'trans_enc',
@ -92,28 +92,28 @@ class Edit extends Base {
'currentLabel' => sprintf('Transport encryption: %s.', $model->getTEnc()),
'newLabel' => ' New transport encryption (StartTLS, LDAPS, none): ',
'autoComplete' => ['tls' => 'StartTLS', 'ssl' => 'LDAPS', 'none' => 'none'],
'setter' => fn ($v) => $model->setTEnc($v),
'setter' => fn ($v): ConfigurationModel => $model->setTEnc($v),
];
yield [
'key' => 'bindDN',
'type' => 'string',
'currentLabel' => sprintf('LDAP bind DN: %s.', $model->getAgentDn()),
'newLabel' => ' New LDAP bind DN: ',
'setter' => fn ($v) => $model->setAgentDn($v),
'setter' => fn ($v): ConfigurationModel => $model->setAgentDn($v),
];
yield [
'key' => 'bindPwd',
'type' => 'string',
'currentLabel' => 'LDAP bind password.',
'newLabel' => ' New LDAP bind password: ',
'setter' => fn ($v) => $model->setAgentPassword($v),
'setter' => fn ($v): ConfigurationModel => $model->setAgentPassword($v),
];
yield [
'key' => 'filter',
'type' => 'string',
'currentLabel' => sprintf('LDAP contacts filter: %s.', $model->getFilter()),
'newLabel' => ' New LDAP contacts filter: ',
'setter' => fn ($v) => $model->setFilter($v),
'setter' => fn ($v): ConfigurationModel => $model->setFilter($v),
];
yield [
'key' => 'base',
@ -121,14 +121,14 @@ class Edit extends Base {
'currentLabel' => sprintf('LDAP contacts bases: %s.', implode('; ', $model->getBases())),
'newLabel' => ' New LDAP contacts bases: ',
'followUpLabel' => ' additional base (leave empty to continue): ',
'setter' => fn ($v) => $model->setBases($v),
'setter' => fn ($v): ConfigurationModel => $model->setBases($v),
];
yield [
'key' => 'attrs',
'type' => 'cs-string',
'currentLabel' => sprintf('LDAP contacts search attributes: %s.', implode(', ', $model->getSearchAttributes())),
'newLabel' => ' New LDAP search attributes (comma separated): ',
'setter' => fn ($v) => $model->setSearchAttributes($v),
'setter' => fn ($v): ConfigurationModel => $model->setSearchAttributes($v),
];
yield [
'key' => 'mapping',
@ -242,7 +242,7 @@ class Edit extends Base {
$q->setAutocompleterValues(array_values($autoComplete));
$q->setNormalizer(fn ($input) => $this->autoCompleteNormalizer($input, $autoComplete));
} else {
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
}
$input->setOption($subject, $helper->ask($input, $output, $q));
@ -253,7 +253,7 @@ class Edit extends Base {
$helper = $this->getHelper('question');
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->uIntNormalizer($input));
$q->setNormalizer(fn ($input): ?int => $this->uIntNormalizer($input));
$input->setOption($subject, $helper->ask($input, $output, $q));
}
@ -266,13 +266,13 @@ class Edit extends Base {
$isFollowUp = false;
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
while (($value = $helper->ask($input, $output, $q)) !== '') {
$values[] = $value;
if (!$isFollowUp) {
$q = new Question($followUpLabel);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$isFollowUp = true;
}
}
@ -285,7 +285,7 @@ class Edit extends Base {
$helper = $this->getHelper('question');
$q = new Question($label);
$q->setNormalizer(fn ($input) => $this->stringNormalizer($input));
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$values = array_map('trim', explode(',', $helper->ask($input, $output, $q)));
$input->setOption($subject, $values);
@ -297,7 +297,7 @@ class Edit extends Base {
$helper = $this->getHelper('question');
$q = new Question($label . ' Modify (y/N)? ');
$q->setNormalizer(fn ($input) => $this->yesOrNoNormalizer($input ?? 'N'));
$q->setNormalizer(fn ($input): ?bool => $this->yesOrNoNormalizer($input ?? 'N'));
$wantEdit = $helper->ask($input, $output, $q);
} while ($wantEdit === null);

Просмотреть файл

@ -52,7 +52,7 @@ class AddressBookProvider implements IAddressBookProvider {
public function fetchAllForAddressBookHome(string $principalUri): array {
$configs = array_filter(
$this->configurationService->getAll(),
fn (ConfigurationModel $config) => $config->isEnabled()
fn (ConfigurationModel $config): bool => $config->isEnabled()
);
$addressBooks = [];
@ -109,7 +109,7 @@ class AddressBookProvider implements IAddressBookProvider {
public function fetchAllForContactsStore(): array {
$configs = array_filter(
$this->configurationService->getAll(),
fn (ConfigurationModel $config) => $config->isEnabled()
fn (ConfigurationModel $config): bool => $config->isEnabled()
);
$addressBooks = [];

Просмотреть файл

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace OCA\LDAPContactsBackend\Service;
use OCA\User_LDAP\Configuration;
use OCA\LDAPContactsBackend\Model\LDAPBaseConfiguration;
use OCA\User_LDAP\Helper;
use OutOfBoundsException;
@ -42,7 +43,7 @@ class ConnectionImporter {
throw new OutOfBoundsException('Specified configuration not available');
}
$c = new \OCA\User_LDAP\Configuration($prefix);
$c = new Configuration($prefix);
$m = new LDAPBaseConfiguration();
$m
->setPort($c->ldapPort)
@ -62,7 +63,7 @@ class ConnectionImporter {
$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
$i = 0;
foreach ($prefixes as $prefix) {
$c = new \OCA\User_LDAP\Configuration($prefix);
$c = new Configuration($prefix);
$m = new LDAPBaseConfiguration();
$m
->setPrefix($prefix)

Просмотреть файл

@ -17,7 +17,8 @@ return RectorConfig::configure()
__DIR__ . '/tests',
])
->withPhpSets(php81: true)
->withTypeCoverageLevel(0)
->withTypeCoverageLevel(10)
->withImportNames(importShortClasses: false)
->withSets([
NextcloudSets::NEXTCLOUD_25,
NextcloudSets::NEXTCLOUD_26,

Просмотреть файл

@ -1,6 +1,8 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @copyright Copyright (c) 2020 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
@ -29,7 +31,7 @@ if (!defined('PHPUNIT_RUN')) {
require_once __DIR__ . '/../../../lib/base.php';
\OC::$loader->addValidRoot(\OC::$SERVERROOT . '/tests');
if (!class_exists(\PHPUnit\Framework\TestCase::class)) {
if (!class_exists(TestCase::class)) {
require_once('PHPUnit/Autoload.php');
}