Completed
Push — master ( 0944f9...613740 )
by Ryan
01:48
created

AddonsController::options()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
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 7
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
 * @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
    public function details(AddonCollection $addons, $addon)
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
     * Return the modal form for the seed
58
     * option when installing modules.
59
     *
60
     * @param AddonCollection $addons
61
     * @param                 $namespace
62
     * @return
63
     */
64
    public function options(AddonCollection $addons, $namespace)
65
    {
66
        /* @var Addon $addon */
67
        $addon = $addons->get($namespace);
68
69
        return $this->view->make('module::ajax/install', compact('addon', 'namespace'));
70
    }
71
72
    /**
73
     * Install an addon.
74
     *
75
     * @param Request          $request
76
     * @param ModuleManager    $modules
77
     * @param AddonCollection  $addons
78
     * @param ExtensionManager $extensions
79
     * @param                  $addon
80
     * @return \Illuminate\Http\RedirectResponse
81
     */
82
    public function install(
83
        Request $request,
84
        ModuleManager $modules,
85
        AddonCollection $addons,
86
        ExtensionManager $extensions,
87
        $addon
88
    ) {
89
        /* @var Addon|Module|Extension $addon */
90
        $addon = $addons->get($addon);
91
92
        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...
93
            $modules->install($addon, filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN));
94
        } 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...
95
            $extensions->install($addon, filter_var($request->input('seed'), FILTER_VALIDATE_BOOLEAN));
96
        }
97
98
        $this->messages->success('module::message.install_addon_success');
99
100
        return $this->redirect->back();
101
    }
102
103
    /**
104
     * Uninstall an addon.
105
     *
106
     * @param AddonCollection  $addons
107
     * @param ModuleManager    $modules
108
     * @param ExtensionManager $extensions
109
     * @param                  $addon
110
     * @return \Illuminate\Http\RedirectResponse
111
     */
112
    public function uninstall(AddonCollection $addons, ModuleManager $modules, ExtensionManager $extensions, $addon)
113
    {
114
        /* @var Addon|Module|Extension $addon */
115
        $addon = $addons->get($addon);
116
117
        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...
118
            $modules->uninstall($addon);
119
        } 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...
120
            $extensions->uninstall($addon);
121
        }
122
123
        $this->messages->success('module::message.uninstall_addon_success');
124
125
        return $this->redirect->back();
126
    }
127
}
128