Skip to content

Commit 45f0e37

Browse files
committed
Add type hints
1 parent f2730bd commit 45f0e37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+339
-468
lines changed

src/Blueprint.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
class Blueprint
1111
{
12-
private $lexers = [];
12+
private array $lexers = [];
1313

14-
private $generators = [];
14+
private array $generators = [];
1515

16-
public static function relativeNamespace(string $fullyQualifiedClassName)
16+
public static function relativeNamespace(string $fullyQualifiedClassName): string
1717
{
1818
$namespace = config('blueprint.namespace') . '\\';
1919
$reference = ltrim($fullyQualifiedClassName, '\\');
@@ -73,7 +73,7 @@ public function parse($content, $strip_dashes = true)
7373
return Yaml::parse($content);
7474
}
7575

76-
public function analyze(array $tokens)
76+
public function analyze(array $tokens): Tree
7777
{
7878
$registry = [
7979
'models' => [],
@@ -100,22 +100,22 @@ public function generate(Tree $tree, array $only = [], array $skip = [], $overwr
100100
return $components;
101101
}
102102

103-
public function dump(array $generated)
103+
public function dump(array $generated): string
104104
{
105105
return Yaml::dump($generated);
106106
}
107107

108-
public function registerLexer(Lexer $lexer)
108+
public function registerLexer(Lexer $lexer): void
109109
{
110110
$this->lexers[] = $lexer;
111111
}
112112

113-
public function registerGenerator(Generator $generator)
113+
public function registerGenerator(Generator $generator): void
114114
{
115115
$this->generators[] = $generator;
116116
}
117117

118-
public function swapGenerator(string $concrete, Generator $generator)
118+
public function swapGenerator(string $concrete, Generator $generator): void
119119
{
120120
foreach ($this->generators as $key => $registeredGenerator) {
121121
if (get_class($registeredGenerator) === $concrete) {

src/BlueprintServiceProvider.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class BlueprintServiceProvider extends ServiceProvider implements DeferrableProv
1818
{
1919
/**
2020
* Bootstrap the application events.
21-
*
22-
* @return void
2321
*/
24-
public function boot()
22+
public function boot(): void
2523
{
2624
if (!defined('STUBS_PATH')) {
2725
define('STUBS_PATH', dirname(__DIR__) . '/stubs');
@@ -42,10 +40,8 @@ public function boot()
4240

4341
/**
4442
* Register the service provider.
45-
*
46-
* @return void
4743
*/
48-
public function register()
44+
public function register(): void
4945
{
5046
$this->mergeConfigFrom(
5147
__DIR__ . '/../config/blueprint.php',
@@ -93,10 +89,8 @@ public function register()
9389

9490
/**
9591
* Get the services provided by the provider.
96-
*
97-
* @return array
9892
*/
99-
public function provides()
93+
public function provides(): array
10094
{
10195
return [
10296
'command.blueprint.build',

src/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Builder
88
{
9-
public function execute(Blueprint $blueprint, Filesystem $filesystem, string $draft, string $only = '', string $skip = '', $overwriteMigrations = false)
9+
public function execute(Blueprint $blueprint, Filesystem $filesystem, string $draft, string $only = '', string $skip = '', $overwriteMigrations = false): array
1010
{
1111
$cache = [];
1212
if ($filesystem->exists('.blueprint')) {

src/Commands/BuildCommand.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class BuildCommand extends Command
3030
*/
3131
protected $description = 'Build components from a Blueprint draft';
3232

33-
/** @var Filesystem */
34-
protected $filesystem;
33+
protected Filesystem $filesystem;
3534

36-
/** @var Builder */
37-
private $builder;
35+
private Builder $builder;
3836

3937
public function __construct(Filesystem $filesystem, Builder $builder)
4038
{
@@ -44,7 +42,7 @@ public function __construct(Filesystem $filesystem, Builder $builder)
4442
$this->builder = $builder;
4543
}
4644

47-
public function handle()
45+
public function handle(): int
4846
{
4947
$file = $this->argument('draft') ?? $this->defaultDraftFile();
5048

@@ -79,17 +77,15 @@ function ($file) {
7977

8078
/**
8179
* Get the console command arguments.
82-
*
83-
* @return array
8480
*/
85-
protected function getArguments()
81+
protected function getArguments(): array
8682
{
8783
return [
8884
['draft', InputArgument::OPTIONAL, 'The path to the draft file, default: draft.yaml or draft.yml', []],
8985
];
9086
}
9187

92-
private function outputStyle($action)
88+
private function outputStyle(string $action): string
9389
{
9490
if ($action === 'deleted') {
9591
return 'error';
@@ -100,7 +96,7 @@ private function outputStyle($action)
10096
return 'info';
10197
}
10298

103-
private function defaultDraftFile()
99+
private function defaultDraftFile(): string
104100
{
105101
return file_exists('draft.yml') ? 'draft.yml' : 'draft.yaml';
106102
}

src/Commands/EraseCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class EraseCommand extends Command
2222
*/
2323
protected $description = 'Erase components created from last Blueprint build';
2424

25-
/** @var Filesystem */
26-
protected $filesystem;
25+
protected Filesystem $filesystem;
2726

2827
public function __construct(Filesystem $filesystem)
2928
{
@@ -32,7 +31,7 @@ public function __construct(Filesystem $filesystem)
3231
$this->filesystem = $filesystem;
3332
}
3433

35-
public function handle()
34+
public function handle(): int
3635
{
3736
$contents = $this->filesystem->get('.blueprint');
3837

@@ -69,7 +68,7 @@ function ($file) {
6968
return $this->call('blueprint:trace');
7069
}
7170

72-
private function outputStyle($action)
71+
private function outputStyle(string $action): string
7372
{
7473
if ($action === 'created') {
7574
return 'error';

src/Commands/InitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class InitCommand extends Command
2020
*/
2121
protected $description = 'An alias for "blueprint:new" command';
2222

23-
public function handle()
23+
public function handle(): int
2424
{
2525
return $this->call(\Blueprint\Commands\NewCommand::class);
2626
}

src/Commands/NewCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class NewCommand extends Command
2424
*/
2525
protected $description = 'Create a draft.yaml file and load existing models';
2626

27-
/** @var Filesystem */
28-
protected $filesystem;
27+
protected Filesystem $filesystem;
2928

3029
public function __construct(Filesystem $filesystem)
3130
{
@@ -34,7 +33,7 @@ public function __construct(Filesystem $filesystem)
3433
$this->filesystem = $filesystem;
3534
}
3635

37-
public function handle()
36+
public function handle(): int
3837
{
3938
if (!$this->filesystem->exists('draft.yaml')) {
4039
$this->filesystem->put('draft.yaml', $this->filesystem->stub('draft.stub'));

src/Commands/PublishStubsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PublishStubsCommand extends Command
2020
*/
2121
protected $description = 'Publish blueprint stubs';
2222

23-
public function handle()
23+
public function handle(): int
2424
{
2525
return $this->call('vendor:publish', ['--tag' => 'blueprint-stubs']);
2626
}

src/Commands/TraceCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ class TraceCommand extends Command
2626
*/
2727
protected $description = 'Create definitions for existing models to reference in new drafts';
2828

29-
/** @var Filesystem */
30-
protected $filesystem;
29+
protected Filesystem $filesystem;
3130

32-
/** @var Tracer */
33-
private $tracer;
31+
private Tracer $tracer;
3432

3533
public function __construct(Filesystem $filesystem, Tracer $tracer)
3634
{
@@ -40,7 +38,7 @@ public function __construct(Filesystem $filesystem, Tracer $tracer)
4038
$this->tracer = $tracer;
4139
}
4240

43-
public function handle()
41+
public function handle(): int
4442
{
4543
$blueprint = resolve(Blueprint::class);
4644
$path = $this->option('path');

src/Concerns/HandlesImports.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
trait HandlesImports
88
{
9-
protected $imports = [];
9+
protected array $imports = [];
1010

11-
protected function addImport(Model $model, $class)
11+
protected function addImport(Model $model, $class): void
1212
{
1313
$this->imports[$model->name()][] = $class;
1414
}
1515

16-
protected function buildImports(Model $model)
16+
protected function buildImports(Model $model): string
1717
{
1818
return collect($this->imports[$model->name()] ?? [])
1919
->map(fn ($class) => "use {$class};")

0 commit comments

Comments
 (0)