DownloadService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 1
A clearBuffers() 0 6 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\services;
11
12
use dosamigos\exportable\contracts\DownloadServiceInterface;
13
use Yii;
14
15
class DownloadService implements DownloadServiceInterface
16
{
17
    /**
18
     * @inheritdoc
19
     */
20
    public function run($filename, $mime, $contents)
21
    {
22
        $this->clearBuffers();
23
24
        Yii::$app->getResponse()->sendContentAsFile($contents, $filename, ['mime' => $mime]);
25
26
        Yii::$app->end();
27
    }
28
29
    /**
30
     * Clean (erase) the output buffers and turns off output buffering
31
     */
32
    protected function clearBuffers()
33
    {
34
        while (ob_get_level() > 0) {
35
            ob_end_clean();
36
        }
37
    }
38
}
39