Completed
Push — master ( 7b0cec...95f4c8 )
by Alexandr
06:11
created

PluginSeoTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addPluginSeo() 0 22 1
1
<?php
2
3
namespace Larrock\Core\Plugins;
4
5
use Larrock\Core\Helpers\FormBuilder\FormInput;
6
use Larrock\Core\Helpers\FormBuilder\FormTextarea;
7
8
trait PluginSeoTrait
9
{
10
    /**
11
     * Подключение плагина SEO
12
     * @return $this
13
     */
14
    public function addPluginSeo()
15
    {
16
        $row = new FormInput('seo_title', 'Title материала');
17
        $this->rows['seo_title'] = $rows_plugin[] = $row->setTab('seo', 'Seo')->setValid('max:255')
0 ignored issues
show
Bug introduced by
The property rows does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Coding Style Comprehensibility introduced by
$rows_plugin was never initialized. Although not strictly required by PHP, it is generally a good practice to add $rows_plugin = 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...
18
            ->setTypo()->setHelp('По-умолчанию равно заголовку материала');
19
20
        $row = new FormInput('seo_description', 'Description материала');
21
        $this->rows['seo_description'] = $rows_plugin[] = $row->setTab('seo', 'Seo')->setValid('max:255')
22
            ->setTypo()->setHelp('По-умолчанию равно заголовку материала');
23
24
        $row = new FormTextarea('seo_keywords', 'Keywords материала');
25
        $this->rows['seo_keywords'] = $rows_plugin[] = $row->setTab('seo', 'Seo')->setValid('max:255')
26
            ->setCssClass('not-editor uk-width-1-1');
27
28
        $this->plugins_backend['seo']['rows'] = $rows_plugin;
0 ignored issues
show
Bug introduced by
The property plugins_backend does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
30
        $row = new FormInput('url', 'URL материала');
31
        $this->rows['url'] = $row->setTab('seo', 'SEO')
32
            ->setValid('max:155|required|unique:'. $this->table .',url,:id')->setCssClass('uk-width-1-1')->setFillable();
0 ignored issues
show
Bug introduced by
The property table does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
34
        return $this;
35
    }
36
}