From 5f9cb6116090a924ea2b506f7216bc844a954343 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 29 Jan 2016 13:24:33 +0100 Subject: [PATCH] Some stuff moving around in test data generation. --- database/seeds/TestData.php | 250 ++++ database/seeds/TestDataSeeder.php | 254 +---- database/seeds/VisualTestDataSeeder.php | 1390 ++++++++++------------- 3 files changed, 833 insertions(+), 1061 deletions(-) create mode 100644 database/seeds/TestData.php diff --git a/database/seeds/TestData.php b/database/seeds/TestData.php new file mode 100644 index 0000000000..9c2a3fe5fb --- /dev/null +++ b/database/seeds/TestData.php @@ -0,0 +1,250 @@ + 'defaultAsset'], + ['accountRole' => 'savingAsset',], + ['accountRole' => 'sharedAsset',], + ['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull',], + ['accountRole' => 'savingAsset',], + ['accountRole' => 'savingAsset',], + ]; + + foreach ($assets as $index => $name) { + // create account: + $account = Account::create( + [ + 'user_id' => $user->id, + 'account_type_id' => 3, + 'name' => $name, + 'active' => 1, + 'encrypted' => 1, + 'iban' => $ibans[$index], + ] + ); + foreach ($assetMeta[$index] as $name => $value) { + AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value,]); + } + } + + } + + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @param User $user + */ + public static function createPiggybanks(User $user) + { + $account = self::findAccount($user, 'TestData Savings'); + + $camera = PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New camera', + 'targetamount' => 1000, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 1, + ] + ); + $repetition = $camera->piggyBankRepetitions()->first(); + $repetition->currentamount = 735; + $repetition->save(); + + // events: + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $camera->id, + 'date' => '2015-05-01', + 'amount' => '245', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $camera->id, + 'date' => '2015-06-01', + 'amount' => '245', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $camera->id, + 'date' => '2015-07-01', + 'amount' => '245', + ] + ); + + + $phone = PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New phone', + 'targetamount' => 600, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 2, + ] + ); + $repetition = $phone->piggyBankRepetitions()->first(); + $repetition->currentamount = 333; + $repetition->save(); + + // events: + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $phone->id, + 'date' => '2015-05-01', + 'amount' => '111', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $phone->id, + 'date' => '2015-06-01', + 'amount' => '111', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $phone->id, + 'date' => '2015-07-01', + 'amount' => '111', + ] + ); + + $couch = PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New couch', + 'targetamount' => 500, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 3, + ] + ); + $repetition = $couch->piggyBankRepetitions()->first(); + $repetition->currentamount = 120; + $repetition->save(); + + // events: + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $couch->id, + 'date' => '2015-05-01', + 'amount' => '40', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $couch->id, + 'date' => '2015-06-01', + 'amount' => '40', + ] + ); + PiggyBankEvent::create( + [ + 'piggy_bank_id' => $couch->id, + 'date' => '2015-07-01', + 'amount' => '40', + ] + ); + + // empty one. + PiggyBank::create( + [ + 'account_id' => $account->id, + 'name' => 'New head set', + 'targetamount' => 500, + 'startdate' => '2015-04-01', + 'reminder_skip' => 0, + 'remind_me' => 0, + 'order' => 4, + ] + ); + + } + + /** + * @param User $user + * @param $name + * + * @return Account|null + */ + public static function findAccount(User $user, $name) + { + /** @var Account $account */ + foreach ($user->accounts()->get() as $account) { + if ($account->name == $name) { + return $account; + break; + } + } + + return null; + } + + /** + * @param User $user + */ + public static function createBills(User $user) + { + Bill::create( + [ + 'name' => 'Rent', + 'match' => 'rent,land,lord', + 'amount_min' => 795, + 'amount_max' => 805, + 'user_id' => $user->id, + 'date' => '2015-01-01', + 'active' => 1, + 'automatch' => 1, + 'repeat_freq' => 'monthly', + 'skip' => 0, + ] + ); + Bill::create( + [ + 'name' => 'Health insurance', + 'match' => 'zilveren,kruis,health', + 'amount_min' => 120, + 'amount_max' => 140, + 'user_id' => $user->id, + 'date' => '2015-01-01', + 'active' => 1, + 'automatch' => 1, + 'repeat_freq' => 'monthly', + 'skip' => 0, + ] + ); + } + + +} \ No newline at end of file diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index 83cb5bac94..8e454e974a 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -8,8 +8,6 @@ use FireflyIII\Models\Bill; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\Category; -use FireflyIII\Models\PiggyBank; -use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\Role; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; @@ -40,7 +38,7 @@ class TestDataSeeder extends Seeder */ public function run() { - $user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]); + $user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]); User::create(['email' => 'thegrumpydictator+empty@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]); @@ -49,10 +47,10 @@ class TestDataSeeder extends Seeder // create asset accounts for user #1. - $this->createAssetAccounts($user); + TestData::createAssetAccounts($user); // create bills for user #1 - $this->createBills($user); + TestData::createBills($user); // create some budgets for user #1 $this->createBudgets($user); @@ -61,7 +59,7 @@ class TestDataSeeder extends Seeder $this->createCategories($user); // create some piggy banks for user #1 - $this->createPiggybanks($user); + TestData::createPiggybanks($user); // create some expense accounts for user #1 $this->createExpenseAccounts($user); @@ -75,51 +73,14 @@ class TestDataSeeder extends Seeder // create opening balance for savings account: $this->openingBalanceSavings($user); } - - /** - * @param User $user - */ - private function createAssetAccounts(User $user) - { - $assets = ['TestData Checking Account', 'TestData Savings', 'TestData Shared', 'TestData Creditcard', 'Emergencies', 'STE']; - // first two ibans match test-upload.csv - $ibans = ['NL11XOLA6707795988', 'NL96DZCO4665940223', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708']; - $assetMeta = [ - ['accountRole' => 'defaultAsset'], - ['accountRole' => 'savingAsset',], - ['accountRole' => 'sharedAsset',], - ['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull',], - ['accountRole' => 'savingAsset',], - ['accountRole' => 'savingAsset',], - ]; - - foreach ($assets as $index => $name) { - // create account: - $account = Account::create( - [ - 'user_id' => $user->id, - 'account_type_id' => 3, - 'name' => $name, - 'active' => 1, - 'encrypted' => 1, - 'iban' => $ibans[$index], - ] - ); - foreach ($assetMeta[$index] as $name => $value) { - AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value,]); - } - } - - } - /** * @param User $user */ private function createAttachments(User $user) { - $toAccount = $this->findAccount($user, 'TestData Checking Account'); - $fromAccount = $this->findAccount($user, 'Job'); + $toAccount = TestData::findAccount($user, 'TestData Checking Account'); + $fromAccount = TestData::findAccount($user, 'Job'); $journal = TransactionJournal::create( [ @@ -188,42 +149,6 @@ class TestDataSeeder extends Seeder file_put_contents(storage_path('upload/at-2.data'), $encrypted); } - - /** - * @param User $user - */ - private function createBills(User $user) - { - Bill::create( - [ - 'name' => 'Rent', - 'match' => 'rent,land,lord', - 'amount_min' => 795, - 'amount_max' => 805, - 'user_id' => $user->id, - 'date' => '2015-01-01', - 'active' => 1, - 'automatch' => 1, - 'repeat_freq' => 'monthly', - 'skip' => 0, - ] - ); - Bill::create( - [ - 'name' => 'Health insurance', - 'match' => 'zilveren,kruis,health', - 'amount_min' => 120, - 'amount_max' => 140, - 'user_id' => $user->id, - 'date' => '2015-01-01', - 'active' => 1, - 'automatch' => 1, - 'repeat_freq' => 'monthly', - 'skip' => 0, - ] - ); - } - /** * @param $user */ @@ -287,144 +212,6 @@ class TestDataSeeder extends Seeder } - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * @param User $user - */ - private function createPiggybanks(User $user) - { - $account = $this->findAccount($user, 'TestData Savings'); - - $camera = PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New camera', - 'targetamount' => 1000, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 1, - ] - ); - $repetition = $camera->piggyBankRepetitions()->first(); - $repetition->currentamount = 735; - $repetition->save(); - - // events: - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $camera->id, - 'date' => '2015-05-01', - 'amount' => '245', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $camera->id, - 'date' => '2015-06-01', - 'amount' => '245', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $camera->id, - 'date' => '2015-07-01', - 'amount' => '245', - ] - ); - - - $phone = PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New phone', - 'targetamount' => 600, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 2, - ] - ); - $repetition = $phone->piggyBankRepetitions()->first(); - $repetition->currentamount = 333; - $repetition->save(); - - // events: - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $phone->id, - 'date' => '2015-05-01', - 'amount' => '111', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $phone->id, - 'date' => '2015-06-01', - 'amount' => '111', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $phone->id, - 'date' => '2015-07-01', - 'amount' => '111', - ] - ); - - $couch = PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New couch', - 'targetamount' => 500, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 3, - ] - ); - $repetition = $couch->piggyBankRepetitions()->first(); - $repetition->currentamount = 120; - $repetition->save(); - - // events: - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $couch->id, - 'date' => '2015-05-01', - 'amount' => '40', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $couch->id, - 'date' => '2015-06-01', - 'amount' => '40', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $couch->id, - 'date' => '2015-07-01', - 'amount' => '40', - ] - ); - - // empty one. - PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New head set', - 'targetamount' => 500, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 4, - ] - ); - - } - /** * @param User $user */ @@ -445,25 +232,6 @@ class TestDataSeeder extends Seeder } } - /** - * @param User $user - * @param $name - * - * @return Account|null - */ - private function findAccount(User $user, $name) - { - /** @var Account $account */ - foreach ($user->accounts()->get() as $account) { - if ($account->name == $name) { - return $account; - break; - } - } - - return null; - } - /** * @param User $user */ @@ -481,7 +249,7 @@ class TestDataSeeder extends Seeder ); // savings - $savings = $this->findAccount($user, 'TestData Savings'); + $savings = TestData::findAccount($user, 'TestData Savings'); $journal = TransactionJournal::create( [ @@ -497,17 +265,17 @@ class TestDataSeeder extends Seeder // transactions Transaction::create( [ - 'account_id' => $opposing->id, + 'account_id' => $opposing->id, 'transaction_journal_id' => $journal->id, - 'amount' => -10000, + 'amount' => -10000, ] ); Transaction::create( [ - 'account_id' => $savings->id, + 'account_id' => $savings->id, 'transaction_journal_id' => $journal->id, - 'amount' => 10000, + 'amount' => 10000, ] ); diff --git a/database/seeds/VisualTestDataSeeder.php b/database/seeds/VisualTestDataSeeder.php index b099d2db30..aa2030390b 100644 --- a/database/seeds/VisualTestDataSeeder.php +++ b/database/seeds/VisualTestDataSeeder.php @@ -7,7 +7,6 @@ use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\Category; use FireflyIII\Models\PiggyBank; -use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Models\Preference; use FireflyIII\Models\Role; use FireflyIII\Models\Rule; @@ -32,15 +31,6 @@ class VisualTestDataSeeder extends Seeder /** @var User */ protected $user; - - /** - * - */ - public function __construct() - { - - } - /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ @@ -448,11 +438,11 @@ class VisualTestDataSeeder extends Seeder $this->createUsers(); // create accounts: - $this->createAssetAccounts(); + TestData::createAssetAccounts($this->user); $this->createExpenseAccounts(); $this->createRevenueAccounts(); - $this->createBills(); - $this->createPiggybanks(); + TestData::createBills($this->user); + TestData::createPiggybanks($this->user); $this->createRules(); @@ -503,715 +493,6 @@ class VisualTestDataSeeder extends Seeder } - /** - * @param Carbon $date - */ - protected function createTags(Carbon $date) - { - Tag::create( - [ - 'user_id' => $this->user->id, - 'tag' => 'SomeTag' . $date->month . '.' . $date->year . '.nothing', - 'tagMode' => 'nothing', - 'date' => $date->format('Y-m-d'), - - - ] - ); - } - - /** - * - */ - protected function createUsers() - { - User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]); - $this->user = User::whereEmail('thegrumpydictator@gmail.com')->first(); - - // create rights: - $role = Role::find(1); - $this->user->roles()->save($role); - - } - - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function createAssetAccounts() - { - $assets = ['MyBank Checking Account', 'Savings', 'Shared', 'Creditcard', 'Emergencies', 'STE']; - $ibans = ['NL47JDYU6179706202', 'NL51WGBP5832453599', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708']; - $assetMeta = [ - [ - 'accountRole' => 'defaultAsset', - ], - [ - 'accountRole' => 'savingAsset', - ], - [ - 'accountRole' => 'sharedAsset', - ], - [ - 'accountRole' => 'ccAsset', - 'ccMonthlyPaymentDate' => '2015-05-27', - 'ccType' => 'monthlyFull', - ], - [ - 'accountRole' => 'savingAsset', - ], - [ - 'accountRole' => 'savingAsset', - ], - - ]; - - foreach ($assets as $index => $name) { - // create account: - $account = Account::create( - [ - 'user_id' => $this->user->id, - 'account_type_id' => 3, - 'name' => $name, - 'active' => 1, - 'encrypted' => 1, - 'iban' => $ibans[$index], - ] - ); - foreach ($assetMeta[$index] as $name => $value) { - AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value,]); - } - } - } - - protected function createExpenseAccounts() - { - $expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl', - 'coolblue', 'Shell', - 'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord']; - foreach ($expenses as $name) { - // create account: - Account::create( - [ - 'user_id' => $this->user->id, - 'account_type_id' => 4, - 'name' => $name, - 'active' => 1, - 'encrypted' => 1, - ] - ); - } - - } - - /** - * - */ - protected function createRevenueAccounts() - { - $revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google']; - foreach ($revenues as $name) { - // create account: - Account::create( - [ - 'user_id' => $this->user->id, - 'account_type_id' => 5, - 'name' => $name, - 'active' => 1, - 'encrypted' => 1, - ] - ); - } - } - - public function createBills() - { - Bill::create( - [ - 'name' => 'Rent', - 'match' => 'rent,land,lord', - 'amount_min' => 795, - 'amount_max' => 805, - 'user_id' => $this->user->id, - 'date' => '2015-01-01', - 'active' => 1, - 'automatch' => 1, - 'repeat_freq' => 'monthly', - 'skip' => 0, - ] - ); - Bill::create( - [ - 'name' => 'Health insurance', - 'match' => 'zilveren,kruis,health', - 'amount_min' => 120, - 'amount_max' => 140, - 'user_id' => $this->user->id, - 'date' => '2015-01-01', - 'active' => 1, - 'automatch' => 1, - 'repeat_freq' => 'monthly', - 'skip' => 0, - ] - ); - } - - /** - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function createPiggybanks() - { - $account = $this->findAccount('Savings'); - - $camera = PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New camera', - 'targetamount' => 1000, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 1, - ] - ); - $repetition = $camera->piggyBankRepetitions()->first(); - $repetition->currentamount = 735; - $repetition->save(); - - // events: - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $camera->id, - 'date' => '2015-05-01', - 'amount' => '245', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $camera->id, - 'date' => '2015-06-01', - 'amount' => '245', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $camera->id, - 'date' => '2015-07-01', - 'amount' => '245', - ] - ); - - - $phone = PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New phone', - 'targetamount' => 600, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 2, - ] - ); - $repetition = $phone->piggyBankRepetitions()->first(); - $repetition->currentamount = 333; - $repetition->save(); - - // events: - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $phone->id, - 'date' => '2015-05-01', - 'amount' => '111', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $phone->id, - 'date' => '2015-06-01', - 'amount' => '111', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $phone->id, - 'date' => '2015-07-01', - 'amount' => '111', - ] - ); - - $couch = PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New couch', - 'targetamount' => 500, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 3, - ] - ); - $repetition = $couch->piggyBankRepetitions()->first(); - $repetition->currentamount = 120; - $repetition->save(); - - // events: - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $couch->id, - 'date' => '2015-05-01', - 'amount' => '40', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $couch->id, - 'date' => '2015-06-01', - 'amount' => '40', - ] - ); - PiggyBankEvent::create( - [ - 'piggy_bank_id' => $couch->id, - 'date' => '2015-07-01', - 'amount' => '40', - ] - ); - - // empty one. - PiggyBank::create( - [ - 'account_id' => $account->id, - 'name' => 'New head set', - 'targetamount' => 500, - 'startdate' => '2015-04-01', - 'reminder_skip' => 0, - 'remind_me' => 0, - 'order' => 4, - ] - ); - - } - - /** - * @param $name - * - * @return Account|null - */ - protected function findAccount($name) - { - /** @var Account $account */ - foreach (Account::get() as $account) { - if ($account->name == $name && $this->user->id == $account->user_id) { - return $account; - break; - } - } - - return null; - } - - /** - * @param $description - * @param Carbon $date - * @param $amount - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - * - * @return TransactionJournal - */ - protected function createIncome($description, Carbon $date, $amount) - { - $date = new Carbon($date->format('Y-m') . '-23'); // paid on 23rd. - $today = new Carbon; - if ($date >= $today) { - return null; - } - $toAccount = $this->findAccount('MyBank Checking Account'); - $fromAccount = $this->findAccount('Job'); - $category = Category::firstOrCreateEncrypted(['name' => 'Salary', 'user_id' => $this->user->id]); - // create journal: - - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 2, - 'transaction_currency_id' => 1, - 'description' => $description, - 'completed' => 1, - 'date' => $date, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - - return $journal; - - } - - /** - * @param $description - * @param Carbon $date - * @param $amount - * - * @return TransactionJournal - */ - protected function createRent($description, Carbon $date, $amount) - { - $fromAccount = $this->findAccount('MyBank Checking Account'); - $toAccount = $this->findAccount('Land lord'); - $category = Category::firstOrCreateEncrypted(['name' => 'Rent', 'user_id' => $this->user->id]); - $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 1, - 'transaction_currency_id' => 1, - 'bill_id' => 1, - 'description' => $description, - 'completed' => 1, - 'date' => $date, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - $journal->budgets()->save($budget); - - return $journal; - - } - - /** - * @param $description - * @param Carbon $date - * @param $amount - * - * @return TransactionJournal - */ - protected function createWater($description, Carbon $date, $amount) - { - $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th - $fromAccount = $this->findAccount('MyBank Checking Account'); - $toAccount = $this->findAccount('Vitens'); - $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]); - $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 1, - 'transaction_currency_id' => 1, - 'description' => $description, - 'completed' => 1, - 'date' => $date, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - $journal->budgets()->save($budget); - - return $journal; - - } - - /** - * @param $description - * @param Carbon $date - * @param $amount - * - * @return TransactionJournal - */ - protected function createTV($description, Carbon $date, $amount) - { - $date = new Carbon($date->format('Y-m') . '-15'); // paid on 10th - $fromAccount = $this->findAccount('MyBank Checking Account'); - $toAccount = $this->findAccount('XS4All'); - $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]); - $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 1, - 'transaction_currency_id' => 1, - 'description' => $description, - 'completed' => 1, - 'date' => $date, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - $journal->budgets()->save($budget); - - return $journal; - - } - - /** - * @param $description - * @param Carbon $date - * @param $amount - * - * @return TransactionJournal - */ - protected function createPower($description, Carbon $date, $amount) - { - $date = new Carbon($date->format('Y-m') . '-06'); // paid on 10th - $fromAccount = $this->findAccount('MyBank Checking Account'); - $toAccount = $this->findAccount('Greenchoice'); - $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]); - $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 1, - 'transaction_currency_id' => 1, - 'description' => $description, - 'completed' => 1, - 'date' => $date, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - $journal->budgets()->save($budget); - - return $journal; - - } - - /** - * @param Carbon $date - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function createGroceries(Carbon $date) - { - $start = clone $date; - $end = clone $date; - $today = new Carbon; - $start->startOfMonth(); - $end->endOfMonth(); - - $fromAccount = $this->findAccount('MyBank Checking Account'); - $stores = ['Albert Heijn', 'PLUS', 'Bakker']; - $descriptions = ['Groceries', 'Bought some groceries', 'Got groceries']; - $category = Category::firstOrCreateEncrypted(['name' => 'Daily groceries', 'user_id' => $this->user->id]); - $budget = Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $this->user->id]); - - $current = clone $start; - while ($current < $end && $current < $today) { - // daily groceries: - $amount = rand(1500, 2500) / 100; - $toAccount = $this->findAccount($stores[rand(0, count($stores) - 1)]); - - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 1, - 'transaction_currency_id' => 1, - 'description' => $descriptions[rand(0, count($descriptions) - 1)], - 'completed' => 1, - 'date' => $current, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - $journal->budgets()->save($budget); - - - $current->addDay(); - } - } - - /** - * @param Carbon $date - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - protected function createDrinksAndOthers(Carbon $date) - { - $start = clone $date; - $end = clone $date; - $today = new Carbon; - $start->startOfMonth(); - $end->endOfMonth(); - $current = clone $start; - while ($current < $end && $current < $today) { - - // weekly drink: - $thisDate = clone $current; - $thisDate->addDay(); - $fromAccount = $this->findAccount('MyBank Checking Account'); - $toAccount = $this->findAccount('Cafe Central'); - $category = Category::firstOrCreateEncrypted(['name' => 'Drinks', 'user_id' => $this->user->id]); - $budget = Budget::firstOrCreateEncrypted(['name' => 'Going out', 'user_id' => $this->user->id]); - $amount = rand(1500, 3600) / 100; - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 1, - 'transaction_currency_id' => 1, - 'description' => 'Going out for drinks', - 'completed' => 1, - 'date' => $thisDate, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount * -1, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => $amount, - - ] - ); - $journal->categories()->save($category); - $journal->budgets()->save($budget); - - // shopping at some (online) shop: - - - $current->addWeek(); - } - } - - /** - * @param Carbon $date - * - * @return TransactionJournal - */ - protected function createSavings(Carbon $date) - { - $date = new Carbon($date->format('Y-m') . '-24'); // paid on 24th. - $toAccount = $this->findAccount('Savings'); - $fromAccount = $this->findAccount('MyBank Checking Account'); - $category = Category::firstOrCreateEncrypted(['name' => 'Money management', 'user_id' => $this->user->id]); - // create journal: - - $journal = TransactionJournal::create( - [ - 'user_id' => $this->user->id, - 'transaction_type_id' => 3, - 'transaction_currency_id' => 1, - 'description' => 'Save money', - 'completed' => 1, - 'date' => $date, - ] - ); - Transaction::create( - [ - 'account_id' => $fromAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => -150, - - ] - ); - Transaction::create( - [ - 'account_id' => $toAccount->id, - 'transaction_journal_id' => $journal->id, - 'amount' => 150, - - ] - ); - $journal->categories()->save($category); - - return $journal; - - } - /** * @param Carbon $current * @param $name @@ -1236,100 +517,6 @@ class VisualTestDataSeeder extends Seeder ); } - /** - * @param $name - * - * @return Budget|null - */ - protected function findBudget($name) - { - /** @var Budget $budget */ - foreach (Budget::get() as $budget) { - if ($budget->name == $name && $this->user->id == $budget->user_id) { - return $budget; - break; - } - } - - return null; - } - - /** - * @param $name - * - * @return Bill|null - */ - protected function findBill($name) - { - /** @var Bill $bill */ - foreach (Bill::get() as $bill) { - if ($bill->name == $name && $this->user->id == $bill->user_id) { - return $bill; - break; - } - } - - return null; - } - - /** - * @param $name - * - * @return Category|null - */ - protected function findCategory($name) - { - - /** @var Category $category */ - foreach (Category::get() as $category) { - if ($category->name == $name && $this->user->id == $category->user_id) { - return $category; - break; - } - } - - return null; - } - - /** - * @param $name - * - * @return PiggyBank|null - */ - protected function findPiggyBank($name) - { - - /** @var Budget $budget */ - foreach (PiggyBank::get() as $piggyBank) { - $account = $piggyBank->account()->first(); - if ($piggyBank->name == $name && $this->user->id == $account->user_id) { - return $piggyBank; - break; - } - } - - return null; - } - - /** - * @param $tagName - * - * @return Tag|null - * @internal param $tag - */ - protected function findTag($tagName) - { - /** @var Tag $tag */ - foreach (Tag::get() as $tag) { - if ($tag->tag == $tagName && $this->user->id == $tag->user_id) { - return $tag; - break; - } - } - - return null; - } - /** * @param $date * @@ -1340,8 +527,8 @@ class VisualTestDataSeeder extends Seeder { // twice: $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th - $fromAccount = $this->findAccount('MyBank Checking Account'); - $toAccount = $this->findAccount('Shell'); + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $toAccount = TestData::findAccount($this->user, 'Shell'); $category = Category::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $this->user->id]); $budget = Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $this->user->id]); $amount = rand(4000, 5000) / 100; @@ -1411,6 +598,242 @@ class VisualTestDataSeeder extends Seeder return $journal; } + /** + * @param Carbon $date + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + protected function createDrinksAndOthers(Carbon $date) + { + $start = clone $date; + $end = clone $date; + $today = new Carbon; + $start->startOfMonth(); + $end->endOfMonth(); + $current = clone $start; + while ($current < $end && $current < $today) { + + // weekly drink: + $thisDate = clone $current; + $thisDate->addDay(); + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $toAccount = TestData::findAccount($this->user, 'Cafe Central'); + $category = Category::firstOrCreateEncrypted(['name' => 'Drinks', 'user_id' => $this->user->id]); + $budget = Budget::firstOrCreateEncrypted(['name' => 'Going out', 'user_id' => $this->user->id]); + $amount = rand(1500, 3600) / 100; + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 1, + 'transaction_currency_id' => 1, + 'description' => 'Going out for drinks', + 'completed' => 1, + 'date' => $thisDate, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + $journal->budgets()->save($budget); + + // shopping at some (online) shop: + + + $current->addWeek(); + } + } + + protected function createExpenseAccounts() + { + $expenses = ['Adobe', 'Google', 'Vitens', 'Albert Heijn', 'PLUS', 'Apple', 'Bakker', 'Belastingdienst', 'bol.com', 'Cafe Central', 'conrad.nl', + 'coolblue', 'Shell', + 'DUO', 'Etos', 'FEBO', 'Greenchoice', 'Halfords', 'XS4All', 'iCentre', 'Jumper', 'Land lord']; + foreach ($expenses as $name) { + // create account: + Account::create( + [ + 'user_id' => $this->user->id, + 'account_type_id' => 4, + 'name' => $name, + 'active' => 1, + 'encrypted' => 1, + ] + ); + } + + } + + /** + * @param Carbon $date + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + protected function createGroceries(Carbon $date) + { + $start = clone $date; + $end = clone $date; + $today = new Carbon; + $start->startOfMonth(); + $end->endOfMonth(); + + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $stores = ['Albert Heijn', 'PLUS', 'Bakker']; + $descriptions = ['Groceries', 'Bought some groceries', 'Got groceries']; + $category = Category::firstOrCreateEncrypted(['name' => 'Daily groceries', 'user_id' => $this->user->id]); + $budget = Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $this->user->id]); + + $current = clone $start; + while ($current < $end && $current < $today) { + // daily groceries: + $amount = rand(1500, 2500) / 100; + $toAccount = TestData::findAccount($this->user, $stores[rand(0, count($stores) - 1)]); + + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 1, + 'transaction_currency_id' => 1, + 'description' => $descriptions[rand(0, count($descriptions) - 1)], + 'completed' => 1, + 'date' => $current, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + $journal->budgets()->save($budget); + + + $current->addDay(); + } + } + + /** + * @param $description + * @param Carbon $date + * @param $amount + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * + * @return TransactionJournal + */ + protected function createIncome($description, Carbon $date, $amount) + { + $date = new Carbon($date->format('Y-m') . '-23'); // paid on 23rd. + $today = new Carbon; + if ($date >= $today) { + return null; + } + $toAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $fromAccount = TestData::findAccount($this->user, 'Job'); + $category = Category::firstOrCreateEncrypted(['name' => 'Salary', 'user_id' => $this->user->id]); + // create journal: + + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 2, + 'transaction_currency_id' => 1, + 'description' => $description, + 'completed' => 1, + 'date' => $date, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + + return $journal; + + } + + /** + * @param $description + * @param Carbon $date + * @param $amount + * + * @return TransactionJournal + */ + protected function createPower($description, Carbon $date, $amount) + { + $date = new Carbon($date->format('Y-m') . '-06'); // paid on 10th + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $toAccount = TestData::findAccount($this->user, 'Greenchoice'); + $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]); + $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 1, + 'transaction_currency_id' => 1, + 'description' => $description, + 'completed' => 1, + 'date' => $date, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + $journal->budgets()->save($budget); + + return $journal; + + } + protected function createPreferences() { $preference = new Preference; @@ -1420,5 +843,336 @@ class VisualTestDataSeeder extends Seeder $preference->save(); } + /** + * @param $description + * @param Carbon $date + * @param $amount + * + * @return TransactionJournal + */ + protected function createRent($description, Carbon $date, $amount) + { + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $toAccount = TestData::findAccount($this->user, 'Land lord'); + $category = Category::firstOrCreateEncrypted(['name' => 'Rent', 'user_id' => $this->user->id]); + $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 1, + 'transaction_currency_id' => 1, + 'bill_id' => 1, + 'description' => $description, + 'completed' => 1, + 'date' => $date, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + $journal->budgets()->save($budget); + + return $journal; + + } + + /** + * + */ + protected function createRevenueAccounts() + { + $revenues = ['Job', 'Belastingdienst', 'Bank', 'KPN', 'Google']; + foreach ($revenues as $name) { + // create account: + Account::create( + [ + 'user_id' => $this->user->id, + 'account_type_id' => 5, + 'name' => $name, + 'active' => 1, + 'encrypted' => 1, + ] + ); + } + } + + /** + * @param Carbon $date + * + * @return TransactionJournal + */ + protected function createSavings(Carbon $date) + { + $date = new Carbon($date->format('Y-m') . '-24'); // paid on 24th. + $toAccount = TestData::findAccount($this->user, 'Savings'); + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $category = Category::firstOrCreateEncrypted(['name' => 'Money management', 'user_id' => $this->user->id]); + // create journal: + + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 3, + 'transaction_currency_id' => 1, + 'description' => 'Save money', + 'completed' => 1, + 'date' => $date, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => -150, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => 150, + + ] + ); + $journal->categories()->save($category); + + return $journal; + + } + + /** + * @param $description + * @param Carbon $date + * @param $amount + * + * @return TransactionJournal + */ + protected function createTV($description, Carbon $date, $amount) + { + $date = new Carbon($date->format('Y-m') . '-15'); // paid on 10th + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $toAccount = TestData::findAccount($this->user, 'XS4All'); + $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]); + $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 1, + 'transaction_currency_id' => 1, + 'description' => $description, + 'completed' => 1, + 'date' => $date, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + $journal->budgets()->save($budget); + + return $journal; + + } + + /** + * @param Carbon $date + */ + protected function createTags(Carbon $date) + { + Tag::create( + [ + 'user_id' => $this->user->id, + 'tag' => 'SomeTag' . $date->month . '.' . $date->year . '.nothing', + 'tagMode' => 'nothing', + 'date' => $date->format('Y-m-d'), + + + ] + ); + } + + /** + * + */ + protected function createUsers() + { + User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => bcrypt('james'), 'reset' => null, 'remember_token' => null]); + $this->user = User::whereEmail('thegrumpydictator@gmail.com')->first(); + + // create rights: + $role = Role::find(1); + $this->user->roles()->save($role); + + } + + /** + * @param $description + * @param Carbon $date + * @param $amount + * + * @return TransactionJournal + */ + protected function createWater($description, Carbon $date, $amount) + { + $date = new Carbon($date->format('Y-m') . '-10'); // paid on 10th + $fromAccount = TestData::findAccount($this->user, 'MyBank Checking Account'); + $toAccount = TestData::findAccount($this->user, 'Vitens'); + $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]); + $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]); + $journal = TransactionJournal::create( + [ + 'user_id' => $this->user->id, + 'transaction_type_id' => 1, + 'transaction_currency_id' => 1, + 'description' => $description, + 'completed' => 1, + 'date' => $date, + ] + ); + Transaction::create( + [ + 'account_id' => $fromAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount * -1, + + ] + ); + Transaction::create( + [ + 'account_id' => $toAccount->id, + 'transaction_journal_id' => $journal->id, + 'amount' => $amount, + + ] + ); + $journal->categories()->save($category); + $journal->budgets()->save($budget); + + return $journal; + + } + + /** + * @param $name + * + * @return Bill|null + */ + protected function findBill($name) + { + /** @var Bill $bill */ + foreach (Bill::get() as $bill) { + if ($bill->name == $name && $this->user->id == $bill->user_id) { + return $bill; + break; + } + } + + return null; + } + + /** + * @param $name + * + * @return Budget|null + */ + protected function findBudget($name) + { + /** @var Budget $budget */ + foreach (Budget::get() as $budget) { + if ($budget->name == $name && $this->user->id == $budget->user_id) { + return $budget; + break; + } + } + + return null; + } + + /** + * @param $name + * + * @return Category|null + */ + protected function findCategory($name) + { + + /** @var Category $category */ + foreach (Category::get() as $category) { + if ($category->name == $name && $this->user->id == $category->user_id) { + return $category; + break; + } + } + + return null; + } + + /** + * @param $name + * + * @return PiggyBank|null + */ + protected function findPiggyBank($name) + { + + /** @var Budget $budget */ + foreach (PiggyBank::get() as $piggyBank) { + $account = $piggyBank->account()->first(); + if ($piggyBank->name == $name && $this->user->id == $account->user_id) { + return $piggyBank; + break; + } + } + + return null; + } + + /** + * @param $tagName + * + * @return Tag|null + * @internal param $tag + */ + protected function findTag($tagName) + { + /** @var Tag $tag */ + foreach (Tag::get() as $tag) { + if ($tag->tag == $tagName && $this->user->id == $tag->user_id) { + return $tag; + break; + } + } + + return null; + } + }