UnknownTypeNode.php 1.91 KB
Newer Older
1 2 3 4 5
<?php

declare(strict_types=1);

/*
6
 * This file is part of the Application mapper application,
7 8 9 10 11 12 13 14 15 16 17
 * following the Explicit Architecture principles.
 *
 * @link https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together
 * @link https://herbertograca.com/2018/07/07/more-than-concentric-layers/
 *
 * (c) Herberto Graça
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

18
namespace Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Node;
19

20
use Hgraca\AppMapper\Core\Port\Parser\Node\TypeNodeInterface;
21
use Hgraca\PhpExtension\String\ClassHelper;
22 23 24 25
use PhpParser\Node;
use function get_class;
use function is_string;

26 27 28 29
/**
 * This node is just for convenience.
 * We don't know what is inside and we don't care.
 */
30 31 32 33 34 35 36 37
final class UnknownTypeNode implements TypeNodeInterface
{
    /**
     * @var string
     */
    private $phpParserNodeType = '';

    /**
Herberto Graca's avatar
Herberto Graca committed
38
     * @param string|Node|null $node
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
     */
    public function __construct($node = null)
    {
        switch (true) {
            case $node === null:
                $this->phpParserNodeType = 'null';
                break;
            case is_string($node):
                $this->phpParserNodeType = $node;
                break;
            default:
                $this->phpParserNodeType = get_class($node);
                break;
        }
    }

    public function getFullyQualifiedType(): string
    {
        return 'Unknown (' . $this->phpParserNodeType . ')';
    }

    public function getCanonicalType(): string
    {
        return 'Unknown (' . $this->phpParserNodeType . ')';
    }
64 65 66 67 68

    public function getAllFamilyFullyQualifiedNameList(): array
    {
        return [];
    }
69 70 71

    public function __toString(): string
    {
72
        return ClassHelper::extractCanonicalClassName(__CLASS__) . ' - ' . $this->phpParserNodeType;
73
    }
74
}