Skip to content

Commit 702b654

Browse files
committed
v1 pint format and fixes
1 parent dea6aa4 commit 702b654

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+277
-116
lines changed

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Bug Report
2+
description: Report an Issue or Bug with the Package
3+
title: "[Bug]: "
4+
labels: [ "bug" ]
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: |
9+
We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
10+
- type: textarea
11+
id: what-happened
12+
attributes:
13+
label: What happened?
14+
description: What did you expect to happen?
15+
placeholder: I cannot currently do X thing because when I do, it breaks X thing.
16+
validations:
17+
required: true
18+
- type: textarea
19+
id: how-to-reproduce
20+
attributes:
21+
label: How to reproduce the bug
22+
description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
23+
placeholder: When I do X I see Y.
24+
validations:
25+
required: true
26+
- type: input
27+
id: package-version
28+
attributes:
29+
label: Package Version
30+
description: What version of our Package are you running? Please be as specific as possible
31+
placeholder: 2.0.0
32+
validations:
33+
required: true
34+
- type: input
35+
id: php-version
36+
attributes:
37+
label: PHP Version
38+
description: What version of PHP are you running? Please be as specific as possible
39+
placeholder: 8.2.0
40+
validations:
41+
required: true
42+
- type: input
43+
id: laravel-version
44+
attributes:
45+
label: Laravel Version
46+
description: What version of Laravel are you running? Please be as specific as possible
47+
placeholder: 9.0.0
48+
validations:
49+
required: true
50+
- type: dropdown
51+
id: db
52+
attributes:
53+
label: Which database does with happen with?
54+
options:
55+
- MySql
56+
- Mariadb
57+
- type: input
58+
id: db-version
59+
attributes:
60+
label: Database Version
61+
description: What version of Database are you running? Please be as specific as possible
62+
placeholder: '8.0'
63+
validations:
64+
required: true
65+
- type: dropdown
66+
id: operating-systems
67+
attributes:
68+
label: Which operating systems does with happen with?
69+
description: You may select more than one.
70+
multiple: true
71+
options:
72+
- macOS
73+
- Windows
74+
- Linux
75+
- type: textarea
76+
id: notes
77+
attributes:
78+
label: Notes
79+
description: Use this field to provide any other notes that you feel might be relevant to the issue.
80+
validations:
81+
required: false

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Ask a question
4+
url: https://github.com/asanikovich/laravel-spatial/discussions/new?category=q-a
5+
about: Ask the community for help
6+
- name: Request a feature
7+
url: https://github.com/asanikovich/laravel-spatial/discussions/new?category=ideas
8+
about: Share ideas for new features
9+
- name: Report a security issue
10+
url: https://github.com/asanikovich/laravel-spatial/security/policy
11+
about: Learn how to notify us for sensitive bugs

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Please see the documentation for all configuration options:
2+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3+
4+
version: 2
5+
updates:
6+
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"
11+
labels:
12+
- "dependencies"

.github/workflows/pest-coverage.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
db:
1313
image: mysql:8.0
1414
env:
15-
MYSQL_ROOT_PASSWORD: root
15+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
1616
MYSQL_DATABASE: laravel
1717
ports:
1818
- 3306
@@ -34,4 +34,9 @@ jobs:
3434
- name: Execute tests
3535
env:
3636
DB_PORT: ${{ job.services.db.ports['3306'] }}
37-
run: XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100
37+
run: XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --min=100 --coverage-clover coverage.xml
38+
39+
- name: Upload coverage reports to Codecov
40+
uses: codecov/codecov-action@v3
41+
env:
42+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pest.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ on: [ push, pull_request ]
44

55
jobs:
66
test:
7-
name: Pest - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - DB ${{ matrix.db }} ${{ matrix.dependency-version }}
7+
name: Pest PHP${{ matrix.php }} Laravel ${{ matrix.laravel }} ${{ matrix.db }} ${{ matrix.dependency-version }}
88

99
runs-on: ubuntu-latest
1010

1111
strategy:
1212
fail-fast: false
1313
matrix:
1414
php: [ 8.2, 8.1 ]
15-
laravel: [ 9.* ]
15+
laravel: [ 9.*, 8.* ]
1616
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.9' ]
17-
dependency-version: [ prefer-lowest, prefer-stable ]
17+
dependency-version: [ prefer-stable ]
1818
include:
1919
- laravel: 9.*
2020
testbench: ^7.0
21+
- laravel: 8.*
22+
testbench: ^6.23
2123

2224
services:
2325
db:
2426
image: ${{ matrix.db }}
2527
env:
26-
MYSQL_ROOT_PASSWORD: root
28+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
2729
MYSQL_DATABASE: laravel
2830
ports:
2931
- 3306

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ 8.2, 8.1, 8.0 ]
14+
php: [ 8.2, 8.1 ]
1515

1616
steps:
1717
- name: Checkout code

.github/workflows/pint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Fix PHP code style issues
2+
3+
on:
4+
push:
5+
paths:
6+
- "**.php"
7+
pull_request:
8+
branches: [master]
9+
10+
jobs:
11+
php-code-styling:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
with:
18+
ref: ${{ github.head_ref }}
19+
20+
- name: Fix PHP code style issues
21+
uses: aglipanci/[email protected]
22+
23+
- name: Commit changes
24+
uses: stefanzweifel/git-auto-commit-action@v4
25+
with:
26+
commit_message: Fix styling

README.md

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
# Laravel Eloquent Spatial
1+
# Laravel Spatial
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/asanikovich/laravel-spatial.svg?style=flat-square)](https://packagist.org/packages/asanikovich/laravel-spatial)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/asanikovich/laravel-spatial/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/asanikovich/laravel-spatial/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
4+
[![GitHub Tests Status](https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/pest.yml?branch=master&label=tests&style=flat-square)](https://github.com/asanikovich/laravel-spatial/actions/workflows/pest.yml?query=branch%3Amaster)
5+
[![GitHub Tests Coverage Status](https://img.shields.io/codecov/c/github/asanikovich/laravel-spatial?token=E0703O0PPT&style=flat-square)](https://github.com/asanikovich/laravel-spatial/actions/workflows/pest-coverage.yml?query=branch%3Amaster)
6+
[![GitHub Code Style Status](https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/phpstan.yml?branch=master&label=code%20style&style=flat-square)](https://github.com/asanikovich/laravel-spatial/actions/workflows/phpstan.yml?query=branch%3Amaster)
7+
[![GitHub Lint Status](https://img.shields.io/github/actions/workflow/status/asanikovich/laravel-spatial/pint.yml?branch=master&label=lint&style=flat-square)](https://github.com/asanikovich/laravel-spatial/actions/workflows/pint.yml?query=branch%3Amaster)
68
[![Total Downloads](https://img.shields.io/packagist/dt/asanikovich/laravel-spatial.svg?style=flat-square)](https://packagist.org/packages/asanikovich/laravel-spatial)
9+
[![Licence](https://img.shields.io/packagist/l/asanikovich/laravel-spatial.svg?style=flat-square)](https://packagist.org/packages/asanikovich/laravel-spatial)
710

811
**This Laravel package allows you to easily work with spatial data types and functions.**
912

10-
The latest version, v3, supports Laravel 10 and PHP 8.1+. For Laravel 8 or 9, and PHP 8.0, use v2.
13+
v1 supports Laravel 8,9 and PHP 8.1+.
1114

12-
This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
15+
This package supports MySQL v8 or v5.7, and MariaDB v10.
1316

1417
## Getting Started
1518

@@ -21,12 +24,32 @@ You can install the package via composer:
2124
composer require asanikovich/laravel-spatial
2225
```
2326

27+
### Configuration
28+
29+
Default Configuration file includes geometry types mapping:
30+
```php
31+
<?php
32+
33+
use ASanikovich\LaravelSpatial\Enums\GeometryType;
34+
use ASanikovich\LaravelSpatial\Geometry;
35+
36+
return [
37+
GeometryType::POINT->value => Geometry\Point::class,
38+
GeometryType::POLYGON->value => Geometry\Polygon::class,
39+
/// ...
40+
];
41+
```
42+
2443
You can publish the config file with:
2544

2645
```bash
2746
php artisan vendor:publish --tag="laravel-spatial-config"
2847
```
2948

49+
If you want you can override custom geometry types mapping:
50+
* globally by config file
51+
* by custom `$casts` in your model (top priority)
52+
3053
### Setting Up Your First Model
3154

3255
1. First, generate a new model along with a migration file by running:
@@ -67,21 +90,19 @@ php artisan vendor:publish --tag="laravel-spatial-config"
6790
php artisan migrate
6891
```
6992

70-
4. In your new model, fill the `$fillable` and `$casts` arrays and use the `HasSpatial` trait:
93+
4. In your new model, fill `$casts` arrays and use the `HasSpatial` trait (fill the `$fillable` - optional):
7194

7295
```php
7396
namespace App\Models;
7497

7598
use Illuminate\Database\Eloquent\Model;
7699
use ASanikovich\LaravelSpatial\Eloquent\HasSpatial;
77-
use ASanikovich\LaravelSpatial\Eloquent\SpatialBuilder;
78100
use ASanikovich\LaravelSpatial\Geometry\Point;
79101
use ASanikovich\LaravelSpatial\Geometry\Polygon;
80102

81103
/**
82104
* @property Point $location
83105
* @property Polygon $area
84-
* @method static SpatialBuilder<Place> query()
85106
*/
86107
class Place extends Model
87108
{
@@ -155,25 +176,9 @@ echo $vacationCity->area->toJson(); // {"type":"Polygon","coordinates":[[[41.907
155176

156177
For more comprehensive documentation on the API, please refer to the [API](API.md) page.
157178

158-
## Tips for Improving IDE Support
159-
160-
In order to get better IDE support, you can add a `query` method phpDoc annotation to your model:
161-
162-
```php
163-
/**
164-
* @method static SpatialBuilder query()
165-
*/
166-
class Place extends Model
167-
{
168-
// ...
169-
}
170-
```
171-
172-
Create queries only with the `query()` static method:
173-
179+
Create queries only with scopes methods:
174180
```php
175-
Place::query()->whereDistance(...); // This is IDE-friendly
176-
Place::whereDistance(...); // This is not
181+
Place::whereDistance(...); // This is IDE-friendly
177182
```
178183

179184
## Extension
@@ -204,18 +209,37 @@ echo $londonEyePoint->getName(); // Point
204209
```
205210

206211
## Development
212+
Here are some useful commands for development
207213

208-
Here are some useful commands for development:
209-
210-
* Run tests: `composer pest`
211-
* Run tests with coverage: `composer pest-coverage`
212-
* Perform type checking: `composer phpstan`
213-
* Format your code: `composer format`
214+
Before running tests run db by docker-compose:
215+
```bash
216+
docker-compose up -d
217+
```
218+
Run tests:
219+
```bash
220+
composer run test
221+
```
222+
Run tests with coverage:
223+
```bash
224+
composer run test-coverage
225+
```
226+
Perform type checking:
227+
```bash
228+
composer run phpstan
229+
```
230+
Format your code:
231+
```bash
232+
composer run format
233+
```
214234

215235
## Updates and Changes
216236

217237
For details on updates and changes, please refer to our [CHANGELOG](CHANGELOG.md).
218238

219239
## License
220240

221-
Laravel Eloquent Spatial is released under The MIT License (MIT). For more information, please see our [License File](LICENSE.md).
241+
Laravel Spatial is released under The MIT License (MIT). For more information, please see our [License File](LICENSE.md).
242+
243+
## Credits
244+
245+
Originally inspired from [MatanYadaev's laravel-eloquent-spatial package](https://github.com/MatanYadaev/laravel-eloquent-spatial).

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^8.0",
13+
"php": "^8.1",
1414
"ext-json": "*",
1515
"ext-pdo": "*",
16-
"laravel/framework": "^9.0",
16+
"laravel/framework": "^8.0",
1717
"phayes/geophp": "^1.2"
1818
},
1919
"require-dev": {
20-
"doctrine/dbal": "^2.0|^3.0",
21-
"laravel/pint": "^1.10",
20+
"doctrine/dbal": "^3.0",
21+
"laravel/pint": "^1.5",
2222
"nunomaduro/larastan": "^1.0|^2.4",
23-
"orchestra/testbench": "^7.0",
23+
"orchestra/testbench": "^6.23|^7.0",
2424
"pestphp/pest": "^1.0",
2525
"pestphp/pest-plugin-laravel": "^1.4.0"
2626
},

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ services:
66
- "3306:3306"
77
environment:
88
MYSQL_DATABASE: 'laravel'
9-
MYSQL_ROOT_PASSWORD: 'root'
9+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'

0 commit comments

Comments
 (0)