BrokenLinksFound   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 13 2
A reportBrokenLink() 0 15 1
1
<?php
2
3
namespace Transmissor\Jobs\Webhook;
4
5
use Transmissor\Models\User;
6
use BotMan\Drivers\Telegram\TelegramDriver;
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Foundation\Bus\Dispatchable;
10
use Illuminate\Queue\InteractsWithQueue;
11
use Illuminate\Queue\SerializesModels;
12
13
class BrokenLinksFound implements ShouldQueue
14
{
15
16
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
17
18
    public $payload;
19
20
    /**
21
     * @var \BotMan\BotMan\BotMan 
22
     */
23
    public $botman;
24
25
    /**
26
     * @var \Transmissor\Models\User 
27
     */
28
    public $user;
29
30
    public function __construct($payload, User $user)
31
    {
32
        $this->payload = $payload;
33
        $this->user = $user;
34
        $this->botman = resolve('botman');
35
    }
36
37
    public function handle()
38
    {
39
        $this->botman->say(
40
            trans('Transmissor.webhook.broken_links_found', ['url' => $this->payload->site->url]),
41
            $this->user->telegram_id,
42
            TelegramDriver::class,
43
            ['disable_web_page_preview' => true]
44
        );
45
46
        foreach ($this->payload->run->result_payload->broken_links as $brokenLink) {
47
            $this->reportBrokenLink($brokenLink);
48
        }
49
    }
50
51
    private function reportBrokenLink($link)
52
    {
53
        $this->botman->say(
54
            trans(
55
                'Transmissor.brokenlinks.result', [
56
                'url' => $link->crawled_url,
57
                'code' => $link->status_code,
58
                'origin' => $link->found_on_url,
59
                ]
60
            ),
61
            $this->user->telegram_id,
62
            TelegramDriver::class,
63
            ['disable_web_page_preview' => true]
64
        );
65
    }
66
}
67