Completed
Push — master ( 9a3bda...239191 )
by Edgard
37:20
created

ColumnSchema::typecast()   D

Complexity

Conditions 18
Paths 15

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 18.8222

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
ccs 19
cts 22
cp 0.8636
rs 4.947
cc 18
eloc 24
nc 15
nop 1
crap 18.8222

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace edgardmessias\db\firebird;
9
10
use yii\db\Expression;
11
12
/**
13
 *
14
 * @author Edgard Lorraine Messias <[email protected]>
15
 * @since 2.0
16
 */
17
class ColumnSchema extends \yii\db\ColumnSchema
18
{
19
20
    /**
21
     * Converts the input value according to [[phpType]] after retrieval from the database.
22
     * If the value is null or an [[Expression]], it will not be converted.
23
     * @param mixed $value input value
24
     * @return mixed converted value
25
     * @since 2.0.3
26
     */
27 98
    protected function typecast($value)
28
    {
29
30 98
        if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
31 1
            return null;
32
        }
33 98
	if ($value instanceof ExpressionInterface) {
0 ignored issues
show
Bug introduced by
The class edgardmessias\db\firebird\ExpressionInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
34 94
	    return $value;
35
	}
36
        if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
37 87
            return $value;
38 87
        }
39 87
40 42
        switch ($this->phpType) {
41
            case 'resource':
42
            case 'string':
43 42
                if (is_resource($value)) {
44
                    return $value;
45 2
                }
46
                if (is_float($value)) {
47 42
                    // ensure type cast always has . as decimal separator in all locales
48 63
                    return str_replace(',', '.', (string) $value);
49 63
                }
50 3
                return (string) $value;
51
            case 'integer':
52 63
                if (is_bool($value)) {
53 16
                    return ($value) ? 1 : 0;
54
                }
55 16
                return (int) $value;
56 16
            case 'boolean':
57
                return (boolean) $value;
58
            case 'double':
59
                return (double) $value;
60
        }
61
62
        return $value;
63
    }
64
}
65