Code Duplication    Length = 86-86 lines in 3 locations

core/services/graphql/ConnectionCollection.php 1 location

@@ 39-124 (lines=86) @@
36
 * @author  Brent Christensen
37
 * @since   $VID:$
38
 */
39
class ConnectionCollection extends Collection
40
{
41
42
    const COLLECTION_NAME = 'espresso_graphql_connections';
43
44
    /**
45
     * @var CollectionLoader $loader
46
     */
47
    protected $loader;
48
49
    /**
50
     * ConnectionCollection constructor
51
     *
52
     * @throws InvalidInterfaceException
53
     */
54
    public function __construct()
55
    {
56
        parent::__construct(
57
            'EventEspresso\core\services\graphql\ConnectionInterface',
58
            ConnectionCollection::COLLECTION_NAME
59
        );
60
    }
61
62
63
    /**
64
     * @throws CollectionDetailsException
65
     * @throws CollectionLoaderException
66
     * @since $VID:$
67
     */
68
    private function loadCollection()
69
    {
70
        if (! $this->loader instanceof CollectionLoader) {
71
            $this->loader = new CollectionLoader(
72
                new CollectionDetails(
73
                // collection name
74
                    ConnectionCollection::COLLECTION_NAME,
75
                    // collection interface
76
                    'EventEspresso\core\services\graphql\ConnectionInterface',
77
                    // FQCNs for classes to add (all classes within each namespace will be loaded)
78
                    apply_filters(
79
                        'FHEE__EventEspresso_core_services_graphql_ConnectionCollection__loadCollection__collection_FQCNs',
80
                        ['EventEspresso\core\domain\services\graphql\connections']
81
                    ),
82
                    // filepaths to classes to add
83
                    array(),
84
                    // file mask to use if parsing folder for files to add
85
                    '',
86
                    // what to use as identifier for collection entities
87
                    // using CLASS NAME prevents duplicates (works like a singleton)
88
                    CollectionDetails::ID_CLASS_NAME
89
                ),
90
                $this
91
            );
92
        }
93
    }
94
95
96
    /**
97
     * @return CollectionInterface
98
     * @throws CollectionDetailsException
99
     * @throws CollectionLoaderException
100
     * @since $VID:$
101
     */
102
    public function loadConnections()
103
    {
104
        $this->loadCollection();
105
        return $this->loader->getCollection();
106
    }
107
108
109
    /**
110
     * getIdentifier
111
     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
112
     * If no $identifier is supplied, then the  fully qualified class name is used
113
     *
114
     * @param        $object
115
     * @param mixed  $identifier
116
     * @return bool
117
     */
118
    public function getIdentifier($object, $identifier = null)
119
    {
120
        return ! empty($identifier)
121
            ? $identifier
122
            : get_class($object);
123
    }
124
}

core/services/graphql/ResolverCollection.php 1 location

@@ 21-106 (lines=86) @@
18
 * @author  Brent Christensen
19
 * @since   $VID:$
20
 */
21
class ResolverCollection extends Collection
22
{
23
24
    const COLLECTION_NAME = 'espresso_graphql_resolvers';
25
26
    /**
27
     * @var CollectionLoader $loader
28
     */
29
    protected $loader;
30
31
    /**
32
     * ResolverCollection constructor
33
     *
34
     * @throws InvalidInterfaceException
35
     */
36
    public function __construct()
37
    {
38
        parent::__construct(
39
            'EventEspresso\core\services\graphql\ResolverInterface',
40
            ResolverCollection::COLLECTION_NAME
41
        );
42
    }
43
44
45
    /**
46
     * @throws CollectionDetailsException
47
     * @throws CollectionLoaderException
48
     * @since $VID:$
49
     */
50
    private function loadCollection()
51
    {
52
        if (! $this->loader instanceof CollectionLoader) {
53
            $this->loader = new CollectionLoader(
54
                new CollectionDetails(
55
                // collection name
56
                    ResolverCollection::COLLECTION_NAME,
57
                    // collection interface
58
                    'EventEspresso\core\services\graphql\ResolverInterface',
59
                    // FQCNs for classes to add (all classes within each namespace will be loaded)
60
                    apply_filters(
61
                        'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs',
62
                        ['EventEspresso\core\domain\services\graphql\resolvers']
63
                    ),
64
                    // filepaths to classes to add
65
                    array(),
66
                    // file mask to use if parsing folder for files to add
67
                    '',
68
                    // what to use as identifier for collection entities
69
                    // using CLASS NAME prevents duplicates (works like a singleton)
70
                    CollectionDetails::ID_CLASS_NAME
71
                ),
72
                $this
73
            );
74
        }
75
    }
76
77
78
    /**
79
     * @return CollectionInterface
80
     * @throws CollectionDetailsException
81
     * @throws CollectionLoaderException
82
     * @since $VID:$
83
     */
84
    public function loadResolvers()
85
    {
86
        $this->loadCollection();
87
        return $this->loader->getCollection();
88
    }
89
90
91
    /**
92
     * getIdentifier
93
     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
94
     * If no $identifier is supplied, then the  fully qualified class name is used
95
     *
96
     * @param        $object
97
     * @param mixed  $identifier
98
     * @return bool
99
     */
100
    public function getIdentifier($object, $identifier = null)
101
    {
102
        return ! empty($identifier)
103
            ? $identifier
104
            : get_class($object);
105
    }
106
}

core/services/graphql/TypeCollection.php 1 location

@@ 39-124 (lines=86) @@
36
 * @author  Brent Christensen
37
 * @since   $VID:$
38
 */
39
class TypeCollection extends Collection
40
{
41
42
    const COLLECTION_NAME = 'espresso_graphql_types';
43
44
    /**
45
     * @var CollectionLoader $loader
46
     */
47
    protected $loader;
48
49
    /**
50
     * TypeCollection constructor
51
     *
52
     * @throws InvalidInterfaceException
53
     */
54
    public function __construct()
55
    {
56
        parent::__construct(
57
            'EventEspresso\core\services\graphql\TypeInterface',
58
            TypeCollection::COLLECTION_NAME
59
        );
60
    }
61
62
63
    /**
64
     * @throws CollectionDetailsException
65
     * @throws CollectionLoaderException
66
     * @since $VID:$
67
     */
68
    private function loadCollection()
69
    {
70
        if (! $this->loader instanceof CollectionLoader) {
71
            $this->loader = new CollectionLoader(
72
                new CollectionDetails(
73
                // collection name
74
                    TypeCollection::COLLECTION_NAME,
75
                    // collection interface
76
                    'EventEspresso\core\services\graphql\TypeInterface',
77
                    // FQCNs for classes to add (all classes within each namespace will be loaded)
78
                    apply_filters(
79
                        'FHEE__EventEspresso_core_services_graphql_TypeCollection__loadCollection__collection_FQCNs',
80
                        ['EventEspresso\core\domain\services\graphql\types']
81
                    ),
82
                    // filepaths to classes to add
83
                    array(),
84
                    // file mask to use if parsing folder for files to add
85
                    '',
86
                    // what to use as identifier for collection entities
87
                    // using CLASS NAME prevents duplicates (works like a singleton)
88
                    CollectionDetails::ID_CLASS_NAME
89
                ),
90
                $this
91
            );
92
        }
93
    }
94
95
96
    /**
97
     * @return CollectionInterface
98
     * @throws CollectionDetailsException
99
     * @throws CollectionLoaderException
100
     * @since $VID:$
101
     */
102
    public function loadTypes()
103
    {
104
        $this->loadCollection();
105
        return $this->loader->getCollection();
106
    }
107
108
109
    /**
110
     * getIdentifier
111
     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
112
     * If no $identifier is supplied, then the  fully qualified class name is used
113
     *
114
     * @param        $object
115
     * @param mixed  $identifier
116
     * @return bool
117
     */
118
    public function getIdentifier($object, $identifier = null)
119
    {
120
        return ! empty($identifier)
121
            ? $identifier
122
            : get_class($object);
123
    }
124
}