Various code optimalisations.

This commit is contained in:
James Cole
2018-07-08 07:59:58 +02:00
parent 10492e3b2f
commit 2f2f907ffe
59 changed files with 309 additions and 279 deletions

View File

@@ -105,7 +105,12 @@ class Authenticate
}
} catch (QueryException $e) {
// @codeCoverageIgnoreStart
throw new FireflyException('It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands?');
throw new FireflyException(
sprintf(
'It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands? Error: %s',
$e->getMessage()
)
);
// @codeCoverageIgnoreEnd
}

View File

@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection PhpMethodParametersCountMismatchInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
@@ -65,6 +66,7 @@ class AuthenticateTwoFactor
return response()->redirectTo(route('login'));
}
$is2faEnabled = app('preferences')->get('twoFactorAuthEnabled', false)->data;
$has2faSecret = null !== app('preferences')->get('twoFactorAuthSecret');
$is2faAuthed = 'true' === $request->cookie('twoFactorAuthenticated');

View File

@@ -30,12 +30,4 @@ use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
*/
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except
= [
];
}

View File

@@ -48,12 +48,12 @@ class Installer
*/
public function handle($request, Closure $next)
{
if (env('APP_ENV') === 'testing') {
if ('testing' === env('APP_ENV')) {
return $next($request);
}
$url = $request->url();
$strpos = stripos($url, '/install');
if (!($strpos === false)) {
if (!(false === $strpos)) {
Log::debug(sprintf('URL is %s, will NOT run installer middleware', $url));
return $next($request);
@@ -102,7 +102,7 @@ class Installer
*/
protected function isAccessDenied(string $message): bool
{
return !(stripos($message, 'Access denied') === false);
return !(false === stripos($message, 'Access denied'));
}
/**
@@ -112,6 +112,6 @@ class Installer
*/
protected function noTablesExist(string $message): bool
{
return !(stripos($message, 'Base table or view not found') === false);
return !(false === stripos($message, 'Base table or view not found'));
}
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@@ -52,7 +53,9 @@ class IsAdmin
}
/** @var User $user */
$user = auth()->user();
if (!$user->hasRole('owner')) {
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if (!$repository->hasRole($user, 'owner')) {
return response()->redirectTo(route('home'));
}

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Http\Middleware;
use Closure;
use FireflyIII\Exceptions\IsDemoUserException;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\Request;
@@ -48,7 +49,9 @@ class IsDemoUser
return $next($request);
}
if ($user->hasRole('demo')) {
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if ($repository->hasRole($user, 'demo')) {
$request->session()->flash('info', (string)trans('firefly.not_available_demo_user'));
$current = $request->url();
$previous = $request->session()->previousUrl();

View File

@@ -107,7 +107,7 @@ class Range
*/
private function loseItAll(Request $request)
{
if (getenv('DB_CONNECTION') === 'sqlite' && getenv('IS_DOCKER') === true) {
if ('sqlite' === getenv('DB_CONNECTION') && true === getenv('IS_DOCKER')) {
$request->session()->flash(
'error', 'You seem to be using SQLite in a Docker container. Don\'t do this. If the container restarts all your data will be gone.'
);

View File

@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
declare(strict_types=1);
namespace FireflyIII\Http\Middleware;

View File

@@ -51,11 +51,11 @@ class TrustProxies extends Middleware
{
$trustedProxies = env('TRUSTED_PROXIES', null);
if (false !== $trustedProxies && null !== $trustedProxies && \strlen($trustedProxies) > 0) {
if ($trustedProxies === '*' || $trustedProxies === '**') {
$this->proxies = (string)$trustedProxies;
if ('*' === $trustedProxies || '**' === $trustedProxies) {
$this->proxies = $trustedProxies;
}
if ($trustedProxies !== '*' && $trustedProxies !== '**') {
if ('*' !== $trustedProxies && '**' !== $trustedProxies) {
$this->proxies = explode(',', $trustedProxies);
}
}

View File

@@ -30,12 +30,4 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
*/
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except
= [
];
}