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

refactor: Replace class strings with ::class constants #48047

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 16 additions & 15 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# .git-blame-ignore-revs

# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later

# Format control structures
caff1023ea72bb2ea94130e18a2a6e2ccf819e5f
# Update to coding-standard 1.1.1
aa5f037af71c915424c6dcfd5ad2dc82797dc0d6
# Update to coding-standard 1.2.3
af6de04e9e141466dc229e444ff3f146f4a34765
0bd284cb81b6866338aaaa67aa1d81ef9bfbb2ab
8af7ecb2576071f170ecbb0aa2311b26581e40e2
# Automated refactorings
49dd79eabb2b8902559a7a4e8f8fcad54f46b604
# .git-blame-ignore-revs

# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later

# Format control structures
caff1023ea72bb2ea94130e18a2a6e2ccf819e5f
# Update to coding-standard 1.1.1
aa5f037af71c915424c6dcfd5ad2dc82797dc0d6
# Update to coding-standard 1.2.3
af6de04e9e141466dc229e444ff3f146f4a34765
0bd284cb81b6866338aaaa67aa1d81ef9bfbb2ab
8af7ecb2576071f170ecbb0aa2311b26581e40e2
# Automated refactorings
275a8ce1dc69e3ae6e27a34d3c8501c1e3078f09
49dd79eabb2b8902559a7a4e8f8fcad54f46b604
2 changes: 1 addition & 1 deletion apps/admin_audit/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,6 @@
private function trashbinHooks(IAuditLogger $logger): void {
$trashActions = new Trashbin($logger);
Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
Util::connectHook(\OCA\Files_Trashbin\Trashbin::class, 'post_restore', $trashActions, 'restore');

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OCP\Util::connectHook has been marked as deprecated
}
}
12 changes: 6 additions & 6 deletions apps/comments/tests/Unit/AppInfo/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function test(): void {
$c = $app->getContainer();

$services = [
'OCA\Comments\Controller\NotificationsController',
'OCA\Comments\Activity\Filter',
'OCA\Comments\Activity\Listener',
'OCA\Comments\Activity\Provider',
'OCA\Comments\Activity\Setting',
'OCA\Comments\Notification\Listener',
\OCA\Comments\Controller\NotificationsController::class,
\OCA\Comments\Activity\Filter::class,
\OCA\Comments\Activity\Listener::class,
\OCA\Comments\Activity\Provider::class,
\OCA\Comments\Activity\Setting::class,
\OCA\Comments\Notification\Listener::class,
Notifier::class,
];

Expand Down
2 changes: 1 addition & 1 deletion apps/comments/tests/Unit/Notification/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testEvaluate($eventType, $notificationMethod): void {
->willReturn($notification);
$this->notificationManager->expects($this->exactly(6))
->method($notificationMethod)
->with($this->isInstanceOf('\OCP\Notification\INotification'));
->with($this->isInstanceOf(\OCP\Notification\INotification::class));

$this->userManager->expects($this->exactly(6))
->method('userExists')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ class CalendarSearchReport implements XmlDeserializable {
*/
public static function xmlDeserialize(Reader $reader) {
$elems = $reader->parseInnerTree([
'{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter',
'{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter',
'{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter',
'{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter',
'{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter',
'{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter',
'{http://nextcloud.com/ns}comp-filter' => \OCA\DAV\CalDAV\Search\Xml\Filter\CompFilter::class,
'{http://nextcloud.com/ns}prop-filter' => \OCA\DAV\CalDAV\Search\Xml\Filter\PropFilter::class,
'{http://nextcloud.com/ns}param-filter' => \OCA\DAV\CalDAV\Search\Xml\Filter\ParamFilter::class,
'{http://nextcloud.com/ns}search-term' => \OCA\DAV\CalDAV\Search\Xml\Filter\SearchTermFilter::class,
'{http://nextcloud.com/ns}limit' => \OCA\DAV\CalDAV\Search\Xml\Filter\LimitFilter::class,
'{http://nextcloud.com/ns}offset' => \OCA\DAV\CalDAV\Search\Xml\Filter\OffsetFilter::class,
'{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
]);

Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function setUp(): void {
parent::setUp();

$db = \OC::$server->getDatabaseConnection();
$this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal');
$this->principal = $this->createMock(\OCA\DAV\Connector\Sabre\Principal::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->random = \OC::$server->getSecureRandom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class CalendarSearchReportTest extends TestCase {
private $elementMap = [
'{http://nextcloud.com/ns}calendar-search' =>
'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport',
\OCA\DAV\CalDAV\Search\Xml\Request\CalendarSearchReport::class,
];

public function testFoo(): void {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testInitialize(): void {

$this->assertEquals(
$server->xml->elementMap['{http://nextcloud.com/ns}calendar-search'],
'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport'
\OCA\DAV\CalDAV\Search\Xml\Request\CalendarSearchReport::class
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp(): void {

public function nodeProvider() {
$mocks = [];
foreach (['\OCA\DAV\Connector\Sabre\File', '\OCA\DAV\Connector\Sabre\Directory', '\Sabre\DAV\INode'] as $class) {
foreach ([\OCA\DAV\Connector\Sabre\File::class, \OCA\DAV\Connector\Sabre\Directory::class, '\Sabre\DAV\INode'] as $class) {
$mocks[] = $this->getMockBuilder($class)
->disableOriginalConstructor()
->getMock();
Expand Down
12 changes: 6 additions & 6 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class DirectoryTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();

$this->view = $this->createMock('OC\Files\View');
$this->info = $this->createMock('OC\Files\FileInfo');
$this->view = $this->createMock(\OC\Files\View::class);
$this->info = $this->createMock(\OC\Files\FileInfo::class);
$this->info->method('isReadable')
->willReturn(true);
$this->info->method('getType')
Expand Down Expand Up @@ -283,8 +283,8 @@ public function testGetQuotaInfoUnlimited(): void {
$storage->expects($this->any())
->method('instanceOfStorage')
->willReturnMap([
'\OCA\Files_Sharing\SharedStorage' => false,
'\OC\Files\Storage\Wrapper\Quota' => false,
\OCA\Files_Sharing\SharedStorage::class => false,
\OC\Files\Storage\Wrapper\Quota::class => false,
]);

$storage->expects($this->once())
Expand Down Expand Up @@ -334,8 +334,8 @@ public function testGetQuotaInfoSpecific(): void {
$storage->expects($this->any())
->method('instanceOfStorage')
->willReturnMap([
['\OCA\Files_Sharing\SharedStorage', false],
['\OC\Files\Storage\Wrapper\Quota', true],
[\OCA\Files_Sharing\SharedStorage::class, false],
[\OC\Files\Storage\Wrapper\Quota::class, true],
]);

$storage->expects($this->once())
Expand Down
12 changes: 6 additions & 6 deletions apps/dav/tests/unit/Connector/Sabre/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,27 @@ public function fopenFailuresProvider() {
],
[
new \OCP\Files\EntityTooLargeException(),
'OCA\DAV\Connector\Sabre\Exception\EntityTooLarge'
\OCA\DAV\Connector\Sabre\Exception\EntityTooLarge::class
],
[
new \OCP\Files\InvalidContentException(),
'OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType'
\OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType::class
],
[
new \OCP\Files\InvalidPathException(),
'Sabre\DAV\Exception\Forbidden'
],
[
new \OCP\Files\ForbiddenException('', true),
'OCA\DAV\Connector\Sabre\Exception\Forbidden'
\OCA\DAV\Connector\Sabre\Exception\Forbidden::class
],
[
new \OCP\Files\LockNotAcquiredException('/test.txt', 1),
'OCA\DAV\Connector\Sabre\Exception\FileLocked'
\OCA\DAV\Connector\Sabre\Exception\FileLocked::class
],
[
new \OCP\Lock\LockedException('/test.txt'),
'OCA\DAV\Connector\Sabre\Exception\FileLocked'
\OCA\DAV\Connector\Sabre\Exception\FileLocked::class
],
[
new \OCP\Encryption\Exceptions\GenericEncryptionException(),
Expand Down Expand Up @@ -454,7 +454,7 @@ public function testPutSingleFileCancelPreHook(): void {
\OCP\Util::connectHook(
Filesystem::CLASSNAME,
Filesystem::signal_create,
'\Test\HookHelper',
\Test\HookHelper::class,
'cancellingCallback'
);

Expand Down
12 changes: 6 additions & 6 deletions apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private function createTestNode($class, $path = '/dummypath') {

public function testGetPropertiesForFile(): void {
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node = $this->createTestNode(\OCA\DAV\Connector\Sabre\File::class);

$propFind = new PropFind(
'/dummyPath',
Expand Down Expand Up @@ -181,7 +181,7 @@ public function testGetPropertiesForFile(): void {

public function testGetPropertiesStorageNotAvailable(): void {
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node = $this->createTestNode(\OCA\DAV\Connector\Sabre\File::class);

$propFind = new PropFind(
'/dummyPath',
Expand Down Expand Up @@ -228,7 +228,7 @@ public function testGetPublicPermissions(): void {
);

/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node = $this->createTestNode(\OCA\DAV\Connector\Sabre\File::class);
$node->expects($this->any())
->method('getDavPermissions')
->willReturn('DWCKMSR');
Expand All @@ -243,7 +243,7 @@ public function testGetPublicPermissions(): void {

public function testGetPropertiesForDirectory(): void {
/** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
$node = $this->createTestNode(\OCA\DAV\Connector\Sabre\Directory::class);

$propFind = new PropFind(
'/dummyPath',
Expand Down Expand Up @@ -345,7 +345,7 @@ public function testGetPropertiesWhenNoPermission(): void {
}

public function testUpdateProps(): void {
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node = $this->createTestNode(\OCA\DAV\Connector\Sabre\File::class);

$testDate = 'Fri, 13 Feb 2015 00:01:02 GMT';
$testCreationDate = '2007-08-31T16:47+00:00';
Expand Down Expand Up @@ -615,7 +615,7 @@ public function testDownloadHeaders($isClumsyAgent, $contentDispositionHeader):

public function testHasPreview(): void {
/** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
$node = $this->createTestNode(\OCA\DAV\Connector\Sabre\Directory::class);

$propFind = new PropFind(
'/dummyPath',
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ public function testFindNodesByFileIdsRoot(): void {
$result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);

$this->assertCount(2, $result);
$this->assertInstanceOf('\OCA\DAV\Connector\Sabre\Directory', $result[0]);
$this->assertInstanceOf(\OCA\DAV\Connector\Sabre\Directory::class, $result[0]);
$this->assertEquals('first node', $result[0]->getName());
$this->assertInstanceOf('\OCA\DAV\Connector\Sabre\File', $result[1]);
$this->assertInstanceOf(\OCA\DAV\Connector\Sabre\File::class, $result[1]);
$this->assertEquals('second node', $result[1]->getName());
}

Expand Down Expand Up @@ -346,9 +346,9 @@ public function testFindNodesByFileIdsSubDir(): void {
$result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);

$this->assertCount(2, $result);
$this->assertInstanceOf('\OCA\DAV\Connector\Sabre\Directory', $result[0]);
$this->assertInstanceOf(\OCA\DAV\Connector\Sabre\Directory::class, $result[0]);
$this->assertEquals('first node', $result[0]->getName());
$this->assertInstanceOf('\OCA\DAV\Connector\Sabre\File', $result[1]);
$this->assertInstanceOf(\OCA\DAV\Connector\Sabre\File::class, $result[1]);
$this->assertEquals('second node', $result[1]->getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testBasicUpload(): void {
$mount->getStorage()->unlink($mount->getInternalPath($internalPath));

// cache entry still exists
$this->assertInstanceOf('\OCP\Files\FileInfo', $view->getFileInfo('foo.txt'));
$this->assertInstanceOf(\OCP\Files\FileInfo::class, $view->getFileInfo('foo.txt'));

$response = $this->request($view, $user, 'pass', 'DELETE', '/foo.txt');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EncryptionMasterKeyUploadTest extends UploadTest {
protected function setupUser($name, $password) {
$this->createUser($name, $password);
$tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
$this->registerMount($name, \OC\Files\Storage\Local::class, '/' . $name, ['datadir' => $tmpFolder]);
// we use the master key
\OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '1');
$this->setupForUser($name, $password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EncryptionUploadTest extends UploadTest {
protected function setupUser($name, $password) {
$this->createUser($name, $password);
$tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
$this->registerMount($name, \OC\Files\Storage\Local::class, '/' . $name, ['datadir' => $tmpFolder]);
// we use per-user keys
\OC::$server->getConfig()->setAppValue('encryption', 'useMasterKey', '0');
$this->setupForUser($name, $password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function setUp(): void {
protected function setupUser($name, $password) {
$this->createUser($name, $password);
$tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
$this->registerMount($name, \OC\Files\Storage\Local::class, '/' . $name, ['datadir' => $tmpFolder]);
$this->loginAsUser($name);
return new View('/' . $name . '/files');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testBasicUpload(): void {
$this->assertEquals('asd', $view->file_get_contents('foo.txt'));

$info = $view->getFileInfo('foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
$this->assertInstanceOf(\OC\Files\FileInfo::class, $info);
$this->assertEquals(3, $info->getSize());
}

Expand All @@ -46,7 +46,7 @@ public function testUploadOverWrite(): void {
$this->assertEquals('asd', $view->file_get_contents('foo.txt'));

$info = $view->getFileInfo('foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $info);
$this->assertInstanceOf(\OC\Files\FileInfo::class, $info);
$this->assertEquals(3, $info->getSize());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testEnable(): void {
);

$response = $this->controller->enable();
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
$this->assertInstanceOf(\OCP\AppFramework\Http\JSONResponse::class, $response);
}

public function testDisable(): void {
Expand All @@ -97,6 +97,6 @@ public function testDisable(): void {
->method('deleteAllBirthdayCalendars');

$response = $this->controller->disable();
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response);
$this->assertInstanceOf(\OCP\AppFramework\Http\JSONResponse::class, $response);
}
}
4 changes: 2 additions & 2 deletions apps/dav/tests/unit/SystemTag/SystemTagPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ public function testCreateTagInByIdCollection($userVisible, $userAssignable, $gr

public function nodeClassProvider() {
return [
['\OCA\DAV\SystemTag\SystemTagsByIdCollection'],
['\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection'],
[\OCA\DAV\SystemTag\SystemTagsByIdCollection::class],
[\OCA\DAV\SystemTag\SystemTagsObjectMappingCollection::class],
];
}

Expand Down
10 changes: 5 additions & 5 deletions apps/dav/tests/unit/SystemTag/SystemTagsByIdCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testGetChild(): void {

$childNode = $this->getNode()->getChild('123');

$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $childNode);
$this->assertInstanceOf(\OCA\DAV\SystemTag\SystemTagNode::class, $childNode);
$this->assertEquals('123', $childNode->getName());
$this->assertEquals($tag, $childNode->getSystemTag());
}
Expand Down Expand Up @@ -145,8 +145,8 @@ public function testGetChildrenAdmin(): void {

$this->assertCount(2, $children);

$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
$this->assertInstanceOf(\OCA\DAV\SystemTag\SystemTagNode::class, $children[0]);
$this->assertInstanceOf(\OCA\DAV\SystemTag\SystemTagNode::class, $children[1]);
$this->assertEquals($tag1, $children[0]->getSystemTag());
$this->assertEquals($tag2, $children[1]->getSystemTag());
}
Expand All @@ -164,8 +164,8 @@ public function testGetChildrenNonAdmin(): void {

$this->assertCount(2, $children);

$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[0]);
$this->assertInstanceOf('\OCA\DAV\SystemTag\SystemTagNode', $children[1]);
$this->assertInstanceOf(\OCA\DAV\SystemTag\SystemTagNode::class, $children[0]);
$this->assertInstanceOf(\OCA\DAV\SystemTag\SystemTagNode::class, $children[1]);
$this->assertEquals($tag1, $children[0]->getSystemTag());
$this->assertEquals($tag2, $children[1]->getSystemTag());
}
Expand Down
Loading
Loading