🏡 index : ~doyle/koselig.git

author Jordan Doyle <jordan@doyle.wf> 2016-10-28 0:08:14.0 +00:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-10-28 0:08:14.0 +00:00:00
commit
2bf24d12a22a48f872738aa703146fc629c07995 [patch]
tree
8b8f8010b4b165a3332ffa80a6d081e7ca9d4438
parent
efb111d0a6b7a2cc03e94166b6826ba5821be328
download
2bf24d12a22a48f872738aa703146fc629c07995.tar.gz

Code cleanup to stop phpmd emitting warnings



Diff

 src/Models/Post.php                        | 26 +++++++++++++-------------
 src/Providers/WordpressServiceProvider.php |  8 ++++++--
 src/Proxy/WordpressDatabase.php            | 23 ++++++++++++-----------
 3 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/src/Models/Post.php b/src/Models/Post.php
index 61e3838..2ffd0b9 100644
--- a/src/Models/Post.php
+++ b/src/Models/Post.php
@@ -216,19 +216,19 @@ class Post extends Model
        })->get();
    }

     /**
      * Retrieves the navigation to next/previous post, when applicable.
      *
      * @see get_the_post_navigation()
      *
      * @param array $args
      *
      * @return string
      */
     public static function navigation($args = [])
     {
         return get_the_post_navigation($args);
     }
    /**
     * Retrieves the navigation to next/previous post, when applicable.
     *
     * @see get_the_post_navigation()
     *
     * @param array $args
     *
     * @return string
     */
    public static function navigation($args = [])
    {
        return get_the_post_navigation($args);
    }

    /**
     * Get the permalink for this post.
diff --git a/src/Providers/WordpressServiceProvider.php b/src/Providers/WordpressServiceProvider.php
index ae04a45..a4ac00d 100644
--- a/src/Providers/WordpressServiceProvider.php
+++ b/src/Providers/WordpressServiceProvider.php
@@ -5,6 +5,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Koselig\Support\Action;
use Koselig\Support\Wordpress;
use Request;

/**
 * Service provider for everything Wordpress, configures
@@ -37,6 +38,8 @@ class WordpressServiceProvider extends ServiceProvider
    /**
     * Bootstrap any application services.
     *
     * @SuppressWarnings(PHPMD.CamelCaseVariableName)
     *
     * @return void
     */
    public function boot()
@@ -51,7 +54,8 @@ class WordpressServiceProvider extends ServiceProvider
        // Set up the WordPress query.
        wp();

        if (defined('WP_ADMIN') || str_contains($_SERVER['SCRIPT_NAME'], strrchr(wp_login_url(), '/'))) {
        if (!$this->app->runningInConsole()
            && (defined('WP_ADMIN') || str_contains(Request::server('SCRIPT_NAME'), strrchr(wp_login_url(), '/')))) {
            // disable query caching when in Wordpress admin
            config(['wordpress.caching' => 0]);
        }
@@ -103,7 +107,6 @@ class WordpressServiceProvider extends ServiceProvider
     * Set up the configuration values that wp-config.php
     * does. Use all the values out of .env instead.
     *
     * @SuppressWarnings(PHPMD.CamelCaseVariableName)
     * @SuppressWarnings(PHPMD.Superglobals)
     *
     * @return void
@@ -121,6 +124,7 @@ class WordpressServiceProvider extends ServiceProvider

        if ($this->app->runningInConsole()) {
            // allow wordpress to run, even when running from console (ie. artisan compiling)
            Request::server()
            $_SERVER['SERVER_PROTOCOL'] = 'https';
            $_SERVER['HTTP_HOST'] = parse_url(config('app.url'))['host'];
        }
diff --git a/src/Proxy/WordpressDatabase.php b/src/Proxy/WordpressDatabase.php
index cbc108c..4600467 100644
--- a/src/Proxy/WordpressDatabase.php
+++ b/src/Proxy/WordpressDatabase.php
@@ -10,6 +10,7 @@ use wpdb;
 * Replace Wordpress' database calls to Laravel's database abstraction
 * to hold a single database connection, and for easier query debugging.
 *
 * @SuppressWarnings(PHPMD.CamelCaseMethodName)
 * @author Jordan Doyle <jordan@doyle.wf>
 */
class WordpressDatabase extends wpdb
@@ -39,11 +40,11 @@ class WordpressDatabase extends wpdb
     * Laravel handles all the connection handling for us including reconnecting
     * so we'll just pretend we're always connected to whatever is calling us.
     *
     * @param bool $allow_bail
     * @param bool $allowBail
     *
     * @return bool
     */
    public function check_connection($allow_bail = true)
    public function check_connection($allowBail = true)
    {
        return true;
    }
@@ -56,7 +57,7 @@ class WordpressDatabase extends wpdb
     *
     * @return void
     */
    public function db_connect($allow_bail = true)
    public function db_connect($allowBail = true)
    {
        $this->is_mysql = true;
        $this->has_connected = true;
@@ -105,10 +106,10 @@ class WordpressDatabase extends wpdb
         *
         * @param array $incompatible_modes An array of incompatible modes.
         */
        $incompatible_modes = (array) apply_filters('incompatible_sql_modes', $this->incompatible_modes);
        $incompatibleModes = (array) apply_filters('incompatible_sql_modes', $this->incompatible_modes);

        foreach ($modes as $i => $mode) {
            if (in_array($mode, $incompatible_modes, true)) {
            if (in_array($mode, $incompatibleModes, true)) {
                unset($modes[$i]);
            }
        }
@@ -168,11 +169,11 @@ class WordpressDatabase extends wpdb

        // If we're writing to the database, make sure the query will write safely.
        if ($this->check_current_query && !$this->check_ascii($query)) {
            $stripped_query = $this->strip_invalid_text_from_query($query);
            $strippedQuery = $this->strip_invalid_text_from_query($query);
            // strip_invalid_text_from_query() can perform queries, so we need
            // to flush again, just to make sure everything is clear.
            $this->flush();
            if ($stripped_query !== $query) {
            if ($strippedQuery !== $query) {
                $this->insert_id = 0;

                return false;
@@ -200,17 +201,17 @@ class WordpressDatabase extends wpdb
        }

        if (preg_match('/^\s*(create|alter|truncate|drop)\s/i', $query)) {
            $return_val = $this->result;
            $return = $this->result;
        } elseif (preg_match('/^\s*(insert|delete|update|replace)\s/i', $query)) {
            $this->rows_affected = $return_val = $this->result;
            $this->rows_affected = $return = $this->result;
        } else {
            // Log number of rows the query returned
            // and return number of rows selected
            $this->num_rows = count($this->result);
            $return_val = $this->result;
            $return = $this->result;
        }

        return $return_val;
        return $return;
    }

    /**