Skip to content

Commit

Permalink
v1 pint format and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asanikovich committed Jun 1, 2023
1 parent dea6aa4 commit 8c66fa5
Show file tree
Hide file tree
Showing 44 changed files with 246 additions and 94 deletions.
66 changes: 66 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Bug Report
description: Report an Issue or Bug with the Package
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
- type: textarea
id: what-happened
attributes:
label: What happened?
description: What did you expect to happen?
placeholder: I cannot currently do X thing because when I do, it breaks X thing.
validations:
required: true
- type: textarea
id: how-to-reproduce
attributes:
label: How to reproduce the bug
description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
placeholder: When I do X I see Y.
validations:
required: true
- type: input
id: package-version
attributes:
label: Package Version
description: What version of our Package are you running? Please be as specific as possible
placeholder: 2.0.0
validations:
required: true
- type: input
id: php-version
attributes:
label: PHP Version
description: What version of PHP are you running? Please be as specific as possible
placeholder: 8.2.0
validations:
required: true
- type: input
id: laravel-version
attributes:
label: Laravel Version
description: What version of Laravel are you running? Please be as specific as possible
placeholder: 9.0.0
validations:
required: true
- type: dropdown
id: operating-systems
attributes:
label: Which operating systems does with happen with?
description: You may select more than one.
multiple: true
options:
- macOS
- Windows
- Linux
- type: textarea
id: notes
attributes:
label: Notes
description: Use this field to provide any other notes that you feel might be relevant to the issue.
validations:
required: false
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/grimzy/laravel-mysql-spatial/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/grimzy/laravel-mysql-spatial/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/grimzy/laravel-mysql-spatial/security/policy
about: Learn how to notify us for sensitive bugs
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
2 changes: 1 addition & 1 deletion .github/workflows/pest-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
db:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: laravel
ports:
- 3306
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/pest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ on: [ push, pull_request ]

jobs:
test:
name: Pest - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - DB ${{ matrix.db }} ${{ matrix.dependency-version }}
name: Pest PHP${{ matrix.php }} Laravel ${{ matrix.laravel }} ${{ matrix.db }} ${{ matrix.dependency-version }}

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [ 8.2, 8.1 ]
laravel: [ 9.* ]
laravel: [ 9.*, 8.* ]
db: [ 'mysql:8.0', 'mysql:5.7', 'mariadb:10.9' ]
dependency-version: [ prefer-lowest, prefer-stable ]
include:
- laravel: 9.*
testbench: ^7.0
- laravel: 8.*
testbench: ^6.23

services:
db:
image: ${{ matrix.db }}
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: laravel
ports:
- 3306
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.2, 8.1, 8.0 ]
php: [ 8.2, 8.1 ]

steps:
- name: Checkout code
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Fix PHP code style issues

on:
push:
paths:
- "**.php"
pull_request:
branches: [master]

jobs:
php-code-styling:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.1.0

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
64 changes: 49 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

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

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

This package supports MySQL v8, MySQL v5.7, and MariaDB v10.
This package supports MySQL v8 or v5.7, and MariaDB v10.

## Getting Started

Expand All @@ -21,12 +21,32 @@ You can install the package via composer:
composer require asanikovich/laravel-spatial
```

### Configuration

Default Configuration file includes geometry types mapping:
```php
<?php

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use ASanikovich\LaravelSpatial\Geometry;

return [
GeometryType::POINT->value => Geometry\Point::class,
GeometryType::POLYGON->value => Geometry\Polygon::class,
/// ...
];
```

You can publish the config file with:

```bash
php artisan vendor:publish --tag="laravel-spatial-config"
```

If you want you can override custom geometry types mapping:
* globally by config file
* by custom `$casts` in your model (top priority)

### Setting Up Your First Model

1. First, generate a new model along with a migration file by running:
Expand Down Expand Up @@ -67,7 +87,7 @@ php artisan vendor:publish --tag="laravel-spatial-config"
php artisan migrate
```

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

```php
namespace App\Models;
Expand All @@ -81,7 +101,6 @@ php artisan vendor:publish --tag="laravel-spatial-config"
/**
* @property Point $location
* @property Polygon $area
* @method static SpatialBuilder<Place> query()
*/
class Place extends Model
{
Expand Down Expand Up @@ -155,10 +174,6 @@ echo $vacationCity->area->toJson(); // {"type":"Polygon","coordinates":[[[41.907

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

## Tips for Improving IDE Support

In order to get better IDE support, you can add a `query` method phpDoc annotation to your model:

```php
/**
* @method static SpatialBuilder query()
Expand All @@ -169,11 +184,10 @@ class Place extends Model
}
```

Create queries only with the `query()` static method:
Create queries only with scopes methods:

```php
Place::query()->whereDistance(...); // This is IDE-friendly
Place::whereDistance(...); // This is not
Place::whereDistance(...); // This is IDE-friendly
```

## Extension
Expand Down Expand Up @@ -207,10 +221,26 @@ echo $londonEyePoint->getName(); // Point

Here are some useful commands for development:

* Run tests: `composer pest`
* Run tests with coverage: `composer pest-coverage`
* Perform type checking: `composer phpstan`
* Format your code: `composer format`
Before running tests run db by docker-compose:
```bash
docker-compose up -d
```
Run tests:
```bash
composer run test
```
Run tests with coverage:
```bash
composer run test-coverage
```
Perform type checking:
```bash
composer run phpstan
```
Format your code:
```bash
composer run format
```

## Updates and Changes

Expand All @@ -219,3 +249,7 @@ For details on updates and changes, please refer to our [CHANGELOG](CHANGELOG.md
## License

Laravel Eloquent Spatial is released under The MIT License (MIT). For more information, please see our [License File](LICENSE.md).

## Credits

Originally inspired from [MatanYadaev's laravel-eloquent-spatial package](https://github.com/MatanYadaev/laravel-eloquent-spatial).
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-json": "*",
"ext-pdo": "*",
"laravel/framework": "^9.0",
"laravel/framework": "^8.0",
"phayes/geophp": "^1.2"
},
"require-dev": {
"doctrine/dbal": "^2.0|^3.0",
"laravel/pint": "^1.10",
"doctrine/dbal": "^3.0",
"laravel/pint": "^1.5",
"nunomaduro/larastan": "^1.0|^2.4",
"orchestra/testbench": "^7.0",
"orchestra/testbench": "^6.23|^7.0",
"pestphp/pest": "^1.0",
"pestphp/pest-plugin-laravel": "^1.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
- "3306:3306"
environment:
MYSQL_DATABASE: 'laravel'
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value="root"/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/Doctrine/GeometryCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ASanikovich\LaravelSpatial\Doctrine;

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use ASanikovich\LaravelSpatial\Enums\GeometryType;

final class GeometryCollectionType extends Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/LineStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ASanikovich\LaravelSpatial\Doctrine;

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use ASanikovich\LaravelSpatial\Enums\GeometryType;

final class LineStringType extends Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/MultiLineStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ASanikovich\LaravelSpatial\Doctrine;

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use ASanikovich\LaravelSpatial\Enums\GeometryType;

final class MultiLineStringType extends Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/MultiPointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ASanikovich\LaravelSpatial\Doctrine;

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use ASanikovich\LaravelSpatial\Enums\GeometryType;

final class MultiPointType extends Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/MultiPolygonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ASanikovich\LaravelSpatial\Doctrine;

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use ASanikovich\LaravelSpatial\Enums\GeometryType;

final class MultiPolygonType extends Type
{
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ASanikovich\LaravelSpatial\Doctrine;

use ASanikovich\LaravelSpatial\Enums\GeometryType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use ASanikovich\LaravelSpatial\Enums\GeometryType;

final class PointType extends Type
{
Expand Down

0 comments on commit 8c66fa5

Please sign in to comment.