Passed
Push — master ( ec4482...3e88a2 )
by Jan Philipp
02:44
created

TranspileCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace JanPiet\PhpTranspilerApp;
4
5
use JanPiet\PhpTranspiler\Feature\AnonymousClassFeature;
6
use JanPiet\PhpTranspiler\Feature\NullCoalescingOperatorVisitor;
7
use JanPiet\PhpTranspiler\Feature\ReturnTypeFeature;
8
use JanPiet\PhpTranspiler\Feature\SpaceshipOperatorFeature;
9
use JanPiet\PhpTranspiler\Feature\TypeHintFeature;
10
use JanPiet\PhpTranspiler\Transpiler;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Filesystem\Filesystem;
16
use Symfony\Component\Finder\Finder;
17
use Symfony\Component\Finder\SplFileInfo;
18
19
/**
20
 * Example command for testing purposes.
21
 */
22
class TranspileCommand extends Command
23
{
24 1
    protected function configure()
25
    {
26
        $this
27 1
            ->setName('transpile')
28 1
            ->setDescription('Transpile a source file to a destination')
29 1
            ->addArgument('source', InputArgument::REQUIRED, 'Where is your PHP7 source?')
30 1
            ->addArgument('destination', InputArgument::REQUIRED, 'Where should the PHP5.6 compatible files be put?')
31
            ;
32 1
    }
33
34 1
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36 1
        $transpiler = new Transpiler();
37
38 1
        $filesystem = new Filesystem();
39 1
        $finder = new Finder();
40 1
        $finder->files()->in($input->getArgument('source'));
41
42
        /** @var  SplFileInfo $file */
43 1
        foreach ($finder as $file) {
44 1
            if ($file->getExtension() !== 'php') {
45
                continue;
46
            }
47
48 1
            $transpiled = $transpiler->transpileFeature(
49 1
                $file->getContents(),
50 1
                new AnonymousClassFeature(),
51 1
                new NullCoalescingOperatorVisitor(),
52 1
                new ReturnTypeFeature(),
53 1
                new SpaceshipOperatorFeature(),
54 1
                new TypeHintFeature()
55
            );
56
57 1
            $filesystem->dumpFile($input->getArgument('destination') . '/' . $file->getRelativePath() . '/' . $file->getFilename(), $transpiled);
58
        }
59 1
    }
60
}
61