Skip to content

Commit

Permalink
linting, unit tests, comment fixes
Browse files Browse the repository at this point in the history
Signed-off-by: leith abdulla <online-nextcloud@eleith.com>
  • Loading branch information
eleith committed Nov 2, 2020
1 parent 296ebf7 commit da321c1
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 143 deletions.
5 changes: 1 addition & 4 deletions lib/Service/Social/CompositeSocialProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public function getSupportedNetworks() : array {
/**
* 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;
Expand All @@ -82,8 +81,6 @@ public function getSocialConnector(string $network) : ?ISocialProvider {
/**
* 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 {
Expand Down
84 changes: 42 additions & 42 deletions lib/Service/Social/DiasporaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -49,41 +49,41 @@ public function __construct(IClientService $httpClient) {
* @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;
}

/**
* Returns all possible profile-picture urls
*
* @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
Expand Down Expand Up @@ -113,29 +113,29 @@ protected function getImageUrl(string $profileUrl):?string {
}
}

/**
* 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
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/Social/FacebookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function __construct(IClientService $httpClient) {
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;
Expand All @@ -67,8 +67,8 @@ public function supportsContact(array $contact):bool {
*/
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;
Expand Down Expand Up @@ -100,9 +100,9 @@ protected function cleanupId(string $candidate):string {
*/
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']);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/Social/GravatarProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public function supportsContact(array $contact):bool {
*/
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);
Expand All @@ -76,6 +76,6 @@ protected function getProfileIds(array $contact):array {
if (isset($emails)) {
return $emails;
}
return array();
return [];
}
}
14 changes: 7 additions & 7 deletions lib/Service/Social/InstagramProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public function __construct(IClientService $httpClient) {
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;
Expand All @@ -67,8 +67,8 @@ public function supportsContact(array $contact):bool {
*/
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');
Expand Down Expand Up @@ -98,9 +98,9 @@ protected function cleanupId(string $candidate):string {
*/
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']);
}
Expand Down
18 changes: 9 additions & 9 deletions lib/Service/Social/MastodonProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MastodonProvider implements ISocialProvider {
/** @var IClientService */
private $httpClient;

/** @var string */
/** @var string */
public $name = "mastodon";

public function __construct(IClientService $httpClient) {
Expand All @@ -47,8 +47,8 @@ public function __construct(IClientService $httpClient) {
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;
Expand All @@ -67,9 +67,9 @@ public function supportsContact(array $contact):bool {
*/
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;
Expand Down Expand Up @@ -110,12 +110,12 @@ public function getImageUrl(string $profileUrl):?string {
*/
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;
}
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/Social/TumblrProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __construct() {
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;
Expand All @@ -60,8 +60,8 @@ public function supportsContact(array $contact):bool {
*/
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;
Expand Down Expand Up @@ -94,9 +94,9 @@ protected function cleanupId(string $candidate):?string {
*/
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']);
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/Social/TwitterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __construct(IClientService $httpClient) {
*/
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;
}
Expand All @@ -64,8 +64,8 @@ public function supportsContact(array $contact):bool {
*/
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');
Expand Down Expand Up @@ -98,9 +98,9 @@ protected function cleanupId(string $candidate):string {
*/
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']);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/Service/Social/XingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function __construct(IClientService $httpClient) {
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;
Expand All @@ -68,9 +68,9 @@ public function supportsContact(array $contact):bool {
*/
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;
Expand Down Expand Up @@ -131,12 +131,12 @@ protected function cleanupId(string $candidate):?string {
*/
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;
}
}
Expand Down
Loading

0 comments on commit da321c1

Please sign in to comment.