Mime   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 51
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @package Cadmium\Framework\Mime
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace {
11
12
	abstract class Mime extends Range {
13
14
		protected static $range = [];
15
16
		/**
17
		 * Check if an extension is of a given type
18
		 */
19
20
		private static function checkType(string $extension, string $type) : bool {
21
22
			if (false === ($mime = self::get($extension))) return false;
23
24
			return (preg_match(('/^' . $type . '\//'), $mime) ? true : false);
25
		}
26
27
		/**
28
		 * Autoloader
29
		 */
30
31
		public static function __autoload() {
32
33
			self::init(DIR_DATA . 'Mime.php');
34
		}
35
36
		/**
37
		 * Check if a given extension is of an image type
38
		 */
39
40
		public static function isImage(string $extension) : bool {
41
42
			return self::checkType($extension, 'image');
43
		}
44
45
		/**
46
		 * Check if a given extension is of an audio type
47
		 */
48
49
		public static function isAudio(string $extension) : bool {
50
51
			return self::checkType($extension, 'audio');
52
		}
53
54
		/**
55
		 * Check if a given extension is of a video type
56
		 */
57
58
		public static function isVideo(string $extension) : bool {
59
60
			return self::checkType($extension, 'video');
61
		}
62
	}
63
}
64