PermissionFormSections::handle()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 24
Code Lines 11

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 11
nc 6
nop 3
1
<?php namespace Anomaly\UsersModule\Role\Permission;
2
3
use Anomaly\Streams\Platform\Addon\Addon;
4
use Anomaly\Streams\Platform\Addon\AddonCollection;
5
use Illuminate\Config\Repository;
6
use Illuminate\Translation\Translator;
7
8
/**
9
 * Class PermissionFormSections
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 */
15 View Code Duplication
class PermissionFormSections
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
16
{
17
18
    /**
19
     * Handle the fields.
20
     *
21
     * @param PermissionFormBuilder $builder
22
     * @param AddonCollection       $addons
23
     * @param Translator            $translator
0 ignored issues
show
Bug introduced by
There is no parameter named $translator. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
24
     * @param Repository            $config
25
     */
26
    public function handle(PermissionFormBuilder $builder, AddonCollection $addons, Repository $config)
27
    {
28
        $sections = [];
29
30
        $sections['streams']['title'] = 'streams::message.system';
31
32
        foreach ($config->get('streams::permissions', []) as $group => $permissions) {
33
            $sections['streams']['fields'][] = 'streams::' . $group;
34
        }
35
36
        /* @var Addon $addon */
37
        foreach ($addons->withConfig('permissions') as $addon) {
38
39
            $sections[$addon->getNamespace()]['title']       = $addon->getName();
40
            $sections[$addon->getNamespace()]['description'] = $addon->getDescription();
41
42
            foreach ($config->get($addon->getNamespace('permissions'), []) as $group => $permissions) {
43
44
                $sections[$addon->getNamespace()]['fields'][] = str_replace('.', '_', $addon->getNamespace($group));
45
            }
46
        }
47
48
        $builder->setSections($sections);
49
    }
50
}
51