Passed
Push — master ( 4ffa89...1148e4 )
by Wilmer
04:06
created

ColumnSchema   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A dbTypecast() 0 13 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle;
6
7
use Yiisoft\Db\Expression\Expression;
8
use Yiisoft\Db\Pdo\PdoValue;
9
use Yiisoft\Db\Schema\ColumnSchema as AbstractColumnSchema;
10
use Yiisoft\Db\Schema\Schema;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Yiisoft\Db\Oracle\Schema. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
12
/**
13
 * Class ColumnSchema for Oracle database
14
 */
15
final class ColumnSchema extends AbstractColumnSchema
16
{
17 35
    public function dbTypecast($value)
18
    {
19 35
        if ($this->getType() === Schema::TYPE_BINARY && $this->getDbType() === 'BLOB') {
20 3
            if ($value instanceof PdoValue && is_string($value->getValue())) {
21 1
                $value = $value->getValue();
22
            }
23 3
            if (is_string($value)) {
24 3
                $placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName()));
25 3
                return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]);
26
            }
27
        }
28
29 35
        return parent::dbTypecast($value);
30
    }
31
}
32