Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor #32

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ on:
jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.2]
laravel: [10.*]
os: [ubuntu-latest]
php: [8.3]
laravel: [11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
carbon: ^2.63

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -40,11 +42,11 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/pest
run: vendor/bin/pest --ci
38 changes: 28 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
# Composer Related
composer.lock
coverage
docs
/vendor

# Frontend Assets
/node_modules

# Logs
npm-debug.log
yarn-error.log

# Caches
.phpunit.cache
.phpunit.result.cache
/build

# IDE Helper
_ide_helper.php
_ide_helper_models.php
.phpstorm.meta.php

# Editors
/.idea
/.fleet
/.vscode

# Misc
phpunit.xml
phpstan.neon
testbench.yaml
vendor
node_modules
.php-cs-fixer.cache
/docs
/coverage
40 changes: 0 additions & 40 deletions .php_cs.dist.php

This file was deleted.

76 changes: 29 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,28 @@ Profile is a package to store basic information - addresses, phone numbers, emai

## Installation

1. In order to install Profile in your Laravel project:
Install Profile package by running in your terminal:

```
$ composer require cleaniquecoders/profile
```

2. Then in your `config/app.php` add the following to the `providers` key:

```php
\CleaniqueCoders\Profile\ProfileServiceProvider::class,
```

Publish factory files:

```
$ php artisan vendor:publish --tag=profile-factories
```bash
composer require cleaniquecoders/profile
```

Publish migrations files:

```
$ php artisan vendor:publish --tag=profile-migrations
```

Publish seed files:

```
$ php artisan vendor:publish --tag=profile-seeds
```bash
php artisan vendor:publish --tag=profile-migrations
```

Then run:

```
$ php artisan migrate
```bash
php artisan migrate
```

Then seed the Country and Phone Types data with:
Then run default seeders:

```
$ php artisan profile:seed
```bash
php artisan profile:seed
```

#### Configuration
Expand All @@ -56,7 +38,7 @@ You may want to define your own seeders for `profile:seed` in `config/profile.ph

### Available Polymorph Traits

User Cases:
User Cases:

1. A company has addresses, phone numbers, emails and websites.
2. An employee has addresses, phone numbers, emails and websites.
Expand All @@ -67,20 +49,20 @@ This lead us to use Polymorph to tackle the issue of similarity in data stored.

Available traits for polymorph:

1. `CleaniqueCoders\Profile\Traits\Morphs\Addressable`
2. `CleaniqueCoders\Profile\Traits\Morphs\Emailable`
3. `CleaniqueCoders\Profile\Traits\Morphs\Phoneable`
4. `CleaniqueCoders\Profile\Traits\Morphs\Websiteable`
5. `CleaniqueCoders\Profile\Traits\Morphs\Bankable`
1. `CleaniqueCoders\Profile\Concerns\Addressable`
2. `CleaniqueCoders\Profile\Concerns\Emailable`
3. `CleaniqueCoders\Profile\Concerns\Phoneable`
4. `CleaniqueCoders\Profile\Concerns\Websiteable`
5. `CleaniqueCoders\Profile\Concerns\Bankable`

For most common setup for entity is to use `HasProfile` trait.

`HasProfile` trait consist of:

1. `CleaniqueCoders\Profile\Traits\Morphs\Addressable`
2. `CleaniqueCoders\Profile\Traits\Morphs\Emailable`
3. `CleaniqueCoders\Profile\Traits\Morphs\Phoneable`
4. `CleaniqueCoders\Profile\Traits\Morphs\Websiteable`
1. `CleaniqueCoders\Profile\Concerns\Addressable`
2. `CleaniqueCoders\Profile\Concerns\Emailable`
3. `CleaniqueCoders\Profile\Concerns\Phoneable`
4. `CleaniqueCoders\Profile\Concerns\Websiteable`

```php

Expand All @@ -91,7 +73,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use HasProfile;
use HasProfile;
}
```

Expand All @@ -101,16 +83,16 @@ class User extends Authenticatable

```php
$user->addresses()->create([
'primary' => '9 miles, Sungei Way',
'secondary' => 'P.O.Box 6503, Seri Setia',
'city' => 'Petaling Jaya',
'postcode' => '46150',
'state' => 'Selangor',
'country_id' => config('profile.providers.country.model')::name('Malaysia')->first()->id
'primary' => '9 miles, Sungei Way',
'secondary' => 'P.O.Box 6503, Seri Setia',
'city' => 'Petaling Jaya',
'postcode' => '46150',
'state' => 'Selangor',
'country_id' => config('profile.providers.country.model')::name('Malaysia')->first()->id
]);
```

```php
```php
$user->phones()->create([
'phone_number' => '+6089259167',
'is_default' => true,
Expand Down Expand Up @@ -162,4 +144,4 @@ $user->banks;

## License

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
125 changes: 72 additions & 53 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,74 @@
{
"name": "cleaniquecoders/profile",
"description": "Common Profile Information",
"license": "MIT",
"authors": [
{
"name": "Nasrul Hazim",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"CleaniqueCoders\\Profile\\": "src/",
"CleaniqueCoders\\Profile\\Database\\": "database/"
},
"files": [
"support/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"CleaniqueCoders\\Profile\\Tests\\": "tests/"
}
},
"require": {
"php": "^8.1 | ^8.2 | ^8.3",
"illuminate/support": "^9.0 | ^10.0 | ^11.0",
"illuminate/auth": "^9.0 | ^10.0 | ^11.0",
"cleaniquecoders/blueprint-macro": "^5.0"
},
"require-dev": {
"orchestra/testbench": "7.*|8.*",
"pestphp/pest": "^2.0",
"phpstan/phpstan-phpunit": "^1.2",
"laravel/pint": "^1.6"
},
"extra": {
"laravel": {
"providers": [
"CleaniqueCoders\\Profile\\ProfileServiceProvider"
]
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"scripts": {
"test": "vendor/bin/pest",
"format": "vendor/bin/pint"
},
"minimum-stability": "dev",
"prefer-stable": true
"name": "cleaniquecoders/profile",
"description": "Common Profile Information",
"license": "MIT",
"authors": [
{
"name": "Nasrul Hazim",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"CleaniqueCoders\\Profile\\": "src/",
"CleaniqueCoders\\Profile\\Database\\": "database/"
}
},
"autoload-dev": {
"psr-4": {
"CleaniqueCoders\\Profile\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"require": {
"php": "^8.3",
"illuminate/support": "^11.0",
"illuminate/auth": "^11.0",
"cleaniquecoders/blueprint-macro": "^5.0",
"spatie/laravel-package-tools": "^1.16",
"cleaniquecoders/traitify": "^1.0"
},
"require-dev": {
"orchestra/testbench": "^9.5",
"pestphp/pest": "^3.0",
"phpstan/phpstan-phpunit": "^1.2",
"laravel/pint": "^1.6",
"pestphp/pest-plugin-laravel": "^3.0"
},
"extra": {
"laravel": {
"providers": [
"CleaniqueCoders\\Profile\\ProfileServiceProvider"
]
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"scripts": {
"test": "vendor/bin/pest",
"format": "vendor/bin/pint",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/pint --ansi",
"@php vendor/bin/phpstan analyse --verbose --ansi"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
Loading