Number   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 44
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormControl() 0 9 1
A __getCondition() 0 19 4
1
<?php
2
3
/**
4
 * This file is part of the Grido (https://github.com/o5/grido)
5
 *
6
 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE.md that was distributed with this source code.
10
 */
11
12
namespace Grido\Components\Filters;
13
14
/**
15
 * Number input filter.
16
 *
17
 * @package     Grido
18
 * @subpackage  Components\Filters
19
 * @author      Petr Bugyík
20
 */
21
class Number extends Text
22 1
{
23
    /** @var string */
24
    protected $condition;
25
26
    /**
27
     * @return \Nette\Forms\Controls\TextInput
28
     */
29
    protected function getFormControl()
30
    {
31 1
        $control = parent::getFormControl();
32 1
        $hint = 'Grido.HintNumber';
33 1
        $control->getControlPrototype()->title = sprintf($this->translate($hint), rand(1, 9));
34 1
        $control->getControlPrototype()->class[] = 'number';
35
36 1
        return $control;
37
    }
38
39
    /**
40
     * @param string $value
41
     * @return Condition|bool
42
     * @throws \Exception
43
     * @internal
44
     */
45
    public function __getCondition($value)
46
    {
47 1
        $condition = parent::__getCondition($value);
48
49 1
        if ($condition === NULL) {
50 1
            $condition = Condition::setupEmpty();
51
52 1
            if (preg_match('/(<>|[<|>]=?)?([-0-9,|.]+)/', $value, $matches)) {
53 1
                $value = str_replace(',', '.', $matches[2]);
54 1
                $operator = $matches[1]
55 1
                    ? $matches[1]
56 1
                    : '=';
57
58 1
                $condition = Condition::setup($this->getColumn(), $operator . ' ?', $value);
59 1
            }
60 1
        }
61
62 1
        return $condition;
63
    }
64
}
65