CacheConsole   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 44.44 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 28
loc 63
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clean() 16 16 3
A remove() 12 12 2
A setDriver() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.
9
 *
10
 * @category   Kumbia
11
 * @package    Console
12
 *
13
 * @copyright  Copyright (c) 2005 - 2019 KumbiaPHP Team (http://www.kumbiaphp.com)
14
 * @license    https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE   New BSD License
15
 */
16
// carga libreria para manejo de cache
17
Load::lib('cache');
18
19
/**
20
 * Consola para manejar la cache
21
 *
22
 * @category   Kumbia
23
 * @package    Console
24
 */
25
class CacheConsole
26
{
27
28
    /**
29
     * Comando de consola para limpiar la cache
30
     *
31
     * @param array $params parametros nombrados de la consola
32
     * @param string $group nombre de grupo
33
     * @throw KumbiaException
34
     */
35 View Code Duplication
    public function clean($params, $group = '')
0 ignored issues
show
Duplication introduced by joanhey
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        // obtiene el driver de cache
38
        $cache = $this->setDriver($params);
39
40
        // limpia la cache
41
        if ($cache->clean($group)) {
42
            if ($group) {
43
                echo "-> Se ha limpiado el grupo $group", PHP_EOL;
44
            } else {
45
                echo "-> Se ha limpiado la cache", PHP_EOL;
46
            }
47
        } else {
48
            throw new KumbiaException('No se ha logrado eliminar el contenido de la cache');
49
        }
50
    }
51
52
    /**
53
     * Comando de consola para eliminar un elemento cacheado
54
     *
55
     * @param array $params parametros nombrados de la consola
56
     * @param string $id id del elemento
57
     * @param string $group nombre de grupo
58
     * @throw KumbiaException
59
     */
60 View Code Duplication
    public function remove($params, $id, $group = 'default')
0 ignored issues
show
Duplication introduced by Emilio Silveira
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        // obtiene el driver de cache
63
        $cache = $this->setDriver($params);
64
65
        // elimina el elemento
66
        if ($cache->remove($id, $group)) {
67
            echo '-> Se ha eliminado el elemento de la cache', PHP_EOL;
68
        } else {
69
            throw new KumbiaException("No se ha logrado eliminar el elemento \"$id\" del grupo \"$group\"");
70
        }
71
    }
72
    
73
    /**
74
     * Devuelve una instancia de cache del driver pasado
75
     *
76
     * @param array $params parametros nombrados
77
     */
78
    private function setDriver($params)
79
    {
80
        if (isset($params['driver'])) {
81
            return Cache::driver($params['driver']);
82
        } 
83
        return Cache::driver();
84
        
85
    }
86
87
}
88