WriterFactory::create()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 22
cp 0
rs 8.439
c 0
b 0
f 0
cc 5
eloc 19
nc 5
nop 1
crap 30
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\factory;
11
12
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
13
use Box\Spout\Writer\WriterFactory as BaseFactory;
14
use dosamigos\exportable\helpers\TypeHelper;
15
use dosamigos\exportable\writers\HtmlWriter;
16
use dosamigos\exportable\writers\JsonWriter;
17
use dosamigos\exportable\writers\TextWriter;
18
use dosamigos\exportable\writers\XmlWriter;
19
20
class WriterFactory extends BaseFactory
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    public static function create($writerType)
26
    {
27
        $writer = null;
0 ignored issues
show
Unused Code introduced by
$writer is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
29
        switch ($writerType) {
30
            case TypeHelper::TXT:
31
                $writer = new TextWriter();
32
                break;
33
            case TypeHelper::JSON:
34
                $writer = new JsonWriter();
35
                break;
36
            case TypeHelper::XML:
37
                $writer = new XmlWriter();
38
                break;
39
            case TypeHelper::HTML:
40
                $writer = new HtmlWriter();
41
                break;
42
            default:
43
                return parent::create($writerType);
44
        }
45
46
        $writer->setGlobalFunctionsHelper(new GlobalFunctionsHelper());
47
48
        return $writer;
49
    }
50
}
51