Completed
Push — develop ( 5d0e16...a66ac3 )
by Carsten
05:49
created

DevelopingFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 51
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A __invoke() 0 14 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 51.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace FilmTools\Developing;
3
4
use FilmTools\Commons\Zones;
5
6
class DevelopingFactory
7
{
8
9
    /**
10
     * PHP class name (FQDN) of the DevelopingInterface instance this factory produces.
11
     *
12
     * @var string
13
     */
14
    public $developing_php_class;
15
16
17
    /**
18
     * @param string|null $developing_php_class DevelopingInterface instance FQDN
19
     *
20
     * @throws InvalidArgumentException         If FQDN does not implement DevelopingInterface
21
     */
22 6
    public function __construct( string $developing_php_class = null )
23
    {
24 6
        $this->developing_php_class = $developing_php_class ?: Developing::class;
25
26 6
        if (!is_subclass_of($this->developing_php_class, DevelopingInterface::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\Developing\DevelopingInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
27
            throw new \InvalidArgumentException("Class name must implement DevelopingInterface.");
28 6
    }
29
30
31
    /**
32
     * The factory method.
33
     *
34
     * Expects an array with at least elements "time", "densities", and "exposures".
35
     *
36
     * If no "exposures" are given, but "zones" numbers are instead, the zone numbers
37
     * will be converted internally.
38
     *
39
     * @param  array $developing
40
     * @return DevelopingInterface
41
     */
42 6
    public function __invoke( $developing )
43
    {
44 6
        $time      = $developing['time']      ?? null;
45 6
        $densities = $developing['densities'] ?? array();
46 6
        $zones     = $developing['zones']     ?? array();
47 6
        $exposures = $developing['exposures'] ?? array();
48
49 6
        if (empty($exposures) and !empty($zones)):
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
50 3
            $exposures = new Zones( $zones );
51
        endif;
52
53 6
        $developing_php_class = $this->developing_php_class;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $developing_php_class.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
54 6
        return new $developing_php_class( $exposures, $densities, $time );
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $developing_php_class.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
55
    }
56
}
57