Completed
Pull Request — master (#11)
by bloveless
01:49
created

AddonsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 103
Duplicated Lines 17.48 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 14
Bugs 1 Features 1
Metric Value
wmc 9
c 14
b 1
f 1
lcom 0
cbo 1
dl 18
loc 103
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A details() 9 9 1
A installOptions() 9 9 1
A install() 0 17 3
A uninstall() 0 15 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Anomaly\AddonsModule\Http\Controller\Admin;
2
3
use Anomaly\AddonsModule\Addon\Table\AddonTableBuilder;
4
use Anomaly\Streams\Platform\Addon\Addon;
5
use Anomaly\Streams\Platform\Addon\AddonCollection;
6
use Anomaly\Streams\Platform\Addon\Extension\Extension;
7
use Anomaly\Streams\Platform\Addon\Extension\ExtensionManager;
8
use Anomaly\Streams\Platform\Addon\Module\Module;
9
use Anomaly\Streams\Platform\Addon\Module\ModuleManager;
10
use Anomaly\Streams\Platform\Http\Controller\AdminController;
11
use Illuminate\Filesystem\Filesystem;
12
use Illuminate\Http\Request;
13
14
/**
15
 * Class AddonsController
16
 *
17
 * @link          http://pyrocms.com/
18
 * @author        PyroCMS, Inc. <[email protected]>
19
 * @author        Ryan Thompson <[email protected]>
20
 * @package       Anomaly\AddonsModule\Http\Controller\Admin
21
 */
22
class AddonsController extends AdminController
23
{
24
25
    /**
26
     * Return an index of existing entries.
27
     *
28
     * @param AddonTableBuilder $builder
29
     * @param string $type
30
     * @return \Symfony\Component\HttpFoundation\Response
31
     */
32
    public function index(AddonTableBuilder $builder, $type = 'modules')
33
    {
34
        $builder->setType($type);
35
36
        return $builder->render();
37
    }
38
39
    /**
40
     * Return the details for an addon.
41
     *
42
     * @param AddonCollection $addons
43
     * @param                 $addon
44
     * @return mixed|null|string
45
     */
46 View Code Duplication
    public function details(AddonCollection $addons, $addon)
0 ignored issues
show
Duplication introduced by
This method 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...
47
    {
48
        /* @var Addon $addon */
49
        $addon = $addons->get($addon);
50
51
        $json = $addon->getComposerJson();
52
53
        return view('module::ajax/details', compact('json', 'addon'))->render();
54
    }
55
56
    /**
57
     * Ask the user for any options when installing the addon.
58
     *
59
     * @param AddonCollection $addons
60
     * @param $addon
61
     * @return mixed|null|string
62
     */
63 View Code Duplication
    public function installOptions(AddonCollection $addons, $namespace)
0 ignored issues
show
Duplication introduced by
This method 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...
64
    {
65
        /* @var Addon $addon */
66
        $addon = $addons->get($namespace);
67
68
        $json = $addon->getComposerJson();
69
70
        return view('module::ajax/install', compact('json', 'addon', 'namespace'))->render();
71
    }
72
73
    /**
74
     * Install an addon.
75
     *
76
     * @param AddonCollection $addons
77
     * @param ModuleManager $modules
78
     * @param ExtensionManager $extensions
79
     * @param                  $addon
80
     * @return \Illuminate\Http\RedirectResponse
81
     */
82
    public function install(Request $request, AddonCollection $addons, ModuleManager $modules, ExtensionManager $extensions, $addon)
83
    {
84
        $seed = filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN);
85
86
        /* @var Addon $addon */
87
        $addon = $addons->get($addon);
88
89
        if ($addon instanceof Module) {
0 ignored issues
show
Bug introduced by
The class Anomaly\Streams\Platform\Addon\Module\Module does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
90
            $modules->install($addon, $seed);
91
        } elseif ($addon instanceof Extension) {
0 ignored issues
show
Bug introduced by
The class Anomaly\Streams\Platform\Addon\Extension\Extension does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
92
            $extensions->install($addon);
93
        }
94
95
        $this->messages->success('module::message.install_addon_success');
96
97
        return $this->redirect->back();
98
    }
99
100
    /**
101
     * Uninstall an addon.
102
     *
103
     * @param AddonCollection $addons
104
     * @param ModuleManager $modules
105
     * @param ExtensionManager $extensions
106
     * @param                  $addon
107
     * @return \Illuminate\Http\RedirectResponse
108
     */
109
    public function uninstall(AddonCollection $addons, ModuleManager $modules, ExtensionManager $extensions, $addon)
110
    {
111
        /* @var Addon $addon */
112
        $addon = $addons->get($addon);
113
114
        if ($addon instanceof Module) {
0 ignored issues
show
Bug introduced by
The class Anomaly\Streams\Platform\Addon\Module\Module does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
115
            $modules->uninstall($addon);
116
        } elseif ($addon instanceof Extension) {
0 ignored issues
show
Bug introduced by
The class Anomaly\Streams\Platform\Addon\Extension\Extension does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
117
            $extensions->uninstall($addon);
118
        }
119
120
        $this->messages->success('module::message.uninstall_addon_success');
121
122
        return $this->redirect->back();
123
    }
124
}
125