Improve code quality.

This commit is contained in:
James Cole 2018-07-22 15:08:56 +02:00
parent d4ba014a8a
commit a941519db5
41 changed files with 210 additions and 52 deletions

View File

@ -183,6 +183,9 @@ class Amount implements ConverterInterface
}
/**
* Replaces other characters like thousand separators with nothing to make the decimal separator the only special
* character in the string.
*
* @param string $decimal
* @param string $value
*

View File

@ -28,6 +28,8 @@ namespace FireflyIII\Import\Converter;
class AmountCredit implements ConverterInterface
{
/**
* Convert an amount, always return positive.
*
* @param $value
*
* @return string

View File

@ -28,6 +28,8 @@ namespace FireflyIII\Import\Converter;
class AmountDebit implements ConverterInterface
{
/**
* Convert amount, always return positive.
*
* @param $value
*
* @return string

View File

@ -28,6 +28,10 @@ namespace FireflyIII\Import\Converter;
interface ConverterInterface
{
/**
* Convert a value.
*
* @return mixed
*
* @param $value
*/
public function convert($value);

View File

@ -30,6 +30,8 @@ use Log;
class INGDebitCredit implements ConverterInterface
{
/**
* Convert Af or Bij to correct integer values.
*
* @param $value
*
* @return int

View File

@ -30,6 +30,8 @@ use Log;
class RabobankDebitCredit implements ConverterInterface
{
/**
* Convert D or A to integer values.
*
* @param $value
*
* @return int

View File

@ -37,11 +37,11 @@ use Log;
*/
class BunqJobConfiguration implements JobConfigurationInterface
{
/** @var BunqJobConfigurationInterface */
/** @var BunqJobConfigurationInterface Bunq job interface */
private $handler;
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -88,6 +88,8 @@ class BunqJobConfiguration implements JobConfigurationInterface
}
/**
* Set import job.
*
* @param ImportJob $importJob
*
* @throws FireflyException
@ -101,6 +103,8 @@ class BunqJobConfiguration implements JobConfigurationInterface
}
/**
* Get correct handler.
*
* @return BunqJobConfigurationInterface
* @throws FireflyException
*/

View File

@ -32,10 +32,10 @@ use Illuminate\Support\MessageBag;
*/
class FakeJobConfiguration implements JobConfigurationInterface
{
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -69,6 +69,8 @@ class FakeJobConfiguration implements JobConfigurationInterface
* @param array $data
*
* @return MessageBag
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function configureJob(array $data): MessageBag
{
@ -125,6 +127,8 @@ class FakeJobConfiguration implements JobConfigurationInterface
* Returns the view of the next step in the job configuration.
*
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getNextView(): string
{
@ -151,6 +155,8 @@ class FakeJobConfiguration implements JobConfigurationInterface
}
/**
* Set import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void

View File

@ -40,9 +40,9 @@ use Illuminate\Support\MessageBag;
*/
class FileJobConfiguration implements JobConfigurationInterface
{
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -91,6 +91,8 @@ class FileJobConfiguration implements JobConfigurationInterface
*
* @throws FireflyException
* @return string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getNextView(): string
{
@ -116,6 +118,8 @@ class FileJobConfiguration implements JobConfigurationInterface
}
/**
* Set import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void
@ -130,6 +134,8 @@ class FileJobConfiguration implements JobConfigurationInterface
*
* @return FileConfigurationInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function getConfigurationObject(): FileConfigurationInterface
{

View File

@ -62,6 +62,8 @@ interface JobConfigurationInterface
public function getNextView(): string;
/**
* Set import job.
*
* @param ImportJob $importJob
*/
public function setImportJob(ImportJob $importJob): void;

View File

@ -26,14 +26,10 @@ namespace FireflyIII\Import\JobConfiguration;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedConfigHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticatedHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\AuthenticateHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccount;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseAccountsHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\DoAuthenticateHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewConfig;
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewSpectreJobHandler;
use FireflyIII\Support\Import\JobConfiguration\Spectre\SpectreJobConfigurationInterface;
use Illuminate\Support\MessageBag;
@ -44,11 +40,11 @@ use Log;
*/
class SpectreJobConfiguration implements JobConfigurationInterface
{
/** @var SpectreJobConfigurationInterface */
/** @var SpectreJobConfigurationInterface The job handler. */
private $handler;
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -95,6 +91,8 @@ class SpectreJobConfiguration implements JobConfigurationInterface
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*
* @throws FireflyException
@ -108,8 +106,12 @@ class SpectreJobConfiguration implements JobConfigurationInterface
}
/**
* Get correct handler.
*
* @return SpectreJobConfigurationInterface
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function getHandler(): SpectreJobConfigurationInterface
{

View File

@ -32,6 +32,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
class AssetAccountIbans implements MapperInterface
{
/**
* Get map of asset accounts.
*
* @return array
*/
public function getMap(): array

View File

@ -32,6 +32,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
class AssetAccounts implements MapperInterface
{
/**
* Get map of asset accounts.
*
* @return array
*/
public function getMap(): array

View File

@ -31,6 +31,8 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
class Bills implements MapperInterface
{
/**
* Get map of bills.
*
* @return array
*/
public function getMap(): array

View File

@ -31,6 +31,8 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
class Budgets implements MapperInterface
{
/**
* Get map of budgets.
*
* @return array
*/
public function getMap(): array

View File

@ -31,6 +31,8 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
class Categories implements MapperInterface
{
/**
* Get map of categories.
*
* @return array
*/
public function getMap(): array

View File

@ -28,6 +28,8 @@ namespace FireflyIII\Import\Mapper;
interface MapperInterface
{
/**
* Get map of objects.
*
* @return array
*/
public function getMap(): array;

View File

@ -32,6 +32,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
class OpposingAccountIbans implements MapperInterface
{
/**
* Get map of opposing accounts.
* @return array
*/
public function getMap(): array

View File

@ -32,6 +32,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
class OpposingAccounts implements MapperInterface
{
/**
* Get map of opposing accounts.
*
* @return array
*/
public function getMap(): array

View File

@ -31,6 +31,8 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;
class Tags implements MapperInterface
{
/**
* Get map of tags.
*
* @return array
*/
public function getMap(): array

View File

@ -30,6 +30,8 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
class TransactionCurrencies implements MapperInterface
{
/**
* Get map of currencies.
*
* @return array
*/
public function getMap(): array

View File

@ -28,6 +28,8 @@ namespace FireflyIII\Import\MapperPreProcess;
interface PreProcessorInterface
{
/**
* Run preprocessor.
*
* @param string $value
*
* @return array

View File

@ -28,6 +28,8 @@ namespace FireflyIII\Import\MapperPreProcess;
class TagsComma implements PreProcessorInterface
{
/**
* Explode and filter list of comma separated tags.
*
* @param string $value
*
* @return array

View File

@ -28,6 +28,8 @@ namespace FireflyIII\Import\MapperPreProcess;
class TagsSpace implements PreProcessorInterface
{
/**
* Explode and filter list of space separated tags.
*
* @param string $value
*
* @return array

View File

@ -36,13 +36,14 @@ use Log;
*/
class BunqPrerequisites implements PrerequisitesInterface
{
/** @var User */
/** @var User The current user */
private $user;
/**
* @codeCoverageIgnore
* Returns view name that allows user to fill in prerequisites.
*
* @codeCoverageIgnore
*
* @return string
*/
public function getView(): string
@ -86,10 +87,11 @@ class BunqPrerequisites implements PrerequisitesInterface
}
/**
* @codeCoverageIgnore
* Set the user for this Prerequisites-routine. Class is expected to implement and save this.
*
* @param User $user
*
* @codeCoverageIgnore
*/
public function setUser(User $user): void
{
@ -104,6 +106,7 @@ class BunqPrerequisites implements PrerequisitesInterface
* @param array $data
*
* @return MessageBag
*
*/
public function storePrerequisites(array $data): MessageBag
{
@ -112,7 +115,6 @@ class BunqPrerequisites implements PrerequisitesInterface
Log::debug('Storing bunq API key');
app('preferences')->setForUser($this->user, 'bunq_api_key', $apiKey);
app('preferences')->setForUser($this->user, 'bunq_external_ip', $externalIP);
$environment = $this->getBunqEnvironment();
$deviceDescription = 'Firefly III v' . config('firefly.version');
$permittedIps = [$externalIP];
@ -147,8 +149,10 @@ class BunqPrerequisites implements PrerequisitesInterface
}
/**
* @codeCoverageIgnore
* Get correct bunq environment.
*
* @return BunqEnumApiEnvironmentType
* @codeCoverageIgnore
*/
private function getBunqEnvironment(): BunqEnumApiEnvironmentType
{
@ -164,6 +168,8 @@ class BunqPrerequisites implements PrerequisitesInterface
}
/**
* Check if we have API context.
*
* @return bool
*/
private function hasApiContext(): bool
@ -180,6 +186,8 @@ class BunqPrerequisites implements PrerequisitesInterface
}
/**
* Check if we have the API key.
*
* @return bool
*/
private function hasApiKey(): bool
@ -196,6 +204,8 @@ class BunqPrerequisites implements PrerequisitesInterface
}
/**
* Checks if we have an external IP.
*
* @return bool
*/
private function hasExternalIP(): bool

View File

@ -32,7 +32,7 @@ use Illuminate\Support\MessageBag;
*/
class FakePrerequisites implements PrerequisitesInterface
{
/** @var User */
/** @var User The current user */
private $user;
/**
@ -87,6 +87,8 @@ class FakePrerequisites implements PrerequisitesInterface
}
/**
* Store fake prerequisites.
*
* @param array $data
*
* @return MessageBag
@ -107,6 +109,8 @@ class FakePrerequisites implements PrerequisitesInterface
}
/**
* Check if we have an API key.
*
* @return bool
*/
private function hasApiKey(): bool

View File

@ -26,9 +26,10 @@ use FireflyIII\User;
use Illuminate\Support\MessageBag;
/**
* @codeCoverageIgnore
*
* This class contains all the routines necessary to import from a file. Hint: there are none.
*
* @codeCoverageIgnore
*/
class FilePrerequisites implements PrerequisitesInterface
{

View File

@ -32,7 +32,7 @@ use Log;
*/
class SpectrePrerequisites implements PrerequisitesInterface
{
/** @var User */
/** @var User The current user */
private $user;
/**
@ -156,6 +156,8 @@ class SpectrePrerequisites implements PrerequisitesInterface
}
/**
* Check if we have the App ID.
*
* @return bool
*/
private function hasAppId(): bool
@ -172,6 +174,8 @@ class SpectrePrerequisites implements PrerequisitesInterface
}
/**
* Check if we have the secret.
*
* @return bool
*/
private function hasSecret(): bool

View File

@ -35,10 +35,10 @@ use Log;
*/
class BunqRoutine implements RoutineInterface
{
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -63,7 +63,6 @@ class BunqRoutine implements RoutineInterface
$handler = app(StageNewHandler::class);
$handler->setImportJob($this->importJob);
$handler->run();
// make user choose accounts to import from.
$this->repository->setStage($this->importJob, 'choose-accounts');
$this->repository->setStatus($this->importJob, 'need_job_config');
@ -91,6 +90,8 @@ class BunqRoutine implements RoutineInterface
/**
* Set the import job.
*
* @param ImportJob $importJob
*
* @return void

View File

@ -36,9 +36,9 @@ use Log;
*/
class FakeRoutine implements RoutineInterface
{
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -51,6 +51,9 @@ class FakeRoutine implements RoutineInterface
*
* @return void
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function run(): void
{
@ -93,6 +96,8 @@ class FakeRoutine implements RoutineInterface
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*
*/

View File

@ -33,9 +33,9 @@ use Log;
*/
class FileRoutine implements RoutineInterface
{
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -66,6 +66,8 @@ class FileRoutine implements RoutineInterface
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*
* @return void

View File

@ -40,6 +40,8 @@ interface RoutineInterface
public function run(): void;
/**
* Set the import job.
*
* @param ImportJob $importJob
*
* @return void

View File

@ -36,10 +36,10 @@ use Log;
class SpectreRoutine implements RoutineInterface
{
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/**
@ -48,6 +48,9 @@ class SpectreRoutine implements RoutineInterface
* The final status of the routine must be "provider_finished".
*
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function run(): void
{
@ -108,6 +111,8 @@ class SpectreRoutine implements RoutineInterface
}
/**
* Set the import job.
*
* @param ImportJob $importJob
*
* @return void

View File

@ -32,12 +32,14 @@ namespace FireflyIII\Import\Specifics;
*/
class AbnAmroDescription implements SpecificInterface
{
/** @var array */
/** @var array The current row. */
public $row;
/**
* @codeCoverageIgnore
* Description of this specific fix.
*
* @return string
* @codeCoverageIgnore
*/
public static function getDescription(): string
{
@ -45,8 +47,10 @@ class AbnAmroDescription implements SpecificInterface
}
/**
* @codeCoverageIgnore
* Name of specific fix.
*
* @return string
* @codeCoverageIgnore
*/
public static function getName(): string
{
@ -54,9 +58,13 @@ class AbnAmroDescription implements SpecificInterface
}
/**
* Run the fix.
*
* @param array $row
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function run(array $row): array
{
@ -123,6 +131,9 @@ class AbnAmroDescription implements SpecificInterface
* Parses the current description in SEPA format.
*
* @return bool true if the description is SEPA format, false otherwise
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function parseSepaDescription(): bool
{
@ -177,6 +188,9 @@ class AbnAmroDescription implements SpecificInterface
* Parses the current description in TRTP format.
*
* @return bool true if the description is TRTP format, false otherwise
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function parseTRTPDescription(): bool
{

View File

@ -34,12 +34,14 @@ namespace FireflyIII\Import\Specifics;
*/
class IngDescription implements SpecificInterface
{
/** @var array */
/** @var array The current row. */
public $row;
/**
* @codeCoverageIgnore
* Description of the current specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getDescription(): string
{
@ -47,8 +49,10 @@ class IngDescription implements SpecificInterface
}
/**
* @codeCoverageIgnore
* Name of the current specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getName(): string
{
@ -56,9 +60,13 @@ class IngDescription implements SpecificInterface
}
/**
* Run the specific code.
*
* @param array $row
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function run(array $row): array
{
@ -112,7 +120,7 @@ class IngDescription implements SpecificInterface
}
/**
*
* Copy description to name of opposite account.
*/
private function copyDescriptionToOpposite(): void
{

View File

@ -28,8 +28,10 @@ namespace FireflyIII\Import\Specifics;
class PresidentsChoice implements SpecificInterface
{
/**
* @codeCoverageIgnore
* Description of specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getDescription(): string
{
@ -37,8 +39,10 @@ class PresidentsChoice implements SpecificInterface
}
/**
* @codeCoverageIgnore
* Name of specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getName(): string
{
@ -46,6 +50,8 @@ class PresidentsChoice implements SpecificInterface
}
/**
* Run this specific.
*
* @param array $row
*
* @return array

View File

@ -26,12 +26,17 @@ use Log;
/**
* Class RabobankDescription.
*
* @codeCoverageIgnore
* @deprecated
*/
class RabobankDescription implements SpecificInterface
{
/**
* @codeCoverageIgnore
* Description of this specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getDescription(): string
{
@ -39,8 +44,10 @@ class RabobankDescription implements SpecificInterface
}
/**
* @codeCoverageIgnore
* Name of this specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getName(): string
{
@ -48,9 +55,13 @@ class RabobankDescription implements SpecificInterface
}
/**
* Run the specific.
*
* @param array $row
*
* @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function run(array $row): array
{

View File

@ -28,8 +28,10 @@ namespace FireflyIII\Import\Specifics;
class SnsDescription implements SpecificInterface
{
/**
* @codeCoverageIgnore
* Get description of specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getDescription(): string
{
@ -37,8 +39,10 @@ class SnsDescription implements SpecificInterface
}
/**
* @codeCoverageIgnore
* Get name of specific.
*
* @return string
* @codeCoverageIgnore
*/
public static function getName(): string
{
@ -46,6 +50,8 @@ class SnsDescription implements SpecificInterface
}
/**
* Run specific.
*
* @param array $row
*
* @return array

View File

@ -28,16 +28,22 @@ namespace FireflyIII\Import\Specifics;
interface SpecificInterface
{
/**
* Get description.
*
* @return string
*/
public static function getDescription(): string;
/**
* Get name.
*
* @return string
*/
public static function getName(): string;
/**
* Run specific.
*
* @param array $row
*
* @return array

View File

@ -46,18 +46,20 @@ use Log;
* Creates new transactions based upon arrays. Will first check the array for duplicates.
*
* Class ImportArrayStorage
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ImportArrayStorage
{
/** @var bool */
/** @var bool Check for transfers during import. */
private $checkForTransfers = false;
/** @var ImportJob */
/** @var ImportJob The import job */
private $importJob;
/** @var JournalRepositoryInterface */
private $journalRepos;
/** @var ImportJobRepositoryInterface */
/** @var ImportJobRepositoryInterface Import job repository */
private $repository;
/** @var Collection */
/** @var Collection The transfers. */
private $transfers;
/**
@ -142,6 +144,8 @@ class ImportArrayStorage
/**
* Count the number of transfers in the array. If this is zero, don't bother checking for double transfers.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function countTransfers(): void
{
@ -156,10 +160,10 @@ class ImportArrayStorage
}
}
if (0 === $count) {
Log::debug('Count is zero.');
Log::debug('Count is zero, will not check for duplicate transfers.');
}
if ($count > 0) {
Log::debug(sprintf('Count is %d', $count));
Log::debug(sprintf('Count is %d, will check for duplicate transfers.', $count));
$this->checkForTransfers = true;
// get users transfers. Needed for comparison.
@ -169,6 +173,8 @@ class ImportArrayStorage
}
/**
* Get hash of transaction.
*
* @param array $transaction
*
* @throws FireflyException
@ -339,6 +345,9 @@ class ImportArrayStorage
*
* @return Collection
* @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
private function storeArray(): Collection
{
@ -431,6 +440,10 @@ class ImportArrayStorage
* @param $transaction
*
* @return bool
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function transferExists(array $transaction): bool
{

View File

@ -167,8 +167,8 @@ class JournalRepository implements JournalRepositoryInterface
Log::debug(sprintf('JSON encoded hash is: %s', $jsonEncode));
Log::debug(sprintf('Hash of hash is: %s', $hashOfHash));
$result = TransactionJournalMeta
::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
$result = TransactionJournalMeta::withTrashed()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->where('hash', $hashOfHash)
->where('name', 'importHashV2')
->first(['journal_meta.*']);