Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrade dev tools and apply upgraded rector #231

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"test:unit": "vendor/bin/phpunit -c tests/phpunit.xml",
"psalm": "psalm --no-cache --threads=$(nproc)",
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm:update-baseline": "psalm --threads=1 --update-baseline"
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
"rector": "rector && composer cs:fix"
},
"autoload-dev": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions lib/Command/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

class Add extends Base {
public function __construct(
private Configuration $configurationService,
private ?ConnectionImporter $connectionImporter = null,
private readonly Configuration $configurationService,
private readonly ?ConnectionImporter $connectionImporter = null,
) {
parent::__construct();
}
Expand Down Expand Up @@ -328,7 +328,7 @@ protected function askImport(InputInterface $input, OutputInterface $output): vo
$list,
count($list) - 1
);
$choice = $helper->ask($input, $output, $question);
$choice = (string)$helper->ask($input, $output, $question);
if ($choice === 'None') {
return;
}
Expand All @@ -354,7 +354,7 @@ protected function askStringToArray(string $subject, string $label, InputInterfa

$q = new Question($label);
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$values = array_map('trim', explode(',', $helper->ask($input, $output, $q)));
$values = array_map('trim', explode(',', (string)$helper->ask($input, $output, $q)));

$input->setOption($subject, $values);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class Delete extends Base {
public function __construct(
private Configuration $configurationService,
private readonly Configuration $configurationService,
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private function stringNormalizer(?string $input): string {
}

private function autoCompleteNormalizer($input, array $autoComplete) {
return array_change_key_case(array_flip($autoComplete))[strtolower($input)] ?? array_pop($autoComplete);
return array_change_key_case(array_flip($autoComplete))[strtolower((string)$input)] ?? array_pop($autoComplete);
}

private function uIntNormalizer(?string $input): ?int {
Expand Down Expand Up @@ -286,7 +286,7 @@ private function askStringToArray(string $subject, string $label, InputInterface

$q = new Question($label);
$q->setNormalizer(fn ($input): string => $this->stringNormalizer($input));
$values = array_map('trim', explode(',', $helper->ask($input, $output, $q)));
$values = array_map('trim', explode(',', (string)$helper->ask($input, $output, $q)));

$input->setOption($subject, $values);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/ListConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class ListConfigs extends Base {
public function __construct(
private Configuration $configurationService,
private readonly Configuration $configurationService,
) {
parent::__construct();
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Controller/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
class ContactsController extends Controller {
public function __construct(
IRequest $request,
private AddressBookProvider $addressBookProvider,
private IManager $contactsManager,
private IUserSession $userSession,
private LoggerInterface $logger,
private IURLGenerator $urlGenerator,
private PhotoService $photoService,
private IFactory $l10nFactory,
private readonly AddressBookProvider $addressBookProvider,
private readonly IManager $contactsManager,
private readonly IUserSession $userSession,
private readonly LoggerInterface $logger,
private readonly IURLGenerator $urlGenerator,
private readonly PhotoService $photoService,
private readonly IFactory $l10nFactory,
) {
parent::__construct(Application::APPID, $request);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Http/InlineImageResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class InlineImageResponse extends Response implements ICallbackResponse {
public function __construct(Image $image) {
parent::__construct();

$etag = md5($image->data());
$ext = '.' . explode('/', $image->dataMimeType())[1];
$etag = md5((string)$image->data());
$ext = '.' . explode('/', (string)$image->dataMimeType())[1];

$this->setETag($etag);
$this->setStatus(Http::STATUS_OK);
Expand All @@ -55,7 +55,7 @@ public function __construct(Image $image) {
*/
public function callback(IOutput $output) {
if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
$output->setHeader('Content-Length: ' . strlen($this->image->data()));
$output->setHeader('Content-Length: ' . strlen((string)$this->image->data()));
$output->setOutput($this->image->data());
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Model/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getETag() {
* @inheritDoc
*/
public function getSize() {
return \strlen($this->get());
return \strlen((string)$this->get());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/Provider/ImportProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
use OCP\IURLGenerator;

class ImportProvider implements IProvider {
private CsrfTokenManager $tokenManager;
private readonly CsrfTokenManager $tokenManager;

public function __construct(
private IActionFactory $actionFactory,
private IURLGenerator $urlGenerator,
private IL10N $l,
private readonly IActionFactory $actionFactory,
private readonly IURLGenerator $urlGenerator,
private readonly IL10N $l,
CsrfTokenManager $tokenManager,
private IAppManager $appManager,
private readonly IAppManager $appManager,
) {
$this->tokenManager = $tokenManager;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/AddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
use Sabre\DAV\PropPatch;

class AddressBook extends ExternalAddressBook {
private ICardBackend $cardBackend;
private readonly ICardBackend $cardBackend;

public function __construct(
private string $principalUri,
private readonly string $principalUri,
ICardBackend $cardBackend,
) {
parent::__construct(Application::APPID, $cardBackend->getURI());
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/AddressBookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

class AddressBookProvider implements IAddressBookProvider {
public function __construct(
private Configuration $configurationService,
private LdapQuerentFactory $ldapQuerentFactory,
private ContactsAddressBookFactory $contactsAddressBookFactory,
private readonly Configuration $configurationService,
private readonly LdapQuerentFactory $ldapQuerentFactory,
private readonly ContactsAddressBookFactory $contactsAddressBookFactory,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Configuration {
protected array $configurations = [];

public function __construct(
private IConfig $config,
private ICredentialsManager $credentialsManager,
private readonly IConfig $config,
private readonly ICredentialsManager $credentialsManager,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ConnectionImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use OutOfBoundsException;

class ConnectionImporter {
private Helper $ldapHelper;
private readonly Helper $ldapHelper;

public function __construct(Helper $ldapHelper) {
$this->ldapHelper = $ldapHelper;
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/ContactsAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
use OCP\IURLGenerator;

class ContactsAddressBook implements IAddressBook {
private CsrfTokenManager $tokenManager;
private readonly CsrfTokenManager $tokenManager;

public const DAV_PROPERTY_SOURCE = 'X-NC_LDAP_CONTACTS_ID';

public function __construct(
private ICardBackend $cardBackend,
private IConfig $config,
private IURLGenerator $urlGenerator,
private readonly ICardBackend $cardBackend,
private readonly IConfig $config,
private readonly IURLGenerator $urlGenerator,
CsrfTokenManager $tokenManager,
private PhotoService $photoService,
private ?string $principalURI = null,
private readonly PhotoService $photoService,
private readonly ?string $principalURI = null,
) {
$this->tokenManager = $tokenManager;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public function search($pattern, $searchProperties, $options) {
if (isset($record['PHOTO'])) {
try {
// "data:image/<submime>;base64," is prefixed
$imageData = substr($record['PHOTO'][0], strpos($record['PHOTO'][0], ','));
$imageData = substr((string)$record['PHOTO'][0], strpos((string)$record['PHOTO'][0], ','));
$this->photoService->store($this->cardBackend->getURI(), $record['URI'], $imageData);
$photoUrl = $this->urlGenerator->linkToRouteAbsolute(Application::APPID . '.contacts.photo',
[
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/ContactsAddressBookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
use OCP\IURLGenerator;

class ContactsAddressBookFactory {
private CsrfTokenManager $tokenManager;
private readonly CsrfTokenManager $tokenManager;

public function __construct(
private IConfig $config,
private IURLGenerator $urlGenerator,
private readonly IConfig $config,
private readonly IURLGenerator $urlGenerator,
CsrfTokenManager $tokenManager,
private PhotoService $photoService,
private readonly PhotoService $photoService,
) {
$this->tokenManager = $tokenManager;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ICardBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getDisplayName(): string;
/**
* @throws RecordNotFound
*/
public function getCard($name): Card;
public function getCard(string $name): Card;

/**
* @return Card[]
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/LdapCardBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

class LdapCardBackend implements ICardBackend {
public function __construct(
private LdapQuerent $ldapQuerent,
private ConfigurationModel $configuration,
private readonly LdapQuerent $ldapQuerent,
private readonly ConfigurationModel $configuration,
) {
}

Expand All @@ -49,7 +49,7 @@ public function getDisplayName(): string {
/**
* @throws RecordNotFound
*/
public function getCard($name): Card {
public function getCard(string $name): Card {
$record = $this->ldapQuerent->fetchOne(base64_decode($name));
return $this->entryToCard($record);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/LdapEntryToVcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function convert(Entry $record, ConfigurationModel $configuration)
$mappings = array_merge(self::DEFAULT_MAPPING, $configuration->getAttributeMapping());
foreach ($mappings as $vcProperty => $lAttributes) {
$propertyName = strtoupper($vcProperty);
$lAttributes = explode(',', $lAttributes);
$lAttributes = explode(',', (string)$lAttributes);
foreach ($lAttributes as $lAttribute) {
$lAttribute = trim($lAttribute);
if ($lAttribute === 'dn') {
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/LdapQuerent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class LdapQuerent {
protected ?Ldap $ldap = null;

public function __construct(
private ConfigurationModel $configuration,
private LoggerInterface $logger,
private readonly ConfigurationModel $configuration,
private readonly LoggerInterface $logger,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/LdapQuerentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class LdapQuerentFactory {
public function __construct(
private LoggerInterface $logger,
private readonly LoggerInterface $logger,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Service/PhotoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class PhotoService {
public function __construct(
private ICacheFactory $cacheFactory,
private readonly ICacheFactory $cacheFactory,
) {
}

Expand All @@ -51,7 +51,7 @@ public function store(string $sourceId, string $entryId, string $imageData): boo
}

$image = $this->prepareImage($imageData);
$cache->set($key, base64_encode($image->data()), 3600);
$cache->set($key, base64_encode((string)$image->data()), 3600);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
phpVersion="8.0"
phpVersion="8.1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
3 changes: 0 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@
->withTypeCoverageLevel(10)
->withImportNames(importShortClasses: false)
->withSets([
NextcloudSets::NEXTCLOUD_25,
NextcloudSets::NEXTCLOUD_26,
NextcloudSets::NEXTCLOUD_27,
NextcloudSets::NEXTCLOUD_ALL,
]);
2 changes: 1 addition & 1 deletion vendor-bin/rector/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require-dev": {
"rector/rector": "^1.2",
"nextcloud/rector": "^0.1.0"
"nextcloud/rector": "^0.2.1"
},
"config": {
"platform": {
Expand Down
Loading
Loading