Completed
Pull Request — master (#3)
by Harry
03:17
created

ObjectToStringProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 4
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Format\Processor;
15
16
use InvalidArgumentException;
17
18
class ObjectToStringProcessor implements ProcessorInterface
19
{
20
    use InvokeProcessor;
21
22
    /**
23
     * Process the data within an array to ensure it is in the correct format
24
     *
25
     * @param array $row
26
     *
27
     * @return array
28
     */
29 15
    public function process(array $row)
30
    {
31 15
        foreach ($row as &$item) {
32 15
            if (is_object($item)) {
33 4
                if (method_exists($item, '__toString')) {
34 3
                    $item = $item->__toString();
35 3
                } else {
36 1
                    throw new InvalidArgumentException("Supplied object does not implement __toString");
37
                }
38 3
            }
39 14
        }
40
41 14
        return $row;
42
    }
43
}
44