Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
83.33% covered (warning)
83.33%
5 / 6
CRAP
90.91% covered (success)
90.91%
10 / 11
DtoRecipe
0.00% covered (danger)
0.00%
0 / 1
83.33% covered (warning)
83.33%
5 / 6
7.04
90.91% covered (success)
90.91%
10 / 11
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 fromReflection
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 cookRecipe
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getSourceClassName
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 getSourceClass
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getTargetName
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
<?php declare(strict_types = 1);
/*
 * Copyright (c) 2020, Josef Kufner  <josef@kufner.cz>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
namespace Smalldb\CodeCooker\Recipe;
use ReflectionClass;
use Smalldb\CodeCooker\Generator\DtoGenerator;
use Smalldb\ClassLocator\ClassLocator;
class DtoRecipe extends ClassRecipe
{
    private string $sourceClassName;
    private ?string $targetName;
    public function __construct(array $targetClassNames, string $sourceClassName, string $targetName = null)
    {
        parent::__construct($targetClassNames);
        $this->sourceClassName = $sourceClassName;
        $this->targetName = $targetName;
    }
    public static function fromReflection(ReflectionClass $sourceClass, string $targetName = null): self
    {
        $targetClassNames = DtoGenerator::calculateTargetClassNames($sourceClass, $targetName);
        return new self($targetClassNames, $sourceClass->getName(), $targetName);
    }
    public function cookRecipe(ClassLocator $classLocator): array
    {
        $generator = new DtoGenerator($classLocator);
        return $generator->generateDtoClasses($this->getSourceClass(), $this->getTargetName());
    }
    public function getSourceClassName(): string
    {
        return $this->sourceClassName;
    }
    public function getSourceClass(): ReflectionClass
    {
        return new ReflectionClass($this->sourceClassName);
    }
    public function getTargetName(): ?string
    {
        return $this->targetName;
    }
}