Completed
Branch tooling/eslint-plugin-react (cf30c8)
by
unknown
110:10 queued 101:37
created

ConnectionsManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 0 5 1
A registerConnections() 0 7 2
1
<?php
2
3
namespace EventEspresso\core\services\graphql;
4
5
use EventEspresso\core\services\collections\CollectionDetailsException;
6
use EventEspresso\core\services\collections\CollectionLoaderException;
7
use EventEspresso\core\services\graphql\connections\ConnectionCollection;
8
use EventEspresso\core\services\graphql\connections\ConnectionInterface;
9
10
/**
11
 * Class ConnectionsManager
12
 * Loads and registers custom GraphQL Connections
13
 *
14
 * @package EventEspresso\core\services\graphql
15
 * @author  Brent Christensen
16
 * @since   $VID:$
17
 */
18
class ConnectionsManager
19
{
20
21
    /**
22
     * @var ConnectionCollection|ConnectionInterface[] $connections
23
     */
24
    private $connections;
25
26
27
    /**
28
     * ConnectionsManager constructor.
29
     *
30
     * @param ConnectionCollection|ConnectionInterface[] $connections
31
     */
32
    public function __construct(ConnectionCollection $connections)
33
    {
34
        $this->connections = $connections;
35
    }
36
37
38
    /**
39
     * @throws CollectionDetailsException
40
     * @throws CollectionLoaderException
41
     * @since $VID:$
42
     */
43
    public function init()
44
    {
45
        $this->connections->loadConnections();
46
        add_action('graphql_register_types', [$this, 'registerConnections'], 20);
47
    }
48
49
50
    public function registerConnections()
51
    {
52
        // loop through the collection of types and register their fields
53
        foreach ($this->connections as $connection) {
54
            register_graphql_connection($connection->config());
55
        }
56
    }
57
}