FileFactory::createFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 9

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 namespace Nord\Lumen\FileManager\Doctrine;
2
3
use Carbon\Carbon;
4
use Nord\Lumen\FileManager\Contracts\FileFactory as FileFactoryContract;
5
6
class FileFactory implements FileFactoryContract
7
{
8
9
    /**
10
     * @var string Full namespace of class to use when creating files
11
     */
12
    protected $fileClass;
13
14
    /**
15
     * FileFactory constructor
16
     * @param string $fileClass
17
     */
18
    public function __construct($fileClass)
19
    {
20
        $this->setFileClass($fileClass);
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function createFile($id, $name, $extension, $path, $mimeType, $byteSize, $data, $disk, Carbon $savedAt)
27
    {
28
        $class = $this->getFileClass();
29
        return new $class($id, $name, $extension, $path, $mimeType, $byteSize, $data, $disk, $savedAt);
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    protected function getFileClass()
36
    {
37
        return $this->fileClass;
38
    }
39
40
    /**
41
     * @param string $fileClass
42
     */
43
    protected function setFileClass($fileClass)
44
    {
45
        $this->fileClass = $fileClass;
46
    }
47
}
48