Limit::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Muffin\Queries\Snippets;
4
5
use Muffin\Snippet;
6
7 View Code Duplication
class Limit implements Snippet
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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