From 165c4fd53cfb732f4a47e40da39d7372b2346c17 Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Wed, 21 Apr 2021 14:41:34 +0200 Subject: [PATCH] Enable PHPStan linter (#12678) * Enable PHPStan linter * Add PHPStan baseline * Switch to Level 5 * Fix StringBlade errors with a stub file --- .github/workflows/lint.yml | 52 +++- LibreNMS/Alert/Template.php | 9 +- app/Http/Controllers/DeviceController.php | 3 +- composer.json | 4 +- composer.lock | 212 +++++++++++++- phpstan-baseline.neon | 322 ++++++++++++++++++++++ phpstan.neon | 31 +++ tests/stubs/StringBlade.stub | 11 + 8 files changed, 633 insertions(+), 11 deletions(-) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon create mode 100644 tests/stubs/StringBlade.stub diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 495cac4291..8d990b41e3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,21 +1,23 @@ -name: Lint Code Base +name: Lint on: push: pull_request: branches: [master, main] jobs: - build: + super-linter: name: Lint Code Base runs-on: ubuntu-latest steps: - - name: Checkout Code + - + name: Checkout Code uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Lint Code Base + - + name: Lint Code Base uses: github/super-linter@v3 env: VALIDATE_BASH: true @@ -26,3 +28,45 @@ jobs: VALIDATE_ALL_CODEBASE: false DEFAULT_BRANCH: master GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + phpstan: + name: PHP Static Analysis + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - + name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + tools: composer + + - + name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - + name: Cache composer + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer-${{ secrets.CACHE_VERSION }}- + + - + name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip-${{ secrets.CACHE_VERSION }}- + + - + name: Composer install + run: composer install --prefer-dist --no-interaction --no-progress + + - + name: Run phpstan + run: ./vendor/bin/phpstan analyze --no-interaction --no-progress --error-format=github --memory-limit=4G diff --git a/LibreNMS/Alert/Template.php b/LibreNMS/Alert/Template.php index 8bb782be11..4f4fbd721b 100644 --- a/LibreNMS/Alert/Template.php +++ b/LibreNMS/Alert/Template.php @@ -26,6 +26,7 @@ namespace LibreNMS\Alert; use App\Models\AlertTemplate; use LibreNMS\Enum\AlertState; +use Wpb\String_Blade_Compiler\Facades\StringBlade as View; class Template { @@ -73,9 +74,9 @@ class Template { $alert['alert'] = new AlertData($data['alert']); try { - return view(['template' => $data['template']->template], $alert)->__toString(); + return View::make(['template' => $data['template']->template], $alert)->__toString(); } catch (\Exception $e) { - return view(['template' => $this->getDefaultTemplate()], $alert)->__toString(); + return View::make(['template' => $this->getDefaultTemplate()], $alert)->__toString(); } } @@ -89,9 +90,9 @@ class Template { $alert['alert'] = new AlertData($data['alert']); try { - return view(['template' => $data['title']], $alert)->__toString(); + return View::make(['template' => $data['title']], $alert)->__toString(); } catch (\Exception $e) { - return $data['title'] ?: view(['template' => 'Template ' . $data['name']], $alert)->__toString(); + return $data['title'] ?: View::make(['template' => 'Template ' . $data['name']], $alert)->__toString(); } } diff --git a/app/Http/Controllers/DeviceController.php b/app/Http/Controllers/DeviceController.php index 90f5725288..b6854c42d8 100644 --- a/app/Http/Controllers/DeviceController.php +++ b/app/Http/Controllers/DeviceController.php @@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Auth; use LibreNMS\Config; use LibreNMS\Util\Graph; use LibreNMS\Util\Url; +use Wpb\String_Blade_Compiler\Facades\StringBlade as View; class DeviceController extends Controller { @@ -165,7 +166,7 @@ class DeviceController extends Controller foreach (array_values(Arr::wrap(Config::get('html.device.links'))) as $index => $link) { $device_links['custom' . ($index + 1)] = [ 'icon' => $link['icon'] ?? 'fa-external-link', - 'url' => view(['template' => $link['url']], ['device' => $device])->__toString(), + 'url' => View::make(['template' => $link['url']], ['device' => $device])->__toString(), 'title' => $link['title'], 'external' => $link['external'] ?? true, ]; diff --git a/composer.json b/composer.json index 6658ca309a..34cfb0654b 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "pear/net_dns2": "^1.5", "php-amqplib/php-amqplib": "^3.0", "phpmailer/phpmailer": "~6.0", + "phpstan/phpstan-mockery": "^0.12.13", "predis/predis": "^1.1", "rmccue/requests": "^1.7", "symfony/yaml": "^4.0", @@ -64,12 +65,13 @@ "barryvdh/laravel-debugbar": "^3.5", "barryvdh/laravel-ide-helper": "^2.8", "facade/ignition": "^2.5", - "friendsofphp/php-cs-fixer": "^2.16", "fakerphp/faker": "^1.9.1", + "friendsofphp/php-cs-fixer": "^2.16", "justinrainbow/json-schema": "^5.2", "laravel/dusk": "^6.7", "mockery/mockery": "^1.4.2", "nunomaduro/collision": "^5.0", + "nunomaduro/larastan": "^0.7.4", "php-parallel-lint/php-parallel-lint": "^1.1", "phpunit/phpunit": "^9.3.3", "staudenmeir/dusk-updater": "^1.1" diff --git a/composer.lock b/composer.lock index 723317d1b2..2f0ce6a42e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a3448867de504ff83ae077bfaa8dfa7d", + "content-hash": "1d1478b7a5e85e9fc74e6bd555677c15", "packages": [ { "name": "amenadiel/jpgraph", @@ -3418,6 +3418,119 @@ ], "time": "2021-04-06T14:00:11+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.83", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a967cec6efb46b500dd6d768657336a3ffe699f", + "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.83" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-04-03T15:35:45+00:00" + }, + { + "name": "phpstan/phpstan-mockery", + "version": "0.12.13", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-mockery.git", + "reference": "a45fee47fe86a2a4992953fb7037cb2620c4d7ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/a45fee47fe86a2a4992953fb7037cb2620c4d7ea", + "reference": "a45fee47fe86a2a4992953fb7037cb2620c4d7ea", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "phpstan/phpstan": "^0.12.60" + }, + "require-dev": { + "mockery/mockery": "^1.2.4", + "phing/phing": "^2.16.3", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^0.12.16", + "phpstan/phpstan-strict-rules": "^0.12.5", + "phpunit/phpunit": "^7.5.20" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan Mockery extension", + "support": { + "issues": "https://github.com/phpstan/phpstan-mockery/issues", + "source": "https://github.com/phpstan/phpstan-mockery/tree/0.12.13" + }, + "time": "2021-03-05T12:36:50+00:00" + }, { "name": "predis/predis", "version": "v1.1.6", @@ -8581,6 +8694,103 @@ ], "time": "2021-01-25T15:34:13+00:00" }, + { + "name": "nunomaduro/larastan", + "version": "v0.7.4", + "source": { + "type": "git", + "url": "https://github.com/nunomaduro/larastan.git", + "reference": "0ceef2a39b45be9d7f7dd96192a1721ba5112278" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/0ceef2a39b45be9d7f7dd96192a1721ba5112278", + "reference": "0ceef2a39b45be9d7f7dd96192a1721ba5112278", + "shasum": "" + }, + "require": { + "composer/composer": "^1.0 || ^2.0", + "ext-json": "*", + "illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/container": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/contracts": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/http": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/pipeline": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "mockery/mockery": "^0.9 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^0.12.83", + "symfony/process": "^4.3 || ^5.0" + }, + "require-dev": { + "orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0", + "phpunit/phpunit": "^7.3 || ^8.2 || ^9.3" + }, + "suggest": { + "orchestra/testbench": "^4.0 || ^5.0" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "0.6-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "NunoMaduro\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/nunomaduro/larastan/issues", + "source": "https://github.com/nunomaduro/larastan/tree/v0.7.4" + }, + "funding": [ + { + "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L", + "type": "custom" + }, + { + "url": "https://github.com/canvural", + "type": "github" + }, + { + "url": "https://github.com/nunomaduro", + "type": "github" + }, + { + "url": "https://www.patreon.com/nunomaduro", + "type": "patreon" + } + ], + "time": "2021-04-16T08:25:31+00:00" + }, { "name": "phar-io/manifest", "version": "2.0.1", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000000..4f49ce269c --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,322 @@ +parameters: + ignoreErrors: + - + message: "#^Call to function is_null\\(\\) with string will always evaluate to false\\.$#" + count: 1 + path: LibreNMS/Alerting/QueryBuilderParser.php + + - + message: "#^Parameter \\#1 \\$ldap of function ldap_error expects resource, false given\\.$#" + count: 1 + path: LibreNMS/Authentication/ADAuthorizationAuthorizer.php + + - + message: "#^Parameter \\#1 \\$ldap of function ldap_error expects resource, false given\\.$#" + count: 1 + path: LibreNMS/Authentication/LdapAuthorizationAuthorizer.php + + - + message: "#^If condition is always false\\.$#" + count: 1 + path: LibreNMS/Authentication/MysqlAuthorizer.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: LibreNMS/Authentication/MysqlAuthorizer.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: LibreNMS/Authentication/MysqlAuthorizer.php + + - + message: "#^Parameter \\#2 \\$password of method LibreNMS\\\\Authentication\\\\MysqlAuthorizer\\:\\:addUser\\(\\) expects string, null given\\.$#" + count: 1 + path: LibreNMS/Authentication/SSOAuthorizer.php + + - + message: "#^Parameter \\#1 \\$num of function base_convert expects string, int given\\.$#" + count: 1 + path: LibreNMS/Authentication/TwoFactor.php + + - + message: "#^Parameter \\#1 \\$string of function str_pad expects string, int given\\.$#" + count: 1 + path: LibreNMS/Authentication/TwoFactor.php + + - + message: "#^Call to function is_null\\(\\) with Illuminate\\\\Database\\\\Capsule\\\\Manager will always evaluate to false\\.$#" + count: 2 + path: LibreNMS/DB/Eloquent.php + + - + message: "#^Call to function is_null\\(\\) with PDO will always evaluate to false\\.$#" + count: 1 + path: LibreNMS/DB/Eloquent.php + + - + message: "#^Result of && is always false\\.$#" + count: 1 + path: LibreNMS/DB/Eloquent.php + + - + message: "#^If condition is always true\\.$#" + count: 1 + path: LibreNMS/Data/Store/OpenTSDB.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: LibreNMS/Data/Store/OpenTSDB.php + + - + message: "#^Right side of && is always true\\.$#" + count: 1 + path: LibreNMS/Data/Store/Rrd.php + + - + message: "#^Parameter \\#1 \\$model of static method LibreNMS\\\\Model\\:\\:onCreate\\(\\) expects static\\(LibreNMS\\\\Device\\\\Processor\\), LibreNMS\\\\Device\\\\Processor given\\.$#" + count: 1 + path: LibreNMS/Device/Processor.php + + - + message: "#^Parameter \\#1 \\$model of static method LibreNMS\\\\Model\\:\\:onDelete\\(\\) expects static\\(LibreNMS\\\\Device\\\\Processor\\), LibreNMS\\\\Device\\\\Processor given\\.$#" + count: 1 + path: LibreNMS/Device/Processor.php + + - + message: "#^Method LibreNMS\\\\Modules\\\\Mempools\\:\\:calculateAvailable\\(\\) never returns void so it can be removed from the return typehint\\.$#" + count: 1 + path: LibreNMS/Modules/Mempools.php + + - + message: "#^Variable \\$lsps might not be defined\\.$#" + count: 1 + path: LibreNMS/Modules/Mpls.php + + - + message: "#^Variable \\$paths might not be defined\\.$#" + count: 2 + path: LibreNMS/Modules/Mpls.php + + - + message: "#^Variable \\$sdps might not be defined\\.$#" + count: 1 + path: LibreNMS/Modules/Mpls.php + + - + message: "#^Variable \\$svcs might not be defined\\.$#" + count: 2 + path: LibreNMS/Modules/Mpls.php + + - + message: "#^Method LibreNMS\\\\OS\\\\AirosAfLtu\\:\\:discoverWirelessDistance\\(\\) should return array but return statement is missing\\.$#" + count: 1 + path: LibreNMS/OS/AirosAfLtu.php + + - + message: "#^Parameter \\#8 \\$multiplier of class LibreNMS\\\\Device\\\\WirelessSensor constructor expects int, null given\\.$#" + count: 2 + path: LibreNMS/OS/ArrisDsr4410md.php + + - + message: "#^Parameter \\#8 \\$warn_percent of static method LibreNMS\\\\Device\\\\Processor\\:\\:discover\\(\\) expects int, null given\\.$#" + count: 1 + path: LibreNMS/OS/Comware.php + + - + message: "#^Parameter \\#8 \\$multiplier of class LibreNMS\\\\Device\\\\WirelessSensor constructor expects int, null given\\.$#" + count: 3 + path: LibreNMS/OS/HarmonyEnhanced.php + + - + message: "#^Parameter \\#16 \\$entPhysicalIndex of class LibreNMS\\\\Device\\\\WirelessSensor constructor expects float\\|int\\|null, string given\\.$#" + count: 1 + path: LibreNMS/OS/Ios.php + + - + message: "#^Method LibreNMS\\\\OS\\\\Routeros\\:\\:discoverWirelessFrequency\\(\\) should return array but return statement is missing\\.$#" + count: 1 + path: LibreNMS/OS/Routeros.php + + - + message: "#^Parameter \\#8 \\$multiplier of class LibreNMS\\\\Device\\\\WirelessSensor constructor expects int, null given\\.$#" + count: 1 + path: LibreNMS/OS/Routeros.php + + - + message: "#^Parameter \\#8 \\$warn_percent of static method LibreNMS\\\\Device\\\\Processor\\:\\:discover\\(\\) expects int, null given\\.$#" + count: 3 + path: LibreNMS/OS/Shared/Cisco.php + + - + message: "#^Variable \\$index might not be defined\\.$#" + count: 2 + path: LibreNMS/OS/SmOs.php + + - + message: "#^Offset 'sonicCurrentConnCac…' does not exist on string\\.$#" + count: 1 + path: LibreNMS/OS/Sonicwall.php + + - + message: "#^Offset 'sonicMaxConnCacheEn…' does not exist on string\\.$#" + count: 1 + path: LibreNMS/OS/Sonicwall.php + + - + message: "#^Parameter \\#8 \\$multiplier of class LibreNMS\\\\Device\\\\WirelessSensor constructor expects int, string given\\.$#" + count: 1 + path: LibreNMS/OS/Timos.php + + - + message: "#^Parameter \\#9 \\$divisor of class LibreNMS\\\\Device\\\\WirelessSensor constructor expects int, string given\\.$#" + count: 1 + path: LibreNMS/OS/Timos.php + + - + message: "#^Variable \\$mplsTunnelARHopIndex in isset\\(\\) always exists and is not nullable\\.$#" + count: 2 + path: LibreNMS/OS/Timos.php + + - + message: "#^Variable \\$mplsTunnelARHopListIndex in isset\\(\\) always exists and is not nullable\\.$#" + count: 2 + path: LibreNMS/OS/Timos.php + + - + message: "#^Variable \\$sdp_oid in isset\\(\\) always exists and is not nullable\\.$#" + count: 2 + path: LibreNMS/OS/Timos.php + + - + message: "#^Variable \\$svc_oid in isset\\(\\) always exists and is not nullable\\.$#" + count: 2 + path: LibreNMS/OS/Timos.php + + - + message: "#^Parameter \\#5 \\$reference of static method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) expects int\\|null, string given\\.$#" + count: 1 + path: LibreNMS/Snmptrap/Handlers/BgpBackwardTransition.php + + - + message: "#^Parameter \\#5 \\$reference of static method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) expects int\\|null, string given\\.$#" + count: 1 + path: LibreNMS/Snmptrap/Handlers/BgpEstablished.php + + - + message: "#^Comparison operation \"\\>\" between int\\<1001, max\\> and 1000 is always true\\.$#" + count: 1 + path: LibreNMS/Validations/Database.php + + - + message: "#^Ternary operator condition is always true\\.$#" + count: 1 + path: app/Console/LnmsCommand.php + + - + message: "#^Call to function is_null\\(\\) with PDO will always evaluate to false\\.$#" + count: 1 + path: app/Http/Controllers/Install/DatabaseController.php + + - + message: "#^Ternary operator condition is always false\\.$#" + count: 1 + path: app/Http/Controllers/LegacyController.php + + - + message: "#^Call to an undefined static method App\\\\Models\\\\ServiceTemplate\\:\\:hasAccess\\(\\)\\.$#" + count: 1 + path: app/Http/Controllers/Select/ServiceTemplateController.php + + - + message: "#^Cannot call method only\\(\\) on array\\\\.$#" + count: 1 + path: app/Http/Controllers/ServiceController.php + + - + message: "#^Ternary operator condition is always true\\.$#" + count: 2 + path: app/Listeners/AuthEventListener.php + + - + message: "#^Access to an undefined property App\\\\Models\\\\DeviceRelatedModel\\:\\:\\$device_id\\.$#" + count: 1 + path: app/Models/DeviceRelatedModel.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: app/Providers/LegacyUserProvider.php + + - + message: "#^Parameter \\#4 \\$transport of function addHost expects string, int given\\.$#" + count: 1 + path: tests/AddHostTest.php + + - + message: "#^Parameter \\#5 \\$poller_group of function addHost expects string, int given\\.$#" + count: 4 + path: tests/AddHostTest.php + + - + message: "#^Parameter \\#1 \\$username of method LibreNMS\\\\Interfaces\\\\Authentication\\\\Authorizer\\:\\:changePassword\\(\\) expects string, null given\\.$#" + count: 1 + path: tests/AuthHTTPTest.php + + - + message: "#^Parameter \\#2 \\$newpassword of method LibreNMS\\\\Interfaces\\\\Authentication\\\\Authorizer\\:\\:changePassword\\(\\) expects string, null given\\.$#" + count: 1 + path: tests/AuthHTTPTest.php + + - + message: "#^Parameter \\#1 \\$attr of method LibreNMS\\\\Authentication\\\\SSOAuthorizer\\:\\:authSSOGetAttr\\(\\) expects string, int given\\.$#" + count: 2 + path: tests/AuthSSOTest.php + + - + message: "#^Parameter \\#1 \\$attr of method LibreNMS\\\\Authentication\\\\SSOAuthorizer\\:\\:authSSOGetAttr\\(\\) expects string, null given\\.$#" + count: 2 + path: tests/AuthSSOTest.php + + - + message: "#^Parameter \\#1 \\$username of method LibreNMS\\\\Interfaces\\\\Authentication\\\\Authorizer\\:\\:changePassword\\(\\) expects string, null given\\.$#" + count: 1 + path: tests/AuthSSOTest.php + + - + message: "#^Parameter \\#2 \\$newpassword of method LibreNMS\\\\Interfaces\\\\Authentication\\\\Authorizer\\:\\:changePassword\\(\\) expects string, null given\\.$#" + count: 1 + path: tests/AuthSSOTest.php + + - + message: "#^Parameter \\#2 \\$default of function set_null expects null, int given\\.$#" + count: 2 + path: tests/CommonFunctionsTest.php + + - + message: "#^Parameter \\#1 \\$os of static method LibreNMS\\\\Config\\:\\:getOsSetting\\(\\) expects string, null given\\.$#" + count: 1 + path: tests/ConfigTest.php + + - + message: "#^Parameter \\#3 \\$default of static method LibreNMS\\\\Config\\:\\:getCombined\\(\\) expects array, false given\\.$#" + count: 2 + path: tests/ConfigTest.php + + - + message: "#^Parameter \\#3 \\$default of static method LibreNMS\\\\Config\\:\\:getCombined\\(\\) expects array, true given\\.$#" + count: 1 + path: tests/ConfigTest.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: tests/TestCase.php + + - + message: "#^Parameter \\#1 \\$new_location of method App\\\\Models\\\\Device\\:\\:setLocation\\(\\) expects App\\\\Models\\\\Location\\|string, null given\\.$#" + count: 1 + path: tests/Unit/LocationTest.php + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000000..8853fa391a --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,31 @@ +includes: + - phpstan-baseline.neon + - vendor/nunomaduro/larastan/extension.neon + - vendor/phpstan/phpstan-mockery/extension.neon + +parameters: + + paths: + - app + - config + - database + - LibreNMS + - resources + - tests + + scanDirectories: + - includes + + level: 5 + + checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false + + ignoreErrors: + - '#Unsafe usage of new static#' + + parallel: + processTimeout: 300.0 + + stubFiles: + - tests/stubs/StringBlade.stub diff --git a/tests/stubs/StringBlade.stub b/tests/stubs/StringBlade.stub new file mode 100644 index 0000000000..45abe8436a --- /dev/null +++ b/tests/stubs/StringBlade.stub @@ -0,0 +1,11 @@ +