oliverde8 /
comfyBundle
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace oliverde8\ComfyBundle\Resolver; |
||||
| 4 | |||||
| 5 | use oliverde8\AssociativeArraySimplified\AssociativeArray; |
||||
| 6 | use oliverde8\ComfyBundle\Manager\ConfigManagerInterface; |
||||
| 7 | use oliverde8\ComfyBundle\Model\ConfigInterface; |
||||
| 8 | use oliverde8\ComfyBundle\Security\ConfigVoter; |
||||
| 9 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
||||
|
0 ignored issues
–
show
|
|||||
| 10 | |||||
| 11 | class VisibleConfigsResolver |
||||
| 12 | { |
||||
| 13 | protected AuthorizationCheckerInterface $checker; |
||||
| 14 | |||||
| 15 | protected ConfigManagerInterface $configManager; |
||||
| 16 | |||||
| 17 | /** |
||||
| 18 | * @param AuthorizationCheckerInterface $checker |
||||
| 19 | * @param ConfigManagerInterface $configManager |
||||
| 20 | */ |
||||
| 21 | public function __construct(AuthorizationCheckerInterface $checker, ConfigManagerInterface $configManager) |
||||
| 22 | { |
||||
| 23 | $this->checker = $checker; |
||||
| 24 | $this->configManager = $configManager; |
||||
| 25 | } |
||||
| 26 | |||||
| 27 | public function getAllowedConfigs(string $configPath, string $action = ConfigVoter::ACTION_VIEW): array |
||||
| 28 | { |
||||
| 29 | $allowedConfigs = []; |
||||
| 30 | foreach ($this->getAllowedConfigsGenerator($configPath, $action) as $config) { |
||||
| 31 | $allowedConfigs[] = $config; |
||||
| 32 | } |
||||
| 33 | |||||
| 34 | return $allowedConfigs; |
||||
| 35 | } |
||||
| 36 | |||||
| 37 | public function getAllAllowedConfigs(string $action = ConfigVoter::ACTION_VIEW): array |
||||
| 38 | { |
||||
| 39 | $allowedConfigs = new AssociativeArray(); |
||||
| 40 | |||||
| 41 | $allConfigs = $this->configManager->getAllConfigs(); |
||||
| 42 | array_walk_recursive($allConfigs, function ($config, $key) use($allowedConfigs, $action) { |
||||
|
0 ignored issues
–
show
The parameter
$key is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 43 | if (is_object($config)) { |
||||
| 44 | if ($config->isHidden()) { |
||||
| 45 | return; |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | if ($this->checker->isGranted($action, $config)) { |
||||
| 49 | $allowedConfigs->set($config->getPath(), $config); |
||||
| 50 | } |
||||
| 51 | } |
||||
| 52 | }); |
||||
| 53 | |||||
| 54 | return $allowedConfigs->getArray(); |
||||
| 55 | } |
||||
| 56 | |||||
| 57 | /** |
||||
| 58 | * @return \Generator|ConfigInterface[] |
||||
| 59 | * @throws \oliverde8\ComfyBundle\Exception\UnknownScopeException |
||||
| 60 | */ |
||||
| 61 | protected function getAllowedConfigsGenerator(string $configPath, string $action) |
||||
| 62 | { |
||||
| 63 | $configs = $this->configManager->getAllConfigs()->get($configPath, []); |
||||
|
0 ignored issues
–
show
|
|||||
| 64 | if (empty($configPath)) { |
||||
| 65 | $this->configManager->getAllConfigs(); |
||||
| 66 | } |
||||
| 67 | |||||
| 68 | foreach ($this->configManager->getAllConfigs()->get($configPath, []) as $config) { |
||||
| 69 | if ($config->isHidden()) { |
||||
| 70 | continue; |
||||
| 71 | } |
||||
| 72 | |||||
| 73 | if ($this->checker->isGranted($action, $config)) { |
||||
| 74 | yield $config; |
||||
| 75 | } |
||||
| 76 | } |
||||
| 77 | } |
||||
| 78 | } |
||||
| 79 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths