Completed
Push — master ( b0f294...520b8f )
by
unknown
03:58
created

CrawlUrlCommand::handlePage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 1
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
    const OPTION_STOP_ON_ERROR = 'stop-on-error';
17
    const OPTION_EXCEPTION_ON_ERROR = 'exception-on-error';
18
19 5
    protected function configure()
20
    {
21 5
        $this
22 5
            ->setName('mediamonks:crawler:crawl-url')
23 5
            ->setDescription('Crawl an url')
24 5
            ->addArgument(
25 5
                self::ARGUMENT_URL,
26 5
                InputArgument::REQUIRED,
27
                'Url of the site you want to crawl'
28 5
            )
29 5
            ->addOption(
30 5
                self::OPTION_LIMIT,
31 5
                null,
32 5
                InputOption::VALUE_OPTIONAL,
33 5
                'Limit number of pages to crawl',
34
                0
35 5
            )
36 5
            ->addOption(
37 5
                self::OPTION_STOP_ON_ERROR,
38 5
                null,
39 5
                InputOption::VALUE_OPTIONAL,
40 5
                'Stop when a page could not be requested',
41
                false
42 5
            )
43 5
            ->addOption(
44 5
                self::OPTION_EXCEPTION_ON_ERROR,
45 5
                null,
46 5
                InputOption::VALUE_OPTIONAL,
47 5
                'Throw exception when a page could not be requested',
48
                false
49 5
            );
50 5
    }
51
52
    /**
53
     * @param InputInterface $input
54
     * @param OutputInterface $output
55
     * @return void
56
     */
57 5
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59 5
        $crawler = $this->getContainer()->get('mediamonks_crawler.crawler');
60
61 5
        $crawler->setLimit((int)$input->getOption(self::OPTION_LIMIT));
62 5
        $crawler->setStopOnError((bool)$input->getOption(self::OPTION_STOP_ON_ERROR));
63 5
        $crawler->setExceptionOnError((bool)$input->getOption(self::OPTION_EXCEPTION_ON_ERROR));
64
65 5
        foreach ($crawler->crawl($input->getArgument('url')) as $page) {
66 5
            $this->handlePage($page);
67 5
        }
68 4
    }
69
70
    /**
71
     * @param Page $page
72
     */
73 5
    protected function handlePage(Page $page)
74
    {
75 5
    }
76
}
77