diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml new file mode 100644 index 0000000..cfeff1e --- /dev/null +++ b/.github/workflows/check-style.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [ push ] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php_cs.dist --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling \ No newline at end of file diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..1e7f9f3 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,39 @@ +name: run-tests + +on: [push, pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + php: [7.4] + laravel: [7.*, 8.*] + dependency-version: [prefer-stable] + include: + - laravel: 7.* + testbench: 5.* + - laravel: 8.* + testbench: 6.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + + - name: Execute tests + run: vendor/bin/phpunit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 49c63d2..f59c8c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock -/vendor \ No newline at end of file +/vendor +.php_cs.cache \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..9824961 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,37 @@ +notPath('vendor') + ->notPath('tests/fixtures/*') + ->in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sortAlgorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'trailing_comma_in_multiline_array' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + ]) + ->ex + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index cedbd2b..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,4 +0,0 @@ -preset: laravel -finder: - exclude: - - "tests/fixtures" \ No newline at end of file diff --git a/composer.json b/composer.json index 6bd153a..a5314d1 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "require-dev": { "orchestra/testbench": "^4.0 || ^5.0 || ^6.0", "mockery/mockery": "^1.3", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "8.0 || ^9.0" }, "autoload": { "psr-4": { diff --git a/src/BlueprintNovaAddonServiceProvider.php b/src/BlueprintNovaAddonServiceProvider.php index 1315085..57a2739 100644 --- a/src/BlueprintNovaAddonServiceProvider.php +++ b/src/BlueprintNovaAddonServiceProvider.php @@ -3,12 +3,12 @@ namespace Naoray\BlueprintNovaAddon; use Blueprint\Blueprint; -use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\ServiceProvider; -use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField; +use Illuminate\Contracts\Support\DeferrableProvider; use Naoray\BlueprintNovaAddon\Tasks\AddRegularFields; -use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields; +use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField; use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; +use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields; class BlueprintNovaAddonServiceProvider extends ServiceProvider implements DeferrableProvider { @@ -19,7 +19,7 @@ public function boot() { if ($this->app->runningInConsole()) { $this->publishes([ - dirname(__DIR__).'/config/nova_blueprint.php' => config_path('nova_blueprint.php'), + dirname(__DIR__) . '/config/nova_blueprint.php' => config_path('nova_blueprint.php'), ], 'nova_blueprint'); } } @@ -30,8 +30,8 @@ public function boot() public function register() { $this->mergeConfigFrom( - dirname(__DIR__).'/config/nova_blueprint.php', - 'blueprint-nova-config' + dirname(__DIR__) . '/config/nova_blueprint.php', + 'blueprint-nova' ); $this->app->singleton(NovaGenerator::class, function ($app) { diff --git a/src/NovaGenerator.php b/src/NovaGenerator.php index 4132663..b4fd3d9 100644 --- a/src/NovaGenerator.php +++ b/src/NovaGenerator.php @@ -2,15 +2,15 @@ namespace Naoray\BlueprintNovaAddon; +use Blueprint\Tree; use Blueprint\Blueprint; -use Blueprint\Contracts\Generator; use Blueprint\Models\Model; -use Blueprint\Tree; -use Illuminate\Pipeline\Pipeline; use Illuminate\Support\Str; +use Illuminate\Pipeline\Pipeline; +use Blueprint\Contracts\Generator; use Naoray\BlueprintNovaAddon\Contracts\Task; -use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; use Naoray\BlueprintNovaAddon\Tasks\RemapImports; +use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; class NovaGenerator implements Generator { @@ -34,13 +34,13 @@ public function output(Tree $tree): array { $output = []; - $stub = $this->files->get($this->stubPath().DIRECTORY_SEPARATOR.'class.stub'); + $stub = $this->files->get($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub'); /** @var \Blueprint\Models\Model $model */ foreach ($tree->models() as $model) { $path = $this->getPath($model); - if (! $this->files->exists(dirname($path))) { + if (!$this->files->exists(dirname($path))) { $this->files->makeDirectory(dirname($path), 0755, true); } @@ -54,9 +54,9 @@ public function output(Tree $tree): array protected function getPath(Model $model): string { - $path = str_replace('\\', '/', Blueprint::relativeNamespace($this->getNovaNamespace($model).'/'.$model->name())); + $path = str_replace('\\', '/', Blueprint::relativeNamespace($this->getNovaNamespace($model) . '/' . $model->name())); - return config('blueprint.app_path').'/'.$path.'.php'; + return config('blueprint.app_path') . '/' . $path . '.php'; } protected function populateStub(string $stub, Model $model): string @@ -72,7 +72,7 @@ protected function populateStub(string $stub, Model $model): string $stub = str_replace('DummyNamespace', $this->getNovaNamespace($model), $stub); $stub = str_replace('DummyClass', $model->name(), $stub); - $stub = str_replace('DummyModel', '\\'.$model->fullyQualifiedClassName(), $stub); + $stub = str_replace('DummyModel', '\\' . $model->fullyQualifiedClassName(), $stub); $stub = str_replace('// fields...', $data['fields'], $stub); $stub = str_replace('use Illuminate\Http\Request;', implode(PHP_EOL, $data['imports']), $stub); @@ -82,10 +82,10 @@ protected function populateStub(string $stub, Model $model): string protected function getNovaNamespace(Model $model): string { $namespace = Str::after($model->fullyQualifiedNamespace(), config('blueprint.namespace')); - $namespace = config('blueprint.namespace').'\Nova'.$namespace; + $namespace = config('blueprint.namespace') . '\Nova' . $namespace; if (config('blueprint.models_namespace')) { - $namespace = str_replace('\\'.config('blueprint.models_namespace'), '', $namespace); + $namespace = str_replace('\\' . config('blueprint.models_namespace'), '', $namespace); } return $namespace; @@ -110,7 +110,7 @@ protected function filteredTasks(): array { $tasks = $this->tasks; - if (! config('nova_blueprint.timestamps')) { + if (!config('nova_blueprint.timestamps')) { $tasks = array_filter($tasks, function ($key) { return $key !== AddTimestampFields::class; }, ARRAY_FILTER_USE_KEY); diff --git a/tests/NovaGeneratorTest.php b/tests/NovaGeneratorTest.php index a75cfdf..ec93853 100644 --- a/tests/NovaGeneratorTest.php +++ b/tests/NovaGeneratorTest.php @@ -2,14 +2,14 @@ namespace Naoray\BlueprintNovaAddon\Tests; -use Blueprint\Blueprint; use Blueprint\Tree; +use Blueprint\Blueprint; use Naoray\BlueprintNovaAddon\HasStubPath; use Naoray\BlueprintNovaAddon\NovaGenerator; -use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField; use Naoray\BlueprintNovaAddon\Tasks\AddRegularFields; -use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields; +use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField; use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields; +use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields; class NovaGeneratorTest extends TestCase { @@ -44,7 +44,7 @@ protected function setUp(): void public function output_generates_nothing_for_empty_tree() { $this->files->expects('get') - ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') + ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->shouldNotHaveReceived('put'); @@ -59,7 +59,7 @@ public function output_generates_nothing_for_empty_tree() public function output_generates_nova_resources($definition, $path, $novaResource) { $this->files->expects('get') - ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') + ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists') @@ -81,7 +81,7 @@ public function output_generates_nova_resources($definition, $path, $novaResourc public function output_generates_relationships() { $this->files->expects('get') - ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') + ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists') @@ -106,7 +106,7 @@ public function output_respects_blueprint_configurations() $this->app['config']->set('blueprint.models_namespace', 'Models'); $this->files->expects('get') - ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') + ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists') @@ -131,7 +131,7 @@ public function output_respects_packages_configuration() $this->app['config']->set('nova_blueprint.timestamps', false); $this->files->expects('get') - ->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub') + ->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub') ->andReturn(file_get_contents('stubs/class.stub')); $this->files->expects('exists')