BaseFormatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
dl 0
loc 37
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;
0 ignored issues
show
Bug introduced by
The type \ByJG\AnyDataset\Core\Row was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use InvalidArgumentException;
8
9
abstract class BaseFormatter implements FormatterInterface
10
{
11
    /**
12
     * @var GenericIterator|Row
13
     */
14
    protected $object;
15
16
    /**
17
     * @inheritDoc
18
     */
19
    abstract public function raw();
20
21
    /**
22
     * @inheritDoc
23
     */
24
    abstract public function toText();
25
26
    /**
27
     * @inheritDoc
28
     */
29 2
    public function saveToFile($filename)
30
    {
31 2
        if (empty($filename)) {
32
            throw new InvalidArgumentException("Filename cannot be empty"); 
33
        }
34 2
        file_put_contents($filename, $this->toText());
35
    }
36
37
    /**
38
     * @param GenericIterator|Row $object
39
     */
40 7
    public function __construct($object)
41
    {
42 7
        if (!($object instanceof GenericIterator) && !($object instanceof Row)) {
43
            throw new InvalidArgumentException("Constructor must have a GenericIterator or Row instance in the argument");
44
        }
45 7
        $this->object = $object;
46
    }
47
}