Passed
Push — master ( 85c5ba...155252 )
by Justin
03:13
created

Page   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadPage() 0 22 3
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: JuKuCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 30.04.2018
25
 * Time: 01:14
26
 */
27
28
namespace Plugin\FacebookApi;
29
30
use Facebook\Facebook;
31
use Facebook\Exceptions\FacebookResponseException;
32
use Facebook\Exceptions\FacebookSDKException;
33
34
class Page {
35
36
	protected $fb = null;
37
	protected $api = null;
38
39
	protected $pageID = "";
40
	protected $response = null;
41
	protected $graphNode = null;
42
43
	public function __construct (Facebook $fb, FacebookApi $api) {
44
		$this->fb = $fb;
45
		$this->api = $api;
46
	}
47
48
	public function loadPage (string $name) {
49
		$this->pageID = $name;
50
51
		//https://stackoverflow.com/questions/7633234/get-public-page-statuses-using-facebook-graph-api-without-access-token
52
53
		//get all available fields: /{page-id}?metadata=1
54
55
		try {
56
			// Returns a `Facebook\FacebookResponse` object
57
			$this->response = $this->fb->get(
58
				"/" . $this->pageID . "?fields=id,about,fan_count,website,location,name,username,phone,feed",
59
				$this->api->getAccessToken()
60
			);
61
		} catch(FacebookResponseException $e) {
62
			echo 'Graph returned an error: ' . $e->getMessage();
63
			exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
64
		} catch(FacebookSDKException $e) {
65
			echo 'Facebook SDK returned an error: ' . $e->getMessage();
66
			exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
67
		}
68
69
		$this->graphNode = $this->response->getGraphNode();
70
	}
71
72
}
73
74
?>
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...
75