]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge pull request #941 from mtmail/parameter-parser-tests2
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 6 Mar 2018 22:25:20 +0000 (23:25 +0100)
committerGitHub <noreply@github.com>
Tue, 6 Mar 2018 22:25:20 +0000 (23:25 +0100)
PHP tests for ParameterParser

23 files changed:
.travis.yml
CONTRIBUTING.md
docs/CMakeLists.txt
docs/admin/Installation.md
docs/develop/overview.md [new file with mode: 0644]
docs/mkdocs.yml
lib/Geocode.php
lib/SearchDescription.php
lib/template/address-json.php
lib/template/address-jsonv2.php
lib/template/address-xml.php
lib/template/search-batch-json.php
lib/template/search-json.php
lib/template/search-jsonv2.php
lib/template/search-xml.php
module/nominatim.c
phpcs.xml
test/bdd/db/import/parenting.feature
test/bdd/osm2pgsql/update/relation.feature
test/bdd/osm2pgsql/update/simple.feature
test/bdd/steps/cgi-with-coverage.php
test/php/Nominatim/PhraseTest.php
test/php/Nominatim/SearchContextTest.php

index 5efc9f083171489a6d391896047c52afb322cdda..c67f155e4240a1b5e2a0e0e08d0b1937143f36c7 100644 (file)
@@ -22,7 +22,7 @@ script:
   - if [[ $TEST_SUITE == "monaco" ]]; then ./utils/specialphrases.php --wiki-import | psql -d test_api_nominatim >/dev/null; fi
   - cd $TRAVIS_BUILD_DIR/test/php
   - if [[ $TEST_SUITE == "tests" ]]; then phpunit ./ ; fi
-  - if [[ $TEST_SUITE == "tests" ]]; then phpcs --report-width=120 */**.php ; fi
+  - if [[ $TEST_SUITE == "tests" ]]; then phpcs --report-width=120 . ; fi
   - cd $TRAVIS_BUILD_DIR/test/bdd
   - # behave --format=progress3 api
   - if [[ $TEST_SUITE == "tests" ]]; then behave --format=progress3 db ; fi
index a00d0ed354aa68ac5ffe4a00d107253f4c62874d..242a9d6f55fb27ce2ba68c97d8e6c671fccb29b9 100644 (file)
@@ -41,7 +41,7 @@ Please add the following information to your issue:
 
 ## Workflow for Pull Requests
 
-We love to get pull reuqests from you. We operate the "Fork & Pull" model
+We love to get pull requests from you. We operate the "Fork & Pull" model
 explained at
 
 https://help.github.com/articles/using-pull-requests
@@ -65,7 +65,7 @@ that duplicate work can be avoided.
 ## Coding style
 
 Nominatim historically hasn't followed a particular coding style but we
-are in process of consolodating the style. The following rules apply:
+are in process of consolidating the style. The following rules apply:
 
  * Python code uses the official Python style
  * indention
@@ -82,7 +82,7 @@ are in process of consolodating the style. The following rules apply:
 The coding style is enforced with PHPCS and can be tested with:
 
 ```
-  phpcs --report-width=120 --colors */**.php
+  phpcs --report-width=120 --colors .
 ```
 
 ## Testing
index e8596e49f81818314e61333b1a5751fdf84a1df0..d2fe03d018729981128ed7a392949f128229fe81 100644 (file)
@@ -8,6 +8,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/appendix)
 
 ADD_CUSTOM_TARGET(doc
    COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/admin ${CMAKE_CURRENT_BINARY_DIR}/admin
+   COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/develop ${CMAKE_CURRENT_BINARY_DIR}/develop
    COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/index.md ${CMAKE_CURRENT_BINARY_DIR}/index.md
    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Centos-7.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Centos-7.md
    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bash2md.sh ${PROJECT_SOURCE_DIR}/vagrant/Install-on-Ubuntu-16.sh ${CMAKE_CURRENT_BINARY_DIR}/appendix/Install-on-Ubuntu-16.md
index ce7fb412fff8ab69d333a8501e2d488d7c8797f6..67c4fe3c6687639423ef3ed465619ee1516347c8 100644 (file)
@@ -8,6 +8,13 @@ the following operating systems:
 These OS-specific instructions can also be found in executable form
 in the `vagrant/` directory.
 
+Users have created instructions for other frameworks. We haven't tested those
+and can't offer support.
+
+  * [Docker](https://github.com/mediagis/nominatim-docker)
+  * [Docker on Kubernetes](https://github.com/peter-evans/nominatim-k8s)
+  * [Ansible](https://github.com/synthesio/infra-ansible-nominatim)
+
 # Prerequisites
 
 ## Software
diff --git a/docs/develop/overview.md b/docs/develop/overview.md
new file mode 100644 (file)
index 0000000..179eeb0
--- /dev/null
@@ -0,0 +1,24 @@
+# Basic Architecture
+
+Nominatim provides geocoding based on OpenStreetMap data. It uses a Postgresql
+database as a backend for storing the data.
+
+There are three basic parts to Nominatim's architecture: the data import,
+the address computation and the search frontend.
+
+The __data import__ stage reads the raw OSM data and extracts all information
+that is useful for geocoding. This part is done by osm2pgsql, the same tool
+that can also be used to import a rendering database. It uses the special
+gazetteer output plugin in `osm2pgsql/output-gazetter.[ch]pp`. The result of
+the import can be found in the database table `place`.
+
+The __address computation__ or __indexing__ stage takes the data from `place`
+and adds additional information needed for geocoding. It ranks the places by
+importance, links objects that belong together and computes addresses and
+the search index. Most of this work is done in Pl/pqSQL via database triggers
+and can be found in the file `sql/functions.sql`.
+
+The __search frontend__ implements the actual API. It takes queries for
+search and reverse geocoding queries from the user, looks up the data and
+returns the results in the requested format. This part is written in PHP
+and can be found in the `lib/` and `website/` directories.
index d647dd8717a9fd9984d63ea8cf16083275a8ddfc..b0aee5d07fa714238661b2c8b024498455aa2cfe 100644 (file)
@@ -10,6 +10,8 @@ pages:
         - 'Importing and Updating' : 'admin/Import-and-Update.md'
         - 'Migration from older Versions' : 'admin/Migration.md'
         - 'Troubleshooting' : 'admin/Faq.md'
+    - 'Developers Guide':
+        - 'Overview' : 'develop/overview.md'
     - 'Appendix':
         - 'Installation on CentOS 7' : 'appendix/Install-on-Centos-7.md'
         - 'Installation on Ubuntu 16' : 'appendix/Install-on-Ubuntu-16.md'
index d5647c761edbc90a7a575edf17227eb8789f1710..26fafb734fa93d2d0beddbff4e52557537d3fad4 100644 (file)
@@ -921,12 +921,12 @@ class Geocode
                 $aResult['importance'] = 0.001;
                 $aResult['foundorder'] = $aResult['addressimportance'];
             } else {
-                // Adjust importance for the number of exact string matches in the result
+                $aResult['importance'] = max(0.001, $aResult['importance']);
                 $aResult['importance'] *= $this->viewboxImportanceFactor(
                     $aResult['lon'],
                     $aResult['lat']
                 );
-                $aResult['importance'] = max(0.001, $aResult['importance']);
+                // Adjust importance for the number of exact string matches in the result
                 $iCountWords = 0;
                 $sAddress = $aResult['langaddress'];
                 foreach ($aRecheckWords as $i => $sWord) {
index 4ba28e352abe7dee676898a614f20494e5eac177..2e72deccc4792908b8067c9cdd30f0a8762a60ad 100644 (file)
@@ -276,11 +276,12 @@ class SearchDescription
                   && $sPhraseType != 'country'
         ) {
             $iWordID = $aSearchTerm['word_id'];
-            if (sizeof($this->aName)) {
-                if (($sPhraseType == '' || !$bFirstPhrase)
-                    && $sPhraseType != 'country'
-                    && !$bHasPartial
-                ) {
+            // Full words can only be a name if they appear at the beginning
+            // 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 (($sPhraseType == '' || !$bFirstPhrase) && !$bHasPartial) {
                     $oSearch = clone $this;
                     $oSearch->iSearchRank++;
                     $oSearch->aAddress[$iWordID] = $iWordID;
@@ -675,7 +676,7 @@ class SearchDescription
         if ($this->sHouseNumber) {
             $sImportanceSQL = '- abs(26 - address_rank) + 3';
         } else {
-            $sImportanceSQL = '(CASE WHEN importance = 0 OR importance IS NULL THEN 0.75-(search_rank::float/40) ELSE importance END)';
+            $sImportanceSQL = '(CASE WHEN importance = 0 OR importance IS NULL THEN 0.75001-(search_rank::float/40) ELSE importance END)';
         }
         $sImportanceSQL .= $this->oContext->viewboxImportanceSQL('centroid');
         $aOrder[] = "$sImportanceSQL DESC";
index 93abb6017308b485c7634bc9a89fe1d670a07f03..cea8774549cef955eb4c91a783cdccbb835f692c 100644 (file)
@@ -2,20 +2,15 @@
 
 $aFilteredPlaces = array();
 
-if (!sizeof($aPlace))
-{
+if (!sizeof($aPlace)) {
     if (isset($sError))
         $aFilteredPlaces['error'] = $sError;
-    else
-        $aFilteredPlaces['error'] = 'Unable to geocode';
-}
-else
-{
+    else $aFilteredPlaces['error'] = 'Unable to geocode';
+} else {
     if (isset($aPlace['place_id'])) $aFilteredPlaces['place_id'] = $aPlace['place_id'];
-    $aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright";
+    $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright';
     $sOSMType = formatOSMType($aPlace['osm_type']);
-    if ($sOSMType)
-    {
+    if ($sOSMType) {
         $aFilteredPlaces['osm_type'] = $sOSMType;
         $aFilteredPlaces['osm_id'] = $aPlace['osm_id'];
     }
@@ -26,31 +21,25 @@ else
     if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
     if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
 
-    if (isset($aPlace['aBoundingBox']))
-    {
+    if (isset($aPlace['aBoundingBox'])) {
         $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox'];
     }
 
-    if (isset($aPlace['asgeojson']))
-    {
+    if (isset($aPlace['asgeojson'])) {
         $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']);
     }
 
-    if (isset($aPlace['assvg']))
-    {
+    if (isset($aPlace['assvg'])) {
         $aFilteredPlaces['svg'] = $aPlace['assvg'];
     }
 
-    if (isset($aPlace['astext']))
-    {
+    if (isset($aPlace['astext'])) {
         $aFilteredPlaces['geotext'] = $aPlace['astext'];
     }
 
-    if (isset($aPlace['askml']))
-    {
+    if (isset($aPlace['askml'])) {
         $aFilteredPlaces['geokml'] = $aPlace['askml'];
     }
 }
 
 javascript_renderData($aFilteredPlaces);
-
index 229303be6e7325bb19de208299b7323300c3c977..399c978f6701d823539af592a678526f33091e9c 100644 (file)
@@ -2,20 +2,15 @@
 
 $aFilteredPlaces = array();
 
-if (!sizeof($aPlace))
-{
+if (!sizeof($aPlace)) {
     if (isset($sError))
         $aFilteredPlaces['error'] = $sError;
-    else
-        $aFilteredPlaces['error'] = 'Unable to geocode';
-}
-else
-{
+    else $aFilteredPlaces['error'] = 'Unable to geocode';
+} else {
     if ($aPlace['place_id']) $aFilteredPlaces['place_id'] = $aPlace['place_id'];
-    $aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright";
+    $aFilteredPlaces['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright';
     $sOSMType = formatOSMType($aPlace['osm_type']);
-    if ($sOSMType)
-    {
+    if ($sOSMType) {
         $aFilteredPlaces['osm_type'] = $sOSMType;
         $aFilteredPlaces['osm_id'] = $aPlace['osm_id'];
     }
@@ -38,31 +33,25 @@ else
     if (isset($aPlace['sExtraTags'])) $aFilteredPlaces['extratags'] = $aPlace['sExtraTags'];
     if (isset($aPlace['sNameDetails'])) $aFilteredPlaces['namedetails'] = $aPlace['sNameDetails'];
 
-    if (isset($aPlace['aBoundingBox']))
-    {
+    if (isset($aPlace['aBoundingBox'])) {
         $aFilteredPlaces['boundingbox'] = $aPlace['aBoundingBox'];
     }
 
-    if (isset($aPlace['asgeojson']))
-    {
+    if (isset($aPlace['asgeojson'])) {
         $aFilteredPlaces['geojson'] = json_decode($aPlace['asgeojson']);
     }
 
-    if (isset($aPlace['assvg']))
-    {
+    if (isset($aPlace['assvg'])) {
         $aFilteredPlaces['svg'] = $aPlace['assvg'];
     }
 
-    if (isset($aPlace['astext']))
-    {
+    if (isset($aPlace['astext'])) {
         $aFilteredPlaces['geotext'] = $aPlace['astext'];
     }
 
-    if (isset($aPlace['askml']))
-    {
+    if (isset($aPlace['askml'])) {
         $aFilteredPlaces['geokml'] = $aPlace['askml'];
     }
-
 }
 
 javascript_renderData($aFilteredPlaces);
index d3db2eddaeb04ac376e0535b1499587fc94c7470..6183b284dbc3e8df471ffc719e438e1de83dd17a 100644 (file)
 <?php
-header("content-type: text/xml; charset=UTF-8");
+header('content-type: text/xml; charset=UTF-8');
 
-echo "<";
-echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
+echo '<';
+echo '?xml version="1.0" encoding="UTF-8" ?';
 echo ">\n";
 
-echo "<reversegeocode";
+echo '<reversegeocode';
 echo " timestamp='".date(DATE_RFC822)."'";
 echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
 echo " querystring='".htmlspecialchars($_SERVER['QUERY_STRING'], ENT_QUOTES)."'";
 echo ">\n";
 
-if (!sizeof($aPlace))
-{
+if (!sizeof($aPlace)) {
     if (isset($sError))
         echo "<error>$sError</error>";
-    else
-        echo "<error>Unable to geocode</error>";
-}
-else
-{
-    echo "<result";
+    else echo '<error>Unable to geocode</error>';
+} else {
+    echo '<result';
     if ($aPlace['place_id']) echo ' place_id="'.$aPlace['place_id'].'"';
     $sOSMType = formatOSMType($aPlace['osm_type']);
     if ($sOSMType) echo ' osm_type="'.$sOSMType.'"'.' osm_id="'.$aPlace['osm_id'].'"';
     if ($aPlace['ref']) echo ' ref="'.htmlspecialchars($aPlace['ref']).'"';
     if (isset($aPlace['lat'])) echo ' lat="'.htmlspecialchars($aPlace['lat']).'"';
     if (isset($aPlace['lon'])) echo ' lon="'.htmlspecialchars($aPlace['lon']).'"';
-    if (isset($aPlace['aBoundingBox']))
-    {
+    if (isset($aPlace['aBoundingBox'])) {
         echo ' boundingbox="';
         echo join(',', $aPlace['aBoundingBox']);
         echo '"';
     }
 
-    if (isset($aPlace['asgeojson']))
-    {
+    if (isset($aPlace['asgeojson'])) {
         echo ' geojson=\'';
         echo $aPlace['asgeojson'];
         echo '\'';
     }
 
-    if (isset($aPlace['assvg']))
-    {
+    if (isset($aPlace['assvg'])) {
         echo ' geosvg=\'';
         echo $aPlace['assvg'];
         echo '\'';
     }
 
-    if (isset($aPlace['astext']))
-    {
+    if (isset($aPlace['astext'])) {
         echo ' geotext=\'';
         echo $aPlace['astext'];
         echo '\'';
     }
-    echo ">".htmlspecialchars($aPlace['langaddress'])."</result>";
+    echo '>'.htmlspecialchars($aPlace['langaddress']).'</result>';
 
-    if (isset($aPlace['aAddress']))
-    {
-        echo "<addressparts>";
-        foreach($aPlace['aAddress'] as $sKey => $sValue)
-        {
-            $sKey = str_replace(' ','_',$sKey);
+    if (isset($aPlace['aAddress'])) {
+        echo '<addressparts>';
+        foreach ($aPlace['aAddress'] as $sKey => $sValue) {
+            $sKey = str_replace(' ', '_', $sKey);
             echo "<$sKey>";
             echo htmlspecialchars($sValue);
             echo "</$sKey>";
         }
-        echo "</addressparts>";
+        echo '</addressparts>';
     }
 
-    if (isset($aPlace['sExtraTags']))
-    {
-        echo "<extratags>";
-        foreach ($aPlace['sExtraTags'] as $sKey => $sValue)
-        {
+    if (isset($aPlace['sExtraTags'])) {
+        echo '<extratags>';
+        foreach ($aPlace['sExtraTags'] as $sKey => $sValue) {
             echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
         }
-        echo "</extratags>";
+        echo '</extratags>';
     }
 
-    if (isset($aPlace['sNameDetails']))
-    {
-        echo "<namedetails>";
-        foreach ($aPlace['sNameDetails'] as $sKey => $sValue)
-        {
+    if (isset($aPlace['sNameDetails'])) {
+        echo '<namedetails>';
+        foreach ($aPlace['sNameDetails'] as $sKey => $sValue) {
             echo '<name desc="'.htmlspecialchars($sKey).'">';
             echo htmlspecialchars($sValue);
-            echo "</name>";
+            echo '</name>';
         }
-        echo "</namedetails>";
+        echo '</namedetails>';
     }
 
-    if (isset($aPlace['askml']))
-    {
+    if (isset($aPlace['askml'])) {
         echo "\n<geokml>";
         echo $aPlace['askml'];
-        echo "</geokml>";
+        echo '</geokml>';
     }
-
 }
 
-echo "</reversegeocode>";
+echo '</reversegeocode>';
index a3ced45bc35bb46ec3fab5be00f04229a952a507..09ea48b63bdbc2a964ac4134de5fcd0d43084dfb 100644 (file)
@@ -1,42 +1,37 @@
 <?php
 
 $aOutput = array();
-$aOutput['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright";
+$aOutput['licence'] = 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright';
 $aOutput['batch'] = array();
 
-foreach($aBatchResults as $aSearchResults)
-{
+foreach ($aBatchResults as $aSearchResults) {
     if (!$aSearchResults) $aSearchResults = array();
     $aFilteredPlaces = array();
-    foreach($aSearchResults as $iResNum => $aPointDetails)
-    {
+    foreach ($aSearchResults as $iResNum => $aPointDetails) {
         $aPlace = array(
-                    'place_id'=>$aPointDetails['place_id'],
-                );
+                   'place_id'=>$aPointDetails['place_id'],
+                  );
 
         $sOSMType = formatOSMType($aPointDetails['osm_type']);
-        if ($sOSMType)
-        {
+        if ($sOSMType) {
             $aPlace['osm_type'] = $sOSMType;
             $aPlace['osm_id'] = $aPointDetails['osm_id'];
         }
 
-        if (isset($aPointDetails['aBoundingBox']))
-        {
+        if (isset($aPointDetails['aBoundingBox'])) {
             $aPlace['boundingbox'] = array(
-                $aPointDetails['aBoundingBox'][0],
-                $aPointDetails['aBoundingBox'][1],
-                $aPointDetails['aBoundingBox'][2],
-                $aPointDetails['aBoundingBox'][3]);
+                                      $aPointDetails['aBoundingBox'][0],
+                                      $aPointDetails['aBoundingBox'][1],
+                                      $aPointDetails['aBoundingBox'][2],
+                $aPointDetails['aBoundingBox'][3]
+                                     );
 
-            if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons)
-            {
+            if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) {
                 $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
             }
         }
 
-        if (isset($aPointDetails['zoom']))
-        {
+        if (isset($aPointDetails['zoom'])) {
             $aPlace['zoom'] = $aPointDetails['zoom'];
         }
 
@@ -50,33 +45,27 @@ foreach($aBatchResults as $aSearchResults)
 
         $aPlace['importance'] = $aPointDetails['importance'];
 
-        if (isset($aPointDetails['icon']))
-        {
+        if (isset($aPointDetails['icon'])) {
             $aPlace['icon'] = $aPointDetails['icon'];
         }
 
-        if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0)
-        {
+        if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) {
             $aPlace['address'] = $aPointDetails['address'];
         }
 
-        if (isset($aPointDetails['asgeojson']))
-        {
+        if (isset($aPointDetails['asgeojson'])) {
             $aPlace['geojson'] = json_decode($aPointDetails['asgeojson']);
         }
 
-        if (isset($aPointDetails['assvg']))
-        {
+        if (isset($aPointDetails['assvg'])) {
             $aPlace['svg'] = $aPointDetails['assvg'];
         }
 
-        if (isset($aPointDetails['astext']))
-        {
+        if (isset($aPointDetails['astext'])) {
             $aPlace['geotext'] = $aPointDetails['astext'];
         }
 
-        if (isset($aPointDetails['askml']))
-        {
+        if (isset($aPointDetails['askml'])) {
             $aPlace['geokml'] = $aPointDetails['askml'];
         }
 
index 846d654c5e3b5fb5da8b317ccb5cf9319d03a268..b997f6d97b1fcb01f7ed12b74f8f3468b5d8377a 100644 (file)
@@ -1,33 +1,28 @@
 <?php
-header("content-type: application/json; charset=UTF-8");
+header('content-type: application/json; charset=UTF-8');
 
 $aFilteredPlaces = array();
-foreach($aSearchResults as $iResNum => $aPointDetails)
-{
+foreach ($aSearchResults as $iResNum => $aPointDetails) {
     $aPlace = array(
-            'place_id'=>$aPointDetails['place_id'],
-            'licence'=>"Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright",
-        );
+               'place_id'=>$aPointDetails['place_id'],
+               'licence'=>'Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright',
+              );
     
     $sOSMType = formatOSMType($aPointDetails['osm_type']);
-    if ($sOSMType)
-    {
+    if ($sOSMType) {
         $aPlace['osm_type'] = $sOSMType;
         $aPlace['osm_id'] = $aPointDetails['osm_id'];
     }
 
-    if (isset($aPointDetails['aBoundingBox']))
-    {
+    if (isset($aPointDetails['aBoundingBox'])) {
         $aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
 
-        if (isset($aPointDetails['aPolyPoints']))
-        {
+        if (isset($aPointDetails['aPolyPoints'])) {
             $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
         }
     }
 
-    if (isset($aPointDetails['zoom']))
-    {
+    if (isset($aPointDetails['zoom'])) {
         $aPlace['zoom'] = $aPointDetails['zoom'];
     }
 
@@ -40,33 +35,27 @@ foreach($aSearchResults as $iResNum => $aPointDetails)
 
     $aPlace['importance'] = $aPointDetails['importance'];
 
-    if (isset($aPointDetails['icon']) && $aPointDetails['icon'])
-    {
+    if (isset($aPointDetails['icon']) && $aPointDetails['icon']) {
         $aPlace['icon'] = $aPointDetails['icon'];
     }
 
-    if (isset($aPointDetails['address']))
-    {
+    if (isset($aPointDetails['address'])) {
         $aPlace['address'] = $aPointDetails['address'];
     }
 
-    if (isset($aPointDetails['asgeojson']))
-    {
+    if (isset($aPointDetails['asgeojson'])) {
         $aPlace['geojson'] = json_decode($aPointDetails['asgeojson']);
     }
 
-    if (isset($aPointDetails['assvg']))
-    {
+    if (isset($aPointDetails['assvg'])) {
         $aPlace['svg'] = $aPointDetails['assvg'];
     }
 
-    if (isset($aPointDetails['astext']))
-    {
+    if (isset($aPointDetails['astext'])) {
         $aPlace['geotext'] = $aPointDetails['astext'];
     }
 
-    if (isset($aPointDetails['askml']))
-    {
+    if (isset($aPointDetails['askml'])) {
         $aPlace['geokml'] = $aPointDetails['askml'];
     }
 
index 5d2802afe60b36f8d5351410832adaf5a9feb4bf..7610330419435279101c01b432d3f468fb97f525 100644 (file)
@@ -1,32 +1,27 @@
 <?php
 
 $aFilteredPlaces = array();
-foreach($aSearchResults as $iResNum => $aPointDetails)
-{
+foreach ($aSearchResults as $iResNum => $aPointDetails) {
     $aPlace = array(
-            'place_id'=>$aPointDetails['place_id'],
-            'licence'=>"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
-        );
+               'place_id'=>$aPointDetails['place_id'],
+               'licence'=>'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright',
+              );
 
     $sOSMType = formatOSMType($aPointDetails['osm_type']);
-    if ($sOSMType)
-    {
+    if ($sOSMType) {
         $aPlace['osm_type'] = $sOSMType;
         $aPlace['osm_id'] = $aPointDetails['osm_id'];
     }
 
-    if (isset($aPointDetails['aBoundingBox']))
-    {
+    if (isset($aPointDetails['aBoundingBox'])) {
         $aPlace['boundingbox'] = $aPointDetails['aBoundingBox'];
 
-        if (isset($aPointDetails['aPolyPoints']))
-        {
+        if (isset($aPointDetails['aPolyPoints'])) {
             $aPlace['polygonpoints'] = $aPointDetails['aPolyPoints'];
         }
     }
 
-    if (isset($aPointDetails['zoom']))
-    {
+    if (isset($aPointDetails['zoom'])) {
         $aPlace['zoom'] = $aPointDetails['zoom'];
     }
 
@@ -40,33 +35,27 @@ foreach($aSearchResults as $iResNum => $aPointDetails)
 
     $aPlace['importance'] = $aPointDetails['importance'];
 
-    if (isset($aPointDetails['icon']))
-    {
+    if (isset($aPointDetails['icon'])) {
         $aPlace['icon'] = $aPointDetails['icon'];
     }
 
-    if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0)
-    {
+    if (isset($aPointDetails['address']) && sizeof($aPointDetails['address'])>0) {
         $aPlace['address'] = $aPointDetails['address'];
     }
 
-    if (isset($aPointDetails['asgeojson']))
-    {
+    if (isset($aPointDetails['asgeojson'])) {
         $aPlace['geojson'] = json_decode($aPointDetails['asgeojson']);
     }
 
-    if (isset($aPointDetails['assvg']))
-    {
+    if (isset($aPointDetails['assvg'])) {
         $aPlace['svg'] = $aPointDetails['assvg'];
     }
 
-    if (isset($aPointDetails['astext']))
-    {
+    if (isset($aPointDetails['astext'])) {
         $aPlace['geotext'] = $aPointDetails['astext'];
     }
 
-    if (isset($aPointDetails['askml']))
-    {
+    if (isset($aPointDetails['askml'])) {
         $aPlace['geokml'] = $aPointDetails['askml'];
     }
 
index 80414fce6829be2f18534e06431aabbb2b9f8db3..94bb7ec96a44cdbfae7a150e6044883650a4ead2 100644 (file)
@@ -1,72 +1,63 @@
 <?php
-header("content-type: text/xml; charset=UTF-8");
+header('content-type: text/xml; charset=UTF-8');
 
-echo "<";
-echo "?xml version=\"1.0\" encoding=\"UTF-8\" ?";
+echo '<';
+echo '?xml version="1.0" encoding="UTF-8" ?';
 echo ">\n";
 
-echo "<";
+echo '<';
 echo (isset($sXmlRootTag)?$sXmlRootTag:'searchresults');
 echo " timestamp='".date(DATE_RFC822)."'";
 echo " attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright'";
 echo " querystring='".htmlspecialchars($sQuery, ENT_QUOTES)."'";
 if (isset($aMoreParams['viewbox'])) echo " viewbox='".htmlspecialchars($aMoreParams['viewbox'], ENT_QUOTES)."'";
 echo " polygon='".(isset($aMoreParams['polygon'])?'true':'false')."'";
-if (isset($aMoreParams['exclude_place_ids']))
-{
+if (isset($aMoreParams['exclude_place_ids'])) {
     echo " exclude_place_ids='".htmlspecialchars($aMoreParams['exclude_place_ids'])."'";
 }
 echo " more_url='".htmlspecialchars($sMoreURL)."'";
 echo ">\n";
 
-foreach($aSearchResults as $iResNum => $aResult)
-{
+foreach ($aSearchResults as $iResNum => $aResult) {
     echo "<place place_id='".$aResult['place_id']."'";
     $sOSMType = formatOSMType($aResult['osm_type']);
-    if ($sOSMType)
-    {
+    if ($sOSMType) {
         echo " osm_type='$sOSMType'";
         echo " osm_id='".$aResult['osm_id']."'";
     }
     echo " place_rank='".$aResult['rank_search']."'";
 
-    if (isset($aResult['aBoundingBox']))
-    {
+    if (isset($aResult['aBoundingBox'])) {
         echo ' boundingbox="';
-        echo join(',',$aResult['aBoundingBox']);
+        echo join(',', $aResult['aBoundingBox']);
         echo '"';
 
-        if (isset($aResult['aPolyPoints']))
-        {
+        if (isset($aResult['aPolyPoints'])) {
             echo ' polygonpoints=\'';
             echo json_encode($aResult['aPolyPoints']);
             echo '\'';
         }
     }
 
-    if (isset($aResult['asgeojson']))
-    {
+    if (isset($aResult['asgeojson'])) {
         echo ' geojson=\'';
         echo $aResult['asgeojson'];
         echo '\'';
     }
 
-    if (isset($aResult['assvg']))
-    {
+    if (isset($aResult['assvg'])) {
         echo ' geosvg=\'';
         echo $aResult['assvg'];
         echo '\'';
     }
 
-    if (isset($aResult['astext']))
-    {
+    if (isset($aResult['astext'])) {
         echo ' geotext=\'';
         echo $aResult['astext'];
         echo '\'';
     }
 
-    if (isset($aResult['zoom']))
-    {
+    if (isset($aResult['zoom'])) {
         echo " zoom='".$aResult['zoom']."'";
     }
 
@@ -77,82 +68,67 @@ foreach($aSearchResults as $iResNum => $aResult)
     echo " class='".htmlspecialchars($aResult['class'])."'";
     echo " type='".htmlspecialchars($aResult['type'], ENT_QUOTES)."'";
     echo " importance='".htmlspecialchars($aResult['importance'])."'";
-    if (isset($aResult['icon']) && $aResult['icon'])
-    {
+    if (isset($aResult['icon']) && $aResult['icon']) {
         echo " icon='".htmlspecialchars($aResult['icon'], ENT_QUOTES)."'";
     }
 
     $bHasDelim = false;
 
-    if (isset($aResult['askml']))
-    {
-        if (!$bHasDelim)
-        {
+    if (isset($aResult['askml'])) {
+        if (!$bHasDelim) {
             $bHasDelim = true;
-            echo ">";
+            echo '>';
         }
         echo "\n<geokml>";
         echo $aResult['askml'];
-        echo "</geokml>";
+        echo '</geokml>';
     }
 
-    if (isset($aResult['sExtraTags']))
-    {
-        if (!$bHasDelim)
-        {
+    if (isset($aResult['sExtraTags'])) {
+        if (!$bHasDelim) {
             $bHasDelim = true;
-            echo ">";
+            echo '>';
         }
         echo "\n<extratags>";
-        foreach ($aResult['sExtraTags'] as $sKey => $sValue)
-        {
+        foreach ($aResult['sExtraTags'] as $sKey => $sValue) {
             echo '<tag key="'.htmlspecialchars($sKey).'" value="'.htmlspecialchars($sValue).'"/>';
         }
-        echo "</extratags>";
+        echo '</extratags>';
     }
 
-    if (isset($aResult['sNameDetails']))
-    {
-        if (!$bHasDelim)
-        {
+    if (isset($aResult['sNameDetails'])) {
+        if (!$bHasDelim) {
             $bHasDelim = true;
-            echo ">";
+            echo '>';
         }
         echo "\n<namedetails>";
-        foreach ($aResult['sNameDetails'] as $sKey => $sValue)
-        {
+        foreach ($aResult['sNameDetails'] as $sKey => $sValue) {
             echo '<name desc="'.htmlspecialchars($sKey).'">';
             echo htmlspecialchars($sValue);
-            echo "</name>";
+            echo '</name>';
         }
-        echo "</namedetails>";
+        echo '</namedetails>';
     }
 
-    if (isset($aResult['address']))
-    {
-        if (!$bHasDelim)
-        {
+    if (isset($aResult['address'])) {
+        if (!$bHasDelim) {
             $bHasDelim = true;
-            echo ">";
+            echo '>';
         }
         echo "\n";
-        foreach($aResult['address'] as $sKey => $sValue)
-        {
-            $sKey = str_replace(' ','_',$sKey);
+        foreach ($aResult['address'] as $sKey => $sValue) {
+            $sKey = str_replace(' ', '_', $sKey);
             echo "<$sKey>";
             echo htmlspecialchars($sValue);
             echo "</$sKey>";
         }
     }
 
-    if ($bHasDelim)
-    {
-        echo "</place>";
-    }
-    else
-    {
-        echo "/>";
+    if ($bHasDelim) {
+        echo '</place>';
+    } else {
+        echo '/>';
     }
 }
 
-echo "</" . (isset($sXmlRootTag)?$sXmlRootTag:'searchresults') . ">";
+echo '</' . (isset($sXmlRootTag)?$sXmlRootTag:'searchresults') . '>';
index 75238e2207ff172aad46771569b091d7e73980d5..73bf16c8df487eac4d462621fe566534e6476621 100644 (file)
@@ -157,17 +157,18 @@ transliteration( PG_FUNCTION_ARGS )
        PG_RETURN_TEXT_P(result);
 }
 
+// Set isspace=1 if the replacement _only_ adds a space before the search string.  I.e. to == " " + from
 void str_replace(char* buffer, int* len, int* changes, char* from, int fromlen, char* to, int tolen, int isspace)
 {
         char *p;
 
-        // Search string is too long to be pressent
+        // Search string is too long to be present
         if (fromlen > *len) return;
 
         p = strstr(buffer, from);
         while(p)
         {
-                if (!isspace || *(p-1) != ' ')
+                if (!isspace || (p > buffer && *(p-1) != ' '))
                 {
                         (*changes)++;
                         if (tolen != fromlen) memmove(p+tolen, p+fromlen, *len-(p-buffer)+1);
@@ -230,7 +231,7 @@ gettokenstring( PG_FUNCTION_ARGS )
        sourcedata = (unsigned char *)VARDATA(source);
        sourcedatalength = VARSIZE(source) - VARHDRSZ;
 
-       // Buffer for doing the replace in - string could get slightly longer (double is mastive overkill)
+       // Buffer for doing the replace in - string could get slightly longer (double is massive overkill)
        buffer = (char *)palloc((sourcedatalength*2)*sizeof(char));
        memcpy(buffer+1, sourcedata, sourcedatalength);
        buffer[0] = 32;
index 8f92f7c99078b87ca7f0bfd213fe93bfe5c44315..a48b5c3e608db00b6ad24a4e3d979af7537e581d 100644 (file)
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -8,6 +8,12 @@
   <!-- https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml -->
   <rule ref="PSR2"/>
 
+  <exclude-pattern>./lib/template/*html*</exclude-pattern>
+  <exclude-pattern>./lib/template/includes/</exclude-pattern>
+  <exclude-pattern>./module/</exclude-pattern>
+  <exclude-pattern>./website/css</exclude-pattern>
+  <exclude-pattern>./website/js</exclude-pattern>
+
   <rule ref="Generic.Files.LineLength">
     <properties>
      <property name="lineLimit" value="194"/>
        INDENTATION, SPACING
        ************************************************************** -->
 
-  <!-- We don't need 2 blank lines after function -->
-  <rule ref="Squiz.WhiteSpace.FunctionSpacing.After">
-    <severity>0</severity>
-  </rule>
-
-  <!-- Aligned looks nicer, but causes too many warnings currently -->
-  <rule ref="Generic.Formatting.MultipleStatementAlignment.NotSame">
-    <severity>0</severity>
-  </rule>
-  <rule ref="Generic.Formatting.MultipleStatementAlignment.NotSameWarning">
-    <severity>0</severity>
-  </rule>
-
   <!-- Aligned looks nicer, but causes too many warnings currently -->
   <rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
     <severity>0</severity>
index 401a58f14676dd08425bb6395c8b4ae42b6fa582..87467fd287a22603d2c1c10f9c8384adfcba6f26 100644 (file)
@@ -20,12 +20,12 @@ Feature: Parenting of objects
          | N2     | W1 |
         When searching for "4 galoo"
         Then results contain
-         | ID | osm_type | osm_id | langaddress
-         | 0  | N        | 1      | 4, galoo, 12345
+         | ID | osm_type | osm_id | langaddress |
+         | 0  | N        | 1      | 4, galoo, 12345 |
         When searching for "5 galoo"
         Then results contain
-         | ID | osm_type | osm_id | langaddress
-         | 0  | N        | 2      | 5, galoo, 99999
+         | ID | osm_type | osm_id | langaddress |
+         | 0  | N        | 2      | 5, galoo, 99999 |
 
     Scenario: Address without tags, closest street
         Given the scene roads-with-pois
index 83ce912989f46b20c8a4b3d348f3d6a6c1ded7d9..fd8b83e3c07cfc07a7bfa7329973afae84852a95 100644 (file)
@@ -11,11 +11,11 @@ Feature: Update of relations by osm2pgsql
           n202 x0.0001 y0.0001
           n203 x0.0001 y0
           w2 Tref=45' Nn200,n201,n202,n203,n200
-          r1 Ttype=multipolygon,tourism=hotel,name=XZ' Mw2@
+          r1 Ttype=multipolygon,tourism=hotel,name=XZ Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'XZ' |
           When updating osm data
             """
             r1 Ttype=multipolygon,tourism=hotel,name=XZ Mn1@
@@ -34,16 +34,16 @@ Feature: Update of relations by osm2pgsql
           r1 Ttype=multipolygon,tourism=hotel,name=XZ Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'XZ' |
         When updating osm data
           """
           r1 Ttype=multipolygon,amenity=prison,name=XZ Mw2@
           """
         Then place has no entry for R1:tourism
         And place contains
-          | object | class   | type   | name
-          | R1     | amenity | prison | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | amenity | prison | 'name' : 'XZ' |
 
     Scenario: Change name of a relation
         When loading osm data
@@ -56,15 +56,15 @@ Feature: Update of relations by osm2pgsql
           r1 Ttype=multipolygon,tourism=hotel,name=AB Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'AB'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'AB' |
         When updating osm data
           """
           r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'XY' |
 
     Scenario: Change type of a relation into something unknown
         When loading osm data
@@ -77,8 +77,8 @@ Feature: Update of relations by osm2pgsql
           r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'XY' |
         When updating osm data
           """
           r1 Ttype=multipolygon,amenities=prison,name=XY Mw2@
@@ -96,8 +96,8 @@ Feature: Update of relations by osm2pgsql
           r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'XY' |
         When updating osm data
           """
           r1 Ttourism=hotel,name=XY Mw2@
@@ -115,8 +115,8 @@ Feature: Update of relations by osm2pgsql
           r1 Ttype=multipolygon,tourism=hotel,name=XY Mw2@
           """
         Then place contains
-          | object | class   | type   | name
-          | R1     | tourism | hotel  | 'name' : 'XZ'
+          | object | class   | type   | name |
+          | R1     | tourism | hotel  | 'name' : 'XY' |
         When updating osm data
           """
           r1 Ttype=multipolygonn,tourism=hotel,name=XY Mw2@
index 33c21039e1425a5a4dc4487407de86a643d2720e..e8d96d44e3e372733b5abf1247314452d50c0159 100644 (file)
@@ -9,10 +9,10 @@ Feature: Update of simple objects by osm2pgsql
           n2 Tplace=locality,name=spotty
           """
         Then place contains
-          | object     | type       | name
-          | N1:tourism | hotel      | 'name' : 'foo'
-          | N1:amenity | restaurant | 'name' : 'foo'
-          | N2:place   | locality   | 'name' : 'spotty'
+          | object     | type       | name+name |
+          | N1:tourism | hotel      | foo |
+          | N1:amenity | restaurant | foo |
+          | N2:place   | locality   | spotty |
         When updating osm data
           """
           n1 dV Ttourism=hotel,name=foo
@@ -21,6 +21,6 @@ Feature: Update of simple objects by osm2pgsql
         Then place has no entry for N1:amenity
         And place has no entry for N2
         And place contains
-          | object     | class   | type       | name
-          | N1:tourism | tourism | hotel      | 'name' : 'foo'
+          | object     | class   | type       | name |
+          | N1:tourism | tourism | hotel      | 'name' : 'foo' |
 
index 165a1b0cd9b312870b4bff750287e865f9ee9e51..47d3cc9ac6760c248cda6a0f56a33f726b302a90 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once 'SebastianBergmann/CodeCoverage/autoload.php';
 
+
 function coverage_shutdown($oCoverage)
 {
     $oCoverage->stop();
@@ -16,5 +17,3 @@ $coverage->start($_SERVER['COV_TEST_NAME']);
 register_shutdown_function('coverage_shutdown', $coverage);
 
 include $_SERVER['COV_SCRIPT_FILENAME'];
-
-
index db8d8b50808ad8325dbcc769908d5fcbe0ee7d7b..b5e6c1bf6e666b0f3a6c631648f3bc24865566e6 100644 (file)
@@ -6,6 +6,8 @@ require_once '../../lib/Phrase.php';
 
 class PhraseTest extends \PHPUnit_Framework_TestCase
 {
+
+
     private function serializeSets($aSets)
     {
         $aParts = array();
index a40d0716aa25a9f635b6b1919f4a2342a88b4ab3..2a74dc41c5b6a21cb14bab50257b95e5e19c309f 100644 (file)
@@ -10,6 +10,7 @@ class SearchContextTest extends \PHPUnit_Framework_TestCase
 {
     private $oCtx;
 
+
     protected function setUp()
     {
         $this->oCtx = new SearchContext();