Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
7311e3a
PHP7 is not allowed to fail
Ocramius Jan 3, 2016
39a386b
Data-provider for simple type-hints
Ocramius Jan 3, 2016
bcf6223
zendframework/zend-code#29 - Testing simple hints syntax
Ocramius Jan 3, 2016
6faf241
zendframework/zend-code#29 - Explicitly setting php version boundaries
Ocramius Jan 3, 2016
4c9ae77
zendframework/zend-code#29 - Bumping PHPUnit version
Ocramius Jan 3, 2016
3a9ec67
zendframework/zend-code#29 - Adding scalar type-hints support
Ocramius Jan 3, 2016
e9ec0b7
zendframework/zend-code#29 - `mixed`, `object`, `resource` are all va…
Ocramius Jan 3, 2016
5c6ba37
zendframework/zend-code#29 - `mixed`, `object`, `resource` are all va…
Ocramius Jan 3, 2016
f599b31
zendframework/zend-code#29 - Enabling support for `mixed`, `object` a…
Ocramius Jan 3, 2016
1a87fc4
zendframework/zend-code#29 - Removing duplicate tests
Ocramius Jan 3, 2016
7fba25a
zendframework/zend-code#29 - Renaming `getType` to `detectType` to av…
Ocramius Jan 3, 2016
bdcff2d
zendframework/zend-code#29 - Test asset: class with internal type hints
Ocramius Jan 3, 2016
551b033
zendframework/zend-code#29 - Internal type hints should be reflected …
Ocramius Jan 3, 2016
5452dc1
zendframework/zend-code#29 - `fromReflection` should honor internal t…
Ocramius Jan 3, 2016
141a655
zendframework/zend-code#29 - Verifying that `getType` retrieves a `Re…
Ocramius Jan 3, 2016
b30dbfa
zendframework/zend-code#29 - Testing reflection of parameter type hints
Ocramius Jan 3, 2016
7695cdf
zendframework/zend-code#29 - test asset: class with class type hints
Ocramius Jan 3, 2016
e412f17
zendframework/zend-code#29 - correcting test incompatibility `getType…
Ocramius Jan 3, 2016
654394e
zendframework/zend-code#29 - simplifying logic to fetch built-in type…
Ocramius Jan 3, 2016
e375cc9
zendframework/zend-code#29 - additional tests for `self` and class ty…
Ocramius Jan 3, 2016
028d8ae
zendframework/zend-code#29 - correcting logic to copy a `ParameterGen…
Ocramius Jan 3, 2016
c753806
zendframework/zend-code#29 - test asset: a class with hints only in t…
Ocramius Jan 3, 2016
af88490
zendframework/zend-code#29 - testing against type-hints that are only…
Ocramius Jan 3, 2016
6321a7b
zendframework/zend-code#29 - docblock-hinted types should never retur…
Ocramius Jan 3, 2016
14577ff
zendframework/zend-code#29 - covering `detectType` with docblock-infe…
Ocramius Jan 3, 2016
624a033
zendframework/zend-code#29 - basic return type generator tests
Ocramius Jan 3, 2016
f5f0dd3
zendframework/zend-code#29 - expectation correction: `class_implement…
Ocramius Jan 3, 2016
02b4a43
zendframework/zend-code#29 - basic return type VO codegen assertions …
Ocramius Jan 3, 2016
e751242
zendframework/zend-code#29 - test expectation fixes (minor)
Ocramius Jan 3, 2016
ced58aa
zendframework/zend-code#29 - a simple `ReturnTypeGenerator` VO implem…
Ocramius Jan 3, 2016
7370c90
zendframework/zend-code#29 - invalid return types should be rejected
Ocramius Jan 3, 2016
100d17c
zendframework/zend-code#29 - rejecting return types that aren't consi…
Ocramius Jan 3, 2016
679e795
zendframework/zend-code#29 - a method generator should generate metho…
Ocramius Jan 3, 2016
c41ab50
zendframework/zend-code#29 - implemented return types in method gener…
Ocramius Jan 3, 2016
2164199
zendframework/zend-code#29 - return types should be mirrored from ref…
Ocramius Jan 3, 2016
01e7145
zendframework/zend-code#29 - respecting return types in the `MethodGe…
Ocramius Jan 3, 2016
07c0ae8
zendframework/zend-code#29 - stricter assertions on the format of gen…
Ocramius Jan 3, 2016
793a364
zendframework/zend-code#29 - committing test asset required for the r…
Ocramius Jan 3, 2016
b562237
zendframework/zend-code#29 - testing variadic signatures for the para…
Ocramius Jan 3, 2016
3dab68c
zendframework/zend-code#29 - test asset for variadic parameter signat…
Ocramius Jan 3, 2016
199ba26
zendframework/zend-code#29 - by-ref variadics are also a thing
Ocramius Jan 3, 2016
01cb8cb
zendframework/zend-code#29 - testing that variadics are actually work…
Ocramius Jan 3, 2016
a6e60ee
zendframework/zend-code#29 - testing simple variadic generation
Ocramius Jan 3, 2016
99f9a0d
zendframework/zend-code#29 - correcting alignment in expectations (PS…
Ocramius Jan 3, 2016
c9ef3ff
zendframework/zend-code#29 - implementing API to support variadic par…
Ocramius Jan 3, 2016
ad068f3
zendframework/zend-code#29 - making code PHP 5.5 compliant again
Ocramius Jan 3, 2016
77fc24b
zendframework/zend-code#29 - setting PHPUnit requirements for tests t…
Ocramius Jan 3, 2016
30f6626
zendframework/zend-code#29 - PHPUnit 4 can also work
Ocramius Jan 3, 2016
37d36b0
zendframework/zend-code#29 - Dropping strict types
Ocramius Jan 3, 2016
1d674bd
zendframework/zend-code#29 - CS (bracket alignment)
Ocramius Jan 3, 2016
ddeb6ff
zendframework/zend-code#29 - `null` return is a valid return
Ocramius Jan 3, 2016
ccbd1c7
zendframework/zend-code#29 - Removing return type hint from code
Ocramius Jan 3, 2016
3c456ec
zendframework/zend-code#29 - Removing return type hint from code
Ocramius Jan 3, 2016
b9a5929
zendframework/zend-code#29 - Removing return type hint from code
Ocramius Jan 3, 2016
6b5e694
zendframework/zend-code#29 - `getReturnType` is not defined below PHP…
Ocramius Jan 3, 2016
a168f50
zendframework/zend-code#29 - removing unsupported scalar type-hint
Ocramius Jan 4, 2016
853de9a
zendframework/zend-code#29 - downgrading to PHPUnit 4.x, since compos…
Ocramius Jan 4, 2016
8968b80
zendframework/zend-code#29 - methods should support by-reference return
Ocramius Jan 4, 2016
3868845
zendframework/zend-code#29 - test asset: class with a by-ref return m…
Ocramius Jan 4, 2016
64849bd
zendframework/zend-code#29 - should respect by-ref return of generate…
Ocramius Jan 4, 2016
1439ee5
zendframework/zend-code#29 - implemented API to generate by-ref methods
Ocramius Jan 4, 2016
8d879bd
zendframework/zend-code#29 - testing code generation of type hints ag…
Ocramius Jan 4, 2016
56d76d3
zendframework/zend-code#29 - imported classes should be generated wit…
Ocramius Jan 4, 2016
769c588
zendframework/zend-code#29 - types should be referenced by FQCN (with…
Ocramius Jan 4, 2016
5971358
zendframework/zend-code#29 - types should be known by FQCN in strings…
Ocramius Jan 4, 2016
8002379
zendframework/zend-code#29 - types are known by FQCN in strings, and …
Ocramius Jan 4, 2016
bad9f6b
zendframework/zend-code#29 - corrected test expectation: FQCN required
Ocramius Jan 4, 2016
a99f2c7
zendframework/zend-code#29 - `ReturnTypeGenerator` is actually just a…
Ocramius Jan 4, 2016
ff6f6ac
zendframework/zend-code#29 - `TypeGenerator` should just be a stringa…
Ocramius Jan 4, 2016
daaf732
zendframework/zend-code#29 - Implemented `TypeGenerator#__toString()`
Ocramius Jan 4, 2016
13670c2
zendframework/zend-code#29 - types prefixed with `\\` should also be …
Ocramius Jan 4, 2016
ab21ddf
zendframework/zend-code#29 - types prefixed with `\\` are allowed as …
Ocramius Jan 4, 2016
9c12764
zendframework/zend-code#29 - internal types, when prefixed with `\\`,…
Ocramius Jan 4, 2016
99fc9f3
zendframework/zend-code#29 - implementing `TypeGenerator` logic in su…
Ocramius Jan 4, 2016
e873412
zendframework/zend-code#29 - re-using internal state instead of re-co…
Ocramius Jan 4, 2016
910537f
zendframework/zend-code#29 - re-using the return type to avoid duplic…
Ocramius Jan 4, 2016
5e238ed
zendframework/zend-code#29 - re-using the return type to avoid duplic…
Ocramius Jan 4, 2016
76b82fe
zendframework/zend-code#29 - `TypeGenerator` should cast as string wi…
Ocramius Jan 4, 2016
5b400dc
zendframework/zend-code#29 - re-using `TypeGenerator` inside `Paramet…
Ocramius Jan 4, 2016
b107b78
zendframework/zend-code#29 - should fallback to `null` when unable to…
Ocramius Jan 4, 2016
640c678
zendframework/zend-code#29 - `"ext-phar"` is required to run tests ag…
Ocramius Jan 4, 2016
6a563ff
zendframework/zend-code#29 - lazily evaluating default parameters of …
Ocramius Jan 4, 2016
d80b789
zendframework/zend-code#29 - removing unused property
Ocramius Jan 4, 2016
b0a1c72
zendframework/zend-code#29 - removing unused type-hint
Ocramius Jan 4, 2016
d2a6a11
zendframework/zend-code#29 - polyfilling `detectType` support for anc…
Ocramius Jan 4, 2016
85c7812
zendframework/zend-code#29 - polyfilling `ParameterReflection` and `P…
Ocramius Jan 4, 2016
b0114f8
zendframework/zend-code#29 - s/boolean/bool (consistency), as per rev…
Ocramius Jan 5, 2016
1e06897
zendframework/zend-code#29 - correcting zendframework/zend-stdlib ref…
Ocramius Jan 5, 2016
8a26fda
zendframework/zend-code#29 - documenting changes in the CHANGELOG
Ocramius Jan 5, 2016
5e7bd96
zendframework/zend-code#29 - correcting namespacing in the changelog
Ocramius Jan 5, 2016
6e923df
zendframework/zend-code#29 - documenting rename of `Zend\Code\Reflect…
Ocramius Jan 5, 2016
ea1817f
zendframework/zend-code#29 - documenting BC break: class names are no…
Ocramius Jan 5, 2016
b3883de
zendframework/zend-code#29 - documenting upgrade notes - scalar type …
Ocramius Jan 5, 2016
f618e6d
zendframework/zend-code#29 - documenting upgrade notes - `tetType` wa…
Ocramius Jan 5, 2016
5e4fb9e
zendframework/zend-code#29 - documenting upgrade notes - `ParameterGe…
Ocramius Jan 5, 2016
780b2f5
zendframework/zend-code#29 - documenting upgrade notes - parameter/re…
Ocramius Jan 5, 2016
8a8ab45
zendframework/zend-code#29 - documenting upgrade notes - namespace se…
Ocramius Jan 5, 2016
b3fb30e
zendframework/zend-code#29 - documenting upgrade notes - `$simple` st…
Ocramius Jan 5, 2016
b7cbef9
zendframework/zend-code#29 - documenting upgrade notes - `$type` prot…
Ocramius Jan 5, 2016
ae152d0
zendframework/zend-code#29 - removing un-wanted scalar type hint from…
Ocramius Jan 5, 2016
aefbf04
zendframework/zend-code#29 - clarifying on how to filter out types wh…
Ocramius Jan 13, 2016
d3667c5
zendframework/zend-code#29 - clarifying why the change of `Zend\Code\…
Ocramius Jan 13, 2016
b004d95
zendframework/zend-code#29 - linking scalar type hints as per @weiero…
Ocramius Jan 13, 2016
3f3bdfc
zendframework/zend-code#29 - s/~/^ (consistency with other components)
Ocramius Jan 13, 2016
2f06164
zendframework/zend-code#29 - using `||` instead of `|` (deprecated)
Ocramius Jan 13, 2016
9acd1e6
zendframework/zend-code#29 - `develop` is `3.0-dev`
Ocramius Jan 13, 2016
61edb5b
zendframework/zend-code#29 - moving upgrade notes to the documentatio…
Ocramius Jan 13, 2016
b464169
zendframework/zend-code#29 - more specific upgrade notes file name/ti…
Ocramius Jan 13, 2016
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ $config->fixers(
'braces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'function_call_space',
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ matrix:
- php: 7
- php: hhvm
allow_failures:
- php: 7
- php: hhvm

notifications:
Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,52 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 3.0.0 - TBD

### Changed

This section refers to breaking changes: please refer to
[doc/book/zend.code.migrate.2.to.3.md](doc/book/zend.code.migrate.2.to.3.md) for migration instructions.

- Types `string`, `int`, `float`, `bool` passed to `Zend\Code\Generator\ParameterGenerator#setType()`
are no longer ignored in generated code [#30](https://github.com/zendframework/zend-code/pull/30)
- Types declared in DocBlocks are now ignored when creating a `Zend\Code\Generator\ParameterGenerator` via
`Zend\Code\Generator\ParameterGenerator::fromReflection()`. [#30](https://github.com/zendframework/zend-code/pull/30)
- Type strings are now validated: passing an invalid type to any method in the generator API
may lead to a `Zend\Code\Generator\InvalidArgumentException` being thrown.
[#30](https://github.com/zendframework/zend-code/pull/30)
- `Zend\Code\Generator\ParameterGenerator::$simple` was removed. [#30](https://github.com/zendframework/zend-code/pull/30)
- `Zend\Code\Generator\ParameterGenerator#$type` is now a `null|Zend\Code\Generator\TypeGenerator`: was a
`string` before. [#30](https://github.com/zendframework/zend-code/pull/30)
- `Zend\Code\Generator` type-hints are now always prefixed with the namespace separator `\`.
[#30](https://github.com/zendframework/zend-code/pull/30)
- `Zend\Code\Reflection\ParameterReflection#getType()` was renamed
to `Zend\Code\Reflection\ParameterReflection#detectType()` in order to not override the inherited
`ReflectionParameter#getType()`, introduced in PHP 7. [#30](https://github.com/zendframework/zend-code/pull/30)

### Added

- PHP 7 return type hints generation support via `Zend\Code\Generator\MethodGenerator#setReturnType()`.
[#30](https://github.com/zendframework/zend-code/pull/30)
- PHP 7 scalar type hints generation support via `Zend\Code\Generator\ParameterGenerator#setType()` and
`Zend\Code\Generator\ParameterGenerator#getType()`. [#30](https://github.com/zendframework/zend-code/pull/30)
- PHP 5.6 variadic arguments support via `Zend\Code\Generator\ParameterGenerator#setVariadic()` and
`Zend\Code\Generator\ParameterGenerator#getVariadic()`. [#30](https://github.com/zendframework/zend-code/pull/30)
- Generation of methods returning by reference is supported via `Zend\Code\Generator\ParameterGenerator#setReturnsReference()`.
[#30](https://github.com/zendframework/zend-code/pull/30)

### Deprecated

- Nothing.

### Removed

- `Zend\Code\ParameterGenerator::$simple` was removed. [#30](https://github.com/zendframework/zend-code/pull/30)

### Fixed

- Nothing.

## 2.7.0 - TBD

### Added
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
}
},
"require": {
"php": ">=5.5",
"php": "^5.5 || ^7.0",
"zendframework/zend-eventmanager": "^2.6|^3.0"
},
"require-dev": {
"ext-phar": "*",
"doctrine/annotations": "~1.0",
"zendframework/zend-stdlib": "~2.7",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "^4.8.21"
},
"suggest": {
"doctrine/annotations": "Doctrine\\Common\\Annotations >=1.0 for annotation features",
Expand All @@ -31,7 +32,7 @@
"extra": {
"branch-alias": {
"dev-master": "2.6-dev",
"dev-develop": "2.7-dev"
"dev-develop": "3.0-dev"
}
},
"autoload-dev": {
Expand Down
131 changes: 131 additions & 0 deletions doc/book/zend.code.migrate.2.to.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Migrating from `Zend\Code` `2.*` to `3.0.0`

### `string`, `int`, `float`, `bool` are no longer ignored

In 2.x, a `Zend\Code\Generator\ParameterGenerator` with name `foo` and type
`string`, `int`, `float` or `bool` simply generated code `"$foo"`:

```php
$generator = new \Zend\Code\ParameterGenerator('foo');

$generator->setType('string');

echo $generator->generate(); // "$foo"
```

In 3.x, this code will instead produce `"string $foo"`.
If you generate code that should run in PHP 5.x, it is advisable to strip
`string`, `int`, `float` and `bool` from type definitions passed to
`Zend\Code\ParameterGenerator` instances. The quickest way is to set the
type to `null`, if it matches any of these scalar types:

```php
if (in_array($type, ['string', 'int', 'float', 'bool'])) {
$type = null;
}

$generator->setType($type);
```

### `Zend\Code\Reflection\ParameterReflection#getType()` changes

PHP 7 introduced [`ReflectionParameter#getType()`](http://php.net/manual/en/reflectionparameter.gettype.php).

In order to not override this method, `Zend\Code\Reflection\ParameterReflection#getType()`
was renamed to `Zend\Code\Reflection\ParameterReflection#detectType()`.

If you relied on `Zend\Code\Reflection\ParameterReflection#getType()`, you can
simply replace the method calls in your code.

### DocBlock types ignored by `Zend\Code\Generator\ParameterGenerator::fromReflection()`

As a direct consequence of the previous change, calls to
`Zend\Code\Generator\ParameterGenerator::fromReflection()` will not mirror the
type hints read from a method's DocBlock.

As an example, take following code:

```php
class Foo
{
/**
* @param string $baz
*/
public function bar($baz)
{
}
}

$methodGenerator = \Zend\Code\Generator\MethodGenerator::fromReflection(
new \Zend\Code\Reflection\MethodReflection('Foo', 'bar')
);

var_dump($methodGenerator->getParameters()[0]->getType());
```

In version 2.x, this code produces `"string"`, in version 3.x it returns `null`. If you
need to rely on the types in the annotations, please use
`Zend\Code\Reflection\ParameterReflection#detectType()` instead, and build a
`MethodGenerator` instance manually.

This change is required: since signatures in PHP 7 include scalar type hints.
That also means that reflecting scalar type hints from DocBlocks into the
signature of a generated method may lead to fatal errors (due to signature
mismatch) at runtime.

### Type strings are validated

If you attempt to generate type-hints for parameters or return types, those types are
now validated before the code is generated.

Be sure to check which values you pass to `Zend\Code\Generator\MethodGenerator#setReturnType()`
or `Zend\Code\Generator\ParameterGenerator#setType()`, as you may incur in a
`Zend\Code\Generator\Exception\InvalidArgumentException` being thrown if any
of those types are invalid strings:

```php
$parameterGenerator->setType('foo'); // valid
$parameterGenerator->setType('array'); // valid
$parameterGenerator->setType('bool'); // valid
$parameterGenerator->setType('123'); // invalid (throws exception)
$parameterGenerator->setType(''); // invalid (throws exception)
$parameterGenerator->setType('*'); // invalid (throws exception)
$parameterGenerator->setType('\\'); // invalid (throws exception)
```


### Generated type-hints are now prefixed by `"\"`

Generated type-hints are now prefixed with the `NAMESPACE_SEPARATOR`,
`"\"`.

Take following example code:

```php
$parameter = new \Zend\Code\Generator\ParameterGenerator('bar', 'baz');
$method = new \Zend\Code\Generator\MethodGenerator('foo', [$parameter]);

$method->setReturnType('tab');

echo $method->generate();
```

This code produces `public function foo(baz $bar) {}` in 2.x.
In version 3.x, it produces `public function foo(\baz $bar) : \tab {}`.

In order to avoid migration problems, be sure to always pass fully qualified class
names to `Zend\Code\Generator\MethodGenerator` and `Zend\Code\Generator\ParameterGenerator`.


### `Zend\Code\Generator\ParameterGenerator::$simple` was removed

If you extended `Zend\Code\Generator\ParameterGenerator`, be sure to check if you
are accessing the protected static variable `$simple`: it was removed, and you should
adapt your code by either copying it into your class or avoiding its usage.

### `Zend\Code\Generator\ParameterGenerator::$type` has changed

If you extended `Zend\Code\Generator\ParameterGenerator`, be sure to check if you
are accessing the protected variable `$type`: its type has changed.
While it can still be used as a string via an explicit `(string)` cast, the type of
this protected member is now `null|Zend\Code\Generator\TypeGenerator`.
3 changes: 2 additions & 1 deletion doc/bookdown.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"content": [
"book/zend.code.generator.introduction.md",
"book/zend.code.generator.reference.md",
"book/zend.code.generator.examples.md"
"book/zend.code.generator.examples.md",
"book/zend.code.migrate.2.to.3.md"
]
}
71 changes: 69 additions & 2 deletions src/Generator/MethodGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ class MethodGenerator extends AbstractMemberGenerator
*/
protected $body = null;

/**
* @var null|TypeGenerator
*/
private $returnType;

/**
* @var bool
*/
private $returnsReference = false;

/**
* @param MethodReflection $reflectionMethod
* @return MethodGenerator
Expand All @@ -39,6 +49,7 @@ public static function fromReflection(MethodReflection $reflectionMethod)

$method->setSourceContent($reflectionMethod->getContents(false));
$method->setSourceDirty(false);
$method->setReturnType(self::extractReturnTypeFromMethodReflection($reflectionMethod));

if ($reflectionMethod->getDocComment() != '') {
$method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock()));
Expand All @@ -56,7 +67,7 @@ public static function fromReflection(MethodReflection $reflectionMethod)

$method->setInterface($declaringClass->isInterface());
$method->setStatic($reflectionMethod->isStatic());

$method->setReturnsReference($reflectionMethod->returnsReference());
$method->setName($reflectionMethod->getName());

foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
Expand Down Expand Up @@ -258,6 +269,32 @@ public function getBody()
return $this->body;
}

/**
* @param string|null
*
* @return MethodGenerator
*/
public function setReturnType($returnType = null)
{
$this->returnType = null === $returnType
? null
: TypeGenerator::fromTypeString($returnType);

return $this;
}

/**
* @param bool $returnsReference
*
* @return MethodGenerator
*/
public function setReturnsReference($returnsReference)
{
$this->returnsReference = (bool) $returnsReference;

return $this;
}

/**
* @return string
*/
Expand All @@ -282,7 +319,9 @@ public function generate()

$output .= $this->getVisibility()
. (($this->isStatic()) ? ' static' : '')
. ' function ' . $this->getName() . '(';
. ' function '
. ($this->returnsReference ? '& ' : '')
. $this->getName() . '(';

$parameters = $this->getParameters();
if (!empty($parameters)) {
Expand All @@ -295,6 +334,10 @@ public function generate()

$output .= ')';

if ($this->returnType) {
$output .= ' : ' . $this->returnType->generate();
}

if ($this->isAbstract()) {
return $output . ';';
}
Expand All @@ -319,4 +362,28 @@ public function __toString()
{
return $this->generate();
}

/**
* @param MethodReflection $methodReflection
*
* @return null|string
*/
private static function extractReturnTypeFromMethodReflection(MethodReflection $methodReflection)
{
$returnType = method_exists($methodReflection, 'getReturnType')
? $methodReflection->getReturnType()
: null;

if (! $returnType) {
return null;
}

$returnTypeString = (string) $returnType;

if ('self' === strtolower($returnType)) {
return $methodReflection->getDeclaringClass()->getName();
}

return $returnTypeString;
}
}
Loading