From 9de4e093a130f7a1bd175198799ebc0efbac6924 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 27 Nov 2018 20:00:14 +0100 Subject: [PATCH] PhpFile: added addUse() [Closes #38] --- src/PhpGenerator/PhpFile.php | 10 ++++++++++ tests/PhpGenerator/PhpFile.phpt | 2 ++ .../expected/PhpFile.globalNamespace.expect | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/PhpGenerator/PhpFile.php b/src/PhpGenerator/PhpFile.php index e1aa45dd..bcc98c2c 100644 --- a/src/PhpGenerator/PhpFile.php +++ b/src/PhpGenerator/PhpFile.php @@ -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 diff --git a/tests/PhpGenerator/PhpFile.phpt b/tests/PhpGenerator/PhpFile.phpt index 91a321e6..a3a6e1bf 100644 --- a/tests/PhpGenerator/PhpFile.phpt +++ b/tests/PhpGenerator/PhpFile.phpt @@ -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); diff --git a/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect b/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect index 6b712bae..fa8a9acc 100644 --- a/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect +++ b/tests/PhpGenerator/expected/PhpFile.globalNamespace.expect @@ -1,5 +1,7 @@