Passed
Branch etl-core (c0e492)
by Jean Paul
01:52
created

StackOverflowSlackCommunicator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 22
c 1
b 0
f 0
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDataArray() 0 23 2
A setListOfJobs() 0 3 1
A send() 0 5 2
A getDatArray() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace Coco\SourceWatcher\Vendors\StackOverflow;
4
5
use Coco\SourceWatcher\Watcher\Communicator\SlackCommunicator;
6
7
class StackOverflowSlackCommunicator extends SlackCommunicator
8
{
9
    private array $dataArray;
10
11
    public function __construct ( array $listOfJobs )
12
    {
13
        parent::__construct();
14
15
        $this->buildDataArray( $listOfJobs );
16
    }
17
18
    public function setListOfJobs ( array $listOfJobs ) : void
19
    {
20
        $this->buildDataArray( $listOfJobs );
21
    }
22
23
    private function buildDataArray ( array $listOfJobs ) : void
24
    {
25
        $this->dataArray = array();
26
27
        foreach ( $listOfJobs as $currentJob ) {
28
            $currentArray = array( "blocks" => array() );
29
30
            array_push( $currentArray["blocks"], array( "type" => "divider" ) );
31
32
            $currentSection = array( "type" => "section", "text" => null, "accessory" => null );
33
34
            $text = "*" . $currentJob->getTitle() . "*" . PHP_EOL;
35
            $text .= $currentJob->getCompany() . " | " . $currentJob->getLocation() . PHP_EOL;
36
            $text .= "<" . $currentJob->getRefinedUrl() . ">";
37
            $currentSection["text"] = array( "type" => "mrkdwn", "text" => $text );
38
39
            $currentSection["accessory"] = array( "type" => "image", "image_url" => $currentJob->getLogo(), "alt_text" => $currentJob->getCompany() );
40
41
            array_push( $currentArray["blocks"], $currentSection );
42
43
            array_push( $currentArray["blocks"], array( "type" => "divider" ) );
44
45
            array_push( $this->dataArray, $currentArray );
46
        }
47
    }
48
49
    public function getDatArray () : array
50
    {
51
        return $this->dataArray;
52
    }
53
54
    public function send ()
55
    {
56
        foreach ( $this->dataArray as $currentSlackMessageBlock ) {
57
            $this->data = json_encode( $currentSlackMessageBlock );
58
            parent::send();
59
        }
60
    }
61
}
62