Code cleanup from inspection results

This commit is contained in:
Nabeel Shahzad
2018-08-26 13:50:08 -05:00
parent 0f3424f41e
commit e95b3eb366
76 changed files with 226 additions and 268 deletions

View File

@@ -14,6 +14,7 @@ class ICAO
* @param null $country
*
* @return string
* @throws \Exception
*/
public static function createHexCode($country = null)
{

View File

@@ -438,6 +438,7 @@ class Metar implements \ArrayAccess
if (array_key_exists('cavok', $this->result) && $this->result['cavok']) {
$this->result['category'] = 'VFR';
} else {
/** @noinspection NestedPositiveIfStatementsInspection */
if (array_key_exists('cloud_height', $this->result) && array_key_exists('visibility', $this->result)) {
if ($this->result['cloud_height']['ft'] > 3000 && $this->result['visibility']['nmi'] > 5) {
$this->result['category'] = 'VFR';
@@ -566,6 +567,7 @@ class Metar implements \ArrayAccess
* Decodes TAF code if present.
*
* @param mixed $part
* @return bool
*/
private function get_taf($part)
{
@@ -770,6 +772,7 @@ class Metar implements \ArrayAccess
if ($found[1] === 'CAVOK' || $found[1] === '9999') {
$this->set_result_value('visibility', new Distance(10000, 'm'));
$this->set_result_value('visibility_report', 'Greater than 10 km');
/** @noinspection NotOptimalIfConditionsInspection */
if ($found[1] === 'CAVOK') {
$this->set_result_value('cavok', true);
$this->method += 4; // can skip the next 4 methods: visibility_min, runway_vr, present_weather, clouds
@@ -887,7 +890,7 @@ class Metar implements \ArrayAccess
];
// Runway past tendency
if (isset($found[8]) && isset(static::$rvr_tendency_codes[$found[8]])) {
if (isset($found[8], static::$rvr_tendency_codes[$found[8]])) {
$observed['tendency'] = $found[8];
}
@@ -1002,7 +1005,7 @@ class Metar implements \ArrayAccess
}
}
// Type
if (isset($found[6]) && !empty($found[6]) && isset(static::$cloud_type_codes[$found[6]]) && $found[4] != 'VV') {
if (isset($found[6], static::$cloud_type_codes[$found[6]]) && !empty($found[6]) && $found[4] !== 'VV') {
$observed['type'] = $found[6];
}
@@ -1204,13 +1207,13 @@ class Metar implements \ArrayAccess
// Build runways report
$report = [];
if (null !== $observed['deposits']) {
if ($observed['deposits'] !== null) {
$report[] = static::$runway_deposits_codes[$observed['deposits']];
if (null !== $observed['deposits_extent']) {
$report[] = 'contamination '.static::$runway_deposits_extent_codes[$observed['deposits_extent']];
}
if (null !== $observed['deposits_depth']) {
if ($observed['deposits_depth'] !== null) {
if ($observed['deposits_depth'] === '99') {
$report[] = 'runway closed';
} elseif (isset(static::$runway_deposits_depth_codes[$observed['deposits_depth']])) {
@@ -1221,7 +1224,7 @@ class Metar implements \ArrayAccess
}
}
if (null !== $observed['friction']) {
if ($observed['friction'] !== null) {
if (isset(static::$runway_friction_codes[$observed['friction']])) {
$report[] = 'a braking action is '.static::$runway_friction_codes[$observed['friction']];
} else {
@@ -1385,7 +1388,7 @@ class Metar implements \ArrayAccess
while ($this->part < \count($this->raw_parts)) {
if (preg_match($r, $this->raw_parts[$this->part], $found)) {
// Get trend flag
if (isset($found[2]) && isset(static::$trends_flag_codes[$found[2]])) {
if (isset($found[2], static::$trends_flag_codes[$found[2]])) {
$trend['flag'] = $found[2];
} // Get PROBpp formatted period
@@ -1393,7 +1396,7 @@ class Metar implements \ArrayAccess
$trend['probability'] = $found[4];
} // Get AT, FM, TL formatted period
elseif (isset($found[8]) && isset(static::$trends_time_codes[$found[5]])) {
elseif (isset($found[8], static::$trends_time_codes[$found[5]])) {
$trend['period']['flag'] = $found[5];
if (!empty($found[6])) {
$trend['period']['day'] = (int) $found[6];
@@ -1512,7 +1515,7 @@ class Metar implements \ArrayAccess
$remarks = [];
// Get all parts after
while ($this->part < count($this->raw_parts)) {
while ($this->part < \count($this->raw_parts)) {
if (isset($this->raw_parts[$this->part])) {
$remarks[] = $this->raw_parts[$this->part];
}
@@ -1582,11 +1585,11 @@ class Metar implements \ArrayAccess
}
}
if (null !== $observed['characteristics']) {
if ($observed['characteristics'] !== null) {
$report[] = static::$weather_char_codes[$observed['characteristics']];
}
if (null !== $observed['types']) {
if ($observed['types'] !== null) {
foreach ($observed['types'] as $code) {
$report[] = static::$weather_type_codes[$code];
}

View File

@@ -15,20 +15,20 @@ class TimezonelistExtended extends Timezonelist
* @param bool $htmlencode
*
* @return string
* @throws \Exception
* @throws \Exception
*/
protected function formatTimezone($timezone, $continent, $htmlencode = true)
{
$time = new \DateTimeImmutable(null, new DateTimeZone($timezone));
$offset = $time->format('P');
if ($htmlencode) {
$offset = str_replace('-', ' &minus; ', $offset);
$offset = str_replace('+', ' &plus; ', $offset);
$offset = str_replace(['-', '+'], array(' &minus; ', ' &plus; '), $offset);
}
$timezone = substr($timezone, strlen($continent) + 1);
$timezone = str_replace('St_', 'St. ', $timezone);
$timezone = str_replace('_', ' ', $timezone);
$formatted = '(GMT/UTC'.$offset.')'.self::WHITESPACE_SEP.$timezone;
return $formatted;
$timezone = substr($timezone, \strlen($continent) + 1);
$timezone = str_replace(['St_', '_'], array('St. ', ' '), $timezone);
return '(GMT/UTC'.$offset.')'.self::WHITESPACE_SEP.$timezone;
}
/**
@@ -46,7 +46,7 @@ class TimezonelistExtended extends Timezonelist
// Attributes for select element
$attrSet = '';
if (!empty($attr)) {
if (is_array($attr)) {
if (\is_array($attr)) {
foreach ($attr as $attr_name => $attr_value) {
$attrSet .= ' '.$attr_name.'="'.$attr_value.'"';
}
@@ -59,7 +59,7 @@ class TimezonelistExtended extends Timezonelist
// Add popular timezones
$listbox .= '<optgroup label="General">';
foreach ($this->popularTimezones as $key => $value) {
$selected_attr = ($selected == $key) ? ' selected="selected"' : '';
$selected_attr = ($selected === $key) ? ' selected="selected"' : '';
$listbox .= '<option value="'.$key.'"'.$selected_attr.'>'.$value.'</option>';
}
$listbox .= '</optgroup>';
@@ -70,7 +70,7 @@ class TimezonelistExtended extends Timezonelist
$listbox .= '<optgroup label="'.$continent.'">';
// create option tags
foreach ($timezones as $timezone) {
$selected_attr = ($selected == $timezone) ? ' selected="selected"' : '';
$selected_attr = ($selected === $timezone) ? ' selected="selected"' : '';
$listbox .= '<option value="'.$timezone.'"'.$selected_attr.'>';
$listbox .= $this->formatTimezone($timezone, $continent, $htmlencode);
$listbox .= '</option>';