GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 928b67...8d8dff )
by Renato
12:32
created

MaintenanceModeService::checkAllowedIp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Rdehnhardt\MaintenanceMode;
4
5
use Laravel\Lumen\Application;
6
7
class MaintenanceModeService
8
{
9
    /**
10
     * File to verify maintenance mode.
11
     *
12
     * @var string
13
     */
14
    protected $maintenanceFile = 'framework/down';
15
16
    /**
17
     * Lumen Application instance.
18
     *
19
     * @var \Laravel\Lumen\Application
20
     */
21
    protected $app;
22
23
    /**
24
     * MaintenanceModeService constructor.
25
     * @param Application $app
26
     */
27
    public function __construct(Application $app)
28
    {
29
        $this->app = $app;
30
    }
31
32
    /**
33
     * Verify if application is in maintenance mode.
34
     *
35
     * @return bool
36
     */
37
    public function isDownMode()
38
    {
39
        return $this->maintenanceFileExists();
40
    }
41
42
    /**
43
     * Indicates if maintenance file exists.
44
     *
45
     * @return bool
46
     */
47
    public function maintenanceFileExists()
48
    {
49
        return file_exists($this->maintenanceFilePath());
50
    }
51
52
    /**
53
     * Maintenance file path.
54
     *
55
     * @return string
56
     */
57
    public function maintenanceFilePath()
58
    {
59
        return $this->app->storagePath($this->maintenanceFile);
60
    }
61
62
    /**
63
     * Verify if application is up.
64
     *
65
     * @return bool
66
     */
67
    public function isUpMode()
68
    {
69
        return !$this->maintenanceFileExists();
70
    }
71
72
    /**
73
     * Put the application in down mode.
74
     *
75
     * @throws Exceptions\FileException
76
     *
77
     * @return bool true if success and false if something fails.
78
     */
79 View Code Duplication
    public function setDownMode()
0 ignored issues
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...
80
    {
81
        $file = $this->maintenanceFilePath();
82
83
        if (!touch($file)) {
84
            $message = sprintf(
85
                'Something went wrong on trying to create maintenance file %s.',
86
                $file
87
            );
88
89
            throw new Exceptions\FileException($message);
90
        }
91
92
        return true;
93
    }
94
95
    /**
96
     * Put application in up mode.
97
     *
98
     * @throws Exceptions\FileException
99
     *
100
     * @return bool true if success and false if something fails.
101
     */
102 View Code Duplication
    public function setUpMode()
0 ignored issues
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...
103
    {
104
        $file = $this->maintenanceFilePath();
105
106
        if (file_exists($file) && !unlink($file)) {
107
            $message = sprintf(
108
                'Something went wrong on trying to remove maintenance file %s.',
109
                $file
110
            );
111
112
            throw new Exceptions\FileException($message);
113
        }
114
115
        return true;
116
    }
117
118
    public function checkAllowedIp($ip)
119
    {
120
        $allowed = explode(',', env('ALLOWED_IPS'));
121
122
        return in_array($ip, $allowed);
123
    }
124
}
125