GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 695db5...fba8ee )
by Anton
02:16
created

src/Console/InitCommand.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Console;
9
10
use Deployer\Component\Initializer\Initializer;
11
use Deployer\Component\Initializer\Template\CakeTemplate;
12
use Deployer\Component\Initializer\Template\CodeIgniterTemplate;
13
use Deployer\Component\Initializer\Template\CommonTemplate;
14
use Deployer\Component\Initializer\Template\DrupalTemplate;
15
use Deployer\Component\Initializer\Template\LaravelTemplate;
16
use Deployer\Component\Initializer\Template\SymfonyTemplate;
17
use Deployer\Component\Initializer\Template\Typo3Template;
18
use Deployer\Component\Initializer\Template\Yii2AdvancedAppTemplate;
19
use Deployer\Component\Initializer\Template\Yii2BasicAppTemplate;
20
use Deployer\Component\Initializer\Template\YiiTemplate;
21
use Deployer\Component\Initializer\Template\ZendTemplate;
22
use Symfony\Component\Console\Command\Command;
23
use Symfony\Component\Console\Helper\FormatterHelper;
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Input\InputOption;
26
use Symfony\Component\Console\Output\OutputInterface;
27
use Symfony\Component\Console\Style\SymfonyStyle;
28
use Symfony\Component\Process\Exception\RuntimeException;
29
use Symfony\Component\Process\Process;
30
31
class InitCommand extends Command
32
{
33
34 9
    protected function configure()
35
    {
36
        $this
37 9
            ->setName('init')
38 9
            ->setDescription('Initialize deployer in your project')
39 9
            ->addOption('template', 't', InputOption::VALUE_OPTIONAL, 'The template of you project')
40 9
            ->addOption('filepath', null, InputOption::VALUE_OPTIONAL, 'The file path (default "deploy.php")', 'deploy.php');
41 9
    }
42
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        /** @var FormatterHelper $formatter */
46
        $formatter = $this->getHelper('formatter');
47
        $initializer = new Initializer();
48
        $template = $input->getOption('template');
49
        $filepath = $input->getOption('filepath');
50
51
        if (file_exists($filepath)) {
52
            $output->writeln([
53
                $formatter->formatBlock(
54
                    sprintf('The file "%s" already exist.', $filepath),
55
                    'bg=red;fg=white', true
56
                ),
57
            ]);
58
            return 2;
59
        }
60
61
        $project = 'my_project';
62
        $repository = '';
63
        $hosts = [];
64
        $allow = true;
65
66
        if ($template === null) {
67
            $io = new SymfonyStyle($input, $output);
68
69
            // Welcome message
70
            $output->writeln("
71
  _____             _
72
 |  __ \           | |
73
 | |  | | ___ _ __ | | ___  _   _  ___ _ __
74
 | |  | |/ _ \ '_ \| |/ _ \| | | |/ _ \ '__|
75
 | |__| |  __/ |_) | | (_) | |_| |  __/ |
76
 |_____/ \___| .__/|_|\___/ \__, |\___|_|
77
             | |             __/ |
78
             |_|            |___/
79
");
80
81
            $io->text([
82
                'Welcome to the Deployer config generator.',
83
                'This utility will walk you through creating a deploy.php file.',
84
                '',
85
                'Press ^C at any time to quit.',
86
            ]);
87
88
            // Yes?
89
            $io->confirm('Continue?');
90
91
            // Template
92
            $recipes = $initializer->getRecipes();
93
            $template = $io->choice('Select project template', $recipes, 'common');
94
95
            // Repo
96
            $default = false;
97
            try {
98
                $process = Process::fromShellCommandline('git remote get-url origin');
99
                $default = $process->mustRun()->getOutput();
100
                $default = trim($default);
101
            } catch (RuntimeException $e) {
102
            }
103
            $repository = $io->ask('Repository', $default);
104
105
            // Repo
106
            $default = false;
107
            try {
108
                $process = Process::fromShellCommandline('basename "$PWD"');
109
                $default = $process->mustRun()->getOutput();
110
                $default = trim($default);
111
            } catch (RuntimeException $e) {
112
            }
113
            $project = $io->ask('Project name', $default);
114
115
            // Hosts
116
            $hosts = explode(',', $io->ask('Hosts (comma separated)', 'deployer.org'));
117
118
            // Privacy
119
            $io->text(<<<TEXT
120
    <info>Contribute to the Deployer Development</info>
121
122
Help development and improve features of Deployer by 
123
an optional usage data collection program. This program
124
collects anonymous usage data and sends it to Deployer. 
125
The data is used in Deployer development to get reliable
126
statistics on which features are used (or not used). The
127
information is not traceable to any individual or 
128
organization. Participation is voluntary, and you can 
129
change your mind at any time.
130
131
Anonymous usage data contains Deployer version, PHP version, 
132
OS type, name of the command being executed and whether 
133
it was successful or not, count of hosts and anonymized 
134
project hash. This program will not affect the performance 
135
of Deployer as the data is insignificant and transmitted 
136
in a separate process.
137
138
We appreciate your involvement!
139
TEXT);
140
141
            $allow = $io->confirm('Do you confirm?');
142
        }
143
144
145
        file_put_contents($filepath, $initializer->getTemplate($template, $project, $repository, $hosts, $allow));
146
147
        $output->writeln(sprintf(
148
            '<info>Successfully created</info> <comment>%s</comment>',
149
            $filepath
150
        ));
151
152
        return 0;
153
    }
154
155
    /**
156
     * Create a initializer system
157
     *
158
     * @return Initializer
159
     */
160
    private function createInitializer()
161
    {
162
        $initializer = new Initializer();
163
164
        $initializer->addTemplate('Common', new CommonTemplate());
165
        $initializer->addTemplate('Laravel', new LaravelTemplate());
166
        $initializer->addTemplate('Symfony', new SymfonyTemplate());
167
        $initializer->addTemplate('Yii', new YiiTemplate());
168
        $initializer->addTemplate('Yii2 Basic App', new Yii2BasicAppTemplate());
169
        $initializer->addTemplate('Yii2 Advanced App', new Yii2AdvancedAppTemplate());
170
        $initializer->addTemplate('Zend Framework', new ZendTemplate());
171
        $initializer->addTemplate('CakePHP', new CakeTemplate());
172
        $initializer->addTemplate('CodeIgniter', new CodeIgniterTemplate());
173
        $initializer->addTemplate('Drupal', new DrupalTemplate());
174
        $initializer->addTemplate('TYPO3', new Typo3Template());
175
176
        return $initializer;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected EOF
Loading history...
177
    }
178
}
179