Completed
Push — master ( 051e1f...fb5ddd )
by ARCANEDEV
05:33
created

PhpInfoComposer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 44
ccs 0
cts 10
cp 0
rs 10
wmc 2
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compose() 0 8 1
A checkPhpRequirements() 0 8 1
1
<?php namespace Arcanesoft\Foundation\ViewComposers\System;
2
3
use Illuminate\View\View;
4
5
/**
6
 * Class     PhpInfoComposer
7
 *
8
 * @package  Arcanesoft\Foundation\ViewComposers\System
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class PhpInfoComposer
12
{
13
    /* -----------------------------------------------------------------
14
     |  Constants
15
     | -----------------------------------------------------------------
16
     */
17
    const VIEW = 'foundation::admin.system.information._includes.php-info';
18
19
    /* -----------------------------------------------------------------
20
     |  Main Methods
21
     | -----------------------------------------------------------------
22
     */
23
    /**
24
     * Compose the view.
25
     *
26
     * @param  \Illuminate\View\View  $view
27
     */
28
    public function compose(View $view)
29
    {
30
        $info['version']      = phpversion();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$info was never initialized. Although not strictly required by PHP, it is generally a good practice to add $info = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
31
        $info['extensions']   = get_loaded_extensions();
32
        $info['requirements'] = $this->checkPhpRequirements();
33
34
        $view->with('phpInfo', $info);
35
    }
36
37
    /* -----------------------------------------------------------------
38
     |  Other Methods
39
     | -----------------------------------------------------------------
40
     */
41
    /**
42
     * Check the PHP requirements.
43
     *
44
     * @return \Illuminate\Support\Collection
45
     */
46
    private function checkPhpRequirements()
47
    {
48
        $requirements = ['openssl', 'pdo', 'mbstring', 'tokenizer', 'xml'];
49
50
        return collect(array_combine($requirements, $requirements))->transform(function ($requirement) {
51
            return extension_loaded($requirement);
52
        });
53
    }
54
}
55