Skip to content

Commit e0274e4

Browse files
susnuxcome-nc
authored andcommitted
refactor(Collaboration): Use non-deprecated methods
Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 922546d commit e0274e4

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

lib/private/Collaboration/AutoComplete/Manager.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
use OCP\Collaboration\AutoComplete\IManager;
99
use OCP\Collaboration\AutoComplete\ISorter;
10-
use OCP\IServerContainer;
10+
use Psr\Container\ContainerExceptionInterface;
11+
use Psr\Container\ContainerInterface;
12+
use Psr\Log\LoggerInterface;
1113

1214
class Manager implements IManager {
1315
/** @var string[] */
@@ -17,7 +19,8 @@ class Manager implements IManager {
1719
protected array $sorterInstances = [];
1820

1921
public function __construct(
20-
private IServerContainer $container,
22+
private ContainerInterface $container,
23+
private LoggerInterface $logger,
2124
) {
2225
}
2326

@@ -27,7 +30,7 @@ public function runSorters(array $sorters, array &$sortArray, array $context): v
2730
if (isset($sorterInstances[$sorter])) {
2831
$sorterInstances[$sorter]->sort($sortArray, $context);
2932
} else {
30-
$this->container->getLogger()->warning('No sorter for ID "{id}", skipping', [
33+
$this->logger->warning('No sorter for ID "{id}", skipping', [
3134
'app' => 'core', 'id' => $sorter
3235
]);
3336
}
@@ -41,16 +44,23 @@ public function registerSorter($className): void {
4144
protected function getSorters(): array {
4245
if (count($this->sorterInstances) === 0) {
4346
foreach ($this->sorters as $sorter) {
44-
/** @var ISorter $instance */
45-
$instance = $this->container->resolve($sorter);
47+
try {
48+
$instance = $this->container->get($sorter);
49+
} catch (ContainerExceptionInterface) {
50+
$this->logger->notice(
51+
'Skipping not registered sorter. Class name: {class}',
52+
['app' => 'core', 'class' => $sorter],
53+
);
54+
continue;
55+
}
4656
if (!$instance instanceof ISorter) {
47-
$this->container->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}',
57+
$this->logger->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}',
4858
['app' => 'core', 'class' => $sorter]);
4959
continue;
5060
}
5161
$sorterId = trim($instance->getId());
5262
if (trim($sorterId) === '') {
53-
$this->container->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}',
63+
$this->logger->notice('Skipping sorter with empty ID. Class name: {class}',
5464
['app' => 'core', 'class' => $sorter]);
5565
continue;
5666
}

tests/lib/Collaboration/Resources/ManagerTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
use OCP\Collaboration\Resources\IManager;
1313
use OCP\Collaboration\Resources\IProviderManager;
1414
use OCP\IDBConnection;
15+
use PHPUnit\Framework\MockObject\MockObject;
1516
use Psr\Log\LoggerInterface;
1617
use Test\TestCase;
1718

1819
class ManagerTest extends TestCase {
19-
/** @var LoggerInterface */
20-
protected $logger;
21-
/** @var IProviderManager */
22-
protected $providerManager;
23-
/** @var IManager */
24-
protected $manager;
20+
21+
protected LoggerInterface&MockObject $logger;
22+
protected IProviderManager&MockObject $providerManager;
23+
protected IManager $manager;
2524

2625
protected function setUp(): void {
2726
parent::setUp();

0 commit comments

Comments
 (0)