Exporter::export()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4286
cc 3
eloc 5
nc 3
nop 4
1
<?php
2
3
namespace Ob\CmsBundle\Export;
4
5
class Exporter implements ExporterInterface
6
{
7
    private $exporters = array();
8
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function export($filename, $format, $data, $fields)
13
    {
14
        foreach ($this->exporters as $exporter) {
15
            if ($exporter->supports($format)) {
16
                return $exporter->export($filename, $format, $data, $fields);
17
            }
18
        }
19
20
        throw new \InvalidArgumentException(sprintf('There are no exporters for format %s.', $format));
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function supports($format)
27
    {
28
        foreach ($this->exporters as $exporter) {
29
            if ($exporter->supports($format)) {
30
                return true;
31
            }
32
        }
33
34
        return false;
35
    }
36
37
    /**
38
     * Add an exporter
39
     *
40
     * @param ExporterInterface $exporter
41
     */
42
    public function addExporter(ExporterInterface $exporter)
43
    {
44
        $this->exporters[] = $exporter;
45
    }
46
}
47