diff --git a/composer.json b/composer.json index d2c3378..fee2287 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/lib/Command/Add.php b/lib/Command/Add.php index 559c103..4bbf972 100644 --- a/lib/Command/Add.php +++ b/lib/Command/Add.php @@ -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(); } @@ -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; } @@ -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); } diff --git a/lib/Command/Delete.php b/lib/Command/Delete.php index b49ff79..a2e4991 100644 --- a/lib/Command/Delete.php +++ b/lib/Command/Delete.php @@ -33,7 +33,7 @@ class Delete extends Base { public function __construct( - private Configuration $configurationService, + private readonly Configuration $configurationService, ) { parent::__construct(); } diff --git a/lib/Command/Edit.php b/lib/Command/Edit.php index 445f4ca..e3bdc27 100644 --- a/lib/Command/Edit.php +++ b/lib/Command/Edit.php @@ -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 { @@ -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); } diff --git a/lib/Command/ListConfigs.php b/lib/Command/ListConfigs.php index 637e06a..86f4bd9 100644 --- a/lib/Command/ListConfigs.php +++ b/lib/Command/ListConfigs.php @@ -33,7 +33,7 @@ class ListConfigs extends Base { public function __construct( - private Configuration $configurationService, + private readonly Configuration $configurationService, ) { parent::__construct(); } diff --git a/lib/Controller/ContactsController.php b/lib/Controller/ContactsController.php index bb36cff..1494ecf 100644 --- a/lib/Controller/ContactsController.php +++ b/lib/Controller/ContactsController.php @@ -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); } diff --git a/lib/Http/InlineImageResponse.php b/lib/Http/InlineImageResponse.php index a0b0536..9a57cb4 100644 --- a/lib/Http/InlineImageResponse.php +++ b/lib/Http/InlineImageResponse.php @@ -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); @@ -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()); } } diff --git a/lib/Model/Card.php b/lib/Model/Card.php index 53af724..3333e19 100644 --- a/lib/Model/Card.php +++ b/lib/Model/Card.php @@ -71,7 +71,7 @@ public function getETag() { * @inheritDoc */ public function getSize() { - return \strlen($this->get()); + return \strlen((string)$this->get()); } /** diff --git a/lib/Provider/ImportProvider.php b/lib/Provider/ImportProvider.php index 538004c..99a6114 100644 --- a/lib/Provider/ImportProvider.php +++ b/lib/Provider/ImportProvider.php @@ -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; } diff --git a/lib/Service/AddressBook.php b/lib/Service/AddressBook.php index 9eabeb1..94138ee 100644 --- a/lib/Service/AddressBook.php +++ b/lib/Service/AddressBook.php @@ -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()); diff --git a/lib/Service/AddressBookProvider.php b/lib/Service/AddressBookProvider.php index d71202f..2832637 100644 --- a/lib/Service/AddressBookProvider.php +++ b/lib/Service/AddressBookProvider.php @@ -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, ) { } diff --git a/lib/Service/Configuration.php b/lib/Service/Configuration.php index f403d7c..d52f607 100644 --- a/lib/Service/Configuration.php +++ b/lib/Service/Configuration.php @@ -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, ) { } diff --git a/lib/Service/ConnectionImporter.php b/lib/Service/ConnectionImporter.php index 9c53066..7b938d3 100644 --- a/lib/Service/ConnectionImporter.php +++ b/lib/Service/ConnectionImporter.php @@ -31,7 +31,7 @@ use OutOfBoundsException; class ConnectionImporter { - private Helper $ldapHelper; + private readonly Helper $ldapHelper; public function __construct(Helper $ldapHelper) { $this->ldapHelper = $ldapHelper; diff --git a/lib/Service/ContactsAddressBook.php b/lib/Service/ContactsAddressBook.php index a245820..ccb1994 100644 --- a/lib/Service/ContactsAddressBook.php +++ b/lib/Service/ContactsAddressBook.php @@ -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; } @@ -83,7 +83,7 @@ public function search($pattern, $searchProperties, $options) { if (isset($record['PHOTO'])) { try { // "data:image/;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', [ diff --git a/lib/Service/ContactsAddressBookFactory.php b/lib/Service/ContactsAddressBookFactory.php index 58ca909..51d7871 100644 --- a/lib/Service/ContactsAddressBookFactory.php +++ b/lib/Service/ContactsAddressBookFactory.php @@ -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; } diff --git a/lib/Service/ICardBackend.php b/lib/Service/ICardBackend.php index 579ffb9..f1c435b 100644 --- a/lib/Service/ICardBackend.php +++ b/lib/Service/ICardBackend.php @@ -36,7 +36,7 @@ public function getDisplayName(): string; /** * @throws RecordNotFound */ - public function getCard($name): Card; + public function getCard(string $name): Card; /** * @return Card[] diff --git a/lib/Service/LdapCardBackend.php b/lib/Service/LdapCardBackend.php index 1772a7c..1f1dfbc 100644 --- a/lib/Service/LdapCardBackend.php +++ b/lib/Service/LdapCardBackend.php @@ -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, ) { } @@ -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); } diff --git a/lib/Service/LdapEntryToVcard.php b/lib/Service/LdapEntryToVcard.php index f1fb0da..454cb26 100644 --- a/lib/Service/LdapEntryToVcard.php +++ b/lib/Service/LdapEntryToVcard.php @@ -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') { diff --git a/lib/Service/LdapQuerent.php b/lib/Service/LdapQuerent.php index 2045b0d..e78793f 100644 --- a/lib/Service/LdapQuerent.php +++ b/lib/Service/LdapQuerent.php @@ -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, ) { } diff --git a/lib/Service/LdapQuerentFactory.php b/lib/Service/LdapQuerentFactory.php index 15d298c..afc67a4 100644 --- a/lib/Service/LdapQuerentFactory.php +++ b/lib/Service/LdapQuerentFactory.php @@ -30,7 +30,7 @@ class LdapQuerentFactory { public function __construct( - private LoggerInterface $logger, + private readonly LoggerInterface $logger, ) { } diff --git a/lib/Service/PhotoService.php b/lib/Service/PhotoService.php index 3ff8d65..24a71c4 100644 --- a/lib/Service/PhotoService.php +++ b/lib/Service/PhotoService.php @@ -33,7 +33,7 @@ class PhotoService { public function __construct( - private ICacheFactory $cacheFactory, + private readonly ICacheFactory $cacheFactory, ) { } @@ -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; } diff --git a/psalm.xml b/psalm.xml index a37f49f..c24e33e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ withTypeCoverageLevel(10) ->withImportNames(importShortClasses: false) ->withSets([ - NextcloudSets::NEXTCLOUD_25, - NextcloudSets::NEXTCLOUD_26, NextcloudSets::NEXTCLOUD_27, - NextcloudSets::NEXTCLOUD_ALL, ]); diff --git a/vendor-bin/rector/composer.json b/vendor-bin/rector/composer.json index 8e900fb..9a2a54d 100644 --- a/vendor-bin/rector/composer.json +++ b/vendor-bin/rector/composer.json @@ -1,7 +1,7 @@ { "require-dev": { "rector/rector": "^1.2", - "nextcloud/rector": "^0.1.0" + "nextcloud/rector": "^0.2.1" }, "config": { "platform": { diff --git a/vendor-bin/rector/composer.lock b/vendor-bin/rector/composer.lock index 578de23..a3e77ac 100644 --- a/vendor-bin/rector/composer.lock +++ b/vendor-bin/rector/composer.lock @@ -4,21 +4,21 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "144580060363807d84c64c8193f2f5cd", + "content-hash": "e61eb2cb2286d57dd0e947d53a8707bb", "packages": [], "packages-dev": [ { "name": "nextcloud/rector", - "version": "v0.1.2", + "version": "v0.2.1", "source": { "type": "git", "url": "https://github.com/nextcloud-libraries/rector.git", - "reference": "f98c2d8bd13654a6c27ea0d9788949e90912f800" + "reference": "d73ab086700564f675eda9a834b6b08410a1da7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-libraries/rector/zipball/f98c2d8bd13654a6c27ea0d9788949e90912f800", - "reference": "f98c2d8bd13654a6c27ea0d9788949e90912f800", + "url": "https://api.github.com/repos/nextcloud-libraries/rector/zipball/d73ab086700564f675eda9a834b6b08410a1da7e", + "reference": "d73ab086700564f675eda9a834b6b08410a1da7e", "shasum": "" }, "require": { @@ -44,7 +44,7 @@ }, "autoload": { "psr-4": { - "ChristophWurst\\Nextcloud\\Rector\\": "src/" + "Nextcloud\\Rector\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -65,22 +65,22 @@ ], "support": { "issues": "https://github.com/nextcloud-libraries/rector/issues", - "source": "https://github.com/nextcloud-libraries/rector/tree/v0.1.2" + "source": "https://github.com/nextcloud-libraries/rector/tree/v0.2.1" }, - "time": "2024-09-11T06:54:05+00:00" + "time": "2024-10-01T12:24:08+00:00" }, { "name": "phpstan/phpstan", - "version": "1.12.12", + "version": "1.12.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0" + "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", + "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", "shasum": "" }, "require": { @@ -125,7 +125,7 @@ "type": "github" } ], - "time": "2024-11-28T22:13:23+00:00" + "time": "2024-11-17T14:08:01+00:00" }, { "name": "rector/rector",