UTM::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\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 convert:utm class
24
 *
25
 * @author Antoine Corcy <[email protected]>
26
 */
27
class UTM extends \Symfony\Component\Console\Command\Command
28
{
29 8
    protected function configure()
30
    {
31 8
        $availableEllipsoids = Ellipsoid::getAvailableEllipsoidNames();
32
33
        $this
34 8
            ->setName('convert:utm')
35 8
            ->setDescription('Convert decimal degrees coordinates in the Universal Transverse Mercator projection')
36 8
            ->addArgument('coordinate', InputArgument::REQUIRED, 'The "Lat,Long" coordinate')
37 8
            ->addOption('ellipsoid', null, InputOption::VALUE_REQUIRED,
38 8
                'If set, the name of the ellipsoid to use', Ellipsoid::WGS84)
39 8
            ->setHelp(<<<EOT
40 8
<info>Available ellipsoids</info>: $availableEllipsoids
41
42
<info>Example with CLARKE_1866 ellipsoid</info>:
43
44
    %command.full_name% "40.446195, -79.948862" <comment>--ellipsoid=CLARKE_1866</comment>
45
EOT
46
            );
47 8
    }
48
49 7
    protected function execute(InputInterface $input, OutputInterface $output)
50
    {
51 7
        $ellipsoid  = Ellipsoid::createFromName($input->getOption('ellipsoid'));
52 5
        $coordinate = new Coordinate($input->getArgument('coordinate'), $ellipsoid);
53 4
        $geotools   = new Geotools;
54
55 4
        $output->writeln(sprintf(
56 4
            '<value>%s</value>',
57 4
            $geotools->convert($coordinate)->toUTM()
58
        ));
59 4
        return 0;
60
    }
61
}
62