Completed
Push — master ( a35590...2bf349 )
by Anton
02:59
created

Facade::makeDecision()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Covery\Client;
4
5
use Psr\Log\LoggerInterface;
6
7
/**
8
 * Class Facade
9
 *
10
 * Static access facade to covery client
11
 *
12
 * @package Covery\Client
13
 */
14
class Facade
15
{
16
    /**
17
     * @var CredentialsInterface
18
     */
19
    private static $credentials;
20
    /**
21
     * @var TransportInterface
22
     */
23
    private static $transport;
24
    /**
25
     * @var PublicAPIClient
26
     */
27
    private static $client;
28
    /**
29
     * @var LoggerInterface|null
30
     */
31
    private static $logger;
32
33
    /**
34
     * Set logger
35
     *
36
     * @param LoggerInterface $logger
37
     */
38
    public static function setLogger(LoggerInterface $logger)
39
    {
40
        self::$logger = $logger;
41
    }
42
43
    /**
44
     * Sets (or replaces) credentials
45
     *
46
     * @param CredentialsInterface $credentials
47
     */
48 View Code Duplication
    public static function setCredentials(CredentialsInterface $credentials)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        self::$credentials = $credentials;
51
        if (self::$transport !== null) {
52
            self::$client = new PublicAPIClient(self::$credentials, self::$transport, self::$logger);
53
        }
54
    }
55
56
    /**
57
     * Sets (or replaces) transport
58
     *
59
     * @param TransportInterface $transport
60
     */
61 View Code Duplication
    public static function setTransport(TransportInterface $transport)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        self::$transport = $transport;
64
        if (self::$credentials !== null) {
65
            self::$client = new PublicAPIClient(self::$credentials, self::$transport, self::$logger);
66
        }
67
    }
68
69
    /**
70
     * Sends request to Covery and returns access level, associated with
71
     * used credentials
72
     *
73
     * This method can be used for Covery health check and availability
74
     * On any problem (network, credentials, server side) this method
75
     * will throw an exception
76
     *
77
     * @return mixed
78
     * @throws Exception
79
     */
80
    public static function ping()
81
    {
82
        if (self::$client === null) {
83
            throw new Exception('Credentials and/or transport not provided');
84
        }
85
86
        return self::$client->ping();
87
    }
88
89
    /**
90
     * Sends envelope to Covery and returns it's ID on Covery side
91
     * Before sending, validation is performed
92
     *
93
     * @param EnvelopeInterface $envelope
94
     * @return int
95
     * @throws Exception
96
     */
97 View Code Duplication
    public static function sendEvent(EnvelopeInterface $envelope)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        if (self::$client === null) {
100
            throw new Exception('Credentials and/or transport not provided');
101
        }
102
103
        return self::$client->sendEvent($envelope);
104
    }
105
106
    /**
107
     * Sends envelope to Covery for analysis
108
     *
109
     * @param EnvelopeInterface $envelope
110
     * @return Result
111
     * @throws Exception
112
     */
113 View Code Duplication
    public static function makeDecision(EnvelopeInterface $envelope)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
    {
115
        if (self::$client === null) {
116
            throw new Exception('Credentials and/or transport not provided');
117
        }
118
119
        return self::$client->makeDecision($envelope);
120
    }
121
}
122