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

Editor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 13.46 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A direction() 0 6 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
/**
8
 * add class 'ckeditor' for each ckeditor if you want jquery validation
9
 * Class Editor
10
 * @package Encore\Admin\Form\Field
11
 */
12
class Editor extends Field
13
{
14
    protected static $js = [
15
        '/js/plugins/ckeditor/ckeditor.js',
16
//        '//cdn.ckeditor.com/4.5.10/standard/ckeditor.js',
17
    ];
18
19
    public function __construct($column, array $arguments = [])
20
    {
21
        parent::__construct($column, $arguments);
22
23
        $this->options(['contentsLangDirection' => 'ltr']);
24
        $this->options(['language' => config('app.locale', 'en')]);
25
        //for jquery validation
26
        $this->addElementClass(['validate','ckeditor']);
27
28
    }
29
30
    /**
31
     * set `direction` .
32
     * https://docs-old.ckeditor.com/ckeditor_api/symbols/CKEDITOR.config.html#.contentsLangDirection
33
     * 'ui' – indicates that content direction will be the same as the user interface language direction;
34
     * 'ltr' – for Left-To-Right language (like English);
35
     * 'rtl' – for Right-To-Left languages (like Arabic).
36
     * @param string $dir
37
     * @return $this
38
     */
39
    public function direction($dir ='ltr')
40
    {
41
         $this->options(['contentsLangDirection' => $dir]);
42
        $this->direction = $dir;
43
44
        return $this;    }
45
46
    /**
47
     * set language for editor
48
     * @param string $dir
49
     * @return $this
50
     */
51
    public function lang($dir)
52
    {
53
        return $this->options(['language' => $dir]);
54
    }
55
56 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...
57
    {
58
        $options = json_encode($this->options);
59
        $this->script = "CKEDITOR.replace('{$this->column}', $options);";
60
61
        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 61 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
62
    }
63
}
64