Completed
Push — master ( ce901a...e066e7 )
by
unknown
04:54
created

CrawlUrlCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 14
cts 14
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
crap 1
1
<?php
2
3
namespace MediaMonks\CrawlerBundle\Command;
4
5
use MediaMonks\Crawler\Page;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class CrawlUrlCommand extends ContainerAwareCommand
13
{
14
    const ARGUMENT_URL = 'url';
15
    const OPTION_LIMIT = 'limit';
16
17 1
    protected function configure()
18
    {
19 1
        $this
20 1
            ->setName('mediamonks:crawler:crawl-url')
21 1
            ->setDescription('Crawl an url')
22 1
            ->addArgument(
23 1
                self::ARGUMENT_URL,
24 1
                InputArgument::REQUIRED,
25
                'Url of the site you want to crawl'
26 1
            )
27 1
            ->addOption(
28 1
                self::OPTION_LIMIT,
29 1
                null,
30 1
                InputOption::VALUE_OPTIONAL,
31
                'Limit number of pages to crawl'
32 1
            )
33
        ;
34 1
    }
35
36
    /**
37
     * @param InputInterface $input
38
     * @param OutputInterface $output
39
     * @return void
40
     */
41 1
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43 1
        $crawler = $this->getContainer()->get('mediamonks_crawler.crawler');
44 1
        $crawler->setLimit((int)$input->getOption(self::OPTION_LIMIT));
45 1
        foreach ($crawler->crawl($input->getArgument('url')) as $page) {
46
            $this->handlePage($page);
47 1
        }
48 1
    }
49
50
    /**
51
     * @param Page $page
52
     */
53
    protected function handlePage(Page $page)
54
    {
55
        echo $page->getUrl() . PHP_EOL;
56
    }
57
}
58