Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MethodGenerationHelper | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createMethod | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace quintenmbusiness\PhpAstCodeGenerationHelper\GeneratorHelpers; |
| 6 | |
| 7 | use PhpParser\Builder\Method; |
| 8 | use PhpParser\BuilderFactory; |
| 9 | use PhpParser\Node\ComplexType; |
| 10 | use PhpParser\Node\Identifier; |
| 11 | use PhpParser\Node\Name; |
| 12 | |
| 13 | class MethodGenerationHelper extends VariableGenerationHelper |
| 14 | { |
| 15 | /** |
| 16 | * @param BuilderFactory $factory |
| 17 | */ |
| 18 | public function __construct(BuilderFactory $factory) |
| 19 | { |
| 20 | parent::__construct($factory); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param string $name |
| 25 | * @param string $visibility |
| 26 | * @param ComplexType|Identifier|Name|string|null $type |
| 27 | * @return Method |
| 28 | */ |
| 29 | public function createMethod(string $name, string $visibility = 'public', ComplexType|Identifier|Name|string $type = null): Method |
| 30 | { |
| 31 | $method = new Method($name); |
| 32 | |
| 33 | $this->addVisibility($method, $visibility); |
| 34 | |
| 35 | if ($type !== null) { |
| 36 | $method->setReturnType($type); |
| 37 | } |
| 38 | |
| 39 | return $method; |
| 40 | } |
| 41 | } |