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 ( 96dff9...f203d9 )
by Oliver
11:47
created

MmexService::deleteCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: okaufmann
5
 * Date: 22.10.2016
6
 * Time: 14:53.
7
 */
8
namespace App\Services;
9
10
use App\Models\Account;
11
use App\Models\Category;
12
use App\Models\Payee;
13
use App\Models\Transaction;
14
use App\Transformers\TransactionTransformer;
15
use Log;
16
17
class MmexService
18
{
19
    /**
20
     * @var TransactionTransformer
21
     */
22
    private $transactionTransformer;
23
24
    /**
25
     * MmexService constructor.
26
     * @param TransactionTransformer $transactionTransformer
27
     */
28
    public function __construct(TransactionTransformer $transactionTransformer)
29
    {
30
31
        $this->transactionTransformer = $transactionTransformer;
32
    }
33
34
35
    public function getTransactions()
36
    {
37
        $transactions = Transaction::all()->all();
38
39
        return $this->transactionTransformer->transformCollection($transactions);
40
        // example
41
        return [
0 ignored issues
show
Unused Code introduced by
// example return array(...ction_1_Attach2.jpg')); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
42
            0 => [
43
                "ID" => 1,
44
                "Date" => "2016-10-07",
45
                "Account" => "Another Account",
46
                "ToAccount" => "None",
47
                "Status" => "R",
48
                "Type" => "Zahlung",
49
                "Payee" => "Migros",
50
                "Category" => "Einkauf",
51
                "SubCategory" => "Etwas anderes",
52
                "Amount" => "123",
53
                "Notes" => "Das ist ein \r\nMeeeeehrzeiliger \r\nText",
54
                "Attachments" => "Transaction_1_Attach1.png;Transaction_1_Attach2.jpg"
55
            ]
56
        ];
57
    }
58
59
    public function deleteAccounts()
60
    {
61
        // TODO: find better method than where hack
62
        Account::where('id', '>', 0)->delete();
63
    }
64
65
    public function importBankAccounts($postData)
66
    {
67
        Log::debug('MmexController.importBankAccounts(), $accounts', [$postData->Accounts]);
68
        foreach ($postData->Accounts as $account) {
69
            Account::create([
70
                'name' => $account->AccountName,
71
            ]);
72
        }
73
    }
74
75
    public function deletePayees()
76
    {
77
        // TODO: find better method than where hack
78
        Payee::where('id', '>', 0)->delete();
79
    }
80
81
    public function importPayees($postData)
82
    {
83
        Log::debug('MmexController.importPayees(), $payees', [$postData->Payees]);
84
85
        foreach ($postData->Payees as $payee) {
86
            $categoryName = $payee->DefCateg;
87
            $subCategoryName = $payee->DefSubCateg;
88
89
            $category = Category::where('name', $subCategoryName)->whereHas('parentCategory', function ($query) use ($categoryName) {
90
                $query->where('name', $categoryName);
91
            })->first();
92
93
            if ($category) {
94
                $category->defaultForPayees()->create([
95
                    'name' => $payee->PayeeName,
96
                ]);
97
            } else {
98
                // ignore default/last category and just create entry
99
                Payee::create([
100
                    'name' => $payee->PayeeName,
101
                ]);
102
            }
103
        }
104
    }
105
106
    public function deleteCategories()
107
    {
108
        // TODO: find better method than where hack
109
        Category::where('id', '>', 0)->delete();
110
    }
111
112
    public function importCategories($postData)
113
    {
114
        $categories = collect($postData->Categories);
115
116
        $grouped = $categories->groupBy('CategoryName');
117
118
        foreach ($grouped as $categoryName => $subCategories) {
119
            $category = $this->createOrGetCategory($categoryName);
120
121
            foreach ($subCategories as $subCategory) {
122
                $this->createOrGetSubCategory($category, $subCategory->SubCategoryName);
123
            }
124
        }
125
    }
126
127 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...
128
    {
129
        $existingCategory = Category::whereName($name)->first();
130
131
        if ($existingCategory) {
132
            return $existingCategory;
133
        }
134
135
        $newCategory = Category::create([
136
            'name' => $name,
137
        ]);
138
139
        return $newCategory;
140
    }
141
142 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...
143
    {
144
        $existingCategory = Category::whereName($name)->first();
145
146
        if ($existingCategory) {
147
            return $existingCategory;
148
        }
149
150
        $newCategory = $parentCategory->subCategories()->create([
151
            'name' => $name,
152
        ]);
153
154
        return $newCategory;
155
    }
156
157
    public function deleteTransactions($transactionId)
158
    {
159
        Transaction::whereId($transactionId)->delete();
160
    }
161
}
162