Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
22.22% |
2 / 9 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TraitSymbol | |
22.22% |
2 / 9 |
|
33.33% |
1 / 3 |
7.23 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getUses | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAutoloadAliasArray | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BrianHenryIE\Strauss\Types; |
| 4 | |
| 5 | use BrianHenryIE\Strauss\Composer\ComposerPackage; |
| 6 | use BrianHenryIE\Strauss\Files\FileBase; |
| 7 | |
| 8 | /** |
| 9 | * @phpstan-import-type TraitAliasArray from AutoloadAliasInterface |
| 10 | */ |
| 11 | class TraitSymbol extends NamespacedSymbol implements AutoloadAliasInterface |
| 12 | { |
| 13 | /** |
| 14 | * @var string[] |
| 15 | */ |
| 16 | protected array $uses; |
| 17 | |
| 18 | /** |
| 19 | * @param string $fqdnClassname |
| 20 | * @param FileBase $sourceFile |
| 21 | * @param ?NamespaceSymbol $namespace |
| 22 | * @param ?ComposerPackage $composerPackage |
| 23 | * @param ?string[] $uses |
| 24 | */ |
| 25 | public function __construct( |
| 26 | string $fqdnClassname, |
| 27 | FileBase $sourceFile, |
| 28 | ?NamespaceSymbol $namespace = null, |
| 29 | ?ComposerPackage $composerPackage = null, |
| 30 | ?array $uses = null |
| 31 | ) { |
| 32 | parent::__construct($fqdnClassname, $sourceFile, $namespace, $composerPackage); |
| 33 | |
| 34 | $this->uses = (array) $uses; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return string[] |
| 39 | */ |
| 40 | public function getUses(): array |
| 41 | { |
| 42 | return $this->uses; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * In `autoload_aliases.php`, we create aliases for the old trait name by creating a trait for them and `use`ing |
| 47 | * the renamed trait. |
| 48 | * |
| 49 | * ``` |
| 50 | * trait OriginalName { |
| 51 | * use UpdatedName; |
| 52 | * } |
| 53 | * ``` |
| 54 | * |
| 55 | * This contains all the methods of the trait and can be used in dev dependencies without renaming their call sites. |
| 56 | * |
| 57 | * @see AliasAutoloader::traitTemplate() |
| 58 | * |
| 59 | * @return TraitAliasArray |
| 60 | */ |
| 61 | public function getAutoloadAliasArray(): array |
| 62 | { |
| 63 | return array ( |
| 64 | 'type' => 'trait', |
| 65 | 'traitname' => $this->getOriginalLocalName(), |
| 66 | 'namespace' => $this->namespace->getOriginalFqdnName(), |
| 67 | 'use' => [$this->getReplacementFqdnName()], |
| 68 | ); |
| 69 | } |
| 70 | } |