CrawlUrlCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 65
ccs 0
cts 38
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 32 1
A execute() 0 12 2
A handlePage() 0 3 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
    protected function configure()
20
    {
21
        $this
22
            ->setName('mediamonks:crawler:crawl-url')
23
            ->setDescription('Crawl an url')
24
            ->addArgument(
25
                self::ARGUMENT_URL,
26
                InputArgument::REQUIRED,
27
                'Url of the site you want to crawl'
28
            )
29
            ->addOption(
30
                self::OPTION_LIMIT,
31
                null,
32
                InputOption::VALUE_OPTIONAL,
33
                'Limit number of pages to crawl',
34
                0
35
            )
36
            ->addOption(
37
                self::OPTION_STOP_ON_ERROR,
38
                null,
39
                InputOption::VALUE_OPTIONAL,
40
                'Stop when a page could not be requested',
41
                false
42
            )
43
            ->addOption(
44
                self::OPTION_EXCEPTION_ON_ERROR,
45
                null,
46
                InputOption::VALUE_OPTIONAL,
47
                'Throw exception when a page could not be requested',
48
                false
49
            );
50
    }
51
52
    /**
53
     * @param InputInterface $input
54
     * @param OutputInterface $output
55
     * @return void
56
     */
57
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59
        $crawler = $this->getContainer()->get('mediamonks_crawler.crawler');
60
61
        $crawler->setLimit((int)$input->getOption(self::OPTION_LIMIT));
62
        $crawler->setStopOnError((bool)$input->getOption(self::OPTION_STOP_ON_ERROR));
63
        $crawler->setExceptionOnError((bool)$input->getOption(self::OPTION_EXCEPTION_ON_ERROR));
64
65
        foreach ($crawler->crawl($input->getArgument('url')) as $page) {
66
            $this->handlePage($page);
67
        }
68
    }
69
70
    /**
71
     * @param Page $page
72
     */
73
    protected function handlePage(Page $page)
0 ignored issues
show
Unused Code introduced by
The parameter $page is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
    }
76
}
77