Completed
Branch BUG-10381-asset-loading (2dbb93)
by
unknown
122:01 queued 110:40
created

FormatterBase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A formatArray() 0 15 2
1
<?php
2
namespace EventEspresso\core\services\formatters;
3
4
use EventEspresso\core\exceptions\InvalidDataTypeException;
5
6
defined('EVENT_ESPRESSO_VERSION') || exit;
7
8
9
10
/**
11
 * Class FormatterBase
12
 * Class for functionality often common among FormatterInterface implementations
13
 *
14
 * @package        Event Espresso
15
 * @author         Mike Nelson
16
 * @since          4.9.31.p
17
 */
18
abstract class FormatterBase implements FormatterInterface
19
{
20
21
    /**
22
     * Recursively applies the formatting to all VALUES in this multi-dimensional array
23
     *
24
     * @param array $input
25
     * @return array
26
     * @throws InvalidDataTypeException if $input is not an array
27
     */
28
    public function formatArray($input)
29
    {
30
        if (! is_array($input)) {
31
            throw new InvalidDataTypeException('input', $input, 'array');
32
        }
33
        //we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead
34
        $formatter = $this;
35
        array_walk_recursive(
36
            $input,
37
            function (&$value, $key) use ($formatter) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

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

Loading history...
38
                $value = $formatter->format($value);
39
            }
40
        );
41
        return $input;
42
    }}
43
// End of file FormatterBase.php
44
// Location: core\services\formatters/FormatterBase.php