Limit   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%
Metric Value
dl 31
loc 31
wmc 5
lcom 1
cbo 0
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A toString() 12 12 2
A ensureIsInteger() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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