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

Destination   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 38
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 21 1
A execute() 0 13 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\Vertex;
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 point:destination class
24
 *
25
 * @author Antoine Corcy <[email protected]>
26
 */
27
class Destination extends \Symfony\Component\Console\Command\Command
28
{
29 8
    protected function configure()
30
    {
31 8
        $availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();
32
33 8
        $this
34 8
            ->setName('vertex:destination')
35 8
            ->setDescription('Compute the destination coordinate with given bearing in degrees and a distance in meters')
36 8
            ->addArgument('origin', InputArgument::REQUIRED, 'The origin "Lat,Long" coordinate')
37 8
            ->addArgument('bearing', InputArgument::REQUIRED, 'The initial bearing in degrees')
38 8
            ->addArgument('distance', InputArgument::REQUIRED, 'The distance from the origin coordinate in meters')
39 8
            ->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED,
40 8
                'If set, the name of the ellipsoid to use', Ellipsoid::WGS84)
41 8
            ->setHelp(<<<EOT
42
<info>Available ellipsoids</info>: $availableEllipsoids
43
44
<info>Example with SOUTH_AMERICAN_1969 ellipsoid, 25 degrees and 10000 meters</info>:
45
46 8
    %command.full_name% "40° 26.7717, -79° 56.93172" 25 10000 <comment>--ellipsoid=SOUTH_AMERICAN_1969</comment>
47
EOT
48 8
            );
49 8
    }
50
51 7
    protected function execute(InputInterface $input, OutputInterface $output)
52
    {
53 7
        $from     = new Coordinate($input->getArgument('origin'), Ellipsoid::createFromName($input->getOption('ellipsoid')));
54 4
        $geotools = new Geotools;
55
56 4
        $destination = $geotools->vertex()->setFrom($from);
57 4
        $destination = $destination->destination($input->getArgument('bearing'), $input->getArgument('distance'));
58
59 4
        $output->writeln(sprintf(
60 4
            '<value>%s, %s</value>',
61 4
            $destination->getLatitude(), $destination->getLongitude()
62 4
        ));
63 4
    }
64
}
65