TranslationsController::manager()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

31
        return /** @scrutinizer ignore-call */ view(Architect::template()->translations('index'), [
Loading history...
32
            'pagination' => $pagination,
33
            'scopes' => $this->manager()->filters(),
34
        ]);
35
    }
36
37
    /**
38
     * @param Request $request
39
     * @return \Illuminate\Http\RedirectResponse
40
     */
41
    public function store(Request $request)
42
    {
43
        $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

43
        $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

43
        $redirectTo = /** @scrutinizer ignore-call */ redirect()->back()->with('messages', [trans('administrator::messages.update_success')]);
Loading history...
44
45
        if (empty($translation = $request->input('translation'))) {
46
            return $redirectTo;
47
        }
48
49
        $changed = [];
50
        foreach ($this->locales() as $locale) {
51
            // protect against saving foreign languages
52
            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

52
            if (/** @scrutinizer ignore-call */ app('scaffold.translations')->readonly($locale)) {
Loading history...
53
                continue;
54
            }
55
56
            $changed[] = $locale->iso6391();
57
            $this->manager()->save($translation, $locale->iso6391());
58
        }
59
60
        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

60
        /** @scrutinizer ignore-call */ 
61
        event(new TranslationsChanged($changed));
Loading history...
61
62
        return $redirectTo;
63
    }
64
65
    /**
66
     * @return Collection
67
     */
68
    protected function locales(): Collection
69
    {
70
        return \localizer\locales();
71
    }
72
73
    /**
74
     * @return TranslationsManager
75
     */
76
    protected function manager(): ?TranslationsManager
77
    {
78
        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

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