Skip to content

Commit

Permalink
Merge pull request #4098 from nextcloud/update-coding-standard-123
Browse files Browse the repository at this point in the history
Hello coding-standard 1.2.3
  • Loading branch information
kesselb authored Aug 26, 2024
2 parents 5e05292 + 1dc714e commit 2489a30
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 212 deletions.
7 changes: 7 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# .git-blame-ignore-revs

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

# Update to coding-standard 1.2.3
fe16be69e7a10647508f8c0b63383cbb5ffbde84
1 change: 1 addition & 0 deletions .nextcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.editorconfig
.eslintrc.js
.git
.git-blame-ignore-revs
.github
.gitignore
.gitlab-ci.yml
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/Service/Social/MastodonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getImageUrl(string $profileUrl):?string {
try {
$result = $this->httpClient->get($profileUrl, ['headers' => ['Accept' => 'application/json']]);
$jsonResult = json_decode($result->getBody(), true);
return $jsonResult["icon"]["url"] ?? null;
return $jsonResult['icon']['url'] ?? null;
} catch (\Exception $e) {
return null;
}
Expand All @@ -89,12 +89,12 @@ protected function getProfileIds($contact):array {
try {
[$masto_user, $masto_server] = $masto_user_server;
# search for user webfinger
$webfinger = $masto_server . '/.well-known/webfinger?resource=acct:' . $masto_user . '@' . parse_url($masto_server)["host"];
$webfinger = $masto_server . '/.well-known/webfinger?resource=acct:' . $masto_user . '@' . parse_url($masto_server)['host'];
$result = $this->httpClient->get($webfinger);
$jsonResult = json_decode($result->getBody(), null, 512, JSON_THROW_ON_ERROR);
# find account link
foreach ($jsonResult->links as $link) {
if (($link->rel == "self") and ($link->type == "application/activity+json")) {
if (($link->rel == 'self') and ($link->type == 'application/activity+json')) {
$profileId = $link->href;
$profileIds[] = $profileId;
break;
Expand Down Expand Up @@ -122,7 +122,7 @@ protected function cleanupId(string $candidate):?array {
try {
$user_server = explode('@', $candidate);
if (strpos($candidate, 'http') !== 0) {
$masto_server = "https://" . array_pop($user_server);
$masto_server = 'https://' . array_pop($user_server);
$masto_user = array_pop($user_server);
} else {
$masto_user = array_pop($user_server);
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/Social/TelegramProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getImageUrls(array $contact):array {
* @return string
*/
protected function cleanupId(string $candidate):string {
$candidate = basename($candidate, ".t.me");
$candidate = basename($candidate, '.t.me');
if ($candidate[0] === '@') {
$candidate = substr($candidate, 1);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/SocialApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class SocialApiService {
private $config;
/** @var IClientService */
private $clientService;
/** @var IL10N */
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
/** @var IURLGenerator */
private $urlGen;
/** @var CardDavBackend */
private $davBackend;
Expand Down Expand Up @@ -398,7 +398,7 @@ public function updateAddressbooks(string $userId, ?string $offsetBook = null, ?

try {
$r = $this->updateContact($addressBook->getURI(), $contact['UID'], $network);
$response = $this->registerUpdateResult($response, $contact['FN'], (int) $r->getStatus());
$response = $this->registerUpdateResult($response, $contact['FN'], (int)$r->getStatus());
} catch (\Exception $e) {
$response = $this->registerUpdateResult($response, $contact['FN'], -1);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function getSection() {

/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*/
public function getPriority() {
return 75;
Expand Down
90 changes: 45 additions & 45 deletions tests/unit/ContactsMenu/Provider/DetailsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,89 +66,89 @@ public function testProcessContact() {
$resultUri = "$domain/index.php/apps/contacts/direct/contact/$uid~$abUri";

$entry->expects($this->exactly(3))
->method('getProperty')
->will($this->returnValueMap([
['UID', $uid],
['isLocalSystemBook', null],
['addressbook-key', 1]
]));
->method('getProperty')
->will($this->returnValueMap([
['UID', $uid],
['isLocalSystemBook', null],
['addressbook-key', 1]
]));

$addressbook->expects($this->once())
->method('getKey')
->willReturn(1);
->method('getKey')
->willReturn(1);

$addressbook->expects($this->once())
->method('getUri')
->willReturn($abUri);
->method('getUri')
->willReturn($abUri);

$this->manager->expects($this->once())
->method('getUserAddressbooks')
->willReturn([1 => $addressbook]);
->method('getUserAddressbooks')
->willReturn([1 => $addressbook]);

// Action icon
$this->urlGenerator->expects($this->once())
->method('imagePath')
->with('core', 'actions/info.svg')
->willReturn($iconUrl);
->method('imagePath')
->with('core', 'actions/info.svg')
->willReturn($iconUrl);

//
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('contacts.contacts.direct', [
'contact' => $uid . '~' . $abUri
])
->willReturn("/apps/contacts/direct/contact/$uid~$abUri");
->method('linkToRoute')
->with('contacts.contacts.direct', [
'contact' => $uid . '~' . $abUri
])
->willReturn("/apps/contacts/direct/contact/$uid~$abUri");

// Action icon and contact absolute urls
$this->urlGenerator->expects($this->exactly(2))
->method('getAbsoluteURL')
->will($this->returnValueMap([
[$iconUrl, "$domain/$iconUrl"],
["/apps/contacts/direct/contact/$uid~$abUri", $resultUri]
]));
->method('getAbsoluteURL')
->will($this->returnValueMap([
[$iconUrl, "$domain/$iconUrl"],
["/apps/contacts/direct/contact/$uid~$abUri", $resultUri]
]));

// Translations
$this->l10n->expects($this->once())
->method('t')
->with('Details')
->willReturnArgument(0);
->method('t')
->with('Details')
->willReturnArgument(0);

$this->actionFactory->expects($this->once())
->method('newLinkAction')
->with($this->equalTo("$domain/$iconUrl"), $this->equalTo('Details'), $this->equalTo($resultUri))
->willReturn($action);
->method('newLinkAction')
->with($this->equalTo("$domain/$iconUrl"), $this->equalTo('Details'), $this->equalTo($resultUri))
->willReturn($action);
$action->expects($this->once())
->method('setPriority')
->with($this->equalTo(0));
->method('setPriority')
->with($this->equalTo(0));
$entry->expects($this->once())
->method('addAction')
->with($action);
->method('addAction')
->with($action);

$this->provider->process($entry);
}

public function testProcessNoUID() {
$entry = $this->createMock(IEntry::class);
$entry->expects($this->once())
->method('getProperty')
->with($this->equalTo('UID'))
->willReturn(null);
->method('getProperty')
->with($this->equalTo('UID'))
->willReturn(null);
$entry->expects($this->never())
->method('addAction');
->method('addAction');

$this->provider->process($entry);
}

public function testProcessSystemContact() {
$entry = $this->createMock(IEntry::class);
$entry->expects($this->exactly(2))
->method('getProperty')
->will($this->returnValueMap([
['UID', 1234],
['isLocalSystemBook', true]
]));
->method('getProperty')
->will($this->returnValueMap([
['UID', 1234],
['isLocalSystemBook', true]
]));
$entry->expects($this->never())
->method('addAction');
->method('addAction');

$this->provider->process($entry);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Controller/ContactsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ContactsControllerTest extends TestCase {
/** @var IL10N|MockObject */
private $l10n;

/** @var IURLGenerator|MockObject*/
/** @var IURLGenerator|MockObject */
private $urlGenerator;


Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PageControllerTest extends TestCase {
/** @var IRequest|MockObject */
private $request;

/** @var IConfig|MockObject*/
/** @var IConfig|MockObject */
private $config;

/** @var IInitialStateService|MockObject */
Expand All @@ -37,13 +37,13 @@ class PageControllerTest extends TestCase {
/** @var IUserSession|MockObject */
private $userSession;

/** @var SocialApiService|MockObject*/
/** @var SocialApiService|MockObject */
private $socialApi;

/** @var IAppManager|MockObject*/
/** @var IAppManager|MockObject */
private $appManager;

/** @var CompareVersion|MockObject*/
/** @var CompareVersion|MockObject */
private $compareVersion;

protected function setUp(): void {
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/Service/Social/DiasporaProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,18 @@ public function dataProviderGetImageUrls() {
public function testGetImageUrls($contact, $urls, $htmls, $imgs) {
if (count($urls)) {
$this->response
->method('getBody')
->willReturnOnConsecutiveCalls(...$htmls);
->method('getBody')
->willReturnOnConsecutiveCalls(...$htmls);

$urlArgs = array_map(function ($url) {
return [$url];
}, $urls);

$this->client
->expects($this->exactly(count($urls)))
->method('get')
->withConsecutive(...$urlArgs)
->willReturn($this->response);
->expects($this->exactly(count($urls)))
->method('get')
->withConsecutive(...$urlArgs)
->willReturn($this->response);
}

$result = $this->provider->getImageUrls($contact);
Expand All @@ -150,14 +150,14 @@ public function testGetImageUrlLoop() {
$img = $url2.'-large-avatar.jpg';

$this->response
->method('getBody')
->willReturnOnConsecutiveCalls($html1, $html2);
->method('getBody')
->willReturnOnConsecutiveCalls($html1, $html2);

$this->client
->expects($this->exactly(2))
->method('get')
->withConsecutive([$url1], [$url2])
->willReturn($this->response);
->expects($this->exactly(2))
->method('get')
->withConsecutive([$url1], [$url2])
->willReturn($this->response);

$result = $this->provider->getImageUrls($contact);
$this->assertEquals([$img], $result);
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/Service/Social/FacebookProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ public function testGetImageUrlLookup() {
$html1 = '"entity_id":"1234567"';

$this->response
->method('getBody')
->willReturn($html1);
->method('getBody')
->willReturn($html1);

$this->response
->method('getStatusCode')
->willReturn(200);
->method('getStatusCode')
->willReturn(200);

$this->client
->expects($this->once())
->method('get')
->with($url1)
->willReturn($this->response);
->expects($this->once())
->method('get')
->with($url1)
->willReturn($this->response);

$result = $this->provider->getImageUrls($contact);
$this->assertEquals([$url2], $result);
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Service/Social/GravatarProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function dataProviderSupportsContact() {
];

$contactWithoutEmail = [
'PHONE' => [['value' => 'one'], ["value" => "two"]]
'PHONE' => [['value' => 'one'], ['value' => 'two']]
];

return [
Expand All @@ -44,19 +44,19 @@ public function testSupportsContact($contact, $expected) {

public function dataProviderGetImageUrls() {
$contactWithEmail = [
'EMAIL' => [["value" => "one"], ["value" => "two"]]
'EMAIL' => [['value' => 'one'], ['value' => 'two']]
];

$contactWithoutEmail = [
'PHONE' => [["value" => "one"], ["value" => "two"]]
'PHONE' => [['value' => 'one'], ['value' => 'two']]
];

$urls = [];

foreach ($contactWithEmail['EMAIL'] as $email) {
$hash = md5(strtolower(trim($email['value'])));
$recipe = 'https://www.gravatar.com/avatar/{hash}?s=720&d=404';
$urls[] = str_replace("{hash}", $hash, $recipe);
$urls[] = str_replace('{hash}', $hash, $recipe);
}

return [
Expand Down
Loading

0 comments on commit 2489a30

Please sign in to comment.