Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

engine/lib/metastrings.php (2 issues)

1
<?php
2
3
/**
4
 * Normalizes metadata / annotation option names to their corresponding metastrings name.
5
 *
6
 * @param array $options An options array
7
 * @return array
8
 * @access private
9
 */
10
function _elgg_normalize_metastrings_options(array $options = []) {
11
12
	// support either metastrings_type or metastring_type
13
	// because I've made this mistake many times and hunting it down is a pain...
14 591
	$type = elgg_extract('metastring_type', $options, null);
15 591
	$type = elgg_extract('metastrings_type', $options, $type);
16
17 591
	$options['metastring_type'] = $type;
18
19
	// support annotation_ and annotations_ because they're way too easy to confuse
20 591
	$prefixes = ['metadata_', 'annotation_', 'annotations_'];
21
22
	// map the metadata_* options to metastring_* options
23
	$map = [
24 591
		'names'                 => 'metastring_names',
25
		'values'                => 'metastring_values',
26
		'case_sensitive'        => 'metastring_case_sensitive',
27
		'owner_guids'           => 'metastring_owner_guids',
28
		'created_time_lower'    => 'metastring_created_time_lower',
29
		'created_time_upper'    => 'metastring_created_time_upper',
30
		'calculation'           => 'metastring_calculation',
31
		'ids'                   => 'metastring_ids',
32
	];
33
34 591
	foreach ($prefixes as $prefix) {
35 591
		$singulars = ["{$prefix}name", "{$prefix}value", "{$prefix}owner_guid", "{$prefix}id"];
36 591
		$options = _elgg_normalize_plural_options_array($options, $singulars);
37
38 591
		foreach ($map as $specific => $normalized) {
39 591
			$key = $prefix . $specific;
40 591
			if (isset($options[$key])) {
41 591
				$options[$normalized] = $options[$key];
42
			}
43
		}
44
	}
45
46 591
	return $options;
47
}
48
49
/**
50
 * Metastring unit tests
51
 *
52
 * @param string $hook  unit_test
53
 * @param string $type  system
54
 * @param array  $value Array of other tests
55
 *
56
 * @return array
57
 * @access private
58
 * @codeCoverageIgnore
59
 */
60
function _elgg_metastrings_test($hook, $type, $value) {
2 ignored issues
show
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
function _elgg_metastrings_test($hook, /** @scrutinizer ignore-unused */ $type, $value) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $hook is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
function _elgg_metastrings_test(/** @scrutinizer ignore-unused */ $hook, $type, $value) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
	$value[] = ElggCoreMetastringsTest::class;
62
	return $value;
63
}
64
65
/**
66
 * @see \Elgg\Application::loadCore Do not do work here. Just register for events.
67
 */
68
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
69 18
	$hooks->registerHandler('unit_test', 'system', '_elgg_metastrings_test');
70
};
71