Create an Abstract collection for the extra methods we need

parent 9f15f793
<?php
declare(strict_types=1);
/*
* This file is part of the Application mapper application,
* following the Explicit Architecture principles.
*
* @link https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together
* @link https://herbertograca.com/2018/07/07/more-than-concentric-layers/
*
* (c) Herberto Graça
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser;
use Hgraca\PhpExtension\Collection\Collection;
abstract class AbstractCollection extends Collection
{
public function implodeKeys(string $glue): string
{
return implode($glue, array_keys($this->itemList));
}
}
......@@ -18,16 +18,15 @@ declare(strict_types=1);
namespace Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Exception;
use Hgraca\AppMapper\Core\SharedKernel\Exception\AppMapperLogicException;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\TypeCollection;
use function array_keys;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\AbstractCollection;
final class NonUniqueTypeCollectionException extends AppMapperLogicException
{
public function __construct(TypeCollection $typeCollection)
public function __construct(AbstractCollection $collection)
{
parent::__construct(
"The type collection contains more than one type: \n"
. implode("\n", array_keys($typeCollection->toArray()))
. $collection->implodeKeys("\n")
);
}
}
......@@ -18,10 +18,10 @@ declare(strict_types=1);
namespace Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor;
use Hgraca\AppMapper\Core\Port\Logger\StaticLoggerFacade;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\AbstractCollection;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Exception\CircularReferenceDetectedException;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Exception\EmptyCollectionException;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Exception\NonUniqueTypeCollectionException;
use Hgraca\PhpExtension\Collection\Collection;
use Hgraca\PhpExtension\String\ClassHelper;
use PhpParser\Node;
use function uniqid;
......@@ -29,7 +29,7 @@ use function uniqid;
/**
* @property Type[] $itemList
*/
final class TypeCollection extends Collection
final class TypeCollection extends AbstractCollection
{
private const REPEATED_TYPE_ADD_LIMIT = 1000;
......@@ -87,14 +87,6 @@ final class TypeCollection extends Collection
}
}
/**
* @return Type[]
*/
public function toArray(): array
{
return $this->itemList;
}
public function getUniqueType(): Type
{
if ($this->count() > 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment