Map   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 21 1
A factories() 0 23 1
1
<?php
2
3
namespace lloc\Msls\ContentImport\Importers;
4
5
use lloc\Msls\ContentImport\ImportCoordinates;
6
use lloc\Msls\MslsRegistryInstance;
7
8
class Map extends MslsRegistryInstance {
9
	/**
10
	 * Builds and returns an array of importers for the specified import coordinates.
11
	 *
12
	 * @param ImportCoordinates $import_coordinates
13
	 *
14
	 * @return array An array of importer instances in the shape [ <string: slug> => <Importer: $importer> ]
15
	 */
16
	public function make( ImportCoordinates $import_coordinates ) {
17
		$importers = array_map( function ( $factory ) use ( $import_coordinates ) {
18
			/** @var ImportersFactory $factory */
19
			return $factory->make( $import_coordinates );
20
		}, $this->factories() );
21
22
		/**
23
		 * Filters the map of importers that should be used.
24
		 *
25
		 * While the filter `msls_content_import_importers_factories_map` will allow filtering the factories this
26
		 * will directly modify the built importers.
27
		 *
28
		 * @param array $importers An array of importers in the shape [ <string: $slug> => <Importer: $importer> ]
29
		 * @param ImportCoordinates $import_coordinates
30
		 *
31
		 * @see Map::factories()
32
		 */
33
		$importers = apply_filters( 'msls_content_import_importers_map', $importers, $import_coordinates );
34
35
		return $importers;
36
	}
37
38
	/**
39
	 * Returns a filtered list of factories that will provide the importers.
40
	 *
41
	 * @since TBD
42
	 *
43
	 * @return array An associative array in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
44
	 */
45
	public function factories() {
46
		$map = [
47
			'post-fields'    => PostFieldsImporters::instance(),
48
			'post-meta'      => PostMetaImporters::instance(),
49
			'terms'          => TermsImporters::instance(),
50
			'post-thumbnail' => PostThumbnailImporters::instance(),
51
			'attachments'    => AttachmentsImporters::instance(),
52
		];
53
54
		/**
55
		 * Filters the map of importer factories that should be used to build the importers.
56
		 *
57
		 * While the filter `msls_content_import_importers_map` will allow filtering the importers after they have been built
58
		 * by the factories this filter acts before allowing the modification of the factories before any importer is built.
59
		 *
60
		 * @param array $importers An array of importer factories in the shape [ <string: $slug> => <ImportersFactory: $factory> ]
61
		 *
62
		 * @see Map::make()
63
		 */
64
		$map = apply_filters( 'msls_content_import_importers_factories_map', $map );
65
66
		return $map;
67
	}
68
}