Completed
Push — master ( 520645...0aa38f )
by Antoine
03:23
created

DM::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1.0004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 12
cts 13
cp 0.9231
rs 8.8571
cc 1
eloc 13
nc 1
nop 0
crap 1.0004
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\Convert;
13
14
use League\Geotools\Convert\ConvertInterface;
15
use League\Geotools\Coordinate\Coordinate;
16
use League\Geotools\Coordinate\Ellipsoid;
17
use League\Geotools\Geotools;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * Command-line convert:dm class
25
 *
26
 * @author Antoine Corcy <[email protected]>
27
 */
28
class DM extends \Symfony\Component\Console\Command\Command
29
{
30 8
    protected function configure()
31
    {
32 8
        $availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();
33
34
        $this
35 8
            ->setName('convert:dm')
36 8
            ->setDescription('Convert and format decimal degrees coordinates to decimal minutes coordinate')
37 8
            ->addArgument('coordinate', InputArgument::REQUIRED, 'The "Lat,Long" coordinate')
38 8
            ->addOption('format', null, InputOption::VALUE_REQUIRED,
39 8
                'If set, the format of the converted decimal minutes coordinate', ConvertInterface::DEFAULT_DM_FORMAT)
40 8
            ->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED,
41 8
                'If set, the name of the ellipsoid to use', Ellipsoid::WGS84)
42 8
            ->setHelp(<<<EOT
43
<info>Available ellipsoids</info>: $availableEllipsoids
44
45
<info>Example with an output format</info>:
46
47
    %command.full_name% "40.446195, -79.948862" <comment>--format="%P%D°%N %p%d°%n"</comment>
48
49
<info>Example with FISCHER_1968 ellipsoid</info>:
50
51 8
    %command.full_name% "40.446195, -79.948862" <comment>--ellipsoid=FISCHER_1968</comment>
52
EOT
53
            );
54 8
    }
55
56 7
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58 7
        $ellipsoid  = Ellipsoid::createFromName($input->getOption('ellipsoid'));
59 5
        $coordinate = new Coordinate($input->getArgument('coordinate'), $ellipsoid);
60 4
        $geotools   = new Geotools;
61
62 4
        $output->writeln(sprintf(
63 4
            '<value>%s</value>',
64 4
            $geotools->convert($coordinate)->toDM($input->getOption('format'))
65
        ));
66 4
    }
67
}
68