GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CFPHPCache   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A configurar() 0 9 3
A obtenerRuta() 0 3 1
A obtener() 0 7 3
A enviar() 0 3 2
A eliminar() 0 6 2
A limpiar() 0 7 2
A file_expired() 0 6 3
1
<?php
2
3
/*
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license. For more information, see
18
 * @category   
19
 * @package    sistema/ayudantes
20
 * @copyright  Copyright (c) 2006 - 2014 webcol.net (http://www.webcol.net/calima)
21
 * @license	https://github.com/webcol/Calima/blob/master/LICENSE	MIT
22
 * @version	##BETA 1.0##, ##2014 - 2015##
23
 * <http://www.calimaframework.com>.
24
 */
25
26
namespace Sistema\Ayudantes;
27
28
class CFPHPCache {
29
	/**
30
	 * Configuracion
31
	 *
32
	 * @access public
33
	 */
34
	public static $configuracion = array(
35
		'cache_dir' => 'cache',
36
		// por defecto el tiempo expira en  *minutos*
37
		'expires' => 180,
38
	);
39
	
40
	public static function configurar($clave, $valor = null) {
41
		if( is_array($clave) ) {
42
			foreach ($clave as $config_name => $config_value) {
43
				self::$configuracion[$config_name] = $config_value;
44
			}
45
		} else {
46
			self::$configuracion[$clave] = $valor;
47
		}
48
	}
49
	/**
50
	 * obtiene la ruta del archivo asociado a la clave.
51
	 *
52
	 * @access public
53
	 * @param string $clave
54
	 * @return string el nombre del archivo php
55
	 */
56
	public static function obtenerRuta($clave) {
57
		return static::$configuracion['cache_path'] . '/' . md5($clave) . '.php';
58
	}
59
	/**
60
	 * obtiene los datos asociados a la clave
61
	 *
62
	 * @access public
63
	 * @param string $clave	 
64
	 */
65
	public static function obtener($clave, $raw = false, $tiempo_personalizado = null) {
66
		if( ! self::file_expired($archivo = self::obtenerRuta($clave), $tiempo_personalizado)) {
67
			$contenido = file_get_contents($archivo);
68
			return $raw ? $contenido : unserialize($contenido);
69
		}
70
		return null;
71
	}
72
	/**
73
	 * Envia el contenido dentro de la cache
74
	 *
75
	 * @access public
76
	 * @param string $clave
77
	 * @param mixed $content the the content you want to store
0 ignored issues
show
Bug introduced by
There is no parameter named $content. 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...
78
	 * @param bool $raw whether if you want to store raw data or not. If it is true, $content *must* be a string
79
	 *        It can be useful for static html caching.
80
	 * @return bool whether if the operation was successful or not
81
	 */
82
	public static function enviar($clave, $contenido, $raw = false) {
83
		return @file_put_contents(self::obtenerRuta($clave), $raw ? $contenido : serialize($contenido)) !== false;
84
	}
85
	/**
86
	 * Delete data from cache
87
	 *
88
	 * @access public
89
	 * @param string $clave
90
	 * @return bool true if the data was removed successfully
91
	 */
92
	public static function eliminar($clave) {
93
		if( ! file_exists($archivo = self::obtenerRuta($clave)) ) {
94
			return true;
95
		}
96
		return @unlink($archivo);
97
	}
98
	/**
99
	 * limpia la cache
100
	 *
101
	 * @access public
102
	 * @return bool always true
103
	 */
104
	public static function limpiar() {
105
		$cache_files = glob(self::$configuracion['cache_path'] . '/*.php', GLOB_NOSORT);
106
		foreach ($cache_files as $archivo) {
107
			@unlink($archivo);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
108
		}
109
		return true;
110
	}
111
	/**
112
	 * Check if a file has expired or not.
113
	 *
114
	 * @access public
115
	 * @param $archivo the rout to the file
116
	 * @param int $fecha the number of minutes it was set to expire
117
	 * @return bool if the file has expired or not
118
	 */
119
	public static function file_expired($archivo, $fecha = null) {
120
		if( ! file_exists($archivo) ) {
121
			return true;
122
		}
123
		return (time() > (filemtime($archivo) + 60 * ($fecha ? $fecha : self::$configuracion['expires'])));
124
	}
125
}
126