FloatTypeCaster::typeCast()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 16
Code Lines 13

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 16
loc 16
ccs 12
cts 12
cp 1
rs 8.8571
cc 6
eloc 13
nc 6
nop 1
crap 6
1
<?php
2
namespace Xiag\Rql\Parser\TypeCaster;
3
4
use Xiag\Rql\Parser\Token;
5
use Xiag\Rql\Parser\TypeCasterInterface;
6
7 View Code Duplication
class FloatTypeCaster implements TypeCasterInterface
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
    /**
10
     * @inheritdoc
11
     */
12 1
    public function typeCast(Token $token)
13
    {
14 1
        if ($token->test(Token::T_NULL)) {
15 1
            return 0.;
16 1
        } elseif ($token->test(Token::T_TRUE)) {
17 1
            return 1.;
18 1
        } elseif ($token->test(Token::T_FALSE)) {
19 1
            return 0.;
20 1
        } elseif ($token->test(Token::T_EMPTY)) {
21 1
            return 0.;
22 1
        } elseif ($token->test(Token::T_DATE)) {
23 1
            return (float)(new \DateTime($token->getValue()))->format('YmdHis');
24
        } else {
25 1
            return (float)$token->getValue();
26
        }
27
    }
28
}
29