HtmlWriter::openWriter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-exportable-widget project.
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace dosamigos\exportable\writers;
11
12
use Box\Spout\Writer\AbstractWriter;
13
use Yii;
14
15
class HtmlWriter extends AbstractWriter
16
{
17
    /**
18
     * @var string the path to the view files
19
     */
20
    protected $viewPath;
21
22
    /**
23
     * HtmlWriter constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->viewPath = dirname(__FILE__) . '/../views/html';
28
        parent::__construct();
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    protected function openWriter()
35
    {
36
        $header = Yii::$app->view->renderPhpFile($this->viewPath . '/_header.php');
37
        fwrite($this->filePointer, $header);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    protected function addRowToWriter(array $dataRow, $style)
44
    {
45
        $row = '<tr>' . implode("\n", $dataRow) . '</tr>';
46
        fwrite($this->filePointer, $row);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    protected function closeWriter()
53
    {
54
        $footer = Yii::$app->view->renderPhpFile($this->viewPath . '/_footer.php');
55
        fwrite($this->filePointer, $footer);
56
    }
57
}
58