Skip to content

Commit

Permalink
Use Laravel Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Oct 6, 2022
1 parent eff605f commit 3b53313
Show file tree
Hide file tree
Showing 54 changed files with 246 additions and 218 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint
on:
- push
- pull_request
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: phplint, laravel/pint
- name: Check syntax
run: phplint .
- name: Check code style
run: pint --test
22 changes: 0 additions & 22 deletions .github/workflows/phplint.yml

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"symfony/yaml": "^6.0"
},
"require-dev": {
"laravel/pint": "^1.2",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.5.10"
Expand Down
19 changes: 19 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"preset": "laravel",
"rules": {
"blank_line_before_statement": {
"statements": ["return", "try"]
},
"cast_spaces": {
"space": "none"
},
"concat_space": {
"spacing": "one"
},
"not_operator_with_successor_space": false,
"logical_operators": true
},
"notPath": [
"tests/fixtures"
]
}
1 change: 1 addition & 0 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Blueprint
{
private $lexers = [];

private $generators = [];

public static function relativeNamespace(string $fullyQualifiedClassName)
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class BuildCommand extends Command
private $builder;

/**
* @param Filesystem $filesystem
* @param Builder $builder
* @param Filesystem $filesystem
* @param Builder $builder
*/
public function __construct(Filesystem $filesystem, Builder $builder)
{
Expand All @@ -54,6 +54,7 @@ public function handle()

if (!$this->filesystem->exists($file)) {
$this->error('Draft file could not be found: ' . ($file ?: 'draft.yaml'));

return 1;
}

Expand Down
1 change: 0 additions & 1 deletion src/Commands/EraseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Blueprint\Blueprint;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Artisan;

class EraseCommand extends Command
{
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class NewCommand extends Command
*/
protected $description = 'Create a draft.yaml file and load existing models';

/** @var Filesystem $files */
/** @var Filesystem */
protected $filesystem;

/**
* @param Filesystem $filesystem
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/TraceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class TraceCommand extends Command
*/
protected $description = 'Create definitions for existing models to reference in new drafts';

/** @var Filesystem $files */
/** @var Filesystem */
protected $filesystem;

/** @var Tracer */
private $tracer;

/**
* @param Filesystem $filesystem
* @param Tracer $tracer
* @param Filesystem $filesystem
* @param Tracer $tracer
*/
public function __construct(Filesystem $filesystem, Tracer $tracer)
{
Expand Down
3 changes: 2 additions & 1 deletion src/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
$this->values
);

return "ENUM(" . implode(", ", $values) . ")";
return 'ENUM(' . implode(', ', $values) . ')';
}

public function convertToPHPValue($value, AbstractPlatform $platform)
Expand All @@ -31,6 +31,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
if (!in_array($value, $this->values)) {
throw new \InvalidArgumentException("Invalid '" . $this->getName() . "' value.");
}

return $value;
}

Expand Down
1 change: 1 addition & 0 deletions src/Generators/AbstractClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function types(): array
protected function getPath(Model $model)
{
$path = str_replace('\\', '/', Blueprint::relativeNamespace($model->fullyQualifiedClassName()));

return sprintf('%s/%s.php', $this->basePath ?? Blueprint::appPath(), $path);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generators/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function buildMethods(Controller $controller)
$queryStatement = new QueryStatement('all', [$statement->reference()]);
$body = implode(PHP_EOL, [
self::INDENT . $queryStatement->output($statement->reference()),
PHP_EOL . $body
PHP_EOL . $body,
]);

$this->addImport($controller, $this->determineModel($controller, $queryStatement->model()));
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function buildDefinition(Model $model)

/**
* @var \Blueprint\Models\Column $column
*/
*/
foreach ($model->columns() as $column) {
$dataType = $column->dataType();

Expand Down
2 changes: 1 addition & 1 deletion src/Generators/RouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
$type = $controller->isApiResource() ? 'api' : 'web';
$routes[$type] .= PHP_EOL . PHP_EOL . $this->buildRoutes($controller);
Expand Down
1 change: 1 addition & 0 deletions src/Generators/SeederGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function populateStub(string $stub, BlueprintModel $model)
protected function build(BlueprintModel $model)
{
$this->addImport($model, $this->tree->fqcnForContext($model->name()));

return sprintf('%s::factory()->count(5)->create();', class_basename($this->tree->fqcnForContext($model->name())));
}
}
2 changes: 1 addition & 1 deletion src/Generators/Statements/EventGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
foreach ($statements as $statement) {
Expand Down
8 changes: 4 additions & 4 deletions src/Generators/Statements/FormRequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
foreach ($statements as $statement) {
Expand Down Expand Up @@ -111,8 +111,8 @@ private function splitField($field)
private function validationRules(string $qualifier, string $column)
{
/**
* @var \Blueprint\Models\Model $model
*/
* @var \Blueprint\Models\Model $model
*/
$model = $this->tree->modelForContext($qualifier);

$rules = [];
Expand All @@ -127,7 +127,7 @@ private function validationRules(string $qualifier, string $column)
} else {
/**
* @var \Blueprint\Models\Model $column
*/
*/
foreach ($model->columns() as $column) {
if ($column->name() === 'id') {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/Statements/JobGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
foreach ($statements as $statement) {
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/Statements/MailGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
foreach ($statements as $statement) {
Expand Down
4 changes: 2 additions & 2 deletions src/Generators/Statements/NotificationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
foreach ($statements as $statement) {
Expand Down Expand Up @@ -64,7 +64,7 @@ protected function populateStub(string $stub, SendStatement $sendStatement)
[
'via($notifiable): array',
sprintf('toMail($notifiable): %s', $sendStatement->mail()),
'toArray($notifiable): array'
'toArray($notifiable): array',
],
$stub
);
Expand Down
1 change: 1 addition & 0 deletions src/Generators/Statements/ResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function populateStub(string $stub, Controller $controller, ResourceSt
if (Blueprint::useReturnTypeHints()) {
$stub = str_replace('toArray($request)', 'toArray($request): array', $stub);
}

return $stub;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generators/Statements/ViewGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function output(Tree $tree): array

/**
* @var \Blueprint\Models\Controller $controller
*/
*/
foreach ($tree->controllers() as $controller) {
foreach ($controller->methods() as $method => $statements) {
foreach ($statements as $statement) {
Expand Down
13 changes: 9 additions & 4 deletions src/Generators/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ class TestGenerator extends AbstractClassGenerator implements Generator
use HandlesImports, HandlesTraits;

const TESTS_VIEW = 1;

const TESTS_REDIRECT = 2;

const TESTS_SAVE = 4;

const TESTS_DELETE = 8;

const TESTS_RESPONDS = 16;

protected $stubs = [];
Expand All @@ -59,6 +63,7 @@ public function output(Tree $tree): array
protected function getPath(BlueprintModel $model)
{
$path = str_replace('\\', '/', Blueprint::relativeNamespace($model->fullyQualifiedClassName()));

return 'tests/Feature/' . $path . 'Test.php';
}

Expand Down Expand Up @@ -125,7 +130,7 @@ protected function buildTestCases(Controller $controller)
$assertion .= ', function ($notification)';

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
if (Str::studly(Str::singular($data)) === $context || !Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$notification->%s->is($%s)', $data, $data);
} else {
Expand Down Expand Up @@ -166,7 +171,7 @@ protected function buildTestCases(Controller $controller)
}

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
if (Str::studly(Str::singular($data)) === $context || !Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$mail->%s->is($%s)', $data, $data);
} else {
Expand Down Expand Up @@ -262,7 +267,7 @@ protected function buildTestCases(Controller $controller)
$assertion .= ', function ($job)';

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
if (Str::studly(Str::singular($data)) === $context || !Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$job->%s->is($%s)', $data, $data);
} else {
Expand Down Expand Up @@ -305,7 +310,7 @@ protected function buildTestCases(Controller $controller)
$assertion .= ', function ($event)';

foreach ($statement->data() as $data) {
if (Str::studly(Str::singular($data)) === $context || ! Str::contains($data, '.')) {
if (Str::studly(Str::singular($data)) === $context || !Str::contains($data, '.')) {
$variables[] .= '$' . $data;
$conditions[] .= sprintf('$event->%s->is($%s)', $data, $data);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
class Column
{
private $modifiers;

private $name;

private $dataType;

private $attributes;

public function __construct(string $name, string $dataType = 'string', array $modifiers = [], array $attributes = [])
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Controller implements BlueprintModel
/** @var array */
public static $resourceMethods = ['index', 'create', 'store', 'edit', 'update', 'show', 'destroy'];

/** @var array */
/** @var array */
public static $apiResourceMethods = ['index', 'store', 'update', 'show', 'destroy'];

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ public function prefix()
}

/**
* @param bool $apiResource
* @param bool $apiResource
*/
public function setApiResource(bool $apiResource)
{
Expand Down
1 change: 1 addition & 0 deletions src/Models/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class Index
{
private $type;

private $columns;

public function __construct(string $type, array $columns = [])
Expand Down
Loading

0 comments on commit 3b53313

Please sign in to comment.