Description::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace LaraComponents\Seo\Entities;
4
5
use LaraComponents\Seo\Traits\HasLimit;
6
7
class Description
8
{
9
    use HasLimit;
10
11
    /**
12
     * @var string
13
     */
14
    protected $content;
15
16
    /**
17
     * @var int
18
     */
19
    protected $maxSize;
20
21
    /**
22
     * Create a new description instance.
23
     *
24
     * @param array $config
25
     */
26
    public function __construct(array $config = [])
27
    {
28
        $this->initConfig($config);
29
    }
30
31
    /**
32
     * Init config.
33
     *
34
     * @param  array  $config
35
     * @return void
36
     */
37
    protected function initConfig(array $config)
38
    {
39
        $this->setMaxSize(isset($config['max_size']) ? $config['max_size'] : 0);
40
41
        if(isset($config['default'])) {
42
            $this->set($config['default']);
43
        }
44
    }
45
46
    public function setMaxSize($size)
47
    {
48
        $this->maxSize = (int) $size;
49
50
        return $this;
51
    }
52
53
    public function getMaxSize()
54
    {
55
        return $this->maxSize;
56
    }
57
58
    public function set($content)
59
    {
60
        $this->content = trim(strip_tags($content));
61
62
        return $this;
63
    }
64
65
    public function get()
66
    {
67
        if (is_null($this->content)) {
68
            return '';
69
        }
70
71
        return $this->maxSize > 0 ? $this->limit($this->content, $this->maxSize) : $this->content;
72
    }
73
74
    public function toString()
75
    {
76
        return $this->get();
77
    }
78
79
    public function __toString()
80
    {
81
        return $this->toString();
82
    }
83
}
84