Completed
Push — master ( eb3e35...0fac1b )
by Ryan
06:16
created

Application::isInstalled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php namespace Anomaly\Streams\Platform\Application;
2
3
use Illuminate\Foundation\Bus\DispatchesJobs;
4
5
/**
6
 * Class Application
7
 *
8
 * @link    http://pyrocms.com/
9
 * @author  PyroCMS, Inc. <[email protected]>
10
 * @author  Ryan Thompson <[email protected]>
11
 */
12
class Application
13
{
14
15
    use DispatchesJobs;
16
17
    /**
18
     * The application locale.
19
     *
20
     * @var string
21
     */
22
    protected $locale = null;
23
24
    /**
25
     * The enabled state of the application.
26
     *
27
     * @var bool
28
     */
29
    protected $enabled = null;
30
31
    /**
32
     * Keep installed status around.
33
     *
34
     * @var bool
35
     */
36
    protected $installed = null;
37
38
    /**
39
     * The application reference.
40
     *
41
     * @var string
42
     */
43
    protected $reference = 'default';
44
45
    /**
46
     * The application repository.
47
     *
48
     * @var ApplicationRepository
49
     */
50
    protected $applications;
51
52
    /**
53
     * Create a new Application instance.
54
     *
55
     * @param ApplicationRepository $model
0 ignored issues
show
Bug introduced by
There is no parameter named $model. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     */
57
    public function __construct(ApplicationRepository $applications)
58
    {
59
        $this->applications = $applications;
60
61
        $this->reference = env('DEFAULT_REFERENCE', $this->reference);
62
    }
63
64
    /**
65
     * Setup the application.
66
     */
67
    public function setup()
68
    {
69
        $this->setTablePrefix();
70
    }
71
72
    /**
73
     * Set the database table prefix going forward.
74
     * We really don't need a core table from here on out.
75
     */
76
    public function setTablePrefix()
77
    {
78
        app('db')->getSchemaBuilder()->getConnection()->setTablePrefix($this->getReference() . '_');
79
        app('db')->getSchemaBuilder()->getConnection()->getSchemaGrammar()->setTablePrefix($this->getReference() . '_');
80
    }
81
82
    /**
83
     * Get the reference.
84
     *
85
     * @return null
86
     */
87
    public function getReference()
88
    {
89
        return $this->reference;
90
    }
91
92
    /**
93
     * Set the reference.
94
     *
95
     * @param $reference
96
     * @return $this
97
     */
98
    public function setReference($reference)
99
    {
100
        $this->reference = $reference;
101
102
        return $this;
103
    }
104
105
    /**
106
     * Get the storage path for the application.
107
     *
108
     * @param  string $path
109
     * @return string
110
     */
111
    public function getStoragePath($path = '')
112
    {
113
        return storage_path('streams/' . $this->getReference()) . ($path ? '/' . $path : $path);
114
    }
115
116
    /**
117
     * Get the public assets path for the application.
118
     *
119
     * @param  string $path
120
     * @return string
121
     */
122
    public function getAssetsPath($path = '')
123
    {
124
        return public_path('app/' . $this->getReference()) . ($path ? '/' . $path : $path);
125
    }
126
127
    /**
128
     * Get the resources path for the application.
129
     *
130
     * @param  string $path
131
     * @return string
132
     */
133
    public function getResourcesPath($path = '')
134
    {
135
        return base_path('resources/' . $this->getReference()) . ($path ? '/' . $path : $path);
136
    }
137
138
    /**
139
     * Return the app reference.
140
     *
141
     * @return string
142
     */
143
    public function tablePrefix()
144
    {
145
        return $this->reference . '_';
146
    }
147
148
    /**
149
     * Locate the app by request or passed
150
     * variable and set the application reference.
151
     *
152
     * @return bool
153
     */
154
    public function locate()
155
    {
156
        if (app('db')->getSchemaBuilder()->hasTable('applications')) {
157
            if ($app = $this->applications->findByDomain(app('request')->root())) {
158
159
                $this->installed = true;
160
                $this->locale    = $app->locale;
0 ignored issues
show
Documentation introduced by
The property locale does not exist on object<Anomaly\Streams\P...ation\ApplicationModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
161
                $this->enabled   = $app->enabled;
0 ignored issues
show
Documentation introduced by
The property enabled does not exist on object<Anomaly\Streams\P...ation\ApplicationModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
162
                $this->reference = $app->reference;
0 ignored issues
show
Documentation introduced by
The property reference does not exist on object<Anomaly\Streams\P...ation\ApplicationModel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
163
164
                return true;
165
            }
166
167
            return false;
168
        }
169
170
        return true;
171
    }
172
173
    /**
174
     * Get the resolved locale.
175
     *
176
     * @return string
177
     */
178
    public function getLocale()
179
    {
180
        return $this->locale;
181
    }
182
183
    /**
184
     * Return if the application is enabled.
185
     *
186
     * @return bool
187
     */
188
    public function isEnabled()
189
    {
190
        if (is_null($this->enabled)) {
191
            return true;
192
        }
193
194
        return $this->enabled;
195
    }
196
197
    /**
198
     * Is the application installed?
199
     *
200
     * @return bool
201
     */
202
    public function isInstalled()
203
    {
204
        if (is_null($this->installed)) {
205
            $this->installed = file_exists(base_path('.env'));
206
        }
207
208
        return $this->installed;
209
    }
210
}
211