ArffWriter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 66
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A writeItem() 0 4 1
A prepare() 0 5 1
A finish() 0 3 1
1
<?php
2
3
namespace Cocur\Arff\Bridge\Plum;
4
5
use Cocur\Arff\Document;
6
use Cocur\Arff\Column\ColumnInterface;
7
use Plum\Plum\Writer\WriterInterface;
8
use Cocur\Arff\Writer as Writer;
9
10
/**
11
 * ArffWriter
12
 *
13
 * @package   Cocur\Arff\Bridge\Plum
14
 * @author    Florian Eckerstorfer
15
 * @copyright 2015 Florian Eckerstorfer
16
 */
17
class ArffWriter implements WriterInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $filename;
23
24
    /**
25
     * @var Document
26
     */
27
    protected $document;
28
29
    /**
30
     * @var ArffWriter
31
     */
32
    protected $writer;
33
34
    /**
35
     * @param string            $filename
36
     * @param string            $name
37
     * @param ColumnInterface[] $columns
38
     *
39
     * @codeCoverageIgnore
40
     */
41
    public function __construct($filename, $name, array $columns)
42
    {
43
        $this->filename = $filename;
44
        $this->document = new Document($name);
45
        foreach ($columns as $column) {
46
            $this->document->addColumn($column);
47
        }
48
        $this->writer = new Writer();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Cocur\Arff\Writer() of type object<Cocur\Arff\Writer> is incompatible with the declared type object<Cocur\Arff\Bridge\Plum\ArffWriter> of property $writer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
    }
50
51
    /**
52
     * Write the given item.
53
     *
54
     * @param mixed $item
55
     *
56
     * @return void
57
     */
58 1
    public function writeItem($item)
59
    {
60 1
        file_put_contents($this->filename, $this->writer->renderRow($this->document, $item), FILE_APPEND);
0 ignored issues
show
Bug introduced by
The method renderRow() does not seem to exist on object<Cocur\Arff\Bridge\Plum\ArffWriter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61 1
    }
62
63
    /**
64
     * Prepare the writer.
65
     *
66
     * @return void
67
     */
68 1
    public function prepare()
69
    {
70 1
        $writer = new Writer();
71 1
        $writer->write($this->document, $this->filename);
72 1
    }
73
74
    /**
75
     * Finish the writer.
76
     *
77
     * @return void
78
     */
79 1
    public function finish()
80
    {
81 1
    }
82
}
83