Issues (53)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

wp-to-diaspora.php (10 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 36 and the first side effect is on line 33.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Plugin Name: WP to diaspora*
4
 * Plugin URI:  https://github.com/gutobenn/wp-to-diaspora
5
 * Description: Automatically shares WordPress posts on diaspora*
6
 * Version:     1.7.2
7
 * Author:      Augusto Bennemann
8
 * Author URI:  https://github.com/gutobenn
9
 * Text Domain: wp-to-diaspora
10
 * Domain Path: /languages
11
 *
12
 * Copyright 2014-2015 Augusto Bennemann (email: gutobenn at gmail.com)
13
 *
14
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
15
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
16
 * or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
19
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
 *
21
 * You should have received a copy of the GNU General Public License along with this program; if not, write
22
 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
 *
24
 * @package   WP_To_Diaspora
25
 * @version   1.7.2
26
 * @author    Augusto Bennemann <[email protected]>
27
 * @copyright Copyright (c) 2015, Augusto Bennemann
28
 * @link      https://github.com/gutobenn/wp-to-diaspora
29
 * @license   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
30
 */
31
32
// Exit if accessed directly.
33
defined( 'ABSPATH' ) || exit;
34
35
// Set the current version.
36
define( 'WP2D_VERSION', '1.7.2' );
37
38
/**
39
 * WP to diaspora* main plugin class.
40
 */
41
class WP_To_Diaspora {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
42
43
	/**
44
	 * Only instance of this class.
45
	 *
46
	 * @var WP_To_Diaspora
47
	 */
48
	private static $_instance = null;
49
50
	/**
51
	 * The minimum required WordPress version.
52
	 *
53
	 * @since 1.5.4
54
	 *
55
	 * @var string
56
	 */
57
	private $_min_wp = '3.9.2';
58
59
	/**
60
	 * The minimum required PHP version.
61
	 *
62
	 * @since 1.5.4
63
	 *
64
	 * @var string
65
	 */
66
	private $_min_php = '5.3';
67
68
	/**
69
	 * Instance of the API class.
70
	 *
71
	 * @var WP2D_API
72
	 */
73
	private $_api = null;
74
75
	/**
76
	 * Create / Get the instance of this class.
77
	 *
78
	 * @return WP_To_Diaspora Instance of this class.
79
	 */
80
	public static function instance() {
81
		if ( ! isset( self::$_instance ) ) {
82
			self::$_instance = new self();
83
			self::$_instance->_constants();
84
			if ( self::$_instance->_version_check() ) {
85
				self::$_instance->_includes();
86
				self::$_instance->_setup();
87
			} else {
88
				self::$_instance = null;
89
			}
90
		}
91
		return self::$_instance;
92
	}
93
94
	/**
95
	 * Define all the required constants.
96
	 *
97
	 * @since 1.5.0
98
	 */
99
	private function _constants() {
0 ignored issues
show
_constants uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
100
		// Are we in debugging mode?
101
		if ( isset( $_GET['debugging'] ) ) {
102
			define( 'WP2D_DEBUGGING', true );
103
		}
104
105
		define( 'WP2D_DIR', dirname( __FILE__ ) );
106
		define( 'WP2D_LIB_DIR', WP2D_DIR . '/lib' );
107
		define( 'WP2D_VENDOR_DIR', WP2D_DIR . '/vendor' );
108
	}
109
110
	/**
111
	 * Check the minimum WordPress and PHP requirements.
112
	 *
113
	 * @since 1.5.4
114
	 *
115
	 * @return bool If version requirements are met.
116
	 */
117
	private function _version_check() {
0 ignored issues
show
_version_check uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
118
		// Check for version requirements.
119
		if ( version_compare( $GLOBALS['wp_version'], $this->_min_wp, '<' )
120
			|| version_compare( PHP_VERSION, $this->_min_php, '<' ) ) {
121
			add_action( 'admin_notices', array( $this, 'deactivate' ) );
122
			return false;
123
		}
124
125
		return true;
126
	}
127
128
	/**
129
	 * Callback to deactivate plugin and display admin notice.
130
	 *
131
	 * @since 1.5.4
132
	 */
133
	public function deactivate() {
0 ignored issues
show
deactivate uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
deactivate uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
134
		// First of all, deactivate the plugin.
135
		deactivate_plugins( plugin_basename( __FILE__ ) );
136
137
		// Get rid of the "Plugin activated" message.
138
		unset( $_GET['activate'] );
139
140
		// Then display the admin notice.
141
		?>
142
		<div class="error">
143
			<p><?php echo esc_html( sprintf( 'WP to diaspora* requires at least WordPress %1$s (you have %2$s) and PHP %3$s (you have %4$s)!', $this->_min_wp, $GLOBALS['wp_version'], $this->_min_php, PHP_VERSION ) ); ?></p>
144
		</div>
145
		<?php
146
	}
147
148
	/**
149
	 * Include all the required files.
150
	 *
151
	 * @since 1.5.0
152
	 */
153
	private function _includes() {
154
		require WP2D_VENDOR_DIR . '/autoload.php';
155
		require_once WP2D_LIB_DIR . '/class-api.php';
156
		require_once WP2D_LIB_DIR . '/class-contextual-help.php';
157
		require_once WP2D_LIB_DIR . '/class-helpers.php';
158
		require_once WP2D_LIB_DIR . '/class-options.php';
159
		require_once WP2D_LIB_DIR . '/class-post.php';
160
	}
161
162
	/**
163
	 * Set up the plugin.
164
	 */
165
	private function _setup() {
166
167
		// Load languages.
168
		add_action( 'plugins_loaded', array( $this, 'l10n' ) );
169
170
		// Add "Settings" link to plugin page.
171
		add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'settings_link' ) );
172
173
		// Perform any necessary data upgrades.
174
		add_action( 'admin_init', array( $this, 'upgrade' ) );
175
176
		// Enqueue CSS and JS scripts.
177
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_load_scripts' ) );
178
179
		// Set up the options.
180
		add_action( 'init', array( 'WP2D_Options', 'instance' ) );
181
182
		// WP2D Post.
183
		add_action( 'init', array( 'WP2D_Post', 'setup' ) );
184
185
		// AJAX actions for loading pods, aspects and services.
186
		add_action( 'wp_ajax_wp_to_diaspora_update_pod_list', array( $this, 'update_pod_list_callback' ) );
187
		add_action( 'wp_ajax_wp_to_diaspora_update_aspects_list', array( $this, 'update_aspects_list_callback' ) );
188
		add_action( 'wp_ajax_wp_to_diaspora_update_services_list', array( $this, 'update_services_list_callback' ) );
189
190
		// Check the pod connection status on the options page.
191
		add_action( 'wp_ajax_wp_to_diaspora_check_pod_connection_status', array( $this, 'check_pod_connection_status_callback' ) );
192
	}
193
194
	/**
195
	 * Load the diaspora* API for ease of use.
196
	 *
197
	 * @return WP2D_API|boolean The API object, or false.
198
	 */
199
	private function _load_api() {
200
		if ( ! isset( $this->_api ) ) {
201
			$this->_api = WP2D_Helpers::api_quick_connect();
202
		}
203
		return $this->_api;
204
	}
205
206
	/**
207
	 * Initialise upgrade sequence.
208
	 */
209
	public function upgrade() {
210
		// Get the current options, or assign defaults.
211
		$options = WP2D_Options::instance();
212
		$version = $options->get_option( 'version' );
213
214
		// If the versions differ, this is probably an update. Need to save updated options.
215
		if ( WP2D_VERSION !== $version ) {
216
217
			// Password is stored encrypted since version 1.2.7.
218
			// When upgrading to it, the plain text password is encrypted and saved again.
219
			if ( version_compare( $version, '1.2.7', '<' ) ) {
220
				$options->set_option( 'password', WP2D_Helpers::encrypt( (string) $options->get_option( 'password' ) ) );
221
			}
222
223
			if ( version_compare( $version, '1.3.0', '<' ) ) {
224
				// The 'user' setting is renamed to 'username'.
225
				$options->set_option( 'username', $options->get_option( 'user' ) );
226
				$options->set_option( 'user', null );
227
228
				// Save tags as arrays instead of comma seperated values.
229
				$global_tags = $options->get_option( 'global_tags' );
230
				$options->set_option( 'global_tags', $options->validate_tags( $global_tags ) );
231
			}
232
233
			if ( version_compare( $version, '1.4.0', '<' ) ) {
234
				// Turn tags_to_post string into an array.
235
				$tags_to_post_old = $options->get_option( 'tags_to_post' );
236
				$tags_to_post = array_filter( array(
237
					( ( false !== strpos( $tags_to_post_old, 'g' ) ) ? 'global' : null ),
238
					( ( false !== strpos( $tags_to_post_old, 'c' ) ) ? 'custom' : null ),
239
					( ( false !== strpos( $tags_to_post_old, 'p' ) ) ? 'post'   : null ),
240
				) );
241
				$options->set_option( 'tags_to_post', $tags_to_post );
242
			}
243
244
			// Update version.
245
			$options->set_option( 'version', WP2D_VERSION );
246
			$options->save();
247
		}
248
	}
249
250
	/**
251
	 * Set up i18n.
252
	 */
253
	public function l10n() {
254
		load_plugin_textdomain( 'wp-to-diaspora', false, 'wp-to-diaspora/languages' );
255
	}
256
257
	/**
258
	 * Load scripts and styles for Settings and Post pages of allowed post types.
259
	 */
260
	public function admin_load_scripts() {
261
		// Get the enabled post types to load the script for.
262
		$enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types', array() );
263
264
		// Get the screen to find out where we are.
265
		$screen = get_current_screen();
266
267
		// Only load the styles and scripts on the settings page and the allowed post types.
268
		if ( 'settings_page_wp_to_diaspora' === $screen->id || ( in_array( $screen->post_type, $enabled_post_types ) && 'post' === $screen->base ) ) {
269
			wp_enqueue_style( 'tag-it', plugins_url( '/css/jquery.tagit.css', __FILE__ ) );
270
			wp_enqueue_style( 'chosen', plugins_url( '/css/chosen.min.css', __FILE__ ) );
271
			wp_enqueue_style( 'wp-to-diaspora-admin', plugins_url( '/css/wp-to-diaspora.css', __FILE__ ) );
272
			wp_enqueue_script( 'chosen', plugins_url( '/js/chosen.jquery.min.js', __FILE__ ), array( 'jquery' ), false, true );
273
			wp_enqueue_script( 'tag-it', plugins_url( '/js/tag-it.min.js', __FILE__ ), array( 'jquery', 'jquery-ui-autocomplete' ), false, true );
274
			wp_enqueue_script( 'wp-to-diaspora-admin', plugins_url( '/js/wp-to-diaspora.js', __FILE__ ), array( 'jquery' ), false, true );
275
			// Javascript-specific l10n.
276
			wp_localize_script( 'wp-to-diaspora-admin', 'WP2DL10n', array(
277
				'no_services_connected' => __( 'No services connected yet.', 'wp-to-diaspora' ),
278
				'sure_reset_defaults'   => __( 'Are you sure you want to reset to default values?', 'wp-to-diaspora' ),
279
				'conn_testing'          => __( 'Testing connection...', 'wp-to-diaspora' ),
280
				'conn_successful'       => __( 'Connection successful.', 'wp-to-diaspora' ),
281
				'conn_failed'           => __( 'Connection failed.', 'wp-to-diaspora' ),
282
			) );
283
		}
284
	}
285
286
	/**
287
	 * Add the "Settings" link to the plugins page.
288
	 *
289
	 * @param array $links Links to display for plugin on plugins page.
290
	 * @return array Links to display for plugin on plugins page.
291
	 */
292
	public function settings_link( $links ) {
293
		$links[] = '<a href="' . admin_url( 'options-general.php?page=wp_to_diaspora' ) . '">' . __( 'Settings' ) . '</a>';
294
		return $links;
295
	}
296
297
	/**
298
	 * Fetch the updated list of pods from podupti.me and save it to the settings.
299
	 *
300
	 * @return array The list of pods.
301
	 */
302
	private function _update_pod_list() {
303
		// API url to fetch pods list from podupti.me.
304
		$pod_list_url = 'http://podupti.me/api.php?format=json&key=4r45tg';
305
		$pods = array();
306
307
		// Get the response from the WP_HTTP request.
308
		$response = wp_safe_remote_get( $pod_list_url );
309
310
		if ( $json = wp_remote_retrieve_body( $response ) ) {
311
			$pod_list = json_decode( $json );
312
313
			if ( isset( $pod_list->pods ) ) {
314
				foreach ( $pod_list->pods as $pod ) {
315
					if ( 'no' === $pod->hidden ) {
316
						$pods[] = array(
317
							'secure' => $pod->secure,
318
							'domain' => $pod->domain,
319
						);
320
					}
321
				}
322
323
				$options = WP2D_Options::instance();
324
				$options->set_option( 'pod_list', $pods );
325
				$options->save();
326
			}
327
		}
328
329
		return $pods;
330
	}
331
332
	/**
333
	 * Update the list of pods and return them for use with AJAX.
334
	 */
335
	public function update_pod_list_callback() {
336
		wp_send_json( $this->_update_pod_list() );
337
	}
338
339
	/**
340
	 * Fetch the list of aspects or services and save them to the settings.
341
	 *
342
	 * NOTE: When updating the lists, always force a fresh fetch.
343
	 *
344
	 * @param string $type Type of list to update.
345
	 * @return array|boolean The list of aspects or services, false if an illegal parameter is passed.
346
	 */
347
	private function _update_aspects_services_list( $type ) {
348
		// Check for correct argument value.
349
		if ( ! in_array( $type, array( 'aspects', 'services' ) ) ) {
350
			return false;
351
		}
352
353
		$options = WP2D_Options::instance();
354
		$list    = $options->get_option( $type . '_list' );
355
356
		// Make sure that we have at least the 'Public' aspect.
357
		if ( 'aspects' === $type && empty( $list ) ) {
358
			$list = array( 'public' => __( 'Public' ) );
0 ignored issues
show
$list is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
359
		}
360
361
		// Set up the connection to diaspora*.
362
		$api = $this->_load_api();
363
364
		// If there was a problem loading the API, return false.
365
		if ( $api->has_last_error() ) {
366
			return false;
367
		}
368
369
		if ( 'aspects' === $type ) {
370
			$list_new = $api->get_aspects( true );
371
		} elseif ( 'services' === $type ) {
372
			$list_new = $api->get_services( true );
373
		}
374
		// If the new list couldn't be fetched successfully, return false.
375
		if ( $api->has_last_error() ) {
376
			return false;
377
		}
378
379
		// We have a new list to save and return!
380
		$options->set_option( $type . '_list', $list_new );
0 ignored issues
show
The variable $list_new does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
381
		$options->save();
382
383
		return $list_new;
384
	}
385
386
	/**
387
	 * Update the list of aspects and return them for use with AJAX.
388
	 */
389
	public function update_aspects_list_callback() {
390
		wp_send_json( $this->_update_aspects_services_list( 'aspects' ) );
391
	}
392
393
	/**
394
	 * Update the list of services and return them for use with AJAX.
395
	 */
396
	public function update_services_list_callback() {
397
		wp_send_json( $this->_update_aspects_services_list( 'services' ) );
398
	}
399
400
	/**
401
	 * Check the pod connection status.
402
	 *
403
	 * @return string The status of the connection.
404
	 */
405
	private function _check_pod_connection_status() {
406
		$options = WP2D_Options::instance();
407
408
		$status = null;
409
410
		if ( $options->is_pod_set_up() ) {
411
			$status = ! $this->_load_api()->has_last_error();
412
		}
413
414
		return $status;
415
	}
416
417
	/**
418
	 * Check the connection to the pod and return the status for use with AJAX.
419
	 *
420
	 * @todo esc_html
421
	 */
422
	public function check_pod_connection_status_callback() {
0 ignored issues
show
check_pod_connection_status_callback uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
423
		if ( isset( $_REQUEST['debugging'] ) && ! defined( 'WP2D_DEBUGGING' ) ) {
424
			define( 'WP2D_DEBUGGING', true );
425
		}
426
427
		$status = $this->_check_pod_connection_status();
428
429
		$data = array(
430
			'debug'   => esc_textarea( WP2D_Helpers::get_debugging() ),
431
			'message' => __( 'Connection successful.', 'wp-to-diaspora' ),
432
		);
433
434
		if ( true === $status ) {
435
			wp_send_json_success( $data );
436
		} elseif ( false === $status && $this->_load_api()->has_last_error() ) {
437
			$data['message'] = $this->_load_api()->get_last_error() . ' ' . WP2D_Contextual_Help::get_help_tab_quick_link( $this->_load_api()->get_last_error_object() );
438
			wp_send_json_error( $data );
439
		}
440
		// If $status === null, do nothing.
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
441
	}
442
}
443
444
// Get the party started!
445
WP_To_Diaspora::instance();
446