Skip to content

Commit 297dc7a

Browse files
committed
add phpstan, fix errors
1 parent 81db54b commit 297dc7a

13 files changed

+40
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
composer.phar
33
composer.lock
44
.DS_Store
5+
build
6+
phpstan.neon
57
.phpunit.result.cache
68
/.idea

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
"illuminate/view": ">=8",
1818
"illuminate/container": ">=8",
1919
"illuminate/console": ">=8",
20-
"illuminate/cache": ">=8"
20+
"illuminate/cache": ">=8",
21+
"illuminate/routing": ">=8"
2122
},
2223
"require-dev": {
23-
"phpunit/phpunit": "~8.0"
24+
"phpunit/phpunit": "~8.0",
25+
"nunomaduro/larastan": "^2.6"
2426
},
2527
"autoload": {
2628
"psr-4": {
@@ -44,6 +46,7 @@
4446
}
4547
},
4648
"scripts": {
49+
"analyse": "vendor/bin/phpstan analyse",
4750
"test": "phpunit"
4851
}
4952
}

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 4
6+
paths:
7+
- src
8+
tmpDir: build/phpstan
9+
checkMissingIterableValueType: false

src/Console/WidgetMakeCommand.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,15 @@ class WidgetMakeCommand extends GeneratorCommand
3030
*/
3131
protected $type = 'Widget';
3232

33-
/**
34-
* Execute the console command for Laravel >= 5.5.
35-
*
36-
* @return void
37-
*/
3833
public function handle()
3934
{
40-
// hack for Laravel < 5.5
41-
if (is_callable('parent::handle')) {
42-
parent::handle();
43-
} else {
44-
parent::fire();
45-
}
35+
parent::handle();
4636

4737
if (!$this->option('plain')) {
4838
$this->createView();
4939
}
50-
}
5140

52-
/**
53-
* Execute the console command for Laravel < 5.5.
54-
*
55-
* @return void
56-
*/
57-
public function fire()
58-
{
59-
parent::fire();
60-
61-
if (!$this->option('plain')) {
62-
$this->createView();
63-
}
41+
return null;
6442
}
6543

6644
/**
@@ -160,7 +138,7 @@ protected function replaceView($stub)
160138
*/
161139
protected function getDefaultNamespace($rootNamespace)
162140
{
163-
$namespace = config('laravel-widgets.default_namespace', $rootNamespace.'\Widgets');
141+
$namespace = $this->laravel->make('config')->get('laravel-widgets.default_namespace', $rootNamespace.'\Widgets');
164142

165143
if (!Str::startsWith($namespace, $rootNamespace)) {
166144
throw new RuntimeException("You can not use the generator if the default namespace ($namespace) does not start with application namespace ($rootNamespace)");
@@ -208,7 +186,7 @@ protected function createView()
208186
*/
209187
protected function getViewPath()
210188
{
211-
return base_path('resources/views').'/widgets/'.$this->makeViewName().'.blade.php';
189+
return $this->laravel->basePath('resources/views').'/widgets/'.$this->makeViewName().'.blade.php';
212190
}
213191

214192
/**

src/Contracts/ApplicationWrapperContract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface ApplicationWrapperContract
1212
* @param $key
1313
* @param $minutes
1414
* @param $tags
15-
* @param callable $callback
15+
* @param Closure $callback
1616
*
1717
* @return mixed
1818
*/

src/Controllers/WidgetController.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
namespace Arrilot\Widgets\Controllers;
44

55
use Arrilot\Widgets\Factories\AbstractWidgetFactory;
6+
use Arrilot\Widgets\Factories\WidgetFactory;
67
use Arrilot\Widgets\WidgetId;
78
use Illuminate\Http\Request;
89
use Illuminate\Routing\Controller as BaseController;
910

1011
class WidgetController extends BaseController
1112
{
13+
private WidgetFactory $factory;
14+
15+
public function __construct(WidgetFactory $factory)
16+
{
17+
$this->factory = $factory;
18+
}
19+
1220
/**
1321
* The action to show widget output via ajax.
1422
*
@@ -20,19 +28,18 @@ public function showWidget(Request $request)
2028
{
2129
$this->prepareGlobals($request);
2230

23-
$factory = app()->make('arrilot.widget');
2431
$widgetName = $request->input('name', '');
2532

2633
$widgetParams = $request->input('skip_encryption', '')
2734
? $request->input('params', '')
28-
: $factory->decryptWidgetParams($request->input('params', ''));
35+
: $this->factory->decryptWidgetParams($request->input('params', ''));
2936

3037
$decodedParams = json_decode($widgetParams, true);
3138

3239
$params = $decodedParams ?: [];
3340
array_unshift($params, $widgetName);
3441

35-
return call_user_func_array([$factory, 'run'], $params);
42+
return call_user_func_array([$this->factory, 'run'], $params);
3643
}
3744

3845
/**

src/Facade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ protected static function getFacadeAccessor()
1818
*/
1919
public static function group($name)
2020
{
21-
return app('arrilot.widget-group-collection')->group($name);
21+
return static::$app->make('arrilot.widget-group-collection')->group($name);
2222
}
2323
}

src/Factories/AbstractWidgetFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class AbstractWidgetFactory
1717
/**
1818
* Widget object to work with.
1919
*
20-
* @var AbstractWidget
20+
* @var AbstractWidget|null
2121
*/
2222
protected $widget;
2323

src/Misc/LaravelApplicationWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct()
2727
* @param $key
2828
* @param $minutes
2929
* @param $tags
30-
* @param callable $callback
30+
* @param Closure $callback
3131
*
3232
* @return mixed
3333
*/

0 commit comments

Comments
 (0)