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

DMS::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
ccs 15
cts 15
cp 1
rs 8.8571
cc 1
eloc 14
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\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:dms class
25
 *
26
 * @author Antoine Corcy <[email protected]>
27
 */
28
class DMS extends \Symfony\Component\Console\Command\Command
29
{
30 8
    protected function configure()
31
    {
32 8
        $availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();
33
34 8
        $this
35 8
            ->setName('convert:dms')
36 8
            ->setDescription('Convert and format decimal degrees coordinates to degrees minutes seconds 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 degrees minutes seconds coordinate',
40 8
                ConvertInterface::DEFAULT_DMS_FORMAT)
41 8
            ->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED,
42 8
                'If set, the name of the ellipsoid to use', Ellipsoid::WGS84)
43 8
            ->setHelp(<<<EOT
44
<info>Available ellipsoids</info>: $availableEllipsoids
45
46
<info>Example with an output format</info>:
47
48
    %command.full_name% "40.446195, -79.948862" <comment>--format="%P%D:%M:%S, %p%d:%m:%s"</comment>
49
50
<info>Example with BESSEL_1841 ellipsoid</info>:
51
52 8
    %command.full_name% "40.446195, -79.948862" <comment>--ellipsoid=BESSEL_1841</comment>
53
EOT
54 8
            );
55 8
    }
56
57 7
    protected function execute(InputInterface $input, OutputInterface $output)
58
    {
59 7
        $ellipsoid  = Ellipsoid::createFromName($input->getOption('ellipsoid'));
60 5
        $coordinate = new Coordinate($input->getArgument('coordinate'), $ellipsoid);
61 4
        $geotools   = new Geotools;
62
63 4
        $output->writeln(sprintf(
64 4
            '<value>%s</value>',
65 4
            $geotools->convert($coordinate)->toDMS($input->getOption('format'))
66 4
        ));
67 4
    }
68
}
69