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
|
||||||||||||
2 | /** |
|||||||||||
3 | * WordPress Settings |
|||||||||||
4 | * |
|||||||||||
5 | * Add setting pages with Amarkal UI components to your WordPress theme or |
|||||||||||
6 | * plugin. |
|||||||||||
7 | * |
|||||||||||
8 | * @package amarkal-settings |
|||||||||||
9 | * @depends amarkal-ui |
|||||||||||
10 | * @author Askupa Software <[email protected]> |
|||||||||||
11 | * @link https://github.com/askupasoftware/amarkal-settings |
|||||||||||
12 | * @copyright 2017 Askupa Software |
|||||||||||
13 | */ |
|||||||||||
14 | ||||||||||||
15 | // Prevent direct file access |
|||||||||||
16 | defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
17 | ||||||||||||
18 | /** |
|||||||||||
19 | * Prevent loading the library more than once |
|||||||||||
20 | */ |
|||||||||||
21 | if( defined( 'AMARKAL_SETTINGS' ) ) return false; |
|||||||||||
22 | define( 'AMARKAL_SETTINGS', true ); |
|||||||||||
23 | ||||||||||||
24 | if(!function_exists('amarkal_add_settings_page')) |
|||||||||||
25 | { |
|||||||||||
26 | /** |
|||||||||||
27 | * Add a new top-level settings page |
|||||||||||
28 | * |
|||||||||||
29 | * @param [array] $args |
|||||||||||
0 ignored issues
–
show
The doc-type
[array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
||||||||||||
30 | * @return void |
|||||||||||
31 | */ |
|||||||||||
32 | function amarkal_add_settings_page( $args ) |
|||||||||||
33 | { |
|||||||||||
34 | $manager = Amarkal\Settings\Manager::get_instance(); |
|||||||||||
35 | $manager->add_page($args); |
|||||||||||
36 | } |
|||||||||||
37 | } |
|||||||||||
38 | ||||||||||||
39 | if(!function_exists('amarkal_add_settings_child_page')) |
|||||||||||
40 | { |
|||||||||||
41 | /** |
|||||||||||
42 | * Add a child page to an existing top-level settings page |
|||||||||||
43 | * |
|||||||||||
44 | * @param [array] $args |
|||||||||||
0 ignored issues
–
show
The doc-type
[array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
||||||||||||
45 | * @return void |
|||||||||||
46 | */ |
|||||||||||
47 | function amarkal_add_settings_child_page( $args ) |
|||||||||||
48 | { |
|||||||||||
49 | $manager = Amarkal\Settings\Manager::get_instance(); |
|||||||||||
50 | $manager->add_child_page($args); |
|||||||||||
51 | } |
|||||||||||
52 | } |
|||||||||||
53 | ||||||||||||
54 | if(!function_exists('amarkal_get_settings_value')) |
|||||||||||
55 | { |
|||||||||||
56 | /** |
|||||||||||
57 | * Get the value of the given settings |
|||||||||||
58 | * |
|||||||||||
59 | * @param [array] $args |
|||||||||||
0 ignored issues
–
show
The doc-type
[array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() There is no parameter named
$args . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
||||||||||||
60 | * @return void |
|||||||||||
61 | */ |
|||||||||||
62 | function amarkal_get_settings_value( $field_name ) |
|||||||||||
63 | { |
|||||||||||
64 | $manager = Amarkal\Settings\Manager::get_instance(); |
|||||||||||
65 | return $manager->get_field_value($field_name); |
|||||||||||
66 | } |
|||||||||||
67 | } |
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.