Completed
Push — master ( 9595c4...4e2149 )
by Antoine
06:18
created

All::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 9.0856
cc 1
eloc 15
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Geotools library.
5
 *
6
 * (c) Antoine Corcy <[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 League\Geotools\CLI\Command\Distance;
13
14
use League\Geotools\Coordinate\Coordinate;
15
use League\Geotools\Coordinate\Ellipsoid;
16
use League\Geotools\Geotools;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Command-line distance:all class
24
 *
25
 * @author Antoine Corcy <[email protected]>
26
 */
27
class All extends \Symfony\Component\Console\Command\Command
28
{
29 12
    protected function configure()
30
    {
31 12
        $availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();
32
33 12
        $this
34 12
            ->setName('distance:all')
35 12
            ->setDescription('Compute the distance between 2 coordinates using all algorithms, in meters by default')
36 12
            ->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
37 12
            ->addArgument('destination', InputArgument::REQUIRED, 'The destination "Lat,Long" coordinate')
38 12
            ->addOption('km', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in kilometers')
39 12
            ->addOption('mi', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in miles')
40 12
            ->addOption('ft', null, InputOption::VALUE_NONE, 'If set, the distance will be shown in feet')
41 12
            ->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED,
42 12
                'If set, the name of the ellipsoid to use', Ellipsoid::WGS84)
43 12
            ->setHelp(<<<EOT
44
<info>Available ellipsoids</info>: $availableEllipsoids
45
46
<info>Example with AIRY ellipsoid</info>:
47
48 12
    %command.full_name% "40° 26.7717, -79° 56.93172" "30°16′57″N 029°48′32″W" <comment>--ellipsoid=AIRY</comment>
49
EOT
50 12
            );
51 12
    }
52
53 11
    protected function execute(InputInterface $input, OutputInterface $output)
54
    {
55 11
        $ellipsoid = Ellipsoid::createFromName($input->getOption('ellipsoid'));
56 9
        $from      = new Coordinate($input->getArgument('origin'), $ellipsoid);
57 8
        $to        = new Coordinate($input->getArgument('destination'), $ellipsoid);
58
59 8
        $geotools = new Geotools;
60 8
        $distance = $geotools->distance()->setFrom($from)->setTo($to);
61
62 8
        if ($input->getOption('km')) {
63 1
            $distance->in('km');
64 1
        }
65
66 8
        if ($input->getOption('mi')) {
67 2
            $distance->in('mi');
68 2
        }
69
70 8
        if ($input->getOption('ft')) {
71 2
            $distance->in('ft');
72 2
        }
73
74 8
        $result = array();
75 8
        $result[] = sprintf('<label>Flat:</label>      <value>%s</value>', $distance->flat());
76 8
        $result[] = sprintf('<label>Haversine:</label> <value>%s</value>', $distance->haversine());
77 8
        $result[] = sprintf('<label>Vincenty:</label>  <value>%s</value>', $distance->vincenty());
78
79 8
        $output->writeln($result);
80 8
    }
81
}
82