Executor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Executor;
13
14
use PhpUnitGen\Configuration\ConfigurationInterface\ConfigInterface;
15
use PhpUnitGen\Executor\ExecutorInterface\ExecutorInterface;
16
use PhpUnitGen\Parser\ParserInterface\PhpParserInterface;
17
use PhpUnitGen\Renderer\RendererInterface\PhpFileRendererInterface;
18
19
/**
20
 * Class Executor.
21
 *
22
 * @author     Paul Thébaud <[email protected]>.
23
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
24
 * @license    https://opensource.org/licenses/MIT The MIT license.
25
 * @link       https://github.com/paul-thebaud/phpunit-generator
26
 * @since      Class available since Release 2.0.0.
27
 */
28
class Executor implements ExecutorInterface
29
{
30
    /**
31
     * @var ConfigInterface $config The configuration to use.
32
     */
33
    private $config;
34
35
    /**
36
     * @var PhpParserInterface $phpFileParser The php file parser.
37
     */
38
    private $phpFileParser;
39
40
    /**
41
     * @var PhpFileRendererInterface $phpFileRenderer The php file renderer.
42
     */
43
    private $phpFileRenderer;
44
45
    /**
46
     * Executor constructor.
47
     *
48
     * @param ConfigInterface          $config          The config instance.
49
     * @param PhpParserInterface       $phpFileParser   The php file parser.
50
     * @param PhpFileRendererInterface $phpFileRenderer The php file renderer.
51
     */
52
    public function __construct(
53
        ConfigInterface $config,
54
        PhpParserInterface $phpFileParser,
55
        PhpFileRendererInterface $phpFileRenderer
56
    ) {
57
        $this->config          = $config;
58
        $this->phpFileParser   = $phpFileParser;
59
        $this->phpFileRenderer = $phpFileRenderer;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function invoke(string $code, string $name = 'GeneratedTest'): ?string
66
    {
67
        $phpFile = $this->phpFileParser->invoke($code);
68
        $phpFile->setName($name);
69
70
        if ($phpFile->getTestableFunctionsCount() === 0) {
71
            if (! $this->config->hasInterfaceParsing() || $phpFile->getInterfacesFunctionsCount() === 0) {
72
                return null;
73
            }
74
        }
75
76
        return $this->phpFileRenderer->invoke($phpFile);
77
    }
78
}
79