Completed
Push — master ( e5ceef...d5cda2 )
by Martijn van
02:11
created

SuperSakeChecker::isApache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
4
class SuperSakeChecker
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
7
    /**
8
     * Checks if the supersake file in webroot is protected with htaccess or web.config
9
     *
10
     * From the command line we don't know on what server software we are running,
11
     * so we just checking if a .htaccess or web.config exists and has the protection lines in it.
12
     *
13
     * @return bool|string
14
     */
15
    public function superSakeIsNotProtected()
16
    {
17
        $file = BASE_PATH . '/.htaccess';
18
        if(is_file($file)) {
19
            return $this->checkHtAccessProtection($file);
20
        }
21
22
        $file = BASE_PATH . '/web.config';
23
        if(is_file($file)) {
24
            return $this->checkWebConfigProtection($file);
25
        }
26
27
        return '';
28
    }
29
30
    /**
31
     * @param string $file
32
     * @return bool|string
33
     */
34 View Code Duplication
    protected function checkHtAccessProtection($file)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        if(!is_file($file) || strpos(file_get_contents($file), '<Files supersake>') !== false) {
37
            return 'supersake is not protected in .htaccess';
38
        }
39
40
        return false;
41
    }
42
43
    /**
44
     * @param string $file
45
     * @return bool|string
46
     */
47 View Code Duplication
    protected function checkWebConfigProtection($file)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        if(!is_file($file) || strpos(file_get_contents($file), '<add fileExtension="supersake" allowed="false"/>') !== false) {
50
            return 'supersake is not protected in web.config';
51
        }
52
53
        return false;
54
    }
55
}
56