Skip to content

Commit 4e05e89

Browse files
committed
Merge branch 'refs/heads/main' into curl-instead-allow_url_fopen
# Conflicts: # psalm-baseline.xml # src/Services/MaxMindDatabase.php
2 parents de4dec1 + c4b73d3 commit 4e05e89

40 files changed

+689
-504
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Before submitting a pull request:
4444

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

47-
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
47+
- **[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).
4848
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
4949
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
5050
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.

.github/workflows/backward-compatibility-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
name: Backward compatibility check
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010

1111
- name: fetch tags
1212
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Coding style
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.php'
7+
- '.composer.json'
8+
- '.php_cs'
9+
- '.github/workflows/php-coding-style.yml'
10+
push:
11+
paths:
12+
- '**.php'
13+
- '.composer.json'
14+
- '.php_cs'
15+
- '.github/workflows/php-coding-style.yml'
16+
branches-ignore:
17+
- main # protected
18+
19+
jobs:
20+
style:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Fix style
28+
uses: docker://oskarstark/php-cs-fixer-ga
29+
with:
30+
args: --config=.php-cs-fixer.php --allow-risky=yes
31+
32+
- name: Commit changes
33+
uses: stefanzweifel/git-auto-commit-action@v5
34+
with:
35+
commit_message: Fix coding style

.github/workflows/run-tests.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
php: [8.2, 8.1, 8.0]
12-
laravel: [^10.0, ^9.0]
11+
php: [8.3, 8.2, 8.1]
12+
laravel: [^10.0]
1313
dependencies: [lowest, highest]
14-
exclude:
15-
- php: 8.0
16-
laravel: ^10.0
1714

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

2017
steps:
2118
- name: Checkout code
22-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2320

2421
- name: Setup PHP
2522
uses: shivammathur/setup-php@v2

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ jobs:
1414
runs-on: ubuntu-latest
1515
timeout-minutes: 6
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818
with:
1919
ref: ${{ github.head_ref }}
2020

2121
- name: Setup PHP
2222
uses: shivammathur/setup-php@v2
2323
with:
24-
php-version: 8.2
24+
php-version: 8.3
2525
coverage: none
2626
env:
2727
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ auth.json
66
.phpunit.cache/
77
.phpunit.result.cache
88

9+
.php-cs-fixer.cache
10+
911
psalm.xml
1012

1113
# in case a developer don't have global git ignore

.php-cs-fixer.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @see https://mlocati.github.io/php-cs-fixer-configurator/
7+
*/
8+
$finder = \PhpCsFixer\Finder::create()
9+
->in(__DIR__)
10+
->exclude(
11+
[
12+
'vendor',
13+
]
14+
)
15+
->name('*.php')
16+
->ignoreDotFiles(false)
17+
->ignoreVCS(true)
18+
->ignoreVCSIgnored(true);
19+
20+
return (new \PhpCsFixer\Config())
21+
->setUsingCache(true)
22+
->setRiskyAllowed(true)
23+
->setIndent(' ')
24+
->setLineEnding("\n")
25+
->setRules([
26+
// Basic PER Coding Style 2.0 ruleset plus our "fixes" for it
27+
'@PER-CS2.0' => true, // https://www.php-fig.org/per/coding-style/}
28+
// 'concat_space' => ['spacing' => 'none'], // make strings shorter "'hello' . $name . '!'" => "'hello'.$name.'!'"
29+
// 'blank_line_after_opening_tag' => false, // it makes "<?php declare(strict_types=1);" multiline (and more verbose)
30+
'function_declaration' => false, // It makes "fn ()" into "fn()" and conflicts with our PHPCS ruleset
31+
'single_line_empty_body' => false, // It has conflict with PSR2.Classes.ClassDeclaration.OpenBraceNewLine
32+
// 'unary_operator_spaces' => false, // It has conflict with PHPCS ruleset
33+
34+
// Additional rules on the top of PER-CS2
35+
// Please keep these rules alphabetically
36+
'align_multiline_comment' => ['comment_type' => 'phpdocs_only'],
37+
'array_indentation' => true,
38+
'assign_null_coalescing_to_coalesce_equal' => true,
39+
'binary_operator_spaces' => ['default' => 'single_space'],
40+
'cast_spaces' => ['space' => 'single'],
41+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
42+
'declare_strict_types' => true,
43+
'explicit_string_variable' => true,
44+
// 'final_public_method_for_abstract_class' => true, // @todo enable it
45+
'general_phpdoc_annotation_remove' => [
46+
'annotations' => [
47+
'api',
48+
'access',
49+
'author',
50+
'category',
51+
'copyright',
52+
'created',
53+
'license',
54+
'link',
55+
'package',
56+
'since',
57+
'subpackage',
58+
'version',
59+
],
60+
],
61+
'modernize_types_casting' => true,
62+
'no_alias_functions' => true,
63+
'no_binary_string' => true,
64+
'no_empty_comment' => true,
65+
'no_empty_phpdoc' => true,
66+
'no_empty_statement' => true,
67+
'no_extra_blank_lines' => ['tokens' => ['extra', 'curly_brace_block']],
68+
'no_homoglyph_names' => true,
69+
'no_leading_namespace_whitespace' => true,
70+
'no_mixed_echo_print' => true,
71+
'no_short_bool_cast' => true,
72+
'no_singleline_whitespace_before_semicolons' => true,
73+
'no_spaces_around_offset' => true,
74+
'no_trailing_comma_in_singleline' => false, // it's a good marker that there are more elements in an array
75+
'no_unneeded_braces' => true,
76+
'no_unneeded_control_parentheses' => true,
77+
'no_unneeded_final_method' => true,
78+
'no_unreachable_default_argument_value' => true,
79+
'no_unused_imports' => true,
80+
'no_useless_concat_operator' => true,
81+
'no_useless_return' => true,
82+
'no_whitespace_before_comma_in_array' => true,
83+
'normalize_index_brace' => true,
84+
'nullable_type_declaration' => ['syntax' => 'question_mark'],
85+
'object_operator_without_whitespace' => true,
86+
/*
87+
* @see https://github.com/slevomat/coding-standard/issues/1620#issuecomment-1758006718
88+
* 'ordered_class_elements' => [
89+
'order' => [
90+
'use_trait',
91+
'constant',
92+
'case', // for enums only
93+
'property',
94+
'method',
95+
]
96+
],*/
97+
'php_unit_construct' => true,
98+
'php_unit_dedicate_assert' => ['target' => 'newest'],
99+
'php_unit_expectation' => true,
100+
'php_unit_fqcn_annotation' => true,
101+
'php_unit_method_casing' => ['case' => 'snake_case'],
102+
'php_unit_no_expectation_annotation' => true,
103+
'php_unit_set_up_tear_down_visibility' => true,
104+
'php_unit_strict' => true,
105+
'php_unit_test_annotation' => ['style' => 'annotation'],
106+
'php_unit_test_class_requires_covers' => true,
107+
'phpdoc_align' => ['align' => 'left'],
108+
'phpdoc_indent' => true,
109+
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
110+
'phpdoc_param_order' => true,
111+
'phpdoc_scalar' => true,
112+
'phpdoc_single_line_var_spacing' => true,
113+
'phpdoc_tag_casing' => true,
114+
'phpdoc_types' => true,
115+
'protected_to_private' => true,
116+
'psr_autoloading' => true,
117+
'self_accessor' => true,
118+
'self_static_accessor' => true,
119+
'single_line_comment_spacing' => true,
120+
'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']],
121+
'space_after_semicolon' => true,
122+
'standardize_not_equals' => true,
123+
'strict_param' => true,
124+
'ternary_to_null_coalescing' => true,
125+
'trim_array_spaces' => true,
126+
'trailing_comma_in_multiline' => true,
127+
'type_declaration_spaces' => true,
128+
'types_spaces' => ['space' => 'single'],
129+
'whitespace_after_comma_in_array' => true,
130+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
131+
])
132+
->setFinder($finder);

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
The BSD 2-Clause License
2-
Copyright (c) 2021, Interaction Design Foundation
2+
Copyright (c) 2013-2020, Daniel Stainback
3+
Copyright (c) 2021-2024, Interaction Design Foundation
34
All rights reserved.
45

56
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ Determine the geographical location and currency of website visitors based on th
1111

1212
## About this fork
1313

14-
We have forked [Torann/laravel-geoip](https://github.com/Torann/laravel-geoip) as it’s almost not maintained anymore.
15-
This fork works with modern PHP versions only (8.0+).
16-
Also, as for any InteractionDesignFoundation project, we are going to improving code quality by using types, static analysers, tests and linters.
17-
But don’t worry, we are using SemVer 2.0.
14+
We have forked [`torann/geoip`](https://github.com/Torann/laravel-geoip) as it’s almost not actively maintained anymore.
15+
This fork works with modern PHP versions only (8.0+), maintained and includes additional features:
16+
- Support modern Laravel and PHP versions
17+
- Better types (native and PHPDoc)
18+
- Safer file and network functionality
19+
- Ability to prefix cache keys (`cache_prefix` config option)
20+
- Updated currencies
21+
- More predictable exceptions
22+
23+
But don’t worry, we are following SemVer 2.0. The [package migration is straightforward](./docs/migration.md).
1824

1925

2026
## Installation
@@ -42,9 +48,9 @@ To find out more simple open the `config/geoip.php` file.
4248

4349
### Service Configuration
4450

45-
To simplify and keep things clean, all third party composer packages, that are needed for a service, are installed separately.
51+
To simplify and keep things clean, all third party composer packages, which are needed for a service, are installed separately.
4652

47-
For further configuration options checkout the services page.
53+
For further configuration options, checkout the [services page](./docs/services.md).
4854

4955

5056
### Caching Configuration
@@ -53,9 +59,9 @@ GeoIP uses Laravel’s default caching to store queried IP locations.
5359
This is done to reduce the number of calls made to the selected service, as some of them are rate limited.
5460

5561
Options:
56-
- `all` all location are cached
62+
- `all` all locations are cached
5763
- `some` cache only the requesting user
58-
- `none` caching is completely disable
64+
- `none` caching is completely disabled
5965

6066

6167
## Usage
@@ -69,36 +75,37 @@ geoip()->getLocation('27.974.399.65'); // Get the location from the provided IP.
6975
geoip()->getClientIP(); // Will return the user IP address.
7076
```
7177

72-
Example of Location object:
78+
Example of a `Location` object:
7379
```php
74-
\InteractionDesignFoundation\GeoIP\Location {
75-
[
76-
'ip' => '1.1.1.1',
77-
'iso_code' => 'US',
78-
'country' => 'United States',
79-
'city' => 'New Haven',
80-
'state' => 'CT',
81-
'state_name' => 'Connecticut',
82-
'postal_code' => '06510',
83-
'lat' => 41.28,
84-
'lon' => -72.88,
85-
'timezone' => 'America/New_York',
86-
'continent' => 'NA',
87-
'currency' => 'USD',
88-
'default' => false,
89-
]
90-
}
80+
\InteractionDesignFoundation\GeoIP\Location {[
81+
'ip' => '1.1.1.1',
82+
'iso_code' => 'US',
83+
'country' => 'United States',
84+
'city' => 'New Haven',
85+
'state' => 'CT',
86+
'state_name' => 'Connecticut',
87+
'postal_code' => '06510',
88+
'lat' => 41.28,
89+
'lon' => -72.88,
90+
'timezone' => 'America/New_York',
91+
'continent' => 'NA',
92+
'currency' => 'USD',
93+
'default' => false,
94+
]}
9195
```
9296

93-
`Location` class implements `\ArrayAccess` interface, means you can access properties of the `Location` object using array access syntax:
97+
`Location` class implements `\ArrayAccess` interface, means you can access properties of the `Location` object using both object and array access:
9498
```php
9599
$location = geoip()->getLocation();
100+
101+
$city = $location->city;
102+
// The same as:
96103
$city = $location['city'];
97104
```
98105

99106
### Artisan
100107

101-
Some services require downloading and use local database to detect Location by IP address.
108+
Some services require downloading and use a local database to detect Location by IP address.
102109
There is a console command to download/update database:
103110
```sh
104111
php artisan geoip:update
@@ -121,7 +128,7 @@ Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
121128

122129
## Contributions
123130

124-
Many people have contributed to project since its inception.
131+
Many people have contributed to the project since its inception.
125132

126133
Thanks to:
127134

0 commit comments

Comments
 (0)