Formated code

This commit is contained in:
Kevin Frantz 2019-03-28 19:15:24 +01:00
parent a931d7aebc
commit 6fb99c2f1a
3 changed files with 37 additions and 38 deletions

View File

@ -1,75 +1,77 @@
<?php
namespace Infinito\Domain\ParameterManagement;
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
use HaydenPierce\ClassFinder\ClassFinder;
use Doctrine\Common\Collections\ArrayCollection;
use PhpCollection\CollectionInterface;
use Doctrine\Migrations\Configuration\Exception\ParameterIncompatibleWithFinder;
use PhpParser\ErrorHandler\Collecting;
use Doctrine\Common\Collections\Collection;
use Infinito\Domain\ParameterManagement\Parameter\AbstractParameter;
/**
*
* @author kevinfrantz
*
*/
final class ParameterFactory implements ParameterFactoryInterface
{
/**
*
* @var string Namespace under which the parameters are stored
*/
const PARAMETER_NAMESPACE = 'Infinito\Domain\ParameterManagement\Parameter';
/**
* @var ArrayCollection|CollectionInterface|ParameterInterface[]
*/
private $parameters;
private function initPossible(string $class){
if($class === AbstractParameter::class){
return false;
}
$reflectionClass = new \ReflectionClass($class);
if($reflectionClass->isInterface()){
private function initPossible(string $class)
{
if (AbstractParameter::class === $class) {
return false;
}
$reflectionClass = new \ReflectionClass($class);
if ($reflectionClass->isInterface()) {
return false;
}
return true;
}
private function initParameters():void{
private function initParameters(): void
{
$this->parameters = new ArrayCollection();
$classFinder = new ClassFinder();
$parameterClasses = $classFinder->getClassesInNamespace(self::PARAMETER_NAMESPACE);
foreach ($parameterClasses as $parameterClass){
if($this->initPossible($parameterClass)){
foreach ($parameterClasses as $parameterClass) {
if ($this->initPossible($parameterClass)) {
$parameter = new $parameterClass();
$this->parameters->set($parameter::getKey(),$parameter);
$this->parameters->set($parameter::getKey(), $parameter);
}
}
}
public function __construct(){
$this->initParameters();
public function __construct()
{
$this->initParameters();
}
/**
*
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Infinito\Domain\ParameterManagement\ParameterFactoryInterface::getParameter()
*/
public function getParameter(string $key): ParameterInterface
{
return $this->parameters->get($key);
return $this->parameters->get($key);
}
/**
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Infinito\Domain\ParameterManagement\ParameterFactoryInterface::getAllParameters()
*/
public function getAllParameters():Collection{
public function getAllParameters(): Collection
{
return $this->parameters;
}
}

View File

@ -1,4 +1,5 @@
<?php
namespace Infinito\Domain\ParameterManagement;
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
@ -6,17 +7,15 @@ use Doctrine\Common\Collections\Collection;
interface ParameterFactoryInterface
{
/**
*
* @param string $key
*
* @return ParameterInterface
*/
public function getParameter(string $key): ParameterInterface;
/**
* @return Collection|ParameterInterface[]
*/
public function getAllParameters():Collection;
public function getAllParameters(): Collection;
}

View File

@ -1,19 +1,18 @@
<?php
namespace tests\Unit\Domain\ParameterManagement;
namespace tests\Unit\Domain\ParameterManagement;
use PHPUnit\Framework\TestCase;
use Infinito\Domain\ParameterManagement\ParameterFactory;
use Infinito\Domain\ParameterManagement\Parameter\VersionParameter;
/**
*
* @author kevinfrantz
*
*/
class ParameterFactoryTest extends TestCase
{
public function testAllParameters():void{
public function testAllParameters(): void
{
$parameterFactory = new ParameterFactory();
$allParameters = $parameterFactory->getAllParameters();
var_dump($allParameters);
@ -22,4 +21,3 @@ class ParameterFactoryTest extends TestCase
$this->assertEquals($versionParameter, $parameterFactory->getParameter('version'));
}
}