Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/DevelopingFactory.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace FilmTools\Developing;
3
4
use FilmTools\Commons\Zones;
5
use FilmTools\Commons\FStops;
6
use FilmTools\Commons\Exposures;
7
use FilmTools\Commons\ExposuresProviderInterface;
8
use FilmTools\Commons\Densities;
9
use FilmTools\Commons\DensitiesProviderInterface;
10
11
class DevelopingFactory
12
{
13
14
    /**
15
     * PHP class name (FQDN) of the DevelopingInterface instance this factory produces.
16
     *
17
     * @var string
18
     */
19
    public $developing_php_class;
20
21
22
    /**
23
     * Field names that may contain density values.
24
     * (Sort order from "most" to "least" specific)
25
     *
26
     * @var array
27
     */
28
    public $density_fields = array("logD", "density", "densities");
29
30
31
    /**
32
     * Field names that may contain exposures values.
33
     * (Sort order from "most" to "least" specific)
34
     *
35
     * @var array
36
     */
37
    public $exposure_fields = array("logH", "exposure", "exposures");
38
39
40
    /**
41
     * @param string|null $developing_php_class DevelopingInterface instance FQDN
42
     *
43
     * @throws InvalidArgumentException If FQDN does not implement DevelopingInterface
44
     */
45 51
    public function __construct( string $developing_php_class = null )
46
    {
47 51
        $this->developing_php_class = $developing_php_class ?: Developing::class;
48
49 51
        if (!is_subclass_of($this->developing_php_class, DevelopingInterface::class )):
0 ignored issues
show
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...
50 3
            $msg = sprintf("Class name must implement '%s'.", DevelopingInterface::class);
51 3
            throw new DevelopingInvalidArgumentException( $msg );
52
        endif;
53 48
    }
54
55
56
    /**
57
     * The factory method.
58
     *
59
     * Expects an array or ArrayAccess with at least elements "time", "densities", and "exposures".
60
     *
61
     * If no "exposures" are given, but "zones" numbers are instead, the zone numbers
62
     * will be converted internally.
63
     *
64
     * @param  array|ArrayAccess $developing
65
     * @return DevelopingInterface
66
     */
67 48
    public function __invoke( $developing ) : DevelopingInterface
68
    {
69 48
        if (!is_array($developing) and !$developing instanceOf \ArrayAccess)
70 3
            throw new DevelopingInvalidArgumentException("Array or ArrayAccess expected");
71
72 45
        $densities = $this->extractDensities($developing);
73 45
        $exposures = $this->extractExposures($developing);
74 45
        $time      = $this->extractTime($developing);
75
76 24
        $developing_php_class = $this->developing_php_class;
77 24
        return new $developing_php_class( $exposures, $densities, $time );
78
    }
79
80
81 45
    protected function extractDensities( $developing ) : DensitiesProviderInterface
82
    {
83 45
        $density_fields = $this->density_fields;
84 45
        $densities = array();
85
86 45
        while (($field = array_shift($density_fields)) and empty($densities)):
87 45
            $densities = $developing[ $field ] ?? array();
88
        endwhile;
89
90 45
        return new Densities($densities);
91
    }
92
93
94 45
    protected function extractExposures( $developing ) : ExposuresProviderInterface
95
    {
96
97 45
        $exposure_fields = $this->exposure_fields;
98 45
        $exposures = array();
99
100 45
        while (($field = array_shift($exposure_fields)) and empty($exposures)):
101 45
            $exposures = $developing[ $field ] ?? array();
102
        endwhile;
103
104 45
        if (!empty($exposures)):
105 3
            return new Exposures( $exposures );
106
        endif;
107
108
        // So if "exposures" are empty, try to make some
109
        // using fstops and zone numbers
110 42
        $fstops = ($developing['fstop'] ?? array()) ?: $developing['fstops'] ?? array();
111 42
        $zones  = ($developing['zone']  ?? array()) ?: $developing['zones']  ?? array();
112
113 42
        if (empty($exposures) and !empty($zones)):
114 30
            $exposures = new Zones( $zones );
115 12
        elseif (empty($exposures) and !empty($fstops)):
116 3
            $exposures = new FStops( $fstops );
117
        else:
118
            // Found nothing, give up
119 9
            $exposures = new Exposures( array() );
120
        endif;
121
122 42
        return $exposures;
123
    }
124
125
126 45
    protected function extractTime( $developing ) : int
127
    {
128 45
        if (!array_key_exists("time", $developing)
129 45
        and !array_key_exists("seconds", $developing))
130 3
            throw new NoTimeGivenException("The data array must contain either 'time' or 'seconds' element.");
131
132 42
        if (empty($time = $developing['seconds'] ?? false)
133 42
        and empty($time = $developing['time'] ?? false)):
134 12
            throw new NoTimeGivenException("At least one element in 'seconds' or 'time' expected");
135
        endif;
136
137
        // Remove surfluous time values
138 30
        if (is_array($time)):
139 9
            $time = array_unique($time);
140 9
            $count_times = count($time);
141 9
            if ($count_times > 1):
142 3
                $msg = sprintf("There must only be one developing time, %s given", $count_times);
143 3
                throw new NoTimeGivenException($msg);
144
            endif;
145 6
            $time = array_shift($time);
146
        endif;
147
148 27
        if (filter_var($time, \FILTER_VALIDATE_INT, ['options' => array( 'min_range' => 0 )]) === false)
149 3
            throw new NoTimeGivenException("The developing time must be integer (positive or 0).");
150
151 24
        return $time;
152
    }
153
}
154