Completed
Branch master (afd3db)
by Yaro
01:50
created

TranslationLocalesSelectorTool   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 55
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A position() 0 4 1
A identifier() 0 4 1
A render() 0 7 1
A handle() 0 8 1
A check() 0 4 1
A isCurrentLocale() 0 4 1
1
<?php
2
3
namespace Yaro\Jarboe\Table\Toolbar;
4
5
use Illuminate\Http\Request;
6
7
class TranslationLocalesSelectorTool extends AbstractTool
8
{
9
    /**
10
     * Position where should tool be placed.
11
     */
12 1
    public function position()
13
    {
14 1
        return self::POSITION_HEADER;
15
    }
16
17
    /**
18
     * Unique tool identifier.
19
     */
20 2
    public function identifier(): string
21
    {
22 2
        return 'translation_locales_selector';
23
    }
24
25
    /**
26
     * Tool's view.
27
     */
28 1
    public function render()
29
    {
30 1
        return view('jarboe::crud.toolbar.translation_locales_selector', [
31 1
            'tool' => $this,
32 1
            'locales' => $this->crud()->getLocales(),
33
        ]);
34
    }
35
36
    /**
37
     * Handle tool execution.
38
     * @param Request $request
39
     */
40 1
    public function handle(Request $request)
41
    {
42 1
        $this->crud()->saveCurrentLocale($request->get('locale'));
43
44 1
        return response()->json([
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
45 1
            'ok' => true,
46
        ]);
47
    }
48
49
    /**
50
     * Check allowance to show and process tool.
51
     */
52 1
    public function check(): bool
53
    {
54 1
        return true;
55
    }
56
57 1
    public function isCurrentLocale($locale)
58
    {
59 1
        return $this->crud()->getCurrentLocale() == $locale;
60
    }
61
}
62