Skip to content

Commit

Permalink
Merge pull request #5 from ncou/analysis-qMZ5RK
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
ncou committed Apr 20, 2019
2 parents 672ccf3 + d1508d0 commit 7daf270
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 231 deletions.
31 changes: 1 addition & 30 deletions src/Container.php
Expand Up @@ -4,29 +4,10 @@

namespace Chiron\Container;


use Chiron\Container\Exception\CannotChangeException;
use Chiron\Container\Exception\CannotFindParameterException;
use Chiron\Container\Exception\CannotResolveException;
use Chiron\Container\Exception\DependencyException;
use Chiron\Container\Exception\NullReferenceException;

use ArrayAccess;
use Chiron\Container\Exception\ContainerException;
use Chiron\Container\Exception\EntityNotFoundException;

use Chiron\Container\Reflection\ReflectionCallable;
use Closure;
use InvalidArgumentException;
use LogicException;

use Psr\Container\ContainerInterface as PsrContainerInterface;
use Psr\Container\ContainerExceptionInterface;

use ReflectionClass;
use ReflectionException;
use ReflectionFunctionAbstract;
use Generator;
use ArrayAccess;

// TODO : créer une méthode singleton() ou share() => https://github.com/illuminate/container/blob/master/Container.php#L354
// https://github.com/thephpleague/container/blob/master/src/Container.php#L92
Expand All @@ -36,7 +17,6 @@

class Container extends ContainerAbstract implements ArrayAccess
{

/**
* Wrap the given closure such that its dependencies will be injected when executed.
*
Expand Down Expand Up @@ -70,8 +50,6 @@ public function factory(string $abstract): Closure
};
}



/*
// TODO : regarder si on peut utiliser cette méthode pour tester le has() !!!!
public function has($name): bool
Expand Down Expand Up @@ -105,8 +83,6 @@ public function has($id)
return $this->bound($id);
}*/



/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -162,7 +138,6 @@ public function bind2(string $name, $className = null): DefinitionInterface
);
}*/


/**
* {@inheritdoc}
*/
Expand All @@ -176,7 +151,6 @@ public function build(string $className, array $arguments = [])
return $this->resolver->build($className, $arguments);
}


/**
* Call the given Closure / class@method and inject its dependencies.
*
Expand Down Expand Up @@ -206,7 +180,6 @@ public function call($callback, array $parameters = [], ?string $defaultMethod =
));
}


return $this->resolver->call($callback, $parameters);
}

Expand Down Expand Up @@ -279,6 +252,4 @@ public function offsetUnset($name)
{
$this->destroy($name);
}


}
47 changes: 8 additions & 39 deletions src/ContainerAbstract.php
Expand Up @@ -4,30 +4,12 @@

namespace Chiron\Container;


use Chiron\Container\Exception\CannotChangeException;
use Chiron\Container\Exception\CannotFindParameterException;
use Chiron\Container\Exception\CannotResolveException;
use Chiron\Container\Exception\DependencyException;
use Chiron\Container\Exception\NullReferenceException;

use Chiron\Container\Exception\ContainerException;
use Chiron\Container\Exception\EntityNotFoundException;

use Chiron\Container\Reflection\ReflectionCallable;
use Closure;
use InvalidArgumentException;
use LogicException;

use Psr\Container\ContainerInterface as PsrContainerInterface;
use Psr\Container\ContainerExceptionInterface;

use ReflectionClass;
use ReflectionException;
use ReflectionFunctionAbstract;
use Generator;
use ArrayAccess;

// TODO : créer une méthode singleton() ou share() => https://github.com/illuminate/container/blob/master/Container.php#L354
// https://github.com/thephpleague/container/blob/master/src/Container.php#L92
//https://github.com/mrferos/di/blob/master/src/Container.php#L99
Expand All @@ -36,17 +18,11 @@

class ContainerAbstract implements ContainerInterface
{


/**
* @var boolean
* @var bool
*/
protected $defaultToShared = false;





/** @var \Wandu\DI\ContainerInterface */
//public static $instance;

Expand Down Expand Up @@ -84,18 +60,17 @@ public function __construct()
/**
* Whether the container should default to defining shared definitions.
*
* @param boolean $shared
* @param bool $shared
*
* @return self
*/
public function defaultToShared(bool $shared = true) : ContainerInterface
public function defaultToShared(bool $shared = true): ContainerInterface
{
$this->defaultToShared = $shared;

return $this;
}


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -162,9 +137,7 @@ public function has($id)

public function destroy(...$names)
{

foreach ($names as $name) {

unset(
$this->definitions[$name],
$this->instances[$name],
Expand Down Expand Up @@ -230,7 +203,6 @@ public function bind2(string $name, $className = null): DefinitionInterface
);
}*/


/**
* Proxy to add with shared as true.
*
Expand All @@ -239,21 +211,21 @@ public function bind2(string $name, $className = null): DefinitionInterface
*
* @return \League\Container\Definition\DefinitionInterface
*/
public function share(string $id, $concrete = null) : DefinitionInterface
public function share(string $id, $concrete = null): DefinitionInterface
{
return $this->add($id, $concrete, true);
}

/**
* Add an item to the container.
*
* @param string $id
* @param mixed $concrete
* @param boolean $shared
* @param string $id
* @param mixed $concrete
* @param bool $shared
*
* @return \League\Container\Definition\DefinitionInterface
*/
public function add(string $id, $concrete = null, bool $shared = null) : DefinitionInterface
public function add(string $id, $concrete = null, bool $shared = null): DefinitionInterface
{
// handle special case when the $id is the interface name and the $concrete the real class.
// TODO : bout de code à virer si on recherche directement avec le getAlias du definition
Expand All @@ -275,7 +247,6 @@ public function add(string $id, $concrete = null, bool $shared = null) : Definit
return $concrete;
}


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -332,7 +303,6 @@ public function getDefinition(string $name): DefinitionInterface
return $this->definitions[$name];
}


/**
* @param string $name
*
Expand Down Expand Up @@ -374,5 +344,4 @@ protected function resolve($name, bool $new = false)

return $instance;
}

}
16 changes: 8 additions & 8 deletions src/ContainerInterface.php
Expand Up @@ -32,13 +32,13 @@ interface ContainerInterface extends PsrContainerInterface
/**
* Add an item to the container.
*
* @param string $id
* @param mixed $concrete
* @param boolean $shared
* @param string $id
* @param mixed $concrete
* @param bool $shared
*
* @return \League\Container\Definition\DefinitionInterface
*/
public function add(string $id, $concrete = null, bool $shared = null) : DefinitionInterface;
public function add(string $id, $concrete = null, bool $shared = null): DefinitionInterface;

/**
* @param string $alias
Expand All @@ -53,30 +53,30 @@ public function alias(string $alias, string $target);
*/
public function getDefinition(string $name): DefinitionInterface;

/**
/*
* @param array $arguments
*
* @return \Wandu\DI\ContainerInterface
*/
//public function with(array $arguments = []): ContainerInterface;

/**
/*
* @param string $className
* @param array $arguments
*
* @return object
*/
//public function build(string $className, array $arguments = []);

/**
/*
* @param callable $callee
* @param array $arguments
*
* @return mixed
*/
//public function call(callable $callee, array $arguments = []);

/**
/*
* Call the given Closure / class@method and inject its dependencies.
*
* @param callable|string $callback
Expand Down

0 comments on commit 7daf270

Please sign in to comment.