Social::fb()   B
last analyzed

Complexity

Conditions 7
Paths 8

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 8.8333
c 0
b 0
f 0
cc 7
nc 8
nop 0
1
<?php
2
namespace NirjharLo\Cgss\Lib\Analysis\Lib;
3
4
if ( ! defined( 'ABSPATH' ) ) exit;
5
6
7
/**
8
 * Object to fetch social meia information from various networks. Twitter, Google Plus and Facebook
9
 * from an input url.
10
 *
11
 * 1 property:
12
 * @prop string $url Input url, whose social value is to be counted
13
 */
14
class Social {
15
16
17
	public $url;
18
19
	//Facebook data for likes and shares
20
	public function fb() {
21
22
		$share = false;
23
		$fb_data = @file_get_contents( 'http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=' . $this->url );
24
		if ( ! empty( $fb_data ) ) {
25
			$fb_shares = json_decode( $fb_data, true );
26
			if ( array_key_exists ( 0, $fb_shares ) ) {
27
				$fb_shares_act = $fb_shares[0];
28
				if ( is_array( $fb_shares_act ) and array_key_exists ( 'share_count', $fb_shares_act ) and array_key_exists ( 'like_count', $fb_shares_act ) ) {
29
					$share = array(
30
						'share' => $fb_shares_act['share_count'],
31
						'like' => $fb_shares_act['like_count'],
32
					);
33
				}
34
			}
35
		}
36
		if (!$share) {
37
			$share = 0;
38
		}
39
		return $share;
40
	}
41
}
42
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
43