summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorleith abdulla <online-nextcloud@eleith.com>2020-11-01 19:31:58 -0800
committerleith abdulla <online-nextcloud@eleith.com>2020-11-01 19:54:19 -0800
commitda321c14516862c1216f57060d1d609704f61c9d (patch)
tree7616a67f2079316d8b04283ffdbc69fded8753d9 /lib/Service
parent296ebf7c7cbe44d297625e29c681b3a8ffb3dc3c (diff)
linting, unit tests, comment fixes
Signed-off-by: leith abdulla <online-nextcloud@eleith.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/Social/CompositeSocialProvider.php5
-rw-r--r--lib/Service/Social/DiasporaProvider.php84
-rw-r--r--lib/Service/Social/FacebookProvider.php14
-rw-r--r--lib/Service/Social/GravatarProvider.php6
-rw-r--r--lib/Service/Social/InstagramProvider.php14
-rw-r--r--lib/Service/Social/MastodonProvider.php18
-rw-r--r--lib/Service/Social/TumblrProvider.php14
-rw-r--r--lib/Service/Social/TwitterProvider.php14
-rw-r--r--lib/Service/Social/XingProvider.php16
-rw-r--r--lib/Service/SocialApiService.php12
10 files changed, 97 insertions, 100 deletions
diff --git a/lib/Service/Social/CompositeSocialProvider.php b/lib/Service/Social/CompositeSocialProvider.php
index 8e9f3e89..751f5cc6 100644
--- a/lib/Service/Social/CompositeSocialProvider.php
+++ b/lib/Service/Social/CompositeSocialProvider.php
@@ -65,10 +65,9 @@ class CompositeSocialProvider {
/**
* generate download url for a social entry
*
- * @param array contact all social data from the contact
* @param String network the choice which network to use
*
- * @returns ISocialProvider if provider of 'network' is found, otherwise null
+ * @return ISocialProvider if provider of 'network' is found, otherwise null
*/
public function getSocialConnector(string $network) : ?ISocialProvider {
$connector = null;
@@ -82,8 +81,6 @@ class CompositeSocialProvider {
/**
* generate download url for a social entry
*
- * @param array contact all social data from the contact
- *
* @return ISocialProvider[] all social providers
*/
public function getSocialConnectors() : array {
diff --git a/lib/Service/Social/DiasporaProvider.php b/lib/Service/Social/DiasporaProvider.php
index 44f46ae1..31269029 100644
--- a/lib/Service/Social/DiasporaProvider.php
+++ b/lib/Service/Social/DiasporaProvider.php
@@ -33,8 +33,8 @@ class DiasporaProvider implements ISocialProvider {
/** @var bool */
private $looping;
- /** @var string */
- public $name = "diaspora";
+ /** @var string */
+ public $name = "diaspora";
public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
@@ -49,17 +49,17 @@ class DiasporaProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
- if ($profile['type'] == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $socialprofiles = $contact['X-SOCIALPROFILE'];
+ $supports = false;
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
+ if ($profile['type'] == $this->name) {
+ $supports = true;
+ break;
+ }
+ }
+ }
+ return $supports;
}
/**
@@ -67,23 +67,23 @@ class DiasporaProvider implements ISocialProvider {
*
* @param {array} contact information
*
- * @return array
+ * @return array
*/
public function getImageUrls(array $contact):array {
- $profileIds = $this->getProfileIds($contact);
- $urls = array();
+ $profileIds = $this->getProfileIds($contact);
+ $urls = [];
- foreach($profileIds as $profileId) {
- $url = $this->getImageUrl($profileId);
- if (isset($url)) {
- $urls[] = $url;
- }
- }
+ foreach ($profileIds as $profileId) {
+ $url = $this->getImageUrl($profileId);
+ if (isset($url)) {
+ $urls[] = $url;
+ }
+ }
- return $urls;
+ return $urls;
}
- /**
+ /**
* Returns the profile-picture url
*
* @param {string} profileId the profile-id
@@ -113,29 +113,29 @@ class DiasporaProvider implements ISocialProvider {
}
}
- /**
- * Returns all possible profile ids for contact
+ /**
+ * Returns all possible profile ids for contact
*
* @param {array} contact information
*
- * @return array
+ * @return array
*/
- protected function getProfileIds($contact):array {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
+ protected function getProfileIds($contact):array {
+ $socialprofiles = $contact['X-SOCIALPROFILE'];
+ $profileIds = [];
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- $profileId = $this->cleanupId($profile['value']);
- if (isset($profileId)) {
- $profileIds[] = $profileId;
- }
- }
- }
- }
- return $profileIds;
- }
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
+ if (strtolower($profile['type']) == $this->name) {
+ $profileId = $this->cleanupId($profile['value']);
+ if (isset($profileId)) {
+ $profileIds[] = $profileId;
+ }
+ }
+ }
+ }
+ return $profileIds;
+ }
/**
* Returns the profile-id
diff --git a/lib/Service/Social/FacebookProvider.php b/lib/Service/Social/FacebookProvider.php
index 2aa27f83..0202e6d0 100644
--- a/lib/Service/Social/FacebookProvider.php
+++ b/lib/Service/Social/FacebookProvider.php
@@ -47,8 +47,8 @@ class FacebookProvider implements ISocialProvider {
public function supportsContact(array $contact):bool {
$socialprofiles = $contact['X-SOCIALPROFILE'];
$supports = false;
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$supports = true;
break;
@@ -67,8 +67,8 @@ class FacebookProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$profileIds = $this->getProfileIds($contact);
- $urls = array();
- foreach($profileIds as $profileId) {
+ $urls = [];
+ foreach ($profileIds as $profileId) {
$recipe = 'https://graph.facebook.com/{socialId}/picture?width=720';
$connector = str_replace("{socialId}", $profileId, $recipe);
$urls[] = $connector;
@@ -100,9 +100,9 @@ class FacebookProvider implements ISocialProvider {
*/
protected function getProfileIds($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ $profileIds = [];
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$profileIds[] = $this->cleanupId($profile['value']);
}
diff --git a/lib/Service/Social/GravatarProvider.php b/lib/Service/Social/GravatarProvider.php
index d735dd5b..07b0f83e 100644
--- a/lib/Service/Social/GravatarProvider.php
+++ b/lib/Service/Social/GravatarProvider.php
@@ -54,8 +54,8 @@ class GravatarProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$emails = $this->getProfileIds($contact);
- $urls = array();
- foreach($emails as $email) {
+ $urls = [];
+ foreach ($emails as $email) {
$hash = md5(strtolower(trim($email['value'])));
$recipe = 'https://www.gravatar.com/avatar/{hash}?s=720&d=404';
$connector = str_replace("{hash}", $hash, $recipe);
@@ -76,6 +76,6 @@ class GravatarProvider implements ISocialProvider {
if (isset($emails)) {
return $emails;
}
- return array();
+ return [];
}
}
diff --git a/lib/Service/Social/InstagramProvider.php b/lib/Service/Social/InstagramProvider.php
index 2cd3bf52..f0c593c7 100644
--- a/lib/Service/Social/InstagramProvider.php
+++ b/lib/Service/Social/InstagramProvider.php
@@ -47,8 +47,8 @@ class InstagramProvider implements ISocialProvider {
public function supportsContact(array $contact):bool {
$socialprofiles = $contact['X-SOCIALPROFILE'];
$supports = false;
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$supports = true;
break;
@@ -67,8 +67,8 @@ class InstagramProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$profileIds = $this->getProfileIds($contact);
- $urls = array();
- foreach($profileIds as $profileId) {
+ $urls = [];
+ foreach ($profileIds as $profileId) {
$recipe = 'https://www.instagram.com/{socialId}/?__a=1';
$connector = str_replace("{socialId}", $profileId, $recipe);
$connector = $this->getFromJson($connector, 'graphql->user->profile_pic_url_hd');
@@ -98,9 +98,9 @@ class InstagramProvider implements ISocialProvider {
*/
protected function getProfileIds($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ $profileIds = [];
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$profileIds[] = $this->cleanupId($profile['value']);
}
diff --git a/lib/Service/Social/MastodonProvider.php b/lib/Service/Social/MastodonProvider.php
index 2c6cbd19..b1bb5097 100644
--- a/lib/Service/Social/MastodonProvider.php
+++ b/lib/Service/Social/MastodonProvider.php
@@ -30,7 +30,7 @@ class MastodonProvider implements ISocialProvider {
/** @var IClientService */
private $httpClient;
- /** @var string */
+ /** @var string */
public $name = "mastodon";
public function __construct(IClientService $httpClient) {
@@ -47,8 +47,8 @@ class MastodonProvider implements ISocialProvider {
public function supportsContact(array $contact):bool {
$socialprofiles = $contact['X-SOCIALPROFILE'];
$supports = false;
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$supports = true;
break;
@@ -67,9 +67,9 @@ class MastodonProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$profileIds = $this->getProfileIds($contact);
- $urls = array();
+ $urls = [];
- foreach($profileIds as $profileId) {
+ foreach ($profileIds as $profileId) {
$url = $this->getImageUrl($profileId);
if (isset($url)) {
$urls[] = $url;
@@ -110,12 +110,12 @@ class MastodonProvider implements ISocialProvider {
*/
protected function getProfileIds($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ $profileIds = [];
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$profileId = $this->cleanupId($profile['value']);
- if(isset($profileId)) {
+ if (isset($profileId)) {
$profileIds[] = $profileId;
}
}
diff --git a/lib/Service/Social/TumblrProvider.php b/lib/Service/Social/TumblrProvider.php
index e1c1d61e..c0d8ffca 100644
--- a/lib/Service/Social/TumblrProvider.php
+++ b/lib/Service/Social/TumblrProvider.php
@@ -40,8 +40,8 @@ class TumblrProvider implements ISocialProvider {
public function supportsContact(array $contact):bool {
$socialprofiles = $contact['X-SOCIALPROFILE'];
$supports = false;
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$supports = true;
break;
@@ -60,8 +60,8 @@ class TumblrProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$profileIds = $this->getProfileIds($contact);
- $urls = array();
- foreach($profileIds as $profileId) {
+ $urls = [];
+ foreach ($profileIds as $profileId) {
$recipe = 'https://api.tumblr.com/v2/blog/{socialId}/avatar/512';
$connector = str_replace("{socialId}", $profileId, $recipe);
$urls[] = $connector;
@@ -94,9 +94,9 @@ class TumblrProvider implements ISocialProvider {
*/
protected function getProfileIds($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ $profileIds = [];
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$profileIds[] = $this->cleanupId($profile['value']);
}
diff --git a/lib/Service/Social/TwitterProvider.php b/lib/Service/Social/TwitterProvider.php
index ed249a0b..08aab855 100644
--- a/lib/Service/Social/TwitterProvider.php
+++ b/lib/Service/Social/TwitterProvider.php
@@ -45,8 +45,8 @@ class TwitterProvider implements ISocialProvider {
*/
public function supportsContact(array $contact):bool {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
return true;
}
@@ -64,8 +64,8 @@ class TwitterProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$profileIds = $this->getProfileIds($contact);
- $urls = array();
- foreach($profileIds as $profileId) {
+ $urls = [];
+ foreach ($profileIds as $profileId) {
$recipe = 'https://mobile.twitter.com/{socialId}';
$connector = str_replace("{socialId}", $profileId, $recipe);
$connector = $this->getFromHtml($connector, '_normal');
@@ -98,9 +98,9 @@ class TwitterProvider implements ISocialProvider {
*/
protected function getProfileIds($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ $profileIds = [];
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$profileIds[] = $this->cleanupId($profile['value']);
}
diff --git a/lib/Service/Social/XingProvider.php b/lib/Service/Social/XingProvider.php
index ce695607..c0a816d9 100644
--- a/lib/Service/Social/XingProvider.php
+++ b/lib/Service/Social/XingProvider.php
@@ -48,8 +48,8 @@ class XingProvider implements ISocialProvider {
public function supportsContact(array $contact):bool {
$socialprofiles = $contact['X-SOCIALPROFILE'];
$supports = false;
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$supports = true;
break;
@@ -68,9 +68,9 @@ class XingProvider implements ISocialProvider {
*/
public function getImageUrls(array $contact):array {
$profileIds = $this->getProfileIds($contact);
- $urls = array();
+ $urls = [];
- foreach($profileIds as $profileId) {
+ foreach ($profileIds as $profileId) {
$url = $this->getImageUrl($profileId);
if (isset($url)) {
$urls[] = $url;
@@ -131,12 +131,12 @@ class XingProvider implements ISocialProvider {
*/
protected function getProfileIds($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = array();
- if(isset($socialprofiles)) {
- foreach($socialprofiles as $profile) {
+ $profileIds = [];
+ if (isset($socialprofiles)) {
+ foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
$profileId = $this->cleanupId($profile['value']);
- if(isset($profileId)) {
+ if (isset($profileId)) {
$profileIds[] = $profileId;
}
}
diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php
index af07c998..446a9ef6 100644
--- a/lib/Service/SocialApiService.php
+++ b/lib/Service/SocialApiService.php
@@ -167,10 +167,10 @@ class SocialApiService {
*
* @returns {JSONResponse} an empty JSONResponse with respective http status code
*/
- public function updateContact(string $addressbookId, string $contactId, string $network) : JSONResponse {
+ public function updateContact(string $addressbookId, string $contactId, ?string $network) : JSONResponse {
$socialdata = null;
$imageType = null;
- $urls = array();
+ $urls = [];
$allConnectors = $this->socialProvider->getSocialConnectors();
try {
@@ -191,7 +191,7 @@ class SocialApiService {
$allConnectors = [$this->socialProvider->getSocialConnector($network)];
}
- $connectors = array_filter($allConnectors, function($connector) use($contact) {
+ $connectors = array_filter($allConnectors, function ($connector) use ($contact) {
return $connector->supportsContact($contact);
});
@@ -199,7 +199,7 @@ class SocialApiService {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}
- foreach($connectors as $connector) {
+ foreach ($connectors as $connector) {
$urls = array_merge($connector->getImageUrls($contact), $urls);
}
@@ -207,7 +207,7 @@ class SocialApiService {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}
- foreach($urls as $url) {
+ foreach ($urls as $url) {
try {
$httpResult = $this->clientService->NewClient()->get($url);
$socialdata = $httpResult->getBody();
@@ -215,7 +215,7 @@ class SocialApiService {
if (isset($socialdata) && isset($imageType)) {
break;
}
- } catch(\Exception $e) {
+ } catch (\Exception $e) {
}
}