replace PHP sizeof() with either count() or empty()

This commit is contained in:
marc tobias 2018-03-22 12:36:24 +01:00
parent d79a2bb17e
commit 27bc8d4f7b
19 changed files with 75 additions and 68 deletions

View File

@ -303,7 +303,7 @@ class Geocode
$this->loadStructuredAddressElement($sPostalCode, 'postalcode', 5, 11, array(5, 11));
$this->loadStructuredAddressElement($sCountry, 'country', 4, 4, false);
if (sizeof($this->aStructuredQuery) > 0) {
if (!empty($this->aStructuredQuery)) {
$this->sQuery = join(', ', $this->aStructuredQuery);
if ($this->iMaxAddressRank < 30) {
$this->sAllowedTypesSQLList = '(\'place\',\'boundary\')';
@ -317,7 +317,7 @@ class Geocode
$aParams = $this->aStructuredQuery;
if (sizeof($aParams) == 1) return false;
if (count($aParams) == 1) return false;
$aOrderToFallback = array('postalcode', 'street', 'city', 'county', 'state');
@ -375,8 +375,8 @@ class Geocode
$sPhraseType,
$iToken == 0 && $iPhrase == 0,
$iPhrase == 0,
$iToken + 1 == sizeof($aWordset)
&& $iPhrase + 1 == sizeof($aPhrases)
$iToken + 1 == count($aWordset)
&& $iPhrase + 1 == count($aPhrases)
);
foreach ($aNewSearches as $oSearch) {
@ -411,7 +411,7 @@ class Geocode
usort($aNewWordsetSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
$aWordsetSearches = array_slice($aNewWordsetSearches, 0, 50);
}
//var_Dump('<hr>',sizeof($aWordsetSearches)); exit;
//var_Dump('<hr>',count($aWordsetSearches)); exit;
$aNewPhraseSearches = array_merge($aNewPhraseSearches, $aNewWordsetSearches);
usort($aNewPhraseSearches, array('Nominatim\SearchDescription', 'bySearchRank'));
@ -442,7 +442,7 @@ class Geocode
$iSearchCount = 0;
$aSearches = array();
foreach ($aGroupedSearches as $iScore => $aNewSearches) {
$iSearchCount += sizeof($aNewSearches);
$iSearchCount += count($aNewSearches);
$aSearches = array_merge($aSearches, $aNewSearches);
if ($iSearchCount > 50) break;
}
@ -627,7 +627,7 @@ class Geocode
}
}
if (sizeof($aTokens)) {
if (!empty($aTokens)) {
// Check which tokens we have, get the ID numbers
$sSQL = 'SELECT word_id, word_token, word, class, type, country_code, operator, search_name_count';
$sSQL .= ' FROM word ';
@ -702,8 +702,8 @@ class Geocode
// because order in the address doesn't matter.
$aPhrases = array_reverse($aPhrases);
$aPhrases[0]->invertWordSets();
if (sizeof($aPhrases) > 1) {
$aPhrases[sizeof($aPhrases)-1]->invertWordSets();
if (count($aPhrases) > 1) {
$aPhrases[count($aPhrases)-1]->invertWordSets();
}
$aReverseGroupedSearches = $this->getGroupedSearches($aSearches, $aPhrases, $aValidTokens, false);
@ -738,7 +738,7 @@ class Geocode
$sHash = serialize($aSearch);
if (isset($aSearchHash[$sHash])) {
unset($aGroupedSearches[$iGroup][$iSearch]);
if (sizeof($aGroupedSearches[$iGroup]) == 0) unset($aGroupedSearches[$iGroup]);
if (empty($aGroupedSearches[$iGroup])) unset($aGroupedSearches[$iGroup]);
} else {
$aSearchHash[$sHash] = 1;
}
@ -771,7 +771,7 @@ class Geocode
if ($iQueryLoop > 20) break;
}
if (sizeof($aResults) && ($this->iMinAddressRank != 0 || $this->iMaxAddressRank != 30)) {
if (!empty($aResults) && ($this->iMinAddressRank != 0 || $this->iMaxAddressRank != 30)) {
// Need to verify passes rank limits before dropping out of the loop (yuk!)
// reduces the number of place ids, like a filter
// rank_address is 30 for interpolated housenumbers
@ -824,7 +824,7 @@ class Geocode
$aResults = $tempIDs;
}
if (sizeof($aResults)) break;
if (!empty($aResults)) break;
if ($iGroupLoop > 4) break;
if ($iQueryLoop > 30) break;
}
@ -843,7 +843,7 @@ class Geocode
}
// No results? Done
if (!sizeof($aResults)) {
if (empty($aResults)) {
if ($this->bFallback) {
if ($this->fallbackStructuredQuery()) {
return $this->lookup();
@ -982,7 +982,7 @@ class Geocode
}
// Absolute limit on number of results
if (sizeof($aSearchResults) >= $this->iFinalLimit) break;
if (count($aSearchResults) >= $this->iFinalLimit) break;
}
if (CONST_Debug) var_dump($aSearchResults);

View File

@ -99,7 +99,7 @@ class ParameterParser
arsort($aLanguages);
}
}
if (!sizeof($aLanguages) && CONST_Default_Language) {
if (empty($aLanguages) && CONST_Default_Language) {
$aLanguages[CONST_Default_Language] = 1;
}

View File

@ -83,7 +83,7 @@ class Phrase
$aResult = array(array(join(' ', $aWords)));
$sFirstToken = '';
if ($iDepth < Phrase::MAX_DEPTH) {
while (sizeof($aWords) > 1) {
while (count($aWords) > 1) {
$sWord = array_shift($aWords);
$sFirstToken .= ($sFirstToken?' ':'').$sWord;
$aRest = $this->createWordSets($aWords, $iDepth + 1);
@ -101,7 +101,7 @@ class Phrase
$aResult = array(array(join(' ', $aWords)));
$sFirstToken = '';
if ($iDepth < Phrase::MAX_DEPTH) {
while (sizeof($aWords) > 1) {
while (count($aWords) > 1) {
$sWord = array_pop($aWords);
$sFirstToken = $sWord.($sFirstToken?' ':'').$sFirstToken;
$aRest = $this->createInverseWordSets($aWords, $iDepth + 1);

View File

@ -164,12 +164,12 @@ class PlaceLookup
$aResults = $this->lookup(array($iPlaceID => new Result($iPlaceID)));
return sizeof($aResults) ? reset($aResults) : null;
return empty($aResults) ? null : reset($aResults);
}
public function lookup($aResults, $iMinRank = 0, $iMaxRank = 30)
{
if (!sizeof($aResults)) {
if (empty($aResults)) {
return array();
}
$aSubSelects = array();
@ -408,7 +408,7 @@ class PlaceLookup
if (CONST_Debug) var_dump($aSubSelects);
if (!sizeof($aSubSelects)) {
if (empty($aSubSelects)) {
return array();
}

View File

@ -94,8 +94,8 @@ class SearchDescription
*/
public function looksLikeFullAddress()
{
return sizeof($this->aName)
&& (sizeof($this->aAddress || $this->sCountryCode))
return (!empty($this->aName))
&& (!empty($this->aAddress) || $this->sCountryCode)
&& preg_match('/[0-9]+/', $this->sHouseNumber);
}
@ -147,7 +147,7 @@ class SearchDescription
*/
public function isValidSearch()
{
if (!sizeof($this->aName)) {
if (empty($this->aName)) {
if ($this->sHouseNumber) {
return false;
}
@ -223,7 +223,7 @@ class SearchDescription
// If we have a structured search or this is not the first term,
// add the postcode as an addendum.
if ($this->iOperator != Operator::POSTCODE
&& ($sPhraseType == 'postalcode' || sizeof($this->aName))
&& ($sPhraseType == 'postalcode' || !empty($this->aName))
) {
$oSearch = clone $this;
$oSearch->iSearchRank++;
@ -247,8 +247,8 @@ class SearchDescription
$oSearch->iSearchRank++;
}
// also must not appear in the middle of the address
if (sizeof($this->aAddress)
|| sizeof($this->aAddressNonSearch)
if (!empty($this->aAddress)
|| (!empty($this->aAddressNonSearch))
|| $this->sPostcode
) {
$oSearch->iSearchRank++;
@ -262,7 +262,7 @@ class SearchDescription
$iOp = Operator::NEAR; // near == in for the moment
if ($aSearchTerm['operator'] == '') {
if (sizeof($this->aName) || $this->oContext->isBoundedSearch()) {
if (!empty($this->aName) || $this->oContext->isBoundedSearch()) {
$iOp = Operator::NAME;
}
$oSearch->iSearchRank += 2;
@ -280,7 +280,7 @@ class SearchDescription
// of the phrase. In structured search the name must forcably in
// the first phrase. In unstructured search it may be in a later
// phrase when the first phrase is a house number.
if (sizeof($this->aName) || !($bFirstPhrase || $sPhraseType == '')) {
if (!empty($this->aName) || !($bFirstPhrase || $sPhraseType == '')) {
if (($sPhraseType == '' || !$bFirstPhrase) && !$bHasPartial) {
$oSearch = clone $this;
$oSearch->iSearchRank++;
@ -322,7 +322,7 @@ class SearchDescription
$iWordID = $aSearchTerm['word_id'];
if ((!$bStructuredPhrases || $iPhrase > 0)
&& sizeof($this->aName)
&& (!empty($this->aName))
&& strpos($aSearchTerm['word_token'], ' ') === false
) {
if ($aSearchTerm['search_name_count'] + 1 < CONST_Max_Word_Frequency) {
@ -337,7 +337,7 @@ class SearchDescription
if (preg_match('#^[0-9]+$#', $aSearchTerm['word_token'])) {
$oSearch->iSearchRank += 2;
}
if (sizeof($aFullTokens)) {
if (!empty($aFullTokens)) {
$oSearch->iSearchRank++;
}
$aNewSearches[] = $oSearch;
@ -358,11 +358,11 @@ class SearchDescription
}
if ((!$this->sPostcode && !$this->aAddress && !$this->aAddressNonSearch)
&& (!sizeof($this->aName) || $this->iNamePhrase == $iPhrase)
&& (empty($this->aName) || $this->iNamePhrase == $iPhrase)
) {
$oSearch = clone $this;
$oSearch->iSearchRank += 2;
if (!sizeof($this->aName)) {
if (empty($this->aName)) {
$oSearch->iSearchRank += 1;
}
if (preg_match('#^[0-9]+$#', $aSearchTerm['word_token'])) {
@ -405,7 +405,7 @@ class SearchDescription
$iHousenumber = -1;
if ($this->sCountryCode
&& !sizeof($this->aName)
&& empty($this->aName)
&& !$this->iOperator
&& !$this->sClass
&& !$this->oContext->hasNearPoint()
@ -414,7 +414,7 @@ class SearchDescription
if (4 >= $iMinRank && 4 <= $iMaxRank) {
$aResults = $this->queryCountry($oDB);
}
} elseif (!sizeof($this->aName) && !sizeof($this->aAddress)) {
} elseif (empty($this->aName) && empty($this->aAddress)) {
// Neither name nor address? Then we must be
// looking for a POI in a geographic area.
if ($this->oContext->isBoundedSearch()) {
@ -435,17 +435,17 @@ class SearchDescription
);
//now search for housenumber, if housenumber provided
if ($this->sHouseNumber && sizeof($aResults)) {
if ($this->sHouseNumber && !empty($aResults)) {
$aNamedPlaceIDs = $aResults;
$aResults = $this->queryHouseNumber($oDB, $aNamedPlaceIDs, $iLimit);
if (!sizeof($aResults) && $this->looksLikeFullAddress()) {
if (empty($aResults) && $this->looksLikeFullAddress()) {
$aResults = $aNamedPlaceIDs;
}
}
// finally get POIs if requested
if ($this->sClass && sizeof($aResults)) {
if ($this->sClass && !empty($aResults)) {
$aResults = $this->queryPoiByOperator($oDB, $aResults, $iLimit);
}
}
@ -455,7 +455,7 @@ class SearchDescription
var_dump(array_keys($aResults));
}
if (sizeof($aResults) && $this->sPostcode) {
if (!empty($aResults) && $this->sPostcode) {
$sPlaceIds = Result::joinIdsByTable($aResults, Result::TABLE_PLACEX);
if ($sPlaceIds) {
$sSQL = 'SELECT place_id FROM placex';
@ -562,7 +562,7 @@ class SearchDescription
{
$sSQL = 'SELECT p.place_id FROM location_postcode p ';
if (sizeof($this->aAddress)) {
if (!empty($this->aAddress)) {
$sSQL .= ', search_name s ';
$sSQL .= 'WHERE s.place_id = p.parent_place_id ';
$sSQL .= 'AND array_cat(s.nameaddress_vector, s.name_vector)';
@ -591,7 +591,7 @@ class SearchDescription
$aTerms = array();
$aOrder = array();
if ($this->sHouseNumber && sizeof($this->aAddress)) {
if ($this->sHouseNumber && !empty($this->aAddress)) {
$sHouseNumberRegex = '\\\\m'.$this->sHouseNumber.'\\\\M';
$aOrder[] = ' (';
$aOrder[0] .= 'EXISTS(';
@ -617,13 +617,13 @@ class SearchDescription
$aOrder[0] .= ') DESC';
}
if (sizeof($this->aName)) {
if (!empty($this->aName)) {
$aTerms[] = 'name_vector @> '.getArraySQL($this->aName);
}
if (sizeof($this->aAddress)) {
if (!empty($this->aAddress)) {
// For infrequent name terms disable index usage for address
if (CONST_Search_NameOnlySearchFrequencyThreshold
&& sizeof($this->aName) == 1
&& count($this->aName) == 1
&& $aWordFrequencyScores[$this->aName[reset($this->aName)]]
< CONST_Search_NameOnlySearchFrequencyThreshold
) {
@ -653,7 +653,7 @@ class SearchDescription
$aTerms[] = $this->oContext->withinSQL('centroid');
$aOrder[] = $this->oContext->distanceSQL('centroid');
} elseif ($this->sPostcode) {
if (!sizeof($this->aAddress)) {
if (empty($this->aAddress)) {
$aTerms[] = "EXISTS(SELECT place_id FROM location_postcode p WHERE p.postcode = '".$this->sPostcode."' AND ST_DWithin(search_name.centroid, p.geometry, 0.1))";
} else {
$aOrder[] = "(SELECT min(ST_Distance(search_name.centroid, p.geometry)) FROM location_postcode p WHERE p.postcode = '".$this->sPostcode."')";
@ -681,7 +681,7 @@ class SearchDescription
$sImportanceSQL .= $this->oContext->viewboxImportanceSQL('centroid');
$aOrder[] = "$sImportanceSQL DESC";
if (sizeof($this->aFullNameAddress)) {
if (!empty($this->aFullNameAddress)) {
$sExactMatchSQL = ' ( ';
$sExactMatchSQL .= ' SELECT count(*) FROM ( ';
$sExactMatchSQL .= ' SELECT unnest('.getArraySQL($this->aFullNameAddress).')';
@ -700,7 +700,7 @@ class SearchDescription
$aResults = array();
if (sizeof($aTerms)) {
if (!empty($aTerms)) {
$sSQL = 'SELECT place_id,'.$sExactMatchSQL;
$sSQL .= ' FROM search_name';
$sSQL .= ' WHERE '.join(' and ', $aTerms);
@ -749,7 +749,7 @@ class SearchDescription
$bIsIntHouseNumber= (bool) preg_match('/[0-9]+/', $this->sHouseNumber);
$iHousenumber = intval($this->sHouseNumber);
if ($bIsIntHouseNumber && !sizeof($aResults)) {
if ($bIsIntHouseNumber && empty($aResults)) {
// if nothing found, search in the interpolation line table
$sSQL = 'SELECT distinct place_id FROM location_property_osmline';
$sSQL .= ' WHERE startnumber is not NULL';
@ -778,7 +778,7 @@ class SearchDescription
}
// If nothing found try the aux fallback table
if (CONST_Use_Aux_Location_data && !sizeof($aResults)) {
if (CONST_Use_Aux_Location_data && empty($aResults)) {
$sSQL = 'SELECT place_id FROM location_property_aux';
$sSQL .= ' WHERE parent_place_id in ('.$sPlaceIDs.')';
$sSQL .= " AND housenumber = '".$this->sHouseNumber."'";
@ -793,7 +793,7 @@ class SearchDescription
}
// If nothing found then search in Tiger data (location_property_tiger)
if (CONST_Use_US_Tiger_Data && $bIsIntHouseNumber && !sizeof($aResults)) {
if (CONST_Use_US_Tiger_Data && $bIsIntHouseNumber && empty($aResults)) {
$sSQL = 'SELECT place_id FROM location_property_tiger';
$sSQL .= ' WHERE parent_place_id in ('.$sPlaceIDs.') and (';
if ($iHousenumber % 2 == 0) {

View File

@ -16,7 +16,7 @@ function getCmdOpt($aArg, $aSpec, &$aResult, $bExitOnError = false, $bExitOnUnkn
$aResult = array();
$bUnknown = false;
$iSize = sizeof($aArg);
$iSize = count($aArg);
for ($i = 1; $i < $iSize; $i++) {
if (isset($aQuick[$aArg[$i]])) {
$aLine = $aQuick[$aArg[$i]];

View File

@ -14,7 +14,7 @@ function getProcessorCount()
{
$sCPU = file_get_contents('/proc/cpuinfo');
preg_match_all('#processor\s+: [0-9]+#', $sCPU, $aMatches);
return sizeof($aMatches[0]);
return count($aMatches[0]);
}

View File

@ -2,7 +2,7 @@
$aFilteredPlaces = array();
if (!sizeof($aPlace)) {
if (empty($aPlace)) {
if (isset($sError))
$aFilteredPlaces['error'] = $sError;
else $aFilteredPlaces['error'] = 'Unable to geocode';

View File

@ -11,7 +11,7 @@ echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.ope
echo " querystring='".htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES)."'";
echo ">\n";
if (!sizeof($aPlace)) {
if (empty($aPlace)) {
if (isset($sError))
echo "<error>$sError</error>";
else echo '<error>Unable to geocode</error>';

View File

@ -199,7 +199,7 @@
}
}
if (sizeof($aParentOfLines))
if (!empty($aParentOfLines))
{
headline('Parent Of');
@ -223,7 +223,7 @@
_one_row($aAddressLine);
}
}
if (sizeof($aParentOfLines) >= 500) {
if (count($aParentOfLines) >= 500) {
echo '<p>There are more child objects which are not shown.</p>';
}
}

View File

@ -49,7 +49,7 @@ foreach ($aBatchResults as $aSearchResults) {
$aPlace['icon'] = $aPointDetails['icon'];
}
if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) {
if (isset($aPointDetails['address']) && !empty($aPointDetails['address'])) {
$aPlace['address'] = $aPointDetails['address'];
}

View File

@ -57,7 +57,7 @@
echo '</div>';
$i = $i+1;
}
if (sizeof($aSearchResults) && $sMoreURL)
if (!empty($aSearchResults) && $sMoreURL)
{
echo '<div class="more"><a class="btn btn-primary" href="'.htmlentities($sMoreURL).'">Search for more results</a></div>';
}

View File

@ -43,7 +43,7 @@ foreach ($aSearchResults as $iResNum => $aPointDetails) {
$aPlace['icon'] = $aPointDetails['icon'];
}
if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])) {
if (isset($aPointDetails['address']) && !empty($aPointDetails['address'])) {
$aPlace['address'] = $aPointDetails['address'];
}

View File

@ -32,6 +32,13 @@
<!-- eval, system, etc -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array" value="sizeof=>count,delete=>unset,print=>echo,create_function=>null,eval=>null"/>
</properties>
</rule>
<!-- **************************************************************
DOCUMENTATION
************************************************************** -->

View File

@ -241,7 +241,7 @@ function _templatesToProperties($aTemplates)
}
// Assume the first template with lots of params is the type (fallback for infobox)
if (!isset($aPageProperties['sPossibleInfoboxType']) && sizeof($aParams) > 10) {
if (!isset($aPageProperties['sPossibleInfoboxType']) && count($aParams) > 10) {
$aPageProperties['sPossibleInfoboxType'] = trim($aTemplate[0]);
// $aPageProperties['aInfoboxParams'] = $aParams;
}
@ -495,7 +495,7 @@ if (isset($aCMDResult['link'])) {
if (!isset($aNominatRecords[0])) {
$aNameParts = preg_split('#[(,]#', $aRecord['name']);
if (sizeof($aNameParts) > 1) {
if (count($aNameParts) > 1) {
$sNameURL = $sURL.'&q='.urlencode(trim($aNameParts[0]));
var_Dump($sNameURL);
$sXML = file_get_contents($sNameURL);
@ -509,7 +509,7 @@ if (isset($aCMDResult['link'])) {
}
// assume first is best/right
for ($i = 0; $i < sizeof($aNominatRecords); $i++) {
for ($i = 0; $i < count($aNominatRecords); $i++) {
$fDiff = ($aRecord['lat']-$aNominatRecords[$i]['LAT']) * ($aRecord['lat']-$aNominatRecords[$i]['LAT']);
$fDiff += ($aRecord['lon']-$aNominatRecords[$i]['LON']) * ($aRecord['lon']-$aNominatRecords[$i]['LON']);
$fDiff = sqrt($fDiff);

View File

@ -62,7 +62,7 @@ $oPlaceLookup->setIncludeAddressDetails(true);
$aPlaceAddress = array_reverse($oPlaceLookup->getAddressDetails($iPlaceID));
if (!sizeof($aPlaceAddress)) userError('Unknown place id.');
if (empty($aPlaceAddress)) userError('Unknown place id.');
$aBreadcrums = array();
foreach ($aPlaceAddress as $i => $aPlace) {
@ -100,7 +100,7 @@ $sSQL .= ' where parent_place_id in ('.join(',', $aRelatedPlaceIDs).') and name
$sSQL .= ' order by rank_address asc,rank_search asc,localname,class, type,housenumber';
$aParentOfLines = chksql($oDB->getAll($sSQL));
if (sizeof($aParentOfLines)) {
if (!empty($aParentOfLines)) {
echo '<h2>Parent Of:</h2>';
$aClassType = getClassTypesWithImportance();
$aGroupedAddressLines = array();
@ -136,7 +136,7 @@ if (sizeof($aParentOfLines)) {
echo '</div>';
}
}
if (sizeof($aParentOfLines) >= 500) {
if (count($aParentOfLines) >= 500) {
echo '<p>There are more child objects which are not shown.</p>';
}
echo '</div>';

View File

@ -18,7 +18,7 @@ $oDB =& getDB();
$iTotalBroken = (int) chksql($oDB->getOne('select count(*) from import_polygon_error'));
$aPolygons = array();
while ($iTotalBroken && !sizeof($aPolygons)) {
while ($iTotalBroken && empty($aPolygons)) {
$sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",';
$sSQL .= 'country_code as "country",errormessage as "error message",updated';
$sSQL .= ' from import_polygon_error';
@ -32,7 +32,7 @@ while ($iTotalBroken && !sizeof($aPolygons)) {
if ($bReduced) $aWhere[] = "errormessage like 'Area reduced%'";
if ($sClass) $sWhere[] = "class = '".pg_escape_string($sClass)."'";
if (sizeof($aWhere)) {
if (!empty($aWhere)) {
$sSQL .= ' where '.join(' and ', $aWhere);
}

View File

@ -41,7 +41,7 @@ if ($sOsmType && $iOsmId > 0) {
if ($oLookup) {
$aPlaces = $oPlaceLookup->lookup(array($oLookup->iId => $oLookup));
if (sizeof($aPlaces)) {
if (!empty($aPlaces)) {
$aPlace = reset($aPlaces);
}
}

View File

@ -68,7 +68,7 @@ $aSearchResults = $oGeocode->lookup();
if ($sOutputFormat=='html') {
$sDataDate = chksql($oDB->getOne("select TO_CHAR(lastimportdate,'YYYY/MM/DD HH24:MI')||' GMT' from import_status limit 1"));
}
logEnd($oDB, $hLog, sizeof($aSearchResults));
logEnd($oDB, $hLog, count($aSearchResults));
$sQuery = $oGeocode->getQueryString();