Factory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 61
loc 61
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A __clone() 3 3 1
A create() 12 12 3
A getClassNameForDriver() 4 4 1
A getInstance() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace FMUP\Ftp;
3
4 View Code Duplication
class Factory
0 ignored issues
show
Duplication introduced by
This class 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...
5
{
6
    const DRIVER_FTP = 'Ftp';
7
    const DRIVER_SFTP = 'Sftp';
8
    const DRIVER_FTP_IMPLICIT_SSL = 'FtpImplicitSSL';
9
10
    private static $instance;
11
    
12 1
    private function __construct()
13
    {
14 1
    }
15
16
    /**
17
     * Design pattern Singleton
18
     * @codeCoverageIgnore
19
     */
20
    private function __clone()
21
    {
22
    }
23
24
    /**
25
     * @return self
26
     */
27 4
    final public static function getInstance()
28
    {
29 4
        if (!self::$instance) {
30 1
            $class = get_called_class();
31 1
            self::$instance = new $class;
32
        }
33 4
        return self::$instance;
34
    }
35
36
    /**
37
     * @param string $driver
38
     * @param array $params
39
     * @return FtpInterface
40
     * @throws Exception
41
     */
42 4
    final public function create($driver = self::DRIVER_FTP, $params = array())
43
    {
44 4
        $class = $this->getClassNameForDriver($driver);
45 4
        if (!class_exists($class)) {
46 1
            throw new Exception('Unable to create ' . $class);
47
        }
48 3
        $instance = new $class($params);
49 3
        if (!$instance instanceof FtpInterface) {
50 1
            throw new Exception('Unable to create ' . $class);
51
        }
52 2
        return $instance;
53
    }
54
55
    /**
56
     * Get full class name to create
57
     * @param string $driver
58
     * @return string
59
     */
60 2
    protected function getClassNameForDriver($driver)
61
    {
62 2
        return __NAMESPACE__ . '\Driver\\' . $driver;
63
    }
64
}
65