mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Request;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Trait AppendsLocationData
|
||||
*/
|
||||
@@ -33,8 +35,8 @@ trait AppendsLocationData
|
||||
{
|
||||
$return['store_location'] = false;
|
||||
if (true === $information['store_location']) {
|
||||
$long = array_key_exists('longitude', $information) ? $information['longitude'] : null;
|
||||
$lat = array_key_exists('latitude', $information) ? $information['latitude'] : null;
|
||||
$long = $information['longitude'] ?? null;
|
||||
$lat = $information['latitude'] ?? null;
|
||||
if (null !== $long && null !== $lat && $this->validLongitude($long) && $this->validLatitude($lat)) {
|
||||
$return['store_location'] = true;
|
||||
$return['longitude'] = $information['longitude'];
|
||||
@@ -49,11 +51,9 @@ trait AppendsLocationData
|
||||
/**
|
||||
* Abstract method stolen from "InteractsWithInput".
|
||||
*
|
||||
* @param null $key
|
||||
* @param bool $default
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
|
||||
*/
|
||||
abstract public function boolean($key = null, $default = false);
|
||||
@@ -88,7 +88,7 @@ trait AppendsLocationData
|
||||
*/
|
||||
protected function appendLocationData(array $data, ?string $prefix): array
|
||||
{
|
||||
app('log')->debug(sprintf('Now in appendLocationData("%s")', $prefix), $data);
|
||||
Log::debug(sprintf('Now in appendLocationData("%s")', $prefix), $data);
|
||||
$data['store_location'] = false;
|
||||
$data['update_location'] = false;
|
||||
$data['remove_location'] = false;
|
||||
@@ -105,7 +105,7 @@ trait AppendsLocationData
|
||||
|
||||
// for a POST (store), all fields must be present and not NULL.
|
||||
if ($isValidPOST) {
|
||||
app('log')->debug('Method is POST and all fields present and not NULL.');
|
||||
Log::debug('Method is POST and all fields present and not NULL.');
|
||||
$data['store_location'] = true;
|
||||
$data['longitude'] = $this->convertString($longitudeKey);
|
||||
$data['latitude'] = $this->convertString($latitudeKey);
|
||||
@@ -114,18 +114,18 @@ trait AppendsLocationData
|
||||
|
||||
// for a PUT (api update) or POST update (UI)
|
||||
if ($isValidPUT) {
|
||||
app('log')->debug('Method is PUT and all fields present and not NULL.');
|
||||
Log::debug('Method is PUT and all fields present and not NULL.');
|
||||
$data['update_location'] = true;
|
||||
$data['longitude'] = $this->convertString($longitudeKey);
|
||||
$data['latitude'] = $this->convertString($latitudeKey);
|
||||
$data['zoom_level'] = $this->convertString($zoomLevelKey);
|
||||
}
|
||||
if ($isValidEmptyPUT) {
|
||||
app('log')->debug('Method is PUT and all fields present and NULL.');
|
||||
Log::debug('Method is PUT and all fields present and NULL.');
|
||||
$data['remove_location'] = true;
|
||||
}
|
||||
app('log')->debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
|
||||
app('log')->debug(
|
||||
Log::debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Returning actions: store: %s, update: %s, delete: %s',
|
||||
var_export($data['store_location'], true),
|
||||
@@ -168,74 +168,74 @@ trait AppendsLocationData
|
||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
|
||||
app('log')->debug('Now in isValidPUT()');
|
||||
Log::debug('Now in isValidPUT()');
|
||||
|
||||
// all fields must be set:
|
||||
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
||||
app('log')->debug('All fields present.');
|
||||
if (!in_array(null, [$this->get($longitudeKey), $this->get($latitudeKey), $this->get($zoomLevelKey)], true)) {
|
||||
Log::debug('All fields present.');
|
||||
// must be PUT and API route:
|
||||
if ('PUT' === $this->method() && $this->routeIs('api.v1.*')) {
|
||||
app('log')->debug('Is API location');
|
||||
Log::debug('Is API location');
|
||||
|
||||
return true;
|
||||
}
|
||||
// if POST and not API route, must also have "has_location"
|
||||
// if is POST and route does not contain API, must also have "has_location" = true
|
||||
if ('POST' === $this->method() && $this->routeIs('*.update') && !$this->routeIs('api.v1.*') && '' !== $hasLocationKey) {
|
||||
app('log')->debug('Is POST + store route.');
|
||||
Log::debug('Is POST + store route.');
|
||||
$hasLocation = $this->boolean($hasLocationKey);
|
||||
if (true === $hasLocation) {
|
||||
app('log')->debug('Has form location data + has_location');
|
||||
Log::debug('Has form location data + has_location');
|
||||
|
||||
return true;
|
||||
}
|
||||
app('log')->debug('Does not have form location');
|
||||
Log::debug('Does not have form location');
|
||||
|
||||
return false;
|
||||
}
|
||||
app('log')->debug('Is not POST API or POST form');
|
||||
Log::debug('Is not POST API or POST form');
|
||||
|
||||
return false;
|
||||
}
|
||||
app('log')->debug('Fields not present');
|
||||
Log::debug('Fields not present');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isValidPost(?string $prefix): bool
|
||||
{
|
||||
app('log')->debug('Now in isValidPost()');
|
||||
Log::debug('Now in isValidPost()');
|
||||
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
|
||||
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
|
||||
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
|
||||
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
|
||||
// fields must not be null:
|
||||
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
|
||||
app('log')->debug('All fields present');
|
||||
if (!in_array(null, [$this->get($longitudeKey), $this->get($latitudeKey), $this->get($zoomLevelKey)], true)) {
|
||||
Log::debug('All fields present');
|
||||
// if is POST and route contains API, this is enough:
|
||||
if ('POST' === $this->method() && $this->routeIs('api.v1.*')) {
|
||||
app('log')->debug('Is API location');
|
||||
Log::debug('Is API location');
|
||||
|
||||
return true;
|
||||
}
|
||||
// if is POST and route does not contain API, must also have "has_location" = true
|
||||
if ('POST' === $this->method() && $this->routeIs('*.store') && !$this->routeIs('api.v1.*') && '' !== $hasLocationKey) {
|
||||
app('log')->debug('Is POST + store route.');
|
||||
Log::debug('Is POST + store route.');
|
||||
$hasLocation = $this->boolean($hasLocationKey);
|
||||
if (true === $hasLocation) {
|
||||
app('log')->debug('Has form form location');
|
||||
Log::debug('Has form form location');
|
||||
|
||||
return true;
|
||||
}
|
||||
app('log')->debug('Does not have form location');
|
||||
Log::debug('Does not have form location');
|
||||
|
||||
return false;
|
||||
}
|
||||
app('log')->debug('Is not POST API or POST form');
|
||||
Log::debug('Is not POST API or POST form');
|
||||
|
||||
return false;
|
||||
}
|
||||
app('log')->debug('Fields not present');
|
||||
Log::debug('Fields not present');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Request;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\UserRoleEnum;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\User;
|
||||
@@ -38,14 +39,14 @@ trait ChecksLogin
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
// Only allow logged-in users
|
||||
$check = auth()->check();
|
||||
if (!$check) {
|
||||
return false;
|
||||
}
|
||||
if (!property_exists($this, 'acceptedRoles')) { // @phpstan-ignore-line
|
||||
app('log')->debug('Request class has no acceptedRoles array');
|
||||
Log::debug('Request class has no acceptedRoles array');
|
||||
|
||||
return true; // check for false already took place.
|
||||
}
|
||||
@@ -54,7 +55,7 @@ trait ChecksLogin
|
||||
$user = auth()->user();
|
||||
$userGroup = $this->getUserGroup();
|
||||
if (null === $userGroup) {
|
||||
app('log')->error('User has no valid user group submitted or otherwise.');
|
||||
Log::error('User has no valid user group submitted or otherwise.');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -80,24 +81,24 @@ trait ChecksLogin
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
app('log')->debug('Now in getUserGroup()');
|
||||
Log::debug('Now in getUserGroup()');
|
||||
|
||||
/** @var null|UserGroup $userGroup */
|
||||
$userGroup = $this->route()?->parameter('userGroup');
|
||||
if (null === $userGroup) {
|
||||
app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
|
||||
Log::debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
|
||||
$userGroupId = (int)$this->get('user_group_id');
|
||||
if (0 === $userGroupId) {
|
||||
app('log')->debug(sprintf('Request class has no user_group_id parameter, grab default from user (group #%d).', $user->user_group_id));
|
||||
Log::debug(sprintf('Request class has no user_group_id parameter, grab default from user (group #%d).', $user->user_group_id));
|
||||
$userGroupId = (int)$user->user_group_id;
|
||||
}
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
if (null === $userGroup) {
|
||||
app('log')->error(sprintf('Request class has user_group_id (#%d), but group does not exist.', $userGroupId));
|
||||
Log::error(sprintf('Request class has user_group_id (#%d), but group does not exist.', $userGroupId));
|
||||
|
||||
return null;
|
||||
}
|
||||
app('log')->debug('Request class has valid user_group_id.');
|
||||
Log::debug('Request class has valid user_group_id.');
|
||||
}
|
||||
|
||||
return $userGroup;
|
||||
|
||||
@@ -274,11 +274,7 @@ trait ConvertsDataTypes
|
||||
if ('y' === $value) {
|
||||
return true;
|
||||
}
|
||||
if ('1' === $value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return '1' === $value;
|
||||
}
|
||||
|
||||
protected function convertDateTime(?string $string): ?Carbon
|
||||
|
||||
@@ -25,10 +25,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Request;
|
||||
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use FireflyIII\Enums\WebhookTrigger;
|
||||
use FireflyIII\Models\Webhook;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
trait ValidatesWebhooks
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user