Icon   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
B setIcon() 0 13 5
A getName() 0 3 1
A getFullName() 0 3 1
A getExtension() 0 3 1
A getPath() 0 3 1
A getShortUri() 0 3 1
A setShortUri() 0 3 1
A getSize() 0 3 1
A toArray() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
namespace OpenMindParser\Models;
4
5
use OpenMindParser\Exceptions\UnexistentFileException;
6
7
/*Object that represent an Icon.*/
8
class Icon 
9
{
10
	/**
11
	 * @var String $name : The name of the icon without the path or the extension.
12
	 */
13
	private $name;
14
	/**
15
	 * @var String $fullName : The name of the icon without the path but with the extension.
16
	 */
17
	private $fullName;
18
	/**
19
	 * @var String $filePath : The file path of the icon. If it is a builtin icon, then it is in the 'img' directory of the project.
20
	 */
21
	private $path;
22
	/**
23
	 * @var String $shortUri : The short uri to thye image. Will be used for exports. If it is a builtin icon, value will be '/img/'.
24
	 */
25
	private $shortUri;
26
	/**
27
	 * @var int $size : The size of the file.
28
	 */
29
	private $size;
30
	/**
31
	 * @var String $extension : The extension of the icon file without the leading dot. If it is a builtin icon, then it is 'png'.
32
	 */
33
	private $extension;
34
	
35
	/**
36
	 * The constructor. Use setIcon method.
37
	 * 
38
	 * @param String $name : The name of the icon without the path or the extension.
39
	 * @param String $path : The file path of the icon. If it is a builtin icon, then it is in the 'img' directory of the project.
40
	 * @param String $shortUri : The short uri to thye image. Will be used for exports. If it is a builtin icon, value will be '/img/'.
41
	 * @param int $size : The size of the file.
42
	 * @param String $extension : The extension of the icon file without the leading dot. If it is a builtin icon, then it is 'png'.
43
	 */ 
44
	public function __construct($name = null, $extension = null, $path = null, $shortUri = null, $size = null) {
45
		if(!empty($name)) {
46
			$this->setIcon($name, $extension, $path, $shortUri, $size);
47
		}
48
	}
49
	
50
	/**
51
	 * Fill all the instance attributes according to the given parameters.
52
	 * If only the name is given , then it will assume that a builtin icon is beeing used so the aother attributes will be filled following this logic.
53
	 * 
54
	 * @param String $name : The name of the icon without the path or the extension.
55
	 * @param String $path : The file path of the icon. If it is a builtin icon, then it is in the 'img' directory of the project.
56
	 * @param String $shortUri : The short uri to thye image. Will be used for exports. If it is a builtin icon, value will be '/img/'.
57
	 * @param int $size : The size of the file.
58
	 * @param String $extension : The extension of the icon file without the leading dot. If it is a builtin icon, then it is 'png'.
59
	 */ 
60
	public function setIcon($name, $extension = null, $path = null, $shortUri = null, $size = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $size is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
		$this->name = $name;
62
		$this->extension = $extension ?: 'png';
63
		$this->fullName = $this->name.'.'.$this->extension;
64
		$this->shortUri = $shortUri ?: '/img/'.$this->fullName;
65
		$this->path = $path ?: realpath(__DIR__.'/../../img/'.$this->fullName);
66
		
67
		if(!file_exists($this->path)) {
68
			throw new UnexistentFileException('The file '.$this->path.' does not exist !');
69
		}
70
		
71
		$this->size = filesize($this->path);
72
	}
73
	
74
	/**
75
	 * Return icon name.
76
	 * 
77
	 * @return String : the icon name.
78
	 */
79
	public function getName() {
80
		return $this->name;
81
	}
82
	
83
	/**
84
	 * Return the full icon name.
85
	 * 
86
	 * @return String : the full icon name.
87
	 */
88
	public function getFullName() {
89
		return $this->fullName;
90
	}
91
	
92
	/**
93
	 * Return icon extension.
94
	 * 
95
	 * @return String : the icon extension.
96
	 */
97
	public function getExtension() {
98
		return $this->extension;
99
	}
100
	
101
	/**
102
	 * Return icon file path.
103
	 * 
104
	 * @return String : the icon path.
105
	 */
106
	 public function getPath() {
107
	 	return $this->path;
108
	 }
109
	
110
	/**
111
	 * Return icon short uri.
112
	 * 
113
	 * @return String : the icon short uri.
114
	 */
115
	 public function getShortUri() {
116
	 	return $this->shortUri;
117
	 }
118
	
119
	/**
120
	 * Set the icon short uri.
121
	 * 
122
	 * @return String : the icon uri.
123
	 */
124
	 public function setShortUri($shortUri) {
125
	 	$this->shortUri = $shortUri;
126
	 }
127
	
128
	/**
129
	 * Return icon name.
130
	 * 
131
	 * @return int : the icon size.
132
	 */
133
	public function getSize() {
134
		return $this->size;
135
	}
136
	
137
	/**
138
	 * Transform the objects tree in an array tree.
139
	 * 
140
	 * @return Array $array : The array tree.
141
	 */
142
	public function toArray() {
143
		return get_object_vars($this);
144
	}
145
	
146
	/**
147
	 * Magic to String method.
148
	 * 
149
	 * @return String
150
	 */
151
	public function __toString() {
152
		return $this->getPath();
153
	}
154
}