Completed
Branch Gutenberg/block-manager (d3ae85)
by
unknown
81:22 queued 67:41
created

PersonalDataExporterManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 98.48 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 65
loc 66
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
B loadPrivateDataExporterCollection() 24 24 1
A hookInExporters() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace EventEspresso\core\services\privacy\export;
4
5
use EventEspresso\core\exceptions\InvalidClassException;
6
use EventEspresso\core\exceptions\InvalidDataTypeException;
7
use EventEspresso\core\exceptions\InvalidEntityException;
8
use EventEspresso\core\exceptions\InvalidFilePathException;
9
use EventEspresso\core\exceptions\InvalidIdentifierException;
10
use EventEspresso\core\exceptions\InvalidInterfaceException;
11
use EventEspresso\core\services\collections\CollectionDetails;
12
use EventEspresso\core\services\collections\CollectionInterface;
13
use EventEspresso\core\services\collections\CollectionLoader;
14
15
/**
16
 * Class PersonalDataExporterManager
17
 * Manages setting up the hooks to add the EE core and add-ons' privacy policies
18
 *
19
 * @package        Event Espresso
20
 * @author         Mike Nelson
21
 * @since          $VID:$
22
 */
23 View Code Duplication
class PersonalDataExporterManager
24
{
25
26
    public function __construct()
27
    {
28
        add_filter(
29
            'wp_privacy_personal_data_exporters',
30
            array($this, 'hookInExporters')
31
        );
32
    }
33
34
35
    /**
36
     * Adds EE's exporters to the list of WP exporters
37
     *
38
     * @param array $exporters
39
     * @return array
40
     */
41
    public function hookInExporters($exporters)
42
    {
43
        // load all the privacy policy stuff
44
        // add post policy text
45
        foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
46
            $exporters[ get_class($exporter) ] = array(
47
                'exporter_friendly_name' => $exporter->name(),
48
                'callback'               => array($exporter, 'export'),
49
            );
50
        }
51
        return $exporters;
52
    }
53
54
55
    /**
56
     * @return CollectionInterface|PersonalDataExporterInterface[]
57
     * @throws InvalidIdentifierException
58
     * @throws InvalidInterfaceException
59
     * @throws InvalidFilePathException
60
     * @throws InvalidEntityException
61
     * @throws InvalidDataTypeException
62
     * @throws InvalidClassException
63
     */
64
    protected function loadPrivateDataExporterCollection()
65
    {
66
        $loader = new CollectionLoader(
67
            new CollectionDetails(
68
                // collection name
69
                'personal_data_exporters',
70
                // collection interface
71
                'EventEspresso\core\services\privacy\export\PersonalDataExporterInterface',
72
                // FQCNs for classes to add (all classes within that namespace will be loaded)
73
                apply_filters(
74
                    'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
75
                    array('EventEspresso\core\domain\services\admin\privacy\export')
76
                ),
77
                // filepaths to classes to add
78
                array(),
79
                // file mask to use if parsing folder for files to add
80
                '',
81
                // what to use as identifier for collection entities
82
                // using CLASS NAME prevents duplicates (works like a singleton)
83
                CollectionDetails::ID_CLASS_NAME
84
            )
85
        );
86
        return $loader->getCollection();
87
    }
88
}
89
90
// End of file PersonalDataExporterManager.php
91
// Location: EventEspresso\core\domain\services\admin/PersonalDataExporterManager.php
92