Passed
Pull Request — 1.x (#13)
by
unknown
43:32 queued 28:34
created

Column   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 17
c 1
b 0
f 1
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 3 1
A formatTypecast() 0 21 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\MermaidRenderer;
6
7
/**
8
 * @psalm-type Ttype=class-string|string|\Closure|object|array{0: class-string, 1: non-empty-string}
9
 */
10
final class Column implements Stringable
11
{
12
    use StringFormatter;
13
14
    private string $type;
15
    private string $column;
16
17
    /**
18
     * @param Ttype $type
0 ignored issues
show
Bug introduced by
The type Cycle\Schema\Renderer\MermaidRenderer\Ttype 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...
19
     */
20
    public function __construct($type, string $column)
21
    {
22
        $this->type = $this->formatTypecast($type);
23
        $this->column = $column;
24
    }
25
26
    public function __toString(): string
27
    {
28
        return "$this->type $this->column";
29
    }
30
31
    /**
32
     * @param Ttype $typecast
33
     *
34
     * @return string
35
     */
36
    private function formatTypecast($typecast): string
37
    {
38
        if (\is_array($typecast)) {
0 ignored issues
show
introduced by
The condition is_array($typecast) is always false.
Loading history...
39
            $typecast[0] = $this->getClassShortName($typecast[0]);
40
41
            return \sprintf("[%s, '%s']", "$typecast[0]::class", $typecast[1]);
42
        }
43
44
        if ($typecast instanceof \Closure) {
45
            return 'Closure';
46
        }
47
48
        if ($typecast === 'datetime') {
49
            return $typecast;
50
        }
51
52
        if (\is_object($typecast) || \class_exists($typecast)) {
53
            return $this->getClassShortName($typecast) . '::class';
54
        }
55
56
        return \htmlentities($typecast, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401);
57
    }
58
}
59