Browse Source

code cleanup part #3

pull/373/head
James Cole 2 years ago
parent
commit
1744f76d1f
  1. 4
      app/Console/AutoImports.php
  2. 3
      app/Console/Commands/UpgradeImportConfigurations.php
  3. 3
      app/Exceptions/SpectreErrorException.php
  4. 1
      app/Http/Controllers/AutoImportController.php
  5. 1
      app/Http/Controllers/AutoUploadController.php
  6. 2
      app/Http/Controllers/Import/ConfigurationController.php
  7. 9
      app/Http/Controllers/Import/ConversionController.php
  8. 4
      app/Http/Controllers/Import/DownloadController.php
  9. 25
      app/Http/Controllers/Import/File/RoleController.php
  10. 4
      app/Http/Controllers/Import/MapController.php
  11. 1
      app/Http/Controllers/Import/Nordigen/LinkController.php
  12. 12
      app/Http/Controllers/Import/Nordigen/SelectionController.php
  13. 4
      app/Http/Controllers/Import/Spectre/ConnectionController.php
  14. 6
      app/Http/Controllers/Import/SubmitController.php
  15. 12
      app/Http/Controllers/Import/UploadController.php
  16. 4
      app/Http/Middleware/Authenticate.php
  17. 8
      app/Http/Middleware/IsReadyForStep.php
  18. 3
      app/Services/CSV/Conversion/Task/Accounts.php
  19. 2
      app/Services/CSV/Conversion/Task/Amount.php
  20. 2
      app/Services/CSV/Converter/Description.php
  21. 2
      app/Services/CSV/Converter/Iban.php
  22. 8
      app/Services/CSV/Mapper/MapperService.php
  23. 29
      app/Services/CSV/Roles/RoleService.php
  24. 68
      app/Services/Camt/Conversion/RoutineManager.php
  25. 6
      app/Services/Camt/Conversion/TransactionMapper.php
  26. 88
      app/Services/Camt/Transaction.php
  27. 9
      app/Services/Nordigen/Conversion/Routine/GenerateTransactions.php
  28. 2
      app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php
  29. 5
      app/Services/Nordigen/Request/GetAccountBalanceRequest.php
  30. 5
      app/Services/Nordigen/Request/GetAccountBasicRequest.php
  31. 2
      app/Services/Nordigen/Request/GetRequisitionRequest.php
  32. 5
      app/Services/Nordigen/Request/ListAccountsRequest.php
  33. 2
      app/Services/Nordigen/Request/ListBanksRequest.php
  34. 2
      app/Services/Nordigen/Request/PostNewRequisitionRequest.php
  35. 2
      app/Services/Nordigen/Request/PostNewTokenRequest.php
  36. 2
      app/Services/Nordigen/Request/PostNewUserAgreement.php
  37. 8
      app/Services/Nordigen/Request/Request.php
  38. 6
      app/Services/Nordigen/Services/AccountInformationCollector.php
  39. 2
      app/Services/Nordigen/TokenManager.php
  40. 2
      app/Services/Shared/Configuration/Configuration.php
  41. 2
      app/Services/Shared/Import/Routine/InfoCollector.php
  42. 2
      app/Services/Spectre/Conversion/Routine/GenerateTransactions.php
  43. 2
      app/Services/Spectre/Conversion/RoutineManager.php
  44. 10
      app/Services/Spectre/Model/Transaction.php
  45. 2
      app/Services/Spectre/Request/GetAccountsRequest.php
  46. 2
      app/Services/Spectre/Request/ListConnectionsRequest.php
  47. 2
      app/Services/Spectre/Request/PostConnectSessionsRequest.php
  48. 4
      app/Services/Spectre/Request/PostCustomerRequest.php
  49. 2
      app/Services/Spectre/Request/PutRefreshConnectionRequest.php
  50. 6
      app/Services/Spectre/Request/Request.php
  51. 7
      app/Services/Storage/StorageService.php
  52. 5
      app/Support/Internal/CollectsAccounts.php

4
app/Console/AutoImports.php

@ -39,6 +39,7 @@ use App\Services\Shared\Import\Status\SubmissionStatusManager;
use App\Services\Spectre\Conversion\RoutineManager as SpectreRoutineManager;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use JsonException;
use League\Flysystem\FilesystemException;
use Storage;
/**
@ -349,7 +350,8 @@ trait AutoImports
}
/**
* @param Configuration $configuration
* @param Configuration $configuration
* @throws FilesystemException
*/
private function startImport(Configuration $configuration): void
{

3
app/Console/Commands/UpgradeImportConfigurations.php

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace App\Console\Commands;
use App\Services\Shared\Configuration\Configuration;
use FilesystemIterator;
use Illuminate\Console\Command;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
@ -86,7 +87,7 @@ class UpgradeImportConfigurations extends Command
*/
private function processRoot(string $directory): void
{
$dir = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
$dir = new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
/**
* @var string $name

3
app/Exceptions/SpectreErrorException.php

@ -33,6 +33,5 @@ use Exception;
*/
class SpectreErrorException extends Exception
{
/** @var array */
public $json;
public array $json;
}

1
app/Http/Controllers/AutoImportController.php

@ -44,6 +44,7 @@ class AutoImportController extends Controller
/**
*
* @throws ImporterErrorException
*/
public function index(Request $request): Response
{

1
app/Http/Controllers/AutoUploadController.php

@ -41,6 +41,7 @@ class AutoUploadController extends Controller
/**
*
* @throws ImporterErrorException
*/
public function index(AutoUploadRequest $request)
{

2
app/Http/Controllers/Import/ConfigurationController.php

@ -91,7 +91,7 @@ class ConfigurationController extends Controller
// if config says to skip it, skip it:
$overruleSkip = 'true' === $request->get('overruleskip');
if (null !== $configuration && true === $configuration->isSkipForm() && false === $overruleSkip) {
if (true === $configuration->isSkipForm() && false === $overruleSkip) {
app('log')->debug('Skip configuration, go straight to the next step.');
// set config as complete.
session()->put(Constants::CONFIG_COMPLETE_INDICATOR, true);

9
app/Http/Controllers/Import/ConversionController.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Http\Controllers\Import;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Http\Controllers\Controller;
use App\Http\Middleware\ConversionControllerMiddleware;
use App\Services\Camt\Conversion\RoutineManager as CamtRoutineManager;
@ -39,6 +40,8 @@ use App\Support\Http\RestoresConfiguration;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use JsonException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Storage;
/**
@ -62,6 +65,7 @@ class ConversionController extends Controller
/**
*
* @throws ImporterErrorException
*/
public function index()
{
@ -144,10 +148,13 @@ class ConversionController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return JsonResponse
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function start(Request $request): JsonResponse
{

4
app/Http/Controllers/Import/DownloadController.php

@ -29,6 +29,8 @@ use App\Support\Http\RestoresConfiguration;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Response;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class DownloadController
@ -39,6 +41,8 @@ class DownloadController extends Controller
/**
* @return Application|ResponseFactory|Response
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function download(): Response|Application|ResponseFactory
{

25
app/Http/Controllers/Import/File/RoleController.php

@ -28,7 +28,6 @@ use App\Exceptions\ImporterErrorException;
use App\Http\Controllers\Controller;
use App\Http\Middleware\RoleControllerMiddleware;
use App\Http\Request\RolesPostRequest;
use App\Services\Camt053\Converter;
use App\Services\CSV\Roles\RoleService;
use App\Services\Session\Constants;
use App\Services\Shared\Configuration\Configuration;
@ -42,6 +41,7 @@ use JsonException;
use League\Csv\Exception;
use League\Csv\InvalidArgument;
use League\Csv\UnableToProcessCsv;
use League\Flysystem\FilesystemException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -65,7 +65,7 @@ class RoleController extends Controller
/**
* @param Request $request
*
* @return Factory|View
* @return View|void
* @throws JsonException
* @throws Exception
* @throws InvalidArgument
@ -136,10 +136,13 @@ class RoleController extends Controller
}
/**
* @param Request $request
* @param Configuration $configuration
* @param Request $request
* @param Configuration $configuration
*
* @return View
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
private function camtIndex(Request $request, Configuration $configuration): View
{
@ -244,11 +247,13 @@ class RoleController extends Controller
}
/**
* @param RolesPostRequest $request
* @param RolesPostRequest $request
*
* @return RedirectResponse
* @throws JsonException
* @throws ContainerExceptionInterface
* @throws FilesystemException
* @throws ImporterErrorException
* @throws JsonException
* @throws NotFoundExceptionInterface
*/
public function postIndex(RolesPostRequest $request): RedirectResponse
@ -335,10 +340,14 @@ class RoleController extends Controller
/**
* TODO is basically the same as the CSV processor.
*
* @param RolesPostRequest $request
* @param Configuration $configuration
* @param RolesPostRequest $request
* @param Configuration $configuration
*
* @return RedirectResponse
* @throws ContainerExceptionInterface
* @throws FilesystemException
* @throws JsonException
* @throws NotFoundExceptionInterface
*/
private function camtPostIndex(RolesPostRequest $request, Configuration $configuration): RedirectResponse
{

4
app/Http/Controllers/Import/MapController.php

@ -66,6 +66,10 @@ class MapController extends Controller
/**
* @return Factory|View
* @throws ContainerExceptionInterface
* @throws FileNotFoundException
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
public function index()
{

1
app/Http/Controllers/Import/Nordigen/LinkController.php

@ -62,6 +62,7 @@ class LinkController extends Controller
}
/**
* @throws ImporterHttpException
*/
public function build()
{

12
app/Http/Controllers/Import/Nordigen/SelectionController.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Http\Controllers\Import\Nordigen;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Http\Controllers\Controller;
@ -42,6 +43,9 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
use JsonException;
use League\Flysystem\FilesystemException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class SelectionController
@ -63,7 +67,10 @@ class SelectionController extends Controller
* Step 9, select a country + bank.
*
* @return Factory|View
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
* @throws AgreementExpiredException
*/
public function index()
{
@ -105,10 +112,13 @@ class SelectionController extends Controller
}
/**
* @param SelectionRequest $request
* @param SelectionRequest $request
*
* @return Application|RedirectResponse|Redirector
* @throws ImporterErrorException
* @throws FilesystemException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function postIndex(SelectionRequest $request)
{

4
app/Http/Controllers/Import/Spectre/ConnectionController.php

@ -152,11 +152,9 @@ class ConnectionController extends Controller
public function post(Request $request)
{
$connectionId = $request->get('spectre_connection_id');
$configuration = $this->restoreConfiguration();
if ('00' === $connectionId) {
// get identifier
$configuration = $this->restoreConfiguration();
// make a new connection.
$url = config('spectre.url');
$appId = SpectreSecretManager::getAppId();

6
app/Http/Controllers/Import/SubmitController.php

@ -40,6 +40,7 @@ use Illuminate\Contracts\View\View;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use JsonException;
use League\Flysystem\FilesystemException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Storage;
@ -98,9 +99,12 @@ class SubmitController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return JsonResponse
* @throws ContainerExceptionInterface
* @throws FilesystemException
* @throws NotFoundExceptionInterface
*/
public function start(Request $request): JsonResponse
{

12
app/Http/Controllers/Import/UploadController.php

@ -39,6 +39,7 @@ use Illuminate\Http\UploadedFile;
use Illuminate\Routing\Redirector;
use Illuminate\Support\MessageBag;
use Illuminate\View\View;
use League\Flysystem\FilesystemException;
use Storage;
/**
@ -92,9 +93,11 @@ class UploadController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return RedirectResponse|Redirector
* @throws FileNotFoundException
* @throws FilesystemException
* @throws ImporterErrorException
*/
public function upload(Request $request)
@ -137,7 +140,12 @@ class UploadController extends Controller
/**
*
* @param string $flow
* @param MessageBag $errors
* @param UploadedFile|null $file
* @return MessageBag
* @throws FilesystemException
* @throws ImporterErrorException
*/
private function processUploadedFile(string $flow, MessageBag $errors, UploadedFile|null $file): MessageBag
{
@ -157,6 +165,7 @@ class UploadController extends Controller
if (0 === $errorNumber) {
$detector = new FileContentSherlock();
$fileType = $detector->detectContentType($file->getPathname());
$content = '';
if ('csv' === $fileType) {
$content = file_get_contents($file->getPathname());
@ -259,6 +268,7 @@ class UploadController extends Controller
// process the config file
$success = false;
$configuration = null;
try {
$configuration = ConfigFileProcessor::convertConfigFile($configFileName);
session()->put(Constants::CONFIGURATION, $configuration->toSessionArray());

4
app/Http/Middleware/Authenticate.php

@ -35,11 +35,11 @@ class Authenticate extends Middleware
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param Request $request
* @param Request $request
*
* @return string|null
*/
protected function redirectTo($request)
protected function redirectTo($request): string|null
{
if (!$request->expectsJson()) {
return route('login');

8
app/Http/Middleware/IsReadyForStep.php

@ -62,10 +62,12 @@ trait IsReadyForStep
}
/**
* @param Request $request
* @param Request $request
*
* @return bool
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
protected function isReadyForStep(Request $request): bool
{
@ -348,10 +350,12 @@ trait IsReadyForStep
}
/**
* @param Request $request
* @param Request $request
*
* @return RedirectResponse|null
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
protected function redirectToCorrectStep(Request $request): ?RedirectResponse
{

3
app/Services/CSV/Conversion/Task/Accounts.php

@ -42,9 +42,10 @@ class Accounts extends AbstractTask
use DeterminesTransactionType;
/**
* @param array $group
* @param array $group
*
* @return array
* @throws ImporterErrorException
*/
public function process(array $group): array
{

2
app/Services/CSV/Conversion/Task/Amount.php

@ -115,7 +115,7 @@ class Amount extends AbstractTask
app('log')->debug(sprintf('Amount is now %s.', $amount));
// modify foreign amount
if (isset($transaction['foreign_amount']) && null !== $transaction['foreign_amount']) {
if (isset($transaction['foreign_amount'])) {
$transaction['foreign_amount'] = bcmul($transaction['foreign_amount'], $transaction['amount_modifier']);
app('log')->debug(sprintf('FOREIGN amount is now %s.', $transaction['foreign_amount']));
}

2
app/Services/CSV/Converter/Description.php

@ -34,7 +34,7 @@ class Description implements ConverterInterface
*
* @param $value
*
* @return mixed
* @return string
*
*/
public function convert($value)

2
app/Services/CSV/Converter/Iban.php

@ -36,7 +36,7 @@ class Iban implements ConverterInterface
*
* @param $value
*
* @return array|string|string[]
* @return string
*
*/
public function convert($value)

8
app/Services/CSV/Mapper/MapperService.php

@ -126,11 +126,9 @@ class MapperService
/**
* Appends the given array with data from the CAMT file in the config.
*
* @param string $content
* @param string $delimiter
* @param bool $hasHeaders
* @param array $specifics
* @param array $data
* @param Configuration $configuration
* @param string $content
* @param array $data
*
* @return array
* @throws ImporterErrorException

29
app/Services/CSV/Roles/RoleService.php

@ -24,9 +24,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Roles;
use App\Exceptions\ImporterErrorException;
use App\Services\Camt\Transaction;
use App\Services\CSV\Specifics\SpecificInterface;
use App\Services\CSV\Specifics\SpecificService;
use App\Services\Session\Constants;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Storage\StorageService;
@ -39,6 +38,8 @@ use League\Csv\InvalidArgument;
use League\Csv\Reader;
use League\Csv\Statement;
use League\Csv\UnableToProcessCsv;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class RoleService
@ -107,19 +108,6 @@ class RoleService
}
}
// specific processors may add or remove headers.
// so those must be processed as well.
// Fix as suggested by @FelikZ in https://github.com/firefly-iii/csv-importer/pull/4
// TODO no longer used.
/** @var string $name */
foreach ($configuration->getSpecifics() as $name) {
if (SpecificService::exists($name)) {
/** @var SpecificInterface $object */
$object = app(SpecificService::fullClass($name));
$headers = $object->runOnHeaders($headers);
}
}
return $headers;
}
@ -184,10 +172,13 @@ class RoleService
}
/**
* @param string $content
* @param Configuration $configuration
* @param string $content
* @param Configuration $configuration
*
* @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
public static function getExampleDataFromCamt(string $content, Configuration $configuration): array
{
@ -236,14 +227,14 @@ class RoleService
$splits = $transaction->countSplits();
if(0 === $splits) {
$value = $transaction->getFieldByIndex($name, 0);
if(null !== $value && '' !== $value) {
if('' !== $value) {
$examples[$name][] = $value;
}
}
if($splits > 0) {
for($index = 0; $index < $splits; $index++) {
$value = $transaction->getFieldByIndex($name, $index);
if(null !== $value && '' !== $value) {
if('' !== $value) {
$examples[$name][] = $value;
}
}

68
app/Services/Camt/Conversion/RoutineManager.php

@ -114,7 +114,10 @@ class RoutineManager implements RoutineManagerInterface
/**
* @inheritDoc
* @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
public function start(): array
{
@ -158,71 +161,6 @@ class RoutineManager implements RoutineManagerInterface
return $camtMessage;
}
/**
* @param int $count
*/
private function mergeMessages(int $count): void
{
$one = $this->csvFileProcessor->getMessages();
$two = $this->lineProcessor->getMessages();
$three = $this->columnValueConverter->getMessages();
$four = $this->pseudoTransactionProcessor->getMessages();
$total = [];
for ($i = 0; $i < $count; $i++) {
$total[$i] = array_merge(
$one[$i] ?? [],
$two[$i] ?? [],
$three[$i] ?? [],
$four[$i] ?? [],
);
}
$this->allMessages = $total;
}
/**
* @param int $count
*/
private function mergeWarnings(int $count): void
{
$one = $this->csvFileProcessor->getWarnings();
$two = $this->lineProcessor->getWarnings();
$three = $this->columnValueConverter->getWarnings();
$four = $this->pseudoTransactionProcessor->getWarnings();
$total = [];
for ($i = 0; $i < $count; $i++) {
$total[$i] = array_merge(
$one[$i] ?? [],
$two[$i] ?? [],
$three[$i] ?? [],
$four[$i] ?? [],
);
}
$this->allWarnings = $total;
}
/**
* @param int $count
*/
private function mergeErrors(int $count): void
{
$one = $this->csvFileProcessor->getErrors();
$two = $this->lineProcessor->getErrors();
$three = $this->columnValueConverter->getErrors();
$four = $this->pseudoTransactionProcessor->getErrors();
$total = [];
for ($i = 0; $i < $count; $i++) {
$total[$i] = array_merge(
$one[$i] ?? [],
$two[$i] ?? [],
$three[$i] ?? [],
$four[$i] ?? [],
);
}
$this->allErrors = $total;
}
/**
* @param string $content
*/

6
app/Services/Camt/Conversion/TransactionMapper.php

@ -2,6 +2,7 @@
namespace App\Services\Camt\Conversion;
use App\Exceptions\ImporterErrorException;
use App\Services\CSV\Mapper\GetAccounts;
use App\Services\Shared\Configuration\Configuration;
use Carbon\Carbon;
@ -19,6 +20,7 @@ class TransactionMapper
/**
* @param Configuration $configuration
* @throws ImporterErrorException
*/
public function __construct(Configuration $configuration)
{
@ -53,7 +55,7 @@ class TransactionMapper
*/
private function mapSingle(array $transaction): array
{
app('log')->debug(sprintf('Now mapping single transaction'));
app('log')->debug('Now mapping single transaction');
// make a new transaction:
$result = [
//'user' => 1, // ??
@ -130,6 +132,7 @@ class TransactionMapper
break;
case 'description': // TODO think about a config value to use both values from level C and D
$current['description'] = $current['description'] ?? '';
$addition = '';
if ('group' === $group_handling || 'split' === $group_handling) {
// use first description
$addition = $data['data'][0];
@ -428,7 +431,6 @@ class TransactionMapper
$accountType['destination'] ?: '<null>'
)
); // 285
return;
}
}

88
app/Services/Camt/Transaction.php

@ -9,6 +9,8 @@ use App\Services\Shared\Configuration\Configuration;
use Genkgo\Camt\Camt053\DTO\Statement;
use Genkgo\Camt\DTO\Address;
use Genkgo\Camt\DTO\BBANAccount;
use Genkgo\Camt\DTO\Creditor;
use Genkgo\Camt\DTO\Debtor;
use Genkgo\Camt\DTO\Entry;
use Genkgo\Camt\DTO\EntryTransactionDetail;
use Genkgo\Camt\DTO\IbanAccount;
@ -32,24 +34,24 @@ class Transaction
/**
* @param Configuration $configuration
* @param Message $levelA
* @param Statement $levelB
* @param Entry $levelC
* @param array $levelD
* @param Configuration $configuration
* @param Message $levelA
* @param Statement $levelB
* @param Entry $levelC
* @param array $levelD
*/
public function __construct(
Configuration $configuration,
Message $levelA,
Statement $levelB,
Entry $levelC,
array $levelD
Message $levelA,
Statement $levelB,
Entry $levelC,
array $levelD
) {
$this->configuration = $configuration;
$this->levelA = $levelA;
$this->levelB = $levelB;
$this->levelC = $levelC;
$this->levelD = $levelD;
$this->configuration = $configuration;
$this->levelA = $levelA;
$this->levelB = $levelB;
$this->levelC = $levelC;
$this->levelD = $levelD;
}
/**
@ -61,7 +63,7 @@ class Transaction
}
/**
* @param int $index
* @param int $index
*
* @return string
*/
@ -72,7 +74,7 @@ class Transaction
}
/**
* @param int $index
* @param int $index
*
* @return string
*/
@ -83,8 +85,8 @@ class Transaction
}
/**
* @param string $field
* @param int $index
* @param string $field
* @param int $index
*
* @return string
* @throws ImporterErrorException
@ -94,18 +96,18 @@ class Transaction
switch ($field) {
default:
// temporary debug message:
echo sprintf('Unknown field "%s" in getFieldByIndex(%d)', $field, $index);
echo PHP_EOL;
exit;
// echo sprintf('Unknown field "%s" in getFieldByIndex(%d)', $field, $index);
// echo PHP_EOL;
// exit;
// end temporary debug message
throw new ImporterErrorException(sprintf('Unknown field "%s" in getFieldByIndex(%d)', $field, $index));
// LEVEL A
// LEVEL A
case 'messageId':
// always the same, since its level A.
return (string)$this->levelA->getGroupHeader()->getMessageId();
// LEVEL B
// LEVEL B
case 'statementId':
// always the same, since its level B.
return (string)$this->levelB->getId();
@ -162,7 +164,7 @@ class Transaction
// always the same, since its level C.
return (string)$this->levelC->getBankTransactionCode()->getDomain()->getFamily()->getSubFamilyCode();
// LEVEL D
// LEVEL D
case 'entryDetailAccountServicerReference':
if (0 === count($this->levelD) || !array_key_exists($index, $this->levelD)) {
return '';
@ -254,9 +256,9 @@ class Transaction
return $result;
}
/** @var EntryTransactionDetail $info */
$info = $this->levelD[$index];
$info = $this->levelD[$index];
$opposingAccount = $this->getOpposingParty($info)?->getAccount();
if (null !== $opposingAccount && IbanAccount::class === get_class($opposingAccount)) {
if (IbanAccount::class === get_class($opposingAccount)) {
$result = (string)$opposingAccount->getIdentification();
}
@ -269,9 +271,9 @@ class Transaction
return $result;
}
/** @var EntryTransactionDetail $info */
$info = $this->levelD[$index];
$info = $this->levelD[$index];
$opposingAccount = $this->getOpposingParty($info)?->getAccount();
$class = null !== $opposingAccount ? get_class($opposingAccount) : '';
$class = null !== $opposingAccount ? get_class($opposingAccount) : '';
if (in_array($class, $list, true)) {
$result = (string)$opposingAccount->getIdentification();
}
@ -284,14 +286,13 @@ class Transaction
return $result;
}
/** @var EntryTransactionDetail $info */
$info = $this->levelD[$index];
$info = $this->levelD[$index];
//$result = '';
$opposingParty = $this->getOpposingParty($info);
$result = $this->getOpposingName($opposingParty);
$result = $this->getOpposingName($opposingParty);
return $result;
}
}
private function getDecimalAmount(?Money $money): string
@ -306,7 +307,7 @@ class Transaction
}
/**
* @param int $index
* @param int $index
*
* @return string
*/
@ -316,39 +317,37 @@ class Transaction
return (string)$this->getDecimalAmount($this->levelC->getAmount());
}
private function getOpposingName(RelatedParty $relatedParty, bool $useEntireAddress = false)
{ // TODO make depend on configuration
if ('' === (string) $relatedParty->getRelatedPartyType()->getName()) {
private function getOpposingName(RelatedParty $relatedParty, bool $useEntireAddress = false): string {
$opposingName = '';
// TODO make depend on configuration
if ('' === (string)$relatedParty->getRelatedPartyType()->getName()) {
// there is no "name", so use the address instead
$opposingName = $this->generateAddressLine($relatedParty->getRelatedPartyType()->getAddress());
}
if ('' !== (string) $relatedParty->getRelatedPartyType()->getName()) {
if ('' !== (string)$relatedParty->getRelatedPartyType()->getName()) {
// there is a name
$opposingName = $relatedParty->getRelatedPartyType()->getName();
// but maybe you want also the entire address
if ($useEntireAddress and $addressLine = $this->generateAddressLine($relatedParty->getRelatedPartyType()->getAddress())) {
$opposingName .= ', ' . $addressLine;
$opposingName .= ', '.$addressLine;
}
}
return $opposingName;
}
private function generateAddressLine(Address $address = null)
{
private function generateAddressLine(Address $address = null) {
$addressLines = implode(", ", $address->getAddressLines());
return $addressLines;
}
/**
* @param EntryTransactionDetail $transactionDetail
*
* @return void
* @param EntryTransactionDetail $transactionDetail
*/
private function getOpposingParty(EntryTransactionDetail $transactionDetail)
private function getOpposingParty(EntryTransactionDetail $transactionDetail): Creditor|Debtor|null
{
$relatedParties = $transactionDetail->getRelatedParties();
$relatedParties = $transactionDetail->getRelatedParties();
$targetRelatedPartyObject = "Genkgo\Camt\DTO\Creditor";
if ($transactionDetail->getAmount()->getAmount() > 0) { // which part in this array is the interesting one?
$targetRelatedPartyObject = "Genkgo\Camt\DTO\Debtor";
@ -358,5 +357,6 @@ class Transaction
return $relatedParty;
}
}
return null;
}
}

9
app/Services/Nordigen/Conversion/Routine/GenerateTransactions.php

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Conversion\Routine;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Model\Transaction;
@ -68,6 +69,7 @@ class GenerateTransactions
/**
* TODO the result of this method is currently not used.
*
* @throws AgreementExpiredException
* @throws ImporterErrorException
*/
public function collectNordigenAccounts(): void
@ -112,6 +114,7 @@ class GenerateTransactions
/**
*
* @throws ApiHttpException
*/
public function collectTargetAccounts(): void
{
@ -263,10 +266,11 @@ class GenerateTransactions
/**
* TODO function is way too complex.
*
* @param string $accountId
* @param Transaction $entry
* @param string $accountId
* @param Transaction $entry
*
* @return array
* @throws ImporterHttpException
*/
private function generateTransaction(string $accountId, Transaction $entry): array
{
@ -479,6 +483,7 @@ class GenerateTransactions
}
/**
* TODO Method "getAccountTypes" does not exist and I'm not sure what it is supposed to do.
* @param int $mappedId
*
* @return string

2
app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php

@ -93,7 +93,7 @@ class TransactionProcessor
return [];
}
app('log')->debug(sprintf('Done downloading information for debug purposes.'));
app('log')->debug('Done downloading information for debug purposes.');
$accessToken = TokenManager::getAccessToken();
$url = config('nordigen.url');

5
app/Services/Nordigen/Request/GetAccountBalanceRequest.php

@ -24,7 +24,9 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Request;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Response\ArrayResponse;
use App\Services\Shared\Response\Response;
@ -51,7 +53,10 @@ class GetAccountBalanceRequest extends Request
/**
* @inheritDoc
* @return Response
* @throws AgreementExpiredException
* @throws ImporterErrorException
* @throws ImporterHttpException
*/
public function get(): Response
{

5
app/Services/Nordigen/Request/GetAccountBasicRequest.php

@ -24,7 +24,9 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Request;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Response\ArrayResponse;
use App\Services\Shared\Response\Response;
@ -51,7 +53,10 @@ class GetAccountBasicRequest extends Request
/**
* @inheritDoc
* @return Response
* @throws AgreementExpiredException
* @throws ImporterErrorException
* @throws ImporterHttpException
*/
public function get(): Response
{

2
app/Services/Nordigen/Request/GetRequisitionRequest.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Request;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Response\ErrorResponse;
@ -53,6 +54,7 @@ class GetRequisitionRequest extends Request
/**
* @inheritDoc
* @throws AgreementExpiredException
*/
public function get(): Response
{

5
app/Services/Nordigen/Request/ListAccountsRequest.php

@ -24,7 +24,9 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Request;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Response\ListAccountsResponse;
use App\Services\Shared\Response\Response;
@ -59,7 +61,10 @@ class ListAccountsRequest extends Request
/**
* @inheritDoc
* @return Response
* @throws AgreementExpiredException
* @throws ImporterErrorException
* @throws ImporterHttpException
*/
public function get(): Response
{

2
app/Services/Nordigen/Request/ListBanksRequest.php

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Request;
use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Response\ErrorResponse;
@ -51,6 +52,7 @@ class ListBanksRequest extends Request
/**
* @inheritDoc
* @throws AgreementExpiredException
*/
public function get(): Response
{

2
app/Services/Nordigen/Request/PostNewRequisitionRequest.php

@ -26,6 +26,7 @@ namespace App\Services\Nordigen\Request;
use App\Services\Nordigen\Response\NewRequisitionResponse;
use App\Services\Shared\Response\Response;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class PostNewRequisitionRequest
@ -56,6 +57,7 @@ class PostNewRequisitionRequest extends Request
/**
* @inheritDoc
* @throws GuzzleException
*/
public function post(): Response
{

2
app/Services/Nordigen/Request/PostNewTokenRequest.php

@ -27,6 +27,7 @@ namespace App\Services\Nordigen\Request;
use App\Services\Nordigen\Response\TokenSetResponse;
use App\Services\Shared\Response\Response;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class PostNewTokenRequest
@ -51,6 +52,7 @@ class PostNewTokenRequest extends Request
/**
* @inheritDoc
* @throws GuzzleException
*/
public function post(): Response
{

2
app/Services/Nordigen/Request/PostNewUserAgreement.php

@ -26,6 +26,7 @@ namespace App\Services\Nordigen\Request;
use App\Services\Nordigen\Response\NewUserAgreementResponse;
use App\Services\Shared\Response\Response;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class PostNewUserAgreement
@ -57,6 +58,7 @@ class PostNewUserAgreement extends Request
/**
* @inheritDoc
* @throws GuzzleException
*/
public function post(): Response
{

8
app/Services/Nordigen/Request/Request.php

@ -100,7 +100,7 @@ abstract class Request
{
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
if (null !== $this->parameters) {
if (0 !== count($this->parameters)) {
$fullUrl = sprintf('%s?%s', $fullUrl, http_build_query($this->parameters));
}
app('log')->debug(sprintf('authenticatedGet(%s)', $fullUrl));
@ -137,7 +137,7 @@ abstract class Request
$json = [];
if (method_exists($e, 'getResponse')) {
$body = (string)$e->getResponse()->getBody();
$json = json_decode($body, true, 512) ?? [];
$json = json_decode($body, true) ?? [];
}
if (array_key_exists('summary', $json) and str_ends_with($json['summary'], 'has expired')) {
$exception = new AgreementExpiredException();
@ -165,7 +165,7 @@ abstract class Request
sprintf(
'Could not decode JSON (%s). Error[%d] is: %s. Response: %s',
$fullUrl,
$res ? $res->getStatusCode() : 0,
$res->getStatusCode(),
$e->getMessage(),
$body
)
@ -254,7 +254,7 @@ abstract class Request
app('log')->debug(sprintf('Now at %s', __METHOD__));
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
if (null !== $this->parameters) {
if (0 !== count($this->parameters)) {
$fullUrl = sprintf('%s?%s', $fullUrl, http_build_query($this->parameters));
}

6
app/Services/Nordigen/Services/AccountInformationCollector.php

@ -170,7 +170,11 @@ class AccountInformationCollector
}
/**
* @param Account $account
* @param Account $account
* @return Account
* @throws AgreementExpiredException
* @throws ImporterErrorException
* @throws ImporterHttpException
*/
private static function getBasicDetails(Account $account): Account
{

2
app/Services/Nordigen/TokenManager.php

@ -56,7 +56,9 @@ class TokenManager
}
/**
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/
public static function validateAllTokens(): void
{

2
app/Services/Shared/Configuration/Configuration.php

@ -759,7 +759,7 @@ class Configuration
}
/**
* @param string $nordigenBank
* @param string $nordigenMaxDays
*/
public function setNordigenMaxDays(string $nordigenMaxDays): void
{

2
app/Services/Shared/Import/Routine/InfoCollector.php

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace App\Services\Shared\Import\Routine;
use App\Services\Shared\Authentication\SecretManager;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Account;
use GrumpyDictator\FFIIIApiSupport\Request\GetAccountsRequest;
@ -40,6 +41,7 @@ class InfoCollector
* Will be used in mapping routine.
*
* @return array
* @throws ApiHttpException
*/
public function collectAccountTypes(): array
{

2
app/Services/Spectre/Conversion/Routine/GenerateTransactions.php

@ -28,6 +28,7 @@ use App\Services\Shared\Authentication\SecretManager;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use App\Services\Spectre\Model\Transaction;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Account;
use GrumpyDictator\FFIIIApiSupport\Request\GetAccountsRequest;
use GrumpyDictator\FFIIIApiSupport\Response\GetAccountsResponse;
@ -57,6 +58,7 @@ class GenerateTransactions
/**
*
* @throws ApiHttpException
*/
public function collectTargetAccounts(): void
{

2
app/Services/Spectre/Conversion/RoutineManager.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\Spectre\Conversion;
use App\Exceptions\ImporterHttpException;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\GeneratesIdentifier;
use App\Services\Shared\Conversion\RoutineManagerInterface;
@ -108,6 +109,7 @@ class RoutineManager implements RoutineManagerInterface
/**
* @inheritDoc
* @throws ImporterHttpException
*/
public function start(): array
{

10
app/Services/Spectre/Model/Transaction.php

@ -55,7 +55,7 @@ class Transaction
/**
* Transaction constructor.
*
* @param array $data
* @param array $data
*
* @return Transaction
*/
@ -155,7 +155,7 @@ class Transaction
}
/**
* @param string $direction
* @param string $direction
*
* @return string
*/
@ -191,9 +191,9 @@ class Transaction
return [
'id' => (string)$this->id,
'account_id' => $this->accountId,
'made_on' => $this->madeOn ? $this->madeOn->toW3cString() : '',
'created_at' => $this->createdAt ? $this->createdAt->toW3cString() : '',
'updated_at' => $this->updatedAt ? $this->updatedAt->toW3cString() : '',
'made_on' => $this->madeOn->toW3cString(),
'created_at' => $this->createdAt->toW3cString(),
'updated_at' => $this->updatedAt->toW3cString(),
'mode' => $this->mode,
'status' => $this->status,
'amount' => $this->amount,

2
app/Services/Spectre/Request/GetAccountsRequest.php

@ -28,6 +28,7 @@ use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\GetAccountsResponse;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class GetAccountsRequest
@ -56,6 +57,7 @@ class GetAccountsRequest extends Request
/**
* @inheritDoc
* @throws GuzzleException
*/
public function get(): Response
{

2
app/Services/Spectre/Request/ListConnectionsRequest.php

@ -28,6 +28,7 @@ use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\ListConnectionsResponse;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class ListConnectionsRequest
@ -55,6 +56,7 @@ class ListConnectionsRequest extends Request
/**
* @inheritDoc
* @throws GuzzleException
*/
public function get(): Response
{

2
app/Services/Spectre/Request/PostConnectSessionsRequest.php

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\Spectre\Request;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\PostConnectSessionResponse;
@ -60,6 +61,7 @@ class PostConnectSessionsRequest extends Request
/**
* @inheritDoc
* @throws ImporterErrorException
*/
public function post(): Response
{

4
app/Services/Spectre/Request/PostCustomerRequest.php

@ -61,10 +61,12 @@ class PostCustomerRequest extends Request
/**
* @inheritDoc
* @throws ImporterErrorException
* @throws ImporterErrorException
*/
public function post(): Response
{
if (null === $this->identifier) {
if ('' === $this->identifier) {
throw new ImporterErrorException('No identifier for PostCustomerRequest');
}
$data = [

2
app/Services/Spectre/Request/PutRefreshConnectionRequest.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\Spectre\Request;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\PutRefreshConnectionResponse;
@ -67,6 +68,7 @@ class PutRefreshConnectionRequest extends Request
/**
* @inheritDoc
* @throws ImporterErrorException
*/
public function put(): Response
{

6
app/Services/Spectre/Request/Request.php

@ -102,7 +102,7 @@ abstract class Request
{
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
if (null !== $this->parameters) {
if (0 !== count($this->parameters)) {
$fullUrl = sprintf('%s?%s', $fullUrl, http_build_query($this->parameters));
}
$client = $this->getClient();
@ -139,7 +139,7 @@ abstract class Request
throw new ImporterErrorException('Transfer exception leads to error.', 0, $e);
}
if (null !== $res && 200 !== $res->getStatusCode()) {
if (200 !== $res->getStatusCode()) {
// return body, class must handle this
app('log')->error(sprintf('[3] Status code is %d', $res->getStatusCode()));
@ -154,7 +154,7 @@ abstract class Request
sprintf(
'Could not decode JSON (%s). Error[%d] is: %s. Response: %s',
$fullUrl,
$res ? $res->getStatusCode() : 0,
$res->getStatusCode(),
$e->getMessage(),
$body
)

7
app/Services/Storage/StorageService.php

@ -26,6 +26,7 @@ namespace App\Services\Storage;
use App\Exceptions\ImporterErrorException;
use JsonException;
use League\Flysystem\FilesystemException;
use Storage;
use UnexpectedValueException;
@ -65,9 +66,10 @@ class StorageService
}
/**
* @param array $array
* @param array $array
*
* @return string
* @throws FilesystemException
* @throws JsonException
*/
public static function storeArray(array $array): string
@ -87,9 +89,10 @@ class StorageService
}
/**
* @param string $content
* @param string $content
*
* @return string
* @throws FilesystemException
* @throws ImporterErrorException
*/
public static function storeContent(string $content): string

5
app/Support/Internal/CollectsAccounts.php

@ -43,6 +43,7 @@ use App\Services\Spectre\Response\GetAccountsResponse;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Account;
use GrumpyDictator\FFIIIApiSupport\Request\GetAccountsRequest;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;
trait CollectsAccounts
@ -144,9 +145,11 @@ trait CollectsAccounts
}
/**
* @param Configuration $configuration
* @param Configuration $configuration
*
* @return array
* @throws GuzzleException
* @throws ImporterHttpException
*/
protected function getSpectreAccounts(Configuration $configuration): array
{

Loading…
Cancel
Save