Completed
Push — master ( 2f347b...82694e )
by Haralan
12s
created

Kohana_Upload_Temp   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 77.42%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 4
dl 0
loc 79
ccs 24
cts 31
cp 0.7742
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A valid() 0 4 2
A directory_url() 0 4 1
A realpath() 0 4 1
A url() 0 4 1
A config() 0 11 2
A directory() 0 15 3
A directory_path() 0 11 2
A clear() 0 8 2
A factory() 0 4 1
1
<?php
2
/**
3
 *  Utility class for managing the temporary upload directory
4
 *
5
 * @package    Jam
6
 * @author     Ivan Kerin
7
 * @copyright  (c) 2011-2012 Despark Ltd.
8
 * @license    http://creativecommons.org/licenses/by-sa/3.0/legalcode
9
 */
10
class Kohana_Upload_Temp
11
{
12 24
	public static function factory()
13
	{
14 24
		return new Upload_Temp;
15
	}
16
17 19
	public static function config($name = NULL)
18
	{
19 19
		if ($name !== NULL)
20
		{
21 19
			return Kohana::$config->load("jam.upload.temp.{$name}");
22
		}
23
		else
24
		{
25
			return Kohana::$config->load("jam.upload.temp");
26
		}
27
	}
28
29
	public static function valid($file)
30
	{
31
		return (substr_count($file, DIRECTORY_SEPARATOR) === 1 AND is_file(Upload_Util::combine(Upload_Temp::config('path'), $file)));
32
	}
33
34
	protected $_directory;
35
36 22
	public function directory($directory = NULL)
37
	{
38 22
		if ($directory !== NULL)
39
		{
40 5
			$this->_directory = $directory;
41 5
			return $this;
42
		}
43
44 22
		if ( ! $this->_directory)
45
		{
46 17
			$this->_directory = uniqid();
47
		}
48
49 22
		return $this->_directory;
50
	}
51
52 15
	public function directory_path($thumbnail = NULL)
53
	{
54 15
		$directory = $this->realpath($this->directory(), $thumbnail);
55
56 15
		if ( ! is_dir($directory))
57
		{
58 15
			mkdir($directory, 0777);
59
		}
60
61 15
		return $directory;
62
	}
63
64
	public function directory_url($thumbnail = NULL)
65
	{
66
		return $this->webpath($this->directory(), $thumbnail);
0 ignored issues
show
Bug introduced by
The method webpath() does not seem to exist on object<Kohana_Upload_Temp>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
	}
68
69 19
	public function clear()
70
	{
71 19
		if ($this->_directory)
72
		{
73 17
			Upload_Util::rmdir($this->realpath($this->directory()));
74 17
			$this->_directory = NULL;
75
		}
76 19
	}
77
78 19
	public function realpath($path, $thumbnail = NULL)
79
	{
80 19
		return Upload_Util::combine(Upload_Temp::config('path'), $path, $thumbnail);
81
	}
82
83
	public function url($path, $thumbnail = NULL)
84
	{
85
		return Upload_Util::combine(Upload_Temp::config('web'), $path, $thumbnail);
86
	}
87
88
}
89