LaravelGoogleIndexing   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A create() 0 4 1
A status() 0 8 1
A update() 0 4 1
A delete() 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 LaravelGoogleIndexing
10
{
11
    /** @var Google_Client */
12
    private $googleClient;
13
14
    /** @var Google_Service_Indexing */
15
    private $indexingService;
16
17
    public function __construct()
18
    {
19
        $this->googleClient = new Google_Client();
20
21
        $this->googleClient->setAuthConfig(config('laravel-google-indexing.google.auth_config'));
22
23
        foreach (config('laravel-google-indexing.google.scopes', []) as $scope) {
24
            $this->googleClient->addScope($scope);
25
        }
26
27
        $this->indexingService = new Google_Service_Indexing($this->googleClient);
28
    }
29
30
    public static function create(): self
31
    {
32
        return new static();
33
    }
34
35
    public function status(string $url)
36
    {
37
        return $this->indexingService
38
            ->urlNotifications
39
            ->getMetadata([
40
                'url' => urlencode($url),
41
            ]);
42
    }
43
44
    public function update(string $url)
45
    {
46
        return $this->publish($url, 'URL_UPDATED');
47
    }
48
49
    public function delete(string $url)
50
    {
51
        return $this->publish($url, 'URL_DELETED');
52
    }
53
54
    private function publish(string $url, string $action)
55
    {
56
        $urlNotification = new Google_Service_Indexing_UrlNotification();
57
58
        $urlNotification->setUrl($url);
59
        $urlNotification->setType($action);
60
61
        return $this->indexingService
62
            ->urlNotifications
63
            ->publish($urlNotification);
64
    }
65
}
66