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 ( 88e408...4d0df3 )
by Anton
04:53 queued 02:21
created

src/Console/InitCommand.php (1 issue)

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\Initializer\Initializer;
11
use Deployer\Initializer\Template\CakeTemplate;
12
use Deployer\Initializer\Template\CodeIgniterTemplate;
13
use Deployer\Initializer\Template\CommonTemplate;
14
use Deployer\Initializer\Template\DrupalTemplate;
15
use Deployer\Initializer\Template\LaravelTemplate;
16
use Deployer\Initializer\Template\SymfonyTemplate;
17
use Deployer\Initializer\Template\Typo3Template;
18
use Deployer\Initializer\Template\Yii2AdvancedAppTemplate;
19
use Deployer\Initializer\Template\Yii2BasicAppTemplate;
20
use Deployer\Initializer\Template\YiiTemplate;
21
use Deployer\Initializer\Template\ZendTemplate;
22
use Symfony\Component\Console\Command\Command;
23
use Symfony\Component\Console\Input\InputInterface;
24
use Symfony\Component\Console\Input\InputOption;
25
use Symfony\Component\Console\Output\OutputInterface;
26
use Symfony\Component\Console\Style\SymfonyStyle;
27
use Symfony\Component\Process\Exception\RuntimeException;
28
use Symfony\Component\Process\Process;
29
30
/**
31
 * The command for initialize Deployer system in your project
32
 *
33
 * @author Vitaliy Zhuk <[email protected]>
34
 */
35
class InitCommand extends Command
36
{
37
    /**
38
     * @var Initializer
39
     */
40
    private $initializer;
41
42
    /**
43
     * @var array
44
     */
45
    private $availableTemplates;
46
47
    /**
48
     * Construct
49
     *
50
     * @param string $name
51
     */
52 14
    public function __construct($name = null)
53
    {
54 14
        $this->initializer = $this->createInitializer();
55 14
        $this->availableTemplates = $this->initializer->getTemplateNames();
56
57 14
        parent::__construct($name);
58 14
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63 14
    protected function configure()
64
    {
65
        $this
66 14
            ->setName('init')
67 14
            ->setDescription('Initialize deployer in your project')
68 14
            ->addOption('template', 't', InputOption::VALUE_OPTIONAL, 'The template of you project. Available templates: ' . implode(', ', $this->availableTemplates))
69 14
            ->addOption('directory', null, InputOption::VALUE_OPTIONAL, 'The directory for create "deploy.php" file', getcwd())
70 14
            ->addOption('filename', null, InputOption::VALUE_OPTIONAL, 'The file name. Default "deploy.php"', 'deploy.php');
71 14
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
execute uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
77
    {
78
        $template = $input->getOption('template');
79
        $directory = $input->getOption('directory');
80
        $file = $input->getOption('filename');
81
        $params = [];
82
83
        if ($template === null) {
84
            $io = new SymfonyStyle($input, $output);
85
            $helper = $this->getHelper('question');
86
            $formatter = $this->getHelper('formatter');
87
88
            // Welcome message
89
            $output->writeln([
90
                '',
91
                $formatter->formatBlock('Welcome to the Deployer config generator', 'bg=blue;fg=white', true),
92
                '',
93
            ]);
94
95
            $io->text([
96
                'This utility will walk you through creating a deploy.php file.',
97
                'It only covers the most common items, and tries to guess sensible defaults.',
98
                '',
99
                'Press ^C at any time to quit.',
100
            ]);
101
102
            // Project type
103
            $template = $io->choice('Please select your project type', $this->availableTemplates, 'Common');
104
105
            // Repo
106
            $default = false;
107
            try {
108
                $default = (new Process('git remote get-url origin'))
109
                    ->mustRun()
110
                    ->getOutput();
111
                $default = trim($default);
112
            } catch (RuntimeException $e) {
113
                // pass
114
            }
115
            $params['repository'] = $io->ask('Repository', $default);
116
117
            // Privacy
118
            $io->text([
119
                'Contribute to the Deployer Development',
120
                '',
121
                'In order to help development and improve the features in Deployer,',
122
                'Deployer has a setting for usage data collection. This function',
123
                'collects anonymous usage data and sends it to Deployer. The data is',
124
                'used in Deployer development to get reliable statistics on which',
125
                'features are used (or not used). The information is not traceable',
126
                'to any individual or organization. Participation is voluntary,',
127
                'and you can change your mind at any time.',
128
                '',
129
                'Anonymous usage data contains Deployer version, php version, os type,',
130
                'name of the command being executed and whether it was successful or not,',
131
                'exception class name, count of hosts and anonymized project hash.',
132
                '',
133
                'If you would like to allow us to gather this information and help',
134
                'us develop a better tool, please add the code below.',
135
                '',
136
                "    <fg=white>set(<fg=cyan>'allow_anonymous_stats'</fg=cyan>, <fg=magenta;options=bold>true</fg=magenta;options=bold>);</fg=white>",
137
                '',
138
                'This function will not affect the performance of Deployer as',
139
                'the data is insignificant and transmitted in a separate process.',
140
            ]);
141
142
            $params['allow_anonymous_stats'] = $GLOBALS['allow_anonymous_stats'] = $io->confirm('Do you confirm?');
143
        }
144
145
        $filePath = $this->initializer->initialize($template, $directory, $file, $params);
146
147
        $output->writeln(sprintf(
148
            '<info>Successfully created:</info> <comment>%s</comment>',
149
            $filePath
150
        ));
151
    }
152
153
    /**
154
     * Create a initializer system
155
     *
156
     * @return Initializer
157
     */
158 14
    private function createInitializer()
159
    {
160 14
        $initializer = new Initializer();
161
162 14
        $initializer->addTemplate('Common', new CommonTemplate());
163 14
        $initializer->addTemplate('Laravel', new LaravelTemplate());
164 14
        $initializer->addTemplate('Symfony', new SymfonyTemplate());
165 14
        $initializer->addTemplate('Yii', new YiiTemplate());
166 14
        $initializer->addTemplate('Yii2 Basic App', new Yii2BasicAppTemplate());
167 14
        $initializer->addTemplate('Yii2 Advanced App', new Yii2AdvancedAppTemplate());
168 14
        $initializer->addTemplate('Zend Framework', new ZendTemplate());
169 14
        $initializer->addTemplate('CakePHP', new CakeTemplate());
170 14
        $initializer->addTemplate('CodeIgniter', new CodeIgniterTemplate());
171 14
        $initializer->addTemplate('Drupal', new DrupalTemplate());
172 14
        $initializer->addTemplate('TYPO3', new Typo3Template());
173
174 14
        return $initializer;
175
    }
176
}
177