mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-16 06:38:09 +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\TransactionRules\Actions;
|
||||
@@ -27,9 +26,7 @@ use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
/**
|
||||
* Interface ActionInterface
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Interface ActionInterface.
|
||||
*/
|
||||
interface ActionInterface
|
||||
{
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,13 +28,10 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AddTag
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class AddTag.
|
||||
*/
|
||||
class AddTag implements ActionInterface
|
||||
{
|
||||
|
||||
/** @var RuleAction */
|
||||
private $action;
|
||||
|
||||
@@ -56,12 +52,11 @@ class AddTag implements ActionInterface
|
||||
*/
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
|
||||
// journal has this tag maybe?
|
||||
$tag = Tag::firstOrCreateEncrypted(['tag' => $this->action->action_value, 'user_id' => $journal->user->id]);
|
||||
|
||||
$count = $journal->tags()->where('tag_id', $tag->id)->count();
|
||||
if ($count === 0) {
|
||||
if (0 === $count) {
|
||||
$journal->tags()->save($tag);
|
||||
Log::debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal->id));
|
||||
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AppendDescription
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class AppendDescription.
|
||||
*/
|
||||
class AppendDescription implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AppendNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class AppendNotes.
|
||||
*/
|
||||
class AppendNotes implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -56,7 +52,7 @@ class AppendNotes implements ActionInterface
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$dbNote = $journal->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($journal);
|
||||
}
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ClearBudget
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Class ClearBudget.
|
||||
*/
|
||||
class ClearBudget implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ClearCategory
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Class ClearCategory.
|
||||
*/
|
||||
class ClearCategory implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ClearNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class ClearNotes.
|
||||
*/
|
||||
class ClearNotes implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AppendDescription
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class AppendDescription.
|
||||
*/
|
||||
class PrependDescription implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -58,7 +54,6 @@ class PrependDescription implements ActionInterface
|
||||
$journal->description = $this->action->action_value . $journal->description;
|
||||
$journal->save();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class PrependNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class PrependNotes.
|
||||
*/
|
||||
class PrependNotes implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -56,7 +52,7 @@ class PrependNotes implements ActionInterface
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$dbNote = $journal->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($journal);
|
||||
}
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RemoveAllTags
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class RemoveAllTags.
|
||||
*/
|
||||
class RemoveAllTags implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class RemoveTag
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class RemoveTag.
|
||||
*/
|
||||
class RemoveTag implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -64,7 +60,7 @@ class RemoveTag implements ActionInterface
|
||||
}
|
||||
)->first();
|
||||
|
||||
if (!is_null($tag)) {
|
||||
if (null !== $tag) {
|
||||
Log::debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal->id));
|
||||
$journal->tags()->detach([$tag->id]);
|
||||
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -31,15 +30,12 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetBudget
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Class SetBudget.
|
||||
*/
|
||||
class SetBudget implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -67,13 +63,13 @@ class SetBudget implements ActionInterface
|
||||
return $current->name === $search;
|
||||
}
|
||||
)->first();
|
||||
if (is_null($budget)) {
|
||||
if (null === $budget) {
|
||||
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($journal->transactionType->type !== TransactionType::WITHDRAWAL) {
|
||||
if (TransactionType::WITHDRAWAL !== $journal->transactionType->type) {
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetBudget could not set budget of journal #%d to "%s" because journal is a %s.',
|
||||
@@ -90,7 +86,6 @@ class SetBudget implements ActionInterface
|
||||
|
||||
$journal->budgets()->sync([$budget->id]);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetCategory
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Class SetCategory.
|
||||
*/
|
||||
class SetCategory implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -28,15 +27,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetDescription
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class SetDescription.
|
||||
*/
|
||||
class SetDescription implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -32,24 +31,21 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetDestinationAccount
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Class SetDestinationAccount.
|
||||
*/
|
||||
class SetDestinationAccount implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
/** @var TransactionJournal */
|
||||
/** @var TransactionJournal */
|
||||
private $journal;
|
||||
|
||||
/** @var Account */
|
||||
/** @var Account */
|
||||
private $newDestinationAccount;
|
||||
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -81,7 +77,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
$type = $journal->transactionType->type;
|
||||
|
||||
// if this is a deposit or a transfer, the destination account must be an asset account or a default account, and it MUST exist:
|
||||
if (($type === TransactionType::DEPOSIT || $type === TransactionType::TRANSFER) && !$this->findAssetAccount()) {
|
||||
if ((TransactionType::DEPOSIT === $type || TransactionType::TRANSFER === $type) && !$this->findAssetAccount()) {
|
||||
Log::error(
|
||||
sprintf(
|
||||
'Cannot change destination account of journal #%d because no asset account with name "%s" exists.',
|
||||
@@ -94,7 +90,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
}
|
||||
|
||||
// if this is a withdrawal, the new destination account must be a expense account and may be created:
|
||||
if ($type === TransactionType::WITHDRAWAL) {
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$this->findExpenseAccount();
|
||||
}
|
||||
|
||||
@@ -117,7 +113,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
||||
|
||||
if (is_null($account->id)) {
|
||||
if (null === $account->id) {
|
||||
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
||||
|
||||
return false;
|
||||
@@ -134,7 +130,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
private function findExpenseAccount()
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]);
|
||||
if (is_null($account->id)) {
|
||||
if (null === $account->id) {
|
||||
// create new revenue account with this name:
|
||||
$data = [
|
||||
'name' => $this->action->action_value,
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -29,15 +28,12 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetNotes
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Actions
|
||||
* Class SetNotes.
|
||||
*/
|
||||
class SetNotes implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -56,7 +52,7 @@ class SetNotes implements ActionInterface
|
||||
public function act(TransactionJournal $journal): bool
|
||||
{
|
||||
$dbNote = $journal->notes()->first();
|
||||
if (is_null($dbNote)) {
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($journal);
|
||||
}
|
||||
|
||||
@@ -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\TransactionRules\Actions;
|
||||
@@ -32,24 +31,21 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SetSourceAccount
|
||||
*
|
||||
* @package FireflyIII\TransactionRules\Action
|
||||
* Class SetSourceAccount.
|
||||
*/
|
||||
class SetSourceAccount implements ActionInterface
|
||||
{
|
||||
private $action;
|
||||
|
||||
/** @var TransactionJournal */
|
||||
/** @var TransactionJournal */
|
||||
private $journal;
|
||||
|
||||
/** @var Account */
|
||||
/** @var Account */
|
||||
private $newSourceAccount;
|
||||
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* TriggerInterface constructor.
|
||||
*
|
||||
@@ -80,7 +76,7 @@ class SetSourceAccount implements ActionInterface
|
||||
// journal type:
|
||||
$type = $journal->transactionType->type;
|
||||
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
|
||||
if (($type === TransactionType::WITHDRAWAL || $type === TransactionType::TRANSFER) && !$this->findAssetAccount()) {
|
||||
if ((TransactionType::WITHDRAWAL === $type || TransactionType::TRANSFER === $type) && !$this->findAssetAccount()) {
|
||||
Log::error(
|
||||
sprintf(
|
||||
'Cannot change source account of journal #%d because no asset account with name "%s" exists.',
|
||||
@@ -93,7 +89,7 @@ class SetSourceAccount implements ActionInterface
|
||||
}
|
||||
|
||||
// if this is a deposit, the new source account must be a revenue account and may be created:
|
||||
if ($type === TransactionType::DEPOSIT) {
|
||||
if (TransactionType::DEPOSIT === $type) {
|
||||
$this->findRevenueAccount();
|
||||
}
|
||||
|
||||
@@ -116,7 +112,7 @@ class SetSourceAccount implements ActionInterface
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
|
||||
|
||||
if (is_null($account->id)) {
|
||||
if (null === $account->id) {
|
||||
Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
|
||||
|
||||
return false;
|
||||
@@ -133,7 +129,7 @@ class SetSourceAccount implements ActionInterface
|
||||
private function findRevenueAccount()
|
||||
{
|
||||
$account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
|
||||
if (is_null($account->id)) {
|
||||
if (null === $account->id) {
|
||||
// create new revenue account with this name:
|
||||
$data = [
|
||||
'name' => $this->action->action_value,
|
||||
|
||||
Reference in New Issue
Block a user