ServiceWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 70%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A write() 0 8 2
1
<?php
2
3
namespace Mathielen\DataImport\Writer;
4
5
use Ddeboer\DataImport\Exception\WriterException;
6
7
/**
8
 * Writes data to a given service.
9
 */
10
class ServiceWriter extends ObjectWriter
11
{
12
    /**
13
     * @var callable
14
     */
15
    private $callable;
16
17 5
    public function __construct(callable $callable, $classOrObjectFactory = null)
18
    {
19 5
        if (!is_callable($callable)) {
20
            throw new \InvalidArgumentException('Cannot call callable');
21
        }
22 5
        $this->callable = $callable;
23
24 5
        parent::__construct(new \SplObjectStorage(), $classOrObjectFactory);
25 5
    }
26
27 5
    protected function write($objectOrItem)
28
    {
29
        try {
30 5
            return call_user_func_array($this->callable, array($objectOrItem));
31
        } catch (\Exception $e) {
32
            throw new WriterException('Could not write item: '.print_r($objectOrItem, true), 0, $e);
33
        }
34
    }
35
}
36