Passed
Pull Request — master (#13)
by Joao
02:10
created

src/Formatter/BaseFormatter.php (1 issue)

Labels
Severity
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
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
}