Skip to content

Commit

Permalink
Format code as current standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmypuckett committed Nov 23, 2022
1 parent 33e6ea3 commit fc50d78
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 136 deletions.
41 changes: 11 additions & 30 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ public function __construct(array $configs, Token $token)
/**
* Build URI to request authorization
*
* @return String
* @throws SdkException
* @throws ServiceException
*/
public function authorizationUri()
public function authorizationUri(): string
{
return $this->getDataService()
->getOAuth2LoginHelper()
Expand All @@ -72,10 +71,8 @@ public function authorizationUri()

/**
* Configure the logging per config/quickbooks.php
*
* @return DataService
*/
public function configureLogging()
public function configureLogging(): DataService
{
// In case any of the keys are not in the configs, just disable logging
try {
Expand All @@ -97,10 +94,9 @@ public function configureLogging()
/**
* Delete the token
*
* @return $this
* @throws Exception
*/
public function deleteToken()
public function deleteToken(): self
{
$this->setToken($this->token->remove());

Expand All @@ -113,14 +109,10 @@ public function deleteToken()
* Upon the user allowing access to their account, there is a code sent to
* over that needs to be converted to an OAuth token.
*
* @param string $code
* @param integer $realm_id
*
* @return $this
* @throws SdkException
* @throws ServiceException
*/
public function exchangeCodeForToken($code, $realm_id)
public function exchangeCodeForToken(string $code, int $realm_id): self
{
$oauth_token = $this->getDataService()
->getOAuth2LoginHelper()
Expand All @@ -138,11 +130,10 @@ public function exchangeCodeForToken($code, $realm_id)
*
* Makes sure that it is setup & ready to be used.
*
* @return DataService
* @throws SdkException
* @throws ServiceException
*/
public function getDataService()
public function getDataService(): DataService
{
if (!$this->hasValidAccessToken() || !isset($this->data_service)) {
$this->data_service = $this->makeDataService();
Expand All @@ -158,11 +149,10 @@ public function getDataService()
*
* Makes sure that it is setup & ready to be used.
*
* @return ReportService
* @throws SdkException
* @throws ServiceException
*/
public function getReportService()
public function getReportService(): ReportService
{
if (!$this->hasValidAccessToken() || !isset($this->report_service)) {
$this->report_service = new ReportService($this->getDataService()->getServiceContext());
Expand All @@ -173,20 +163,16 @@ public function getReportService()

/**
* Check to see if the token has a valid access token
*
* @return boolean
*/
public function hasValidAccessToken()
public function hasValidAccessToken(): bool
{
return $this->token->hasValidAccessToken;
}

/**
* Check to see if the token has a valid refresh token
*
* @return boolean
*/
public function hasValidRefreshToken()
public function hasValidRefreshToken(): bool
{
return $this->token->hasValidRefreshToken;
}
Expand All @@ -200,11 +186,10 @@ public function hasValidRefreshToken()
* 2) Have valid refresh token, so renew access token & then use
* 3) No existing token, so need to link account
*
* @return DataService
* @throws SdkException
* @throws ServiceException
*/
protected function makeDataService()
protected function makeDataService(): DataService
{
// Associative array to use to filter out only the needed config keys when using existing token
$existing_keys = [
Expand Down Expand Up @@ -252,7 +237,7 @@ protected function makeDataService()
/**
* QuickBooks is not consistent on their naming of variables, so map them
*/
protected function parseDataConfigs()
protected function parseDataConfigs(): array
{
return [
'auth_mode' => $this->configs['data_service']['auth_mode'],
Expand All @@ -266,12 +251,8 @@ protected function parseDataConfigs()

/**
* Allow setting a token to switch "user"
*
* @param Token $token
*
* @return $this
*/
public function setToken(Token $token)
public function setToken(Token $token): self
{
$this->token = $token;

Expand Down
6 changes: 3 additions & 3 deletions src/HasQuickBooksToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Spinen\QuickBooks;

use Illuminate\Database\Eloquent\Relations\HasOne;

trait HasQuickBooksToken
{
/**
* Have a quickBooksToken.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function quickBooksToken()
public function quickBooksToken(): HasOne
{
return $this->hasOne(Token::class);
}
Expand Down
41 changes: 18 additions & 23 deletions src/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

namespace Spinen\QuickBooks\Http\Controllers;

use Exception;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Contracts\View\View as ViewContract;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as LaravelController;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
use QuickBooksOnline\API\Exception\SdkException;
use QuickBooksOnline\API\Exception\ServiceException;
use Spinen\QuickBooks\Client as QuickBooks;

/**
Expand All @@ -23,14 +29,10 @@ class Controller extends LaravelController
*
* If the user has a valid OAuth, then give form to disconnect, otherwise link to connect it
*
* @param QuickBooks $quickbooks
* @param ViewFactory $view_factory
*
* @return \Illuminate\Contracts\View\View|\Illuminate\View\View
* @throws \QuickBooksOnline\API\Exception\SdkException
* @throws \QuickBooksOnline\API\Exception\ServiceException
* @throws SdkException
* @throws ServiceException
*/
public function connect(QuickBooks $quickbooks, ViewFactory $view_factory)
public function connect(QuickBooks $quickbooks, ViewFactory $view_factory): ViewContract|View
{
// Give view to remove token if user already linked account
if ($quickbooks->hasValidRefreshToken()) {
Expand All @@ -48,14 +50,13 @@ public function connect(QuickBooks $quickbooks, ViewFactory $view_factory)
/**
* Removes the token
*
* @param Redirector $redirector
* @param QuickBooks $quickbooks
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
* @throws \Exception
* @throws Exception
*/
public function disconnect(Redirector $redirector, Request $request, QuickBooks $quickbooks)
{
public function disconnect(
Redirector $redirector,
Request $request,
QuickBooks $quickbooks,
): RedirectResponse|View {
$quickbooks->deleteToken();

$request->session()->flash('success', 'Disconnected from QuickBooks');
Expand All @@ -69,21 +70,15 @@ public function disconnect(Redirector $redirector, Request $request, QuickBooks
* Once a user approves linking account, then QuickBooks sends back
* a code which can be converted to an OAuth token.
*
* @param Redirector $redirector
* @param Request $request
* @param QuickBooks $quickbooks
* @param UrlGenerator $url_generator
*
* @return \Illuminate\Http\RedirectResponse
* @throws \QuickBooksOnline\API\Exception\SdkException
* @throws \QuickBooksOnline\API\Exception\ServiceException
* @throws SdkException
* @throws ServiceException
*/
public function token(
Redirector $redirector,
Request $request,
QuickBooks $quickbooks,
UrlGenerator $url_generator,
) {
): RedirectResponse {
// TODO: Deal with exceptions
$quickbooks->exchangeCodeForToken($request->get('code'), $request->get('realmId'));

Expand Down
48 changes: 5 additions & 43 deletions src/Http/Middleware/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Contracts\Session\Session;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Spinen\QuickBooks\Client;
use Spinen\QuickBooks\Client as QuickBooks;

/**
Expand All @@ -17,34 +16,6 @@
*/
class Filter
{
/**
* The QuickBooks client instance.
*
* @var Client
*/
protected $quickbooks;

/**
* The redirector instance.
*
* @var Redirector
*/
protected $redirector;

/**
* The session instance.
*
* @var Session
*/
protected $session;

/**
* The UrlGenerator instance.
*
* @var UrlGenerator
*/
protected $url_generator;

/**
* Create a new QuickBooks filter middleware instance.
*
Expand All @@ -54,26 +25,17 @@ class Filter
* @param UrlGenerator $url_generator
*/
public function __construct(
QuickBooks $quickbooks,
Redirector $redirector,
Session $session,
UrlGenerator $url_generator,
protected QuickBooks $quickbooks,
protected Redirector $redirector,
protected Session $session,
protected UrlGenerator $url_generator,
) {
$this->quickbooks = $quickbooks;
$this->redirector = $redirector;
$this->session = $session;
$this->url_generator = $url_generator;
}

/**
* Handle an incoming request.
*
* @param Request $request Request
* @param Closure $next Closure
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if (!$this->quickbooks->hasValidRefreshToken()) {
// Set intended route, so that after linking account, user is put where they were going
Expand Down
12 changes: 3 additions & 9 deletions src/Providers/ClientServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@ class ClientServiceProvider extends LaravelServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
protected bool $defer = true;

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
public function provides(): array
{
return [Client::class];
}

/**
* Register the application services.
*
* @return void
*/
public function register()
public function register(): void
{
$this->app->bind(Client::class, function (Application $app) {
$token =
Expand Down
Loading

0 comments on commit fc50d78

Please sign in to comment.