Skip to content

Commit

Permalink
Merge pull request #124 from shivammathur/develop
Browse files Browse the repository at this point in the history
3.1.0
  • Loading branch information
shivammathur authored Jul 25, 2020
2 parents 8cafd47 + f2ddd53 commit da5c59b
Show file tree
Hide file tree
Showing 11 changed files with 1,198 additions and 1,891 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
labels: 'bug'
assignees: ''

---
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: [7.4]
php-versions: ['7.4', '8.0']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v2
- name: Set up php and composer
uses: shivammathur/setup-php@develop
with:
php-version: ${{ matrix.php-versions }}
extensions: 'mbstring'
ini-values: 'pcov.directory=api'
coverage: 'pcov'
extensions: iconv, json, mbstring
ini-values: pcov.directory=api
coverage: pcov
tools: composer:v2
- name: Install dependencies
run: composer install --no-progress --no-suggest --prefer-dist
run: composer install --no-progress --prefer-dist --ignore-platform-reqs
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-text
- name: coveralls
run: sh -c php vendor/bin/php-coveralls -v
- name: codecov-umbrella
run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f build/logs/clover.xml -n github-actions-codecov
- name: Send Coverage
continue-on-error: true
timeout-minutes: 1
run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f build/logs/clover.xml -n github-actions-codecov-${{ matrix.operating-system }}-php${{ matrix.php-versions }}

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 shivammathur and contributors
Copyright (c) 2019-2020 shivammathur and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
33 changes: 26 additions & 7 deletions api/v1/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use JsonMachine\JsonMachine;
use Exception;
use phpDocumentor\Reflection\Types\Integer;
use function iconv;
use function mb_stripos;
use function preg_replace;
Expand All @@ -25,7 +26,7 @@ class Location
/**
* Return the json encoded list of all countries.
*
* @author Shivam Mathur <shivam_jpr@hotmail.com>
* @author Shivam Mathur <contact@shivammathur.com>
* @param string|NULL $search
* @return false|string
*/
Expand All @@ -43,7 +44,7 @@ public function getCountries(string $search = NULL)
/**
* Return the json encoded list of all cities in a country.
*
* @author Shivam Mathur <shivam_jpr@hotmail.com>
* @author Shivam Mathur <contact@shivammathur.com>
* @param string $countryName
* @param string|NULL $search
* @return false|string
Expand All @@ -64,7 +65,7 @@ public function getCities(string $countryName, string $search = NULL)
/**
* Return the array containing all countries.
*
* @author Shivam Mathur <shivam_jpr@hotmail.com>
* @author Shivam Mathur <contact@shivammathur.com>
* @param string $haystack
* @param string $needle
* @return bool|false|int
Expand All @@ -80,7 +81,7 @@ public function mb_search(string $haystack, string $needle)
/**
* Return the array containing all countries.
*
* @author Shivam Mathur <shivam_jpr@hotmail.com>
* @author Shivam Mathur <contact@shivammathur.com>
* @param string|NULL $search
* @return array
* @throws Exception
Expand All @@ -96,14 +97,23 @@ private function countries(string $search = NULL)
array_keys(iterator_to_array($data, true)),
fn (string $country) => !$search || $this->mb_search($country, $search) !== false
);
sort($countries);
if(empty($search)) {
sort($countries);
} else {
usort($countries, function (string $a, string $b) use ($search) : int {
if (strpos($a, $search) == strpos($b, $search)) {
return 0;
}
return (strpos($a, $search) < strpos($b, $search)) ? -1 : 1;
});
}
return $countries;
}

/**
* Returns the array containing all cities in a country.
*
* @author Shivam Mathur <shivam_jpr@hotmail.com>
* @author Shivam Mathur <contact@shivammathur.com>
* @param string $countryName
* @param string|NULL $search
* @return array
Expand All @@ -126,7 +136,16 @@ private function cities(string $countryName, string $search = NULL)
$value,
fn (string $city) => !$search || $this->mb_search($city, $search) !== false
);
sort($cities);
if(empty($search)) {
sort($cities);
} else {
usort($cities, function (string $a, string $b) use ($search) : int {
if (strpos($a, $search) == strpos($b, $search)) {
return 0;
}
return (strpos($a, $search) < strpos($b, $search)) ? -1 : 1;
});
}
break;
}
}
Expand Down
12 changes: 4 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@
],
"require": {
"php": "^7.4",
"ext-iconv": "*",
"ext-json": "*",
"ext-mbstring": "*",
"halaxa/json-machine": "*",
"laminas/laminas-httphandlerrunner": "*",
"slim/http-cache": "^0.4.0",
"slim/php-view": "^2.2",
"slim/psr7": "*",
"slim/php-view": "^3.0",
"slim/slim": "^3.12",
"symfony/event-dispatcher": "*",
"symfony/http-kernel": "*",
"symfony/lock": "*",
"symfony/polyfill-iconv": "^1.17",
"symfony/polyfill-mbstring": "^1.17",
"symfony/process": "*"
},
"require-dev": {
"php-coveralls/php-coveralls": "*",
"nikic/php-parser": "*",
"phpunit/php-code-coverage": "dev-master",
"phpunit/php-timer": "dev-master",
"phpunit/phpunit": "dev-master",
"sebastian/global-state": "dev-master",
"sebastian/type": "dev-master",
Expand All @@ -64,6 +59,7 @@
"CountryCity\\Tests\\API\\": "tests/api/v1"
}
},
"minimum-stability": "dev",
"support": {
"email": "contact@shivammathur.com",
"issues": "https://github.com/shivammathur/countrycity/issues"
Expand Down
Loading

0 comments on commit da5c59b

Please sign in to comment.