SpreadsheetLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Akeneo\Component\SpreadsheetParser\Xlsx;
4
5
use Akeneo\Component\SpreadsheetParser\SpreadsheetLoaderInterface;
6
7
/**
8
 * XLSX file reader
9
 *
10
 * @author    Antoine Guigan <[email protected]>
11
 * @copyright 2014 Akeneo SAS (http://www.akeneo.com)
12
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
13
 */
14
class SpreadsheetLoader implements SpreadsheetLoaderInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $spreadsheetClass;
20
21
    /**
22
     * @var RelationshipsLoader
23
     */
24
    protected $relationshipsLoader;
25
26
    /**
27
     * @var SharedStringsLoader
28
     */
29
    protected $sharedStringsLoader;
30
31
    /**
32
     * @var StylesLoader
33
     */
34
    protected $stylesLoader;
35
36
    /**
37
     * @var WorksheetListReader
38
     */
39
    protected $worksheetListReader;
40
41
    /**
42
     * @var ValueTransformerFactory
43
     */
44
    protected $valueTransformerFactory;
45
46
    /**
47
     * @var RowIteratorFactory
48
     */
49
    protected $rowIteratorFactory;
50
51
    /**
52
     * @var ArchiveLoader
53
     */
54
    protected $archiveLoader;
55
56
    /**
57
     * Constructor
58
     *
59
     * @param ArchiveLoader           $archiveLoader
60
     * @param RelationshipsLoader     $relationshipsLoader
61
     * @param SharedStringsLoader     $sharedStringsLoader
62
     * @param StylesLoader            $stylesLoader
63
     * @param WorksheetListReader     $worksheetListReader
64
     * @param ValueTransformerFactory $valueTransformerFactory
65
     * @param RowIteratorFactory      $rowIteratorFactory
66
     * @param string                  $spreadsheetClass
67
     */
68 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
        ArchiveLoader $archiveLoader,
70
        RelationshipsLoader $relationshipsLoader,
71
        SharedStringsLoader $sharedStringsLoader,
72
        StylesLoader $stylesLoader,
73
        WorksheetListReader $worksheetListReader,
74
        ValueTransformerFactory $valueTransformerFactory,
75
        RowIteratorFactory $rowIteratorFactory,
76
        $spreadsheetClass
77
    ) {
78
        $this->relationshipsLoader = $relationshipsLoader;
79
        $this->sharedStringsLoader = $sharedStringsLoader;
80
        $this->stylesLoader = $stylesLoader;
81
        $this->worksheetListReader = $worksheetListReader;
82
        $this->valueTransformerFactory = $valueTransformerFactory;
83
        $this->rowIteratorFactory = $rowIteratorFactory;
84
        $this->archiveLoader = $archiveLoader;
85
        $this->spreadsheetClass = $spreadsheetClass;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function open($path, $type = null)
92
    {
93
        $archive = $this->archiveLoader->open($path);
94
95
        return new $this->spreadsheetClass(
96
            $archive,
97
            $this->relationshipsLoader,
98
            $this->sharedStringsLoader,
99
            $this->stylesLoader,
100
            $this->worksheetListReader,
101
            $this->valueTransformerFactory,
102
            $this->rowIteratorFactory
103
        );
104
    }
105
106
}
107