HtaccessSecurity   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMainHtaccess() 0 3 1
A getPaths() 0 3 1
A activate() 0 4 1
A getUploadsHtaccess() 0 3 1
A deactivate() 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 Illuminate\Support\Collection;
13
use Yemenifree\WpSecurity\Interfaces\Activable;
14
use Yemenifree\WpSecurity\Traits\HasFilesReader;
15
use Yemenifree\WpSecurity\Traits\HasHtaccessEditMode;
16
17
class HtaccessSecurity implements Activable
18
{
19
    use HasHtaccessEditMode, HasFilesReader;
20
21
    protected $paths;
22
23
    /**
24
     * HtaccessSecurity constructor.
25
     */
26
    public function __construct()
27
    {
28
        $this->paths = [
29
            ABSPATH => $this->getMainHtaccess(),
0 ignored issues
show
Bug introduced by
The constant Yemenifree\WpSecurity\Modules\ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
            wp_upload_dir()['basedir'] => $this->getUploadsHtaccess(),
0 ignored issues
show
Bug introduced by
The function wp_upload_dir 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

30
            /** @scrutinizer ignore-call */ 
31
            wp_upload_dir()['basedir'] => $this->getUploadsHtaccess(),
Loading history...
31
        ];
32
    }
33
34
    /**
35
     * get main htaccess content file from plugin.
36
     *
37
     * @return string
38
     */
39
    private function getMainHtaccess()
40
    {
41
        return $this->getFileContent('.htaccess');
42
    }
43
44
    /**
45
     * get upload htaccess content from plugin.
46
     *
47
     * @return string
48
     */
49
    private function getUploadsHtaccess()
50
    {
51
        return $this->getFileContent('.uploads-htaccess');
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function activate()
58
    {
59
        $this->getPaths()->each(function ($content, $path) {
60
            $this->setHtaccessPath($path)->setHtaccessRule($content)->addHtaccessContent();
61
        });
62
    }
63
64
    /**
65
     * get list paths & htaccess content.
66
     *
67
     * @return Collection
68
     */
69
    public function getPaths()
70
    {
71
        return collect($this->paths);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function deactivate()
78
    {
79
        $this->getPaths()->each(function ($content, $path) {
80
            $this->setHtaccessPath($path)->setHtaccessRule($content)->removeHtaccessContent();
81
        });
82
    }
83
}
84