Skip to content

Commit 9de4e09

Browse files
committed
PhpFile: added addUse() [Closes #38]
1 parent 7c5e08e commit 9de4e09

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/PhpGenerator/PhpFile.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public function getNamespaces(): array
7777
}
7878

7979

80+
/**
81+
* @return static
82+
*/
83+
public function addUse(string $name, string $alias = null): self
84+
{
85+
$this->addNamespace('')->addUse($name, $alias);
86+
return $this;
87+
}
88+
89+
8090
/**
8191
* Adds declare(strict_types=1) to output.
8292
* @return static

tests/PhpGenerator/PhpFile.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ sameFile(__DIR__ . '/expected/PhpFile.bracketed.expect', (string) $file);
7878

7979
$file = new PhpFile;
8080
$file->addClass('A');
81+
$file->addUse('A')
82+
->addUse('B', 'C');
8183

8284
sameFile(__DIR__ . '/expected/PhpFile.globalNamespace.expect', (string) $file);
8385

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use B as C;
4+
35
class A
46
{
57
}

0 commit comments

Comments
 (0)