Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
12 / 15
40.00% covered (danger)
40.00%
2 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
ClassSymbol
80.00% covered (warning)
80.00%
12 / 15
40.00% covered (danger)
40.00%
2 / 5
5.20
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getExtends
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInterfaces
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isAbstract
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAutoloadAliasArray
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BrianHenryIE\Strauss\Types;
4
5use BrianHenryIE\Strauss\Files\FileBase;
6
7/**
8 * @phpstan-import-type ClassAliasArray from AutoloadAliasInterface
9 */
10class ClassSymbol extends NamespacedSymbol implements AutoloadAliasInterface
11{
12    protected ?string $extends;
13    protected bool $isAbstract;
14
15    /**
16     * @var string[]
17     */
18    protected array $interfaces;
19
20    /**
21     * @param string $fqdnClassname
22     * @param FileBase $sourceFile
23     * @param ?NamespaceSymbol $namespace
24     * @param bool $isAbstract
25     * @param ?string $extends
26     * @param string[] $interfaces
27     */
28    public function __construct(
29        string $fqdnClassname,
30        FileBase $sourceFile,
31        NamespaceSymbol $namespace,
32        bool $isAbstract = false,
33        ?string $extends = null,
34        array $interfaces = []
35    ) {
36        parent::__construct($fqdnClassname, $sourceFile, $namespace);
37
38        $this->isAbstract = $isAbstract;
39        $this->extends = $extends;
40        $this->interfaces = $interfaces;
41    }
42
43    public function getExtends(): ?string
44    {
45        return $this->extends;
46    }
47
48    /**
49     * @return string[]
50     */
51    public function getInterfaces(): array
52    {
53        return $this->interfaces;
54    }
55
56    public function isAbstract(): bool
57    {
58        return $this->isAbstract;
59    }
60
61    /**
62     * In `autoload_aliases.php`, we create aliases for the old class name by creating a class that extends the renamed
63     * class. This makes the original methods available via the original classname to dev dependencies without updating
64     * their call sites.
65     *
66     * ```
67     * class OriginalName extends NewName {}
68     * ```
69     *
70     * @see AliasAutoloader::classTemplate()
71     *
72     * @return ClassAliasArray
73     */
74    public function getAutoloadAliasArray(): array
75    {
76        return array (
77            'type' => 'class',
78            'classname' => $this->getOriginalLocalName(),
79            'isabstract' => $this->isAbstract,
80            'namespace' => $this->namespace->getOriginalFqdnName(),
81            'extends' => $this->getReplacementFqdnName(),
82            'implements' => $this->interfaces,
83        );
84    }
85}