Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Jan 19, 2022
0 parents commit 54e3ba6
Show file tree
Hide file tree
Showing 11 changed files with 678 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[**.{neon,neon.dist}]
indent_style = tab

[**.{yml,yaml}]
indent_size = 2
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.github/ export-ignore
/tests/ export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
65 changes: 65 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Tests

on:
pull_request:
push:
branches:
- 'main'

jobs:
tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-20.04

strategy:
matrix:
php:
- "8.0"
- "8.1"

env:
extensions: ctype, dom, intl, json, mbstring, openssl, xml, zip, zlib
key: cache-v1 # can be any string, change to clear the extension cache.

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
tools: composer, pecl
coverage: xdebug
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: "ramsey/composer-install@v2"

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Run PHPStan
run: vendor/bin/phpstan analyse

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
run: vendor/bin/phpunit --testdox --coverage-text
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.build/
/vendor/

/composer.lock
/phpstan.neon
/phpunit.xml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Jérôme Gamez, https://github.com/beste <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Geohash

Library to convert a [geohash](https://en.wikipedia.org/wiki/Geohash) to/from a latitude/longitude point, and to
determine bounds of a geohash cell and find neighbours of a geohash.

This is a PHP implementation based on [chrisveness/latlon-geohash](https://github.com/chrisveness/latlon-geohash).
More information (with interactive conversion) at
([www.movable-type.co.uk/scripts/geohash.html](https://www.movable-type.co.uk/scripts/geohash.html)).

## Usage

```php
use Beste\Geohash;

// encode latitude/longitude point to geohash of given precision (number of characters in resulting geohash);
// if precision is not specified, it is inferred from precision of latitude/longitude values.
Geohash::encode(float $lat, float $lon, ?int $precision = null)

// return { lat, lon } of centre of given geohash, to appropriate precision.
Geohash::decode(string $geohash)

// return { sw, ne } bounds of given geohash.
Geohash::bounds(string $geohash)

// return adjacent cell to given geohash in specified direction (n/s/e/w).
Geohash::adjacent(string $geohash, string $direction)

// return all 8 adjacent cells (n/ne/e/se/s/sw/w/nw) to given geohash.
Geohash::neighbours(string $geohash)
```

## Installation

```shell
composer require beste/latlon-geohash
```

## Running tests

```shell
composer run tests
```
52 changes: 52 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "beste/latlon-geohash",
"type": "library",
"description": "Gustavo Niemeyer's geocoding system",
"keywords": ["geohash", "geocoding"],
"license": "MIT",
"authors": [
{
"name": "Jérôme Gamez",
"email": "[email protected]"
}
],
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0"
},
"require-dev": {
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpunit/phpunit": "^9.5.11"
},
"autoload": {
"files": ["src/Geohash.php"]
},
"autoload-dev": {
"psr-4": {
"Beste\\Geohash\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"scripts": {
"clean": "rm -rf .build && mkdir .build",
"phpstan": "vendor/bin/phpstan analyse",
"phpunit": "vendor/bin/phpunit",
"tests": [
"@phpstan",
"@phpunit"
]
},
"scripts-descriptions": {
"clean": "Recreates ",
"phpstan": "Runs static analysis with PHPStan",
"phpunit": "Runs tests with PHPUnit",
"tests": "Runs static analysis and test suites"
}
}
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: max

paths:
- src/
- tests/

tmpDir: .build/phpstan/
20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".build/phpunit/phpunit.cache"
colors="true"
>
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

</phpunit>
Loading

0 comments on commit 54e3ba6

Please sign in to comment.