Test Failed
Push — main ( 94eef3...96fa17 )
by Dimitri
14:06
created

ClearLogs::execute()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 25
rs 9.6111
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Cli\Commands\Housekeeping;
13
14
use BlitzPHP\Cli\Console\Command;
15
16
/**
17
 * Efface tous les logs
18
 */
19
class ClearLogs extends Command
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24
    protected $group = 'Housekeeping';
25
26
    /**
27
     * {@inheritDoc}
28
     */
29
    protected $name = 'logs:clear';
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected $description = 'Efface tous les fichiers de log.';
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    protected $options = [
40
        '--force' => 'Forcer la suppression de tous les fichiers de logs sans avoir à demander.',
41
    ];
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function execute(array $params)
47
    {
48
        $force = array_key_exists('force', $params) || $this->option('force');
49
50
        if (! $force && ! $this->confirm('Êtes-vous sûr de vouloir supprimer les logs?')) {
51
            // @codeCoverageIgnoreStart
52
            $this->fail('Suppression des logs interrompue.');
53
            $this->fail('Si vous le souhaitez, utilisez l\'option "-force" pour forcer la suppression de tous les fichiers de log.');
54
            $this->newLine();
55
56
            return;
57
            // @codeCoverageIgnoreEnd
58
        }
59
60
        helper('filesystem');
61
62
        if (! delete_files(STORAGE_PATH . 'logs', false, true)) {
63
            // @codeCoverageIgnoreStart
64
            $this->error('Erreur lors de la suppression des fichiers de logs.')->eol();
65
66
            return;
67
            // @codeCoverageIgnoreEnd
68
        }
69
70
        $this->success('Logs netoyés.')->eol();
71
    }
72
}
73