AddonsController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
 */
21
class AddonsController extends AdminController
22
{
23
24
    /**
25
     * Return an index of existing entries.
26
     *
27
     * @param  AddonTableBuilder                          $builder
28
     * @param  string                                     $type
29
     * @return \Symfony\Component\HttpFoundation\Response
30
     */
31
    public function index(AddonTableBuilder $builder, $type = 'modules')
32
    {
33
        $builder->setType($type);
34
35
        return $builder->render();
36
    }
37
38
    /**
39
     * Return the details for an addon.
40
     *
41
     * @param  AddonCollection   $addons
42
     * @param                    $addon
43
     * @return mixed|null|string
44
     */
45
    public function details(AddonCollection $addons, $addon)
46
    {
47
        /* @var Addon $addon */
48
        $addon = $addons->get($addon);
49
50
        $json = $addon->getComposerJson();
51
52
        return view('module::ajax/details', compact('json', 'addon'))->render();
53
    }
54
55
    /**
56
     * Return the modal form for the seed
57
     * option when installing modules.
58
     *
59
     * @param AddonCollection $addons
60
     * @param                 $namespace
61
     * @return
62
     */
63
    public function options(AddonCollection $addons, $namespace)
64
    {
65
        /* @var Addon $addon */
66
        $addon = $addons->get($namespace);
67
68
        return $this->view->make('module::ajax/install', compact('addon', 'namespace'));
69
    }
70
71
    /**
72
     * Install an addon.
73
     *
74
     * @param  Request                           $request
75
     * @param  ModuleManager                     $modules
76
     * @param  AddonCollection                   $addons
77
     * @param  ExtensionManager                  $extensions
78
     * @param                                    $addon
79
     * @return \Illuminate\Http\RedirectResponse
80
     */
81 View Code Duplication
    public function install(
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...
82
        Request $request,
83
        ModuleManager $modules,
84
        AddonCollection $addons,
85
        ExtensionManager $extensions,
86
        $addon
87
    ) {
88
        /* @var Addon|Module|Extension $addon */
89
        $addon = $addons->get($addon);
90
91
        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...
92
            $modules->install($addon, filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN));
93
        } 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...
94
            $extensions->install($addon, filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN));
95
        }
96
97
        $this->messages->success('module::message.install_addon_success');
98
99
        return $this->redirect->back();
100
    }
101
102
    /**
103
     * Migrate an addon.
104
     *
105
     * @param  Request                           $request
106
     * @param  ModuleManager                     $modules
107
     * @param  AddonCollection                   $addons
108
     * @param  ExtensionManager                  $extensions
109
     * @param                                    $addon
110
     * @return \Illuminate\Http\RedirectResponse
111
     */
112 View Code Duplication
    public function migrate(
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...
113
        Request $request,
114
        ModuleManager $modules,
115
        AddonCollection $addons,
116
        ExtensionManager $extensions,
117
        $addon
118
    ) {
119
        /* @var Addon|Module|Extension $addon */
120
        $addon = $addons->get($addon);
121
122
        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...
123
            $modules->migrate($addon, filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN));
124
        } 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...
125
            $extensions->migrate($addon, filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN));
126
        }
127
128
        $this->messages->success('module::message.migrate_addon_success');
129
130
        return $this->redirect->back();
131
    }
132
133
    /**
134
     * Uninstall an addon.
135
     *
136
     * @param  AddonCollection                   $addons
137
     * @param  ModuleManager                     $modules
138
     * @param  ExtensionManager                  $extensions
139
     * @param                                    $addon
140
     * @return \Illuminate\Http\RedirectResponse
141
     */
142
    public function uninstall(AddonCollection $addons, ModuleManager $modules, ExtensionManager $extensions, $addon)
143
    {
144
        /* @var Addon|Module|Extension $addon */
145
        $addon = $addons->get($addon);
146
147
        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...
148
            $modules->uninstall($addon);
149
        } 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...
150
            $extensions->uninstall($addon);
151
        }
152
153
        $this->messages->success('module::message.uninstall_addon_success');
154
155
        return $this->redirect->back();
156
    }
157
}
158