mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 04:21:20 +00:00
Code clean up.
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -31,15 +30,13 @@ use Requests;
|
||||
use Requests_Exception;
|
||||
|
||||
/**
|
||||
* Class BunqRequest
|
||||
*
|
||||
* @package Bunq\Request
|
||||
* Class BunqRequest.
|
||||
*/
|
||||
abstract class BunqRequest
|
||||
{
|
||||
/** @var string */
|
||||
protected $secret = '';
|
||||
/** @var ServerPublicKey */
|
||||
/** @var ServerPublicKey */
|
||||
protected $serverPublicKey;
|
||||
/** @var string */
|
||||
private $privateKey = '';
|
||||
@@ -111,14 +108,15 @@ abstract class BunqRequest
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function generateSignature(string $method, string $uri, array $headers, string $data): string
|
||||
{
|
||||
if (strlen($this->privateKey) === 0) {
|
||||
if (0 === strlen($this->privateKey)) {
|
||||
throw new FireflyException('No private key present.');
|
||||
}
|
||||
if (strtolower($method) === 'get' || strtolower($method) === 'delete') {
|
||||
if ('get' === strtolower($method) || 'delete' === strtolower($method)) {
|
||||
$data = '';
|
||||
}
|
||||
|
||||
@@ -127,7 +125,7 @@ abstract class BunqRequest
|
||||
$headersToSign = ['Cache-Control', 'User-Agent'];
|
||||
ksort($headers);
|
||||
foreach ($headers as $name => $value) {
|
||||
if (in_array($name, $headersToSign) || substr($name, 0, 7) === 'X-Bunq-') {
|
||||
if (in_array($name, $headersToSign) || 'X-Bunq-' === substr($name, 0, 7)) {
|
||||
$toSign .= sprintf("%s: %s\n", $name, $value);
|
||||
}
|
||||
}
|
||||
@@ -202,11 +200,12 @@ abstract class BunqRequest
|
||||
* @param array $headers
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function sendSignedBunqDelete(string $uri, array $headers): array
|
||||
{
|
||||
if (strlen($this->server) === 0) {
|
||||
if (0 === strlen($this->server)) {
|
||||
throw new FireflyException('No bunq server defined');
|
||||
}
|
||||
|
||||
@@ -216,7 +215,7 @@ abstract class BunqRequest
|
||||
try {
|
||||
$response = Requests::delete($fullUri, $headers);
|
||||
} catch (Requests_Exception $e) {
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()],]];
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
|
||||
}
|
||||
|
||||
$body = $response->body;
|
||||
@@ -235,7 +234,6 @@ abstract class BunqRequest
|
||||
throw new FireflyException(sprintf('Could not verify signature for request to "%s"', $uri));
|
||||
}
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -245,11 +243,12 @@ abstract class BunqRequest
|
||||
* @param array $headers
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function sendSignedBunqGet(string $uri, array $data, array $headers): array
|
||||
{
|
||||
if (strlen($this->server) === 0) {
|
||||
if (0 === strlen($this->server)) {
|
||||
throw new FireflyException('No bunq server defined');
|
||||
}
|
||||
|
||||
@@ -260,7 +259,7 @@ abstract class BunqRequest
|
||||
try {
|
||||
$response = Requests::get($fullUri, $headers);
|
||||
} catch (Requests_Exception $e) {
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()],]];
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
|
||||
}
|
||||
|
||||
$body = $response->body;
|
||||
@@ -287,6 +286,7 @@ abstract class BunqRequest
|
||||
* @param array $headers
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function sendSignedBunqPost(string $uri, array $data, array $headers): array
|
||||
@@ -298,7 +298,7 @@ abstract class BunqRequest
|
||||
try {
|
||||
$response = Requests::post($fullUri, $headers, $body);
|
||||
} catch (Requests_Exception $e) {
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()],]];
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
|
||||
}
|
||||
|
||||
$body = $response->body;
|
||||
@@ -316,7 +316,6 @@ abstract class BunqRequest
|
||||
throw new FireflyException(sprintf('Could not verify signature for request to "%s"', $uri));
|
||||
}
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -332,7 +331,7 @@ abstract class BunqRequest
|
||||
try {
|
||||
$response = Requests::delete($fullUri, $headers);
|
||||
} catch (Requests_Exception $e) {
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()],]];
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
|
||||
}
|
||||
$body = $response->body;
|
||||
$array = json_decode($body, true);
|
||||
@@ -362,7 +361,7 @@ abstract class BunqRequest
|
||||
try {
|
||||
$response = Requests::post($fullUri, $headers, $body);
|
||||
} catch (Requests_Exception $e) {
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()],]];
|
||||
return ['Error' => [0 => ['error_description' => $e->getMessage(), 'error_description_translated' => $e->getMessage()]]];
|
||||
}
|
||||
$body = $response->body;
|
||||
$array = json_decode($body, true);
|
||||
@@ -375,7 +374,6 @@ abstract class BunqRequest
|
||||
$this->throwResponseError($array);
|
||||
}
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -387,7 +385,7 @@ abstract class BunqRequest
|
||||
private function isErrorResponse(array $response): bool
|
||||
{
|
||||
$key = key($response);
|
||||
if ($key === 'Error') {
|
||||
if ('Error' === $key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -431,6 +429,7 @@ abstract class BunqRequest
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function verifyServerSignature(string $body, array $headers, int $statusCode): bool
|
||||
@@ -440,15 +439,14 @@ abstract class BunqRequest
|
||||
$verifyHeaders = [];
|
||||
|
||||
// false when no public key is present
|
||||
if (is_null($this->serverPublicKey)) {
|
||||
if (null === $this->serverPublicKey) {
|
||||
Log::error('No public key present in class, so return FALSE.');
|
||||
|
||||
return false;
|
||||
}
|
||||
foreach ($headers as $header => $value) {
|
||||
|
||||
// skip non-bunq headers or signature
|
||||
if (substr($header, 0, 7) !== 'x-bunq-' || $header === 'x-bunq-server-signature') {
|
||||
if ('x-bunq-' !== substr($header, 0, 7) || 'x-bunq-server-signature' === $header) {
|
||||
continue;
|
||||
}
|
||||
// need to have upper case variant of header:
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -27,13 +26,11 @@ use FireflyIII\Services\Bunq\Token\SessionToken;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class DeleteDeviceSessionRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
* Class DeleteDeviceSessionRequest.
|
||||
*/
|
||||
class DeleteDeviceSessionRequest extends BunqRequest
|
||||
{
|
||||
/** @var SessionToken */
|
||||
/** @var SessionToken */
|
||||
private $sessionToken;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -27,17 +26,15 @@ use FireflyIII\Services\Bunq\Id\DeviceServerId;
|
||||
use FireflyIII\Services\Bunq\Token\InstallationToken;
|
||||
|
||||
/**
|
||||
* Class DeviceServerRequest
|
||||
*
|
||||
* @package Bunq\Request
|
||||
* Class DeviceServerRequest.
|
||||
*/
|
||||
class DeviceServerRequest extends BunqRequest
|
||||
{
|
||||
/** @var string */
|
||||
private $description = '';
|
||||
/** @var DeviceServerId */
|
||||
/** @var DeviceServerId */
|
||||
private $deviceServerId;
|
||||
/** @var InstallationToken */
|
||||
/** @var InstallationToken */
|
||||
private $installationToken;
|
||||
/** @var array */
|
||||
private $permittedIps = [];
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -31,21 +30,19 @@ use FireflyIII\Services\Bunq\Token\SessionToken;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class DeviceSessionRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
* Class DeviceSessionRequest.
|
||||
*/
|
||||
class DeviceSessionRequest extends BunqRequest
|
||||
{
|
||||
/** @var DeviceSessionId */
|
||||
/** @var DeviceSessionId */
|
||||
private $deviceSessionId;
|
||||
/** @var InstallationToken */
|
||||
/** @var InstallationToken */
|
||||
private $installationToken;
|
||||
/** @var SessionToken */
|
||||
/** @var SessionToken */
|
||||
private $sessionToken;
|
||||
/** @var UserCompany */
|
||||
/** @var UserCompany */
|
||||
private $userCompany;
|
||||
/** @var UserPerson */
|
||||
/** @var UserPerson */
|
||||
private $userPerson;
|
||||
|
||||
/**
|
||||
@@ -59,7 +56,6 @@ class DeviceSessionRequest extends BunqRequest
|
||||
$headers['X-Bunq-Client-Authentication'] = $this->installationToken->getToken();
|
||||
$response = $this->sendSignedBunqPost($uri, $data, $headers);
|
||||
|
||||
|
||||
$this->deviceSessionId = $this->extractDeviceSessionId($response);
|
||||
$this->sessionToken = $this->extractSessionToken($response);
|
||||
$this->userPerson = $this->extractUserPerson($response);
|
||||
@@ -137,7 +133,6 @@ class DeviceSessionRequest extends BunqRequest
|
||||
$data = $this->getKeyFromResponse('UserCompany', $response);
|
||||
$userCompany = new UserCompany($data);
|
||||
|
||||
|
||||
return $userCompany;
|
||||
}
|
||||
|
||||
@@ -151,7 +146,6 @@ class DeviceSessionRequest extends BunqRequest
|
||||
$data = $this->getKeyFromResponse('UserPerson', $response);
|
||||
$userPerson = new UserPerson($data);
|
||||
|
||||
|
||||
return $userPerson;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -29,15 +28,13 @@ use FireflyIII\Services\Bunq\Token\InstallationToken;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class InstallationTokenRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
* Class InstallationTokenRequest.
|
||||
*/
|
||||
class InstallationTokenRequest extends BunqRequest
|
||||
{
|
||||
/** @var InstallationId */
|
||||
private $installationId;
|
||||
/** @var InstallationToken */
|
||||
/** @var InstallationToken */
|
||||
private $installationToken;
|
||||
/** @var string */
|
||||
private $publicKey = '';
|
||||
@@ -48,7 +45,7 @@ class InstallationTokenRequest extends BunqRequest
|
||||
public function call(): void
|
||||
{
|
||||
$uri = '/v1/installation';
|
||||
$data = ['client_public_key' => $this->publicKey,];
|
||||
$data = ['client_public_key' => $this->publicKey];
|
||||
$headers = $this->getDefaultHeaders();
|
||||
$response = $this->sendUnsignedBunqPost($uri, $data, $headers);
|
||||
Log::debug('Installation request response', $response);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -28,15 +27,13 @@ use FireflyIII\Services\Bunq\Token\InstallationToken;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ListDeviceServerRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
* Class ListDeviceServerRequest.
|
||||
*/
|
||||
class ListDeviceServerRequest extends BunqRequest
|
||||
{
|
||||
/** @var Collection */
|
||||
private $devices;
|
||||
/** @var InstallationToken */
|
||||
/** @var InstallationToken */
|
||||
private $installationToken;
|
||||
|
||||
public function __construct()
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -28,15 +27,13 @@ use FireflyIII\Services\Bunq\Token\SessionToken;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ListMonetaryAccountRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
* Class ListMonetaryAccountRequest.
|
||||
*/
|
||||
class ListMonetaryAccountRequest extends BunqRequest
|
||||
{
|
||||
/** @var Collection */
|
||||
/** @var Collection */
|
||||
private $monetaryAccounts;
|
||||
/** @var SessionToken */
|
||||
/** @var SessionToken */
|
||||
private $sessionToken;
|
||||
/** @var int */
|
||||
private $userId = 0;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Bunq\Request;
|
||||
@@ -29,19 +28,17 @@ use FireflyIII\Services\Bunq\Object\UserPerson;
|
||||
use FireflyIII\Services\Bunq\Token\SessionToken;
|
||||
|
||||
/**
|
||||
* Class ListUserRequest
|
||||
*
|
||||
* @package FireflyIII\Services\Bunq\Request
|
||||
* Class ListUserRequest.
|
||||
*/
|
||||
class ListUserRequest extends BunqRequest
|
||||
{
|
||||
/** @var SessionToken */
|
||||
/** @var SessionToken */
|
||||
private $sessionToken;
|
||||
/** @var UserCompany */
|
||||
/** @var UserCompany */
|
||||
private $userCompany;
|
||||
/** @var UserLight */
|
||||
/** @var UserLight */
|
||||
private $userLight;
|
||||
/** @var UserPerson */
|
||||
/** @var UserPerson */
|
||||
private $userPerson;
|
||||
|
||||
/**
|
||||
@@ -90,7 +87,6 @@ class ListUserRequest extends BunqRequest
|
||||
return $this->userPerson;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SessionToken $sessionToken
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user