Skip to content

Commit

Permalink
Update core
Browse files Browse the repository at this point in the history
- Restructuring source code.
- Remove :readme command.
- Update README
  • Loading branch information
JackieDo committed Mar 4, 2022
1 parent 7c64ab3 commit e3541f6
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 261 deletions.
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.1
- 7.2
- hhvm

before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction --dev
- composer self-update
- composer install --prefer-source --no-interaction --dev

script: phpunit
script: vendor/bin/phpunit --testdox
78 changes: 40 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ These are introductions from authors who created PHP-CS-Fixer and this package i
# Overview
Look at one of the following topics to learn more about Artisan PHP CS Fixer

* [Versions and compatibility](#versions-and-compatibility)
* [Installation](#installation)
* [Usage](#usage)
- [Get version](#get-version)
- [Fix code](#fix-code)
- [Describe rule or set](#describe-rule-or-set)
- [Show README content](#show-readme-content)
* [Configuration](#configuration)
* [Exclusion of the cache file](#exclusion-of-the-cache-file)
* [License](#license)
* [PHP CS Fixer official documentation](#php-cs-fixer-official-documentation)
* [Thanks from author](#thanks-for-use)
- [Artisan PHP CS Fixer](#artisan-php-cs-fixer)
- [Features of this package](#features-of-this-package)
- [Overview](#overview)
- [Versions and compatibility](#versions-and-compatibility)
- [Installation](#installation)
- [Step 1 - Require package](#step-1---require-package)
- [Step 2 - Register service provider](#step-2---register-service-provider)
- [Usage](#usage)
- [Get version](#get-version)
- [Fix code](#fix-code)
- [Describe rule or rule set](#describe-rule-or-rule-set)
- [Configuration](#configuration)
- [Exclusion of the cache file](#exclusion-of-the-cache-file)
- [License](#license)
- [PHP CS Fixer official documentation](#php-cs-fixer-official-documentation)
- [Thanks for use](#thanks-for-use)

## Versions and compatibility
Artisan PHP CS Fixer don't support Laravel 4.x. Currently, this package have following branchs compatible with Laravel 5.x:
Expand All @@ -39,45 +43,41 @@ Artisan PHP CS Fixer don't support Laravel 4.x. Currently, this package have fol
| [1.x](https://github.com/JackieDo/Artisan-PHP-CS-Fixer/tree/1.x) | 5.0 - 5.2 |
| [2.x](https://github.com/JackieDo/Artisan-PHP-CS-Fixer/tree/2.x) | 5.3 and later |

> **Note:** This documentation is use for Laravel 5.3 and later.
> **Note:** This documentation is used for branch 2.x
## Installation
You can install this package through [Composer](https://getcomposer.org).

- First, edit your project's `composer.json` file to require `jackiedo/artisan-php-cs-fixer`. Add following line to the `require` section:
```
"jackiedo/artisan-php-cs-fixer": "2.*"
```

- Next step, we run Composer update commend from the Terminal on your project source directory:
#### Step 1 - Require package
At the root of your Laravel application directory, run the following command (in any terminal client):
```shell
$ composer update
$ composer require jackiedo/artisan-php-cs-fixer
```

> **Note:** Instead of performing the above two steps, you can perform faster with the command line `$ composer require jackiedo/artisan-php-cs-fixer:2.*` from Terminal
**Note:** Since Laravel 5.5, [service providers and aliases are automatically registered](https://laravel.com/docs/5.5/packages#package-discovery), so you can safely skip the following step:

- Once install/update operation completes, the final step is add the service provider. Open `config/app.php`, and add a new item to the `providers` section:
```
'Jackiedo\ArtisanPhpCsFixer\ArtisanPhpCsFixerServiceProvider',
```
#### Step 2 - Register service provider
Open `config/app.php`, and add a new line to the providers section:

> **Note:** From Laravel 5.1, you should write as `Jackiedo\ArtisanPhpCsFixer\ArtisanPhpCsFixerServiceProvider::class,`
```php
Jackiedo\ArtisanPhpCsFixer\ArtisanPhpCsFixerServiceProvider::class,
```

## Usage

#### Get version
Display PHP-CS-Fixer version installed.

Syntax:
```
```shell
$ php artisan php-cs-fixer:version
```

#### Fix code
Fix your code with PHP Coding Standards.

Syntax:
```
```shell
$ php artisan php-cs-fixer:fix [options] [path/to/dir/or/file]
```

Expand All @@ -93,23 +93,25 @@ $ php artisan php-cs-fixer:fix
$ php artisan php-cs-fixer:fix app
// Only fixes all files in the `app` directory with specific configuration file
$ php artisan php-cs-fixer:fix --config="path/to/config/file" app
$ php artisan php-cs-fixer:fix --config="path/to/fixer-config/file" app
```

#### Describe rule or set
Display description of rule or set.
#### Describe rule or rule set
Display description of rule or rule set.

Syntax:
```shell
$ php artisan php-cs-fixer:describe name/of/rule/or/rule-set
```
$ php artisan php-cs-fixer:describe name/of/rule/or/set
```

#### Show README content
Display README content of PHP-CS-Fixer.

Syntax:
Exampple 1:
```shell
$ php artisan php-cs-fixer:describe @Symfony
```
$ php artisan php-cs-fixer:readme

Exampple 2:
```shell
$ php artisan php-cs-fixer:describe array_syntax
```

## Configuration
Expand Down
39 changes: 23 additions & 16 deletions src/ArtisanPhpCsFixerServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?php namespace Jackiedo\ArtisanPhpCsFixer;
<?php

namespace Jackiedo\ArtisanPhpCsFixer;

use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use Jackiedo\ArtisanPhpCsFixer\Console\Commands\ArtisanPhpCsFixerDescribe;
use Jackiedo\ArtisanPhpCsFixer\Console\Commands\ArtisanPhpCsFixerFix;
use Jackiedo\ArtisanPhpCsFixer\Console\Commands\ArtisanPhpCsFixerVersion;
use Jackiedo\ArtisanPhpCsFixer\Console\Commands\ArtisanPhpCsFixerDescribe;
use Jackiedo\ArtisanPhpCsFixer\Console\Commands\ArtisanPhpCsFixerReadme;

/**
* The ArtisanPhpCsFixerServiceProvider class.
*
* @package Jackiedo\ArtisanPhpCsFixer
*
* @author Jackie Do <[email protected]>
*/
class ArtisanPhpCsFixerServiceProvider extends ServiceProvider implements DeferrableProvider
Expand All @@ -23,7 +25,8 @@ class ArtisanPhpCsFixerServiceProvider extends ServiceProvider implements Deferr
public function boot()
{
// Bootstrap handles
$this->configHandle();
$this->bootConfig();
$this->bootCommands();
}

/**
Expand All @@ -44,15 +47,6 @@ public function register()
$this->app->singleton('command.phpcsfixer.describe', function ($app) {
return new ArtisanPhpCsFixerDescribe;
});

$this->app->singleton('command.phpcsfixer.readme', function ($app) {
return new ArtisanPhpCsFixerReadme;
});

$this->commands('command.phpcsfixer.fix');
$this->commands('command.phpcsfixer.version');
$this->commands('command.phpcsfixer.describe');
$this->commands('command.phpcsfixer.readme');
}

/**
Expand All @@ -66,7 +60,6 @@ public function provides()
'command.phpcsfixer.fix',
'command.phpcsfixer.version',
'command.phpcsfixer.describe',
'command.phpcsfixer.readme',
];
}

Expand All @@ -75,13 +68,27 @@ public function provides()
*
* @return void
*/
protected function configHandle()
protected function bootConfig()
{
$sourceConfig = __DIR__.'/Config/.php_cs';
$sourceConfig = __DIR__ . '/Config/.php_cs';
$exportConfig = base_path('.php_cs');

$this->publishes([
$sourceConfig => $exportConfig,
], 'config');
}

/**
* Handle package's commands.
*
* @return void
*/
protected function bootCommands()
{
$this->commands([
'command.phpcsfixer.version',
'command.phpcsfixer.fix',
'command.phpcsfixer.describe',
]);
}
}
38 changes: 8 additions & 30 deletions src/Console/Commands/ArtisanPhpCsFixerDescribe.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php namespace Jackiedo\ArtisanPhpCsFixer\Console\Commands;
<?php

namespace Jackiedo\ArtisanPhpCsFixer\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

/**
* The ArtisanPhpCsFixerDescribe class.
*
* @package Jackiedo\ArtisanPhpCsFixer
*
* @author Jackie Do <[email protected]>
*/
class ArtisanPhpCsFixerDescribe extends Command
class ArtisanPhpCsFixerDescribe extends BaseCommand
{

/**
* The console command name.
*
Expand All @@ -25,17 +25,7 @@ class ArtisanPhpCsFixerDescribe extends Command
*
* @var string
*/
protected $description = 'Describe rule / ruleset of fixer.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
protected $description = 'Describe rule / rule set of fixer.';

/**
* Execute the console command.
Expand All @@ -44,19 +34,7 @@ public function __construct()
*/
public function fire()
{
$phpCsFixerBinnaryPath = base_path('vendor/bin/php-cs-fixer');

passthru($phpCsFixerBinnaryPath.' describe '.$this->argument('name'));
}

/**
* Alias of the fire() method
*
* @return mixed
*/
public function handle()
{
$this->fire();
passthru($this->phpCsFixerBinary . ' describe ' . $this->argument('name'));
}

/**
Expand All @@ -67,7 +45,7 @@ public function handle()
protected function getArguments()
{
return [
array('name', InputArgument::REQUIRED, 'Name of rule / set.'),
['name', InputArgument::REQUIRED, 'Name of rule / rule set.'],
];
}

Expand Down
Loading

0 comments on commit e3541f6

Please sign in to comment.