Implement lint

This commit is contained in:
2026-08-27 12:45:30 +02:00
parent 171db88400
commit 17009b641f
41 changed files with 70402 additions and 580 deletions
+51 -51
View File
@@ -13,32 +13,32 @@ use \Settings;
class Feed extends PhpObject {
//Spot feed
const FEED_HOOK = 'https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/';
const FEED_TYPE_XML = '/message.xml';
const FEED_TYPE_JSON = '/message.json';
const FEED_MAX_REFRESH = 5 * 60; //Seconds
private const FEED_HOOK = 'https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/';
private const FEED_TYPE_XML = '/message.xml';
private const FEED_TYPE_JSON = '/message.json';
private const FEED_MAX_REFRESH = 5 * 60; //Seconds
//Weather
const WEATHER_HOOK = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline';
const WEATHER_PARAM = array(
private const WEATHER_HOOK = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline';
private const WEATHER_PARAM = [
'key' => Settings::WEATHER_TOKEN,
'unitGroup' => 'metric',
'lang' => 'en',
'include' => 'current',
'iconSet' => 'icons2'
);
];
//Timezone
const TIMEZONE_HOOK = 'http://api.geonames.org/timezoneJSON';
private const TIMEZONE_HOOK = 'http://api.geonames.org/timezoneJSON';
//DB Tables
const SPOT_TABLE = 'spots';
const FEED_TABLE = 'feeds';
const MSG_TABLE = 'messages';
public const SPOT_TABLE = 'spots';
public const FEED_TABLE = 'feeds';
public const MSG_TABLE = 'messages';
//Hide/Display values
const MSG_HIDDEN = 0;
const MSG_DISPLAYED = 1;
public const MSG_HIDDEN = 0;
public const MSG_DISPLAYED = 1;
/**
* Database Handle
@@ -72,10 +72,10 @@ class Feed extends PhpObject {
}
public function createFeedId($oProjectId) {
$this->setFeedId($this->oDb->insertRow(self::FEED_TABLE, array(
$this->setFeedId($this->oDb->insertRow(self::FEED_TABLE, [
Db::getId(Project::PROJ_TABLE) => $oProjectId,
'status' => 'INACTIVE'
)));
]));
return $this->getFeedId();
}
@@ -92,14 +92,14 @@ class Feed extends PhpObject {
}
public function getSpots() {
$asSpots = $this->oDb->selectRows(array('from'=>self::SPOT_TABLE));
$asSpots = $this->oDb->selectRows(['from'=>self::SPOT_TABLE]);
foreach($asSpots as &$asSpot) $asSpot['id'] = $asSpot[Db::getId(self::SPOT_TABLE)];
return $asSpots;
}
public function getFeeds($iFeedId=0) {
$asInfo = array('from'=>self::FEED_TABLE);
if($iFeedId > 0) $asInfo['constraint'] = array(Db::getId(self::FEED_TABLE)=>$iFeedId);
$asInfo = ['from'=>self::FEED_TABLE];
if($iFeedId > 0) $asInfo['constraint'] = [Db::getId(self::FEED_TABLE)=>$iFeedId];
$asFeeds = $this->oDb->selectRows($asInfo);
foreach($asFeeds as &$asFeed) $asFeed['id'] = $asFeed[Db::getId(self::FEED_TABLE)];
@@ -111,21 +111,21 @@ class Feed extends PhpObject {
return array_shift($asFeeds);
}
public function getMessages($asConstraints=array()) {
public function getMessages($asConstraints=[]) {
$sFeedIdCol = Db::getId(self::FEED_TABLE, true);
$asInfo = array(
'select' => array(
$asInfo = [
'select' => [
Db::getId(self::MSG_TABLE), 'ref_msg_id', 'type', //ID
'latitude', 'longitude', //Position
'site_time', 'timezone', 'unix_time', //Time
'weather_icon', 'weather_cond', 'weather_temp' //Weather
),
],
'from' => self::MSG_TABLE,
'join' => array(self::FEED_TABLE => Db::getId(self::FEED_TABLE)),
'constraint'=> array($sFeedIdCol => $this->getFeedId(), 'display' => self::MSG_DISPLAYED),
'constOpe' => array($sFeedIdCol => "=", 'display' => "="),
'orderBy' => array('site_time'=>'ASC')
);
'join' => [self::FEED_TABLE => Db::getId(self::FEED_TABLE)],
'constraint'=> [$sFeedIdCol => $this->getFeedId(), 'display' => self::MSG_DISPLAYED],
'constOpe' => [$sFeedIdCol => '=', 'display' => '='],
'orderBy' => ['site_time'=>'ASC']
];
if(!empty($asConstraints)) $asInfo = array_merge($asInfo, $asConstraints);
$asResult = $this->oDb->selectRows($asInfo);
@@ -134,7 +134,7 @@ class Feed extends PhpObject {
$iCount = 0;
foreach($asResult as &$asMsg) {
if($asMsg['weather_icon'] == '' && $iCount < 3) {
$asWeather = $this->getWeather(array($asMsg['latitude'], $asMsg['longitude']), $asMsg['unix_time']);
$asWeather = $this->getWeather([$asMsg['latitude'], $asMsg['longitude']], $asMsg['unix_time']);
$asMsg = array_merge($asMsg, $asWeather);
$this->oDb->updateRow(self::MSG_TABLE, $asMsg[Db::getId(self::MSG_TABLE)], $asWeather, false);
$iCount++;
@@ -145,7 +145,7 @@ class Feed extends PhpObject {
return $asResult;
}
public function getLastMessageId($asConstraints=array()) {
public function getLastMessageId($asConstraints=[]) {
$asMessages = $this->getMessages($asConstraints);
return end($asMessages)[Db::getId(self::MSG_TABLE)] ?? 0;
}
@@ -169,7 +169,7 @@ class Feed extends PhpObject {
$sTimeZone = date_default_timezone_get();
$oDateTime = new \DateTime('@'.$iTimestamp);
$oDateTime->setTimezone(new \DateTimeZone($sTimeZone));
$asWeather = $this->getWeather(array($sLat, $sLng), $iTimestamp);
$asWeather = $this->getWeather([$sLat, $sLng], $iTimestamp);
$asMsg = [
'ref_msg_id' => $iTimestamp.'/man',
@@ -200,33 +200,33 @@ class Feed extends PhpObject {
//Fix unstable Spot API Structure
if(array_key_exists('message', $asMsgs)) $asMsgs = $asMsgs['message']; //Sometimes adds an extra "message" level
if(!array_key_exists(0, $asMsgs)) $asMsgs = array($asMsgs); //Jumps a level when there is only 1 message
if(!array_key_exists(0, $asMsgs)) $asMsgs = [$asMsgs]; //Jumps a level when there is only 1 message
//Update Spot, Feed & Messages
if(!empty($asMsgs) && array_key_exists('messengerId', $asMsgs[0])) {
//Update Spot Info from the first message
$asSpotInfo = array(
$asSpotInfo = [
'ref_spot_id' => $asMsgs[0]['messengerId'],
'name' => $asMsgs[0]['messengerName'],
'model' => $asMsgs[0]['modelId']
);
$iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, array('ref_spot_id'));
];
$iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, ['ref_spot_id']);
//Update Feed Info and last update date
$asFeedInfo = array(
$asFeedInfo = [
'ref_feed_id' => $asFeed['id'],
Db::getId(self::SPOT_TABLE) => $iSpotId,
'name' => $asFeed['name'],
'description' => $asFeed['description'],
'status' => $asFeed['status'],
'last_update' => $sNow
);
$iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id'));
];
$iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, ['ref_feed_id']);
//Update Messages
foreach($asMsgs as $asMsg) {
$asMsg = array(
$asMsg = [
'ref_msg_id' => $asMsg['id'],
Db::getId(self::FEED_TABLE) => $iFeedId,
'type' => $asMsg['messageType'],
@@ -238,15 +238,15 @@ class Feed extends PhpObject {
'unix_time' => $asMsg['unixTime'], //UNIX Time (backup)
'content' => $asMsg['messageContent'],
'battery_state' => $asMsg['batteryState']
);
];
$iMsgId = $this->oDb->selectId(self::MSG_TABLE, array('ref_msg_id'=>$asMsg['ref_msg_id']));
$iMsgId = $this->oDb->selectId(self::MSG_TABLE, ['ref_msg_id'=>$asMsg['ref_msg_id']]);
if(!$iMsgId) {
//First Catch
$asMsg['posted_on'] = $sNow;
//Weather Data
$asMsg = array_merge($asMsg, $this->getWeather(array($asMsg['latitude'], $asMsg['longitude']), $asMsg['unix_time']));
$asMsg = array_merge($asMsg, $this->getWeather([$asMsg['latitude'], $asMsg['longitude']], $asMsg['unix_time']));
$this->oDb->insertRow(self::MSG_TABLE, $asMsg);
$bNewMsg = true;
@@ -255,7 +255,7 @@ class Feed extends PhpObject {
}
}
}
else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array('last_update'=>$sNow));
else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), ['last_update'=>$sNow]);
return $bNewMsg;
}
@@ -281,19 +281,19 @@ class Feed extends PhpObject {
//Get Condition Language ID
$sCondLangId = (new Translator(self::WEATHER_PARAM['lang']))->getTranslationKey($sWeatherCond);
return array(
return [
'weather_icon' => $sWeatherIcon,
'weather_cond' => $sCondLangId,
'weather_temp' => floatval($sWeatherTemp)
);
];
}
private function getTimeZone($iLat, $iLng) {
$asParams = array(
$asParams = [
'username' => Settings::TIMEZONE_USER,
'lat' => $iLat,
'lng' => $iLng
);
];
$sApiUrl = self::TIMEZONE_HOOK.'?'.http_build_query($asParams);
$asTimeZone = json_decode(file_get_contents($sApiUrl), true);
@@ -314,7 +314,7 @@ class Feed extends PhpObject {
}
private function updateField($sField, $oValue) {
$bResult = ($this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array($sField=>$oValue)) > 0);
$bResult = ($this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), [$sField=>$oValue]) > 0);
$this->setFeedId($this->getFeedId());
return $bResult;
@@ -323,8 +323,8 @@ class Feed extends PhpObject {
public function delete() {
$bSuccess = false;
$sLangId = '';
$asLangParams = array();
$asData = array();
$asLangParams = [];
$asData = [];
if($this->getFeedId() > 0) {
$asData['id'] = $this->getFeedId();
@@ -333,7 +333,7 @@ class Feed extends PhpObject {
}
else {
$sLangId = 'error.impossible_value';
$asLangParams = array($this->getFeedId(), 'feed ID');
$asLangParams = [$this->getFeedId(), 'feed ID'];
}
return Livetrail::getResult($bSuccess, $sLangId, $asData, $asLangParams);