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

TranspileCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Test Coverage

Coverage 95.65%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 10
dl 0
loc 39
ccs 22
cts 23
cp 0.9565
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
B execute() 0 26 3
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