Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
23 changes: 23 additions & 0 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ jobs:
- name: Run code quality checks (on pull request)
if: github.event_name == 'pull_request'
run: ./.github/workflows/utilities/phpcs-pr ${{ github.base_ref }}
staticAnalysis:
runs-on: ubuntu-latest
name: PHPStan
steps:
- name: Checkout changes
uses: actions/checkout@v2
Comment thread
austinderrick marked this conversation as resolved.
Outdated

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: curl, fileinfo, gd, mbstring, openssl, pdo, pdo_sqlite, sqlite3, xml, zip

- name: Install Composer dependencies
run: composer install --no-interaction --no-progress --no-scripts

- name: Reset modules
run: |
git reset --hard
git clean -fd

- name: Run static analysis
run: vendor/bin/phpstan analyse --no-progress
Comment thread
austinderrick marked this conversation as resolved.
Outdated
codeQualityJS:
runs-on: ubuntu-latest
name: JavaScript
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"fakerphp/faker": "^1.9.2",
"squizlabs/php_codesniffer": "^3.2",
"php-parallel-lint/php-parallel-lint": "^1.0",
"dms/phpunit-arraysubset-asserts": "dev-add-phpunit-11-support"
"dms/phpunit-arraysubset-asserts": "dev-add-phpunit-11-support",
"larastan/larastan": "^3.6"
},
"repositories": [
{
Expand Down
5 changes: 5 additions & 0 deletions modules/backend/classes/FilterScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class FilterScope
*/
public $dependsOn;

/**
* @var mixed Default value for this filter scope.
*/
public $default;

/**
* @var string Specifies contextual visibility of this form scope.
*/
Expand Down
4 changes: 2 additions & 2 deletions modules/backend/classes/FormTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function getAllFields()
/**
* Returns an icon for the tab based on the tab's name.
* @param string $name
* @return string
* @return string|null
*/
public function getIcon($name)
{
Expand All @@ -216,7 +216,7 @@ public function getIcon($name)
* Returns a tab pane CSS class.
* @param string $index
* @param string $label
* @return string
* @return string|null
*/
public function getPaneCssClass($index = null, $label = null)
{
Expand Down
2 changes: 1 addition & 1 deletion modules/backend/classes/WidgetBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function init()

/**
* Renders the widget's primary contents.
* @return string HTML markup supplied by this widget.
* @return string|null HTML markup supplied by this widget, or null when the widget renders nothing.
*/
public function render()
{
Expand Down
2 changes: 1 addition & 1 deletion modules/cms/classes/CmsObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function inTheme($theme)
* Save the object to the theme.
*
* @param array $options
* @return bool
* @return void
*/
public function save(?array $options = null)
{
Expand Down
4 changes: 2 additions & 2 deletions modules/cms/classes/ComponentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function loadComponents()
* });
*
* @param callable $definitions
* @return array Array values are class names.
* @return void
*/
public function registerComponents(callable $definitions)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ public function hasComponent($name)
* @param array $properties The properties set by the Page or Layout.
* @param bool $isSoftComponent Defines if this is a soft component.
*
* @return ComponentBase The component object.
* @return ComponentBase|null The component object, or null for an unresolvable soft component.
* @throws SystemException If the (hard) component cannot be found or is not registered.
*/
public function makeComponent($name, $cmsObject = null, $properties = [], $isSoftComponent = false)
Expand Down
4 changes: 2 additions & 2 deletions modules/cms/classes/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(Theme $theme)
/**
* Finds a page by its URL. Returns the page object and sets the $parameters property.
* @param string $url The requested URL string.
* @return \Cms\Classes\Page Returns \Cms\Classes\Page object or null if the page cannot be found.
* @return \Cms\Classes\Page|null Returns \Cms\Classes\Page object or null if the page cannot be found.
*/
public function findByUrl($url)
{
Expand Down Expand Up @@ -275,7 +275,7 @@ public function clearCache()
/**
* Sets the current routing parameters.
* @param array $parameters
* @return array
* @return void
*/
public function setParameters(array $parameters)
{
Expand Down
2 changes: 1 addition & 1 deletion modules/cms/models/ThemeExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ThemeExport extends Model
*/
public function save(?array $options = null, $sessionKey = null)
{
throw new ApplicationException(sprintf("The % model is not intended to be saved, please use %s instead", get_class($this), 'ThemeData'));
throw new ApplicationException(sprintf("The %s model is not intended to be saved, please use %s instead", get_class($this), 'ThemeData'));
}

public function getFoldersOptions()
Expand Down
2 changes: 1 addition & 1 deletion modules/cms/models/ThemeImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ThemeImport extends Model
*/
public function save(?array $options = null, $sessionKey = null)
{
throw new ApplicationException(sprintf("The % model is not intended to be saved, please use %s instead", get_class($this), 'ThemeData'));
throw new ApplicationException(sprintf("The %s model is not intended to be saved, please use %s instead", get_class($this), 'ThemeData'));
}

public function getFoldersOptions()
Expand Down
2 changes: 1 addition & 1 deletion modules/system/classes/CombineAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ protected function setHashOnCombinerFilters($hash)
/**
* Returns a deep hash on filters that support it.
* @param array $assets List of asset files.
* @return void
* @return string
*/
protected function getDeepHashFromAssets($assets)
{
Expand Down
8 changes: 4 additions & 4 deletions modules/system/classes/PluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function registerComponents()
/**
* Registers back-end navigation items for this plugin.
*
* @return array
* @return array|null
*/
public function registerNavigation()
{
Expand All @@ -141,7 +141,7 @@ public function registerNavigation()
/**
* Registers back-end quick actions for this plugin.
*
* @return array
* @return array|null
*/
public function registerQuickActions()
{
Expand All @@ -164,7 +164,7 @@ public function registerQuickActions()
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
* @return array|null
*/
public function registerPermissions()
{
Expand All @@ -177,7 +177,7 @@ public function registerPermissions()
/**
* Registers any back-end configuration links used by this plugin.
*
* @return array
* @return array|null
*/
public function registerSettings()
{
Expand Down
6 changes: 3 additions & 3 deletions modules/system/classes/UpdateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public function rollbackPlugin(string $name, ?string $stopOnVersion = null)
* @param string $name Plugin name.
* @param string $hash Expected file hash.
* @param boolean $installation Indicates whether this is a plugin installation request.
* @return self
* @return void
*/
public function downloadPlugin($name, $hash, $installation = false)
{
Expand Down Expand Up @@ -699,7 +699,7 @@ public function requestThemeDetails($name)
* Downloads a theme from the update server.
* @param string $name Theme name.
* @param string $hash Expected file hash.
* @return self
* @return void
*/
public function downloadTheme($name, $hash)
{
Expand Down Expand Up @@ -896,7 +896,7 @@ public function requestChangelog()
protected function write($component, ...$arguments)
{
if ($this->notesOutput !== null) {
with(new $component($this->notesOutput))->render(...$arguments);
(new $component($this->notesOutput))->render(...$arguments);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion modules/system/classes/VersionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ protected function hasDatabaseHistory($code, $version, $script = null)
protected function write($component, ...$arguments)
{
if ($this->notesOutput !== null) {
with(new $component($this->notesOutput))->render(...$arguments);
(new $component($this->notesOutput))->render(...$arguments);
}

return $this;
Expand Down
73 changes: 73 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
parameters:
Comment thread
austinderrick marked this conversation as resolved.
Outdated
ignoreErrors:
-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 1
path: modules/backend/classes/MainMenuItem.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 1
path: modules/backend/classes/QuickActionItem.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 1
path: modules/backend/classes/SideMenuItem.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 2
path: modules/cms/classes/Asset.php

-
message: '#^Result of method Cms\\Classes\\CodeParser\:\:handleCorruptCache\(\) \(void\) is used\.$#'
identifier: method.void
count: 1
path: modules/cms/classes/CodeParser.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 2
path: modules/cms/classes/ComponentPartial.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 1
path: modules/cms/classes/Controller.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 3
path: modules/system/classes/ImageResizer.php

-
message: '#^Call to an undefined method System\\Classes\\Asset\\BundleManager\:\:argument\(\)\.$#'
identifier: method.notFound
count: 2
path: modules/system/classes/asset/BundleManager.php

-
message: '#^Call to an undefined method System\\Classes\\Asset\\BundleManager\:\:getFixture\(\)\.$#'
identifier: method.notFound
count: 7
path: modules/system/classes/asset/BundleManager.php

-
message: '#^Call to an undefined method System\\Classes\\Asset\\BundleManager\:\:option\(\)\.$#'
identifier: method.notFound
count: 1
path: modules/system/classes/asset/BundleManager.php

-
message: '#^Call to an undefined method System\\Classes\\Asset\\BundleManager\:\:writeFile\(\)\.$#'
identifier: method.notFound
count: 4
path: modules/system/classes/asset/BundleManager.php
37 changes: 37 additions & 0 deletions phpstan-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* Analysis bootstrap for PHPStan.
*
* Two things need registering that a plain composer autoload does not provide:
*
* - The modules follow Winter's class loader convention (StudlyCase namespaces over lowercase
* directories) rather than composer PSR-4, so a matching autoloader is registered here. PHPStan
* only needs it to load classes referenced indirectly, such as alias targets; the module code
* itself is discovered through the scanDirectories setting.
* - Winter registers global class aliases (Model, BackendAuth, and friends) while the application
* boots, and module code references the aliases directly. The same alias map is registered here.
*/
require __DIR__ . '/vendor/autoload.php';

spl_autoload_register(function (string $class): void {
foreach (['System' => 'system', 'Backend' => 'backend', 'Cms' => 'cms'] as $prefix => $directory) {
if (str_starts_with($class, $prefix . '\\')) {
$parts = explode('\\', substr($class, strlen($prefix) + 1));
$file = array_pop($parts) . '.php';
$path = __DIR__ . '/modules/' . $directory
. '/' . strtolower(implode('/', $parts))
. ($parts === [] ? '' : '/') . $file;

if (is_file($path)) {
require_once $path;
}

return;
}
}
});
Comment thread
austinderrick marked this conversation as resolved.
Outdated

Illuminate\Foundation\AliasLoader::getInstance(
require __DIR__ . '/modules/system/aliases.php'
)->register();
19 changes: 19 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
includes:
- vendor/larastan/larastan/extension.neon
- phpstan-baseline.neon

parameters:
paths:
- modules/system/classes
- modules/system/models
- modules/backend/classes
- modules/backend/models
- modules/cms/classes
- modules/cms/models
level: 0
bootstrapFiles:
- phpstan-bootstrap.php
scanDirectories:
- modules
treatPhpDocTypesAsCertain: false
disableSchemaScan: true
Loading