Completed
Pull Request — develop (#297)
by John
04:22
created

PhpinfoController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 15
loc 15
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Alpha\Controller;
4
5
use Alpha\Util\Logging\Logger;
6
use Alpha\Util\Config\ConfigProvider;
7
use Alpha\Util\Http\Request;
8
use Alpha\Util\Http\Response;
9
use Alpha\Util\Http\Session\SessionProviderFactory;
10
use Alpha\View\View;
11
use Alpha\Controller\Front\FrontController;
12
13
/**
14
 * Login controller that adds the current user object to the session.
15
 *
16
 * @since 2.0.3
17
 *
18
 * @author John Collins <[email protected]>
19
 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
20
 * @copyright Copyright (c) 2016, John Collins (founder of Alpha Framework).
21
 * All rights reserved.
22
 *
23
 * <pre>
24
 * Redistribution and use in source and binary forms, with or
25
 * without modification, are permitted provided that the
26
 * following conditions are met:
27
 *
28
 * * Redistributions of source code must retain the above
29
 *   copyright notice, this list of conditions and the
30
 *   following disclaimer.
31
 * * Redistributions in binary form must reproduce the above
32
 *   copyright notice, this list of conditions and the
33
 *   following disclaimer in the documentation and/or other
34
 *   materials provided with the distribution.
35
 * * Neither the name of the Alpha Framework nor the names
36
 *   of its contributors may be used to endorse or promote
37
 *   products derived from this software without specific
38
 *   prior written permission.
39
 *
40
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
41
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
42
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
45
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
51
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
52
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53
 * </pre>
54
 */
55
class PhpinfoController extends Controller implements ControllerInterface
56
{
57
    /**
58
     * Trace logger.
59
     *
60
     * @var Alpha\Util\Logging\Logger
61
     *
62
     * @since 2.0.3
63
     */
64
    private static $logger = null;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
65
66
    /**
67
     * constructor to set up the object.
68
     *
69
     * @since 2.0.3
70
     */
71 View Code Duplication
    public function __construct()
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...
72
    {
73
        self::$logger = new Logger('PhpinfoController');
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Alpha\Util\Logging\...er('PhpinfoController') of type object<Alpha\Util\Logging\Logger> is incompatible with the declared type object<Alpha\Controller\...ha\Util\Logging\Logger> of property $logger.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
        self::$logger->debug('>>__construct()');
75
76
        $config = ConfigProvider::getInstance();
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
78
        // ensure that the super class constructor is called, indicating the rights group
79
        parent::__construct('Admin');
80
81
        // set up the title and meta details
82
        $this->setTitle('Information about the PHP installation');
83
84
        self::$logger->debug('<<__construct');
85
    }
86
87
    /**
88
     * Handle GET requests.
89
     *
90
     * @param Alpha\Util\Http\Request $request
91
     *
92
     * @return Alpha\Util\Http\Response
93
     *
94
     * @since 2.0.3
95
     */
96
    public function doGET($request)
97
    {
98
        self::$logger->debug('>>doGET($request=['.var_export($request, true).'])');
99
100
        if ($request->getParam('displayphpinfo') != null) {
101
102
            ob_start();
103
            phpinfo();
104
            $body = ob_get_contents();
105
106
        } else {
107
108
            $body = View::displayPageHead($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Alpha\Controller\PhpinfoController>, but the function expects a object<Alpha\View\Alpha\Controller\Controller>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
109
110
            $url = FrontController::generateSecureURL('act=Alpha\Controller\PhpinfoController&displayphpinfo=true');
111
112
            $body .= '<iframe src="'.$url.'" style="border:none; overflow-x: scroll; overflow-y: scroll; width:100%; height:100vh;"></iframe>';
113
114
            $body .= View::displayPageFoot($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Alpha\Controller\PhpinfoController>, but the function expects a object<Alpha\View\Alpha\Aonctoller\Controller>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
115
116
        }
117
118
        self::$logger->debug('<<doGET');
119
120
        return new Response(200, $body, array('Content-Type' => 'text/html', 'X-Frame-Options' => 'SAMEORIGIN'));
121
    }
122
}