Skip to content

Commit

Permalink
iterate and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Jan 23, 2017
1 parent 9da81e5 commit c20b70d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 139 deletions.
10 changes: 9 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<phpunit bootstrap='tests/bootstrap.php'
colors='true'>
colors='true'>
<testsuites>
<testsuite name='All'>
<directory suffix="Test.php">tests/52-compat</directory>
<directory suffix="Test.php" phpVersion="5.3.0" phpVersionOperator=">=">tests/53-above</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">vendor</directory>
</blacklist>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
75 changes: 0 additions & 75 deletions src/tad/DI52/BindGroup.php

This file was deleted.

91 changes: 28 additions & 63 deletions src/tad/DI52/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,6 @@ public function offsetGet($offset)
return call_user_func($this->callables[$offset], $this);
}

if (isset($this->singletons[$offset])) {
$this->objects[$offset] = call_user_func($this->singletons[$offset]);
return $this->objects[$offset];
}

if (class_exists($offset)) {
return $this->resolve($offset);
}
Expand Down Expand Up @@ -293,13 +288,7 @@ public function make($classOrInterface)
}

if (isset($this->singletons[$classOrInterface])) {
if ($this->singletons[$classOrInterface] instanceof tad_DI52_BindGroup) {
foreach ($this->singletons[$classOrInterface] as $key) {
$this->objects[$key] = $resolved;
}
} else {
$this->objects[$classOrInterface] = $resolved;
}
$this->objects[$classOrInterface] = $resolved;
}

return $resolved;
Expand Down Expand Up @@ -334,11 +323,7 @@ protected function resolve($classOrInterface)
throw new RuntimeException("'{$classOrInterface}' is not a bound alias or an existing class.");
}
} else {
if (is_object($this->strings[$classOrInterface]) && !is_callable($this->strings[$classOrInterface])) {
$instance = $this->strings[$classOrInterface];
} elseif (is_callable($this->strings[$classOrInterface])) {
$instance = $this->buildFromCallable($classOrInterface);
} elseif (isset($this->chains[$classOrInterface])) {
if (isset($this->chains[$classOrInterface])) {
$instance = $this->buildFromChain($classOrInterface);
} else {
$instance = $this->build($this->strings[$classOrInterface]);
Expand All @@ -357,8 +342,10 @@ protected function resolve($classOrInterface)
} catch (Exception $e) {
preg_match('/Error while making/', $e->getMessage(), $matches);
if (count($matches)) {
// @codeCoverageIgnoreStart
$divider = "\n\t => ";
$prefix = ' ';
// @codeCoverageIgnoreEnd
} else {
$divider = ':';
$prefix = 'Error while making ';
Expand Down Expand Up @@ -397,17 +384,6 @@ protected function build($implementation, $resolving = false)
return $instance;
}

/**
* @param $classOrInterface
*
* @return mixed
*/
protected function buildFromCallable($classOrInterface)
{
$instance = call_user_func($this->strings[$classOrInterface], $this);
return $instance;
}

/**
* @param string $classOrInterface
*
Expand Down Expand Up @@ -647,7 +623,15 @@ public function offsetUnset($offset)
$this->callables[$offset],
$this->contexts[$offset],
$this->tags[$offset],
$this->chains[$offset]);
$this->chains[$offset],
$this->parameterReflections[$offset]
);

if (isset($this->dependants[$offset])) {
foreach ($this->dependants[$offset] as $dependant) {
unset($this->parameterReflections[$dependant]);
}
}
}

/**
Expand Down Expand Up @@ -744,34 +728,22 @@ public function protect($value)
*/
public function bind($classOrInterface, $implementation, array $afterBuildMethods = null)
{
$this->bindings[$classOrInterface] = $classOrInterface;

unset($this->strings[$classOrInterface],
$this->singletons[$classOrInterface],
$this->objects[$classOrInterface],
$this->callables[$classOrInterface],
$this->chains[$classOrInterface],
$this->parameterReflections[$classOrInterface]
);
$this->offsetUnset($classOrInterface);

if (isset($this->dependants[$classOrInterface])) {
foreach ($this->dependants[$classOrInterface] as $dependant) {
unset($this->parameterReflections[$dependant]);
}
}
$this->bindings[$classOrInterface] = $classOrInterface;

if (is_string($implementation)) {
unset($this->parameterReflections[$implementation]);
}

if (is_callable($implementation)) {
$this->callables[$classOrInterface] = $implementation;
return;
}

if (is_object($implementation)) {
if (is_callable($implementation)) {
$this->callables[$classOrInterface] = $implementation;
return;
} else {
$this->objects[$classOrInterface] = $implementation;
return;
}
$this->objects[$classOrInterface] = $implementation;
return;
}

$this->strings[$classOrInterface] = $implementation;
Expand All @@ -794,14 +766,7 @@ public function singleton($classOrInterface, $implementation, array $afterBuildM
{
$this->bind($classOrInterface, $implementation, $afterBuildMethods);

if (is_array($classOrInterface)) {
$group = new tad_DI52_BindGroup($classOrInterface);
foreach ($classOrInterface as $key) {
$this->singletons[$key] = $group;
}
} else {
$this->singletons[$classOrInterface] = $classOrInterface;
}
$this->singletons[$classOrInterface] = $classOrInterface;
}

/**
Expand All @@ -820,20 +785,18 @@ public function callback($classOrInterface, $method)
$this->initClosuresSupport();

if (!is_string($method)) {
throw new RuntimeException('Lazy make method must be a string');
}

if (isset($this->callbacks[$classOrInterface . '::' . $method])) {
return $this->callbacks[$classOrInterface . '::' . $method];
throw new RuntimeException('Callback method must be a string');
}

if ($this->useClosures) {
$f = di52_callbackClosure($this, $classOrInterface, $method);
} else {
// @codeCoverageIgnoreStart
$f = create_function(
'',
'$a = func_get_args(); global $__container_' . $this->id . '; $c = $__container_' . $this->id . '; $i = $c->make(\'' . $classOrInterface . '\'); return call_user_func_array(array($i, \'' . $method . '\'),$a);'
);
// @codeCoverageIgnoreEnd
}

$this->callbacks[$classOrInterface . '::' . $method] = $f;
Expand Down Expand Up @@ -890,6 +853,7 @@ public function instance($classOrInterface, array $args = array())
if ($this->useClosures) {
$f = di52_instanceClosure($this, $classOrInterface, $args);
} else {
// @codeCoverageIgnoreStart
$body = "global \$__container_{$this->id};
\$c = \$__container_{$this->id};
\$r = new ReflectionClass('{$classOrInterface}');
Expand All @@ -909,6 +873,7 @@ public function instance($classOrInterface, array $args = array())
return \$r->newInstanceArgs(\$args);";

$f = create_function('', $body);
// @codeCoverageIgnoreEnd
}

$this->instanceCallbacks[$instanceId] = $f;
Expand Down

0 comments on commit c20b70d

Please sign in to comment.