PruneEntries   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 60
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A prune() 0 10 3
A isEnabled() 0 8 2
1
<?php
2
3
namespace Insense\LaravelTelescopePruning;
4
5
use Insense\LaravelTelescopePruning\Models\EntryModel;
6
7
class PruneEntries
8
{
9
10
    /**
11
     * The Laravel application instance.
12
     *
13
     * @var \Illuminate\Contracts\Foundation\Application
14
     */
15
    protected $app;
16
17
    /**
18
     * The pruning configuration options.
19
     *
20
     * @var array
21
     */
22
    protected $config;
23
24
    /**
25
     * Create a new prune entries instance.
26
     *
27
     * @param  \Illuminate\Contracts\Foundation\Application $app
28
     */
29
    public function __construct($app)
30
    {
31
        $this->app = $app;
32
33
        $config = $this->app['config'];
34
        $this->config = $config->get('telescope-pruning');
35
    }
36
37
    /**
38
     * Prune the Telescope entries.
39
     *
40
     * @return int
41
     */
42
    public function prune()
43
    {
44
        if (!$this->isEnabled() || is_null($this->config['limit'])) {
45
            return 0;
46
        }
47
48
        $limit = (int) $this->config['limit'];
49
        $whitelistedLimit = $this->config['whitelist']['whitelist_limit'];
50
51
        return EntryModel::prune($limit, $whitelistedLimit);
52
    }
53
54
    /**
55
     * Check if Telescope pruning is enabled.
56
     *
57
     * @return boolean
58
     */
59
    protected function isEnabled()
60
    {
61
        if (is_null($this->config['enabled'])) {
62
            // enable pruning in non-local environments
63
            return !$this->app->environment('local');
64
        }
65
66
        return (bool) $this->config['enabled'];
67
    }
68
}
69