Skip to content

Commit

Permalink
enhance code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dipeshsukhia committed May 7, 2021
1 parent 113c331 commit ba8bd65
Show file tree
Hide file tree
Showing 10 changed files with 4,441 additions and 4,418 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# laravel country-state-city-data
# Laravel country-state-city-data

[![Latest Version on Packagist](https://img.shields.io/packagist/v/dipeshsukhia/laravel-country-state-city-data.svg?style=flat-square)](https://packagist.org/packages/dipeshsukhia/laravel-country-state-city-data)
[![Build Status](https://img.shields.io/travis/dipeshsukhia/laravel-country-state-city-data/master.svg?style=flat-square)](https://travis-ci.org/dipeshsukhia/laravel-country-state-city-data)
[![Quality Score](https://img.shields.io/scrutinizer/g/dipeshsukhia/laravel-country-state-city-data.svg?style=flat-square)](https://scrutinizer-ci.com/g/dipeshsukhia/laravel-country-state-city-data)
[![Total Downloads](https://img.shields.io/packagist/dt/dipeshsukhia/laravel-country-state-city-data.svg?style=flat-square)](https://packagist.org/packages/dipeshsukhia/laravel-country-state-city-data)

World`s Country State City Provider for Laravel 5.x, 6.x, 7.x, 8.x
World`s Country State City Provider for Laravel

## Installation

Expand All @@ -24,10 +24,11 @@ run below commands
3) php artisan migrate
```

### Testing
### Requirements

``` bash
composer test
Laravel 5.x,6.x, 7.x or 8.x
PHP >= 7.0 or 8.0
```

### Changelog
Expand Down
39 changes: 15 additions & 24 deletions src/LaravelCountryStateCityDataServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,52 @@

class LaravelCountryStateCityDataServiceProvider extends ServiceProvider
{
const STUB_DIR = __DIR__.'/resources/stubs/';
const STUB_DIR = __DIR__ . '/resources/stubs/';

/**
* Bootstrap the application services.
*/
public function boot()
{
/*
* Optional methods to load your package assets
*/

if ($this->app->runningInConsole()) {
/* model */
if(is_dir(base_path('app/Models'))){
if (is_dir(base_path('app/Models'))) {
$modelDir = base_path('app/Models');
$modelNameSpace = "\\Models";
}else{
} else {
$modelDir = base_path('app');
$modelNameSpace = "";
}

foreach (['Country','State','City'] as $modelName){
$ModelTemplate = self::getStubContents("Models/{$modelName}.stub");
foreach (['Country', 'State', 'City'] as $modelName) {
$ModelTemplate = self::getStubContents("Models/".$modelName.".stub");
$ModelTemplate = str_replace('{{modelNameSpace}}', $modelNameSpace, $ModelTemplate);
file_put_contents($modelDir."/{$modelName}.php", $ModelTemplate);
file_put_contents($modelDir . "/".$modelName.".php", $ModelTemplate);
}

/* model */

/* seeders */
if(is_dir(database_path('seeds'))){
if (is_dir(database_path('seeds'))) {
$seedDir = database_path('seeds');
$seederNameSpace = "";
}else{
} else {
$seedDir = database_path('seeders');
$seederNameSpace = "namespace Database\\Seeders;\n";
}
$seederTemplate = self::getStubContents('CountryStateCityTableSeeder.stub');
$seederTemplate = str_replace('{{seederNameSpace}}', $seederNameSpace, $seederTemplate);
$seederTemplate = str_replace('{{modelNameSpace}}', $modelNameSpace, $seederTemplate);
file_put_contents($seedDir.'/CountryStateCityTableSeeder.php', $seederTemplate);
file_put_contents($seedDir . '/CountryStateCityTableSeeder.php', $seederTemplate);
/* seeders */

$this->publishes([
__DIR__.'/resources/migrations' => database_path('migrations'),
__DIR__.'/resources/DataProviders' => app_path('DataProviders'),
__DIR__ . '/resources/migrations/2014_02_04_000000_create_country_state_city_table.stub' => database_path('migrations/2014_02_04_000000_create_country_state_city_table.php'),
__DIR__ . '/resources/DataProviders/CountryDataProvider.stub' => app_path('DataProviders/CountryDataProvider.php'),
__DIR__ . '/resources/DataProviders/StateDataProvider.stub' => app_path('DataProviders/StateDataProvider.php'),
__DIR__ . '/resources/DataProviders/CityDataProvider.stub' => app_path('DataProviders/CityDataProvider.php'),
], 'LaravelCountryStateCityData');

// Registering package commands.
// $this->commands([]);
}
}

Expand All @@ -63,17 +60,11 @@ public function boot()
*/
public function register()
{
// Automatically apply the package configuration
/*$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-country-state-city-data');*/

// Register the main class to use with the facade
/*$this->app->singleton('laravel-country-state-city-data', function () {
return new LaravelCountryStateCityData;
});*/
}

private function getStubContents($stubName)
{
return file_get_contents(self::STUB_DIR.$stubName);
return file_get_contents(self::STUB_DIR . $stubName);
}
}
Loading

0 comments on commit ba8bd65

Please sign in to comment.