Failed Conditions
Pull Request — master (#39)
by Tobias
10:29
created

src/PuliApplicationConfig.php (8 issues)

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
3
/*
4
 * This file is part of the puli/cli package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Cli;
13
14
use Puli\Cli\Handler\BindCommandHandler;
15
use Puli\Cli\Handler\BuildCommandHandler;
16
use Puli\Cli\Handler\CatCommandHandler;
17
use Puli\Cli\Handler\ConfigCommandHandler;
18
use Puli\Cli\Handler\FindCommandHandler;
19
use Puli\Cli\Handler\InstallerCommandHandler;
20
use Puli\Cli\Handler\LsCommandHandler;
21
use Puli\Cli\Handler\MapCommandHandler;
22
use Puli\Cli\Handler\ModuleCommandHandler;
23
use Puli\Cli\Handler\PluginCommandHandler;
24
use Puli\Cli\Handler\PublishCommandHandler;
25
use Puli\Cli\Handler\SelfUpdateCommandHandler;
26
use Puli\Cli\Handler\ServerCommandHandler;
27
use Puli\Cli\Handler\TreeCommandHandler;
28
use Puli\Cli\Handler\TypeCommandHandler;
29
use Puli\Cli\Handler\UpgradeCommandHandler;
30
use Puli\Cli\Handler\UrlCommandHandler;
31
use Puli\Cli\Proxy\DiscoveryManagerProxy;
32
use Puli\Cli\Proxy\RepositoryManagerProxy;
33
use Puli\Manager\Api\Container;
34
use Puli\Manager\Api\Context\ProjectContext;
35
use Puli\Manager\Api\Module\InstallInfo;
36
use Puli\Manager\Api\Module\ModuleFile;
37
use Puli\Manager\Api\Server\Server;
38
use Puli\Manager\Module\ModuleFileConverter;
39
use Webmozart\Console\Api\Args\Format\Argument;
40
use Webmozart\Console\Api\Args\Format\Option;
41
use Webmozart\Console\Api\Event\ConsoleEvents;
42
use Webmozart\Console\Api\Event\PreHandleEvent;
43
use Webmozart\Console\Api\Formatter\Style;
44
use Webmozart\Console\Config\DefaultApplicationConfig;
45
46
/**
47
 * The configuration of the Puli CLI.
48
 *
49
 * @since  1.0
50
 *
51
 * @author Bernhard Schussek <[email protected]>
52
 * @author Stephan Wentz <[email protected]>
53
 */
54
class PuliApplicationConfig extends DefaultApplicationConfig
55
{
56
    /**
57
     * The version of the Puli CLI.
58
     */
59
    const VERSION = '@package_version@';
60
61
    /**
62
     * @var Container
63
     */
64
    private $puli;
65
66
    /**
67
     * Creates the configuration.
68
     *
69
     * @param Container $puli The Puli service container
70
     */
71
    public function __construct(Container $puli = null)
72
    {
73
        // Start Puli already so that plugins can change the CLI configuration
74
        $this->puli = $puli ?: new Container(getcwd());
75
76
        if (!$this->puli->isStarted()) {
77
            $this->puli->start();
78
        }
79
80
        parent::__construct();
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    protected function configure()
87
    {
88
        // Make sure the console and Puli use the same event dispatcher so that
89
        // Puli plugins can listen to the console events.
90
        // Add the dispatcher before parent::configure() so that the parent
91
        // listeners don't get overwritten.
92
        $this->setEventDispatcher($this->puli->getEventDispatcher());
93
94
        parent::configure();
95
96
        $puli = $this->puli;
97
        $context = $this->puli->getContext();
98
99
        $this
100
            ->setName('puli')
101
            ->setDisplayName('Puli')
102
            ->setVersion(self::VERSION)
103
104
            // Enable debug for unreleased versions only. Split the string to
105
            // prevent its replacement during release
106
            ->setDebug('@pack'.'age_version@' === self::VERSION)
107
108
            ->addStyle(Style::tag('good')->fgGreen())
109
            ->addStyle(Style::tag('bad')->fgRed())
110
        ;
111
112
        if ($context instanceof ProjectContext) {
113
            // Don't do a version check in the global context (if not in a project)
114
            $this->addEventListener(
115
                ConsoleEvents::PRE_HANDLE,
116
                function (PreHandleEvent $event) use ($context) {
117
                    $io = $event->getIO();
118
                    $moduleFile = $context->getRootModuleFile();
119
120
                    // Don't show warning for "upgrade" command
121
                    if ('upgrade' === $event->getCommand()->getName()) {
122
                        return;
123
                    }
124
125
                    if (version_compare($moduleFile->getVersion(), ModuleFileConverter::VERSION, '<')) {
126
                        $io->errorLine(sprintf(
127
                            '<warn>Warning: Your puli.json file has version %s, '.
128
                            'but the latest version is %s. Run "puli upgrade" to '.
129
                            'upgrade to %s.</warn>',
130
                            $moduleFile->getVersion(),
131
                            ModuleFileConverter::VERSION,
132
                            ModuleFileConverter::VERSION
133
                        ));
134
                    }
135
                }
136
            );
137
        }
138
139
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
140
            ->beginCommand('bind')
141
                ->setDescription('Bind resources to binding types')
142
                ->setHandler(function () use ($puli) {
143
                    return new BindCommandHandler(
144
                        $puli->getDiscoveryManager(),
145
                        $puli->getModuleManager()->getModules()
146
                    );
147
                })
148
149
                ->beginOptionCommand('add')
150
                    ->markAnonymous()
151
                    ->addArgument('artifact', Argument::REQUIRED, 'A class name or a query for resources')
152
                    ->addArgument('type', Argument::REQUIRED, 'The name of the binding type')
153
                    ->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the resource query', 'glob', 'language')
154
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A binding parameter in the form <key>=<value>', null, 'key=value')
155
                    ->addOption('class', null, Option::NO_VALUE, 'Force adding of a class binding')
156
                    ->addOption('force', 'f', Option::NO_VALUE, 'Add binding even if the binding type does not exist')
157
                    ->setHandlerMethod('handleAdd')
158
                ->end()
159
160
                ->beginOptionCommand('list')
161
                    ->markDefault()
162
                    ->addOption('root', null, Option::NO_VALUE, 'Show bindings of the root module')
163
                    ->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show bindings of a module', null, 'module')
164
                    ->addOption('all', 'a', Option::NO_VALUE, 'Show bindings of all modules')
165
                    ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled bindings')
166
                    ->addOption('disabled', null, Option::NO_VALUE, 'Show disabled bindings')
167
                    ->addOption('type-not-found', null, Option::NO_VALUE, 'Show bindings whose type is not found')
168
                    ->addOption('type-not-enabled', null, Option::NO_VALUE, 'Show bindings whose type is not enabled')
169
                    ->addOption('ignored', null, Option::NO_VALUE, 'Show bindings whose type is disabled')
170
                    ->addOption('invalid', null, Option::NO_VALUE, 'Show bindings with invalid parameters')
171
                    ->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the resource query', 'glob', 'language')
172
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A binding parameter in the form <key>=<value>', null, 'key=value')
173
                    ->setHandlerMethod('handleList')
174
                ->end()
175
176
                ->beginOptionCommand('update', 'u')
177
                    ->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the updated binding')
178
                    ->addOption('query', null, Option::REQUIRED_VALUE, 'A query for resources')
179
                    ->addOption('class', null, Option::REQUIRED_VALUE, 'A class name')
180
                    ->addOption('type', null, Option::REQUIRED_VALUE, 'The name of the binding type')
181
                    ->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the resource query', null, 'language')
182
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A binding parameter in the form <key>=<value>', null, 'key=value')
183
                    ->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Unset a binding parameter', null, 'key')
184
                    ->addOption('force', 'f', Option::NO_VALUE, 'Update binding even if the binding type does not exist')
185
                    ->setHandlerMethod('handleUpdate')
186
                ->end()
187
188
                ->beginOptionCommand('delete', 'd')
189
                    ->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the removed binding')
190
                    ->setHandlerMethod('handleDelete')
191
                ->end()
192
193
                ->beginOptionCommand('enable')
194
                    ->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the enabled binding')
195
                    ->setHandlerMethod('handleEnable')
196
                ->end()
197
198
                ->beginOptionCommand('disable')
199
                    ->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the disabled binding')
200
                    ->setHandlerMethod('handleDisable')
201
                ->end()
202
            ->end()
203
        ;
204
205
        $this
206
            ->beginCommand('build')
207
                ->setDescription('Build the resource repository/discovery')
208
                ->addArgument('target', Argument::OPTIONAL, 'The build target. One of "repository", "discovery", "factory" and "all"', 'all')
209
                ->setHandler(function () use ($puli) {
210
                    return new BuildCommandHandler(
211
                        // Use proxies to make sure this command runs even if
212
                        // the factory file is corrupt. If the file is corrupt,
213
                        // we get an error when loading the actual managers.
214
                        new RepositoryManagerProxy($puli),
215
                        new DiscoveryManagerProxy($puli),
216
                        $puli->getFactoryManager()
217
                    );
218
                })
219
            ->end()
220
        ;
221
222
        $this
223
            ->beginCommand('cat')
224
                ->setDescription('Concatenate a file resource in the repository')
225
                ->addArgument('path', Argument::REQUIRED, 'The path of a resource')
226
                ->setHandler(function () use ($puli) {
227
                    return new CatCommandHandler(
228
                        $puli->getRepository()
229
                    );
230
                })
231
            ->end()
232
        ;
233
234
        $this
235
            ->beginCommand('config')
236
                ->setDescription('Display and modify configuration values')
237
                ->setHandler(function () use ($puli) {
238
                    return new ConfigCommandHandler($puli->getRootModuleFileManager());
239
                })
240
241
                ->beginSubCommand('list')
242
                    ->markDefault()
243
                    ->addOption('parsed', null, Option::NO_VALUE, 'Replace placeholders by their values in the output')
244
                    ->setHandlerMethod('handleList')
245
                ->end()
246
247
                ->beginSubCommand('show')
248
                    ->markAnonymous()
249
                    ->addArgument('key', Argument::REQUIRED, 'The configuration key to show. May contain wildcards ("*")')
250
                    ->addOption('parsed', null, Option::NO_VALUE, 'Replace placeholders by their values in the output')
251
                    ->setHandlerMethod('handleShow')
252
                ->end()
253
254
                ->beginSubCommand('set')
255
                    ->markAnonymous()
256
                    ->addArgument('key', Argument::REQUIRED, 'The modified configuration key')
257
                    ->addArgument('value', Argument::REQUIRED, 'The value to set for the configuration key')
258
                    ->setHandlerMethod('handleSet')
259
                ->end()
260
261
                ->beginOptionCommand('reset', 'r')
262
                    ->addArgument('key', Argument::REQUIRED, 'The configuration key(s) to reset. May contain wildcards ("*")')
263
                    ->setHandlerMethod('handleReset')
264
                ->end()
265
            ->end()
266
        ;
267
268
        $this
269
            ->beginCommand('find')
270
                ->setDescription('Find resources by different criteria')
271
                ->addOption('path', null, Option::REQUIRED_VALUE, 'The resource path. May contain the wildcard "*"')
272
                ->addOption('name', null, Option::REQUIRED_VALUE, 'The resource filename. May contain the wildcard "*"')
273
                ->addOption('class', null, Option::REQUIRED_VALUE, 'The short name of a resource class')
274
                ->addOption('type', null, Option::REQUIRED_VALUE, 'The name of a binding type')
275
                ->addOption('language', null, Option::REQUIRED_VALUE, 'The language of the query passed with --path', 'glob')
276
                ->setHandler(function () use ($puli) {
277
                    return new FindCommandHandler(
278
                        $puli->getRepository(),
279
                        $puli->getDiscovery()
280
                    );
281
                })
282
            ->end()
283
        ;
284
285
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
286
            ->beginCommand('installer')
287
                ->setDescription('Manage the installers used to install web resources')
288
                ->setHandler(function () use ($puli) {
289
                    return new InstallerCommandHandler($puli->getInstallerManager());
290
                })
291
292
                ->beginOptionCommand('list')
293
                    ->markDefault()
294
                    ->addOption('long', 'l', Option::NO_VALUE, 'Print the fully-qualified class name')
295
                    ->setHandlerMethod('handleList')
296
                ->end()
297
298
                ->beginOptionCommand('add', 'a')
299
                    ->addArgument('name', Argument::REQUIRED, 'The name of the installer')
300
                    ->addArgument('class', Argument::REQUIRED, 'The fully-qualified class name of the installer')
301
                    ->addOption('description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'The description of the installer')
302
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional installer parameters')
303
                    ->setHandlerMethod('handleAdd')
304
                ->end()
305
306
                ->beginOptionCommand('delete', 'd')
307
                    ->addArgument('name', Argument::REQUIRED, 'The name of the installer to remove')
308
                    ->setHandlerMethod('handleDelete')
309
                ->end()
310
            ->end()
311
        ;
312
313
        $this
314
            ->beginCommand('ls')
315
                ->setDescription('List the children of a resource in the repository')
316
                ->addArgument('path', Argument::OPTIONAL, 'The path of a resource', '/')
317
                ->addOption('long', 'l', Option::NO_VALUE, 'Print more information about each child')
318
                ->setHandler(function () use ($puli) {
319
                    return new LsCommandHandler(
320
                        $puli->getRepository()
321
                    );
322
                })
323
            ->end()
324
        ;
325
326
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
327
            ->beginCommand('map')
328
                ->setDescription('Display and change path mappings')
329
                ->setHandler(function () use ($puli) {
330
                    return new MapCommandHandler(
331
                        $puli->getRepositoryManager(),
332
                        $puli->getModuleManager()->getModules()
333
                    );
334
                })
335
336
                ->beginOptionCommand('add')
337
                    ->markAnonymous()
338
                    ->addArgument('path', Argument::REQUIRED)
339
                    ->addArgument('file', Argument::REQUIRED | Argument::MULTI_VALUED)
340
                    ->addOption('force', 'f', Option::NO_VALUE, 'Map even if the target path does not exist')
341
                    ->setHandlerMethod('handleAdd')
342
                ->end()
343
344
                ->beginOptionCommand('list')
345
                    ->markDefault()
346
                    ->addOption('root', null, Option::NO_VALUE, 'Show mappings of the root module')
347
                    ->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show mappings of a module', null, 'module')
348
                    ->addOption('all', 'a', Option::NO_VALUE, 'Show mappings of all modules')
349
                    ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled mappings')
350
                    ->addOption('not-found', null, Option::NO_VALUE, 'Show mappings whose referenced paths do not exist')
351
                    ->addOption('conflict', null, Option::NO_VALUE, 'Show conflicting mappings')
352
                    ->setHandlerMethod('handleList')
353
                ->end()
354
355
                ->beginOptionCommand('update', 'u')
356
                    ->addArgument('path', Argument::REQUIRED)
357
                    ->addOption('add', 'a', Option::REQUIRED_VALUE | Option::MULTI_VALUED | Option::PREFER_LONG_NAME, 'Add a file to the path mapping', null, 'file')
358
                    ->addOption('remove', 'r', Option::REQUIRED_VALUE | Option::MULTI_VALUED | Option::PREFER_LONG_NAME, 'Remove a file from the path mapping', null, 'file')
359
                    ->addOption('force', 'f', Option::NO_VALUE, 'Map even if the target path does not exist')
360
                    ->setHandlerMethod('handleUpdate')
361
                ->end()
362
363
                ->beginOptionCommand('delete', 'd')
364
                    ->addArgument('path', Argument::REQUIRED)
365
                    ->addArgument('file', Argument::OPTIONAL)
366
                    ->setHandlerMethod('handleDelete')
367
                ->end()
368
            ->end()
369
        ;
370
371
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
372
            ->beginCommand('module')
373
                ->setDescription('Display the installed modules')
374
                ->setHandler(function () use ($puli) {
375
                    return new ModuleCommandHandler($puli->getModuleManager());
376
                })
377
378
                ->beginOptionCommand('install', 'i')
379
                    ->addArgument('path', Argument::REQUIRED, 'The path to the module')
380
                    ->addArgument('name', Argument::OPTIONAL, 'The name of the module. Taken from puli.json if not passed.')
381
                    ->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the installer', InstallInfo::DEFAULT_INSTALLER_NAME)
382
                    ->addOption('dev', null, Option::NO_VALUE, 'Install the module in the development environment')
383
                    ->setHandlerMethod('handleInstall')
384
                ->end()
385
386
                ->beginOptionCommand('list')
387
                    ->markDefault()
388
                    ->addOption('installer', null, Option::REQUIRED_VALUE, 'Show modules installed by a specific installer')
389
                    ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled modules')
390
                    ->addOption('not-found', null, Option::NO_VALUE, 'Show modules that could not be found')
391
                    ->addOption('not-loadable', null, Option::NO_VALUE, 'Show modules that could not be loaded')
392
                    ->addOption('dev', null, Option::NO_VALUE, 'Show modules of the development environment')
393
                    ->addOption('prod', null, Option::NO_VALUE, 'Show modules of the production environment')
394
                    ->addOption('format', null, Option::REQUIRED_VALUE, 'The format of the output. You can use the variables %name%, %install_path%, %installer% and %state% in the format string', null, 'format')
395
                    ->setHandlerMethod('handleList')
396
                ->end()
397
398
                ->beginOptionCommand('rename')
399
                    ->addArgument('name', Argument::REQUIRED, 'The name of the module')
400
                    ->addArgument('new-name', Argument::REQUIRED, 'The new name of the module')
401
                    ->setHandlerMethod('handleRename')
402
                ->end()
403
404
                ->beginOptionCommand('delete', 'd')
405
                    ->addArgument('name', Argument::REQUIRED, 'The name of the module')
406
                    ->setHandlerMethod('handleDelete')
407
                ->end()
408
409
                ->beginOptionCommand('clean')
410
                    ->setHandlerMethod('handleClean')
411
                ->end()
412
            ->end()
413
        ;
414
415
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
416
            ->beginCommand('plugin')
417
                ->setDescription('Manage the installed Puli plugins')
418
                ->setHandler(function () use ($puli) {
419
                    return new PluginCommandHandler($puli->getRootModuleFileManager());
420
                })
421
422
                ->beginOptionCommand('install', 'i')
423
                    ->addArgument('class', Argument::REQUIRED, 'The fully-qualified plugin class name')
424
                    ->setHandlerMethod('handleInstall')
425
                ->end()
426
427
                ->beginOptionCommand('list')
428
                    ->markDefault()
429
                    ->setHandlerMethod('handleList')
430
                ->end()
431
432
                ->beginOptionCommand('delete', 'd')
433
                    ->addArgument('class', Argument::REQUIRED, 'The fully-qualified plugin class name')
434
                    ->setHandlerMethod('handleDelete')
435
                ->end()
436
            ->end()
437
        ;
438
439
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
440
            ->beginCommand('publish')
441
                ->setDescription('Manage public resources')
442
                ->setHandler(function () use ($puli) {
443
                    return new PublishCommandHandler(
444
                        $puli->getAssetManager(),
445
                        $puli->getInstallationManager(),
446
                        $puli->getServerManager()
447
                    );
448
                })
449
450
                ->beginOptionCommand('add')
451
                    ->markAnonymous()
452
                    ->addArgument('path', Argument::REQUIRED, 'The resource path')
453
                    ->addArgument('server', Argument::REQUIRED, 'The resource path')
454
                    ->addArgument('server-path', Argument::OPTIONAL, 'The path in the document root of the server', '/')
455
                    ->addOption('force', 'f', Option::NO_VALUE, 'Map even if the server does not exist')
456
                    ->setHandlerMethod('handleAdd')
457
                ->end()
458
459
                ->beginOptionCommand('update', 'u')
460
                    ->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')
461
                    ->addOption('path', null, Option::REQUIRED_VALUE, 'The resource path')
462
                    ->addOption('server', 's', Option::REQUIRED_VALUE | Option::PREFER_LONG_NAME, 'The name of the target server')
463
                    ->addOption('server-path', null, Option::REQUIRED_VALUE, 'The path in the document root')
464
                    ->addOption('force', 'f', Option::NO_VALUE, 'Update even if the server does not exist')
465
                    ->setHandlerMethod('handleUpdate')
466
                ->end()
467
468
                ->beginOptionCommand('delete', 'd')
469
                    ->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')
470
                    ->setHandlerMethod('handleDelete')
471
                ->end()
472
473
                ->beginOptionCommand('list', 'l')
474
                    ->markDefault()
475
                    ->setHandlerMethod('handleList')
476
                ->end()
477
478
                ->beginOptionCommand('install')
479
                    ->addArgument('server', Argument::OPTIONAL, 'The server to install. By default, all servers are installed')
480
                    ->setHandlerMethod('handleInstall')
481
                ->end()
482
            ->end()
483
        ;
484
485
        $this
486
            ->beginCommand('self-update')
487
                ->setDescription('Update Puli to the latest version.')
488
                ->addOption('stable', null, Option::NO_VALUE, 'Update to the latest stable version')
489
                ->addOption('unstable', null, Option::NO_VALUE, 'Update to the latest unstable version')
490
                ->setHandler(function () {
491
                    return new SelfUpdateCommandHandler();
492
                })
493
                ->enableIf('phar://' === substr(__DIR__, 0, 7))
494
            ->end()
495
        ;
496
497
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
498
            ->beginCommand('server')
499
                ->setDescription('Manage your asset servers')
500
                ->setHandler(function () use ($puli) {
501
                    return new ServerCommandHandler($puli->getServerManager());
502
                })
503
504
                ->beginOptionCommand('list')
505
                    ->markDefault()
506
                    ->setHandlerMethod('handleList')
507
                ->end()
508
509
                ->beginOptionCommand('add', 'a')
510
                    ->addArgument('name', Argument::REQUIRED, 'The name of the added server')
511
                    ->addArgument('document-root', Argument::REQUIRED, 'The document root of the server')
512
                    ->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')
513
                    ->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', Server::DEFAULT_URL_FORMAT)
514
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters required by the resource installer')
515
                    ->setHandlerMethod('handleAdd')
516
                ->end()
517
518
                ->beginOptionCommand('update', 'u')
519
                    ->addArgument('name', Argument::REQUIRED, 'The name of the updated server')
520
                    ->addOption('document-root', null, Option::REQUIRED_VALUE, 'The document root of the server')
521
                    ->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')
522
                    ->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', Server::DEFAULT_URL_FORMAT)
523
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters required by the resource installer')
524
                    ->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Parameters to remove from the server')
525
                    ->setHandlerMethod('handleUpdate')
526
                ->end()
527
528
                ->beginOptionCommand('delete', 'd')
529
                    ->addArgument('name', Argument::REQUIRED, 'The name of the server to remove')
530
                    ->setHandlerMethod('handleDelete')
531
                ->end()
532
            ->end()
533
        ;
534
535
        $this
536
            ->beginCommand('tree')
537
                ->setDescription('Print the contents of a resource as tree')
538
                ->addArgument('path', Argument::OPTIONAL, 'The path of a resource', '/')
539
                ->setHandler(function () use ($puli) {
540
                    return new TreeCommandHandler($puli->getRepository());
541
                })
542
            ->end()
543
        ;
544
545
        $this
0 ignored issues
show
The method beginOptionCommand does only exist in Webmozart\Console\Api\Config\CommandConfig, but not in Webmozart\Console\Api\Config\ApplicationConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
546
            ->beginCommand('type')
547
                ->setDescription('Display and change binding types')
548
                ->setHandler(function () use ($puli) {
549
                    return new TypeCommandHandler(
550
                        $puli->getDiscoveryManager(),
551
                        $puli->getModuleManager()->getModules()
552
                    );
553
                })
554
555
                ->beginOptionCommand('define')
556
                    ->addArgument('name', Argument::REQUIRED, 'The name of the binding type')
557
                    ->addOption('description', null, Option::REQUIRED_VALUE, 'A human-readable description of the type')
558
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A type parameter in the form <key> or <key>=<value>', null, 'key=value')
559
                    ->addOption('param-description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A human-readable parameter description in the form <key>=<description>', null, 'key=description')
560
                    ->addOption('force', 'f', Option::NO_VALUE, 'Add type even if another type exists with the same name')
561
                    ->setHandlerMethod('handleDefine')
562
                ->end()
563
564
                ->beginSubCommand('list')
565
                    ->markDefault()
566
                    ->addOption('root', null, Option::NO_VALUE, 'Show types of the root module')
567
                    ->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show types of a module', null, 'module')
568
                    ->addOption('all', 'a', Option::NO_VALUE, 'Show types of all modules')
569
                    ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled types')
570
                    ->addOption('duplicate', null, Option::NO_VALUE, 'Show duplicate types')
571
                    ->setHandlerMethod('handleList')
572
                ->end()
573
574
                ->beginOptionCommand('update', 'u')
575
                    ->addArgument('name', Argument::REQUIRED, 'The name of the binding type')
576
                    ->addOption('description', null, Option::REQUIRED_VALUE, 'A human-readable description of the type')
577
                    ->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A type parameter in the form <key> or <key>=<value>', null, 'key=value')
578
                    ->addOption('param-description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'A human-readable parameter description in the form <key>=<description>', null, 'key=description')
579
                    ->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Unset a type parameter', null, 'key')
580
                    ->setHandlerMethod('handleUpdate')
581
                ->end()
582
583
                ->beginOptionCommand('delete', 'd')
584
                    ->addArgument('name', Argument::REQUIRED, 'The name of the binding type')
585
                    ->setHandlerMethod('handleDelete')
586
                ->end()
587
            ->end()
588
        ;
589
590
        $this
591
            ->beginCommand('upgrade')
592
                ->setDescription('Upgrades puli.json to the newest version')
593
                ->addArgument('version', Argument::OPTIONAL, 'The version to upgrade/downgrade to', ModuleFileConverter::VERSION)
594
                ->setHandler(function () use ($puli) {
595
                    return new UpgradeCommandHandler($puli->getRootModuleFileManager());
596
                })
597
            ->end()
598
        ;
599
600
        $this
601
            ->beginCommand('url')
602
                ->setDescription('Generate the URL of a public resource')
603
                ->addArgument('path', Argument::REQUIRED | Argument::MULTI_VALUED, 'The path of a resource')
604
                ->setHandler(function () use ($puli) {
605
                    return new UrlCommandHandler(
606
                        $puli->getUrlGenerator(),
607
                        $puli->getRepository()
608
                    );
609
                })
610
            ->end()
611
        ;
612
    }
613
}
614