Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiGAndromeda committed Sep 29, 2021
1 parent a8e2cff commit ac92819
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 160 deletions.
15 changes: 0 additions & 15 deletions src/Exception/InvalidAdditionalData.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Exception/InvalidInputObject.php

This file was deleted.

9 changes: 2 additions & 7 deletions src/Exception/InvalidOutputClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

final class InvalidOutputClassName extends InvalidArgumentException
{
public static function notString(): self
public static function notClass(string $className): self
{
return new self('The passed output class name is not a string. Only strings are allowed.');
}

public static function emptyString(): self
{
return new self('The passed output class name is empty.');
return new self(sprintf('The passed output class name \'%s\' is not an existing class.', $className));
}
}
25 changes: 11 additions & 14 deletions src/Stamp/InputClassStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@

namespace ITB\ObjectTransformer\Stamp;

use ITB\ObjectTransformer\Validation\InputClassNameValidator;
use ITB\ObjectTransformer\Validation\PriorityValidator;

final class InputClassStamp implements TransformationStampInterface
{
/** @var string $inputClassName */
private string $inputClassName;
/** @var int $priority */
private int $priority;

public function __construct($inputClassName, $priority = 0)
/**
* @param string $inputClassName
* @param int $priority
*/
public function __construct(private string $inputClassName, private int $priority = 0)
{
InputClassNameValidator::validate($inputClassName);
$this->inputClassName = $inputClassName;

PriorityValidator::validate($priority);
$this->priority = $priority;
}

/**
* @return string
*/
public function getInputClassName(): string
{
return $this->inputClassName;
}

/**
* @return int
*/
public function getPriority(): int
{
return $this->priority;
Expand Down
6 changes: 4 additions & 2 deletions src/TransformationMediator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace ITB\ObjectTransformer;

use ITB\ObjectTransformer\Exception\InvalidOutputClassName;
use ITB\ObjectTransformer\Exception\NoTransformers;
use ITB\ObjectTransformer\Exception\UnsupportedInputOutputTypes;
use ITB\ObjectTransformer\Stamp\InputClassStamp;
use ITB\ObjectTransformer\Validation\OutputClassNameValidator;
use ITB\ObjectTransformer\Validation\TransformerConfigurationValidator;

final class TransformationMediator implements TransformationMediatorInterface
Expand Down Expand Up @@ -42,7 +42,9 @@ public function __construct(iterable $transformers)
public function transform(object $input, string $outputClassName): object
{
$envelope = TransformationEnvelope::wrap($input, []);
OutputClassNameValidator::validate($outputClassName);
if (!class_exists($outputClassName)) {
throw InvalidOutputClassName::notClass($outputClassName);
}

// Populate the transformers array if the commander is used the first time.
if (false === $this->transformersPopulated) {
Expand Down
17 changes: 0 additions & 17 deletions src/Validation/AdditionalDataValidator.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Validation/InputClassNameValidator.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Validation/InputObjectValidator.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Validation/OutputClassNameValidator.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Validation/PriorityValidator.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Validation/TransformationStampValidator.php

This file was deleted.

1 change: 0 additions & 1 deletion tests/TransformationMediatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace ITB\ObjectTransformer\Tests;

use ArrayObject;
use ITB\ObjectTransformer\Exception\InvalidAdditionalData;
use ITB\ObjectTransformer\Exception\InvalidOutputClassName;
use ITB\ObjectTransformer\Exception\InvalidTransformerConfiguration;
use ITB\ObjectTransformer\Exception\NoTransformers;
Expand Down

0 comments on commit ac92819

Please sign in to comment.