GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — rewrite-laravel ( 4c0408...686099 )
by Oliver
02:53
created

ClientApiService::importBankAccounts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: okaufmann
5
 * Date: 22.10.2016
6
 * Time: 14:53.
7
 */
8
9
namespace App\Services\Mmex;
10
11
use App\Models\Account;
12
use App\Models\Category;
13
use App\Models\Payee;
14
use App\Models\Transaction;
15
use Log;
16
17
class ClientApiService
18
{
19
    public function getTransactions()
20
    {
21
        $transactions = Transaction::all();
22
23
        return $transactions;
24
    }
25
26
    public function deleteAccounts()
27
    {
28
        // TODO: find better method than where hack
29
        Account::where('id', '>', 0)->delete();
30
    }
31
32
    public function importBankAccounts($postData)
33
    {
34
        Log::debug('MmexController.importBankAccounts(), $accounts', [$postData->Accounts]);
35
        foreach ($postData->Accounts as $account) {
36
            Account::create([
37
                'name' => $account->AccountName,
38
            ]);
39
        }
40
    }
41
42
    public function deletePayees()
43
    {
44
        // TODO: find better method than where hack
45
        Payee::where('id', '>', 0)->delete();
46
    }
47
48
    public function importPayees($postData)
49
    {
50
        Log::debug('MmexController.importPayees(), $payees', [$postData->Payees]);
51
52
        foreach ($postData->Payees as $payee) {
53
            $categoryName = $payee->DefCateg;
54
            $subCategoryName = $payee->DefSubCateg;
55
56
            $category = Category::where('name', $subCategoryName)->whereHas('parentCategory', function ($query) use ($categoryName) {
57
                $query->where('name', $categoryName);
58
            })->first();
59
60
            if ($category) {
61
                $category->defaultForPayees()->create([
62
                    'name' => $payee->PayeeName,
63
                ]);
64
            } else {
65
                // ignore default/last category and just create entry
66
                Payee::create([
67
                    'name' => $payee->PayeeName,
68
                ]);
69
            }
70
        }
71
    }
72
73
    public function deleteCategories()
74
    {
75
        // TODO: find better method than where hack
76
        Category::where('id', '>', 0)->delete();
77
    }
78
79
    public function importCategories($postData)
80
    {
81
        $categories = collect($postData->Categories);
82
83
        $grouped = $categories->groupBy('CategoryName');
84
85
        foreach ($grouped as $categoryName => $subCategories) {
86
            $category = $this->createOrGetCategory($categoryName);
87
88
            foreach ($subCategories as $subCategory) {
89
                $this->createOrGetSubCategory($category, $subCategory->SubCategoryName);
90
            }
91
        }
92
    }
93
94 View Code Duplication
    private function createOrGetCategory($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $existingCategory = Category::whereName($name)->first();
97
98
        if ($existingCategory) {
99
            return $existingCategory;
100
        }
101
102
        $newCategory = Category::create([
103
            'name' => $name,
104
        ]);
105
106
        return $newCategory;
107
    }
108
109 View Code Duplication
    private function createOrGetSubCategory(Category $parentCategory, $name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $existingCategory = Category::whereName($name)->first();
112
113
        if ($existingCategory) {
114
            return $existingCategory;
115
        }
116
117
        $newCategory = $parentCategory->subCategories()->create([
118
            'name' => $name,
119
        ]);
120
121
        return $newCategory;
122
    }
123
124
    public function deleteTransactions($transactionId)
125
    {
126
        Transaction::whereId($transactionId)->delete();
127
    }
128
}
129