Completed
Push — master ( 02e9e6...9b3fc3 )
by ARCANEDEV
09:52
created

PagePresenter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 1
dl 0
loc 44
rs 10
c 0
b 0
f 0
ccs 0
cts 15
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocaleNameAttribute() 0 4 1
A getContentPreviewAttribute() 0 6 2
A getReplacerPattern() 0 6 2
1
<?php namespace Arcanesoft\Seo\Models\Presenters;
2
3
use Arcanesoft\Seo\Entities\Locales;
4
5
/**
6
 * Class     PagePresenter
7
 *
8
 * @package  Arcanesoft\Seo\Models\Presenters
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  string  locale
12
 * @property  string  locale_name
13
 * @property  string  content
14
 * @property  string  content_preview
15
 */
16
trait PagePresenter
17
{
18
    /* -----------------------------------------------------------------
19
     |  Accessors
20
     | -----------------------------------------------------------------
21
     */
22
    /**
23
     * Get the `locale_name` attribute.
24
     *
25
     * @return string|null
26
     */
27
    public function getLocaleNameAttribute()
28
    {
29
        return Locales::get($this->locale);
30
    }
31
32
    /**
33
     * Get the `content_preview` attribute.
34
     *
35
     * @return string
36
     */
37
    public function getContentPreviewAttribute()
38
    {
39
        return empty($pattern = $this->getReplacerPattern())
40
            ? $this->content
41
            : preg_replace($pattern, '<span class="label label-inverse">[\1]</span>', $this->content);
42
    }
43
44
    /* -----------------------------------------------------------------
45
     |  Other Methods
46
     | -----------------------------------------------------------------
47
     */
48
    /**
49
     * Get the content replacer pattern.
50
     *
51
     * @return string
52
     */
53
    protected function getReplacerPattern()
54
    {
55
        $replacer = config('arcanesoft.seo.pages.replacer', []);
56
57
        return empty($replacer) ? '' : '/\[('.implode('|', $replacer).')\]/';
58
    }
59
}
60