PluginSecurity   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 70
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A disable_deactivate_plugin() 0 9 3
A getLockFilename() 0 3 1
A load() 0 3 1
A deactivate() 0 2 1
A activate() 0 3 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\Activable;
13
use Yemenifree\WpSecurity\Interfaces\Loadable;
14
15
class PluginSecurity implements Loadable, Activable
16
{
17
    /**
18
     * Basename of plugin.
19
     *
20
     * @var string
21
     */
22
    private $basename;
23
24
    /**
25
     * lock filename.
26
     *
27
     * @var string
28
     */
29
    private $lock_filename = '.wp-security-lock';
30
31
    public function __construct($basename)
32
    {
33
        $this->basename = $basename;
34
    }
35
36
    /**
37
     * Load module (perform any tasks that should be done immediately on plugin load).
38
     */
39
    public function load()
40
    {
41
        add_action('deactivate_plugin', [$this, 'disable_deactivate_plugin'], 99, 2);
0 ignored issues
show
Bug introduced by
The function add_action 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

41
        /** @scrutinizer ignore-call */ 
42
        add_action('deactivate_plugin', [$this, 'disable_deactivate_plugin'], 99, 2);
Loading history...
42
    }
43
44
    /**
45
     * Disabled upload zip files ( plugins & themes ) via admin account.
46
     *
47
     * @param $plugin
48
     * @param $network_deactivating
49
     */
50
    public function disable_deactivate_plugin($plugin, $network_deactivating)
0 ignored issues
show
Unused Code introduced by
The parameter $network_deactivating is not used and could be removed. ( Ignorable by Annotation )

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

50
    public function disable_deactivate_plugin($plugin, /** @scrutinizer ignore-unused */ $network_deactivating)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        if ($this->basename !== $plugin) {
53
            return;
54
        }
55
56
        // if deactivate is lock.
57
        if (\file_exists($this->getLockFilename())) {
58
            wp_die(__('Sorry, you should remove file ' . $this->getLockFilename() . ' to allow to deactivate this plugin.'));
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

58
            wp_die(/** @scrutinizer ignore-call */ __('Sorry, you should remove file ' . $this->getLockFilename() . ' to allow to deactivate this plugin.'));
Loading history...
Bug introduced by
The function wp_die 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

58
            /** @scrutinizer ignore-call */ 
59
            wp_die(__('Sorry, you should remove file ' . $this->getLockFilename() . ' to allow to deactivate this plugin.'));
Loading history...
59
        }
60
    }
61
62
    /**
63
     * get full path of lock file.
64
     *
65
     * @return string
66
     */
67
    public function getLockFilename()
68
    {
69
        return \rtrim(WC_SECURITY_PATH, '/') . '/' . $this->lock_filename;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function activate()
76
    {
77
        \touch($this->getLockFilename());
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function deactivate()
84
    {
85
    }
86
}
87