Code Duplication    Length = 31-31 lines in 2 locations

src/Queries/Snippets/Limit.php 1 location

@@ 7-37 (lines=31) @@
4
5
use Muffin\Snippet;
6
7
class Limit implements Snippet
8
{
9
    private
10
        $limit;
11
12
    public function __construct($limit)
13
    {
14
        $this->limit = $this->ensureIsInteger($limit);
15
    }
16
17
    public function toString()
18
    {
19
        if(empty($this->limit))
20
        {
21
            return '';
22
        }
23
24
        return sprintf(
25
            'LIMIT %s',
26
            $this->limit
27
        );
28
    }
29
30
    private function ensureIsInteger($value)
31
    {
32
        if(preg_match('~^[\d]+$~', $value))
33
        {
34
            return (int) $value;
35
        }
36
    }
37
}
38

src/Queries/Snippets/Offset.php 1 location

@@ 7-37 (lines=31) @@
4
5
use Muffin\Snippet;
6
7
class Offset implements Snippet
8
{
9
    private
10
        $offset;
11
12
    public function __construct($offset)
13
    {
14
        $this->offset = $this->ensureIsInteger($offset);
15
    }
16
17
    public function toString()
18
    {
19
        if(empty($this->offset))
20
        {
21
            return '';
22
        }
23
24
        return sprintf(
25
            'OFFSET %s',
26
            $this->offset
27
        );
28
    }
29
30
    private function ensureIsInteger($value)
31
    {
32
        if(preg_match('~^[\d]+$~', $value))
33
        {
34
            return (int) $value;
35
        }
36
    }
37
}
38