Skip to content

Commit

Permalink
PhpFile: added addUse() [Closes #38]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 27, 2018
1 parent 7c5e08e commit 9de4e09
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/PhpGenerator/PhpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public function getNamespaces(): array
}


/**
* @return static
*/
public function addUse(string $name, string $alias = null): self
{
$this->addNamespace('')->addUse($name, $alias);
return $this;
}


/**
* Adds declare(strict_types=1) to output.
* @return static
Expand Down
2 changes: 2 additions & 0 deletions tests/PhpGenerator/PhpFile.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ sameFile(__DIR__ . '/expected/PhpFile.bracketed.expect', (string) $file);

$file = new PhpFile;
$file->addClass('A');
$file->addUse('A')
->addUse('B', 'C');

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

Expand Down
2 changes: 2 additions & 0 deletions tests/PhpGenerator/expected/PhpFile.globalNamespace.expect
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use B as C;

class A
{
}

0 comments on commit 9de4e09

Please sign in to comment.