Code clean up.

This commit is contained in:
James Cole
2017-11-15 12:25:49 +01:00
parent 57dcdfa0c4
commit ffca858b8d
476 changed files with 2055 additions and 4181 deletions

View File

@@ -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\Repositories\Journal;
@@ -39,8 +38,6 @@ use Log;
* @property User $user
*
* Trait CreateJournalsTrait
*
* @package FireflyIII\Repositories\Journal
*/
trait CreateJournalsTrait
{
@@ -54,7 +51,6 @@ trait CreateJournalsTrait
abstract public function storeAccounts(User $user, TransactionType $type, array $data): array;
/**
*
* * Remember: a balancingAct takes at most one expense and one transfer.
* an advancePayment takes at most one expense, infinite deposits and NO transfers.
*
@@ -71,7 +67,7 @@ trait CreateJournalsTrait
foreach ($array as $name) {
if (strlen(trim($name)) > 0) {
$tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]);
if (!is_null($tag)) {
if (null !== $tag) {
Log::debug(sprintf('Will try to connect tag #%d to journal #%d.', $tag->id, $journal->id));
$tagRepository->connect($journal, $tag);
}
@@ -87,7 +83,7 @@ trait CreateJournalsTrait
*/
protected function storeBudgetWithTransaction(Transaction $transaction, int $budgetId)
{
if (intval($budgetId) > 0 && $transaction->transactionJournal->transactionType->type !== TransactionType::TRANSFER) {
if (intval($budgetId) > 0 && TransactionType::TRANSFER !== $transaction->transactionJournal->transactionType->type) {
/** @var \FireflyIII\Models\Budget $budget */
$budget = Budget::find($budgetId);
$transaction->budgets()->save($budget);
@@ -123,7 +119,7 @@ trait CreateJournalsTrait
// store transaction one way:
$amount = bcmul(strval($transaction['amount']), '-1');
$foreignAmount = is_null($transaction['foreign_amount']) ? null : bcmul(strval($transaction['foreign_amount']), '-1');
$foreignAmount = null === $transaction['foreign_amount'] ? null : bcmul(strval($transaction['foreign_amount']), '-1');
$one = $this->storeTransaction(
[
'journal' => $journal,
@@ -143,7 +139,7 @@ trait CreateJournalsTrait
// and the other way:
$amount = strval($transaction['amount']);
$foreignAmount = is_null($transaction['foreign_amount']) ? null : strval($transaction['foreign_amount']);
$foreignAmount = null === $transaction['foreign_amount'] ? null : strval($transaction['foreign_amount']);
$two = $this->storeTransaction(
[
'journal' => $journal,
@@ -182,11 +178,10 @@ trait CreateJournalsTrait
'identifier' => $data['identifier'],
];
if (is_null($data['foreign_currency_id'])) {
if (null === $data['foreign_currency_id']) {
unset($fields['foreign_currency_id']);
}
if (is_null($data['foreign_amount'])) {
if (null === $data['foreign_amount']) {
unset($fields['foreign_amount']);
}
@@ -195,18 +190,17 @@ trait CreateJournalsTrait
Log::debug(sprintf('Transaction stored with ID: %s', $transaction->id));
if (!is_null($data['category'])) {
if (null !== $data['category']) {
$transaction->categories()->save($data['category']);
}
if (!is_null($data['budget'])) {
if (null !== $data['budget']) {
$transaction->categories()->save($data['budget']);
}
return $transaction;
}
/**
* @param TransactionJournal $journal
* @param string $note
@@ -215,16 +209,16 @@ trait CreateJournalsTrait
*/
protected function updateNote(TransactionJournal $journal, string $note): bool
{
if (strlen($note) === 0) {
if (0 === strlen($note)) {
$dbNote = $journal->notes()->first();
if (!is_null($dbNote)) {
if (null !== $dbNote) {
$dbNote->delete();
}
return true;
}
$dbNote = $journal->notes()->first();
if (is_null($dbNote)) {
if (null === $dbNote) {
$dbNote = new Note();
$dbNote->noteable()->associate($journal);
}