Skip to content

Commit

Permalink
Update CI, WIP doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitriBouteille committed Feb 11, 2024
1 parent 145d3fc commit 55b71e9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 27 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: PHPCsFixer
run: vendor/bin/php-cs-fixer fix --verbose --diff --dry-run
run: composer csFixer

- name: PHPStan Analyse
run: php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon
run: composer phpstan

- name: Rector
run: composer rector
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Running unit test
run: vendor/bin/phpunit
run: composer phpunit
17 changes: 0 additions & 17 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This documentation only covers the specific points of this library, if you want
- [Use WordPress core models](doc/wordpress-core-models.md)
- [Filter data](/doc/filter-data.md)
- [With findOneBy*](/doc/filter-data.md#with-findoneby)
- [With predefined taps](/doc/filter-data.md#with-taps)
- [With taps](/doc/filter-data.md#with-taps)
- [With query builder](/doc/filter-data.md#with-query-builder)
- [Create custom model](doc/create-model.md)
- [Generic Model](doc/create-model.md#generic-model)
Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@
"extension.neon"
]
}
},
"scripts": {
"rector": "vendor/bin/rector process src --dry-run",
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon",
"phpunit": "vendor/bin/phpunit",
"csFixer": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"fix:csFixer": "vendor/bin/php-cs-fixer fix"
}
}
8 changes: 5 additions & 3 deletions doc/create-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ class MyModel extends AbstractModel

Once a model is defined, you are ready to start retrieving and creating records in your table. Note that you will need to place `updated_at` and `created_at` columns on your table by default. If you do not wish to have these columns automatically maintained, set the `$timestamps` property on your model to false.

> 💡 If your model have metas, you can easily link metas to your model and use custom functions (e.g. `getMeta`, `getMetaValue`, ...). You can look `Dbout\WpOrm\Models\Post` to understand how it works.
> 📘 If you want to know more about creating a model you can look the [Eloquent documentation](https://laravel.com/docs/5.0/eloquent#basic-usage).
### Add meta relation

If your model have metas, you can easily link metas to your model and use custom functions (e.g. `getMeta`, `getMetaValue`, ...). You can look `Dbout\WpOrm\Models\Post` to understand how it works.

## Custom Post Type Model

All Custom Post Type (CPT) models extend `Dbout\WpOrm\Models\CustomPost`.
Expand All @@ -58,4 +60,4 @@ When retrieving a model `MyCustomType`, the `posts.post_type = my_customm_type`

When creating the model, the `post_type` property is automatically filled in with the value `my_customm_type`.

**Note:** You cannot use `setPostType` function on CPT models.
**Note:** You cannot use `setPostType` function on CPT models.
32 changes: 29 additions & 3 deletions doc/filter-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

You can filter data in several ways:

- With predefined `findOneBy` functions in place on some models
- With predefined taps
- With `findOneBy` functions in place on some models
- With taps
- With Eloquent query builder. If your model has metas, you can use custom filter methods.

## With findOneBy

By default, Eloquent does not offer a magic feature [findOneBy*](https://github.com/laravel/ideas/issues/107), however you can use this feature on some models :

**User :**

- `User::findOneByEmail()`
- `User::findOneByLogin()`

**Option :**

- `Option::findOneByName()`

**Post :**

- `Post::findOneByName()`
- `Post::findOneByGuid()`

## With taps

You can easily filter data via the `tap` function :
Expand Down Expand Up @@ -57,4 +73,14 @@ $posts = Post::query()

> 📘 More information here: [Eloquent query builder](https://laravel.com/docs/10.x/queries).
### Model with meta relation
### Model with meta relation

For models that may have metas (e.g. `Post`, `User`, ...), you can filter with `addMetaToFilter`, here is an example that speaks for itself:)

```php
$products = Post::query()
->addMetaToFilter('product_type', 'simple')
->get();
```

> 📘 You can find all functions usable on models with metas here:

0 comments on commit 55b71e9

Please sign in to comment.