Skip to content

Commit

Permalink
Add BaseDefinitionLoader and use it ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
msvrtan committed Jan 2, 2018
1 parent 15cafde commit cb8379c
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 544 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace NullDevelopment\Skeleton\SourceCode\DefinitionLoader;

use NullDevelopment\PhpStructure\DataTypeName\ClassName;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstantCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstructorMethodFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\InterfaceNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\MethodCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\PropertyCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\TraitNameCollectionFactory;

/**
* @see SimpleEntityLoaderSpec
* @see SimpleEntityLoaderTest
*/
abstract class BaseDefinitionLoader implements DefinitionLoader
{
/** @var InterfaceNameCollectionFactory */
protected $interfaceNameCollectionFactory;

/** @var TraitNameCollectionFactory */
protected $traitNameCollectionFactory;

/** @var ConstantCollectionFactory */
protected $constantCollectionFactory;

/** @var ConstructorMethodFactory */
protected $constructorMethodFactory;

/** @var PropertyCollectionFactory */
protected $propertyCollectionFactory;

/** @var MethodCollectionFactory */
protected $methodCollectionFactory;

public function __construct(
InterfaceNameCollectionFactory $interfaceNameCollectionFactory,
TraitNameCollectionFactory $traitNameCollectionFactory,
ConstantCollectionFactory $constantCollectionFactory,
ConstructorMethodFactory $constructorMethodFactory,
PropertyCollectionFactory $propertyCollectionFactory,
MethodCollectionFactory $methodCollectionFactory
) {
$this->interfaceNameCollectionFactory = $interfaceNameCollectionFactory;
$this->traitNameCollectionFactory = $traitNameCollectionFactory;
$this->constantCollectionFactory = $constantCollectionFactory;
$this->constructorMethodFactory = $constructorMethodFactory;
$this->propertyCollectionFactory = $propertyCollectionFactory;
$this->methodCollectionFactory = $methodCollectionFactory;
}

abstract public function supports(array $input): bool;

protected function extractParent(array $data): ?ClassName
{
if (null === $data['parent']) {
return null;
}
if (true === is_array($data['parent'])) {
return ClassName::create($data['parent']['instanceOf'], $data['parent']['alias']);
}

return ClassName::create($data['parent']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,13 @@
use NullDevelopment\PhpStructure\CustomType\CollectionOf;
use NullDevelopment\PhpStructure\DataTypeName\ClassName;
use NullDevelopment\Skeleton\SourceCode\Definition\SimpleCollection;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstantCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstructorMethodFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\InterfaceNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\MethodCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\PropertyCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\TraitNameCollectionFactory;

/**
* @see SimpleCollectionLoaderSpec
* @see SimpleCollectionLoaderTest
*/
class SimpleCollectionLoader implements DefinitionLoader
class SimpleCollectionLoader extends BaseDefinitionLoader
{
/** @var InterfaceNameCollectionFactory */
private $interfaceNameCollectionFactory;

/** @var TraitNameCollectionFactory */
private $traitNameCollectionFactory;

/** @var ConstantCollectionFactory */
private $constantCollectionFactory;

/** @var ConstructorMethodFactory */
private $constructorMethodFactory;

/** @var PropertyCollectionFactory */
private $propertyCollectionFactory;

/** @var MethodCollectionFactory */
private $methodCollectionFactory;

public function __construct(
InterfaceNameCollectionFactory $interfaceNameCollectionFactory,
TraitNameCollectionFactory $traitNameCollectionFactory,
ConstantCollectionFactory $constantCollectionFactory,
ConstructorMethodFactory $constructorMethodFactory,
PropertyCollectionFactory $propertyCollectionFactory,
MethodCollectionFactory $methodCollectionFactory
) {
$this->interfaceNameCollectionFactory = $interfaceNameCollectionFactory;
$this->traitNameCollectionFactory = $traitNameCollectionFactory;
$this->constantCollectionFactory = $constantCollectionFactory;
$this->constructorMethodFactory = $constructorMethodFactory;
$this->propertyCollectionFactory = $propertyCollectionFactory;
$this->methodCollectionFactory = $methodCollectionFactory;
}

public function supports(array $input): bool
{
if ('SimpleCollection' === $input['type']) {
Expand Down Expand Up @@ -113,16 +72,4 @@ public function getDefaultValues(): array
'constructor' => [],
];
}

private function extractParent(array $data): ?ClassName
{
if (null === $data['parent']) {
return null;
}
if (true === is_array($data['parent'])) {
return ClassName::create($data['parent']['instanceOf'], $data['parent']['alias']);
}

return ClassName::create($data['parent']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

use NullDevelopment\PhpStructure\DataTypeName\ClassName;
use NullDevelopment\Skeleton\SourceCode\Definition\SimpleEntity;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstantCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstructorMethodFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\InterfaceNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\MethodCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\PropertyCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\TraitNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\Method\DeserializeMethod;
use NullDevelopment\Skeleton\SourceCode\Method\GetterMethod;
use NullDevelopment\Skeleton\SourceCode\Method\HasPropertyMethod;
Expand All @@ -22,45 +15,9 @@
/**
* @see SimpleEntityLoaderSpec
* @see SimpleEntityLoaderTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SimpleEntityLoader implements DefinitionLoader
class SimpleEntityLoader extends BaseDefinitionLoader
{
/** @var InterfaceNameCollectionFactory */
private $interfaceNameCollectionFactory;

/** @var TraitNameCollectionFactory */
private $traitNameCollectionFactory;

/** @var ConstantCollectionFactory */
private $constantCollectionFactory;

/** @var ConstructorMethodFactory */
private $constructorMethodFactory;

/** @var PropertyCollectionFactory */
private $propertyCollectionFactory;

/** @var MethodCollectionFactory */
private $methodCollectionFactory;

public function __construct(
InterfaceNameCollectionFactory $interfaceNameCollectionFactory,
TraitNameCollectionFactory $traitNameCollectionFactory,
ConstantCollectionFactory $constantCollectionFactory,
ConstructorMethodFactory $constructorMethodFactory,
PropertyCollectionFactory $propertyCollectionFactory,
MethodCollectionFactory $methodCollectionFactory
) {
$this->interfaceNameCollectionFactory = $interfaceNameCollectionFactory;
$this->traitNameCollectionFactory = $traitNameCollectionFactory;
$this->constantCollectionFactory = $constantCollectionFactory;
$this->constructorMethodFactory = $constructorMethodFactory;
$this->propertyCollectionFactory = $propertyCollectionFactory;
$this->methodCollectionFactory = $methodCollectionFactory;
}

public function supports(array $input): bool
{
if ('SimpleEntity' === $input['type']) {
Expand Down Expand Up @@ -123,16 +80,4 @@ public function getDefaultValues(): array
'constructor' => [],
];
}

private function extractParent(array $data): ?ClassName
{
if (null === $data['parent']) {
return null;
}
if (true === is_array($data['parent'])) {
return ClassName::create($data['parent']['instanceOf'], $data['parent']['alias']);
}

return ClassName::create($data['parent']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

use NullDevelopment\PhpStructure\DataTypeName\ClassName;
use NullDevelopment\Skeleton\SourceCode\Definition\SimpleIdentifier;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstantCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstructorMethodFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\InterfaceNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\MethodCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\PropertyCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\TraitNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\Method\DeserializeMethod;
use NullDevelopment\Skeleton\SourceCode\Method\GetterMethod;
use NullDevelopment\Skeleton\SourceCode\Method\SerializeMethod;
Expand All @@ -22,42 +15,8 @@
* @see SimpleIdentifierLoaderSpec
* @see SimpleIdentifierLoaderTest
*/
class SimpleIdentifierLoader implements DefinitionLoader
class SimpleIdentifierLoader extends BaseDefinitionLoader
{
/** @var InterfaceNameCollectionFactory */
private $interfaceNameCollectionFactory;

/** @var TraitNameCollectionFactory */
private $traitNameCollectionFactory;

/** @var ConstantCollectionFactory */
private $constantCollectionFactory;

/** @var ConstructorMethodFactory */
private $constructorMethodFactory;

/** @var PropertyCollectionFactory */
private $propertyCollectionFactory;

/** @var MethodCollectionFactory */
private $methodCollectionFactory;

public function __construct(
InterfaceNameCollectionFactory $interfaceNameCollectionFactory,
TraitNameCollectionFactory $traitNameCollectionFactory,
ConstantCollectionFactory $constantCollectionFactory,
ConstructorMethodFactory $constructorMethodFactory,
PropertyCollectionFactory $propertyCollectionFactory,
MethodCollectionFactory $methodCollectionFactory
) {
$this->interfaceNameCollectionFactory = $interfaceNameCollectionFactory;
$this->traitNameCollectionFactory = $traitNameCollectionFactory;
$this->constantCollectionFactory = $constantCollectionFactory;
$this->constructorMethodFactory = $constructorMethodFactory;
$this->propertyCollectionFactory = $propertyCollectionFactory;
$this->methodCollectionFactory = $methodCollectionFactory;
}

public function supports(array $input): bool
{
if ('SimpleIdentifier' === $input['type']) {
Expand Down Expand Up @@ -118,16 +77,4 @@ public function getDefaultValues(): array
'constructor' => [],
];
}

private function extractParent(array $data): ?ClassName
{
if (null === $data['parent']) {
return null;
}
if (true === is_array($data['parent'])) {
return ClassName::create($data['parent']['instanceOf'], $data['parent']['alias']);
}

return ClassName::create($data['parent']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

use NullDevelopment\PhpStructure\DataTypeName\ClassName;
use NullDevelopment\Skeleton\SourceCode\Definition\SingleValueObject;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstantCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\ConstructorMethodFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\InterfaceNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\MethodCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\PropertyCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\DefinitionLoader\Factory\TraitNameCollectionFactory;
use NullDevelopment\Skeleton\SourceCode\Method\DeserializeMethod;
use NullDevelopment\Skeleton\SourceCode\Method\GetterMethod;
use NullDevelopment\Skeleton\SourceCode\Method\HasPropertyMethod;
Expand All @@ -24,42 +17,8 @@
* @see SingleValueObjectLoaderTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SingleValueObjectLoader implements DefinitionLoader
class SingleValueObjectLoader extends BaseDefinitionLoader
{
/** @var InterfaceNameCollectionFactory */
private $interfaceNameCollectionFactory;

/** @var TraitNameCollectionFactory */
private $traitNameCollectionFactory;

/** @var ConstantCollectionFactory */
private $constantCollectionFactory;

/** @var ConstructorMethodFactory */
private $constructorMethodFactory;

/** @var PropertyCollectionFactory */
private $propertyCollectionFactory;

/** @var MethodCollectionFactory */
private $methodCollectionFactory;

public function __construct(
InterfaceNameCollectionFactory $interfaceNameCollectionFactory,
TraitNameCollectionFactory $traitNameCollectionFactory,
ConstantCollectionFactory $constantCollectionFactory,
ConstructorMethodFactory $constructorMethodFactory,
PropertyCollectionFactory $propertyCollectionFactory,
MethodCollectionFactory $methodCollectionFactory
) {
$this->interfaceNameCollectionFactory = $interfaceNameCollectionFactory;
$this->traitNameCollectionFactory = $traitNameCollectionFactory;
$this->constantCollectionFactory = $constantCollectionFactory;
$this->constructorMethodFactory = $constructorMethodFactory;
$this->propertyCollectionFactory = $propertyCollectionFactory;
$this->methodCollectionFactory = $methodCollectionFactory;
}

public function supports(array $input): bool
{
if ('SingleValueObject' === $input['type']) {
Expand Down Expand Up @@ -124,16 +83,4 @@ public function getDefaultValues(): array
'constructor' => [],
];
}

private function extractParent(array $data): ?ClassName
{
if (null === $data['parent']) {
return null;
}
if (true === is_array($data['parent'])) {
return ClassName::create($data['parent']['instanceOf'], $data['parent']['alias']);
}

return ClassName::create($data['parent']);
}
}
Loading

0 comments on commit cb8379c

Please sign in to comment.