diff --git a/readme.md b/readme.md index 0bd8841a..22d186b6 100644 --- a/readme.md +++ b/readme.md @@ -7,19 +7,33 @@ Nette PHP Generator [![Latest Stable Version](https://poser.pugx.org/nette/php-generator/v/stable)](https://github.com/nette/php-generator/releases) [![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/php-generator/blob/master/license.md) + +Introduction +------------ + Generate PHP code, classes, namespaces etc. with a simple programmatical API. -Usage is very easy. Install it using Composer: +Documentation can be found on the [website](https://doc.nette.org/php-generator). + + +Installation +------------ + +The recommended way to install is via Composer: ``` composer require nette/php-generator ``` -The last stable release requires PHP version 5.6 or newer (is compatible with PHP 7.0 and 7.1). The dev-master version requires PHP 7.0. +- v2.6 requires PHP 5.6 or newer (is compatible up to 7.2) +- v3.0 requires PHP 7.0 or newer (is compatible up to 7.2) +- v3.1 requires PHP 7.1 or newer (is compatible up to 7.2) -Examples --------- +Usage +----- + +Usage is very easy. Let's start with a straightforward example of generating class: ```php $class = new Nette\PhpGenerator\ClassType('Demo'); diff --git a/src/PhpGenerator/ClassType.php b/src/PhpGenerator/ClassType.php index a5952cf5..eef9c227 100644 --- a/src/PhpGenerator/ClassType.php +++ b/src/PhpGenerator/ClassType.php @@ -51,7 +51,7 @@ final class ClassType /** @var string[] */ private $implements = []; - /** @var string[] */ + /** @var array[] */ private $traits = []; /** @var Constant[] name => Constant */ @@ -65,7 +65,7 @@ final class ClassType /** - * @param string|object + * @param string|object $class * @return static */ public static function from($class): self @@ -141,7 +141,7 @@ public function getNamespace() /** - * @param string|null + * @param string|null $name * @return static */ public function setName($name): self @@ -215,7 +215,7 @@ public function isAbstract(): bool /** - * @param string|string[] + * @param string|string[] $names * @return static */ public function setExtends($names): self @@ -251,7 +251,7 @@ public function addExtend(string $name): self /** - * @param string[] + * @param string[] $names * @return static */ public function setImplements(array $names): self @@ -283,7 +283,7 @@ public function addImplement(string $name): self /** - * @param string[] + * @param string[] $names * @return static */ public function setTraits(array $names): self @@ -348,7 +348,7 @@ public function addConst(string $name, $value): self /** - * @param Constant[]|mixed[] + * @param Constant[]|mixed[] $consts * @return static */ public function setConstants(array $consts): self @@ -378,7 +378,7 @@ public function addConstant(string $name, $value): Constant /** - * @param Property[] + * @param Property[] $props * @return static */ public function setProperties(array $props): self @@ -403,7 +403,7 @@ public function getProperties(): array } - public function getProperty($name): Property + public function getProperty(string $name): Property { if (!isset($this->properties[$name])) { throw new Nette\InvalidArgumentException("Property '$name' not found."); @@ -413,7 +413,7 @@ public function getProperty($name): Property /** - * @param string without $ + * @param string $name without $ */ public function addProperty(string $name, $value = null): Property { @@ -422,7 +422,7 @@ public function addProperty(string $name, $value = null): Property /** - * @param Method[] + * @param Method[] $methods * @return static */ public function setMethods(array $methods): self @@ -447,7 +447,7 @@ public function getMethods(): array } - public function getMethod($name): Method + public function getMethod(string $name): Method { if (!isset($this->methods[$name])) { throw new Nette\InvalidArgumentException("Method '$name' not found."); diff --git a/src/PhpGenerator/Closure.php b/src/PhpGenerator/Closure.php index a8f413fa..20e0697a 100644 --- a/src/PhpGenerator/Closure.php +++ b/src/PhpGenerator/Closure.php @@ -51,7 +51,7 @@ public function __toString(): string /** - * @param Parameter[] + * @param Parameter[] $uses * @return static */ public function setUses(array $uses): self @@ -68,7 +68,7 @@ public function getUses(): array } - public function addUse($name): Parameter + public function addUse(string $name): Parameter { return $this->uses[] = new Parameter($name); } diff --git a/src/PhpGenerator/Method.php b/src/PhpGenerator/Method.php index 45432ba9..92559c40 100644 --- a/src/PhpGenerator/Method.php +++ b/src/PhpGenerator/Method.php @@ -39,6 +39,7 @@ final class Method /** + * @param string|array $method * @return static */ public static function from($method): self @@ -80,7 +81,7 @@ public function __toString(): string /** - * @param string|null + * @param string|null $code * @return static */ public function setBody($code, array $args = null): self @@ -89,7 +90,7 @@ public function setBody($code, array $args = null): self $code = null; trigger_error(__METHOD__ . '() use null instead of false', E_USER_DEPRECATED); } - $this->body = $args === null ? $code : Helpers::formatArgs($code, $args); + $this->body = $args === null || $code === null ? $code : Helpers::formatArgs($code, $args); return $this; } diff --git a/src/PhpGenerator/Parameter.php b/src/PhpGenerator/Parameter.php index a1de0da4..48d2bf86 100644 --- a/src/PhpGenerator/Parameter.php +++ b/src/PhpGenerator/Parameter.php @@ -55,7 +55,7 @@ public function isReference(): bool /** - * @param string|null + * @param string|null $hint * @return static */ public function setTypeHint($hint): self diff --git a/src/PhpGenerator/Traits/CommentAware.php b/src/PhpGenerator/Traits/CommentAware.php index 714e0592..57d81584 100644 --- a/src/PhpGenerator/Traits/CommentAware.php +++ b/src/PhpGenerator/Traits/CommentAware.php @@ -20,7 +20,7 @@ trait CommentAware /** - * @param string|null + * @param string|null $val * @return static */ public function setComment($val): self diff --git a/src/PhpGenerator/Traits/FunctionLike.php b/src/PhpGenerator/Traits/FunctionLike.php index ad9f8954..17d33d83 100644 --- a/src/PhpGenerator/Traits/FunctionLike.php +++ b/src/PhpGenerator/Traits/FunctionLike.php @@ -69,7 +69,7 @@ public function addBody(string $code, array $args = null): self /** - * @param Parameter[] + * @param Parameter[] $val * @return static */ public function setParameters(array $val): self @@ -95,7 +95,7 @@ public function getParameters(): array /** - * @param string without $ + * @param string $name without $ */ public function addParameter(string $name, $defaultValue = null): Parameter { @@ -124,7 +124,7 @@ public function isVariadic(): bool /** - * @param string|null + * @param string|null $val * @return static */ public function setReturnType($val): self diff --git a/src/PhpGenerator/Traits/VisibilityAware.php b/src/PhpGenerator/Traits/VisibilityAware.php index d7a41e1c..78bc6215 100644 --- a/src/PhpGenerator/Traits/VisibilityAware.php +++ b/src/PhpGenerator/Traits/VisibilityAware.php @@ -22,7 +22,7 @@ trait VisibilityAware /** - * @param string|null public|protected|private + * @param string|null $val public|protected|private * @return static */ public function setVisibility($val): self