Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
t1k3 committed Aug 24, 2018
0 parents commit 5fdaef8
Show file tree
Hide file tree
Showing 23 changed files with 1,068 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea

build
vendor
composer.lock
.phpunit.result.cache
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: php

php:
- 7.1.3

before_install:
- travis_retry composer self-update

install:
- travis_retry composer install --no-interaction --prefer-dist

script:
- vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
- vendor/bin/phpmd src text phpmd.xml --exclude src/database

after_success:
- bash <(curl -s https://codecov.io/bash)

matrix:
fast_finish: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 stylers-llc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Laravel Address

[![Latest Stable Version](https://poser.pugx.org/stylers/laravel-address/version)](https://packagist.org/packages/stylers/laravel-address)
[![Total Downloads](https://poser.pugx.org/stylers/laravel-address/downloads)](https://packagist.org/packages/stylers/laravel-address)
[![License](https://poser.pugx.org/stylers/laravel-address/license)](https://packagist.org/packages/stylers/laravel-address)
[![Build Status](https://travis-ci.org/stylers-llc/laravel-address.svg?branch=master)](https://travis-ci.org/stylers-llc/laravel-address)
[![codecov](https://codecov.io/gh/stylers-llc/laravel-address/branch/master/graph/badge.svg)](https://codecov.io/gh/stylers-llc/laravel-address)

## Requirements
- PHP >= 7.1.3
- Laravel ~5.x

## Installation
```bash
composer require stylers/laravel-address
```

You can publish the migration
```bash
php artisan vendor:publish --provider="Stylers\Address\Providers\AddressServiceProvider"
```

After the migration has been published, you can run the migrations
```bash
php artisan migrate
```

## Usage
* How to address
```php
use Stylers\Address\Contracts\Models\Traits\HasAddressesInterface;
use Stylers\Address\Models\Traits\HasAddresses;

class User extends Authenticatable implements HasAddressesInterface
{
use Notifiable;
use HasAddresses;
}
```

## Update or Create Address
```php
use Stylers\Address\Enums\AddressTypeEnum;

$user = User::first();
$attributes = [
"country" => "Hungary",
"zip_code" => "1055",
"city" => "Budapest",
"name_of_public_place" => "Kossuth Lajos",
"type_of_public_place" => "place",
"number_of_house" => "1-3",
]; // array
$type = AddressTypeEnum::PRIMARY; // ?string
$address = $user->updateOrCreateAddress($attributes, $type); // AddressInterface
```

## Delete Address
```php
use Stylers\Address\Enums\AddressTypeEnum;

$user = User::first();
$type = AddressTypeEnum::PRIMARY; // ?string
$isDeleted = $user->deleteAddress($type); // boolean
```

## Sync Address(es)
The `syncAddresses()` method delete all addressable address if $`type` is not exists in `$arrayOfAttributes[$type][]`.
The `syncAddresses()` method create all `$type` of `arrayOfAttributes[$type][]` if type is not exists in `addresses` table.
```php
use Stylers\Address\Enums\AddressTypeEnum;

$user = User::first();
$arrayOfAttributes = [
AddressTypeEnum::MAILING => [
"country" => "Hungary",
"zip_code" => "1055",
"city" => "Budapest",
"name_of_public_place" => "Kossuth Lajos",
"type_of_public_place" => "place",
"number_of_house" => "1-3",
]
];
$addresses = $user->syncAddresses($arrayOfAttributes); // Collection
```
61 changes: 61 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "stylers/laravel-address",
"description": "Laravel Address Manager",
"homepage": "https://github.com/stylers-llc/laravel-address",
"keywords": [
"stylers",
"laravel",
"address",
"addressable"
],
"type": "library",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Szilveszter Nagy",
"email": "[email protected]",
"homepage": "http://stylers.hu",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3",
"illuminate/database": "~5",
"illuminate/support": "~5"
},
"require-dev": {
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3.0|~3.6|~3.7",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "^7.3"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Stylers\\Address\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Stylers\\Address\\Tests\\": "tests",
"Stylers\\Address\\Tests\\Fixtures\\": "tests/fixtures"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Stylers\\Address\\Providers\\AddressServiceProvider"
]
}
}
}
39 changes: 39 additions & 0 deletions database/migrations/2018_07_09_104935_create_addresses_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAddressesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('addresses', function (Blueprint $table) {
$table->increments('id');
$table->morphs('addressable');
$table->string('country')->nullable();
$table->string('zip_code')->nullable();
$table->string('city')->nullable();
$table->string('name_of_public_place')->nullable(); // example: "Kossuth Lajos"
$table->string('type_of_public_place')->nullable(); // example: "street" <or> "place"
$table->string('number_of_house')->nullable(); // example: "1-3"
$table->string('type')->nullable(); // AddressTypeEnum
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('addresses');
}
}
45 changes: 45 additions & 0 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Package Ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Package Code Check</description>

<rule ref="rulesets/unusedcode.xml"/>

<rule ref="rulesets/codesize.xml">
<exclude name="CyclomaticComplexity"/>
<exclude name="TooManyPublicMethods"/>
</rule>
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" value="30"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyPublicMethods">
<properties>
<property name="maxmethods" value="20"/>
</properties>
</rule>

<rule ref="rulesets/controversial.xml"/>
<rule ref="rulesets/design.xml">
<exclude name="CouplingBetweenObjects"/>
</rule>
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
<properties>
<property name="minimum" value="25"/>
</properties>
</rule>

<rule ref="rulesets/naming.xml">
<exclude name="LongVariable"/>
<exclude name="BooleanGetMethodName"/>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="30"/>
</properties>
</rule>
</ruleset>
32 changes: 32 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix=".php">tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/phpunit/html"/>
<log type="coverage-clover" target="build/phpunit/clover.xml"/>
<log type="coverage-text" target="build/phpunit/coverage.txt"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
15 changes: 15 additions & 0 deletions src/Contracts/Enums/EnumInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Stylers\Address\Contracts\Enums;

/**
* Interface EnumInterface
* @package Stylers\Address\Contracts\Enums
*/
interface EnumInterface
{
/**
* @return array
*/
public static function getConstants(): array;
}
18 changes: 18 additions & 0 deletions src/Contracts/Models/AddressInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php


namespace Stylers\Address\Contracts\Models;

use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
* Interface AddressInterface
* @package Stylers\Address\Contracts\Models
*/
interface AddressInterface
{
/**
* @return MorphTo
*/
public function addressable(): MorphTo;
}
Loading

0 comments on commit 5fdaef8

Please sign in to comment.