mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Improve code quality and add documentation in folder "Generator"
This commit is contained in:
@@ -18,15 +18,20 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Generator\Report\Audit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Steam;
|
||||
@@ -36,15 +41,18 @@ use Steam;
|
||||
*/
|
||||
class MonthReportGenerator implements ReportGeneratorInterface
|
||||
{
|
||||
/** @var Collection */
|
||||
/** @var Collection The accounts used. */
|
||||
private $accounts;
|
||||
/** @var Carbon */
|
||||
/** @var Carbon End date of the report. */
|
||||
private $end;
|
||||
/** @var Carbon */
|
||||
/** @var Carbon Start date of the report. */
|
||||
private $start;
|
||||
|
||||
/**
|
||||
* Generates the report.
|
||||
*
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function generate(): string
|
||||
{
|
||||
@@ -77,6 +85,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Account collection setter.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -89,6 +99,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Budget collection setter.
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -99,6 +111,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Category collection setter.
|
||||
*
|
||||
* @param Collection $categories
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -109,6 +123,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* End date setter.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -121,6 +137,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Expenses collection setter.
|
||||
*
|
||||
* @param Collection $expense
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -131,6 +149,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Start date collection setter.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -143,6 +163,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Tags collection setter.
|
||||
*
|
||||
* @param Collection $tags
|
||||
*
|
||||
* @return ReportGeneratorInterface
|
||||
@@ -153,18 +175,25 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the audit report.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // not that long
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getAuditReport(Account $account, Carbon $date): array
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$accountRepository->setUser($account->user);
|
||||
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end);
|
||||
@@ -172,7 +201,11 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
$journals = $journals->reverse();
|
||||
$dayBeforeBalance = Steam::balance($account, $date);
|
||||
$startBalance = $dayBeforeBalance;
|
||||
$currency = $currencyRepos->find((int)$account->getMeta('currency_id'));
|
||||
$currency = $currencyRepos->findNull((int)$accountRepository->getMetaValue($account, 'currency_id'));
|
||||
|
||||
if (null === $currency) {
|
||||
throw new FireflyException('Unexpected NULL value in account currency preference.');
|
||||
}
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journals as $transaction) {
|
||||
@@ -186,7 +219,6 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
$newBalance = bcadd($startBalance, $transactionAmount);
|
||||
$transaction->after = $newBalance;
|
||||
$startBalance = $newBalance;
|
||||
$transaction->currency = $currency;
|
||||
}
|
||||
|
||||
$return = [
|
||||
|
||||
@@ -27,5 +27,4 @@ namespace FireflyIII\Generator\Report\Audit;
|
||||
*/
|
||||
class MultiYearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
// Doesn't do anything different.
|
||||
}
|
||||
|
||||
@@ -27,5 +27,4 @@ namespace FireflyIII\Generator\Report\Audit;
|
||||
*/
|
||||
class YearReportGenerator extends MonthReportGenerator
|
||||
{
|
||||
// Doesn't do anything different.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user