Skip to content

Commit

Permalink
add phpstan, fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed Nov 19, 2023
1 parent 81db54b commit 297dc7a
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
composer.phar
composer.lock
.DS_Store
build
phpstan.neon
.phpunit.result.cache
/.idea
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"illuminate/view": ">=8",
"illuminate/container": ">=8",
"illuminate/console": ">=8",
"illuminate/cache": ">=8"
"illuminate/cache": ">=8",
"illuminate/routing": ">=8"
},
"require-dev": {
"phpunit/phpunit": "~8.0"
"phpunit/phpunit": "~8.0",
"nunomaduro/larastan": "^2.6"
},
"autoload": {
"psr-4": {
Expand All @@ -44,6 +46,7 @@
}
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"test": "phpunit"
}
}
Empty file added phpstan-baseline.neon
Empty file.
9 changes: 9 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- phpstan-baseline.neon

parameters:
level: 4
paths:
- src
tmpDir: build/phpstan
checkMissingIterableValueType: false
30 changes: 4 additions & 26 deletions src/Console/WidgetMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,15 @@ class WidgetMakeCommand extends GeneratorCommand
*/
protected $type = 'Widget';

/**
* Execute the console command for Laravel >= 5.5.
*
* @return void
*/
public function handle()
{
// hack for Laravel < 5.5
if (is_callable('parent::handle')) {
parent::handle();
} else {
parent::fire();
}
parent::handle();

if (!$this->option('plain')) {
$this->createView();
}
}

/**
* Execute the console command for Laravel < 5.5.
*
* @return void
*/
public function fire()
{
parent::fire();

if (!$this->option('plain')) {
$this->createView();
}
return null;
}

/**
Expand Down Expand Up @@ -160,7 +138,7 @@ protected function replaceView($stub)
*/
protected function getDefaultNamespace($rootNamespace)
{
$namespace = config('laravel-widgets.default_namespace', $rootNamespace.'\Widgets');
$namespace = $this->laravel->make('config')->get('laravel-widgets.default_namespace', $rootNamespace.'\Widgets');

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

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ApplicationWrapperContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ApplicationWrapperContract
* @param $key
* @param $minutes
* @param $tags
* @param callable $callback
* @param Closure $callback
*
* @return mixed
*/
Expand Down
13 changes: 10 additions & 3 deletions src/Controllers/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
namespace Arrilot\Widgets\Controllers;

use Arrilot\Widgets\Factories\AbstractWidgetFactory;
use Arrilot\Widgets\Factories\WidgetFactory;
use Arrilot\Widgets\WidgetId;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

class WidgetController extends BaseController
{
private WidgetFactory $factory;

public function __construct(WidgetFactory $factory)
{
$this->factory = $factory;
}

/**
* The action to show widget output via ajax.
*
Expand All @@ -20,19 +28,18 @@ public function showWidget(Request $request)
{
$this->prepareGlobals($request);

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

$widgetParams = $request->input('skip_encryption', '')
? $request->input('params', '')
: $factory->decryptWidgetParams($request->input('params', ''));
: $this->factory->decryptWidgetParams($request->input('params', ''));

$decodedParams = json_decode($widgetParams, true);

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

return call_user_func_array([$factory, 'run'], $params);
return call_user_func_array([$this->factory, 'run'], $params);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ protected static function getFacadeAccessor()
*/
public static function group($name)
{
return app('arrilot.widget-group-collection')->group($name);
return static::$app->make('arrilot.widget-group-collection')->group($name);
}
}
2 changes: 1 addition & 1 deletion src/Factories/AbstractWidgetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class AbstractWidgetFactory
/**
* Widget object to work with.
*
* @var AbstractWidget
* @var AbstractWidget|null
*/
protected $widget;

Expand Down
2 changes: 1 addition & 1 deletion src/Misc/LaravelApplicationWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct()
* @param $key
* @param $minutes
* @param $tags
* @param callable $callback
* @param Closure $callback
*
* @return mixed
*/
Expand Down
4 changes: 2 additions & 2 deletions src/NamespacesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NamespacesRepository
* @param string $alias
* @param string $namespace
*
* @return WidgetNamespaces
* @return $this
*/
public function registerNamespace($alias, $namespace)
{
Expand All @@ -31,7 +31,7 @@ public function registerNamespace($alias, $namespace)
/**
* Get namespace by his alias.
*
* @param string $label
* @param string $alias
*
* @throws \Exception
*
Expand Down
5 changes: 3 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Arrilot\Widgets\Factories\AsyncWidgetFactory;
use Arrilot\Widgets\Factories\WidgetFactory;
use Arrilot\Widgets\Misc\LaravelApplicationWrapper;
use Illuminate\Contracts\Foundation\CachesRoutes;
use Illuminate\Support\Facades\Blade;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
Expand Down Expand Up @@ -56,7 +57,7 @@ public function register()
public function boot()
{
$this->publishes([
__DIR__.'/config/config.php' => config_path('laravel-widgets.php'),
__DIR__.'/config/config.php' => $this->app->configPath('laravel-widgets.php'),
]);

$routeConfig = [
Expand All @@ -65,7 +66,7 @@ public function boot()
'middleware' => $this->app['config']->get('laravel-widgets.route_middleware', []),
];

if (!$this->app->routesAreCached()) {
if (!$this->app instanceof CachesRoutes || !$this->app->routesAreCached()) {
$this->app['router']->group($routeConfig, function ($router) {
$router->get('load-widget', 'WidgetController@showWidget');
});
Expand Down
2 changes: 1 addition & 1 deletion src/WidgetGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WidgetGroup
/**
* A callback that defines extra markup that wraps every widget in the group.
*
* @var callable
* @var callable|null
*/
protected $wrapCallback;

Expand Down

0 comments on commit 297dc7a

Please sign in to comment.