Completed
Push — master ( 72d96f...36cc69 )
by Yannick
16:46 queued 04:01
created

tools-metar.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
require_once('require/class.Connection.php');
3
require_once('require/class.Spotter.php');
4
require_once('require/class.METAR.php');
5
require_once('require/class.Language.php');
6
$Spotter = new Spotter();
7
$METAR = new METAR();
8
$title = _("Parse METAR messages");
9
require_once('header.php');
10
11
$page_url = $globalURL.'/tools-metar';
12
13
$message = filter_input(INPUT_POST,'metar_message',FILTER_SANITIZE_STRING);
14
15
print '<div class="info column">';
16
print '<h1>'._("Parse METAR messages").'</h1>';
17
print '</div>';
18
19
print '<div class="table column">';	
20
print '<p>'._("Parse METAR messages and translate them in human readable format.").'</p>';
21
print '<div class="pagination">';
22
print '<form method="post">';
23
print '<fieldset class="form-group">';
24
print '<label for="metar_message">'._("METAR Message").'</label>';
25
print '<textarea class="form-control" name="metar_message" id="metar_message" rows="5">';
26
if ($message != '') print $message;
27
print '</textarea>';
28
print '</fieldset>';
29
print '<button type="submit" class="btn btn-primary">Submit</button>';
30
print '</form>';
31
if ($message != '') {
32
	$globalDebug = FALSE;
33
	$metar_parse = $METAR->parse($message);
34
	if (!empty($metar_parse)) {
35
		//print_r($metar_parse);
36
		print '<p>'._("METAR message in human readable format:").'</p>';
37
		if (isset($metar_parse['location'])) {
38
			print '<b>'._("Location:").'</b> ';
39
			print $metar_parse['location']." ";
40
		}
41 View Code Duplication
		if (isset($metar_parse['wind'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
			print '<b>'._("Wind:").'</b> ';
43
			if (isset($metar_parse['wind']['direction'])) {
44
				$direction = $Spotter->parseDirection($metar_parse['wind']['direction']);
45
				print $direction[0]['direction_fullname'];
46
				print ' ('.$metar_parse['wind']['direction'].'°) ';
47
			}
48
			if (isset($metar_parse['wind']['speed'])) {
49
				print $metar_parse['wind']['speed'].' m/s';
50
			}
51
			print ' ';
52
		}
53 View Code Duplication
		if (isset($metar_parse['visibility'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
			print '<b>'._("Visibility:").'</b> '.$metar_parse['visibility'].' m'." ";
55
		}
56 View Code Duplication
		if (isset($metar_parse['weather'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
			print '<b>'._("Weather:").'</b> '.$metar_parse['weather']." ";
58
		}
59
		if (isset($metar_parse['cloud'])) {
60
			print '<b>'._("Cloud:").'</b> ';
61
			foreach ($metar_parse['cloud'] as $key => $cloud) {
62
				if ($key > 0) print ' / ';
63
				print $cloud['type'].' at '.$cloud['level'].' m';
64
			}
65
			print " ";
66
		}
67 View Code Duplication
		if (isset($metar_parse['temperature'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
			print '<b>'._("Temperature:").'</b> '.$metar_parse['temperature'].' °C'." ";
69
		}
70 View Code Duplication
		if (isset($metar_parse['dew'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
			print '<b>'._("Dew point:").'</b> '.$metar_parse['dew'].' °C'." ";
72
		}
73 View Code Duplication
		if (isset($metar_parse['temperature']) && isset($metar_parse['dew'])) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
			$humidity = round(100 * pow((112 - (0.1 * $metar_parse['temperature']) + $metar_parse['dew']) / (112 + (0.9 * $metar_parse['temperature'])), 8),1);
75
			print '<b>'._("Humidity:").'</b> '.$humidity.'%'." ";
76
		}
77
		if (isset($metar_parse['QNH'])) {
78
			print '<b>'._("Pressure:").'</b> '.$metar_parse['QNH'].' hPa';
79
		}
80
	} else {
81
		print '<p>'._("This METAR message can't be translated in human readable format :(").'</p>';
82
	}
83
	//var_dump($parsed_msg);
84
}
85
86
print '</div>';
87
print '</div>';
88
89
require_once('footer.php');
90
?>
1 ignored issue
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...