SearchCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
cbo 5
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A execute() 0 19 2
1
<?php
2
3
/*
4
 * This file is part of Bowerphp.
5
 *
6
 * (c) Mauro D'Alatri <[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 Bowerphp\Command;
13
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Search
20
 */
21
class SearchCommand extends Command
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function configure()
27
    {
28
        $this
29
            ->setName('search')
30
            ->setDescription('Search for a package by name')
31
            ->addArgument('name', InputArgument::REQUIRED, 'Name to search for.')
32
            ->setHelp(<<<'EOT'
33
The <info>%command.name%</info> command searches for a package by name.
34
35
  <info>php %command.full_name% name</info>
36
EOT
37
            );
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $this->setGithubToken($output);
46
47
        $name = $input->getArgument('name');
48
49
        $bowerphp = $this->getBowerphp($output);
50
        $packages = $bowerphp->searchPackages($name);
51
52
        if (empty($packages)) {
53
            $output->writeln('No results.');
54
        } else {
55
            $output->writeln('Search results:' . PHP_EOL);
56
            $consoleOutput = $this->consoleOutput;
57
            array_walk($packages, function ($package) use ($consoleOutput) {
58
                $consoleOutput->writelnSearchOrLookup($package['name'], $package['url'], 4);
59
            });
60
        }
61
    }
62
}
63