Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
UseTrait | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
addUse | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addUses | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
hasUse | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasUses | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUses | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Code\Generator\Traits; |
15 | |
16 | /** |
17 | * Use trait |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Code |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 5.0.0 |
25 | */ |
26 | trait UseTrait |
27 | { |
28 | |
29 | /** |
30 | * Array of namespaces to use |
31 | * @var array |
32 | */ |
33 | protected array $uses = []; |
34 | |
35 | /** |
36 | * Add a namespace to use |
37 | * |
38 | * @param string $use |
39 | * @param ?string $as |
40 | * @return static |
41 | */ |
42 | public function addUse(string $use, ?string $as = null): static |
43 | { |
44 | $this->uses[$use] = $as; |
45 | return $this; |
46 | } |
47 | |
48 | /** |
49 | * Add namespaces to use |
50 | * |
51 | * @param array $uses |
52 | * @return static |
53 | */ |
54 | public function addUses(array $uses): static |
55 | { |
56 | foreach ($uses as $as => $use) { |
57 | if (!is_numeric($as)) { |
58 | $this->addUse($use, $as); |
59 | } else { |
60 | $this->addUse($use); |
61 | } |
62 | } |
63 | return $this; |
64 | } |
65 | |
66 | /** |
67 | * Has use |
68 | * |
69 | * @param string $use |
70 | * @return bool |
71 | */ |
72 | public function hasUse(string$use): bool |
73 | { |
74 | return array_key_exists($use, $this->uses); |
75 | } |
76 | |
77 | /** |
78 | * Has uses |
79 | * |
80 | * @return bool |
81 | */ |
82 | public function hasUses(): bool |
83 | { |
84 | return (!empty($this->uses)); |
85 | } |
86 | |
87 | /** |
88 | * Get uses |
89 | * |
90 | * @return array |
91 | */ |
92 | public function getUses(): array |
93 | { |
94 | return $this->uses; |
95 | } |
96 | |
97 | } |