Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - #241 - support scalar type hints #271

Merged
merged 30 commits into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
76f8f52
Class assets for scalar type hiting tests
Apr 9, 2015
30a2ac5
Simple test for params using scalar type hinting
Apr 9, 2015
cd1ebe2
Fix comparation to run tests on php7 build
Apr 9, 2015
d616c9e
#241 - minor grammar fix: class rename
Ocramius Jan 4, 2016
97a7ad1
#241 - scalar type hinted classes should also be generated without cl…
Ocramius Jan 4, 2016
f0907ce
#241 - test asset: interface with scalar type hints
Ocramius Jan 4, 2016
d4dbe38
#241 - removing reliance on `returnsReference` (using generated code …
Ocramius Jan 4, 2016
ab8ce44
#241 - removing `MethodGenerator` boilerplate
Ocramius Jan 4, 2016
3678706
#241 - removing `ParameterGenerator` boilerplate
Ocramius Jan 4, 2016
424112a
#241 - relying on `Zend\Code`'s API instead of custom extended API
Ocramius Jan 4, 2016
72f3e3d
#241 - removing deprecated tests
Ocramius Jan 4, 2016
417f4b6
#241 #271 - test asset: interface with defined return types
Ocramius Jan 4, 2016
36d038d
#241 #271 - test asset: class with defined return types
Ocramius Jan 4, 2016
4b8da45
#241 #271 - should also generate classes with return type hints (any …
Ocramius Jan 4, 2016
5ba32d1
#241 #271 - s/interface/class for the class test asset
Ocramius Jan 4, 2016
1b4bcf9
#241 #271 - proxying also classes and interfaces with return type hints
Ocramius Jan 4, 2016
96f66cb
#241 #271 - relying on zendframework/zend-code dev branch (for now)
Ocramius Jan 4, 2016
31f2162
#241 #271 - no need to test PHP 5.x anymore
Ocramius Jan 4, 2016
dabc0e4
#241 #271 - upgrading requirement to support PHP 7 only
Ocramius Jan 4, 2016
64e35f8
#241 #271 - coverage can be generated in 7.0 as well
Ocramius Jan 4, 2016
888194d
#241 #271 - couscous docs can be generated in 7.0 as well
Ocramius Jan 4, 2016
648a4ca
#241 #271 - correcting PHP version, for more specificity
Ocramius Jan 4, 2016
7b93ab9
#241 #271 - removing PHP4 constructor compat tests: they should not b…
Ocramius Jan 4, 2016
96b006f
#241 #271 - removing checks against PHP < 7 versions
Ocramius Jan 4, 2016
0a0c83d
#241 #271 - removing unused import, relaxing requirements
Ocramius Jan 4, 2016
ebab097
#241 #271 - simplifying assertions, removing XDebug dumps, as they ke…
Ocramius Jan 4, 2016
ccacad9
#241 #271 - removing usage of our custom `ParameterGenerator` where p…
Ocramius Jan 4, 2016
a05be37
#241 #271 - dropping our custom `ParameterGenerator` tests
Ocramius Jan 4, 2016
e0a8b68
#241 #271 - dropping our custom `ParameterGenerator`
Ocramius Jan 4, 2016
ed2682b
#241 #271 - relying on zend-code 3.x
Ocramius Jan 13, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.coverage.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set -x
if [ "$TRAVIS_PHP_VERSION" = '5.6' ] ; then
if [ "$TRAVIS_PHP_VERSION" = '7.0' ] ; then
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover ./clover.xml
fi
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ language: php
sudo: false

php:
- 5.6
- 7
- 7.0
- hhvm

env:
Expand All @@ -29,4 +28,4 @@ matrix:

after_script:
- sh .travis.coverage.sh
- ./vendor/bin/couscous travis-auto-deploy --php-version=5.6
- ./vendor/bin/couscous travis-auto-deploy --php-version=7.0
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
}
],
"require": {
"php": "~5.6|~7.0",
"zendframework/zend-code": "^2.6.1"
"php": "~7.0",
"zendframework/zend-code": "dev-feature/php7-compliance@DEV"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fixed before merging

},
"require-dev": {
"ext-phar": "*",
Expand Down
121 changes: 2 additions & 119 deletions src/ProxyManager/Generator/MethodGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,131 +31,14 @@
class MethodGenerator extends ZendMethodGenerator
{
/**
* @var bool
*/
protected $returnsReference = false;

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

/**
* @return boolean
*/
public function returnsReference()
{
return $this->returnsReference;
}

/**
* @override enforces generation of \ProxyManager\Generator\MethodGenerator
*
* {@inheritDoc}
*/
public static function fromReflection(MethodReflection $reflectionMethod)
{
/* @var $method self */
$method = new static();
$method = parent::fromReflection($reflectionMethod);

$method->setSourceContent($reflectionMethod->getContents(false));
$method->setSourceDirty(false);

if ($reflectionMethod->getDocComment() != '') {
$method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock()));
}

$method->setFinal($reflectionMethod->isFinal());
$method->setVisibility(self::extractVisibility($reflectionMethod));

foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
$method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
}

$method->setStatic($reflectionMethod->isStatic());
$method->setName($reflectionMethod->getName());
$method->setBody($reflectionMethod->getBody());
$method->setReturnsReference($reflectionMethod->returnsReference());
$method->setInterface(false);

return $method;
}

/**
* Retrieves the visibility for the given method reflection
*
* @param MethodReflection $reflectionMethod
*
* @return string
*/
private static function extractVisibility(MethodReflection $reflectionMethod)
{
if ($reflectionMethod->isPrivate()) {
return static::VISIBILITY_PRIVATE;
}

if ($reflectionMethod->isProtected()) {
return static::VISIBILITY_PROTECTED;
}

return static::VISIBILITY_PUBLIC;
}

/**
* @override fixes by-reference return value in zf2's method generator
*
* {@inheritDoc}
*/
public function generate()
{
$output = '';
$indent = $this->getIndentation();

if (null !== ($docBlock = $this->getDocBlock())) {
$docBlock->setIndentation($indent);

$output .= $docBlock->generate();
}

$output .= $indent . $this->generateMethodDeclaration() . self::LINE_FEED . $indent . '{' . self::LINE_FEED;

if ($this->body) {
$output .= preg_replace('#^(.+?)$#m', $indent . $indent . '$1', trim($this->body))
. self::LINE_FEED;
}

$output .= $indent . '}' . self::LINE_FEED;

return $output;
}

/**
* @return string
*/
private function generateMethodDeclaration()
{
$output = $this->generateVisibility()
. ' function '
. (($this->returnsReference()) ? '& ' : '')
. $this->getName() . '(';

$parameterOutput = [];

foreach ($this->getParameters() as $parameter) {
$parameterOutput[] = $parameter->generate();
}

return $output . implode(', ', $parameterOutput) . ')';
}

/**
* @return string
*/
private function generateVisibility()
{
return $this->isAbstract() ? 'abstract ' : (($this->isFinal()) ? 'final ' : '')
. ($this->getVisibility() . (($this->isStatic()) ? ' static' : ''));
}
}
188 changes: 0 additions & 188 deletions src/ProxyManager/Generator/ParameterGenerator.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use Closure;
use ProxyManager\Generator\MethodGenerator;
use ProxyManager\Generator\ParameterGenerator;
use Zend\Code\Generator\ParameterGenerator;
use Zend\Code\Generator\PropertyGenerator;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use Closure;
use ProxyManager\Generator\MethodGenerator;
use ProxyManager\Generator\ParameterGenerator;
use Zend\Code\Generator\ParameterGenerator;
use Zend\Code\Generator\PropertyGenerator;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;

use ProxyManager\Generator\MethodGenerator;
use ProxyManager\Generator\ParameterGenerator;
use Zend\Code\Generator\ParameterGenerator;
use ProxyManager\ProxyGenerator\Util\Properties;
use ReflectionClass;
use Zend\Code\Generator\PropertyGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;

use ProxyManager\Generator\MagicMethodGenerator;
use ProxyManager\Generator\ParameterGenerator;
use Zend\Code\Generator\ParameterGenerator;
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\Util\InterceptorGenerator;
use ProxyManager\ProxyGenerator\Util\PublicScopeSimulator;
use ReflectionClass;
Expand Down
Loading