Container   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A getBreadcrumbs() 0 15 2
A getPath() 0 4 1
A getPathFull() 0 4 1
A getOrigin() 0 4 1
A getPermissions() 0 4 1
A isIgnoreHidden() 0 4 1
1
<?php
2
3
/**
4
 * @package Cadmium\System\Modules\Filemanager
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Filemanager\Utils {
11
12
	use Explorer;
13
14
	abstract class Container {
15
16
		private $scheme = [], $path = '';
17
18
		protected $path_full = '';
19
20
		/**
21
		 * Constructor
22
		 */
23
24
		public function __construct(string $path = '') {
25
26
			$scheme = array_diff(preg_split('/[\/\\\\]+/', $path, -1, PREG_SPLIT_NO_EMPTY), ['.', '..']);
27
28
			$path_full = ($this->path_full . (('' !== ($path = implode('/', $scheme))) ? ($path . '/') : ''));
29
30
			if (!Explorer::isDir($path_full)) return;
31
32
			$this->scheme = $scheme; $this->path = $path; $this->path_full = $path_full;
33
		}
34
35
		/**
36
		 * Get the container breadcrumbs
37
		 *
38
		 * @return array : the list of ancestor directories where each item is an array of type
39
		 *         ['origin' => $origin, 'path' => $path, 'name' => $name], where $origin is a container's origin directory name,
40
		 *         $path is a directory's relative path, and $name is an directory's file name
41
		 */
42
43
		public function getBreadcrumbs() : array {
44
45
			$scheme = []; $breadcrumbs = [];
46
47
			foreach ($this->scheme as $name) {
48
49
				$scheme[] = $name; $path = implode('/', $scheme);
50
51
				$breadcrumbs[] = ['origin' => static::$origin, 'path' => $path, 'name' => $name];
52
			}
53
54
			# ------------------------
55
56
			return $breadcrumbs;
57
		}
58
59
		/**
60
		 * Get the container relative path
61
		 */
62
63
		public function getPath() : string {
64
65
			return $this->path;
66
		}
67
68
		/**
69
		 * Get the container full path
70
		 */
71
72
		public function getPathFull() : string {
73
74
			return $this->path_full;
75
		}
76
77
		/**
78
		 * Get the origin directory name
79
		 */
80
81
		public function getOrigin() : string {
82
83
			return static::$origin;
84
		}
85
86
		/**
87
		 * Get the list of container permissions (inherited from origin)
88
		 */
89
90
		public function getPermissions() : array {
91
92
			return static::$permissions;
93
		}
94
95
		/**
96
		 * Check whether the container is set to ignore hidden files or not (inherited from origin)
97
		 */
98
99
		public function isIgnoreHidden() : bool {
100
101
			return static::$ignore_hidden;
102
		}
103
	}
104
}
105