Completed
Pull Request — master (#272)
by
unknown
10:38
created

LogViewer::allFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php namespace Arcanedev\LogViewer;
2
3
use Arcanedev\LogViewer\Contracts\Utilities\Filesystem as FilesystemContract;
4
use Arcanedev\LogViewer\Contracts\Utilities\Factory as FactoryContract;
5
use Arcanedev\LogViewer\Contracts\Utilities\LogLevels as LogLevelsContract;
6
use Arcanedev\LogViewer\Contracts\LogViewer as LogViewerContract;
7
8
/**
9
 * Class     LogViewer
10
 *
11
 * @package  Arcanedev\LogViewer
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class LogViewer implements LogViewerContract
15
{
16
    /* -----------------------------------------------------------------
17
     |  Constants
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * LogViewer Version
23
     */
24
    const VERSION = '4.7.1';
25
26
    /* -----------------------------------------------------------------
27
     |  Properties
28
     | -----------------------------------------------------------------
29
     */
30
31
    /**
32
     * The factory instance.
33
     *
34
     * @var \Arcanedev\LogViewer\Contracts\Utilities\Factory
35
     */
36
    protected $factory;
37
38
    /**
39
     * The filesystem instance.
40
     *
41
     * @var \Arcanedev\LogViewer\Contracts\Utilities\Filesystem
42
     */
43
    protected $filesystem;
44
45
    /**
46
     * The log levels instance.
47
     *
48
     * @var \Arcanedev\LogViewer\Contracts\Utilities\LogLevels
49
     */
50
    protected $levels;
51
52
    /* -----------------------------------------------------------------
53
     |  Constructor
54
     | -----------------------------------------------------------------
55
     */
56
57
    /**
58
     * Create a new instance.
59
     *
60
     * @param  \Arcanedev\LogViewer\Contracts\Utilities\Factory     $factory
61
     * @param  \Arcanedev\LogViewer\Contracts\Utilities\Filesystem  $filesystem
62
     * @param  \Arcanedev\LogViewer\Contracts\Utilities\LogLevels   $levels
63
     */
64 195
    public function __construct(
65
        FactoryContract    $factory,
66
        FilesystemContract $filesystem,
67
        LogLevelsContract  $levels
68
    ) {
69 195
        $this->factory    = $factory;
70 195
        $this->filesystem = $filesystem;
71 195
        $this->levels     = $levels;
72 195
    }
73
74
    /* -----------------------------------------------------------------
75
     |  Getters & Setters
76
     | -----------------------------------------------------------------
77
     */
78
79
    /**
80
     * Get the log levels.
81
     *
82
     * @param  bool  $flip
83
     *
84
     * @return array
85
     */
86 105
    public function levels($flip = false)
87
    {
88 105
        return $this->levels->lists($flip);
89
    }
90
91
    /**
92
     * Get the translated log levels.
93
     *
94
     * @param  string|null  $locale
95
     *
96
     * @return array
97
     */
98 12
    public function levelsNames($locale = null)
99
    {
100 12
        return $this->levels->names($locale);
101
    }
102
103
    /**
104
     * Set the log storage path.
105
     *
106
     * @param  string  $path
107
     *
108
     * @return self
109
     */
110 6
    public function setPath($path)
111
    {
112 6
        $this->factory->setPath($path);
113
114 6
        return $this;
115
    }
116
117
    /**
118
     * Get the log pattern.
119
     *
120
     * @return string
121
     */
122 3
    public function getPattern()
123
    {
124 3
        return $this->factory->getPattern();
125
    }
126
127
    /**
128
     * Set the log pattern.
129
     *
130
     * @param  string  $date
131
     * @param  string  $prefix
132
     * @param  string  $extension
133
     *
134
     * @return self
135
     */
136 3
    public function setPattern(
137
        $prefix    = FilesystemContract::PATTERN_PREFIX,
138
        $date      = FilesystemContract::PATTERN_DATE,
139
        $extension = FilesystemContract::PATTERN_EXTENSION
140
    ) {
141 3
        $this->factory->setPattern($prefix, $date, $extension);
142
143 3
        return $this;
144
    }
145
146
    /* -----------------------------------------------------------------
147
     |  Main Methods
148
     | -----------------------------------------------------------------
149
     */
150
151
    /**
152
     * Get all logs.
153
     *
154
     * @return \Arcanedev\LogViewer\Entities\LogCollection
155
     */
156 3
    public function all()
157
    {
158 3
        return $this->factory->all();
159
    }
160
161
    /**
162
     * Paginate all logs.
163
     *
164
     * @param  int  $perPage
165
     *
166
     * @return \Illuminate\Pagination\LengthAwarePaginator
167
     */
168 3
    public function paginate($perPage = 30)
169
    {
170 3
        return $this->factory->paginate($perPage);
171
    }
172
173
    /**
174
     * Get a log.
175
     *
176
     * @param  string  $date
177
     *
178
     * @return \Arcanedev\LogViewer\Entities\Log
179
     */
180 15
    public function get($date)
181
    {
182 15
        return $this->factory->log($date);
183
    }
184
185
    /**
186
     * Get the log entries.
187
     *
188
     * @param  string  $date
189
     * @param  string  $level
190
     *
191
     * @return \Arcanedev\LogViewer\Entities\LogEntryCollection
192
     */
193 9
    public function entries($date, $level = 'all')
194
    {
195 9
        return $this->factory->entries($date, $level);
196
    }
197
198
    /**
199
     * Download a log file.
200
     *
201
     * @param  string       $date
202
     * @param  string|null  $filename
203
     * @param  array        $headers
204
     *
205
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
206
     */
207 6
    public function download($date, $filename = null, $headers = [])
208
    {
209 6
        if (is_null($filename)) {
210 6
            $filename = "laravel-{$date}.log";
211
        }
212
213 6
        $path = $this->filesystem->path($date);
214
215 6
        return response()->download($path, $filename, $headers);
0 ignored issues
show
Bug introduced by
The method download does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
216
    }
217
218
    /**
219
     * Get logs statistics.
220
     *
221
     * @return array
222
     */
223 33
    public function stats()
224
    {
225 33
        return $this->factory->stats();
226
    }
227
228
    /**
229
     * Get logs statistics table.
230
     *
231
     * @param  string|null  $locale
232
     *
233
     * @return \Arcanedev\LogViewer\Tables\StatsTable
234
     */
235 12
    public function statsTable($locale = null)
236
    {
237 12
        return $this->factory->statsTable($locale);
238
    }
239
240
    /**
241
     * Delete the log.
242
     *
243
     * @param  string  $date
244
     *
245
     * @return bool
246
     */
247 9
    public function delete($date)
248
    {
249 9
        return $this->filesystem->delete($date);
250
    }
251
252
    /**
253
     * Clear the log files.
254
     *
255
     * @return bool
256
     */
257 3
    public function clear()
258
    {
259 3
        return $this->filesystem->clear();
260
    }
261
262
    /**
263
     * Get all valid log files.
264
     *
265
     * @return array
266
     */
267 3
    public function files()
268
    {
269 3
        return $this->filesystem->logs();
270
    }
271
272
    /**
273
     * Get all log files.
274
     *
275
     * @return array
276
     */
277 6
    public function allFiles()
278
    {
279 6
        return $this->filesystem->all();
280
    }
281
282
    /**
283
     * List the log files (only dates).
284
     *
285
     * @return array
286
     */
287 6
    public function dates()
288
    {
289 6
        return $this->factory->dates();
290
    }
291
292
    /**
293
     * Get logs count.
294
     *
295
     * @return int
296
     */
297
    public function count()
298
    {
299 6
        return $this->factory->count();
300
    }
301 6
302
    /**
303
     * Get entries total from all logs.
304
     *
305
     * @param  string  $level
306
     *
307
     * @return int
308
     */
309
    public function total($level = 'all')
310
    {
311 3
        return $this->factory->total($level);
312
    }
313 3
314
    /**
315
     * Get logs tree.
316
     *
317
     * @param  bool  $trans
318
     *
319
     * @return array
320
     */
321
    public function tree($trans = false)
322
    {
323 3
        return $this->factory->tree($trans);
324
    }
325 3
326
    /**
327
     * Get logs menu.
328
     *
329
     * @param  bool  $trans
330
     *
331
     * @return array
332
     */
333
    public function menu($trans = true)
334
    {
335
        return $this->factory->menu($trans);
336
    }
337
338 3
    /* -----------------------------------------------------------------
339
     |  Check Methods
340 3
     | -----------------------------------------------------------------
341
     */
342
343
    /**
344
     * Determine if the log folder is empty or not.
345
     *
346
     * @return bool
347
     */
348
    public function isEmpty()
349
    {
350
        return $this->factory->isEmpty();
351
    }
352
353 36
    /* -----------------------------------------------------------------
354
     |  Other Methods
355 36
     | -----------------------------------------------------------------
356
     */
357
358
    /**
359
     * Get the LogViewer version.
360
     *
361
     * @return string
362
     */
363
    public function version()
364
    {
365
        return self::VERSION;
366
    }
367
}
368