Completed
Push — uv-index ( 9af66d )
by Christian
02:24
created

AbstractCache::setSeconds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org .
4
 *
5
 * @license MIT
6
 *
7
 * Please see the LICENSE file distributed with this source code for further
8
 * information regarding copyright and licensing.
9
 *
10
 * Please visit the following links to read about the usage policies and the license of
11
 * OpenWeatherMap before using this class:
12
 *
13
 * @see http://www.OpenWeatherMap.org
14
 * @see http://www.OpenWeatherMap.org/terms
15
 * @see http://openweathermap.org/appid
16
 */
17
18
namespace Cmfcmf\OpenWeatherMap;
19
20
/**
21
 * Abstract cache class to be overwritten by custom cache implementations.
22
 */
23
abstract class AbstractCache
24
{
25
    /**
26
     * @var int $seconds Cache time in seconds.
27
     */
28
    protected $seconds;
29
30
    /**
31
     * Checks whether a cached weather data is available.
32
     *
33
     * @param string $url The unique url of the cached content.
34
     *
35
     * @return bool False if no cached information is available, otherwise true.
36
     *
37
     * You need to check if a cached result is outdated here. Return false in that case.
38
     */
39
    abstract public function isCached($url);
40
41
    /**
42
     * Returns cached weather data.
43
     *
44
     * @param string $url The unique url of the cached content.
45
     *
46
     * @return string|bool The cached data if it exists, false otherwise.
47
     */
48
    abstract public function getCached($url);
49
50
    /**
51
     * Saves cached weather data.
52
     *
53
     * @param string $url     The unique url of the cached content.
54
     * @param string $content The weather data to cache.
55
     *
56
     * @return bool True on success, false on failure.
57
     */
58
    abstract public function setCached($url, $content);
59
60
    /**
61
     * Set after how much seconds the cache shall expire.
62
     *
63
     * @param int $seconds
64
     */
65 1
    public function setSeconds($seconds)
66
    {
67 1
        $this->seconds = $seconds;
68 1
    }
69
}
70