Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Fixing problems discovered by static analysis #219

Open
szepeviktor opened this issue Jul 25, 2019 · 0 comments
Open

Fixing problems discovered by static analysis #219

szepeviktor opened this issue Jul 25, 2019 · 0 comments
Labels
Milestone

Comments

@szepeviktor
Copy link

szepeviktor commented Jul 25, 2019

@justintadlock Are you interested?

This is only on Level 0 vendor/bin/phpstan analyze -l 0

diff --git a/admin/class-settings.php b/admin/class-settings.php
index 82838d0..f26084f 100644
--- a/admin/class-settings.php
+++ b/admin/class-settings.php
@@ -132,7 +132,7 @@ final class Settings_Page {
        public function unregister_view( $name ) {

                if ( $this->view_exists( $name ) )
-                       unset( $this->view[ $name ] );
+                       unset( $this->views[ $name ] );
        }

        /**
diff --git a/composer.json b/composer.json
index 2b1c001..99f0e7e 100644
--- a/composer.json
+++ b/composer.json
@@ -16,6 +16,17 @@
                "composer/installers" : "^1.0",
                "php"                 : ">=5.3.0"
        },
+    "require-dev": {
+        "phpstan/phpstan-shim": "^0.11.5",
+        "szepeviktor/phpstan-wordpress": "^0.1.0"
+    },
+    "config": {
+        "optimize-autoloader": true
+    },
+    "scripts": {
+        "post-install-cmd": "PHPStan\\WordPress\\Composer\\FixWpStubs::php73Polyfill",
+        "post-update-cmd": "PHPStan\\WordPress\\Composer\\FixWpStubs::php73Polyfill"
+    },
        "support"     : {
                "issues": "https://github.com/justintadlock/members/issues",
                "forum" : "https://themehybrid.com/board/topics"
diff --git a/inc/template.php b/inc/template.php
index 29df3fe..8b0caf1 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -68,7 +68,7 @@ function members_can_user_view_post( $user_id, $post_id = '' ) {
                        }

                        // If the post author, the current user can edit the post, or the current user can 'restrict_content', return true.
-                       elseif ( $post->post_author == $user_id || user_can( $user_id, 'restrict_content' ) || user_can( $user_id, $post_type->cap->edit_post, $post_id ) ) {
+                       elseif ( $post->post_author == $user_id || user_can( $user_id, 'restrict_content' ) || user_can( $user_id, $post_type->cap->edit_post ) ) {
                                $can_view = true;
                        }

diff --git a/members.php b/members.php
index 50fd99b..5ba7df3 100644
--- a/members.php
+++ b/members.php
@@ -315,7 +315,7 @@ final class Members_Plugin {
         *
         * @since  2.0.1
         * @access private
-        * @return void
+        * @return string
         */
        private function get_min_php_message() {

phpstan.neon.dist

# Start command: vendor/bin/phpstan analyze

includes:
    - phar://phpstan.phar/conf/bleedingEdge.neon
    - vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
    level: max
    inferPrivatePropertyTypeFromConstructor: true
    paths:
        - %currentWorkingDirectory%/members.php
        - %currentWorkingDirectory%/inc/
        - %currentWorkingDirectory%/admin/
    autoload_files:
        # Stubs
        - %currentWorkingDirectory%/tests/bootstrap.php
        # Main file
        - %currentWorkingDirectory%/members.php
        # Functions
        - %currentWorkingDirectory%/inc/functions-admin-bar.php
        - %currentWorkingDirectory%/inc/functions-cap-groups.php
        - %currentWorkingDirectory%/inc/functions-deprecated.php
        - %currentWorkingDirectory%/inc/functions-shortcodes.php
        - %currentWorkingDirectory%/inc/functions.php
        - %currentWorkingDirectory%/inc/functions-users.php
        - %currentWorkingDirectory%/inc/functions-options.php
        - %currentWorkingDirectory%/inc/functions-content-permissions.php
        - %currentWorkingDirectory%/inc/functions-capabilities.php
        - %currentWorkingDirectory%/inc/functions-roles.php
        - %currentWorkingDirectory%/inc/functions-private-site.php
        - %currentWorkingDirectory%/inc/functions-widgets.php
        - %currentWorkingDirectory%/inc/functions-role-groups.php
        - %currentWorkingDirectory%/admin/functions-admin.php
        - %currentWorkingDirectory%/admin/functions-settings.php
        - %currentWorkingDirectory%/admin/functions-addons.php
        - %currentWorkingDirectory%/admin/functions-help.php
    autoload_directories:
        - %currentWorkingDirectory%/inc/
        - %currentWorkingDirectory%/admin/
    ignoreErrors:
        # Uses func_get_args()
        - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#'
        - '#^Function do_action invoked with [3456] parameters, 1-2 required\.$#'
        - '#^Function current_user_can invoked with 2 parameters, 1 required\.$#'
        - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#'

tests/bootstrap.php

<?php

$GLOBALS['wp_embed'] = '';

function bp_is_current_component( $p1 ) { return ''; }
@szepeviktor szepeviktor changed the title Fixing problem discovered by static analysis Fixing problems discovered by static analysis Jul 25, 2019
@justintadlock justintadlock added this to the 3.0.0 milestone Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants