diff --git a/composer.json b/composer.json index 1ec62f4..7c2e4e9 100644 --- a/composer.json +++ b/composer.json @@ -6,5 +6,10 @@ "psr-4": { "Krlove\\CodeGenerator\\": "src/" } - } -} \ No newline at end of file + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/src/Model/ArgumentModel.php b/src/Model/ArgumentModel.php index b9ab551..7e19b02 100644 --- a/src/Model/ArgumentModel.php +++ b/src/Model/ArgumentModel.php @@ -29,7 +29,7 @@ class ArgumentModel extends RenderableModel * ArgumentModel constructor. * @param string $name * @param string|null $type - * @param mixed|null $default + * @param mixed|null $default used "as is" */ public function __construct($name, $type = null, $default = null) { @@ -43,11 +43,12 @@ public function __construct($name, $type = null, $default = null) */ public function toLines() { - if ($this->type !== null) { - return $this->type . ' $' . $this->name; - } else { + if ($this->default !== null) { + return ltrim($this->type?:'' . ' $' . $this->name. ' = ' .$this->default); + } else { return '$' . $this->name; - } + return ltrim($this->type?:'' . ' $' . $this->name); + } } /** diff --git a/src/Model/UseClassModel.php b/src/Model/UseClassModel.php index 09a91f1..7ec4dc1 100644 --- a/src/Model/UseClassModel.php +++ b/src/Model/UseClassModel.php @@ -14,14 +14,19 @@ class UseClassModel extends RenderableModel * @var string */ protected $name; + /** + * @var string + */ + protected $alias=null; /** * PHPClassUse constructor. * @param string $name */ - public function __construct($name) + public function __construct($name,$alias=null) { $this->name = $name; + if ($alias) $this->alias=$alias; } /** @@ -29,7 +34,12 @@ public function __construct($name) */ public function toLines() { - return sprintf('use %s;', $this->name); + if (is_null($this->alias)) { + return sprintf('use %s;', $this->name); + } + else { + return sprintf('use %s as %s;', $this->name,$this->alias); + } } /** @@ -40,6 +50,14 @@ public function getName() return $this->name; } + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + /** * @param string $name * @@ -51,4 +69,16 @@ public function setName($name) return $this; } + + /** + * @param string $alias + * + * @return $this + */ + public function setAlias($alias) + { + $this->alias = $alias; + + return $this; + } }