TranslationController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 11

Importance

Changes 9
Bugs 0 Features 0
Metric Value
wmc 6
c 9
b 0
f 0
lcom 3
cbo 11
dl 0
loc 63
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A index() 0 6 1
A update() 0 6 1
A export() 0 8 1
A import() 0 6 1
A requireAssets() 0 7 1
1
<?php namespace Modules\Translation\Http\Controllers\Admin;
2
3
use Illuminate\Http\Request;
4
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
5
use Modules\Translation\Entities\TranslationTranslation;
6
use Modules\Translation\Exporters\TranslationsExporter;
7
use Modules\Translation\Http\Requests\ImportTranslationsRequest;
8
use Modules\Translation\Importers\TranslationsImporter;
9
use Modules\Translation\Repositories\TranslationRepository;
10
use Modules\Translation\Services\TranslationsService;
11
use Pingpong\Modules\Facades\Module;
12
13
class TranslationController extends AdminBaseController
14
{
15
    /**
16
     * @var TranslationsService
17
     */
18
    private $translationsService;
19
    /**
20
     * @var TranslationRepository
21
     */
22
    private $translation;
23
24
    public function __construct(TranslationsService $translationsService, TranslationRepository $translation)
25
    {
26
        parent::__construct();
27
28
        $this->translationsService = $translationsService;
29
        $this->translation = $translation;
30
        $this->requireAssets();
31
    }
32
33
    /**
34
     * Display a listing of the resource.
35
     *
36
     * @return Response
37
     */
38
    public function index()
39
    {
40
        $translations = $this->translationsService->getFileAndDatabaseMergedTranslations();
41
42
        return view('translation::admin.translations.index', compact('translations'));
43
    }
44
45
    public function update(TranslationTranslation $translationTranslation, Request $request)
46
    {
47
        $this->translation->updateTranslationToValue($translationTranslation, $request->get('oldValue'));
48
49
        return redirect()->route('admin.translation.translation.index')->withSuccess('Translation saved.');
50
    }
51
52
    public function export(TranslationsExporter $exporter)
53
    {
54
        return response()->make($exporter->export(), [
0 ignored issues
show
Documentation introduced by
array('Content-Type' => ...'Pragma' => 'no-cache') is of type array<string,string,{"Co...ng","Pragma":"string"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
55
            "Content-Type" => "application/csv",
56
            "Content-Disposition" => "attachment; filename=export_{$exporter->getFileName()}.csv",
57
            "Pragma" => "no-cache"
58
        ]);
59
    }
60
61
    public function import(ImportTranslationsRequest $request, TranslationsImporter $importer)
62
    {
63
        $importer->import($request->file('file'));
0 ignored issues
show
Bug introduced by
It seems like $request->file('file') targeting Illuminate\Http\Request::file() can also be of type array or null; however, Modules\Translation\Impo...tionsImporter::import() does only seem to accept object<Symfony\Component...tion\File\UploadedFile>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
64
65
        return redirect()->route('admin.translation.translation.index')->withSuccess(trans('translation::translations.Translations imported'));
66
    }
67
68
    private function requireAssets()
69
    {
70
        $this->assetManager->addAsset('bootstrap-editable.css', Module::asset('translation:vendor/x-editable/dist/bootstrap3-editable/css/bootstrap-editable.css'));
71
        $this->assetManager->addAsset('bootstrap-editable.js', Module::asset('translation:vendor/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.min.js'));
72
        $this->assetPipeline->requireJs('bootstrap-editable.js');
73
        $this->assetPipeline->requireCss('bootstrap-editable.css');
74
    }
75
}
76