Passed
Push — renovate/configure ( 3d37a9...8f147e )
by
unknown
19:53
created

filemanager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
c 2
b 0
f 0
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get_upload_destination() 0 3 1
A get_upload_dir() 0 3 1
A set_user_dir() 0 10 3
A __construct() 0 5 1
A get_user_dir() 0 8 2
1
<?php
2
3
/**
4
 *
5
 * @package sitemaker
6
 * @copyright (c) 2017 Daniel A. (blitze)
7
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace blitze\sitemaker\services;
12
13
/**
14
 * @package sitemaker
15
 */
16
class filemanager
17
{
18
	/** @var \phpbb\filesystem\filesystem */
19
	protected $filesystem;
20
21
	/** @var \phpbb\user */
22
	protected $user;
23
24
	/** @var string */
25
	protected $phpbb_root_path;
26
27
	/** @var string */
28
	protected $user_dir = false;
29
30
	/** @var string */
31
	protected $upload_dir = 'images/sitemaker_uploads/source/';
32
33
	/**
34
	 * Constructor
35
	 *
36
	 * @param \phpbb\filesystem\filesystem	$filesystem			File system
37
	 * @param \phpbb\user					$user				User object
38
	 * @param string						$phpbb_root_path	phpBB root path
39
	 */
40
	public function __construct(\phpbb\filesystem\filesystem $filesystem, \phpbb\user $user, $phpbb_root_path)
41
	{
42
		$this->filesystem = $filesystem;
43
		$this->user = $user;
44
		$this->phpbb_root_path = $phpbb_root_path;
45
	}
46
47
	/**
48
	 * @return string
49
	 */
50
	public function get_upload_dir()
51
	{
52
		return $this->upload_dir;
53
	}
54
55
	/**
56
	 * @return string
57
	 */
58
	public function get_upload_destination()
59
	{
60
		return $this->upload_dir . $this->get_user_dir();
61
	}
62
63
	/**
64
	 * @return string
65
	 */
66
	public function get_user_dir()
67
	{
68
		if (!$this->user_dir)
69
		{
70
			$this->set_user_dir();
71
		}
72
73
		return $this->user_dir;
74
	}
75
76
	/**
77
	 * @return string
78
	 */
79
	protected function set_user_dir()
80
	{
81
		// if user is not founder, they must have a directory
82
		$this->user_dir = ($this->user->data['user_type'] != USER_FOUNDER) ? 'users/' . $this->user->data['username'] . '/' : '';
83
84
		$destination = $this->phpbb_root_path . $this->upload_dir . $this->user_dir;
85
86
		if (!is_dir($destination))
87
		{
88
			$this->filesystem->mkdir($destination, 0755);
89
		}
90
	}
91
}
92