Completed
Push — master ( 3b8df9...2f57f8 )
by Marius
04:00
created

PhpStormHelperApplication::createZippy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paysera\PhpStormHelper;
6
7
use Alchemy\Zippy\Adapter\AdapterContainer;
8
use Alchemy\Zippy\FileStrategy\ZipFileStrategy;
9
use Alchemy\Zippy\Zippy;
10
use GuzzleHttp\Client;
11
use Humbug\SelfUpdate\Strategy\GithubStrategy;
12
use Humbug\SelfUpdate\Updater;
13
use Paysera\PhpStormHelper\Command\ConfigureCommand;
14
use Paysera\PhpStormHelper\Command\ConfigureInstallationCommand;
15
use Paysera\PhpStormHelper\Command\SelfUpdateCommand;
16
use Paysera\PhpStormHelper\Service\ConfigurationOptionFinder;
17
use Paysera\PhpStormHelper\Service\DirectoryResolver;
18
use Paysera\PhpStormHelper\Service\DomHelper;
19
use Paysera\PhpStormHelper\Service\ExternalToolsConfigurationHelper;
20
use Paysera\PhpStormHelper\Service\GitignoreHelper;
21
use Paysera\PhpStormHelper\Service\PluginDownloader;
22
use Paysera\PhpStormHelper\Service\StructureConfigurator;
23
use Paysera\PhpStormHelper\Service\WorkspaceConfigurationHelper;
24
use Symfony\Component\Console\Application;
25
use Symfony\Component\Filesystem\Filesystem;
26
27
class PhpStormHelperApplication extends Application
28
{
29 5
    public function __construct()
30
    {
31 5
        parent::__construct('phpstorm-helper', '@application_version@');
32
33 5
        $filesystem = new Filesystem();
34 5
        $domHelper = new DomHelper();
35
36 5
        $this->addCommands([
37 5
            new ConfigureCommand(
38 5
                new StructureConfigurator($filesystem),
39 5
                new GitignoreHelper($filesystem, [
40 5
                    file_get_contents(__DIR__ . '/Resources/gitignore-rules.txt'),
41
                ]),
42 5
                new ConfigurationOptionFinder($domHelper),
43 5
                new WorkspaceConfigurationHelper($domHelper, $filesystem)
44
            ),
45 5
            new ConfigureInstallationCommand(
46 5
                new ExternalToolsConfigurationHelper(new DirectoryResolver(), $filesystem, $domHelper),
47 5
                new PluginDownloader(new DirectoryResolver(), $this->createZippy(), new Client(), $filesystem)
48
            ),
49 5
            $this->createSelfUpdateCommand(),
50
        ]);
51 5
    }
52
53 5
    private function createZippy()
54
    {
55 5
        $adapters = AdapterContainer::load();
56
57
        // Avoid using ProcessBuilder as 4.x version is not supported in zippy
58 5
        $adapters['Alchemy\\Zippy\\Adapter\\ZipAdapter'] = $adapters['Alchemy\\Zippy\\Adapter\\ZipExtensionAdapter'];
59
60 5
        $zippy = new Zippy($adapters);
61 5
        $zippy->addStrategy(new ZipFileStrategy($adapters));
62 5
        return $zippy;
63
    }
64
65 5
    private function createSelfUpdateCommand(): SelfUpdateCommand
66
    {
67 5
        $strategy = new GithubStrategy();
68 5
        $strategy->setCurrentLocalVersion('@application_version@');
69 5
        $strategy->setPharName('phpstorm-helper.phar');
70 5
        $strategy->setPackageName('paysera/util-phpstorm-helper');
71
72 5
        $updater = new Updater(null, false);
73 5
        $updater->setStrategyObject($strategy);
74
75 5
        return new SelfUpdateCommand($updater);
76
    }
77
}
78