Passed
Branch master (ffb5df)
by Michele
03:52
created

LaravelWebArtisan::useAuthentication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace Micheledamo\LaravelWebArtisan;
3
4
use GuzzleHttp;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp 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...
5
use Illuminate\Http\Response;
6
7
class LaravelWebArtisan
8
{
9
    /**
10
     * The Laravel application instance.
11
     *
12
     * @var \Illuminate\Foundation\Application
13
     */
14
    protected $app;
15
16
    /**
17
     * True when enabled.
18
     *
19
     * @var bool
20
     */
21
    protected $enabled;
22
23
    /**
24
     * True when use authentication
25
     *
26
     * @var
27
     */
28
    protected $use_authentication;
29
30
    /**
31
     * True when authenticated.
32
     *
33
     * @var
34
     */
35
    protected $authenticated;
36
37
    /**
38
     * LaravelWebArtisan constructor.
39
     *
40
     * @param null $app
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $app is correct as it would always require null to be passed?
Loading history...
41
     */
42
	public function __construct($app = null)
43
	{
44
        if (!$app) {
0 ignored issues
show
introduced by
$app is of type null, thus it always evaluated to false.
Loading history...
45
            $app = app();   //Fallback when $app is not given
46
        }
47
        $this->app = $app;
48
49
        $this->enabled = value($this->app['config']->get('webartisan.enabled'));
50
        $this->use_authentication = value($this->app['config']->get('webartisan.use_authentication'));
51
        $this->authenticated = false;
52
	}
53
54
    /**
55
     * Check if the Web Artisan is enabled
56
     *
57
     * @return boolean
58
     */
59
    public function isEnabled()
60
    {
61
        return $this->enabled;
62
    }
63
64
    /**
65
     * Check if the Web Artisan is authenticated
66
     *
67
     * @return bool
68
     */
69
    public function isAuthenticated()
70
    {
71
        return $this->authenticated or request()->session()->has('webartisan__authenticated');
72
    }
73
74
    /**
75
     * Check if the Web Artisan use authentication before run commands
76
     *
77
     * @return mixed
78
     */
79
    public function useAuthentication()
80
    {
81
        return $this->use_authentication;
82
    }
83
84
    /**
85
     * Render the Web Artisan Window
86
     *
87
     * @param Response $response
88
     */
89
    public function render(Response $response)
90
    {
91
        $content = $response->getContent();
92
        if (($body = mb_strpos($content, '</body>')) !== false) {
93
            $response->setContent(mb_substr($content, 0, $body) .
94
                view('webartisan::window', ['webartisan' => $this]) .
95
                mb_substr($content, $body));
96
        }
97
    }
98
99
    /**
100
     * Set authenticated
101
     *
102
     * @param bool $value
103
     */
104
    public function setAuthenticated($value = true)
105
    {
106
        $this->authenticated = $value;
107
    }
108
109
}