Issues (319)

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/Column/Factory.php (8 issues)

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
/**
3
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid\Column;
8
9
use Nnx\DataGrid\Column\Exception\InvalidColumnException;
10
use Nnx\DataGrid\Column\Exception\InvalidNameException;
11
use Nnx\DataGrid\Column\Exception\InvalidSpecificationException;
12
use Zend\ServiceManager\FactoryInterface;
13
use Nnx\DataGrid\Mutator\MutatorInterface;
14
use Traversable;
15
use Zend\Http\Header\HeaderInterface;
16
use Zend\ServiceManager\MutableCreationOptionsInterface;
17
use Zend\ServiceManager\MutableCreationOptionsTrait;
18
use Zend\ServiceManager\ServiceLocatorInterface;
19
use ReflectionClass;
20
use Nnx\DataGrid\Mutator\Exception\RuntimeException;
21
22
23
/**
24
 * Class Factory
25
 * @package Nnx\DataGrid\Column
26
 */
27
class Factory implements MutableCreationOptionsInterface, FactoryInterface
28
{
29
    use GridColumnPluginManagerAwareTrait;
30
    use MutableCreationOptionsTrait;
31
32
33
    /**
34
     * Конструктор класса
35
     * @param array $options
36
     */
37
    public function __construct(array $options)
38
    {
39
        $this->setCreationOptions($options);
40
    }
41
42
    /**
43
     * @param array | Traversable $spec
44
     * @throws InvalidColumnException
45
     * @throws InvalidNameException
46
     * @throws InvalidSpecificationException
47
     */
48
    protected function validate($spec)
49
    {
50 View Code Duplication
        if (!is_array($spec) && !$spec instanceof Traversable) {
0 ignored issues
show
This code seems to be duplicated across 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...
51
            throw new InvalidSpecificationException(
52
                sprintf('Передана некорректная спецификация для создания колонки. Ожидается array или %s, прищел: %s',
53
                    Traversable::class,
54
                    gettype($spec)
55
                    )
56
            );
57
        }
58
        if (!array_key_exists('type', $spec) || !$spec['type']) {
59
            throw new InvalidColumnException('Не передан тип создаваемого столбца.');
60
        }
61
        if (!array_key_exists('name', $spec) || !$spec['name']) {
62
            throw new InvalidNameException('Не задано имя для колонки.');
63
        }
64
    }
65
66
    /**
67
     * Возвращщает набор мутаторов
68
     * @param array $spec
69
     * @return array
70
     * @throws RuntimeException
71
     */
72
    protected function getMutators($spec)
73
    {
74
        $mutators = [];
75
        if (array_key_exists('mutators', $spec) && $spec['mutators']) {
76
            $mutatorPluginManager = $this->getColumnPluginManager()->getServiceLocator()->get('GridMutatorManager');
77
            foreach ($spec['mutators'] as $mutator) {
78
                if (!$mutator instanceof MutatorInterface) {
79
                    if (is_array($mutator) && (!array_key_exists('type', $mutator) || !$mutator['type'])) {
80
                        throw new RuntimeException('Для создания экземпляра мутатора должен быть передан его type');
81
                    }
82
                    $mutator['options'] = array_key_exists('options', $mutator) ? $mutator['options'] : [];
83
                    $mutator = $mutatorPluginManager->get($mutator['type'], $mutator['options']);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 12 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
84
                }
85
                $mutators[] = $mutator;
86
            }
87
        }
88
89
        return $mutators;
90
    }
91
92
    /**
93
     * Метод осуществляет подготовку данных предустановленных мутаторов по умолчанию.
94
     * Преобразует массив данных для предустановленных мутаторов в общий формат.
95
     * @param ColumnInterface $column
96
     * @param array | Traversable $spec
97
     * @return array | Traversable
98
     */
99
    protected function prepareMutatorsSpecification(ColumnInterface $column, $spec)
100
    {
101
        $mutatorsNames = $column->getInvokableMutators();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
102
        $mutatorsOptions = [];
103
        if (count($mutatorsNames)) {
104
            if (array_key_exists('options', $spec)
105
                && is_array($spec['options'])
106
                && array_key_exists('mutatorsOptions', $spec['options'])
107
            ) {
108
                $mutatorsOptions = $spec['options']['mutatorsOptions'];
109
            }
110
            foreach ($mutatorsNames as $k => $mutator) {
111
                $spec['mutators'][] = [
112
                    'type' => $mutator,
113
                    'options' => array_key_exists($k, $mutatorsOptions) ? $mutatorsOptions[$k] : []
114
                ];
115
            }
116
            unset($spec['options']['mutatorsOptions']);
117
        }
118
119
        return $spec;
120
    }
121
122
    protected function createHeader($spec)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
123
    {
124
        $header = null;
125
        if (array_key_exists('header', $spec)
126
            && $spec['header']
127
        ) {
128
            if (!$spec['header'] instanceof HeaderInterface) {
129
                /** @var Header\Factory $headerFactory */
130
                $headerFactory = $this->getColumnPluginManager()->getServiceLocator()->get(Header\Factory::class);
131
                $header = $headerFactory->create($spec['header']);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
132
            } else {
133
                $header = $spec['header'];
134
            }
135
        }
136
        return $header;
137
    }
138
139
    /**
140
     * Create service
141
     *
142
     * @param ServiceLocatorInterface $serviceLocator
143
     * @return mixed
144
     * @throws Exception\RuntimeException
145
     * @throws InvalidColumnException
146
     * @throws InvalidNameException
147
     * @throws InvalidSpecificationException
148
     * @throws RuntimeException
149
     */
150
    public function createService(ServiceLocatorInterface $serviceLocator)
151
    {
152
        $spec = $this->getCreationOptions();
153
        $this->setColumnPluginManager($serviceLocator);
0 ignored issues
show
$serviceLocator of type object<Zend\ServiceManag...erviceLocatorInterface> is not a sub-type of object<Nnx\DataGrid\Colu...ridColumnPluginManager>. It seems like you assume a concrete implementation of the interface Zend\ServiceManager\ServiceLocatorInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
154
        $this->validate($spec);
155
        $className = __NAMESPACE__ . '\\' . ucfirst($spec['type']);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
156
        $reflectionColumn = new ReflectionClass($className);
157
        if (!$reflectionColumn->isInstantiable()) {
158
            throw new Exception\RuntimeException(sprintf('Класс %s не найден', $className));
159
        }
160
        unset($spec['columnPluginManager']);
161
        $column = $reflectionColumn->newInstance($spec);
162
        $header = $this->createHeader($spec);
163
        $column->setHeader($header);
164
        $spec = $this->prepareMutatorsSpecification($column, $spec);
165
        $column->setMutators($this->getMutators($spec));
166
167
        return $column;
168
    }
169
}
0 ignored issues
show
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
170