This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * @author Pierre-Henry Soria <[email protected]> |
||
4 | * @copyright (c) 2012-2019, Pierre-Henry Soria. All Rights Reserved. |
||
5 | * @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
||
6 | * @link http://ph7cms.com |
||
7 | * @package PH7 / App / Core |
||
8 | */ |
||
9 | |||
10 | namespace PH7; |
||
11 | |||
12 | defined('PH7') or exit('Restricted access'); |
||
13 | |||
14 | use Exception; |
||
15 | use PH7\App\Includes\Classes\Loader\Autoloader as AppLoader; |
||
16 | use PH7\Framework\Config\Config; |
||
17 | use PH7\Framework\Config\FileNotFoundException; |
||
18 | use PH7\Framework\Core\Kernel; |
||
19 | use PH7\Framework\Error\CException as Except; |
||
20 | use PH7\Framework\File\Import; |
||
0 ignored issues
–
show
This use statement conflicts with another class in this namespace,
PH7\Import .
Let’s assume that you have a directory layout like this: .
|-- OtherDir
| |-- Bar.php
| `-- Foo.php
`-- SomeDir
`-- Foo.php
and let’s assume the following content of // Bar.php
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // Bar.php
namespace OtherDir;
use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
![]() |
|||
21 | use PH7\Framework\Loader\Autoloader as FrameworkLoader; |
||
22 | use PH7\Framework\Mvc\Router\FrontController; |
||
23 | use PH7\Framework\Navigation\Browser; |
||
24 | use PH7\Framework\Registry\Registry; |
||
25 | use PH7\Framework\Server\Environment as Env; |
||
26 | use PH7\Framework\Server\Server; |
||
27 | |||
28 | /*** Begin Loading Files ***/ |
||
29 | require 'configs/constants.php'; |
||
30 | require 'includes/helpers/misc.php'; |
||
31 | |||
32 | class Bootstrap |
||
33 | { |
||
34 | /** |
||
35 | * @var Bootstrap $oInstance |
||
36 | */ |
||
37 | private static $oInstance = null; |
||
38 | |||
39 | /** |
||
40 | * Set constructor/cloning to private since it's a singleton class. |
||
41 | */ |
||
42 | private function __construct() {} |
||
43 | private function __clone() {} |
||
44 | |||
45 | /** |
||
46 | * Get instance of class. |
||
47 | * |
||
48 | * @return Bootstrap Returns the instance class or create initial instance of the class. |
||
49 | */ |
||
50 | public static function getInstance() |
||
51 | { |
||
52 | return null === static::$oInstance ? static::$oInstance = new static : static::$oInstance; |
||
0 ignored issues
–
show
Since
$oInstance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $oInstance to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Set a default timezone if it is not already configured in environment. |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function setTimezoneIfNotSet() |
||
61 | { |
||
62 | if (!ini_get('date.timezone')) { |
||
63 | ini_set('date.timezone', PH7_DEFAULT_TIMEZONE); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Initialize the app, load the files and launch the main FrontController router. |
||
69 | * |
||
70 | * @return void |
||
71 | * |
||
72 | * @throws Exception |
||
73 | * @throws Except\PH7Exception |
||
74 | * @throws Except\UserException |
||
75 | * @throws FileNotFoundException |
||
76 | */ |
||
77 | public function run() |
||
78 | { |
||
79 | try { |
||
80 | $this->loadInitFiles(); |
||
81 | |||
82 | //** Temporary code. In the near future, pH7CMS will be usable without mod_rewrite |
||
83 | if (!Server::isRewriteMod()) { |
||
0 ignored issues
–
show
The expression
\PH7\Framework\Server\Server::isRewriteMod() of type null|boolean is loosely compared to false ; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.
If an expression can have both $a = canBeFalseAndNull();
// Instead of
if ( ! $a) { }
// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
![]() |
|||
84 | $this->notRewriteModEnabledError(); |
||
85 | exit; |
||
0 ignored issues
–
show
The method
run() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
86 | } //*/ |
||
87 | |||
88 | // Enable client browser cache |
||
89 | (new Browser)->cache(); |
||
90 | |||
91 | new Server; // Start Server |
||
92 | |||
93 | $this->startPageBenchmark(); |
||
94 | //Framework\Compress\Compress::setZlipCompression(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
95 | |||
96 | // Initialize the FrontController, we are asking the front controller to process the HTTP request |
||
97 | FrontController::getInstance()->runRouter(); |
||
98 | /** TODO: When pH7CMS will support PHP 7.1 |
||
99 | } catch (FileNotFoundException | Except\UserException $oE) { |
||
100 | //*/ |
||
101 | } catch (FileNotFoundException $oE) { |
||
102 | echo $oE->getMessage(); |
||
103 | } catch (Except\UserException $oE) { |
||
104 | echo $oE->getMessage(); // Simple User Error with Exception |
||
105 | } catch (Except\PH7Exception $oE) { |
||
106 | Except\PH7Exception::launch($oE); |
||
107 | } catch (Exception $oE) { |
||
108 | Except\PH7Exception::launch($oE); |
||
109 | } finally { |
||
110 | $this->closeAppSession(); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Load all necessary files for running the app. |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | private function loadInitFiles() |
||
120 | { |
||
121 | // Load Framework Classes |
||
122 | require PH7_PATH_FRAMEWORK . 'Loader/Autoloader.php'; |
||
123 | FrameworkLoader::getInstance()->init(); |
||
124 | |||
125 | /** Loading configuration files environments **/ |
||
126 | // For All environment |
||
127 | Import::file(PH7_PATH_APP . 'configs/environment/all.env'); |
||
128 | // Specific to the current environment |
||
129 | Import::file(PH7_PATH_APP . 'configs/environment/' . Env::getFileName(Config::getInstance()->values['mode']['environment'])); |
||
130 | |||
131 | // Load Class ~/protected/app/includes/classes/* |
||
132 | Import::pH7App('includes.classes.Loader.Autoloader'); |
||
133 | AppLoader::getInstance()->init(); |
||
134 | |||
135 | // Load Debug class |
||
136 | Import::pH7FwkClass('Error.Debug'); |
||
137 | |||
138 | // Load String Class |
||
139 | Import::pH7FwkClass('Str.Str'); |
||
140 | |||
141 | /* Structure/General.class.php functions are not currently used */ |
||
142 | // Import::pH7FwkClass('Structure.General'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Initialize the benchmark time. It is calculated in Framework\Layout\Html\Design::stat() |
||
147 | * |
||
148 | * @return void |
||
149 | */ |
||
150 | private function startPageBenchmark() |
||
151 | { |
||
152 | Registry::getInstance()->start_time = microtime(true); |
||
0 ignored issues
–
show
The property
start_time does not exist on object<PH7\Framework\Registry\Registry> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
153 | } |
||
154 | |||
155 | /** |
||
156 | * If sessions status are enabled, writes session data and ends session. |
||
157 | * |
||
158 | * @return void |
||
159 | */ |
||
160 | private function closeAppSession() |
||
161 | { |
||
162 | if (session_status() === PHP_SESSION_ACTIVE) { |
||
163 | session_write_close(); |
||
164 | } |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * Display an error message if the Apache mod_rewrite is not enabled. |
||
169 | * |
||
170 | * @return void HTML output. |
||
171 | */ |
||
172 | private function notRewriteModEnabledError() |
||
173 | { |
||
174 | $sMsg = '<p class="warning"><a href="' . Kernel::SOFTWARE_WEBSITE . '">pH7CMS</a> requires Apache "mod_rewrite".</p> |
||
175 | <p>Firstly, please <strong>make sure the ".htaccess" file has been uploaded to the root directory where pH7CMS is installed</strong>. If not, use your FTP client (such as Filezilla) and upload it again from pH7CMS unziped package and try again.<br /> |
||
176 | Secondly, please <strong>make sure "mod_rewrite" is correctly installed</strong>.<br /> Click <a href="http://ph7cms.com/doc/en/how-to-install-rewrite-module" target="_blank" rel="noopener">here</a> if you want to get more information on how to install the rewrite module.<br /><br /> |
||
177 | After that, please <a href="' . PH7_URL_ROOT . '">retry</a>.</p>'; |
||
178 | |||
179 | echo html_body("Apache's mod_rewrite is required", $sMsg); |
||
180 | } |
||
181 | } |
||
182 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.