Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Torann/laravel-geoip
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: InteractionDesignFoundation/laravel-geoip
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
Loading
Showing with 1,973 additions and 713 deletions.
  1. +0 −1 .gitattributes
  2. +54 −0 .github/CONTRIBUTING.md
  3. +11 −0 .github/ISSUE_TEMPLATE/config.yml
  4. +14 −0 .github/dependabot.yml
  5. +22 −0 .github/workflows/backward-compatibility-check.yml
  6. +17 −0 .github/workflows/contributors.yml
  7. +35 −0 .github/workflows/php-coding-style.yml
  8. +42 −0 .github/workflows/run-tests.yml
  9. +33 −0 .github/workflows/static-analysis.yml
  10. +11 −1 .gitignore
  11. +132 −0 .php-cs-fixer.php
  12. +0 −15 .travis.yml
  13. +1 −0 LICENSE
  14. +344 −22 README.md
  15. +71 −67 composer.json
  16. +28 −13 config/geoip.php
  17. +8 −0 docs/README.md
  18. +12 −0 docs/artisan.md
  19. +8 −0 docs/config.md
  20. +16 −0 docs/migration.md
  21. +13 −0 docs/services.md
  22. +38 −0 docs/usage.md
  23. +13 −3 phpstan.neon
  24. +19 −18 phpunit.xml
  25. +381 −0 psalm-baseline.xml
  26. +18 −0 psalm.xml.dist
  27. +29 −0 rector.php
  28. +30 −20 src/Cache.php
  29. +11 −21 src/Console/Clear.php
  30. +19 −22 src/Console/Update.php
  31. +13 −6 src/Contracts/ServiceInterface.php
  32. +11 −0 src/Exceptions/MissingConfigurationException.php
  33. +11 −2 src/Facades/GeoIP.php
  34. +51 −59 src/GeoIP.php
  35. +16 −30 src/GeoIPServiceProvider.php
  36. +42 −35 src/Location.php
  37. +35 −19 src/Services/AbstractService.php
  38. +21 −15 src/Services/IPApi.php
  39. +10 −10 src/Services/IPData.php
  40. +13 −15 src/Services/IPFinder.php
  41. +8 −10 src/Services/IPGeoLocation.php
  42. +80 −28 src/Services/MaxMindDatabase.php
  43. +29 −7 src/Services/MaxMindWebService.php
  44. +27 −18 src/Support/Currencies.php
  45. +50 −70 src/Support/HttpClient.php
  46. +8 −5 src/helpers.php
  47. +31 −81 tests/CacheTest.php
  48. +42 −21 tests/GeoIPTest.php
  49. +26 −26 tests/Services/MaxMindDatabaseTest.php
  50. +19 −31 tests/TestCase.php
  51. +0 −22 tests/TestFunctions.php
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/tests export-ignore
54 changes: 54 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

Please read and understand the contribution guide before creating an issue or pull request.


## Etiquette

This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.

Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.

It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.


## Viability

When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.


## Procedure

Before filing an issue:

- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.


## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

- **[PER-CS2.0 Coding Standard](https://github.com/php-fig/per-coding-style/blob/master/spec.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/InteractionDesignFoundation/laravel-geoip/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/InteractionDesignFoundation/laravel-geoip/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a bug
url: https://github.com/InteractionDesignFoundation/laravel-geoip/issues/new
about: Report a reproducable bug
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: monthly
open-pull-requests-limit: 50
labels:
- "dependencies"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: monthly
22 changes: 22 additions & 0 deletions .github/workflows/backward-compatibility-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: [push]
name: Backward compatibility check

jobs:
bc_check:
name: Backward compatibility check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: fetch tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

# User in the container seems to be different from the cloned repo's owner.
# Git doesn't like that as the repo will then be unusable by the owner.
# We don't care about this here since this is only used for running one test.
# See https://github.com/actions/runner/issues/2033
- name: Workaround directory permissions
run: mkdir -p /home/runner/work/_temp/_github_home && printf "[safe]\n\tdirectory = /github/workspace" > /home/runner/work/_temp/_github_home/.gitconfig

- name: BC Check
uses: docker://nyholm/roave-bc-check-ga
17 changes: 17 additions & 0 deletions .github/workflows/contributors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
push:
branches:
- main

jobs:
contrib-readme-job:
runs-on: ubuntu-latest
name: A job to automate contrib in readme
permissions:
contents: write
pull-requests: write
steps:
- name: Contribute List
uses: akhilmhdh/contributors-readme-action@v2.3.10
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/php-coding-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Coding style

on:
pull_request:
paths:
- '**.php'
- '.composer.json'
- '.php_cs'
- '.github/workflows/php-coding-style.yml'
push:
paths:
- '**.php'
- '.composer.json'
- '.php_cs'
- '.github/workflows/php-coding-style.yml'
branches-ignore:
- main # protected

jobs:
style:
runs-on: ubuntu-latest

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

- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix coding style
42 changes: 42 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: run-tests

on: [ push, pull_request ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.3, 8.2, 8.1]
laravel: [^10.0]
dependencies: [lowest, highest]

name: P${{ matrix.php }} | L${{ matrix.laravel }} | ${{ matrix.dependencies == 'highest' && '↑' || '↓' }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install lowest dependencies from composer.json
if: "matrix.dependencies == 'lowest'"
run: composer update --prefer-dist --no-interaction --prefer-dist --prefer-stable --prefer-lowest

- name: Install highest dependencies from composer.json
if: "matrix.dependencies == 'highest'"
run: composer update --prefer-dist --no-interaction --prefer-dist --prefer-stable

- name: Execute tests
run: composer test
33 changes: 33 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Static Analysis

on:
workflow_dispatch:
push:
paths:
- '**.php'
- 'composer.lock'
- 'psalm*'

jobs:
psalm:
name: Psalm
runs-on: ubuntu-latest
timeout-minutes: 6
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install composer dependencies
run: "composer install --no-interaction --no-progress --no-scripts"

- name: Run Psalm
run: ./vendor/bin/psalm --find-unused-psalm-suppress --output-format=github --shepherd
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/vendor
composer.phar
composer.lock
auth.json

.phpunit.cache/
.phpunit.result.cache

.php-cs-fixer.cache

psalm.xml

# in case a developer don't have global git ignore
.DS_Store
.idea/*
Thumbs.db
/.idea
132 changes: 132 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

declare(strict_types=1);

/**
* @see https://mlocati.github.io/php-cs-fixer-configurator/
*/
$finder = \PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(
[
'vendor',
]
)
->name('*.php')
->ignoreDotFiles(false)
->ignoreVCS(true)
->ignoreVCSIgnored(true);

return (new \PhpCsFixer\Config())
->setUsingCache(true)
->setRiskyAllowed(true)
->setIndent(' ')
->setLineEnding("\n")
->setRules([
// Basic PER Coding Style 2.0 ruleset plus our "fixes" for it
'@PER-CS2.0' => true, // https://www.php-fig.org/per/coding-style/}
// 'concat_space' => ['spacing' => 'none'], // make strings shorter "'hello' . $name . '!'" => "'hello'.$name.'!'"
// 'blank_line_after_opening_tag' => false, // it makes "<?php declare(strict_types=1);" multiline (and more verbose)
'function_declaration' => false, // It makes "fn ()" into "fn()" and conflicts with our PHPCS ruleset
'single_line_empty_body' => false, // It has conflict with PSR2.Classes.ClassDeclaration.OpenBraceNewLine
// 'unary_operator_spaces' => false, // It has conflict with PHPCS ruleset

// Additional rules on the top of PER-CS2
// Please keep these rules alphabetically
'align_multiline_comment' => ['comment_type' => 'phpdocs_only'],
'array_indentation' => true,
'assign_null_coalescing_to_coalesce_equal' => true,
'binary_operator_spaces' => ['default' => 'single_space'],
'cast_spaces' => ['space' => 'single'],
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'declare_strict_types' => true,
'explicit_string_variable' => true,
// 'final_public_method_for_abstract_class' => true, // @todo enable it
'general_phpdoc_annotation_remove' => [
'annotations' => [
'api',
'access',
'author',
'category',
'copyright',
'created',
'license',
'link',
'package',
'since',
'subpackage',
'version',
],
],
'modernize_types_casting' => true,
'no_alias_functions' => true,
'no_binary_string' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => ['tokens' => ['extra', 'curly_brace_block']],
'no_homoglyph_names' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_trailing_comma_in_singleline' => false, // it's a good marker that there are more elements in an array
'no_unneeded_braces' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_concat_operator' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'normalize_index_brace' => true,
'nullable_type_declaration' => ['syntax' => 'question_mark'],
'object_operator_without_whitespace' => true,
/*
* @see https://github.com/slevomat/coding-standard/issues/1620#issuecomment-1758006718
* 'ordered_class_elements' => [
'order' => [
'use_trait',
'constant',
'case', // for enums only
'property',
'method',
]
],*/
'php_unit_construct' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'php_unit_expectation' => true,
'php_unit_fqcn_annotation' => true,
'php_unit_method_casing' => ['case' => 'snake_case'],
'php_unit_no_expectation_annotation' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_test_class_requires_covers' => true,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_indent' => true,
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
'phpdoc_param_order' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_tag_casing' => true,
'phpdoc_types' => true,
'protected_to_private' => true,
'psr_autoloading' => true,
'self_accessor' => true,
'self_static_accessor' => true,
'single_line_comment_spacing' => true,
'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']],
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
'trim_array_spaces' => true,
'trailing_comma_in_multiline' => true,
'type_declaration_spaces' => true,
'types_spaces' => ['space' => 'single'],
'whitespace_after_comma_in_array' => true,
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
])
->setFinder($finder);
Loading