Issues (19)

config/bootstrap.php (10 issues)

1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
11
 * @link          https://cakephp.org CakePHP(tm) Project
12
 * @since         0.10.8
13
 * @license       https://opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
/*
17
 * Configure paths required to find CakePHP + general filepath constants
18
 */
19
require __DIR__ . '/paths.php';
20
21
/*
22
 * Bootstrap CakePHP.
23
 *
24
 * Does the various bits of setup that CakePHP needs to do.
25
 * This includes:
26
 *
27
 * - Registering the CakePHP autoloader.
28
 * - Setting the default application paths.
29
 */
30
require CORE_PATH . 'config' . DS . 'bootstrap.php';
31
32
use Cake\Cache\Cache;
33
use Cake\Core\Configure;
34
use Cake\Core\Configure\Engine\PhpConfig;
35
use Cake\Database\Type;
36
use Cake\Datasource\ConnectionManager;
37
use Cake\Error\ConsoleErrorHandler;
38
use Cake\Error\ErrorHandler;
39
use Cake\Http\ServerRequest;
40
use Cake\Log\Log;
41
use Cake\Mailer\Email;
42
use Cake\Mailer\TransportFactory;
43
use Cake\Utility\Security;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Security. Consider defining an alias.

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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
44
use Detection\MobileDetect;
0 ignored issues
show
The type Detection\MobileDetect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
46
/**
47
 * Uncomment block of code below if you want to use `.env` file during development.
48
 * You should copy `config/.env.default to `config/.env` and set/modify the
49
 * variables as required.
50
 *
51
 * It is HIGHLY discouraged to use a .env file in production, due to security risks
52
 * and decreased performance on each request. The purpose of the .env file is to emulate
53
 * the presence of the environment variables like they would be present in production.
54
 */
55
// if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
56
//     $dotenv = new \josegonzalez\Dotenv\Loader([CONFIG . '.env']);
57
//     $dotenv->parse()
58
//         ->putenv()
59
//         ->toEnv()
60
//         ->toServer();
61
// }
62
63
/*
64
 * Read configuration file and inject configuration into various
65
 * CakePHP classes.
66
 *
67
 * By default there is only one configuration file. It is often a good
68
 * idea to create multiple configuration files, and separate the configuration
69
 * that changes from configuration that does not. This makes deployment simpler.
70
 */
71
try {
72
    Configure::config('default', new PhpConfig());
73
    Configure::load('app', 'default', false);
74
} catch (Throwable $e) {
75
    exit($e->getMessage() . "\n");
76
}
77
78
/*
79
 * Load an environment local configuration file.
80
 * You can use a file like app_local.php to provide local overrides to your
81
 * shared configuration.
82
 */
83
//Configure::load('app_local', 'default');
84
85
/*
86
 * When debug = true the metadata cache should only last
87
 * for a short time.
88
 */
89
if (Configure::read('debug')) {
90
    Configure::write('Cache._cake_model_.duration', '+2 minutes');
91
    Configure::write('Cache._cake_core_.duration', '+2 minutes');
92
    // disable router cache during development
93
    Configure::write('Cache._cake_routes_.duration', '+2 seconds');
94
}
95
96
/*
97
 * Set the default server timezone. Using UTC makes time calculations / conversions easier.
98
 * Check http://php.net/manual/en/timezones.php for list of valid timezone strings.
99
 */
100
date_default_timezone_set(Configure::read('App.defaultTimezone'));
0 ignored issues
show
It seems like Cake\Core\Configure::read('App.defaultTimezone') can also be of type null; however, parameter $timezoneId of date_default_timezone_set() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

100
date_default_timezone_set(/** @scrutinizer ignore-type */ Configure::read('App.defaultTimezone'));
Loading history...
101
102
/*
103
 * Configure the mbstring extension to use the correct encoding.
104
 */
105
mb_internal_encoding(Configure::read('App.encoding'));
106
107
/*
108
 * Set the default locale. This controls how dates, number and currency is
109
 * formatted and sets the default language to use for translations.
110
 */
111
ini_set('intl.default_locale', Configure::read('App.defaultLocale'));
0 ignored issues
show
It seems like Cake\Core\Configure::read('App.defaultLocale') can also be of type null; however, parameter $value of ini_set() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
ini_set('intl.default_locale', /** @scrutinizer ignore-type */ Configure::read('App.defaultLocale'));
Loading history...
112
113
/*
114
 * Register application error and exception handlers.
115
 */
116
$isCli = PHP_SAPI === 'cli';
117
if ($isCli) {
118
    (new ConsoleErrorHandler(Configure::read('Error')))->register();
0 ignored issues
show
It seems like Cake\Core\Configure::read('Error') can also be of type null; however, parameter $config of Cake\Error\ConsoleErrorHandler::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

118
    (new ConsoleErrorHandler(/** @scrutinizer ignore-type */ Configure::read('Error')))->register();
Loading history...
119
} else {
120
    (new ErrorHandler(Configure::read('Error')))->register();
0 ignored issues
show
It seems like Cake\Core\Configure::read('Error') can also be of type null; however, parameter $config of Cake\Error\ErrorHandler::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

120
    (new ErrorHandler(/** @scrutinizer ignore-type */ Configure::read('Error')))->register();
Loading history...
121
}
122
123
/*
124
 * Include the CLI bootstrap overrides.
125
 */
126
if ($isCli) {
127
    require __DIR__ . '/bootstrap_cli.php';
128
}
129
130
/*
131
 * Set the full base URL.
132
 * This URL is used as the base of all absolute links.
133
 *
134
 * If you define fullBaseUrl in your config file you can remove this.
135
 */
136
if (! Configure::read('App.fullBaseUrl')) {
137
    $s = null;
138
    if (env('HTTPS')) {
139
        $s = 's';
140
    }
141
142
    $httpHost = env('HTTP_HOST');
143
    if (isset($httpHost)) {
144
        Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost);
145
    }
146
147
    unset($httpHost, $s);
148
}
149
150
Cache::setConfig(Configure::consume('Cache'));
151
ConnectionManager::setConfig(Configure::consume('Datasources'));
152
TransportFactory::setConfig(Configure::consume('EmailTransport'));
153
Email::setConfig(Configure::consume('Email'));
154
Log::setConfig(Configure::consume('Log'));
155
Security::setSalt(Configure::consume('Security.salt'));
0 ignored issues
show
It seems like Cake\Core\Configure::consume('Security.salt') can also be of type array and null; however, parameter $salt of Cake\Utility\Security::setSalt() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

155
Security::setSalt(/** @scrutinizer ignore-type */ Configure::consume('Security.salt'));
Loading history...
156
157
/*
158
 * The default crypto extension in 3.0 is OpenSSL.
159
 * If you are migrating from 2.x uncomment this code to
160
 * use a more compatible Mcrypt based implementation
161
 */
162
//Security::engine(new \Cake\Utility\Crypto\Mcrypt());
163
164
/*
165
 * Setup detectors for mobile and tablet.
166
 */
167
ServerRequest::addDetector('mobile', static function ($request) {
0 ignored issues
show
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

167
ServerRequest::addDetector('mobile', static function (/** @scrutinizer ignore-unused */ $request) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
168
    $detector = new MobileDetect();
169
170
    return $detector->isMobile();
171
});
172
ServerRequest::addDetector('tablet', static function ($request) {
0 ignored issues
show
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

172
ServerRequest::addDetector('tablet', static function (/** @scrutinizer ignore-unused */ $request) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
    $detector = new MobileDetect();
174
175
    return $detector->isTablet();
176
});
177
178
/*
179
 * Enable immutable time objects in the ORM.
180
 *
181
 * You can enable default locale format parsing by adding calls
182
 * to `useLocaleParser()`. This enables the automatic conversion of
183
 * locale specific date formats. For details see
184
 * @link https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
185
 */
186
Type::build('time')
187
    ->useImmutable();
0 ignored issues
show
The method useImmutable() does not exist on Cake\Database\TypeInterface. It seems like you code against a sub-type of Cake\Database\TypeInterface such as Cake\Database\Type\DateTimeType. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

187
    ->/** @scrutinizer ignore-call */ useImmutable();
Loading history...
188
Type::build('date')
189
    ->useImmutable();
190
Type::build('datetime')
191
    ->useImmutable();
192
Type::build('timestamp')
193
    ->useImmutable();
194
195
/*
196
 * Custom Inflector rules, can be set to correctly pluralize or singularize
197
 * table, model, controller names or whatever other string is passed to the
198
 * inflection functions.
199
 */
200
//Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
201
//Inflector::rules('irregular', ['red' => 'redlings']);
202
//Inflector::rules('uninflected', ['dontinflectme']);
203
//Inflector::rules('transliteration', ['/å/' => 'aa']);
204
require 'oauth.php';
205
require 'forwarding.php';
206