Completed
Pull Request — master (#1350)
by
unknown
02:38
created

Editor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 14.89 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 7
loc 47
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A dir() 0 4 1
A lang() 0 4 1
A render() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Form\Field;
6
7
class Editor extends Field
8
{
9
    protected static $js = [
10
        '//cdn.ckeditor.com/4.5.10/standard/ckeditor.js',
11
    ];
12
13
    public function __construct($column, array $arguments = [])
14
    {
15
        parent::__construct($column, $arguments);
16
17
        $this->options(['contentsLangDirection' => 'ltr']);
18
        $this->options(['language' => config('app.locale', 'en')]);
19
20
    }
21
22
    /**
23
     * set `direction` .
24
     * https://docs-old.ckeditor.com/ckeditor_api/symbols/CKEDITOR.config.html#.contentsLangDirection
25
     * 'ui' – indicates that content direction will be the same as the user interface language direction;
26
     * 'ltr' – for Left-To-Right language (like English);
27
     * 'rtl' – for Right-To-Left languages (like Arabic).
28
     * @param string $dir
29
     * @return $this
30
     */
31
    public function dir($dir)
32
    {
33
        return $this->options(['contentsLangDirection' => $dir]);
34
    }
35
36
    /**
37
     * set language for editor
38
     * @param string $dir
39
     * @return $this
40
     */
41
    public function lang($dir)
42
    {
43
        return $this->options(['language' => $dir]);
44
    }
45
46 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $options = json_encode($this->options);
49
        $this->script = "CKEDITOR.replace('{$this->column}', $options);";
50
51
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 51 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
52
    }
53
}
54