TranslationController::savestring()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use Illuminate\Http\Request;
11
use Waavi\Translation\Repositories\LanguageRepository;
12
use Waavi\Translation\Repositories\TranslationRepository;
13
14
class TranslationController extends Controller
15
{
16
    protected $languageRepository;
17
    protected $translationRepository;
18
19
    public function __construct(LanguageRepository $languageRepository, TranslationRepository $translationRepository)
20
    {
21
        $this->languageRepository = $languageRepository;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
22
        $this->translationRepository = $translationRepository;
23
    }
24
25
    public function index()
26
    {
27
        $locales = $this->languageRepository->availableLocales();
28
29
        $list = [];
30
31
        foreach ($locales as $loc) {
32
            $temp['loc'] = $loc;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$temp was never initialized. Although not strictly required by PHP, it is generally a good practice to add $temp = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
33
            $temp['perc'] = $this->languageRepository->percentTranslated($loc);
34
            $list[] = $temp;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
        }
36
37
        return view('translate.index', [
38
            'list' => $list,
39
        ]);
40
    }
41
42
    public function edit($loc1, $loc2 = 'de', $viewtype = 'untranslated', $searchterm = '')
0 ignored issues
show
Unused Code introduced by
The parameter $searchterm is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        $list = null;
45
46
        if ($viewtype == 'untranslated') {
47
            $list = $this->translationRepository->untranslated($loc2);
48
        } elseif ($viewtype == 'all') {
49
            $list = $this->translationRepository->allByLocale($loc2);
50
        }
51
52
        return view('translate.show', [
53
            'list' => $list,
54
            'loc1' => $loc1,
55
            'loc2' => $loc2,
56
        ]);
57
    }
58
59
    public function savestring(Request $request)
60
    {
61
        //$this->translationRepository->translateText($request->get('transstring'), $request->get('loc2'), $request->get('loc1'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
        $trans = $this->translationRepository->find($request->get('id'));
63
64
        $this->translationRepository->create([
65
            'locale'    => $request->get('loc2'),
66
            'namespace' => $trans->namespace,
67
            'group'     => $trans->group,
68
            'item'      => $trans->item,
69
            'text'      => $request->get('transstring'),
70
        ]);
71
72
        return redirect()->action('TranslationController@edit', [$request->get('loc1'), $request->get('loc2')]);
73
    }
74
}
75