From 3fa22c3418a50c78b1e5ad5b6d4b424f71038268 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Oct 2024 23:18:52 +0200 Subject: [PATCH 01/10] build: Bump symfony/* to 6.4 Signed-off-by: Joas Schilling --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 3558cc253049d..9e360791930a8 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 3558cc253049d15a89760af2ecfa8bcfac4f4802 +Subproject commit 9e360791930a82b6770ba72ab0456f5ba27e543f From fd77bc84d12728ae8e4b72012f82ab2137ad1ba2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Oct 2024 23:38:05 +0200 Subject: [PATCH 02/10] fix(command): Make method compatible with upstream class (backportable) Signed-off-by: Joas Schilling --- core/Command/Base.php | 2 +- lib/private/Console/TimestampFormatter.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/Command/Base.php b/core/Command/Base.php index 0af5981e9422e..b915ae2ae4a3a 100644 --- a/core/Command/Base.php +++ b/core/Command/Base.php @@ -149,7 +149,7 @@ public function cancelOperation(): void { $this->interrupted = true; } - public function run(InputInterface $input, OutputInterface $output) { + public function run(InputInterface $input, OutputInterface $output): int { // check if the php pcntl_signal functions are accessible $this->php_pcntl_signal = function_exists('pcntl_signal'); if ($this->php_pcntl_signal) { diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php index da1b7ba48dd57..0254bff2b3246 100644 --- a/lib/private/Console/TimestampFormatter.php +++ b/lib/private/Console/TimestampFormatter.php @@ -41,7 +41,7 @@ public function setDecorated($decorated) { * * @return bool true if the output will decorate messages, false otherwise */ - public function isDecorated() { + public function isDecorated(): bool { return $this->formatter->isDecorated(); } @@ -61,7 +61,7 @@ public function setStyle($name, OutputFormatterStyleInterface $style) { * @param string $name * @return bool */ - public function hasStyle($name) { + public function hasStyle($name): bool { return $this->formatter->hasStyle($name); } @@ -72,7 +72,7 @@ public function hasStyle($name) { * @return OutputFormatterStyleInterface * @throws \InvalidArgumentException When style isn't defined */ - public function getStyle($name) { + public function getStyle($name): OutputFormatterStyleInterface { return $this->formatter->getStyle($name); } From 87acaef73c77db05b11b5e82f740e0991ec4b3a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Oct 2024 23:41:44 +0200 Subject: [PATCH 03/10] fix(command): Make method compatible with upstream class (requires 3rdparty bump) Signed-off-by: Joas Schilling --- lib/private/Console/TimestampFormatter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php index 0254bff2b3246..e8d9eef6b16c9 100644 --- a/lib/private/Console/TimestampFormatter.php +++ b/lib/private/Console/TimestampFormatter.php @@ -32,7 +32,7 @@ public function __construct(?IConfig $config, OutputFormatterInterface $formatte * * @param bool $decorated Whether to decorate the messages or not */ - public function setDecorated($decorated) { + public function setDecorated(bool $decorated) { $this->formatter->setDecorated($decorated); } @@ -51,7 +51,7 @@ public function isDecorated(): bool { * @param string $name The style name * @param OutputFormatterStyleInterface $style The style instance */ - public function setStyle($name, OutputFormatterStyleInterface $style) { + public function setStyle(string $name, OutputFormatterStyleInterface $style) { $this->formatter->setStyle($name, $style); } @@ -61,7 +61,7 @@ public function setStyle($name, OutputFormatterStyleInterface $style) { * @param string $name * @return bool */ - public function hasStyle($name): bool { + public function hasStyle(string $name): bool { return $this->formatter->hasStyle($name); } @@ -72,7 +72,7 @@ public function hasStyle($name): bool { * @return OutputFormatterStyleInterface * @throws \InvalidArgumentException When style isn't defined */ - public function getStyle($name): OutputFormatterStyleInterface { + public function getStyle(string $name): OutputFormatterStyleInterface { return $this->formatter->getStyle($name); } From c0ffe3942195402589815bb7e13b6d9070429682 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Oct 2024 23:58:01 +0200 Subject: [PATCH 04/10] ci: Update psalm-baseline Signed-off-by: Joas Schilling --- build/psalm-baseline.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index a143c6188a1fb..16fe161a9ba4d 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -44,11 +44,6 @@ - - - - - From c109ae9437403c5bd17834c2ee53507c1d1f2ad2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Oct 2024 23:58:31 +0200 Subject: [PATCH 05/10] ci: Fix psalm by typing the QuestionHelper Signed-off-by: Joas Schilling --- apps/files_external/lib/Command/Delete.php | 3 +++ core/Command/Background/Delete.php | 2 ++ core/Command/Config/App/SetConfig.php | 2 ++ core/Command/Db/ConvertFilecacheBigInt.php | 2 ++ core/Command/Db/Migrations/GenerateCommand.php | 2 ++ core/Command/Maintenance/RepairShareOwnership.php | 2 ++ core/Command/Preview/Repair.php | 2 ++ 7 files changed, 15 insertions(+) diff --git a/apps/files_external/lib/Command/Delete.php b/apps/files_external/lib/Command/Delete.php index 61e974ff58957..3e6ccf751a88d 100644 --- a/apps/files_external/lib/Command/Delete.php +++ b/apps/files_external/lib/Command/Delete.php @@ -13,6 +13,7 @@ use OCP\AppFramework\Http; use OCP\IUserManager; use OCP\IUserSession; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -26,6 +27,7 @@ public function __construct( protected UserStoragesService $userService, protected IUserSession $userSession, protected IUserManager $userManager, + protected QuestionHelper $questionHelper, ) { parent::__construct(); } @@ -64,6 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $listInput->setOption('output', $input->getOption('output')); $listCommand->listMounts(null, [$mount], $listInput, $output); + /** @var QuestionHelper $questionHelper */ $questionHelper = $this->getHelper('question'); $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false); diff --git a/core/Command/Background/Delete.php b/core/Command/Background/Delete.php index 41efaf8466521..50ae309065b46 100644 --- a/core/Command/Background/Delete.php +++ b/core/Command/Background/Delete.php @@ -10,6 +10,7 @@ use OC\Core\Command\Base; use OCP\BackgroundJob\IJobList; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -51,6 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int '/^(y|Y)/i' ); + /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); if (!$helper->ask($input, $output, $question)) { $output->writeln('aborted.'); diff --git a/core/Command/Config/App/SetConfig.php b/core/Command/Config/App/SetConfig.php index 461c024d03825..b1d1632ff1a74 100644 --- a/core/Command/Config/App/SetConfig.php +++ b/core/Command/Config/App/SetConfig.php @@ -12,6 +12,7 @@ use OCP\Exceptions\AppConfigIncorrectTypeException; use OCP\Exceptions\AppConfigUnknownKeyException; use OCP\IAppConfig; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -229,6 +230,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } private function ask(InputInterface $input, OutputInterface $output, string $request): bool { + /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); if ($input->getOption('no-interaction')) { return true; diff --git a/core/Command/Db/ConvertFilecacheBigInt.php b/core/Command/Db/ConvertFilecacheBigInt.php index d16e6d302312f..f5028aacaefd7 100644 --- a/core/Command/Db/ConvertFilecacheBigInt.php +++ b/core/Command/Db/ConvertFilecacheBigInt.php @@ -11,6 +11,7 @@ use OCP\DB\Types; use OCP\IDBConnection; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; @@ -89,6 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('This can take up to hours, depending on the number of files in your instance!'); if ($input->isInteractive()) { + /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php index cd92dc5acd60d..ed29412f00bdd 100644 --- a/core/Command/Db/Migrations/GenerateCommand.php +++ b/core/Command/Db/Migrations/GenerateCommand.php @@ -15,6 +15,7 @@ use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\RuntimeException; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -117,6 +118,7 @@ public function execute(InputInterface $input, OutputInterface $output): int { $output->writeln(' - Actual: ' . $version . ''); if ($input->isInteractive()) { + /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Continue with your given version? (y/n) [n] ', false); diff --git a/core/Command/Maintenance/RepairShareOwnership.php b/core/Command/Maintenance/RepairShareOwnership.php index a24be53b00ef4..16675545afea7 100644 --- a/core/Command/Maintenance/RepairShareOwnership.php +++ b/core/Command/Maintenance/RepairShareOwnership.php @@ -14,6 +14,7 @@ use OCP\IUser; use OCP\IUserManager; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -60,6 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(''); if (!$noConfirm) { + /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Repair these shares? [y/N]', false); diff --git a/core/Command/Preview/Repair.php b/core/Command/Preview/Repair.php index 641e204e0502b..3ccd82313002a 100644 --- a/core/Command/Preview/Repair.php +++ b/core/Command/Preview/Repair.php @@ -19,6 +19,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -133,6 +134,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($input->getOption('batch')) { $output->writeln('Batch mode active: migration is started right away.'); } else { + /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Should the migration be started? (y/[n]) ', false); From 843f638315a6379e2fb896786e3f8465fb3134cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 3 Oct 2024 00:27:52 +0200 Subject: [PATCH 06/10] test: Fix mock creation Signed-off-by: Joas Schilling --- tests/Core/Command/User/SettingTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Core/Command/User/SettingTest.php b/tests/Core/Command/User/SettingTest.php index 6848b0bb350ae..95d1c192b81df 100644 --- a/tests/Core/Command/User/SettingTest.php +++ b/tests/Core/Command/User/SettingTest.php @@ -49,15 +49,14 @@ protected function setUp(): void { public function getCommand(array $methods = []) { if (empty($methods)) { - return new Setting($this->userManager, $this->config, $this->connection); + return new Setting($this->userManager, $this->config); } else { - $mock = $this->getMockBuilder('OC\Core\Command\User\Setting') + $mock = $this->getMockBuilder(Setting::class) ->setConstructorArgs([ $this->userManager, $this->config, - $this->connection, ]) - ->setMethods($methods) + ->onlyMethods($methods) ->getMock(); return $mock; } From 4312473fbc1318e4a53dda7161fa85ee7aed9eed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 3 Oct 2024 00:28:07 +0200 Subject: [PATCH 07/10] test: Fix wrongly mocked method Signed-off-by: Joas Schilling --- apps/encryption/tests/Crypto/CryptTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/encryption/tests/Crypto/CryptTest.php b/apps/encryption/tests/Crypto/CryptTest.php index a9869af99d96c..9b6c822708328 100644 --- a/apps/encryption/tests/Crypto/CryptTest.php +++ b/apps/encryption/tests/Crypto/CryptTest.php @@ -37,8 +37,7 @@ protected function setUp(): void { ->disableOriginalConstructor() ->getMock(); $this->logger->expects($this->any()) - ->method('warning') - ->willReturn(true); + ->method('warning'); $this->userSession = $this->getMockBuilder(IUserSession::class) ->disableOriginalConstructor() ->getMock(); From 4219969c96f8dcbe734b22faf1a1b92f35c16028 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 3 Oct 2024 00:28:22 +0200 Subject: [PATCH 08/10] fix: Ensure we only pass string to writeln() Signed-off-by: Joas Schilling --- apps/files_external/lib/Command/Config.php | 2 +- apps/files_external/lib/Command/Option.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_external/lib/Command/Config.php b/apps/files_external/lib/Command/Config.php index f677e51d60435..0736749f6d981 100644 --- a/apps/files_external/lib/Command/Config.php +++ b/apps/files_external/lib/Command/Config.php @@ -73,7 +73,7 @@ protected function getOption(StorageConfig $mount, $key, OutputInterface $output if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly $value = json_encode($value); } - $output->writeln($value); + $output->writeln((string)$value); } /** diff --git a/apps/files_external/lib/Command/Option.php b/apps/files_external/lib/Command/Option.php index 6b679f1d6f7ba..6051c9c5fbdc5 100644 --- a/apps/files_external/lib/Command/Option.php +++ b/apps/files_external/lib/Command/Option.php @@ -38,7 +38,7 @@ protected function getOption(StorageConfig $mount, $key, OutputInterface $output if (!is_string($value)) { // show bools and objects correctly $value = json_encode($value); } - $output->writeln($value); + $output->writeln((string)$value); } /** From e6cd1051dac570826c969c7e7372a38b192056fa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 4 Oct 2024 16:13:28 +0200 Subject: [PATCH 09/10] fix(message): Fix logic of Mail test Signed-off-by: Joas Schilling --- tests/lib/Mail/MessageTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/lib/Mail/MessageTest.php b/tests/lib/Mail/MessageTest.php index 681ec03338015..260d3aaff7684 100644 --- a/tests/lib/Mail/MessageTest.php +++ b/tests/lib/Mail/MessageTest.php @@ -91,23 +91,23 @@ public function testSetRecipients(): void { $this->symfonyEmail ->expects($this->once()) ->method('from') - ->willReturn(new Address('pierres-general-store@stardewvalley.com', 'Pierres General Store')); + ->with(new Address('pierres-general-store@stardewvalley.com', 'Pierres General Store')); $this->symfonyEmail ->expects($this->once()) ->method('to') - ->willReturn(new Address('lewis-tent@stardewvalley.com', "Lewis' Tent Life")); + ->with(new Address('lewis-tent@stardewvalley.com', "Lewis' Tent Life")); $this->symfonyEmail ->expects($this->once()) ->method('replyTo') - ->willReturn(new Address('penny@stardewvalley-library.co.edu', 'Penny')); + ->with(new Address('penny@stardewvalley-library.co.edu', 'Penny')); $this->symfonyEmail ->expects($this->once()) ->method('cc') - ->willReturn(new Address('gunther@stardewvalley-library.co.edu', 'Gunther')); + ->with(new Address('gunther@stardewvalley-library.co.edu', 'Gunther')); $this->symfonyEmail ->expects($this->once()) ->method('bcc') - ->willReturn(new Address('pam@stardewvalley-bus.com', 'Pam')); + ->with(new Address('pam@stardewvalley-bus.com', 'Pam')); $this->message->setRecipients(); } From 315e4658dd3694df144f708e42bb83073bc3b187 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 4 Oct 2024 16:24:22 +0200 Subject: [PATCH 10/10] test(settings): Correctly only return bool for Symfony Input::hasParameterOption calls Signed-off-by: Joas Schilling --- tests/Core/Command/User/SettingTest.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/Core/Command/User/SettingTest.php b/tests/Core/Command/User/SettingTest.php index 95d1c192b81df..62b75191d36de 100644 --- a/tests/Core/Command/User/SettingTest.php +++ b/tests/Core/Command/User/SettingTest.php @@ -193,7 +193,16 @@ public function testCheckInput($arguments, $options, $parameterOptions, $user, $ ->willReturnMap($options); $this->consoleInput->expects($this->any()) ->method('hasParameterOption') - ->willReturnMap($parameterOptions); + ->willReturnCallback(function (string|array $config, bool $default = false) use ($parameterOptions): bool { + foreach ($parameterOptions as $parameterOption) { + if ($config === $parameterOption[0] + // Check the default value if the maps has 3 entries + && (!isset($parameterOption[2]) || $default === $parameterOption[1])) { + return end($parameterOption); + } + } + return false; + }); if ($user !== false) { $this->userManager->expects($this->once()) @@ -401,15 +410,16 @@ public function testExecuteGet($value, $defaultValue, $expectedLine, $expectedRe if ($defaultValue === null) { $this->consoleInput->expects($this->atLeastOnce()) ->method('hasParameterOption') - ->willReturnMap([ - ['--default-value', false], - ]); + ->willReturn(false); } else { $this->consoleInput->expects($this->atLeastOnce()) ->method('hasParameterOption') - ->willReturnMap([ - ['--default-value', false, true], - ]); + ->willReturnCallback(function (string|array $config, bool $default = false): bool { + if ($config === '--default-value' && $default === false) { + return true; + } + return false; + }); $this->consoleInput->expects($this->once()) ->method('getOption') ->with('default-value')