Completed
Push — master ( cab6a9...753b78 )
by Robin
02:45
created

LaravelGoogleIndexingClass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A googleClientSetup() 0 4 1
A status() 0 7 1
A update() 0 4 1
A remove() 0 4 1
A publish() 0 11 1
1
<?php
2
3
namespace Famdirksen\LaravelGoogleIndexing;
4
5
use Google_Client;
6
use Google_Service_Indexing;
7
use Google_Service_Indexing_UrlNotification;
8
9
class LaravelGoogleIndexingClass
10
{
11
    /** @var Google_Client $googleClient */
12
    private $googleClient;
13
14
    /** @var Google_Service_Indexing $indexingService */
15
    private $indexingService;
16
17
    public function __construct(Google_Client $googleClient)
18
    {
19
        $this->googleClient = $googleClient;
20
21
        $this->googleClientSetup();
22
    }
23
24
    private function googleClientSetup() {
25
        $this->googleClient->setAuthConfig(config('laravel-google-indexing.google.auth_config'));
26
        $this->indexingService = new Google_Service_Indexing($this->googleClient);
27
    }
28
29
    public function status(string $url) {
30
        return $this->indexingService
31
            ->urlNotifications
32
            ->getMetadata([
33
                "url" => urlencode($url)
34
            ]);
35
    }
36
37
    public function update(string $url)
38
    {
39
        return $this->publish($url, "URL_UPDATED");
40
    }
41
42
    public function remove(string $url)
43
    {
44
        return $this->publish($url, "URL_DELETED");
45
    }
46
47
    private function publish(string $url, string $action)
48
    {
49
        $urlNotification = new Google_Service_Indexing_UrlNotification();
50
51
        $urlNotification->setUrl($url);
52
        $urlNotification->setType($action);
53
54
        return $this->indexingService
55
            ->urlNotifications
56
            ->publish($urlNotification);
57
    }
58
}
59