Passed
Pull Request — master (#10)
by Joao
01:36
created

BaseFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
dl 0
loc 28
ccs 6
cts 8
cp 0.75
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A saveToFile() 0 6 2
1
<?php
2
3
namespace ByJG\AnyDataset\Core\Formatter;
4
5
use ByJG\AnyDataset\Core\GenericIterator;
6
use \ByJG\AnyDataset\Core\Row;
7
use InvalidArgumentException;
8
9
abstract class BaseFormatter
10
{
11
    /**
12
     * @var GenericIterator|Row
13
     */
14
    protected $object;
15
16
    abstract public function raw();
17
18
    abstract public function toText();
19
20 2
    public function saveToFile($filename)
21
    {
22 2
        if (empty($filename)) {
23
            throw new InvalidArgumentException("Filename cannot be empty"); 
24
        }
25 2
        file_put_contents($filename, $this->toText());
26
    }
27
28
    /**
29
     * $object AnyDataset|Row
30
     */
31 7
    public function __construct($object)
32
    {
33 7
        if (!($object instanceof GenericIterator) && !($object instanceof Row)) {
34
            throw new InvalidArgumentException("Constructor must have a GenericIterator or Row instance in the argument");
35
        }
36 7
        $this->object = $object;
37
    }
38
}