This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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; |
||
8 | |||
9 | use Nnx\DataGrid\Adapter\AdapterInterface; |
||
10 | use Nnx\DataGrid\NavigationBar\NavigationBarInterface; |
||
11 | use Nnx\DataGrid\Mutator\MutatorInterface; |
||
12 | use Nnx\DataGrid\Options\ModuleOptions; |
||
13 | use Zend\ServiceManager\AbstractFactoryInterface; |
||
14 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
||
15 | use Zend\ServiceManager\ServiceLocatorInterface; |
||
16 | use ArrayAccess; |
||
17 | use Zend\Stdlib\InitializableInterface; |
||
18 | use ZF\ContentNegotiation\Request; |
||
19 | |||
20 | /** |
||
21 | * Class AbstractGridManager |
||
22 | * @package Nnx\DataGrid |
||
23 | */ |
||
24 | class AbstractGridManagerFactory implements AbstractFactoryInterface |
||
25 | { |
||
26 | use ServiceLocatorAwareTrait; |
||
27 | |||
28 | const CONFIG_KEY = 'grids'; |
||
29 | |||
30 | /** |
||
31 | * Determine if we can create a service with name |
||
32 | * |
||
33 | * @param ServiceLocatorInterface $serviceLocator |
||
34 | * @param $name |
||
35 | * @param $requestedName |
||
36 | * @return bool |
||
37 | */ |
||
38 | public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
||
39 | { |
||
40 | $res = false; |
||
41 | if (strpos($requestedName, static::CONFIG_KEY . '.') === 0) { |
||
42 | $res = true; |
||
43 | } |
||
44 | return $res; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Создает экземпляр класса adapter'a и настраивает его. |
||
49 | * @param array | ArrayAccess | AdapterInterface $adapterOptions |
||
50 | * @param ServiceLocatorInterface $serviceManager |
||
51 | * @return AdapterInterface|null |
||
0 ignored issues
–
show
|
|||
52 | * @throws Adapter\Exception\AdapterNotFoundException |
||
53 | * @throws Adapter\Exception\InvalidArgumentException |
||
54 | * @throws Adapter\Exception\InvalidOptionsException |
||
55 | * @throws Adapter\Exception\RuntimeException |
||
56 | * @throws Exception\RuntimeException |
||
57 | */ |
||
58 | protected function createAdapter($adapterOptions, ServiceLocatorInterface $serviceManager) |
||
59 | { |
||
60 | $moduleOptions = $serviceManager->get('GridModuleOptions'); |
||
61 | if (is_array($adapterOptions) || $adapterOptions instanceof ArrayAccess) { |
||
62 | /** @var Adapter\Factory $adapterFactory */ |
||
63 | $adapterFactory = $serviceManager->get(Adapter\Factory::class); |
||
64 | if (!array_key_exists('doctrine_entity_manager', $adapterOptions) |
||
65 | || !$adapterOptions['doctrine_entity_manager'] |
||
66 | ) { |
||
67 | $adapterOptions['doctrine_entity_manager'] = $moduleOptions->getDoctrineEntityManager(); |
||
68 | } |
||
69 | $adapter = $adapterFactory->create($adapterOptions); |
||
70 | } elseif (is_object($adapterOptions)) { |
||
71 | /** @var Adapter\Factory $adapterFactory */ |
||
72 | $adapter = $adapterOptions; |
||
73 | if (!$adapter instanceof AdapterInterface) { |
||
74 | throw new Exception\RuntimeException(sprintf('Adapter должен реализовывать %s', AdapterInterface::class)); |
||
0 ignored issues
–
show
|
|||
75 | } |
||
76 | } else { |
||
77 | throw new Exception\RuntimeException('Не задан EntityManager для грида.'); |
||
78 | } |
||
79 | return $adapter; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Возвращщает набор мутаторов |
||
84 | * @param array $spec |
||
85 | * @return array |
||
86 | */ |
||
87 | protected function getMutators($spec) |
||
88 | { |
||
89 | $mutators = []; |
||
90 | if (array_key_exists('mutators', $spec) && $spec['mutators']) { |
||
91 | /** @var Mutator\GridMutatorPluginManager $mutatorFactory */ |
||
92 | $mutatorManager = $this->getServiceLocator()->get('GridMutatorManager'); |
||
93 | |||
94 | foreach ($spec['mutators'] as $mutator) { |
||
95 | if (!$mutator instanceof MutatorInterface) { |
||
96 | if (!array_key_exists('type', $mutator) || !$mutator['type']) { |
||
97 | throw new Mutator\Exception\RuntimeException('Не передан type для создания мутатора.'); |
||
98 | } |
||
99 | if ($mutatorManager->has($mutator['type'])) { |
||
100 | throw new Mutator\Exception\RuntimeException( |
||
101 | sprintf('Mutator %s не зарегистрирован в MutatorManager') |
||
102 | ); |
||
103 | } |
||
104 | $mutator = $mutatorManager->get($mutator['type'], $mutator['options']); |
||
105 | } |
||
106 | $mutators[] = $mutator; |
||
107 | } |
||
108 | } |
||
109 | return $mutators; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Create service with name |
||
114 | * |
||
115 | * @param GridPluginManager | ServiceLocatorInterface $serviceLocator |
||
116 | * @param $name |
||
117 | * @param $requestedName |
||
118 | * @return mixed |
||
119 | * @throws Exception\RuntimeException |
||
120 | */ |
||
121 | public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
||
122 | { |
||
123 | $this->setServiceLocator($serviceLocator); |
||
124 | /** @var ServiceLocatorInterface $serviceManager */ |
||
125 | $serviceManager = $serviceLocator->getServiceLocator(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\ServiceManager\ServiceLocatorInterface as the method getServiceLocator() does only exist in the following implementations of said interface: Nnx\DataGrid\Button\GridButtonPluginManager , Nnx\DataGrid\Column\GridColumnPluginManager , Nnx\DataGrid\GridPluginManager , Nnx\DataGrid\Mutator\GridMutatorPluginManager , Zend\Cache\PatternPluginManager , Zend\Cache\Storage\AdapterPluginManager , Zend\Cache\Storage\PluginManager , Zend\Config\ReaderPluginManager , Zend\Config\WriterPluginManager , Zend\Filter\FilterPluginManager , Zend\Form\FormElementManager , Zend\I18n\Translator\LoaderPluginManager , Zend\InputFilter\InputFilterPluginManager , Zend\Log\ProcessorPluginManager , Zend\Log\WriterPluginManager , Zend\Log\Writer\FilterPluginManager , Zend\Log\Writer\FormatterPluginManager , Zend\Mvc\Controller\ControllerManager , Zend\Mvc\Controller\PluginManager , Zend\Mvc\Router\RoutePluginManager , Zend\Paginator\AdapterPluginManager , Zend\Paginator\ScrollingStylePluginManager , Zend\Serializer\AdapterPluginManager , Zend\ServiceManager\AbstractPluginManager , Zend\Stdlib\Hydrator\HydratorPluginManager , Zend\Validator\ValidatorPluginManager , Zend\View\HelperPluginManager , Zend\View\Helper\Navigation\PluginManager .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
126 | /** @var ModuleOptions $moduleOptions */ |
||
127 | $moduleOptions = $serviceManager->get('GridModuleOptions'); |
||
128 | $gridsConfig = $moduleOptions->getGrids(); |
||
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. ![]() |
|||
129 | /** @noinspection NotOptimalIfConditionsInspection */ |
||
130 | if ($gridsConfig === null || count($gridsConfig) === 0) { |
||
131 | throw new Exception\RuntimeException('В конфигурационном файле нет секции grids'); |
||
132 | } |
||
133 | $gridName = substr($requestedName, strlen(self::CONFIG_KEY . '.')); |
||
134 | if (!array_key_exists($gridName, $gridsConfig) || !$gridsConfig[$gridName]) { |
||
135 | throw new Exception\RuntimeException( |
||
136 | sprintf('Таблица с именем %s не найдена в конфиге гридов.', $gridName) |
||
137 | ); |
||
138 | } |
||
139 | $gridConfig =& $gridsConfig[$gridName]; |
||
140 | if (!array_key_exists('class', $gridConfig) || !$gridConfig['class']) { |
||
141 | throw new Exception\RuntimeException('Необходимо задать класс таблицы в конфиге.'); |
||
142 | } |
||
143 | $gridClass =& $gridConfig['class']; |
||
144 | $options = []; |
||
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. ![]() |
|||
145 | if (array_key_exists('options', $gridConfig) && $gridConfig['options']) { |
||
146 | if (!is_array($gridConfig['options']) && !$gridConfig['options'] instanceof ArrayAccess) { |
||
147 | throw new Exception\RuntimeException( |
||
148 | sprintf('Опции в секции %s должны быть массивом или %s', $gridName, ArrayAccess::class) |
||
149 | ); |
||
150 | } |
||
151 | $options = $gridConfig['options']; |
||
152 | $adapter = $this->createAdapter($options['adapter'], $serviceManager); |
||
153 | View Code Duplication | if (!empty($options['topNavigationBar'])) { |
|
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. ![]() |
|||
154 | $options['topNavigationBar'] = $this->createNavigationBar($options['topNavigationBar'], $serviceManager); |
||
0 ignored issues
–
show
|
|||
155 | } |
||
156 | View Code Duplication | if (!empty($options['bottomNavigationBar'])) { |
|
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. ![]() |
|||
157 | $options['bottomNavigationBar'] = $this->createNavigationBar($options['bottomNavigationBar'], $serviceManager); |
||
0 ignored issues
–
show
|
|||
158 | } |
||
159 | $options['adapter'] = $adapter; |
||
160 | } |
||
161 | $options['columnPluginManager'] = $serviceManager->get('GridColumnManager'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||
162 | $options['mutatorPluginManager'] = $serviceManager->get('GridMutatorManager'); |
||
163 | /** @var GridInterface|AbstractGrid|SimpleGrid $grid */ |
||
164 | $grid = $serviceLocator->get($gridClass, $options); |
||
0 ignored issues
–
show
The call to
ServiceLocatorInterface::get() has too many arguments starting with $options .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
165 | if ($grid instanceof InitializableInterface) { |
||
166 | $grid->init(); |
||
167 | } |
||
168 | /** @var Request $request */ |
||
169 | $request = $serviceManager->get('request'); |
||
170 | if ($grid instanceof ColumHidebleProviderInterface |
||
171 | && $request instanceof Request |
||
172 | ) { |
||
173 | $cookie = $request->getCookie(); |
||
174 | $name = !empty($gridConfig['options']['name']) ? $gridConfig['options']['name'] : $gridName; |
||
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. ![]() |
|||
175 | if (!empty($cookie['nnx']['grid'][$name]) |
||
176 | && is_string($cookie['nnx']['grid'][$name]) |
||
177 | && $userHideColumns = json_decode($cookie['nnx']['grid'][$name], true) |
||
178 | ) { |
||
179 | $grid->setUserHiddenColums($userHideColumns); |
||
180 | } |
||
181 | } |
||
182 | return $grid; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @param $navigationBarOptions |
||
187 | * @param ServiceLocatorInterface $serviceManager |
||
188 | * @return NavigationBarInterface|null |
||
189 | * @throws NavigationBar\Exception\InvalidArgumentException |
||
190 | * @throws NavigationBar\Exception\NavigationBarNotFoundException |
||
191 | * @throws NavigationBar\Exception\RuntimeException |
||
192 | */ |
||
193 | protected function createNavigationBar($navigationBarOptions, ServiceLocatorInterface $serviceManager) |
||
194 | { |
||
195 | /** @var NavigationBar\Factory $navigationBarFactory */ |
||
196 | $navigationBarFactory = $serviceManager->get(NavigationBar\Factory::class); |
||
197 | $navigationBar = $navigationBarFactory->create($navigationBarOptions); |
||
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. ![]() |
|||
198 | return $navigationBar; |
||
199 | } |
||
200 | } |
||
0 ignored issues
–
show
|
|||
201 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.