Test Failed
Pull Request — master (#277)
by Sergei
19:11 queued 04:37
created

BinaryColumnSchema   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 16
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A dbTypecast() 0 14 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use Yiisoft\Db\Command\ParamInterface;
8
use Yiisoft\Db\Expression\Expression;
9
use Yiisoft\Db\Schema\Column\BinaryColumnSchema as BaseBinaryColumnSchema;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Schema\Column\BinaryColumnSchema was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
use function bin2hex;
12
use function is_string;
13
14
final class BinaryColumnSchema extends BaseBinaryColumnSchema
15
{
16
    public function dbTypecast(mixed $value): mixed
17
    {
18
        if ($this->getDbType() === 'varbinary') {
19
            if ($value instanceof ParamInterface && is_string($value->getValue())) {
20
                /** @psalm-var string */
21
                $value = $value->getValue();
22
            }
23
24
            if (is_string($value)) {
25
                return new Expression('CONVERT(VARBINARY(MAX), ' . ('0x' . bin2hex($value)) . ')');
26
            }
27
        }
28
29
        return parent::dbTypecast($value);
30
    }
31
}
32