update composer scripts, add phpmd and phpstan

This commit is contained in:
IanDelMar 2022-03-07 03:31:52 +01:00
parent 07427df9af
commit e9ff226360
7 changed files with 1824 additions and 247 deletions

View File

@ -1,6 +1,6 @@
{
"name": "understrap/understrap",
"description": "Combines Automattic´s Underscores Starter Theme and Bootstrap 4",
"description": "Combines Automattic's Underscores Starter Theme and Bootstrap",
"type": "wordpress-theme",
"license": "GPL-2.0-only",
"minimum-stability": "stable",
@ -10,21 +10,39 @@
"bootstrap"
],
"homepage": "https://github.com/understrap/understrap",
"authors": [
{
"name": "Contributors",
"homepage": "https://github.com/understrap/understrap/contributors.md"
}
],
"require": {
"composer/installers": "^1.12",
"php": ">=5.6"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
"phpmd/phpmd": "^2.11.1",
"phpstan/phpstan": "^1.4.8",
"roave/security-advisories": "dev-master",
"wp-coding-standards/wpcs": "^2.3",
"wptrt/wpthemereview": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
"php-parallel-lint/php-parallel-lint": "^1.3"
"squizlabs/php_codesniffer": "^3.6.2",
"szepeviktor/phpstan-wordpress": "^1.0.3",
"wp-coding-standards/wpcs": "^2.3.0",
"wptrt/wpthemereview": "^0.2.1"
},
"scripts": {
"check:cs": ["@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"],
"fix:cs": ["@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"],
"lint:php": ["@php ./vendor/bin/parallel-lint --exclude .git --exclude vendor --exclude dist ."]
"php-lint": "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint --exclude vendor --exclude dist --exclude node_modules --exclude .git .",
"phpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs -p",
"phpcs-ga": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs -n --report=checkstyle",
"phpcs-fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf",
"phpcs-config-set" : "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths ../../phpcompatibility/php-compatibility,../../phpcompatibility/phpcompatibility-paragonie,../../phpcompatibility/phpcompatibility-wp,../../wp-coding-standards/wpcs,../../wptrt/wpthemereview",
"phpmd": "@php ./vendor/phpmd/phpmd/src/bin/phpmd . ansi phpmd.xml --exclude vendor,src,node_modules,languages,js,fonts,css,.github,.git,class-wp-bootstrap-navwalker.php,inc/deprecated.php",
"phpmd-baseline": "@phpmd -- --generate-baseline",
"phpmd-ga": "@php ./vendor/phpmd/phpmd/src/bin/phpmd . github phpmd.xml --exclude vendor,src,node_modules,languages,js,fonts,css,.github,.git,class-wp-bootstrap-navwalker.php,inc/deprecated.php",
"phpstan": "@php ./vendor/phpstan/phpstan/phpstan analyse",
"phpstan-baseline": "@php ./vendor/phpstan/phpstan/phpstan analyse --generate-baseline",
"post-install-cmd": "@phpcs-config-set",
"post-update-cmd": "@phpcs-config-set"
},
"support": {
"issues": "https://github.com/understrap/understrap/issues",

1644
composer.lock generated

File diff suppressed because it is too large Load Diff

7
phpmd.baseline.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<phpmd-baseline>
<violation rule="PHPMD\Rule\Design\LongMethod" file="inc/customizer.php"/>
<violation rule="PHPMD\Rule\Naming\LongVariable" file="inc/deprecated.php"/>
<violation rule="PHPMD\Rule\Naming\LongVariable" file="inc/widgets.php"/>
<violation rule="PHPMD\Rule\UnusedFormalParameter" file="inc/woocommerce.php"/>
</phpmd-baseline>

53
phpmd.xml Normal file
View File

@ -0,0 +1,53 @@
<?xml version="1.0"?>
<ruleset name="PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
PHPMD rule set for Understrap
</description>
<!-- Import the entire codesize rule set -->
<rule ref="rulesets/codesize.xml">
<exclude name="ExcessiveMethodLength" />
<exclude name="ExcessiveParameterList" />
</rule>
<!-- Do not import the controversial rule set -->
<!-- <rule ref="rulesets/controversial.xml" /> -->
<!-- Import the entire design rule set -->
<rule ref="rulesets/design.xml" />
<!-- Import entire naming rule set and exclude rules -->
<rule ref="rulesets/naming.xml" />
<!-- Import the entire unused code rule set -->
<rule ref="rulesets/unusedcode.xml">
<exclude name="UnusedLocalVariable" />
</rule>
<!-- Some customizations. -->
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
<properties>
<property name="ignore-whitespace" value="true"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
<properties>
<property name="minimum" value="4"/>
</properties>
</rule>
<!-- Allow unused variables in foreach statement -->
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable">
<properties>
<property name="allow-unused-foreach-variables" value="true" />
</properties>
</rule>
</ruleset>

267
phpstan-baseline.neon Normal file
View File

@ -0,0 +1,267 @@
parameters:
ignoreErrors:
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: inc/block-editor.php
-
message: "#^Function understrap_generate_color_palette\\(\\) never returns bool so it can be removed from the return type\\.$#"
count: 1
path: inc/block-editor.php
-
message: "#^Function understrap_generate_color_palette\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/block-editor.php
-
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, mixed given\\.$#"
count: 1
path: inc/block-editor.php
-
message: "#^Function understrap_bootstrap_comment_form_fields\\(\\) has parameter \\$fields with no value type specified in iterable type array\\.$#"
count: 1
path: inc/custom-comments.php
-
message: "#^Function understrap_bootstrap_comment_form_fields\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/custom-comments.php
-
message: "#^Parameter \\#1 \\$post_type of function post_type_supports expects string, string\\|false given\\.$#"
count: 1
path: inc/custom-comments.php
-
message: "#^Call to an undefined method object\\:\\:get_setting\\(\\)\\.$#"
count: 3
path: inc/customizer.php
-
message: "#^Cannot access property \\$choices on void\\|WP_Customize_Control\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Inner named functions are not supported by PHPStan\\. Consider refactoring to an anonymous function, class method, or a top\\-level\\-defined function\\. See issue \\#165 \\(https\\://github\\.com/phpstan/phpstan/issues/165\\) for more details\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Parameter \\#3 \\$args of class WP_Customize_Control constructor expects array\\{instance_number\\?\\: int, manager\\?\\: WP_Customize_Manager, id\\?\\: string, settings\\?\\: array, setting\\?\\: string, capability\\?\\: string, priority\\?\\: int, section\\?\\: string, \\.\\.\\.\\}, array\\{label\\: string, description\\: string, section\\: 'understrap_theme…', settings\\: 'understrap_navbar…', type\\: 'select', sanitize_callback\\: 'understrap_theme…', choices\\: array\\{collapse\\: string, offcanvas\\: string\\}, priority\\: mixed\\} given\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Parameter \\#3 \\$args of class WP_Customize_Control constructor expects array\\{instance_number\\?\\: int, manager\\?\\: WP_Customize_Manager, id\\?\\: string, settings\\?\\: array, setting\\?\\: string, capability\\?\\: string, priority\\?\\: int, section\\?\\: string, \\.\\.\\.\\}, array\\{label\\: string, description\\: string, section\\: 'understrap_theme…', settings\\: 'understrap_sidebar…', type\\: 'select', sanitize_callback\\: 'understrap_theme…', choices\\: array\\{right\\: string, left\\: string, both\\: string, none\\: string\\}, priority\\: mixed\\} given\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Parameter \\#3 \\$args of class WP_Customize_Control constructor expects array\\{instance_number\\?\\: int, manager\\?\\: WP_Customize_Manager, id\\?\\: string, settings\\?\\: array, setting\\?\\: string, capability\\?\\: string, priority\\?\\: int, section\\?\\: string, \\.\\.\\.\\}, array\\{label\\: string, description\\: string, section\\: 'understrap_theme…', settings\\: 'understrap_site…', type\\: 'textarea', priority\\: 20\\} given\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Parameter \\#3 \\$args of class WP_Customize_Control constructor expects array\\{instance_number\\?\\: int, manager\\?\\: WP_Customize_Manager, id\\?\\: string, settings\\?\\: array, setting\\?\\: string, capability\\?\\: string, priority\\?\\: int, section\\?\\: string, \\.\\.\\.\\}, array\\{label\\: string, description\\: string, section\\: 'understrap_theme…', settings\\: 'understrap…', type\\: 'select', choices\\: array\\{bootstrap4\\: string, bootstrap5\\: string\\}, priority\\: mixed\\} given\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Parameter \\#3 \\$args of class WP_Customize_Control constructor expects array\\{instance_number\\?\\: int, manager\\?\\: WP_Customize_Manager, id\\?\\: string, settings\\?\\: array, setting\\?\\: string, capability\\?\\: string, priority\\?\\: int, section\\?\\: string, \\.\\.\\.\\}, array\\{label\\: string, description\\: string, section\\: 'understrap_theme…', settings\\: 'understrap…', type\\: 'select', choices\\: array\\{container\\: string, container\\-fluid\\: string\\}, priority\\: mixed\\} given\\.$#"
count: 1
path: inc/customizer.php
-
message: "#^Function understrap_tiny_mce_before_init\\(\\) has parameter \\$settings with no value type specified in iterable type array\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Function understrap_tiny_mce_before_init\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Function understrap_tiny_mce_blockquote_button\\(\\) has parameter \\$buttons with no value type specified in iterable type array\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Function understrap_tiny_mce_blockquote_button\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Function understrap_tiny_mce_style_formats\\(\\) has parameter \\$buttons with no value type specified in iterable type array\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Function understrap_tiny_mce_style_formats\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Parameter \\#1 \\$arr1 of function array_merge expects array, mixed given\\.$#"
count: 1
path: inc/editor.php
-
message: "#^Binary operation \"\\.\" between array\\|string\\|false and '\\.' results in an error\\.$#"
count: 2
path: inc/enqueue.php
-
message: "#^Function understrap_body_classes\\(\\) has parameter \\$classes with no value type specified in iterable type array\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Function understrap_body_classes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Function understrap_default_body_attributes\\(\\) has parameter \\$atts with no value type specified in iterable type array\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Function understrap_default_body_attributes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Parameter \\#1 \\$post of function get_permalink expects int\\|WP_Post, int\\|false given\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Parameter \\#1 \\$post of function get_the_title expects int\\|WP_Post, int\\|false given\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Parameter \\#1 \\$url of function esc_url expects string, string\\|false given\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Parameter \\#2 \\$callback of function add_filter expects callable\\(\\)\\: mixed, 'understrap_adjust…' given\\.$#"
count: 1
path: inc/extras.php
-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, array\\|string\\|false given\\.$#"
count: 2
path: inc/hooks.php
-
message: "#^Parameter \\#2 \\$name of function get_template_part expects string\\|null, string\\|false given\\.$#"
count: 1
path: inc/jetpack.php
-
message: "#^Argument of an invalid type array\\|string\\|void supplied for foreach, only iterables are supported\\.$#"
count: 1
path: inc/pagination.php
-
message: "#^Cannot assign offset 'total' to array\\|string\\.$#"
count: 1
path: inc/pagination.php
-
message: "#^Function understrap_pagination\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: inc/pagination.php
-
message: "#^Cannot access property \\$post_parent on WP_Post\\|null\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$author_id of function get_author_posts_url expects int, string given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, int\\|string\\|false given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, string\\|false given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$text of function esc_html expects string, int\\|string\\|false given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$text of function esc_html expects string, string\\|false given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$text of function esc_html expects string, string\\|null given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#1 \\$url of function esc_url expects string, string\\|false given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function printf expects bool\\|float\\|int\\|string\\|null, string\\|WP_Error given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, string\\|void given\\.$#"
count: 1
path: inc/template-tags.php
-
message: "#^Function understrap_get_theme_default_settings\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/theme-settings.php
-
message: "#^Function understrap_widget_classes\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: inc/widgets.php
-
message: "#^Function understrap_widget_classes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/widgets.php
-
message: "#^Function understrap_quantity_input_classes\\(\\) has parameter \\$classes with no value type specified in iterable type array\\.$#"
count: 1
path: inc/woocommerce.php
-
message: "#^Function understrap_quantity_input_classes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/woocommerce.php
-
message: "#^Offset 'type' does not exist on string\\.$#"
count: 1
path: inc/woocommerce.php
-
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, mixed given\\.$#"
count: 1
path: inc/woocommerce.php

46
phpstan.neon.dist Normal file
View File

@ -0,0 +1,46 @@
#$ vendor/bin/phpstan analyze
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/szepeviktor/phpstan-wordpress/extension.neon
- phpstan.baseline.neon
parameters:
level: max
paths:
- inc/
excludePaths:
- inc/deprecated.php
- inc/class-wp-bootstrap-navwalker.php
ignoreErrors:
- '#Function understrap_block_editor_setup\(\) has no return type specified.#'
- '#Function understrap_custom_header_setup\(\) has no return type specified.#'
- '#Function understrap_comment_form_comments_closed\(\) has no return type specified.#'
- '#Function understrap_customize_register\(\) has no return type specified.#'
- '#Function understrap_theme_customize_register\(\) has no return type specified.#'
- '#Function understrap_customize_preview_js\(\) has no return type specified.#'
- '#Function understrap_customize_controls_js\(\) has no return type specified.#'
- '#Function understrap_wpdocs_theme_add_editor_styles\(\) has no return type specified.#'
- '#Function understrap_scripts\(\) has no return type specified.#'
- '#Function understrap_pingback\(\) has no return type specified.#'
- '#Function understrap_mobile_web_app_meta\(\) has no return type specified.#'
- '#Function understrap_add_site_info\(\) has no return type specified.#'
- '#Function understrap_site_info\(\) has no return type specified.#'
- '#Function understrap_components_jetpack_setup\(\) has no return type specified.#'
- '#Function understrap_components_infinite_scroll_render\(\) has no return type specified.#'
- '#Function understrap_components_social_menu\(\) has no return type specified.#'
- '#Function understrap_pagination\(\) has no return type specified.#'
- '#Function understrap_setup\(\) has no return type specified.#'
- '#Function understrap_posted_on\(\) has no return type specified.#'
- '#Function understrap_entry_footer\(\) has no return type specified.#'
- '#Function understrap_category_transient_flusher\(\) has no return type specified.#'
- '#Function understrap_body_attributes\(\) has no return type specified.#'
- '#Function understrap_comment_navigation\(\) has no return type specified.#'
- '#Function understrap_edit_post_link\(\) has no return type specified.#'
- '#Function understrap_post_nav\(\) has no return type specified.#'
- '#Function understrap_setup_theme_default_settings\(\) has no return type specified.#'
- '#Function understrap_widgets_init\(\) has no return type specified.#'
- '#Function understrap_woocommerce_support\(\) has no return type specified.#'
- '#Function understrap_woocommerce_wrapper_start\(\) has no return type specified.#'
- '#Function understrap_woocommerce_wrapper_end\(\) has no return type specified.#'
- '#Function understrap_wpcom_setup\(\) has no return type specified.#'
- '#Function understrap_wpcom_styles\(\) has no return type specified.#'

View File

@ -4,26 +4,26 @@ const pkg = require( '../../package.json' );
async function copyDir( src, dest ) {
await fs.mkdir( dest, { recursive: true } );
const entries = await fs.readdir( src, { withFileTypes: true } );
let entries = await fs.readdir( src, { withFileTypes: true } );
// Exclude all dot files and directories.
entries = entries.filter( dirent => ! dirent.name.startsWith('.') );
const ignore = [
'node_modules',
'dist',
'node_modules',
'src',
'vendor',
'.github',
'.browserslistrc',
'.editorconfig',
'.gitattributes',
'.gitignore',
'composer.json',
'composer.lock',
'package.json',
'package-lock.json',
'phpcs.xml.dist',
'.git',
'phpmd.baseline.xml',
'phpmd.xml',
'phpstan-baseline.neon',
'phpstan.neon.dist',
];
for ( let entry of entries ) {
for ( const entry of entries ) {
if ( ignore.indexOf( entry.name ) != -1 ) {
continue;
}