Completed
Push — master ( 3e3e3a...cfc77c )
by ARCANEDEV
11s
created

Spammer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
c 1
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php namespace Arcanedev\SpamBlocker\Entities;
2
3
use Illuminate\Contracts\Support\Arrayable;
4
use Illuminate\Contracts\Support\Jsonable;
5
6
/**
7
 * Class     Spammer
8
 *
9
 * @package  Entities
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class Spammer implements Arrayable, Jsonable
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /** @var string */
19
    protected $host;
20
21
    /** @var bool */
22
    protected $blocked;
23
24
    /* ------------------------------------------------------------------------------------------------
25
     |  Constructor
26
     | ------------------------------------------------------------------------------------------------
27
     */
28
    /**
29
     * Spammer constructor.
30
     *
31
     * @param  string  $host
32
     * @param  bool    $blocked
33
     */
34 360
    public function __construct($host, $blocked)
35
    {
36 360
        $this->setHost($host);
37 360
        $this->setBlocked($blocked);
38 360
    }
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Getters & Setters
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * Get the host url.
46
     *
47
     * @return string
48
     */
49 351
    public function host()
50
    {
51 351
        return $this->host;
52
    }
53
54
    /**
55
     * Set the host url.
56
     *
57
     * @param  string  $host
58
     *
59
     * @return self
60
     */
61 360
    public function setHost($host)
62
    {
63 360
        $this->host = trim(utf8_encode($host));
64
65 360
        return $this;
66
    }
67
68
    /**
69
     * Get the blocked status.
70
     *
71
     * @return bool
72
     */
73 171
    public function isBlocked()
74
    {
75 171
        return $this->blocked;
76
    }
77
78
    /**
79
     * Set the blocked status.
80
     *
81
     * @param  bool  $blocked
82
     *
83
     * @return self
84
     */
85 360
    public function setBlocked($blocked)
86
    {
87 360
        $this->blocked = (bool) $blocked;
88
89 360
        return $this;
90
    }
91
92
    /* ------------------------------------------------------------------------------------------------
93
     |  Main Functions
94
     | ------------------------------------------------------------------------------------------------
95
     */
96
    /**
97
     * Make a spammer instance.
98
     *
99
     * @param  string  $host
100
     * @param  bool    $blocked
101
     *
102
     * @return self
103
     */
104 324
    public static function make($host, $blocked = true)
105
    {
106 324
        return new static($host, $blocked);
107
    }
108
109
    /**
110
     * Check if the given host is the same as the spammer host.
111
     *
112
     * @param  string  $host
113
     *
114
     * @return bool
115
     */
116 9
    public function isSameHost($host)
117
    {
118 9
        return $this->host() === trim(utf8_encode($host));
119
    }
120
121
    /* ------------------------------------------------------------------------------------------------
122
     |  Other Functions
123
     | ------------------------------------------------------------------------------------------------
124
     */
125
    /**
126
     * Get the instance as an array.
127
     *
128
     * @return array
129
     */
130 18
    public function toArray()
131
    {
132
        return [
133 18
            'host'    => $this->host,
134 18
            'blocked' => $this->blocked,
135 6
        ];
136
    }
137
138
    /**
139
     * Convert the object to its JSON representation.
140
     *
141
     * @param  int  $options
142
     *
143
     * @return string
144
     */
145 9
    public function toJson($options = 0)
146
    {
147 9
        return json_encode($this->toArray(), $options);
148
    }
149
}
150