ExposuresFactory   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 53
loc 53
c 0
b 0
f 0
ccs 18
cts 19
cp 0.9474
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 3
A fromValues() 10 10 3
A fromKeys() 10 10 3

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 FilmTools\Commons;
3
4
5 View Code Duplication
class ExposuresFactory
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...
6
{
7
8
    /**
9
     * @var string
10
     */
11
    public $php_exposures_class;
12
13
14
    /**
15
     * @param string|null $php_exposures_class
16
     */
17 30
    public function __construct( string $php_exposures_class = null )
18
    {
19 30
        $this->php_exposures_class = $php_exposures_class ?: Exposures::class;
20
21 30
        if (!is_subclass_of($this->php_exposures_class, ExposuresInterface::class ))
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \FilmTools\Commons\ExposuresInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
22 3
            throw new FilmToolsInvalidArgumentException("Class name must implement ExposuresInterface.");
23
24 27
    }
25
26
27
    /**
28
     * @param  array  $data
29
     * @return ExposuresInterface
30
     */
31 18
    public function fromValues( $data ) : ExposuresInterface
32
    {
33 18
        if ($data instanceOf \Traversable )
34 6
            $data = iterator_to_array( $data );
35 12
        else if (!is_array($data))
36 9
            throw new FilmToolsInvalidArgumentException("Array or Traversable expected");
37
38 9
        $php_class = $this->php_exposures_class;
39 9
        return new $php_class( array_values( $data ));
40
    }
41
42
43
    /**
44
     * @param  array  $data
45
     * @return ExposuresInterface
46
     */
47 9
    public function fromKeys( $data ) : ExposuresInterface
48
    {
49 9
        if ($data instanceOf \Traversable )
50 6
            $data = iterator_to_array( $data );
51 3
        else if (!is_array($data))
52
            throw new FilmToolsInvalidArgumentException("Array or Traversable expected");
53
54 9
        $php_class = $this->php_exposures_class;
55 9
        return new $php_class( array_keys( $data ));
56
    }
57
}
58