File class-llms-media-protector.php
has 405 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* LLMS_Media_Protector class
*
* @package LifterLMS/Classes
Function is_authorized_to_view
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function is_authorized_to_view( $user_id, $media_id ): ?bool {
if ( ! is_numeric( $media_id ) || ! intval( $media_id ) ) {
return null;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function save_mod_rewrite_rules
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function save_mod_rewrite_rules() {
// TODO: Different for multi-site?
if ( false === get_transient( 'lifterlms_check_media_protection_files' ) ) {
global $wp_filesystem;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
LLMS_Media_Protector
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class LLMS_Media_Protector {
/**
* The meta key used to specify the filter hook name that authorizes viewing of a media file.
*
Method serve_file
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function serve_file() {
$media_id = llms_filter_input( INPUT_GET, self::URL_PARAMETER_ID, FILTER_SANITIZE_NUMBER_INT );
// Handle a rewritten URL.
Function serve_file
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function serve_file() {
$media_id = llms_filter_input( INPUT_GET, self::URL_PARAMETER_ID, FILTER_SANITIZE_NUMBER_INT );
// Handle a rewritten URL.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method is_authorized_to_view
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function is_authorized_to_view( $user_id, $media_id ): ?bool {
if ( ! is_numeric( $media_id ) || ! intval( $media_id ) ) {
return null;
}
Method save_mod_rewrite_rules
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function save_mod_rewrite_rules() {
// TODO: Different for multi-site?
if ( false === get_transient( 'lifterlms_check_media_protection_files' ) ) {
global $wp_filesystem;
Function send_file
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
protected function send_file( $file_name, $media_id ) {
$server_software = ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : '' );
if (
( array_key_exists( 'MOD_X_SENDFILE_ENABLED', $_SERVER ) && '1' === $_SERVER['MOD_X_SENDFILE_ENABLED'] ) ||
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if (
( array_key_exists( 'MOD_X_SENDFILE_ENABLED', $_SERVER ) && '1' === $_SERVER['MOD_X_SENDFILE_ENABLED'] ) ||
( function_exists( 'apache_get_modules' ) && in_array( 'mod_xsendfile', apache_get_modules(), true ) ) ||
stristr( $server_software, 'cherokee' ) ||
stristr( $server_software, 'lighttpd' )
Method handle_upload
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
$file_id,
$post_id,
$hook_name,
$post_data = array(),
$overrides = array( 'test_form' => false )
Function get_size
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function get_size() {
$size = ( isset( $_GET[ self::URL_PARAMETER_SIZE ] ) ) ? sanitize_text_field( $_GET[ self::URL_PARAMETER_SIZE ] ) : null;
if ( false === $size ) {
$size = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function find_wp_root
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function find_wp_root() {
$dir = dirname( WP_CONTENT_DIR );
while ( $dir ) {
if ( file_exists( $dir . '/wp-load.php' ) || file_exists( $dir . '/wp-config.php' ) ) {
return $dir;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"