-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace LaravelFans\Lint; | ||
|
||
use FilesystemIterator; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class LintPhpcsCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'lint:phpcs | ||
{--fix : automatic fix} | ||
{--standard=phpcs.xml : coding standards} | ||
{files?*}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Lint by phpcs'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$bin = $this->option('fix') ? 'phpcbf' : 'phpcs'; | ||
$files = empty($this->argument('files')) ? ['.'] : $this->argument('files'); | ||
$command = "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "$bin --standard="; | ||
exec( | ||
$command . $this->option('standard') . ' ' . implode(' ', $files), | ||
$output, | ||
$code | ||
); | ||
foreach ($output as $line) { | ||
$this->line($line); | ||
} | ||
return $code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace LaravelFans\Lint; | ||
|
||
use FilesystemIterator; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
|
||
class LintPmdCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'lint:pmd | ||
{files?*} | ||
{--format=text} | ||
{--ruleset=phpmd.xml}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Lint by phpmd'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$files = empty($this->argument('files')) ? ['.'] : $this->argument('files'); | ||
$command = "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "phpmd "; | ||
exec( | ||
$command . implode(' ', $files) . ' ' . $this->option('format') . ' ' . $this->option('ruleset'), | ||
$output, | ||
$code | ||
); | ||
foreach ($output as $line) { | ||
$this->line($line); | ||
} | ||
return $code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace LaravelFans\Lint\Tests; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use phpmock\MockBuilder; | ||
use phpmock\functions\FixedValueFunction; | ||
|
||
class LintPhpcsCommandTest extends TestCase | ||
{ | ||
public function testLintPhpcsWithoutArgs() | ||
{ | ||
$builder = new MockBuilder(); | ||
$builder->setNamespace('\\LaravelFans\\Lint') | ||
->setName("exec") | ||
->setFunction( | ||
function ($command, &$output, &$code) { | ||
$this->assertEquals("vendor/bin/phpcs --standard=phpcs.xml .", $command); | ||
$output = []; | ||
$code = 0; | ||
} | ||
); | ||
$mock = $builder->build(); | ||
$mock->enable(); | ||
$this->artisan('lint:phpcs')->assertExitCode(0); | ||
$mock->disable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace LaravelFans\Lint\Tests; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use phpmock\MockBuilder; | ||
use phpmock\functions\FixedValueFunction; | ||
|
||
class LintPmdCommandTest extends TestCase | ||
{ | ||
public function testLintPmdWithoutArgs() | ||
{ | ||
$builder = new MockBuilder(); | ||
$builder->setNamespace('\\LaravelFans\\Lint') | ||
->setName("exec") | ||
->setFunction( | ||
function ($command, &$output, &$code) { | ||
$this->assertEquals("vendor/bin/phpmd . text phpmd.xml", $command); | ||
$output = []; | ||
$code = 1; | ||
} | ||
); | ||
$mock = $builder->build(); | ||
$mock->enable(); | ||
$this->artisan('lint:pmd')->assertExitCode(1); | ||
$mock->disable(); | ||
} | ||
} |