WriterFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 31
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 25 5
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