Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check phpstan by github actions #22

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "8.0", "8.1" ]
php: [ "8.1", "8.2" ]
steps:
- uses: actions/checkout@v3

Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: phpstan

on:
pull_request:
paths:
- 'src/**'
- 'tests/**'

jobs:
phpstan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ "8.1", "8.2" ]
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mongodb, sodium
tools: composer:v2

- name: Prepare
run: composer install

- name: Versions
run: |
cat /etc/os-release
php -v
./vendor/bin/phpstan --version
- name: Execute phpstan
run: |
./vendor/bin/phpstan analyse
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ "8.0", "8.1" ]
php: [ "8.2", "8.1" ]
steps:
- uses: actions/checkout@v3

Expand Down
20 changes: 14 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
"symfony/dom-crawler": "^6.3",
"laravel/framework": "^10.10",
"intervention/image": "^2.7",
"doctrine/dbal": "^3.6"
"doctrine/dbal": "^3.6",
"maatwebsite/excel": "^3.1"
},
"require-dev": {
"laravel/laravel": "^10.0",
"phpunit/phpunit": "^9.0",
"laravel/framework": "^10.10",
"symfony/css-selector": "~5.2",
"fzaninotto/faker": "~1.4",
"laravel/browser-kit-testing": "~6.2"
"fakerphp/faker": "^1.9",
"laravel/browser-kit-testing": "~6.2",
"phpstan/phpstan": "^1.10",
"matthiasmullie/minify": "^1.3",
"nunomaduro/larastan": "^2.5",
"orchestra/testbench": "^8.0",
"spatie/eloquent-sortable": "^4.0"
},
"autoload": {
"psr-4": {
Expand All @@ -44,7 +50,10 @@
]
},
"scripts": {
"test": "./vendor/bin/phpunit"
"test": "./vendor/bin/phpunit",
"post-autoload-dump": [
"@php vendor/bin/testbench package:discover --ansi"
]
},
"suggest": {
"intervention/image": "Required to handling and manipulation upload images (~2.3).",
Expand All @@ -58,7 +67,6 @@
"aliases": {
"Admin": "Encore\\Admin\\Facades\\Admin"
}

}
}
}
15 changes: 15 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
paths:
- src
level: 3
ignoreErrors:
- '#Call to static method transaction\(\) on an unknown class ExmentDB.#'
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::\$id.#'
- '#Access to an undefined property Illuminate\\Database\\Eloquent\\Model::\$password.#'
- '#Call to an undefined method Encore\\Admin\\Grid\\Column::pluck\(\).#'
- '#Cannot call method with\(\) on string.#'
- '#Cannot call method render\(\) on string.#'
- '#Return type \(Illuminate\\Contracts\\View\\Factory\|Illuminate\\View\\View\) of method Encore\\Admin\\Widgets\\Grid\\Tools\\QuickSearch::render\(\) should be compatible with return type \(string\) of method Encore\\Admin\\Widgets\\Grid\\Tools\\AbstractTool::render\(\)#'
- '#Return type \(Illuminate\\Contracts\\View\\Factory\|Illuminate\\View\\View\) of method Encore\\Admin\\Widgets\\Grid\\Tools\\QuickSearch::render\(\) should be compatible with return type \(string\) of method Illuminate\\Contracts\\Support\\Renderable::render\(\)#'
includes:
- vendor/nunomaduro/larastan/extension.neon
8 changes: 4 additions & 4 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ class Admin
public static $extensions = [];

/**
* @var []Closure
* @var Closure[]
*/
protected static $bootingCallbacks = [];

/**
* @var []Closure
* @var Closure[]
*/
protected static $registeredCallbacks = [];

/**
* @var []Closure
* @var Closure[]
*/
protected static $bootedCallbacks = [];

Expand Down Expand Up @@ -266,7 +266,7 @@ public function user()
*
* @param Closure|null $builder
*
* @return Navbar
* @return Navbar|void
*/
public function navbar(Closure $builder = null)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Auth/Database/Administrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
use Encore\Admin\Traits\AdminBuilder;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\Storage;

/**
* Class Administrator.
*
* @property Role[] $roles
* @property Collection $roles
* @phpstan-consistent-constructor
*/
class Administrator extends Model implements AuthenticatableContract
{
Expand Down
12 changes: 8 additions & 4 deletions src/Auth/Database/HasPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use Illuminate\Support\Collection;

/**
* @property mixed $permissions
*/
trait HasPermissions
{

/**
* Get all permissions of user.
*
* @return mixed
* @return Collection
*/
public function allPermissions() : Collection
{
Expand Down Expand Up @@ -52,7 +56,7 @@ public function cannot(string $permission) : bool
/**
* Check if user is administrator.
*
* @return mixed
* @return bool
*/
public function isAdministrator() : bool
{
Expand All @@ -64,7 +68,7 @@ public function isAdministrator() : bool
*
* @param string $role
*
* @return mixed
* @return bool
*/
public function isRole(string $role) : bool
{
Expand All @@ -76,7 +80,7 @@ public function isRole(string $role) : bool
*
* @param array $roles
*
* @return mixed
* @return bool
*/
public function inRoles(array $roles = []) : bool
{
Expand Down
4 changes: 1 addition & 3 deletions src/Auth/Database/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Class Menu.
*
* @property int $id
*
* @method where($parent_id, $id)
* @phpstan-consistent-constructor
*/
class Menu extends Model
{
Expand All @@ -23,8 +23,6 @@ class Menu extends Model

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['parent_id', 'order', 'title', 'icon', 'uri', 'permission'];

Expand Down
3 changes: 3 additions & 0 deletions src/Auth/Database/OperationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @method static mixed create(array $attributes)
*/
class OperationLog extends Model
{
protected $fillable = ['user_id', 'path', 'method', 'ip', 'input'];
Expand Down
3 changes: 0 additions & 3 deletions src/Auth/Database/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

class Permission extends Model
{
/**
* @var array
*/
protected $fillable = ['name', 'slug', 'http_method', 'http_path'];

/**
Expand Down
13 changes: 7 additions & 6 deletions src/Auth/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class Permission
{

/**
* Check permission.
*
* @param $permission
*
* @return true
* @return true|void
*/
public static function check($permission)
{
Expand All @@ -38,15 +38,15 @@ public static function check($permission)
* Roles allowed to access.
*
* @param $roles
*
* @return true
* @return true|void
*/
public static function allow($roles)
{
if (static::isAdministrator()) {
return true;
}

// @phpstan-ignore-next-line inRoles undefined
if (!Auth::guard('admin')->user()->inRoles($roles)) {
static::error();
}
Expand All @@ -66,15 +66,15 @@ public static function free()
* Roles denied to access.
*
* @param $roles
*
* @return true
* @return true|void
*/
public static function deny($roles)
{
if (static::isAdministrator()) {
return true;
}

// @phpstan-ignore-next-line inRoles undefined
if (Auth::guard('admin')->user()->inRoles($roles)) {
static::error();
}
Expand Down Expand Up @@ -108,6 +108,7 @@ public static function error($message = null)
*/
public static function isAdministrator()
{
// @phpstan-ignore-next-line isRole undefined
return Auth::guard('admin')->user()->isRole('administrator');
}
}
2 changes: 0 additions & 2 deletions src/Console/ExportSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ protected function getStub($name)
*
* @param $var
* @param string $indent
*
* @return string
*/
protected function varExport($var, $indent = '')
{
Expand Down
2 changes: 0 additions & 2 deletions src/Console/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class MakeCommand extends GeneratorCommand

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
Expand Down
6 changes: 5 additions & 1 deletion src/Console/ResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Encore\Admin\Console;

use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Illuminate\Database\Eloquent\Model;

class ResourceGenerator
Expand Down Expand Up @@ -220,7 +221,10 @@ protected function getTableColumns()
}

$table = $this->model->getConnection()->getTablePrefix().$this->model->getTable();
/** @var \Doctrine\DBAL\Schema\MySqlSchemaManager $schema */
/**
* @var AbstractSchemaManager $schema
* @phpstan-ignore-next-line Maybe not use $table argument
*/
$schema = $this->model->getConnection()->getDoctrineSchemaManager($table);

// custom mapping the types that doctrine/dbal does not support
Expand Down
5 changes: 5 additions & 0 deletions src/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Encore\Admin\Layout\Content;
use Illuminate\Routing\Controller;

/**
* @method mixed grid()
* @method mixed detail($id)
* @method mixed form()
*/
class AdminController extends Controller
{
use HasResourceActions;
Expand Down
10 changes: 5 additions & 5 deletions src/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AuthController extends Controller
/**
* Show the login page.
*
* @return \Illuminate\Contracts\View\Factory|Redirect|\Illuminate\View\View
* @return bool|\Illuminate\Auth\Access\Response|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
*/
public function getLogin()
{
Expand Down Expand Up @@ -74,7 +74,8 @@ protected function loginValidator(array $data)
/**
* User logout.
*
* @return Redirect
* @param Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function getLogout(Request $request)
{
Expand Down Expand Up @@ -182,9 +183,8 @@ protected function redirectPath()
/**
* Send the response after the user was authenticated.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
protected function sendLoginResponse(Request $request)
{
Expand Down
5 changes: 2 additions & 3 deletions src/Controllers/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ protected function grid()
}

/**
* @param mixed $id
*
* @return \Illuminate\Http\JsonResponse
* @param $id
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
public function destroy($id)
{
Expand Down
Loading
Loading