FetchCommand::execute()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 30
ccs 23
cts 23
cp 1
rs 8.8571
cc 2
eloc 21
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Innmind\RestBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class FetchCommand extends ContainerAwareCommand
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 2
    protected function configure()
16
    {
17 2
        $this
18 2
            ->setName('innmind:rest:fetch')
19 2
            ->setDescription(
20
                'Fetch all the resource definitions from the given server'
21 2
            )
22 2
            ->addArgument('server', InputArgument::REQUIRED);
23 2
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30 2
        $server = $input->getArgument('server');
31
32 2
        $capabilities = $this
33 2
            ->getContainer()
34 2
            ->get('innmind_rest.client.capabilities_factory')
35 2
            ->make($server);
36 2
        $loader = $this
37 2
            ->getContainer()
38 2
            ->get('innmind_rest.client.loader_factory')
39 2
            ->make($server);
40
41 2
        $output->writeln(sprintf(
42 2
            'Fetching exposed resources at <fg=cyan>%s</fg=cyan>',
43
            $server
44 2
        ));
45 2
        $capabilities->refresh();
46
47 2
        foreach ($capabilities->keys() as $name => $url) {
48 2
            $output->writeln(sprintf(
49 2
                'Fetching definition for the resource "<fg=cyan>%s</fg=cyan>" at "<fg=cyan>%s</fg=cyan>"',
50 2
                $name,
51
                $url
52 2
            ));
53 2
            $loader->refresh($url);
54 2
        }
55
56 2
        $output->writeln('<success>All definitions loaded</success>');
57 2
    }
58
}
59