ThirdPartyConnectionCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 32
rs 10
ccs 7
cts 7
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getByVendor() 0 7 2
A add() 0 3 1
1
<?php
2
/**
3
 * @author Tharanga Kothalawala <[email protected]>
4
 * @date 30-12-2018
5
 */
6
7
namespace TSK\SSO\ThirdParty;
8
9
use TSK\SSO\ThirdParty\Exception\UnknownVendorRequestException;
10
11
/**
12
 * @package TSK\SSO\ThirdParty
13
 *
14
 * Use this to hold multiple vendor connections if you require.
15
 */
16
class ThirdPartyConnectionCollection
17
{
18
    /**
19
     * VendorConnection[] list of configured vendor connections
20
     */
21
    private $vendorConnections;
22
23
    /**
24
     * Adds a configured vendor connection into the known list of connections.
25
     *
26
     * @param string $vendorName the third party vendor name. ex: google, facebook, linkedin etc
27
     * @param VendorConnection $vendorConnection
28
     */
29 2
    public function add($vendorName, VendorConnection $vendorConnection)
30
    {
31 2
        $this->vendorConnections[$vendorName] = $vendorConnection;
32 2
    }
33
34
    /**
35
     * Returns a requested vendor connection if available or throws an exception.
36
     *
37
     * @param string $vendorName the third party vendor name. ex: google, facebook, linkedin etc
38
     * @return VendorConnection
39
     * @throws UnknownVendorRequestException
40
     */
41 2
    public function getByVendor($vendorName)
42
    {
43 2
        if (!isset($this->vendorConnections[$vendorName])) {
44 1
            throw new UnknownVendorRequestException(sprintf('Given vendor \'%s\' is not yet configured', $vendorName));
45
        }
46
47 1
        return $this->vendorConnections[$vendorName];
48
    }
49
}
50