Skip to content

Commit

Permalink
PSR compliance (fixes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Jan 12, 2013
1 parent 2f35f04 commit 92f165f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class MyDocument
$this->filename = $filename;
}

public function getContents() {
public function getContents()
{
return file_get_contents($this->filename);
}

Expand All @@ -59,12 +60,14 @@ use Icecave\Isolator\Isolator;

class MyDocument
{
public function __construct($filename, Isolator $isolator = NULL) {
public function __construct($filename, Isolator $isolator = NULL)
{
$this->filename = $filename;
$this->isolator = Isolator::get($isolator);
}

public function getContents() {
public function getContents()
{
return $this->isolator->file_get_contents($this->filename);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Icecave/Isolator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use ReflectionClass;
use ReflectionFunction;
use ReflectionParameter;

/**
* Generates an isolator that can accommodate calls to functions with reference parameters.
Expand Down Expand Up @@ -45,7 +44,7 @@ public function requiresIsolatorProxy(ReflectionFunction $reflector)
{
if ($reflector->isDisabled()) {
return FALSE;
} else if ($reflector->returnsReference()) {
} elseif ($reflector->returnsReference()) {
return TRUE;
}

Expand Down Expand Up @@ -92,6 +91,7 @@ public function generateProxyMethod(ReflectionFunction $reflector)
$code .= $this->generateReturn($name, $maxArity);
$code .= '} // End function ' . $name . '.' . PHP_EOL;
$code .= PHP_EOL;

return $code;
}

Expand Down
16 changes: 11 additions & 5 deletions lib/Icecave/Isolator/Isolator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Isolator
* - require
* - require_once
*
* @param string $name The name of the global function to call.
* @param array $arguments The arguments to the function.
* @param string $name The name of the global function to call.
* @param array $arguments The arguments to the function.
*
* @return mixed The result of the function call.
*/
Expand All @@ -33,20 +33,25 @@ public function __call($name, array $arguments)
// @codeCoverageIgnoreEnd
case 'echo':
echo current($arguments);

return;
case 'eval':
return eval(current($arguments));
case 'include':
include current($arguments);

return;
case 'include_once':
include_once current($arguments);

return;
case 'require':
require current($arguments);

return;
case 'require_once':
require_once current($arguments);

return;
default:

Expand Down Expand Up @@ -76,9 +81,9 @@ public static function get(Isolator $instance = NULL)
/**
* Fetch the default isolator instance, constructing it if necessary.
*
* @param boolean $handleReferences Indicates whether or not the isolator should account for functions with reference parameters and return types.
* @param Generator|NULL $generator The Generator instance to use to construct the concreate isolator class, or NULL to use the default.
* @param Isolator|NULL $isolator The isolator used to access the global list of functions, or NULL to use the default.
* @param boolean $handleReferences Indicates whether or not the isolator should account for functions with reference parameters and return types.
* @param Generator|NULL $generator The Generator instance to use to construct the concreate isolator class, or NULL to use the default.
* @param Isolator|NULL $isolator The isolator used to access the global list of functions, or NULL to use the default.
*/
public static function getIsolator($handleReferences = TRUE, Generator $generator = NULL, Isolator $isolator = NULL)
{
Expand Down Expand Up @@ -112,6 +117,7 @@ public static function getIsolator($handleReferences = TRUE, Generator $generato

// Generate the concrete isolator class and install it as the global instance ...
$classReflector = $generator->generateClass($functionReflectors);

return self::$instance = $classReflector->newInstance();
}

Expand Down
36 changes: 22 additions & 14 deletions test/suite/Icecave/Isolator/GeneratorTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
namespace Icecave\Isolator;

use ReflectionClass;
use ReflectionFunction;
use PHPUnit_Framework_TestCase;
use Phake;
use stdClass;

class GeneratorTest extends PHPUnit_Framework_TestCase {

public function setUp() {
class GeneratorTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->_isolator = Phake::mock(__NAMESPACE__ . '\Isolator');
$this->_generator = Phake::partialMock(
__NAMESPACE__ . '\Generator'
Expand All @@ -18,7 +17,8 @@ public function setUp() {
);
}

public function testGenerateClass() {
public function testGenerateClass()
{
$reflector = Phake::mock('ReflectionFunction');
$reflectors = array($reflector);

Expand Down Expand Up @@ -50,7 +50,8 @@ public function testGenerateClass() {
}
}

public function testInspect() {
public function testInspect()
{
$reflector = Phake::mock('ReflectionFunction');
$parameter1 = Phake::mock('ReflectionParameter');
$parameter2 = Phake::mock('ReflectionParameter');
Expand Down Expand Up @@ -94,7 +95,8 @@ public function testInspect() {
);
}

public function testInspectEllipsis() {
public function testInspectEllipsis()
{
$reflector = Phake::mock('ReflectionFunction');
$parameter1 = Phake::mock('ReflectionParameter');
$parameter2 = Phake::mock('ReflectionParameter');
Expand Down Expand Up @@ -152,7 +154,8 @@ public function testInspectEllipsis() {
);
}

public function testInspectEllipsisOptional() {
public function testInspectEllipsisOptional()
{
$reflector = Phake::mock('ReflectionFunction');
$parameter1 = Phake::mock('ReflectionParameter');
$parameter2 = Phake::mock('ReflectionParameter');
Expand Down Expand Up @@ -210,7 +213,8 @@ public function testInspectEllipsisOptional() {
);
}

public function testInspectEllipsisReference() {
public function testInspectEllipsisReference()
{
$reflector = Phake::mock('ReflectionFunction');
$parameter1 = Phake::mock('ReflectionParameter');
$parameter2 = Phake::mock('ReflectionParameter');
Expand Down Expand Up @@ -268,7 +272,8 @@ public function testInspectEllipsisReference() {
);
}

public function testRequiresIsolatorProxyDisabled() {
public function testRequiresIsolatorProxyDisabled()
{
$reflector = Phake::mock('ReflectionFunction');
Phake::when($reflector)
->isDisabled()
Expand All @@ -279,7 +284,8 @@ public function testRequiresIsolatorProxyDisabled() {
Phake::verify($reflector)->isDisabled();
}

public function testRequiresIsolatorProxyReturnsReference() {
public function testRequiresIsolatorProxyReturnsReference()
{
$reflector = Phake::mock('ReflectionFunction');
Phake::when($reflector)
->isDisabled()
Expand All @@ -297,7 +303,8 @@ public function testRequiresIsolatorProxyReturnsReference() {
);
}

public function testRequiresIsolatorProxyReferenceParameter() {
public function testRequiresIsolatorProxyReferenceParameter()
{
$reflector = Phake::mock('ReflectionFunction');
$parameter1 = Phake::mock('ReflectionParameter');
$parameter2 = Phake::mock('ReflectionParameter');
Expand Down Expand Up @@ -333,7 +340,8 @@ public function testRequiresIsolatorProxyReferenceParameter() {
);
}

public function testRequiresIsolatorProxyNoReferenceParameters() {
public function testRequiresIsolatorProxyNoReferenceParameters()
{
$reflector = Phake::mock('ReflectionFunction');
$parameter1 = Phake::mock('ReflectionParameter');
$parameter2 = Phake::mock('ReflectionParameter');
Expand Down

0 comments on commit 92f165f

Please sign in to comment.