Test Failed
Push — master ( 54db62...a5394f )
by Terzi
06:48
created

TranslationsController::index()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 1
nop 1
dl 0
loc 15
ccs 0
cts 10
cp 0
crap 6
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Terranet\Administrator\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Collection;
7
use Terranet\Administrator\Events\TranslationsChanged;
8
use Terranet\Administrator\Services\TranslationsManager;
9
10
ini_set('opcache.enable', 0);
11
12
class TranslationsController extends AdminController
13
{
14
    /**
15
     * @param Request $request
16
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
17
     */
18
    public function index(Request $request)
19
    {
20
        $page = $request->get('page', 1);
21
        $term = $request->get('term');
22
        $only = $request->get('only');
23
24
        $pagination = $this->manager()->load(
25
            $term, 'all' === $only ? null : $only, $page, 20
26
        );
27
28
        $pagination->appends(compact('term', 'only'));
29
30
        return view(app('scaffold.template')->translations('index'), [
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return view(/** @scrutinizer ignore-call */ app('scaffold.template')->translations('index'), [
Loading history...
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return /** @scrutinizer ignore-call */ view(app('scaffold.template')->translations('index'), [
Loading history...
31
            'pagination' => $pagination,
32
            'scopes' => $this->manager()->filters(),
33
        ]);
34
    }
35
36
    /**
37
     * @param Request $request
38
     * @return \Illuminate\Http\RedirectResponse
39
     */
40
    public function store(Request $request)
41
    {
42
        $redirectTo = redirect()->back()->with('messages', [trans('administrator::messages.update_success')]);
0 ignored issues
show
Bug introduced by
The function trans was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $redirectTo = redirect()->back()->with('messages', [/** @scrutinizer ignore-call */ trans('administrator::messages.update_success')]);
Loading history...
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $redirectTo = /** @scrutinizer ignore-call */ redirect()->back()->with('messages', [trans('administrator::messages.update_success')]);
Loading history...
43
44
        if (empty($translation = $request->input('translation'))) {
45
            return $redirectTo;
46
        }
47
48
        $changed = [];
49
        foreach ($this->locales() as $locale) {
50
            // protect against saving foreign languages
51
            if (app('scaffold.translations')->readonly($locale)) {
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
            if (/** @scrutinizer ignore-call */ app('scaffold.translations')->readonly($locale)) {
Loading history...
52
                continue;
53
            }
54
55
            $changed[] = $locale->iso6391();
56
            $this->manager()->save($translation, $locale->iso6391());
57
        }
58
59
        event(new TranslationsChanged($changed));
0 ignored issues
show
Bug introduced by
The function event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        event(new TranslationsChanged($changed));
Loading history...
60
61
        return $redirectTo;
62
    }
63
64
    /**
65
     * @return Collection
66
     */
67
    protected function locales(): Collection
68
    {
69
        return \localizer\locales();
70
    }
71
72
    /**
73
     * @return TranslationsManager
74
     */
75
    protected function manager(): ?TranslationsManager
76
    {
77
        return app(TranslationsManager::class)->setLocales(
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        return /** @scrutinizer ignore-call */ app(TranslationsManager::class)->setLocales(
Loading history...
78
            $this->locales()
79
        );
80
    }
81
}
82