Code Duplication    Length = 85-87 lines in 5 locations

core/services/graphql/connections/ConnectionCollection.php 1 location

@@ 21-106 (lines=86) @@
18
 * @author  Brent Christensen
19
 * @since   $VID:$
20
 */
21
class ConnectionCollection extends Collection
22
{
23
24
    const COLLECTION_NAME = 'espresso_graphql_connections';
25
26
    /**
27
     * @var CollectionLoader $loader
28
     */
29
    protected $loader;
30
31
    /**
32
     * ConnectionCollection constructor
33
     *
34
     * @throws InvalidInterfaceException
35
     */
36
    public function __construct()
37
    {
38
        parent::__construct(
39
            'EventEspresso\core\services\graphql\connections\ConnectionInterface',
40
            ConnectionCollection::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
                    ConnectionCollection::COLLECTION_NAME,
57
                    // collection interface
58
                    'EventEspresso\core\services\graphql\connections\ConnectionInterface',
59
                    // FQCNs for classes to add (all classes within each namespace will be loaded)
60
                    apply_filters(
61
                        'FHEE__EventEspresso_core_services_graphql_ConnectionCollection__loadCollection__collection_FQCNs',
62
                        ['EventEspresso\core\domain\services\graphql\connections']
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 loadConnections()
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
}
107

core/services/graphql/enums/EnumCollection.php 1 location

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

core/services/graphql/inputs/InputCollection.php 1 location

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

core/services/graphql/resolvers/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
}
107

core/services/graphql/types/TypeCollection.php 1 location

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