Skip to content

Commit

Permalink
wip: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rjackson committed Aug 2, 2024
1 parent 840d689 commit 5c374f1
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 420 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/CreateTodaysSubCharges.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct()
*/
public function handle()
{
$dayOffset = $this->argument('dayOffset');
$dayOffset = intval($this->argument('dayOffset'));

$targetDate = Carbon::now()->addDays($dayOffset);

Expand Down
4 changes: 0 additions & 4 deletions app/Entities/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ class Address extends Model
'approved' => 0,
];

/**
* @return User
*/
public function user()
{
return $this->hasOne('\BB\Entities\User');
}

}
14 changes: 7 additions & 7 deletions app/Entities/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use Illuminate\Database\Eloquent\Model;

/**
* @property User user
* @property integer user_id
* @property string message
* @property string type
* @property string hash
* @property boolean unread
* @property User $user
* @property integer $user_id
* @property string $message
* @property string $type
* @property string $hash
* @property boolean $unread
*/
class Notification extends Model
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public static function logNew($userId, $message, $type, $hash) {
return $existingNotifications;
}

$newNotification = parent::create([
$newNotification = static::create([
'user_id' => $userId,
'message' => $message,
'type' => $type,
Expand Down
27 changes: 14 additions & 13 deletions app/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
* @property string $phone
* @property integer $storage_box_payment_id
* @property ProfileData $profile
* @property string|null secondary_payment_method
* @property string mandate_id
* @property int monthly_subscription
* @property string gocardless_setup_id
* @property bool postFob (false=collect, true=post)
* @property date last_seen
* @property string|null $secondary_payment_method
* @property string|null $mandate_id
* @property int $monthly_subscription
* @property string|null $gocardless_setup_id
* @property bool $postFob (false=collect, true=post)
* @property date $last_seen
* @package BB\Entities
*/
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
Expand Down Expand Up @@ -450,7 +450,7 @@ public function cancelSubscription()
$this->payment_method = '';
$this->subscription_id = '';
$this->mandate_id = '';
$this->payment_day = '';
$this->payment_day = 0;
$this->status = 'leaving';
$this->save();
}
Expand Down Expand Up @@ -511,13 +511,13 @@ public function markAsSeen()
*/
public static function findWithPermission($id = null, $role = 'admin')
{
//Return the logged in user
if (empty($id)) {
//Return the logged in user
return Auth::user();
return Auth::user(); // @phpstan-ignore-line
}

$requestedUser = self::findOrFail($id);
if (Auth::user()->id == $requestedUser->id) {
if (Auth::user()->getAuthIdentifier() == $requestedUser->id) {
//The user they are after is themselves
return $requestedUser;
}
Expand All @@ -536,7 +536,7 @@ public function extendMembership($paymentMethod = null, DateTime $expiry = null)
if ($this->banned) {
return;
}

if (empty($expiry)) {
$expiry = Carbon::now()->addMonth();
}
Expand All @@ -546,7 +546,7 @@ public function extendMembership($paymentMethod = null, DateTime $expiry = null)
$this->payment_method = $paymentMethod;
}
$this->gift = '';
$this->subscription_expires = $expiry;
$this->subscription_expires = Carbon::instance($expiry);
$this->save();
}

Expand All @@ -558,7 +558,8 @@ public function getAuditFields()
return $this->auditFields;
}

public function isActive() {
public function isActive()
{
return $this->active && !$this->banned;
}
}
3 changes: 2 additions & 1 deletion app/Events/MemberBalanceChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
class MemberBalanceChanged extends Event
{
use SerializesModels;

/**
* @var
* @var int
*/
public $userId;

Expand Down
12 changes: 6 additions & 6 deletions app/Events/SubscriptionPayment/FailedInsufficientFunds.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ class FailedInsufficientFunds extends Event
use SerializesModels;

/**
* @var
* @var int
*/
public $userId;

/**
* @var
* @var int
*/
public $ubChargeId;
public $subChargeId;

/**
* @param $userId
* @param $ubChargeId
* @param $subChargeId
*/
public function __construct($userId, $ubChargeId)
public function __construct($userId, $subChargeId)
{
$this->userId = $userId;
$this->ubChargeId = $ubChargeId;
$this->subChargeId = $subChargeId;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ class InsufficientFundsTryingDirectDebit extends Event
use SerializesModels;

/**
* @var
* @var int
*/
public $userId;

/**
* @var
* @var int
*/
public $ubChargeId;
public $subChargeId;

/**
* @param $userId
* @param $ubChargeId
* @param $subChargeId
*/
public function __construct($userId, $ubChargeId)
public function __construct($userId, $subChargeId)
{
$this->userId = $userId;
$this->ubChargeId = $ubChargeId;
$this->subChargeId = $subChargeId;
}

/**
Expand Down
24 changes: 6 additions & 18 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BB\Exceptions;

use BB\Entities\User;
use BB\Helpers\TelegramErrorHelper;
use BB\Notifications\ErrorNotification;
use Exception;
Expand All @@ -10,6 +11,7 @@
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Validation\ValidationException as IlluminateValidationException;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

class Handler extends ExceptionHandler
{
Expand Down Expand Up @@ -72,14 +74,13 @@ protected function telegramException(Exception $e)
$level = 'error';
$title = 'Error';
$suppress = false;
$ignore = false;

if ($e instanceof NotImplementedException) {
$level = 'info';
$title = 'Not Implemented';
}

if (!$ignore) $this->notifyTelegram($level, $title, $suppress, $e);
$this->notifyTelegram($level, $title, $suppress, $e);
} catch (Exception $e) {
}
}
Expand All @@ -102,7 +103,6 @@ protected function notifyTelegram($level = 'error', $title = 'Exception', $suppr
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Symfony\Component\HttpFoundation\Response
*
*
* @throws \Exception
*/
Expand Down Expand Up @@ -134,7 +134,7 @@ public function render($request, Exception $e)
if ($request->wantsJson()) {
return \Response::json(['error' => $e->getMessage()], 403);
}
$userString = \Auth::guest() ? "A guest" : \Auth::user()->name;
$userString = \Auth::guest() ? "A guest" : (\Auth::user() instanceof User ? \Auth::user()->name : \Auth::user()->getAuthIdentifier());
Log::warning($userString . " tried to access something they weren't supposed to.");

return \Response::view('errors.403', [], 403);
Expand All @@ -145,31 +145,19 @@ public function render($request, Exception $e)
}

if (config('app.debug') && $this->shouldReport($e) && !$request->wantsJson()) {
// @phpstan-ignore-next-line
return $this->renderExceptionWithWhoops($e);
}

if ($request->wantsJson()) {
if ($this->isHttpException($e)) {
/** @var HttpExceptionInterface $e */
return \Response::json(['error' => $e->getMessage()], $e->getStatusCode());
}
}
return parent::render($request, $e);
}

/**
* Render an exception using Whoops.
*
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
protected function renderExceptionWithWhoops(Exception $e)
{
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());

return new \Illuminate\Http\Response($whoops->handleException($e), $e->getCode());
}

protected function invalid($request, IlluminateValidationException $exception)
{
\FlashNotification::error($exception->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions app/FlashNotification/FlashNotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function hasMessage()

/**
* @param string $detail
* @param null|string $response
* @return bool|null
* @param string|null $response
* @return bool|string|null
*/
public function hasErrorDetail($detail, $response = null)
{
Expand Down
20 changes: 9 additions & 11 deletions app/Handlers/PaymentEventHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace BB\Handlers;

use BB\Entities\Induction;
use BB\Entities\Payment;
use BB\Entities\User;
use BB\Events\Inductions\InductionRequestedEvent;
use BB\Exceptions\PaymentException;
use BB\Repo\InductionRepository;
Expand All @@ -11,39 +13,33 @@

class PaymentEventHandler
{

/**
* @var UserRepository
*/
private $userRepository;
/**
* @var InductionRepository
*/
private $inductionRepository;

/**
* @var PaymentRepository
*/
private $paymentRepository;

/**
* @var SubscriptionChargeRepository
*/
private $subscriptionChargeRepository;

/**
* @param UserRepository $userRepository
* @param InductionRepository $inductionRepository
* @param PaymentRepository $paymentRepository
* @param SubscriptionChargeRepository $subscriptionChargeRepository
*/
public function __construct(UserRepository $userRepository, InductionRepository $inductionRepository, PaymentRepository $paymentRepository, SubscriptionChargeRepository $subscriptionChargeRepository)
public function __construct(UserRepository $userRepository, PaymentRepository $paymentRepository, SubscriptionChargeRepository $subscriptionChargeRepository)
{
$this->userRepository = $userRepository;
$this->inductionRepository = $inductionRepository;
$this->paymentRepository = $paymentRepository;
$this->subscriptionChargeRepository = $subscriptionChargeRepository;
}


/**
* New payment record is created
*
Expand Down Expand Up @@ -160,6 +156,7 @@ private function updateBalance($userId)

private function updateSubPayment($paymentId, $userId, $status)
{
/** @var Payment */
$payment = $this->paymentRepository->getById($paymentId);
$subCharge = $this->subscriptionChargeRepository->findCharge($userId);

Expand All @@ -170,7 +167,7 @@ private function updateSubPayment($paymentId, $userId, $status)

//The sub charge record id gets saved onto the payment
if (empty($payment->reference)) {
$payment->reference = $subCharge->id;
$payment->reference = strval($subCharge->id);
$payment->save();
} else if ($payment->reference != $subCharge->id) {
throw new PaymentException('Attempting to update sub charge (' . $subCharge->id . ') but payment (' . $payment->id . ') doesn\'t match. Sub charge has an existing reference on it.');
Expand All @@ -184,7 +181,7 @@ private function updateSubPayment($paymentId, $userId, $status)

//The amount isn't stored on the sub charge record until its paid or processing
if ($payment->amount != $subCharge->amount) {
$this->subscriptionChargeRepository->updateAmount($subCharge->id, $payment->amount);
$this->subscriptionChargeRepository->updateAmount($subCharge->id, intval($payment->amount));
}
}

Expand All @@ -204,6 +201,7 @@ private function createInductionRecord($userId, $ref, $paymentId)
private function recordDoorKeyPaymentId($userId, $paymentId)
{
/* @TODO: Verify payment amount is valid - this could have been changed */
/** @var User */
$user = $this->userRepository->getById($userId);
$user->key_deposit_payment_id = $paymentId;
$user->save();
Expand Down
Loading

0 comments on commit 5c374f1

Please sign in to comment.