Completed
Push — develop ( 722f70...af048b )
by Jaap
15:12 queued 05:04
created

src/phpDocumentor/Command/Project/RunCommand.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
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Command\Project;
13
14
use phpDocumentor\Command\Command;
15
use phpDocumentor\Descriptor\ProjectDescriptorBuilder;
16
use Symfony\Component\Console\Input\ArrayInput;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Parse and transform the given directory (-d|-f) to the given location (-t).
23
 *
24
 * phpDocumentor creates documentation from PHP source files. The simplest way
25
 * to use it is:
26
 *
27
 *     $ phpdoc run -d <directory to parse> -t <output directory>
28
 *
29
 * This will parse every file ending with .php, .php3 and .phtml in <directory
30
 * to parse> and then output a HTML site containing easily readable documentation
31
 * in <output directory>.
32
 *
33
 * phpDocumentor will try to look for a phpdoc.dist.xml or phpdoc.xml file in your
34
 * current working directory and use that to override the default settings if
35
 * present. In the configuration file can you specify the same settings (and
36
 * more) as the command line provides.
37
 */
38
class RunCommand extends Command
39
{
40
    /**
41
     * Initializes this command and sets the name, description, options and
42
     * arguments.
43
     *
44
     * @return void
45
     */
46
    protected function configure()
47
    {
48
        $this->setName('project:run')
49
            ->setAliases(array('run'))
50
            ->setDescription(
51
                'Parses and transforms the given files to a specified location'
52
            )
53
            ->setHelp(
54
<<<HELP
55
phpDocumentor creates documentation from PHP source files. The simplest way
56
to use it is:
57
58
    <info>$ phpdoc run -d [directory to parse] -t [output directory]</info>
59
60
This will parse every file ending with .php, .php3 and .phtml in <directory
61
to parse> and then output a HTML site containing easily readable documentation
62
in <output directory>.
63
64
phpDocumentor will try to look for a phpdoc.dist.xml or phpdoc.xml file in your
65
current working directory and use that to override the default settings if
66
present. In the configuration file can you specify the same settings (and
67
more) as the command line provides.
68
69
<comment>Other commands</comment>
70
In addition to this command phpDocumentor also supports additional commands:
71
72
<comment>Available commands:</comment>
73
<info>  help
74
  list
75
  parse
76
  run
77
  transform
78
<comment>project</comment>
79
  project:parse
80
  project:run
81
  project:transform
82
<comment>template</comment>
83
  template:generate
84
  template:list
85
  template:package</info>
86
87
You can get a more detailed listing of the commands using the <info>list</info>
88
command and get help by prepending the word <info>help</info> to the command
89
name.
90
HELP
91
            )
92
            ->addOption(
93
                'target',
94
                't',
95
                InputOption::VALUE_OPTIONAL,
96
                'Path where to store the generated output'
97
            )
98
            ->addOption(
99
                'cache-folder',
100
                null,
101
                InputOption::VALUE_OPTIONAL,
102
                'Path where to store the cache files'
103
            )
104
            ->addOption(
105
                'filename',
106
                'f',
107
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
108
                'Comma-separated list of files to parse. The wildcards ? and * are supported'
109
            )
110
            ->addOption(
111
                'directory',
112
                'd',
113
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
114
                'Comma-separated list of directories to (recursively) parse'
115
            )
116
            ->addOption(
117
                'encoding',
118
                null,
119
                InputOption::VALUE_OPTIONAL,
120
                'encoding to be used to interpret source files with'
121
            )
122
            ->addOption(
123
                'extensions',
124
                'e',
125
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
126
                'Comma-separated list of extensions to parse, defaults to php, php3 and phtml'
127
            )
128
            ->addOption(
129
                'ignore',
130
                'i',
131
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
132
                'Comma-separated list of file(s) and directories (relative to the source-code directory) that will be '
133
                . 'ignored. Wildcards * and ? are supported'
134
            )
135
            ->addOption(
136
                'ignore-tags',
137
                null,
138
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
139
                'Comma-separated list of tags that will be ignored, defaults to none. package, subpackage and ignore '
140
                . 'may not be ignored.'
141
            )
142
            ->addOption(
143
                'hidden',
144
                null,
145
                InputOption::VALUE_NONE,
146
                'Use this option to tell phpDocumentor to parse files and directories that begin with a period (.), '
147
                . 'by default these are ignored'
148
            )
149
            ->addOption(
150
                'ignore-symlinks',
151
                null,
152
                InputOption::VALUE_NONE,
153
                'Ignore symlinks to other files or directories, default is on'
154
            )
155
            ->addOption(
156
                'markers',
157
                'm',
158
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
159
                'Comma-separated list of markers/tags to filter'
160
            )
161
            ->addOption(
162
                'title',
163
                null,
164
                InputOption::VALUE_OPTIONAL,
165
                'Sets the title for this project; default is the phpDocumentor logo'
166
            )
167
            ->addOption(
168
                'force',
169
                null,
170
                InputOption::VALUE_NONE,
171
                'Forces a full build of the documentation, does not increment existing documentation'
172
            )
173
            ->addOption(
174
                'validate',
175
                null,
176
                InputOption::VALUE_NONE,
177
                'Validates every processed file using PHP Lint, costs a lot of performance'
178
            )
179
            ->addOption(
180
                'visibility',
181
                null,
182
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
183
                'Specifies the parse visibility that should be displayed in the documentation (comma separated e.g. '
184
                . '"public,protected")'
185
            )
186
            ->addOption(
187
                'defaultpackagename',
188
                null,
189
                InputOption::VALUE_OPTIONAL,
190
                'Name to use for the default package.',
191
                'Default'
192
            )
193
            ->addOption(
194
                'sourcecode',
195
                null,
196
                InputOption::VALUE_NONE,
197
                'Whether to include syntax highlighted source code'
198
            )
199
            ->addOption(
200
                'progressbar',
201
                'p',
202
                InputOption::VALUE_NONE,
203
                'Whether to show a progress bar; will automatically quiet logging to stdout'
204
            )
205
            ->addOption(
206
                'template',
207
                null,
208
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
209
                'Name of the template to use (optional)'
210
            )
211
            ->addOption(
212
                'parseprivate',
213
                null,
214
                InputOption::VALUE_NONE,
215
                'Whether to parse DocBlocks marked with @internal tag'
216
            );
217
218
        parent::configure();
219
    }
220
221
    /**
222
     * Executes the business logic involved with this command.
223
     *
224
     * @param \Symfony\Component\Console\Input\InputInterface   $input
225
     * @param \Symfony\Component\Console\Output\OutputInterface $output
226
     *
227
     * @return int
228
     */
229
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
This operation has 200 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

You can also find more information in the “Code” section of your repository.

Loading history...
230
    {
231
        $parse_command     = $this->getApplication()->find('project:parse');
232
        $transform_command = $this->getApplication()->find('project:transform');
233
234
        $parse_input = new ArrayInput(
235
            array(
236
                 'command'              => 'project:parse',
237
                 '--filename'           => $input->getOption('filename'),
238
                 '--directory'          => $input->getOption('directory'),
239
                 '--encoding'           => $input->getOption('encoding'),
240
                 '--extensions'         => $input->getOption('extensions'),
241
                 '--ignore'             => $input->getOption('ignore'),
242
                 '--ignore-tags'        => $input->getOption('ignore-tags'),
243
                 '--hidden'             => $input->getOption('hidden'),
244
                 '--ignore-symlinks'    => $input->getOption('ignore-symlinks'),
245
                 '--markers'            => $input->getOption('markers'),
246
                 '--title'              => $input->getOption('title'),
247
                 '--target'             => $input->getOption('cache-folder') ?: $input->getOption('target'),
248
                 '--force'              => $input->getOption('force'),
249
                 '--validate'           => $input->getOption('validate'),
250
                 '--visibility'         => $input->getOption('visibility'),
251
                 '--defaultpackagename' => $input->getOption('defaultpackagename'),
252
                 '--sourcecode'         => $input->getOption('sourcecode'),
253
                 '--parseprivate'       => $input->getOption('parseprivate'),
254
                 '--progressbar'        => $input->getOption('progressbar'),
255
                 '--log'                => $input->getOption('log')
256
            ),
257
            $this->getDefinition()
258
        );
259
260
        $return_code = $parse_command->run($parse_input, $output);
261
        if ($return_code !== 0) {
262
            return $return_code;
263
        }
264
265
        $transform_input = new ArrayInput(
266
            array(
267
                 'command'       => 'project:transform',
268
                 '--source'      => $input->getOption('cache-folder') ?: $input->getOption('target'),
269
                 '--target'      => $input->getOption('target'),
270
                 '--template'    => $input->getOption('template'),
271
                 '--progressbar' => $input->getOption('progressbar'),
272
                 '--log'         => $input->getOption('log')
273
            )
274
        );
275
        $return_code = $transform_command->run($transform_input, $output);
276
        if ($return_code !== 0) {
277
            return $return_code;
278
        }
279
280
        if ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG) {
281
            /** @var ProjectDescriptorBuilder $descriptorBuilder */
282
            $descriptorBuilder = $this->getService('descriptor.builder');
283
            file_put_contents('ast.dump', serialize($descriptorBuilder->getProjectDescriptor()));
284
        }
285
286
        return 0;
287
    }
288
}
289