Completed
Pull Request — master (#3)
by Harry
05:31
created

ObjectToStringProcessor::process()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.2
cc 4
eloc 8
nc 4
nop 1
crap 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 13
    public function process(array $row)
30
    {
31 13
        foreach ($row as &$item) {
32 13
            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 12
        }
40
41 12
        return $row;
42
    }
43
}
44