ResetSecurity   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A requireAuthForRestAccess() 0 11 2
A init() 0 4 1
1
<?php
2
3
/*
4
 * Copyright (c) 2017 Salah Alkhwlani <[email protected]>
5
 *
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Yemenifree\WpSecurity\Modules;
11
12
use Yemenifree\WpSecurity\Interfaces\Initializable;
13
14
class ResetSecurity implements Initializable
15
{
16
    /**
17
     * Initialize module (perform any tasks that should be done init hook).
18
     */
19
    public function init()
20
    {
21
        // Disable REST API methods to anonymous users
22
        add_filter('rest_authentication_errors', [$this, 'requireAuthForRestAccess']);
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        /** @scrutinizer ignore-call */ 
23
        add_filter('rest_authentication_errors', [$this, 'requireAuthForRestAccess']);
Loading history...
23
    }
24
25
    /**
26
     * Return an authentication error if a user who is not logged in tries to query the REST API.
27
     *
28
     * @param mixed $access
29
     *
30
     * @return WP_Error
0 ignored issues
show
Bug introduced by
The type Yemenifree\WpSecurity\Modules\WP_Error was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    public function requireAuthForRestAccess($access)
33
    {
34
        if (!is_user_logged_in()) {
0 ignored issues
show
Bug introduced by
The function is_user_logged_in was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        if (!/** @scrutinizer ignore-call */ is_user_logged_in()) {
Loading history...
35
            return new \WP_Error(
0 ignored issues
show
Bug introduced by
The type WP_Error was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
                'rest_cannot_access',
37
                __('Only authenticated users can access the REST API.', 'wp-security'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
                /** @scrutinizer ignore-call */ 
38
                __('Only authenticated users can access the REST API.', 'wp-security'),
Loading history...
38
                ['status' => rest_authorization_required_code()]
0 ignored issues
show
Bug introduced by
The function rest_authorization_required_code was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
                ['status' => /** @scrutinizer ignore-call */ rest_authorization_required_code()]
Loading history...
39
            );
40
        }
41
42
        return $access;
43
    }
44
}
45