Skip to content

Commit

Permalink
Merge b832d35 into 1ac78a8
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Aug 19, 2013
2 parents 1ac78a8 + b832d35 commit 8b596e0
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 24 deletions.
39 changes: 39 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
before_commands:
- "composer install --no-dev --prefer-source"

tools:
php_code_coverage:
enabled: true
test_command: phpunit -c phpunit.xml.dist --exclude-group Functional,Performance
#filter:
#paths: ["src"]
php_code_sniffer:
enabled: true
config:
standard: PSR2
filter:
paths: ["src/*", "tests/*"]
php_cpd:
enabled: true
excluded_dirs: ["build/*", "docs", "examples", "tests", "vendor"]
php_cs_fixer:
enabled: true
config:
level: all
filter:
paths: ["src/*", "tests/*"]
php_loc:
enabled: true
excluded_dirs: ["build", "docs", "examples", "tests", "vendor"]
php_mess_detector:
enabled: true
filter:
paths: ["src/*"]
php_pdepend:
enabled: true
excluded_dirs: ["build", "docs", "examples", "tests", "vendor"]
php_analyzer: true
php_analyzer:
filter:
paths: ["src/*", "tests/*", "examples/*"]
sensiolabs_security_checker: true
51 changes: 27 additions & 24 deletions src/ProxyManager/Generator/MethodGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,40 +108,43 @@ public function generate()
$output .= $docBlock->generate();
}

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

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

$output .= $this->getVisibility()
. (($this->isStatic()) ? ' static' : '')
$output .= $indent . '}' . self::LINE_FEED;

return $output;
}

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

if (!empty($parameters)) {
$parameterOutput = array();

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

$output .= implode(', ', $parameterOutput);
foreach ($this->getParameters() as $parameter) {
$parameterOutput[] = $parameter->generate();
}

$output .= ')' . 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 . implode(', ', $parameterOutput) . ')';
}

return $output;
/**
* @return string
*/
private function generateVisibility()
{
return $this->isAbstract() ? 'abstract ' : (($this->isFinal()) ? 'final ' : '')
. ($this->getVisibility() . (($this->isStatic()) ? ' static' : ''));
}
}
49 changes: 49 additions & 0 deletions tests/ProxyManagerTest/Generator/MethodGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ProxyManagerTest\Generator;

use PHPUnit_Framework_TestCase;
use ProxyManager\Generator\MethodGenerator;

/**
* Tests for {@see \ProxyManager\Generator\MethodGenerator}
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*
* @covers \ProxyManager\Generator\MethodGenerator
*/
class MethodGeneratorTest extends PHPUnit_Framework_TestCase
{
public function testGenerateSimpleMethod()
{
$methodGenerator = new MethodGenerator();

$methodGenerator->setReturnsReference(true);
$methodGenerator->setName('methodName');
$methodGenerator->setVisibility('protected');
$methodGenerator->setBody('/* body */');

$this->assertSame(true, $methodGenerator->returnsReference());
$this->assertStringMatchesFormat(
'%aprotected function & methodName()%a{%a/* body */%a}',
$methodGenerator->generate()
);
}
}

0 comments on commit 8b596e0

Please sign in to comment.