Completed
Push — 16145-Improve-Installer ( 6dfbbe...8ebf2b )
by Shawn
02:13
created

EnvironmentController::breakApartEnv()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace SET\Http\Controllers\Installation;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Artisan;
7
use RachidLaasri\LaravelInstaller\Helpers\EnvironmentManager;
8
use SET\Http\Controllers\Controller;
9
10
class EnvironmentController extends Controller
11
{
12
13
    /**
14
     * @var EnvironmentManager
15
     */
16
    protected $EnvironmentManager;
17
18
    /**
19
     * @param EnvironmentManager $environmentManager
20
     */
21
    public function __construct(EnvironmentManager $environmentManager)
22
    {
23
        $this->EnvironmentManager = $environmentManager;
24
    }
25
26
    /**
27
     * Display the Environment page.
28
     *
29
     * @return \Illuminate\View\View
30
     */
31
    public function index()
32
    {
33
        $envConfig = $this->EnvironmentManager->getEnvContent();
34
        $fields = $this->breakApartEnv($envConfig);
35
36
        return view('vendor.installer.environment', compact('fields'));
1 ignored issue
show
Bug Compatibility introduced by
The expression view('vendor.installer.e...t', compact('fields')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 36 which is incompatible with the return type documented by SET\Http\Controllers\Ins...onmentController::index of type Illuminate\View\View.
Loading history...
37
    }
38
39
40
    /**
41
     * Processes the newly saved environment configuration and redirects back.
42
     *
43
     * @param Request $input
44
     * @return \Illuminate\Http\RedirectResponse
45
     */
46
    public function store(Request $input)
47
    {
48
        $message = $this->EnvironmentManager->saveFile($input);
49
50
        Artisan::call('generate:key');
51
52
        return $this->route('LaravelInstaller::requirements')
0 ignored issues
show
Documentation Bug introduced by
The method route does not exist on object<SET\Http\Controll...\EnvironmentController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
53
            ->with(['message' => $message]);
54
    }
55
56
    /**
57
     * Key should be before the first = symbol and value should be after.
58
     * Each new line (\r\n) should be a new array entry.
59
     * @param $string
60
     * @return array
61
     */
62
    private function breakApartEnv($string)
63
    {
64
        preg_match_all('/([^=]*?)=([^\r\n]*?)[\r\n]+/', $string, $matches);
65
66
        return array_combine($matches[1], $matches[2]);
67
    }
68
69
}
70